-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
120 lines (101 loc) · 3.36 KB
/
Copy pathmain.go
File metadata and controls
120 lines (101 loc) · 3.36 KB
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
package main
import (
"log"
"os"
"os/signal"
"self-stabilizing-binary-consensus/config"
"self-stabilizing-binary-consensus/logger"
"self-stabilizing-binary-consensus/messenger"
"self-stabilizing-binary-consensus/modules"
"self-stabilizing-binary-consensus/threshenc"
"self-stabilizing-binary-consensus/variables"
"strconv"
"syscall"
)
func cleanup() {
terminate := make(chan os.Signal, 1)
signal.Notify(terminate,
os.Interrupt,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
for range terminate {
for i := 0; i < variables.N; i++ {
if i == variables.ID {
continue // Not myself
}
messenger.ReceiveSockets[i].Close()
messenger.SendSockets[i].Close()
}
for i := 0; i < variables.Clients; i++ {
messenger.ServerSockets[i].Close()
messenger.ResponseSockets[i].Close()
}
os.Exit(0)
}
}()
}
// Initializer - Method that initializes all required processes
func initializer(id int, n int, m int, clients int, remote int, byzantine_scenario int, self_stabilizing int, corruption int,
debug int, optimization int) {
variables.Initialize(id, n, m, clients, remote, debug, optimization)
logger.InitializeLogger("./logs/out/", "./logs/error/")
config.InitializeByzantineScenario(byzantine_scenario)
config.InitializeCorruptionScenario(corruption)
if variables.Remote {
config.InitializeIP()
} else {
config.InitializeLocal()
}
logger.OutLogger.Print(
"ID:", variables.ID, " | N:", variables.N, " | F:", variables.F, " | M:", variables.M, " | Clients:",
variables.Clients, " | Byzantine scenario:", config.ByzantineScenario, " | Byzantine processor:", variables.Byzantine,
" | Self-Stabilization:", self_stabilizing == 1, " | Corruption scenario:", config.CorruptionScenario, " | Remote:",
variables.Remote, " | Debug:", variables.Debug, " | Optimization:", variables.Optimization, "\n\n",
)
threshenc.ReadKeys("./keys/")
messenger.InitializeMessenger()
messenger.Subscribe()
// IDLE Attack Scenario
if (config.ByzantineScenario == "IDLE") && (variables.Byzantine) {
logger.OutLogger.Println("IDLE ATTACK")
return
}
messenger.TransmitMessages()
cleanup()
}
func main() {
args := os.Args[1:]
if len(args) == 2 && string(args[0]) == "generate_keys" {
N, _ := strconv.Atoi(args[1])
threshenc.GenerateKeys(N, "./keys/")
} else if len(args) == 11 {
id, _ := strconv.Atoi(args[0])
n, _ := strconv.Atoi(args[1])
m, _ := strconv.Atoi(args[2])
clients, _ := strconv.Atoi(args[3])
remote, _ := strconv.Atoi(args[4])
byzantine_scenario, _ := strconv.Atoi(args[5])
self_stabilizing, _ := strconv.Atoi(args[6])
corruption, _ := strconv.Atoi(args[7])
debug, _ := strconv.Atoi(args[8])
optimization, _ := strconv.Atoi(args[9])
init_value, _ := strconv.Atoi(args[10])
initializer(id, n, m, clients, remote, byzantine_scenario, self_stabilizing, corruption, debug, optimization)
if variables.Debug {
logger.OutLogger.Print("Initial estimate value:", init_value, "\n\n")
}
if self_stabilizing == 0 {
modules.BinaryConsensus(1, uint(init_value))
} else {
modules.SelfStabilizingBinaryConsensus(1, int(init_value))
}
done := make(chan interface{}) // To keep the server running
<-done
} else {
log.Fatal("go run main.go <ID> <N> <M> <Clients> <Remote> <Byzantine scenario> <Self-Stabilizing> " +
"<Corruption> <Debug> <Optimization> <Initial value>")
}
}