This repository has been archived by the owner on Feb 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
114 lines (99 loc) · 2.68 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"net"
"net/http"
"os"
"os/signal"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/gorilla/mux"
"github.com/robvanmieghem/siapool/api"
"github.com/robvanmieghem/siapool/sharechain"
"github.com/robvanmieghem/siapool/siad"
)
func main() {
app := cli.NewApp()
app.Name = "Siapool node"
app.Version = "0.1-Dev"
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
var debugLogging bool
var bindAddress, apiAddr, rpcAddr string
var poolFee int
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, d",
Usage: "Enable debug logging",
Destination: &debugLogging,
},
cli.StringFlag{
Name: "bind, b",
Usage: "Pool bind address",
Value: ":9985",
Destination: &bindAddress,
},
cli.IntFlag{
Name: "fee, f",
Usage: "Pool fee, in 0.01%",
Value: 200,
Destination: &poolFee,
},
cli.StringFlag{
Name: "api-addr",
Value: "localhost:9980", Usage: "which host:port the API server listens on",
Destination: &apiAddr,
},
cli.StringFlag{
Name: "rpc-addr",
Value: ":9981",
Usage: "which port the gateway listens on",
Destination: &rpcAddr,
},
}
app.Before = func(c *cli.Context) error {
log.Infoln(app.Name, "-", app.Version)
if debugLogging {
log.SetLevel(log.DebugLevel)
log.Debugln("Debug logging enabled")
}
return nil
}
app.Action = func(c *cli.Context) {
// Print a startup message.
log.Infoln("Loading...")
// Create the listener for the server
l, err := net.Listen("tcp", bindAddress)
if err != nil {
log.Fatal("Error listening on", bindAddress, err)
}
dc := &siad.Siad{RPCAddr: rpcAddr, APIAddr: apiAddr}
err = dc.Start()
if err != nil {
log.Fatal("Error running embedded siad: ", err)
}
log.Infoln("Loading sharechain...")
sc, err := sharechain.New(dc, "p2pool")
if err != nil {
log.Fatal("Error initializing sharechain: ", err)
}
poolapi := api.PoolAPI{Fee: poolFee, ShareChain: sc}
r := mux.NewRouter()
r.Path("/fee").Methods("GET").Handler(http.HandlerFunc(poolapi.FeeHandler))
r.Path("/{payoutaddress}/miner/header").Methods("GET").Handler(http.HandlerFunc(poolapi.GetWorkHandler))
r.Path("/{payoutaddress}/miner/header").Methods("POST").Handler(http.HandlerFunc(poolapi.SubmitHeaderHandler))
// stop the server if a kill signal is caught
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, os.Kill)
go func() {
<-sigChan
log.Infoln("\rCaught stop signal, quitting...")
dc.Close()
l.Close()
}()
log.Infoln("Listening for miner requests")
srv := &http.Server{
Handler: r,
}
srv.Serve(l)
}
app.Run(os.Args)
}