You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
800 B

  1. package net
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. "time"
  7. "strconv"
  8. "io"
  9. )
  10. type submission struct {
  11. Type string
  12. Nonce []byte
  13. Key []byte
  14. Package []byte
  15. Expiry time.Time
  16. }
  17. func parseSubmission(rw http.ResponseWriter, request *http.Request) {
  18. decoder := json.NewDecoder(request.Body)
  19. var s submission
  20. err := decoder.Decode(&s)
  21. if err != nil {
  22. panic(err)
  23. }
  24. //check PoW
  25. //check discriminator
  26. //decrypt
  27. //check franchise
  28. //add to leveldb
  29. j, err := json.Marshal(s)
  30. //io.WriteString(rw, string(j))
  31. }
  32. func listen(port int) {
  33. http.HandleFunc("/submit", parseSubmission)
  34. portstr := strconv.Itoa(port)
  35. go func() {
  36. fmt.Println("serving on " + portstr)
  37. err := http.ListenAndServe(":" + portstr, nil)
  38. if err != nil {
  39. panic("ListenAndServe: " + err.Error())
  40. }
  41. }()
  42. }