-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
132 lines (121 loc) · 2.6 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"Remora/Remora-Change"
"Remora/Remora-main"
"Remora/config"
"Remora/fork1"
"Remora/qcdag"
"Remora/tusk"
"errors"
"fmt"
"time"
)
var conf *config.Config
var err error
func init() {
conf, err = config.LoadConfig("", "config")
if err != nil {
panic(err)
}
}
func main() {
if conf.Protocol == "fork1" {
startForkBFT1()
} else if conf.Protocol == "qcdag" {
startQCDAG()
} else if conf.Protocol == "tusk" {
startTusk()
} else if conf.Protocol == "Remora" {
startRemora()
} else if conf.Protocol == "RemoraC" {
startRemoraC()
} else {
panic(errors.New("the protocol is unknown"))
}
}
func startForkBFT1() {
node := fork1.NewNode(conf)
if err = node.StartP2PListen(); err != nil {
panic(err)
}
// wait for each node to start
time.Sleep(time.Second * 10)
if err = node.EstablishP2PConns(); err != nil {
panic(err)
}
if !node.IsFaultyNode() {
fmt.Println("node starts the ForkBFT1!")
go node.RunLoop()
node.HandleMsgLoop()
}
}
func startQCDAG() {
node := qcdag.NewNode(conf)
if err = node.StartP2PListen(); err != nil {
panic(err)
}
// wait for each node to start
time.Sleep(time.Second * 25)
if err = node.EstablishP2PConns(); err != nil {
panic(err)
}
node.InitCBC(conf)
fmt.Println("node starts the QCDAG!")
go node.RunLoop()
go node.HandleMsgLoop()
go node.DoneOutputLoop()
node.CBCOutputBlockLoop()
}
func startRemora() {
node := Remora.NewNode(conf)
if err = node.StartP2PListen(); err != nil {
panic(err)
}
// wait for each node to start
time.Sleep(time.Second * 10)
if err = node.EstablishP2PConns(); err != nil {
panic(err)
}
node.InitCBC(conf)
fmt.Println("node starts the Remora!")
go node.RunLoop()
go node.HandleMsgLoop()
go node.RoundProcessLoop()
go node.DoneOutputLoop()
node.CBCOutputBlockLoop()
}
func startRemoraC() {
node := RemoraC.NewNode(conf)
node.InitialRoundProcessChannel()
if err = node.StartP2PListen(); err != nil {
panic(err)
}
// wait for each node to start
time.Sleep(time.Second * 25)
if err = node.EstablishP2PConns(); err != nil {
panic(err)
}
node.InitCBC(conf)
fmt.Println("node starts the RemoraC!")
go node.RunLoop()
go node.HandleMsgLoop()
go node.RoundProcessLoop()
go node.DoneOutputLoop()
node.CBCOutputBlockLoop()
}
func startTusk() {
node := tusk.NewNode(conf)
if err = node.StartP2PListen(); err != nil {
panic(err)
}
// wait for each node to start
time.Sleep(time.Second * 25)
if err = node.EstablishP2PConns(); err != nil {
panic(err)
}
node.InitRBC(conf)
fmt.Println("node starts the Tusk!")
go node.RunLoop()
go node.HandleMsgLoop()
node.ConstructedBlockLoop()
}