chiark / gitweb /
fixes
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 23 Mar 2017 19:08:59 +0000 (19:08 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 23 Mar 2017 19:08:59 +0000 (19:08 +0000)
client
fake-userv
hippotat/__init__.py
server

diff --git a/client b/client
index 018da51..afdee9d 100755 (executable)
--- a/client
+++ b/client
@@ -28,7 +28,7 @@ def process_cfg():
     c.url = cfg.get('server','url')
   except NoOptionError:
     process_cfg_saddrs()
-    sa = c.saddrs[0].url()
+    c.url = c.saddrs[0].url()
 
   process_cfg_clients(set_client)
 
@@ -73,27 +73,28 @@ def req_ok(resp):
 def req_err(err):
   print(err, file=sys.stderr)
 
-def req_fin(*args):  
+def req_fin(*args):
+  global outstanding
   outstanding -= 1
 
 def check_outbound():
+  global outstanding
   while True:
     if                          outstanding >= c.max_outstanding   : break
     if not queue.nonempty() and outstanding >= c.target_outstanding: break
 
     d = b''
-    def moredata(s): global d; d += s
+    def moredata(s): nonlocal d; d += s
     queue.process((lambda: len(d)),
                   moredata,
                   c.max_batch_up)
-    assert(len(d))
     
     crlf = b'\r\n'
     mime = (b'--b'                                      + crlf +
             b'Content-Disposition: form-data; name="m"' + crlf +
             password                                    + crlf +
-            c.client                                    + crlf +
-            c.target_outstanding                        + crlf +
+            str(c.client)             .encode('ascii')  + crlf +
+            str(c.target_outstanding) .encode('ascii')  + crlf +
             b'--b'                                      + crlf +
             b'Content-Disposition: form-data; name="d"' + crlf +
             mime_translate(d)                           + crlf +
@@ -104,7 +105,7 @@ def check_outbound():
     req = agent.request(b'POST',
                         c.url,
                         twisted.web.client.Headers(hh))
-    req.addTimeout(c.http_timeout)
+    req.addTimeout(c.http_timeout, reactor)
     req.addCallbacks(req_ok, req_err)
     req.addBoth(req_fin)
     outstanding += 1
index 0796412..24f6aad 100755 (executable)
@@ -5,5 +5,6 @@ exec 3<&0 4>&1 5>&2 >&2 </dev/null
 exec xterm -T netns -e unshare -n -- sh -xc '
   "$@" <&3 >&4 2>&5 &
   sleep 0.1
+  ping 192.0.2.1 &
   env - bash -i
 ' x "$@"
index 67991b0..029b22d 100644 (file)
@@ -18,6 +18,7 @@ from configparser import ConfigParser
 from configparser import NoOptionError
 
 import collections
+import time
 
 import re as regexp
 
@@ -190,7 +191,7 @@ class PacketQueue():
       except IndexError: return False
 
       age = time.monotonic() - queuetime
-      if age > self.max_queue_time:
+      if age > self._max_queue_time:
         # strip old packets off the front
         self._pq.popleft()
         continue
@@ -213,7 +214,7 @@ class PacketQueue():
         moredata(slip.delimiter)
 
       moredata(encoded)
-      self._pq.popLeft()
+      self._pq.popleft()
 
 #---------- error handling ----------
 
@@ -264,17 +265,17 @@ class ServerAddr():
     try:
       self.addr = ipaddress.IPv4Address(addrspec)
       self._endpointfactory = twisted.internet.endpoints.TCP4ServerEndpoint
-      self._inurl = '%s'
+      self._inurl = b'%s'
     except AddressValueError:
       self.addr = ipaddress.IPv6Address(addrspec)
       self._endpointfactory = twisted.internet.endpoints.TCP6ServerEndpoint
-      self._inurl = '[%s]'
+      self._inurl = b'[%s]'
   def make_endpoint(self):
     return self._endpointfactory(reactor, self.port, self.addr)
   def url(self):
-    url = 'http://' + (self._inurl % self.addr)
-    if self.port != 80: url += ':%d' % self.port
-    url += '/'
+    url = b'http://' + (self._inurl % str(self.addr).encode('ascii'))
+    if self.port != 80: url += b':%d' % self.port
+    url += b'/'
     return url
     
 def process_cfg_saddrs():
@@ -292,6 +293,7 @@ def process_cfg_clients(constructor):
     if not (':' in cs or '.' in cs): continue
     ci = ipaddr(cs)
     pw = cfg.get(cs, 'password')
+    pw = pw.encode('utf-8')
     constructor(ci,cs,pw)
 
 #---------- startup ----------
diff --git a/server b/server
index e3e28ce..cb9322b 100755 (executable)
--- a/server
+++ b/server
@@ -18,7 +18,7 @@ clients = { }
 
 def route(packet, saddr, daddr):
   print('TRACE ', saddr, daddr, packet)
-  try: client = clients[daddr]
+  try: dclient = clients[daddr]
   except KeyError: dclient = None
   if dclient is not None:
     dclient.queue_outbound(packet)
@@ -107,7 +107,7 @@ class Client():
                        self.max_batch_down)
 
       assert(request.sentLength)
-      self._rq.popLeft()
+      self._rq.popleft()
       request.finish()
       # round again, looking for more to do