-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (56 loc) · 1.31 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
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
help := flag.Bool("help", false, "Display Help")
cfg := parseFlags()
if *help {
fmt.Println("This is the P2P component of the Stratosphere Linux IPS.")
fmt.Println("Run './p2p-experiments' to start it.")
fmt.Println("For testing multiple peers on one machine, use './p2p-experiments -port [port]'")
fmt.Println()
fmt.Println("Usage:")
flag.PrintDefaults()
os.Exit(0)
}
name, err := os.Hostname()
if err != nil {
panic(err)
}
fmt.Println("hostname:", name)
keyFile := cfg.keyFile
peerstoreFile := cfg.peerstoreFile
if cfg.addPortToFilename {
if keyFile != "" {
keyFile = fmt.Sprintf("%s%d", keyFile, cfg.listenPort)
}
if peerstoreFile != "" {
peerstoreFile = fmt.Sprintf("%s%d", peerstoreFile, cfg.listenPort)
}
}
peer := Peer{
dbAddress:cfg.redisDb,
port:cfg.listenPort,
protocol:cfg.ProtocolID,
hostname:cfg.listenHost,
rendezVous:cfg.RendezvousString,
peerstoreFile:peerstoreFile,
keyFile:keyFile,
resetKey:cfg.resetKeys,
}
err = peer.peerInit()
if err != nil {
fmt.Println("Initializing peer failed")
os.Exit(1)
}
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<- ch
fmt.Printf("\nReceived signal, shutting down...\n")
os.Exit(0)
}