-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peer.py
37 lines (31 loc) · 882 Bytes
/
peer.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
import sys
from client import ClientConnection
from server import ServerConnection
import time
class p2p:
peers = ['127.0.0.1'] # Replace 'bootnode_address' with the actual bootnode address
def main():
msg = "test message".encode('utf-8')
bootnode_addr = p2p.peers[0]
local_addr = '127.0.0.1'
try:
print("-" * 21 + "connecting" + "-" * 21)
client = ClientConnection(bootnode_addr)
except KeyboardInterrupt:
sys.exit(0)
except:
pass
try:
server = ServerConnection(local_addr, msg)
server.update_bootnode(bootnode_addr)
except KeyboardInterrupt:
sys.exit()
except:
pass
while True:
try:
time.sleep(1) # Sleep for a second, can be adjusted as needed
except KeyboardInterrupt:
sys.exit()
if __name__ == "__main__":
main()