chiark / gitweb /
wip fixes
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Apr 2017 21:16:52 +0000 (22:16 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Apr 2017 21:16:52 +0000 (22:16 +0100)
client
hippotat/__init__.py
server
test.cfg

diff --git a/client b/client
index 6080d4d..074803a 100755 (executable)
--- a/client
+++ b/client
@@ -91,9 +91,9 @@ class Client():
     cl.log(DBG.CTRL_DUMP, 'OS %s' % outstanding)
 
   def start(cl):
-    cl.queue = PacketQueue('up', c.max_queue_time)
+    cl.queue = PacketQueue('up', cl.c.max_queue_time)
     cl.agent = twisted.web.client.Agent(
-      reactor, connectTimeout = c.http_timeout)
+      reactor, connectTimeout = cl.c.http_timeout)
 
   def outbound(cl, packet, saddr, daddr):
     #print('OUT ', saddr, daddr, repr(packet))
@@ -104,13 +104,13 @@ class Client():
     cl.log(DBG.HTTP_CTRL,
             'req_ok %d %s %s' % (resp.code, repr(resp.phrase), str(resp)),
             idof=req)
-  if resp.code == 200:
-    rc = ResponseConsumer(cl, req)
-  else:
-    rc = ErrorResponseConsumer(cl, req, resp)
+    if resp.code == 200:
+      rc = ResponseConsumer(cl, req)
+    else:
+      rc = ErrorResponseConsumer(cl, req, resp)
 
-  resp.deliverBody(rc)
-  # now rc is responsible for calling req_fin
+    resp.deliverBody(rc)
+    # now rc is responsible for calling req_fin
 
   def req_err(cl, req, err):
     # called when the Deferred fails, or (if it completes),
@@ -124,7 +124,7 @@ class Client():
         raise RuntimeError('[%#x] previously %s' % (id(req), outstanding[req]))
       cl.outstanding[req] = err
       cl.log_outstanding()
-      reactor.callLater(c.http_retry, partial(cl.req_fin, req))
+      reactor.callLater(cl.c.http_retry, partial(cl.req_fin, req))
     except Exception as e:
       crash(traceback.format_exc() + '\n----- handling -----\n' + err)
 
@@ -205,7 +205,7 @@ def process_cfg(putative_servers, putative_clients):
     for (ci,cs) in putative_clients.items():
       c = ConfigResults()
 
-      sections = process_cfg_client_common(c,ss,cs,ci):
+      sections = cfg_process_client_common(c,ss,cs,ci)
       if not sections: continue
 
       def srch(getter,key): return cfg_search(getter,key,sections)
@@ -216,13 +216,16 @@ def process_cfg(putative_servers, putative_clients):
       c.http_retry      = srch(cfg.getint, 'http_retry')
       c.vroutes         = srch(cfg.get,    'vroutes')
 
-      process_cfg_common(c,ss)
       try: c.url = srch(cfg.get,'url')
       except NoOptionError:
-        process_cfg_saddrs()
+        cfg_process_saddrs(c, ss)
         c.url = c.saddrs[0].url()
 
