chiark / gitweb /
reorg SlipStreamDecoder again
[hippotat.git] / server
diff --git a/server b/server
index d36a84e4b7cfe65c0edb8909ae3f096277e15e20..e3e28cebada5e77c3186f47d2a3748fa90f8e1d7 100755 (executable)
--- a/server
+++ b/server
@@ -2,7 +2,6 @@
 
 from hippotat import *
 
 
 from hippotat import *
 
-import sys
 import os
 
 import twisted.internet
 import os
 
 import twisted.internet
@@ -31,11 +30,6 @@ def route(packet, saddr, daddr):
   else:
     log_discard(packet, saddr, daddr, 'no client')
 
   else:
     log_discard(packet, saddr, daddr, 'no client')
 
-def log_discard(packet, saddr, daddr, why):
-  print('DROP ', saddr, daddr, why)
-#  syslog.syslog(syslog.LOG_DEBUG,
-#                'discarded packet %s -> %s (%s)' % (saddr, daddr, why))
-
 #---------- client ----------
 
 class Client():
 #---------- client ----------
 
 class Client():
@@ -108,20 +102,9 @@ class Client():
         break
 
       # request, and also some non-expired packets
         break
 
       # request, and also some non-expired packets
-      while True:
-        packet = self.pq.popleft()
-        if packet is None: break
-
-        encoded = slip.encode(packet)
-        
-        if request.sentLength > 0:
-          if (request.sentLength + len(slip.delimiter)
-              + len(encoded) > self.max_batch_down):
-            break
-          request.write(slip.delimiter)
-
-        request.write(encoded)
-        self._pq.popLeft()
+      self._pq.process((lambda: request.sentLength),
+                       request.write,
+                       self.max_batch_down)
 
       assert(request.sentLength)
       self._rq.popLeft()
 
       assert(request.sentLength)
       self._rq.popLeft()
@@ -136,28 +119,20 @@ class IphttpResource(twisted.web.resource.Resource):
   isLeaf = True
   def render_POST(self, request):
     # find client, update config, etc.
   isLeaf = True
   def render_POST(self, request):
     # find client, update config, etc.
-    ci = ipaddr(request.args['i'])
-    c = clients[ci]
-    pw = request.args['pw']
-    if pw != c.pw: raise ValueError('bad password')
-
-    # update config
-    
-    xxx check sanity, do not update
-    for r, w in (('mbd', 'max_batch_down'),
-                 ('mqt', 'max_queue_time'),
-                 ('mrt', 'max_request_time'),
-                 ('tro', 'target_requests_outstanding')):
-      try: v = request.args[r]
-      except KeyError: continue
-      v = int(v)
-      c.__dict__[w] = v
+    metadata = request.args['m']
+    (ci_s, pw, tro) = metadata.split(b'\n')[0:3]
+    ci = ipaddr(ci_s)
+    cl = clients[ci]
+    if pw != cl.pw: raise ValueError('bad password')
+
+    if pw != cl.target_requests_outstanding:
+      raise ...
 
     try: d = request.args['d']
     except KeyError: d = ''
 
 
     try: d = request.args['d']
     except KeyError: d = ''
 
-    c.process_arriving_data(d)
-    c.new_request(request)
+    cl.process_arriving_data(d)
+    cl.new_request(request)
 
   def render_GET(self, request):
     return b'<html><body>hippotat</body></html>'
 
   def render_GET(self, request):
     return b'<html><body>hippotat</body></html>'
@@ -192,7 +167,7 @@ def process_cfg():
                     ('peer', 'relay'),
                     ('rnets','network')))
 
                     ('peer', 'relay'),
                     ('rnets','network')))
 
-common_startup(defcfg)
+common_startup()
 process_cfg()
 start_ipif(c.ipif_command, route)
 start_http()
 process_cfg()
 start_ipif(c.ipif_command, route)
 start_http()