chiark / gitweb /
7684cf33b682dad6212861880aa52df1bab245ac
[hippotat.git] / client
1 #!/usr/bin/python3
2
3 from hippotat import *
4
5 defcfg = '''
6 [DEFAULT]
7 max_requests_outstanding = 4
8
9 [virtual]
10 mtu = 1500
11 # [server]  # maybe computed from `network' (see server defaults)
12 # [routes]  # default is none
13
14 [server]
15 # url     # maybe computed from `addrs' and `port' (see server defaults)
16
17 # [<my ip address>]
18 # password = <password>
19 '''
20
21 client_cs = None
22
23 def set_client(ci,cs,pw):
24   global client_cs
25   global password
26   assert(client_cs is None)
27   client_cs = cs
28   c.client = ci
29   c.max_outstanding = cfg.getint(cs, 'max_requests_outstanding')
30   password = pw
31
32 def process_cfg():
33   global url
34   global max_requests_outstanding
35
36   process_cfg_common_always()
37   process_cfg_server()
38
39   try:
40     c.url = cfg.get('server','url')
41   except NoOptionError:
42     process_cfg_saddrs()
43     sa = c.saddrs[0].url()
44
45   process_cfg_clients(set_client)
46
47   try:
48     c.routes = cfg.get('virtual','routes')
49   except NoOptionError:
50     c.routes = ''
51
52   process_cfg_ipif(client_cs,
53                    (('local', 'client'),
54                     ('peer',  'server'),
55                     ('rnets', 'routes')))
56
57 def outbound(packet, saddr, daddr):
58   print('OUT ', saddr, daddr, repr(packet))
59   pass
60
61 common_startup(defcfg)
62 process_cfg()
63 start_ipif(c.ipif_command, outbound)
64 common_run()