X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=hippotat.git;a=blobdiff_plain;f=hippotat%2F__init__.py;h=e13b31f642429f443da389eb7095e350155d0baa;hp=ae13eece753bb87b17131c48a32f3173aabe1ef8;hb=380ed56c213ae7a2aa192904c7c031626fad57c2;hpb=db6ba5840b00c61fe6e576b54179ddeb30202b0e diff --git a/hippotat/__init__.py b/hippotat/__init__.py index ae13eec..e13b31f 100644 --- a/hippotat/__init__.py +++ b/hippotat/__init__.py @@ -20,6 +20,8 @@ from optparse import OptionParser from configparser import ConfigParser from configparser import NoOptionError +from functools import partial + import collections import time import codecs @@ -30,15 +32,17 @@ import re as regexp import hippotat.slip as slip class DBG(twisted.python.constants.Names): + INIT = NamedConstant() ROUTE = NamedConstant() DROP = NamedConstant() FLOW = NamedConstant() HTTP = NamedConstant() - HTTP_CTRL = NamedConstant() - INIT = NamedConstant() + TWISTED = NamedConstant() QUEUE = NamedConstant() + HTTP_CTRL = NamedConstant() QUEUE_CTRL = NamedConstant() HTTP_FULL = NamedConstant() + CTRL_DUMP = NamedConstant() SLIP_FULL = NamedConstant() _hex_codec = codecs.getencoder('hex_codec') @@ -46,9 +50,10 @@ _hex_codec = codecs.getencoder('hex_codec') log = twisted.logger.Logger() def log_debug(dflag, msg, idof=None, d=None): + if dflag > DBG.HTTP: return #print('---------------->',repr((dflag, msg, idof, d)), file=sys.stderr) if idof is not None: - msg = '[%d] %s' % (id(idof), msg) + msg = '[%#x] %s' % (id(idof), msg) if d is not None: #d = d[0:64] d = _hex_codec(d)[0].decode('ascii') @@ -60,11 +65,11 @@ defcfg = ''' #[] overrides max_batch_down = 65536 # used by server, subject to [limits] max_queue_time = 10 # used by server, subject to [limits] -max_request_time = 54 # used by server, subject to [limits] target_requests_outstanding = 3 # must match; subject to [limits] on server +http_timeout = 30 # used by both } must be +http_timeout_grace = 5 # used by both } compatible max_requests_outstanding = 4 # used by client max_batch_up = 4000 # used by client -http_timeout = 30 # used by client http_retry = 5 # used by client #[server] or [] overrides @@ -93,7 +98,7 @@ port = 80 # used by server [limits] max_batch_down = 262144 # used by server max_queue_time = 121 # used by server -max_request_time = 121 # used by server +http_timeout = 121 # used by server target_requests_outstanding = 10 # used by server ''' @@ -164,25 +169,24 @@ class SlipStreamDecoder(): self._log('__init__') def _log(self, msg, **kwargs): - log_debug(DBG.SLIP_FULL, 'slip '+msg, **kwargs) + log_debug(DBG.SLIP_FULL, 'slip %s: %s' % (self._desc, msg), **kwargs) def inputdata(self, data): self._log('inputdata', d=data) - data = self._buffer + data - self._buffer = b'' packets = slip.decode(data) + packets[0] = self._buffer + packets[0] self._buffer = packets.pop() for packet in packets: self._maybe_packet(packet) - self._log('inputdata bufremain', d=self._buffer) + self._log('bufremain', d=self._buffer) def _maybe_packet(self, packet): - self._log('inputdata maybepacket', d=packet) + self._log('maybepacket', d=packet) if len(packet): self._on_packet(packet) def flush(self): - self._log('inputdata flush') + self._log('flush') self._maybe_packet(self._buffer) self._buffer = b'' @@ -285,7 +289,8 @@ _crashing = False def crash(err): global _crashing _crashing = True - print('CRASH ', err, file=sys.stderr) + print('========== CRASH ==========', err, + '===========================', file=sys.stderr) try: reactor.stop() except twisted.internet.error.ReactorNotRunning: pass @@ -366,7 +371,12 @@ def process_cfg_clients(constructor): def common_startup(): log_formatter = twisted.logger.formatEventAsClassicLogText - log_observer = twisted.logger.FileLogObserver(sys.stderr, log_formatter) + stdout_obs = twisted.logger.FileLogObserver(sys.stdout, log_formatter) + stderr_obs = twisted.logger.FileLogObserver(sys.stderr, log_formatter) + pred = twisted.logger.LogLevelFilterPredicate(LogLevel.error) + log_observer = twisted.logger.FilteringLogObserver( + stderr_obs, [pred], stdout_obs + ) twisted.logger.globalLogBeginner.beginLoggingTo( [ log_observer, crash_on_critical ] )