chiark / gitweb /
fake-userv from secnet abf665fc6ca2974e13acede83e0a77967fdccf9a
[hippotat.git] / client
diff --git a/client b/client
index 39e04c56640e7eeac6a4c0ec01a0310a8f314bd1..c878d724cd243b5ebcaaa73d227f390435f01840 100755 (executable)
--- a/client
+++ b/client
@@ -51,13 +51,26 @@ def outbound(packet, saddr, daddr):
   queue.append(packet)
   check_outbound()
 
-def req_ok(data)
+class ResponseConsumer(twisted.internet.protocol.Protocol):
+  def __init__(self):
+    self._ssd = SlipStreamDecoder(queue_inbound)
+  def dataReceived(self, data):
+    self._ssd.inputdata(mime_translate(data))
+  def connectionMade(self): pass
+  def connectionLost(self, reason):
+    if isinstance(reason, twisted.internet.error.ConnectionDone):
+      self._ssd.flush()
+    else:
+      print(reason, file=sys.stderr)
+
+def req_ok(resp):
+  resp.deliverBody(ResponseConsumer())
 
 def req_err(err):
   print(err, >>sys.stderr)
-  outstanding--
 
 def req_fin(*args):  
+  outstanding--
 
 def check_outbound():
   while True:
@@ -83,7 +96,7 @@ def check_outbound():
 
     hh = { 'User-Agent': ['hippotat'],
            'Content-Type': ['multipart/form-data; boundary="b"'] }
-    req = agent.request('POST',
+    req = agent.request(b'POST',
                         c.url,
                         twisted.web.client.Headers(hh))
     req.addTimeout(c.http_timeout,