-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.go
65 lines (57 loc) · 1.21 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
package main
import (
"log"
"math/rand"
"os"
"os/signal"
"syscall"
)
const (
eventQuit = iota
)
type sysEventMessage struct {
event int
idata int
}
// Passes messages such as eventQuit
var sysEventChannel = make(chan sysEventMessage, 5)
func main() {
rand.Seed(p2pEphemeralID + getNowUTC()) // Initialise weak RNG with strong RNG
log.Println("Starting up", p2pClientVersionString, "...")
sigChannel := make(chan os.Signal, 1)
signal.Notify(sigChannel, syscall.SIGINT, syscall.SIGTERM)
configInit()
if processPreBlockchainActions() {
return
}
dbInit()
cryptoInit()
blockchainInit(true)
if processActions() {
return
}
log.Printf("Ephemeral ID: %x\n", p2pEphemeralID)
go p2pCoordinator.Run()
go p2pServer()
go p2pClient()
go blockWebServer()
for {
select {
case msg := <-sysEventChannel:
switch msg.event {
case eventQuit:
log.Println("Exiting")
os.Exit(msg.idata)
}
case sig := <-sigChannel:
switch sig {
case syscall.SIGINT:
sysEventChannel <- sysEventMessage{event: eventQuit, idata: 0}
log.Println("^C detected")
case syscall.SIGTERM:
sysEventChannel <- sysEventMessage{event: eventQuit, idata: 0}
log.Println("Quit signal detected")
}
}
}
}