chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 1 Apr 2017 22:01:04 +0000 (23:01 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 1 Apr 2017 22:01:04 +0000 (23:01 +0100)
client
hippotat/__init__.py

diff --git a/client b/client
index b5a4db5..e3fcd0d 100755 (executable)
--- a/client
+++ b/client
@@ -58,12 +58,10 @@ def outbound(packet, saddr, daddr):
   queue.append(packet)
   check_outbound()
 
-def crashy(): assert(False)
-
 class ResponseConsumer(twisted.internet.protocol.Protocol):
   def __init__(self, req):
     self._req = req
-    self._ssd = SlipStreamDecoder(crashy)
+    self._ssd = SlipStreamDecoder('req %s' % id(req), queue_inbound)
     self._log(DBG.HTTP_CTRL, '__init__')
 
   def _log(self, dflag, msg, **kwargs):
index 4cc9e70..ae13eec 100644 (file)
@@ -39,6 +39,7 @@ class DBG(twisted.python.constants.Names):
   QUEUE = NamedConstant()
   QUEUE_CTRL = NamedConstant()
   HTTP_FULL = NamedConstant()
+  SLIP_FULL = NamedConstant()
 
 _hex_codec = codecs.getencoder('hex_codec')
 
@@ -156,32 +157,39 @@ def ipnetwork(input):
 #---------- ipif (SLIP) subprocess ----------
 
 class SlipStreamDecoder():
-  def __init__(self, on_packet):
-    # we will call packet(<packet>)
+  def __init__(self, desc, on_packet):
     self._buffer = b''
     self._on_packet = on_packet
+    self._desc = desc
+    self._log('__init__')
+
+  def _log(self, msg, **kwargs):
+    log_debug(DBG.SLIP_FULL, 'slip '+msg, **kwargs)
 
   def inputdata(self, data):
-    #print('SLIP-GOT ', repr(data))
+    self._log('inputdata', d=data)
     data = self._buffer + data
     self._buffer = b''
     packets = slip.decode(data)
     self._buffer = packets.pop()
     for packet in packets:
       self._maybe_packet(packet)
+    self._log('inputdata bufremain', d=self._buffer)
 
   def _maybe_packet(self, packet):
-      if len(packet):
-        self._on_packet(packet)
+    self._log('inputdata maybepacket', d=packet)
+    if len(packet):
+      self._on_packet(packet)
 
   def flush(self):
+    self._log('inputdata flush')
     self._maybe_packet(self._buffer)
     self._buffer = b''
 
 class _IpifProcessProtocol(twisted.internet.protocol.ProcessProtocol):
   def __init__(self, router):
     self._router = router
-    self._decoder = SlipStreamDecoder(self.slip_on_packet)
+    self._decoder = SlipStreamDecoder('ipif', self.slip_on_packet)
   def connectionMade(self): pass
   def outReceived(self, data):
     self._decoder.inputdata(data)