forked from sepehrMSP/Computer-Network-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peer.py
58 lines (50 loc) · 1.75 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from firewall.app.detectors.greet import GreetAppDetector
import socket
import threading
from cli.handlers.advertise import AdvertiseCommandHandler
from cli.handlers.route import RouteCommandHandler
from cli.handlers.app_firewall import AppFirewallCommandHandler
from cli.handlers.connect import ConnectCommandHandler
from cli.handlers.known_clients import KnownClientsCommandHandler
from cli.handlers.net_firewall import NetFirewallCommandHandler
from cli.handlers.app_greeting import AppGreetingCommandHandler
from cli.handlers.start_chat import StartChatCommandHandler
from cli.manager import CommandLineManager
from firewall.app import AppFirewall
from firewall.app.detectors.chat import ChatAppDetector
from firewall.net import NetFirewall
from node import Node
from server import Server
def cli_thread(clm: CommandLineManager):
while True:
clm.handle(input())
def main():
app_firewall = AppFirewall(
detectors=[
ChatAppDetector(),
GreetAppDetector(),
],
)
net_firewall = NetFirewall()
server = Server(daemon=True)
node = Node(
server=server,
net_firewall=net_firewall,
app_firewall=app_firewall,
)
command_handlers = [
NetFirewallCommandHandler(net_firewall),
AppFirewallCommandHandler(app_firewall),
ConnectCommandHandler(node),
AdvertiseCommandHandler(node),
KnownClientsCommandHandler(node),
RouteCommandHandler(node),
AppGreetingCommandHandler(node),
StartChatCommandHandler(node),
]
cl_manager = CommandLineManager(command_handlers)
c_thread = threading.Thread(target=cli_thread, args=(cl_manager,), daemon=True)
c_thread.start()
c_thread.join()
if __name__ == '__main__':
main()