-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (39 loc) · 1.07 KB
/
main.py
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
# Press the green button in the gutter to run the script.
import socket
def broadcast(round, v):
pass
class Node(object):
def __init__(self, i, address):
self.i = i
self.address = address
print(i)
address = 12345 + i
print(address)
def initialize_nodes(total_nodes, failed_nodes):
i = 1
nodes = []
starting_port = 12345
while i < total_nodes:
nodes.append(Node(i, starting_port + i))
i = i + 1
return nodes
def connect_nodes(nodes):
s = socket.socket()
n = 5
connections = []
for obj in nodes:
port = obj.address
s.bind(('', port))
s.listen(n)
n = n + 1
if __name__ == '__main__':
# parameters:
total_nodes = 7 # number of processors
failed_nodes = 1 # number of failures
nodes = initialize_nodes(total_nodes, failed_nodes)
connect_nodes(nodes)
round = 1
decided = False
v = True # binary input value (attack or defence in byzantine generals problem)
# while True:
# broadcast(round, v) # notification