-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_router.py
45 lines (33 loc) · 1.21 KB
/
app_router.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
from phy_interface import PhyInterface
from threadpool import * # we'll need thread pool, please easy_install threadpool it.
import os
from app_ip_stack import IPStack
from app_mac_stack import MACStack
from abstracts import AbstractStack
from environment import Environment
POOL_SIZE = 50
class Router(AbstractStack):
"""
Application Router
- Receive packages from tun device
- Substract layer 4 information and forward through TCP connection to relay node
"""
def __init__(self):
AbstractStack.__init__(self)
self.pif = PhyInterface(Environment.default_if) # open main physical interface for injection
# bring_if_up(self.pif.ifname)
self.pool = ThreadPool(POOL_SIZE)
def loop(self):
while True:
data = self.pif.read(1600) # controlled by MTU
# print "data recv from vif:", repr(data)
MACStack(self, data)
# IPStack(self, data) # just create object, it'll do the rest automatically
if __name__=="__main__":
import thread, time
from event import Event
def timeout_loop():
time.sleep(1)
Event.check_timeout()
thread.start_new(timeout_loop, ())
Router().loop()