From: Ian Jackson Date: Mon, 3 Apr 2017 11:04:35 +0000 (+0100) Subject: slip fix X-Git-Tag: hippotat/1.0.0~55^2~119 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=hippotat.git;a=commitdiff_plain;h=7fa9c13219dead4880b5912445167efc45d34487 slip fix --- diff --git a/hippotat/__init__.py b/hippotat/__init__.py index cc77cf6..654a5c5 100644 --- a/hippotat/__init__.py +++ b/hippotat/__init__.py @@ -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): diff --git a/hippotat/slip.py b/hippotat/slip.py index f135137..d7c4463 100644 --- a/hippotat/slip.py +++ b/hippotat/slip.py @@ -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 -*- diff --git a/test.cfg b/test.cfg index 9f5f182..d3bdb48 100644 --- 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