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

package net
import (
"encoding/json"
"fmt"
"net/http"
"time"
"strconv"
"io"
)
type submission struct {
Type string
Nonce []byte
Key []byte
Package []byte
Expiry time.Time
}
func parseSubmission(rw http.ResponseWriter, request *http.Request) {
decoder := json.NewDecoder(request.Body)
var s submission
err := decoder.Decode(&s)
if err != nil {
panic(err)
}
//check PoW
//check discriminator
//decrypt
//check franchise
//add to leveldb
j, err := json.Marshal(s)
//io.WriteString(rw, string(j))
}
func listen(port int) {
http.HandleFunc("/submit", parseSubmission)
portstr := strconv.Itoa(port)
go func() {
fmt.Println("serving on " + portstr)
err := http.ListenAndServe(":" + portstr, nil)
if err != nil {
panic("ListenAndServe: " + err.Error())
}
}()
}