chiark / gitweb /
slip fix
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 Apr 2017 11:04:35 +0000 (12:04 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 Apr 2017 11:04:35 +0000 (12:04 +0100)
hippotat/__init__.py
hippotat/slip.py
test.cfg

index cc77cf6..654a5c5 100644 (file)
@@ -206,8 +206,9 @@ class SlipStreamDecoder():
 
   def inputdata(self, data):
     self._log('inputdata', d=data)
-    packets = slip.decode(data)
-    packets[0] = self._buffer + packets[0]
+    data = self._buffer + data
+    self._buffer = b''
+    packets = slip.decode(data, True)
     self._buffer = packets.pop()
     for packet in packets:
       self._maybe_packet(packet)
@@ -220,8 +221,11 @@ class SlipStreamDecoder():
 
   def flush(self):
     self._log('flush')
-    self._maybe_packet(self._buffer)
+    data = self._buffer
     self._buffer = b''
+    packets = slip.decode(data)
+    assert(len(packets) == 1)
+    self._maybe_packet(packets[0])
 
 class _IpifProcessProtocol(twisted.internet.protocol.ProcessProtocol):
   def __init__(self, router):
index f135137..d7c4463 100644 (file)
@@ -11,10 +11,14 @@ def encode(packet):
           .replace(esc, esc + esc_esc)
           .replace(end, esc + esc_end))
 
-def decode(data):
+def decode(data, keep_tail=False):
   #print('DECODE ', repr(data))
   out = []
-  for packet in data.split(end):
+  inp = data.split(end)
+  tail = []
+  if keep_tail:
+    tail.append(inp.pop())
+  for packet in inp:
     pdata = b''
     while True:
       eix = packet.find(esc)
@@ -31,6 +35,7 @@ def decode(data):
       packet = packet[eix+2 : ]
     out.append(pdata)
   #print('DECODED ', repr(out))
+  out += tail
   return out
 # -*- python -*-
 
index 9f5f182..d3bdb48 100644 (file)
--- a/test.cfg
+++ b/test.cfg
@@ -18,3 +18,5 @@ ipif = PATH=/usr/local/sbin:/sbin:/usr/sbin:$PATH really ./fake-userv /home/ian/
 
 [192.0.2.4]
 #password = zorkmids
+
+# dd if=/dev/zero bs=1024 count=1024 | nc -n -v 192.0.2.1 8100