-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonode_client.py
82 lines (55 loc) · 1.7 KB
/
onode_client.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
import sys
import json
import socket
from threading import Thread
from onode import ONode, FLOOD_PORT
from socket import error as SocketError
from routingtable import UpdateStatus
from stream_service.Cliente import Cliente
STREAM = sys.argv[2]
class ONodeClient(ONode):
# Overwrite
def connect_bootstrap(self, *args, **kwargs):
super().connect_bootstrap(*args, **kwargs)
if STREAM not in self.stream_ports:
print(f"Stream ({STREAM}) doesn't exist")
_exit(0)
'''
Flood
'''
# Overwrite
def flood_info(self, info, update_status):
if update_status != UpdateStatus.UPDATED:
return
prev_addr = info['value']['path'][-2] # -1 is this node
self.update_stream_from_node(STREAM, prev_addr, 1)
#Overwrite
def process_flood_info_client(self, *args, **kwargs):
pass
#Overwrite
def process_flood_info_node(self, *args, **kwargs):
pass
#Overwrite
def process_flood_info_server(self, routing_table, info, addr):
if routing_table.stream == STREAM:
super().process_flood_info_server(routing_table, info, addr)
#Overwrite
def pre_flood(self, addr):
self.update_stream_from_node(STREAM, addr, None)
'''
RUN
'''
# Overwrite
def run(self):
routing_table = self.routing_tables[STREAM]
routing_table.add('127.0.0.1')
Thread(target=self.run_stream, args=(routing_table, )).start()
Cliente().main('127.0.0.1', self.stream_ports[STREAM])
def main():
client = ONodeClient()
try:
client.start()
except:
client.stop()
if __name__ == '__main__':
main()