-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
131 lines (94 loc) · 3.94 KB
/
config.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
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
from typing import final, List
from nodes import Node
M: final = 3
PING_TIMEOOUT: final = 4
PING_DURATION: final = 5
CLEANUP_TIME: final = 20
# INTRODUCER_DNS_HOST = '127.0.0.1'
INTRODUCER_DNS_HOST = "fa22-cs425-6901.cs.illinois.edu"
INTRODUCER_DNS_PORT = 8888
# USERNAME = 'meghansh'
USERNAME = "mgoel7"
PASSWORD = None
with open('password.txt') as f:
line = f.readline()
USERNAME = line.split(',')[0].strip()
PASSWORD = line.split(',')[1].strip()
f.close()
# H1: final = Node('127.0.0.1', 8001, USERNAME, PASSWORD, 'H1')
# H2: final = Node('127.0.0.1', 8002, USERNAME, PASSWORD, 'H2')
# H3: final = Node('127.0.0.1', 8003, USERNAME, PASSWORD, 'H3')
# H4: final = Node('127.0.0.1', 8004, USERNAME, PASSWORD, 'H4')
# H5: final = Node('127.0.0.1', 8005, USERNAME, PASSWORD, 'H5')
# H6: final = Node('127.0.0.1', 8006, USERNAME, PASSWORD, 'H6')
# H7: final = Node('127.0.0.1', 8007, USERNAME, PASSWORD, 'H7')
# H8: final = Node('127.0.0.1', 8008, USERNAME, PASSWORD, 'H8')
# H9: final = Node('127.0.0.1', 8009, USERNAME, PASSWORD, 'H9')
# H10: final = Node('127.0.0.1', 8010, USERNAME, PASSWORD, 'H10')
# Global nodes configuration
# ADD new nodes here...
H1: final = Node('fa22-cs425-6901.cs.illinois.edu', 8000,USERNAME, PASSWORD, 'H1')
H2: final = Node('fa22-cs425-6902.cs.illinois.edu', 8000,USERNAME, PASSWORD, 'H2')
H3: final = Node('fa22-cs425-6903.cs.illinois.edu', 8000,USERNAME, PASSWORD, 'H3')
H4: final = Node('fa22-cs425-6904.cs.illinois.edu', 8000,USERNAME, PASSWORD, 'H4')
H5: final = Node('fa22-cs425-6905.cs.illinois.edu', 8000,USERNAME, PASSWORD, 'H5')
H6: final = Node('fa22-cs425-6906.cs.illinois.edu', 8000,USERNAME, PASSWORD, 'H6')
H7: final = Node('fa22-cs425-6907.cs.illinois.edu', 8000,USERNAME, PASSWORD, 'H7')
H8: final = Node('fa22-cs425-6908.cs.illinois.edu', 8000,USERNAME, PASSWORD, 'H8')
H9: final = Node('fa22-cs425-6909.cs.illinois.edu', 8000,USERNAME, PASSWORD, 'H9')
H10: final = Node('fa22-cs425-6910.cs.illinois.edu', 8000,USERNAME, PASSWORD, 'H10')
# Current Ring topology
# Edit the ring as needed
GLOBAL_RING_TOPOLOGY: dict = {
H1: [H2, H10, H5],
H2: [H3, H1, H6],
H3: [H4, H2, H7],
H4: [H5, H3, H8],
H5: [H6, H4, H9],
H6: [H7, H5, H10],
H7: [H8, H6, H1],
H8: [H9, H7, H2],
H9: [H10, H8, H3],
H10: [H1, H9, H4]
}
class Config:
"""
Config class which takes current hostname, port, introducer and testing flags from cmdline args.
"""
def __init__(self, hostname: str, port: int, testing: bool) -> None:
self.node: Node = Config.get_node(hostname, port)
self.ping_nodes: List[Node] = GLOBAL_RING_TOPOLOGY[self.node]
self.introducerDNSNode = Node(INTRODUCER_DNS_HOST, INTRODUCER_DNS_PORT, USERNAME, PASSWORD)
# self.introducerNode = None
# self.introducerFlag = False
# self.introducerNode = Node(introducer.split(
# ":")[0], int(introducer.split(":")[1]))
# if (self.node.unique_name == self.introducerNode.unique_name):
# self.introducerFlag = True
# else:
# self.introducerFlag = False
self.testing = testing
@staticmethod
def get_node(hostname: str, port: int) -> Node:
"""Return class Node which matches hostname and port"""
member = None
for node in GLOBAL_RING_TOPOLOGY.keys():
if node.host == hostname and node.port == port:
member = node
break
return member
@staticmethod
def get_node_from_unique_name(unique_name: str) -> Node:
"""Return class Node which matches unique name"""
member = None
for node in GLOBAL_RING_TOPOLOGY.keys():
if node.unique_name == unique_name:
member = node
break
return member
@staticmethod
def get_node_from_id(id: str):
for node in GLOBAL_RING_TOPOLOGY.keys():
if node.name == id:
return node
return None