-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go.old
69 lines (55 loc) · 1.38 KB
/
main.go.old
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
package main
import (
"crypto/sha256"
"os"
"strconv"
"strings"
"github.com/tonyyanga/gdp-replicate/daemon"
"github.com/tonyyanga/gdp-replicate/gdp"
"go.uber.org/zap"
)
func main() {
if len(os.Args) < 4 {
panic("Requires arguments: SQL file, listen address, peer address, fanout degree [optional:naive]")
}
sqlFile := os.Args[1]
listenAddr := os.Args[2]
selfGDPAddr := gdp.GenerateHash(listenAddr)
daemon.InitLogger(selfGDPAddr)
peerMap := parsePeers(os.Args[3])
fanoutDegree, err := strconv.Atoi(os.Args[4])
if err != nil {
panic("unable to parse fanout degree")
}
var d *daemon.Daemon
if len(os.Args) >= 6 && os.Args[5] == "naive" {
d, err = daemon.NewDaemon(listenAddr, sqlFile, selfGDPAddr, peerMap, "naive")
} else {
panic("Regular daemon not supported rn")
}
if err != nil {
panic(err)
}
err = d.Start(fanoutDegree)
if err != nil {
panic(err)
}
}
// parsePeers parses a comma delimited string of IP:ports to a map from
// GDP addr to IP addr.
func parsePeers(peers string) map[gdp.Hash]string {
peerMap := make(map[gdp.Hash]string)
peerAddrs := strings.Split(peers, ",")
for _, peerAddr := range peerAddrs {
peerGDPAddr := sha256.Sum256([]byte(peerAddr))
peerMap[peerGDPAddr] = peerAddr
}
for gdpAddr, httpAddr := range peerMap {
zap.S().Infow(
"Added peer",
"gdpAddr", gdpAddr.Readable(),
"httpAddr", httpAddr,
)
}
return peerMap
}