chiark / gitweb /
wip debug
[hippotat.git] / hippotat / __init__.py
index 3e8649ae1e122f7b4252ad4dbc4453e54ffca673..e13b31f642429f443da389eb7095e350155d0baa 100644 (file)
@@ -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,28 +32,30 @@ 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()
-  SLIP_FULL = NamedConstant()
   CTRL_DUMP = NamedConstant()
+  SLIP_FULL = NamedConstant()
 
 _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 = '[%#x] %s' % (id(idof), msg)
   if d is not None:
-    d = d[0:64]
+    #d = d[0:64]
     d = _hex_codec(d)[0].decode('ascii')
     msg += ' ' + d
   log.info('{dflag} {msgcore}', dflag=dflag, msgcore=msg)
@@ -61,11 +65,11 @@ defcfg = '''
 #[<client>] 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 [<client>] overrides
@@ -94,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
 '''
 
@@ -169,9 +173,8 @@ class SlipStreamDecoder():
 
   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)
@@ -368,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 ]
     )