-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
44 lines (35 loc) · 1.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"net/http"
"os"
)
//TODO use struct
type Infos struct {
Filename string `json:"filename"`
Hash string `json:"hash"`
// BTCaddr string `json:"btc_addr"`
}
func main() {
fmt.Printf("toadserver service starting...\n")
mux := http.NewServeMux()
mux.HandleFunc("/postfile/", postHandler) //post a file with its contents to gateway, returns hash
//ts makes & signs a nameTx, then posts to a node, which does the broadcasting
mux.HandleFunc("/receiveNameTx/", receiveNameTx) //unpack tx, if valid, add to chain
mux.HandleFunc("/cacheHash/", cacheHash) //also if valid, pin hash on all hosts (except one that sent it :~( )
mux.HandleFunc("/getfile/", getHandler) // request by name, receive contents
http.ListenAndServe(":11113", mux)
fmt.Printf("blockchain notary service listening on port 11113...\n")
}
//-------------------------------------------------------
//--helpers
func exit(err error) {
fmt.Println(err)
os.Exit(1)
}
func ifExit(err error) {
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}