chiark / gitweb /
wip, before optional args log_xxx
[hippotat.git] / hippotat / __init__.py
index 67991b08e8be31eb04fd7b3375cd73196f176211..abc2a9fd687129eecd9732e258ac68168ed24711 100644 (file)
@@ -18,11 +18,23 @@ from configparser import ConfigParser
 from configparser import NoOptionError
 
 import collections
 from configparser import NoOptionError
 
 import collections
+import time
 
 import re as regexp
 
 
 import re as regexp
 
+from twisted.python.constants import NamedConstant
+
 import hippotat.slip as slip
 
 import hippotat.slip as slip
 
+class DBG(twisted.python.constants.Names):
+  ROUTE = NamedConstant()
+  FLOW = NamedConstant()
+  HTTP = NamedConstant()
+  HTTP_CTRL = NamedConstant()
+  INIT = NamedConstant()
+  QUEUE = NamedConstant()
+  QUEUE_CTRL = NamedConstant()
+
 defcfg = '''
 [DEFAULT]
 #[<client>] overrides
 defcfg = '''
 [DEFAULT]
 #[<client>] overrides
@@ -33,6 +45,7 @@ target_requests_outstanding = 3  # must match; subject to [limits] on server
 max_requests_outstanding = 4     # used by client
 max_batch_up = 4000              # used by client
 http_timeout = 30                # used by client
 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
 ipif = userv root ipif %(local)s,%(peer)s,%(mtu)s,slip %(rnets)s
 
 #[server] or [<client>] overrides
 ipif = userv root ipif %(local)s,%(peer)s,%(mtu)s,slip %(rnets)s
@@ -177,20 +190,26 @@ def queue_inbound(packet):
 #---------- packet queue ----------
 
 class PacketQueue():
 #---------- packet queue ----------
 
 class PacketQueue():
-  def __init__(self, max_queue_time):
+  def __init__(self, desc, max_queue_time):
+    self._desc = desc
     self._max_queue_time = max_queue_time
     self._pq = collections.deque() # packets
 
     self._max_queue_time = max_queue_time
     self._pq = collections.deque() # packets
 
+  def _log_debug(self, fn, pri, msg)
+    log_debug(pri, 
+
   def append(self, packet):
   def append(self, packet):
+    log_data(DBG.QUEUE, packet, 'pq %s: append' % self._desc)
     self._pq.append((time.monotonic(), packet))
 
   def nonempty(self):
     self._pq.append((time.monotonic(), packet))
 
   def nonempty(self):
+    log_debug(DBG.QUEUE, 'pq %s: nonempty ?' % self._desc)
     while True:
       try: (queuetime, packet) = self._pq[0]
       except IndexError: return False
 
       age = time.monotonic() - queuetime
     while True:
       try: (queuetime, packet) = self._pq[0]
       except IndexError: return False
 
       age = time.monotonic() - queuetime
-      if age > self.max_queue_time:
+      if age > self._max_queue_time:
         # strip old packets off the front
         self._pq.popleft()
         continue
         # strip old packets off the front
         self._pq.popleft()
         continue
@@ -213,7 +232,7 @@ class PacketQueue():
         moredata(slip.delimiter)
 
       moredata(encoded)
         moredata(slip.delimiter)
 
       moredata(encoded)
-      self._pq.popLeft()
+      self._pq.popleft()
 
 #---------- error handling ----------
 
 
 #---------- error handling ----------
 
@@ -264,17 +283,17 @@ class ServerAddr():
     try:
       self.addr = ipaddress.IPv4Address(addrspec)
       self._endpointfactory = twisted.internet.endpoints.TCP4ServerEndpoint
     try:
       self.addr = ipaddress.IPv4Address(addrspec)
       self._endpointfactory = twisted.internet.endpoints.TCP4ServerEndpoint
-      self._inurl = '%s'
+      self._inurl = b'%s'
     except AddressValueError:
       self.addr = ipaddress.IPv6Address(addrspec)
       self._endpointfactory = twisted.internet.endpoints.TCP6ServerEndpoint
     except AddressValueError:
       self.addr = ipaddress.IPv6Address(addrspec)
       self._endpointfactory = twisted.internet.endpoints.TCP6ServerEndpoint
-      self._inurl = '[%s]'
+      self._inurl = b'[%s]'
   def make_endpoint(self):
     return self._endpointfactory(reactor, self.port, self.addr)
   def url(self):
   def make_endpoint(self):
     return self._endpointfactory(reactor, self.port, self.addr)
   def url(self):
-    url = 'http://' + (self._inurl % self.addr)
-    if self.port != 80: url += ':%d' % self.port
-    url += '/'
+    url = b'http://' + (self._inurl % str(self.addr).encode('ascii'))
+    if self.port != 80: url += b':%d' % self.port
+    url += b'/'
     return url
     
 def process_cfg_saddrs():
     return url
     
 def process_cfg_saddrs():
@@ -292,6 +311,7 @@ def process_cfg_clients(constructor):
     if not (':' in cs or '.' in cs): continue
     ci = ipaddr(cs)
     pw = cfg.get(cs, 'password')
     if not (':' in cs or '.' in cs): continue
     ci = ipaddr(cs)
     pw = cfg.get(cs, 'password')
+    pw = pw.encode('utf-8')
     constructor(ci,cs,pw)
 
 #---------- startup ----------
     constructor(ci,cs,pw)
 
 #---------- startup ----------