-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
81 lines (69 loc) · 1.55 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
package main
import (
"SSBFT/app"
"SSBFT/app/messenger"
"SSBFT/config"
"SSBFT/logger"
"SSBFT/variables"
"log"
"os"
"os/signal"
"strconv"
)
func Initialise(id int, n int, t int, k int, scenario config.Scenario) {
variables.Initialise(id, n, t, k)
config.InitialiseLocal(n)
config.InitialiseIp(n)
config.InitialiseScenario(scenario)
logger.InitialiseLogger()
logger.OutLogger.Println(
"N", variables.N,
"ID", variables.Id,
"F", variables.F,
"Threshold T", variables.T,
"Client Size", variables.K,
)
messenger.InitialiseMessenger()
app.InitializeAutomaton()
app.InitializeViewChange()
app.InitializeFailureDetector()
app.InitializeEstablishment()
app.InitializeReplication()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
for i := 0; i < n; i++ {
if i == id {
continue
}
messenger.RcvSockets[i].Close()
messenger.SndSockets[i].Close()
}
os.Exit(0)
}
}()
}
func main() {
done := make(chan interface{})
args := os.Args[1:]
if len(args) < 5 {
log.Fatal("Arguments should be 'ssbft <id> <n> <f> <k> <scenario>")
}
id, _ := strconv.Atoi(args[0])
n, _ := strconv.Atoi(args[1])
t, _ := strconv.Atoi(args[2])
k, _ := strconv.Atoi(args[3])
tmp, _ := strconv.Atoi(args[4])
scenario := config.Scenario(tmp)
Initialise(id, n, t, k, scenario)
messenger.Subscribe()
if config.TestCase != config.NON_SS {
go app.FailDetector()
go app.ViewChangeMonitor()
go app.CoordinatingAutomaton()
}
go messenger.TransmitMessages()
go app.ByzantineReplication()
_ = <-done
}