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 018da51da4bdc4bb77d43b025971e7e62b5a1d86..afdee9dcb7e7c8a8e2f72cfbd1f610687c1a29a9 100755 (executable)
--- a/client
+++ b/client
@@ -28,7 +28,7 @@ def process_cfg():
     c.url = cfg.get('server','url')
   except NoOptionError:
     process_cfg_saddrs()
     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)
 
 
   process_cfg_clients(set_client)
 
@@ -73,27 +73,28 @@ def req_ok(resp):
 def req_err(err):
   print(err, file=sys.stderr)
 
 def req_err(err):
   print(err, file=sys.stderr)
 
-def req_fin(*args):  
+def req_fin(*args):
+  global outstanding
   outstanding -= 1
 
 def check_outbound():
   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''
   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)
     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 +
     
     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 +
             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 = 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
     req.addCallbacks(req_ok, req_err)
     req.addBoth(req_fin)
     outstanding += 1
index 0796412e65ee454ba44e6dd5273f4b5301593f7d..24f6aada7ba7a6fe55cc6376e09f6d2a35bde7d7 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
 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 "$@"
   env - bash -i
 ' x "$@"
index 67991b08e8be31eb04fd7b3375cd73196f176211..029b22d7ddf245dcfa385459fc02a2762fc91cb2 100644 (file)
@@ -18,6 +18,7 @@ from configparser import ConfigParser
 from configparser import NoOptionError
 
 import collections
 from configparser import NoOptionError
 
 import collections
+import time
 
 import re as regexp
 
 
 import re as regexp
 
@@ -190,7 +191,7 @@ class PacketQueue():
       except IndexError: return False
 
       age = time.monotonic() - queuetime
       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
         # strip old packets off the front
         self._pq.popleft()
         continue
@@ -213,7 +214,7 @@ class PacketQueue():
         moredata(slip.delimiter)
 
       moredata(encoded)
         moredata(slip.delimiter)
 
       moredata(encoded)
-      self._pq.popLeft()
+      self._pq.popleft()
 
 #---------- error handling ----------
 
 
 #---------- error handling ----------
 
@@ -264,17 +265,17 @@ class ServerAddr():
     try:
       self.addr = ipaddress.IPv4Address(addrspec)
       self._endpointfactory = twisted.internet.endpoints.TCP4ServerEndpoint
     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
     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):
   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():
     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')
     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 ----------
     constructor(ci,cs,pw)
 
 #---------- startup ----------
diff --git a/server b/server
index e3e28cebada5e77c3186f47d2a3748fa90f8e1d7..cb9322b183f8ce440e29ced72093fc3eab6f2942 100755 (executable)
--- a/server
+++ b/server
@@ -18,7 +18,7 @@ clients = { }
 
 def route(packet, saddr, daddr):
   print('TRACE ', saddr, daddr, packet)
 
 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)
   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.max_batch_down)
 
       assert(request.sentLength)
-      self._rq.popLeft()
+      self._rq.popleft()
       request.finish()
       # round again, looking for more to do
 
       request.finish()
       # round again, looking for more to do