-      process_cfg_ipif(cc,
+      c.client = ci
+
+      cfg_process_vaddr(c,ss)
+
+      cfg_process_ipif(c,
                        sections,
                        (('local','client'),
                         ('peer', 'vaddr'),
index 08ae2ff..3617235 100644 (file)
@@ -106,6 +106,7 @@ max_requests_outstanding = 6
 max_batch_up = 4000
 http_retry = 5
 port = 80
+vroutes = ''
 
 #[server] or [<client>] overrides
 ipif = userv root ipif %(local)s,%(peer)s,%(mtu)s,slip %(rnets)s
@@ -119,11 +120,10 @@ server = SERVER
 # url
 
 # relating to virtual network
-routes = ''
-vnetwork = 172.24.230.192
-# network = <prefix>/<len>
-# server  = <ipaddr>
-# relay   = <ipaddr>
+vvnetwork = 172.24.230.192
+# vnetwork = <prefix>/<len>
+# vadd  r  = <ipaddr>
+# vrelay   = <ipaddr>
 
 
 # [<client-ip4-or-ipv6-address>]
@@ -355,7 +355,7 @@ def _cfg_process_putatives():
   serverclient_re = regexp.compile(server_pat + r' ' + client_pat)
 
   for cs in cfg.sections():
-    if cs = 'LIMIT':
+    if cs == 'LIMIT':
       # plan A "[LIMIT]"
       continue
 
@@ -373,7 +373,7 @@ def _cfg_process_putatives():
         # plan D "[<servername> <client>]" part 1
         (pss,pcs) = cs.split(' ')
 
-        if pcs = 'LIMIT':
+        if pcs == 'LIMIT':
           # plan E "[<servername> LIMIT]"
           continue
 
@@ -434,18 +434,18 @@ def cfg_process_vnetwork(c, ss):
   if c.network.num_addresses < 3 + 2:
     raise ValueError('network needs at least 2^3 addresses')
 
-def cfg_process_vaddr():
+def cfg_process_vaddr(c, ss):
   try:
-    c.server = cfg.get('virtual','server')
+    c.vaddr = cfg.get(ss,'server')
   except NoOptionError:
-    process_cfg_network()
-    c.server = next(c.network.hosts())
+    cfg_process_vnetwork(c, ss)
+    c.vaddr = next(c.network.hosts())
 
 def cfg_search_section(key,sections):
   for section in sections:
     if cfg.has_option(section, key):
       return section
-  raise NoOptionError('missing %s %s' % (key, repr(sections)))
+  raise NoOptionError(key, repr(sections))
 
 def cfg_search(getter,key,sections):
   section = cfg_search_section(key,sections)
@@ -453,14 +453,14 @@ def cfg_search(getter,key,sections):
 
 def cfg_process_client_limited(cc,ss,sections,key):
   val = cfg_search(cfg.getint, key, sections)
-  lim = cfg_search(cfg.getint, key, '%s LIMIT' % ss, 'LIMIT')
+  lim = cfg_search(cfg.getint, key, ['%s LIMIT' % ss, 'LIMIT'])
   cc.__dict__[key] = min(val,lim)
 
 def cfg_process_client_common(cc,ss,cs,ci):
   # returns sections to search in, iff password is defined, otherwise None
   cc.ci = ci
 
-  sections = ['%s %s' % section,
+  sections = ['%s %s' % (ss,cs),
               cs,
               ss,
               'DEFAULT']
@@ -476,12 +476,14 @@ def cfg_process_client_common(cc,ss,cs,ci):
 
   return sections
 
-def process_cfg_ipif(c, sections, varmap):
+def cfg_process_ipif(c, sections, varmap):
   for d, s in varmap:
     try: v = getattr(c, s)
     except AttributeError: continue
     setattr(c, d, v)
 
+  print('CFGIPIF',repr((varmap, sections, c.__dict__)),file=sys.stderr)
+
   section = cfg_search_section('ipif', sections)
   c.ipif_command = cfg.get(section,'ipif', vars=c.__dict__)
 
@@ -602,7 +604,7 @@ just `+': all DFLAGs.
     readconfig('/etc/hippotat/config.d', False)
 
   try:
-    (pss, pcs) = process_cfg_putatives()
+    (pss, pcs) = _cfg_process_putatives()
     process_cfg(pss, pcs)
   except (configparser.Error, ValueError):
     traceback.print_exc(file=sys.stderr)
diff --git a/server b/server
index 144866f..52d83b5 100755 (executable)
--- a/server
+++ b/server
@@ -24,7 +24,7 @@ def route(packet, iface, saddr, daddr):
   if dclient is not None:
     lt('client')
     dclient.queue_outbound(packet)
-  elif daddr == c.server or daddr not in c.network:
+  elif daddr == c.vaddr or daddr not in c.vnetwork:
     lt('inbound')
     queue_inbound(packet)
   elif daddr == relay:
@@ -37,11 +37,10 @@ def route(packet, iface, saddr, daddr):
 #---------- client ----------
 
 class Client():
-  def __init__(self, ip, cs, pw):
+  def __init__(self, ip, cc):
     # instance data members
     self._ip = ip
-    self._cs = cs
-    self.pw = pw
+    self.cc = cc
     self._rq = collections.deque() # requests
     # self._pq = PacketQueue(...)
     # plus from config:
@@ -49,17 +48,9 @@ class Client():
     #  .max_queue_time
     #  .target_requests_outstanding
 
-    if ip not in c.network:
+    if ip not in c.vnetwork:
       raise ValueError('client %s not in network' % ip)
 
-    for k in ('max_batch_down',
-              'max_queue_time',
-              'http_timeout',
-              'target_requests_outstanding'):
-      req = cfg.getint(cs, k)
-      limit = cfg.getint('limits',k)
-      self.__dict__[k] = min(req, limit)
-
     self._pq = PacketQueue(str(ip), self.max_queue_time)
 
     if ip in clients:
@@ -223,13 +214,14 @@ def start_http():
 #---------- config and setup ----------
         
 def process_cfg(putative_servers, putative_clients):
+  global c
   c = ConfigResults()
   c.server = cfg.get('SERVER','server')
 
-  process_cfg_common(c, c.server)
-  process_cfg_saddrs(c, c.server)
-  process_cfg_vnetwork(c, c.server)
-  process_cfg_vaddr(c, c.server)
+  cfg_process_common(c, c.server)
+  cfg_process_saddrs(c, c.server)
+  cfg_process_vnetwork(c, c.server)
+  cfg_process_vaddr(c, c.server)
 
   for (ci,cs) in putative_clients.items():
     cc = ConfigResults()
@@ -237,16 +229,17 @@ def process_cfg(putative_servers, putative_clients):
     if not sections: continue
     cfg_process_client_limited(cc,c.server,sections, 'max_batch_down')
     cfg_process_client_limited(cc,c.server,sections, 'max_queue_time')
+    Client(ci)
 
   try:
     c.relay = cfg.get(c.server, 'relay')
   except NoOptionError:
-    for search in c.network.hosts():
-      if search == c.server: continue
+    for search in c.vnetwork.hosts():
+      if search == c.vaddr: continue
       c.relay = search
       break
 
-  process_cfg_ipif(c,
+  cfg_process_ipif(c,
                    [c.server, 'DEFAULT'],
                    (('local','vaddr'),
                     ('peer', 'vrelay'),
index 0c2ebbe..d858da7 100644 (file)
--- a/test.cfg
+++ b/test.cfg
@@ -1,15 +1,13 @@
-[DEFAULT]
+[SERVER]
+
 ipif = PATH=/usr/local/sbin:/sbin:/usr/sbin:$PATH really /home/ian/things/Userv/userv-utils.git/ipif/service \* -- %(local)s,%(peer)s,%(mtu)s,slip '%(rnets)s'
 
-[server]
 addrs = 127.0.0.1
 port = 8099
+vnetwork = 192.0.2.0/24
 
 # ./server --debug-select=+ -c test.cfg
 
-[virtual]
-network = 192.0.2.0/24
-
 [192.0.2.3]
 password = sesame