chiark
/
gitweb
/
~ian
/
hippotat.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
wip
[hippotat.git]
/
hippotat
/
__init__.py
diff --git
a/hippotat/__init__.py
b/hippotat/__init__.py
index 798f5d2bbce4f3f31a8eef9bbec3a83dcc7e250e..6de4d14c33e659b1bc91daa236ab86096c7b323d 100644
(file)
--- a/
hippotat/__init__.py
+++ b/
hippotat/__init__.py
@@
-23,6
+23,7
@@
from configparser import NoOptionError
import collections
import time
import codecs
import collections
import time
import codecs
+import traceback
import re as regexp
import re as regexp
@@
-38,6
+39,7
@@
class DBG(twisted.python.constants.Names):
QUEUE = NamedConstant()
QUEUE_CTRL = NamedConstant()
HTTP_FULL = NamedConstant()
QUEUE = NamedConstant()
QUEUE_CTRL = NamedConstant()
HTTP_FULL = NamedConstant()
+ SLIP_FULL = NamedConstant()
_hex_codec = codecs.getencoder('hex_codec')
_hex_codec = codecs.getencoder('hex_codec')
@@
-155,31
+157,39
@@
def ipnetwork(input):
#---------- ipif (SLIP) subprocess ----------
class SlipStreamDecoder():
#---------- 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._buffer = b''
self._on_packet = on_packet
+ self._desc = desc
+ self._log('__init__')
+
+ def _log(self, msg, **kwargs):
+ log_debug(DBG.SLIP_FULL, 'slip %s: %s' % (self._desc, msg), **kwargs)
def inputdata(self, data):
def inputdata(self, data):
- #print('SLIP-GOT ', repr(data))
- self._buffer += data
- packets = slip.decode(self._buffer)
+ 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._buffer = packets.pop()
for packet in packets:
self._maybe_packet(packet)
+ self._log('inputdata bufremain', d=self._buffer)
def _maybe_packet(self, packet):
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):
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._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)
def connectionMade(self): pass
def outReceived(self, data):
self._decoder.inputdata(data)