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.

53 lines
885 B

  1. package net
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. "io"
  7. "github.com/vocdoni/dvote-relay/batch"
  8. "github.com/vocdoni/dvote-relay/types"
  9. )
  10. func parse(rw http.ResponseWriter, request *http.Request) {
  11. decoder := json.NewDecoder(request.Body)
  12. var s types.Submission
  13. var p types.Packet
  14. err := decoder.Decode(&s)
  15. if err != nil {
  16. panic(err)
  17. }
  18. //check PoW
  19. //check key
  20. //decrypt
  21. //check franchise
  22. //construct packet
  23. p.PID = 1
  24. p.Nullifier = []byte{1,2,3}
  25. p.Vote = []byte{4,5,6}
  26. p.Franchise = []byte{7,8,9}
  27. err = batch.Add(p)
  28. if err != nil {
  29. panic(err)
  30. }
  31. j, err := json.Marshal(s)
  32. io.WriteString(rw, string(j))
  33. }
  34. func Listen(port string) {
  35. http.HandleFunc("/submit", parse)
  36. //add waitgroup
  37. func() {
  38. fmt.Println("serving on " + port)
  39. err := http.ListenAndServe(":" + port, nil)
  40. if err != nil {
  41. panic("ListenAndServe: " + err.Error())
  42. }
  43. }()
  44. }