chiark / gitweb /
fixes
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Apr 2017 00:34:10 +0000 (01:34 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Apr 2017 00:34:10 +0000 (01:34 +0100)
client
hippotat/__init__.py
server

diff --git a/client b/client
index 83dfd66..a5edd7e 100755 (executable)
--- a/client
+++ b/client
@@ -37,8 +37,9 @@ def process_cfg():
   c.routes = cfg.get('virtual','routes')
   c.max_queue_time = cfg.getint(client_cs, 'max_queue_time')
   c.max_batch_up   = cfg.getint(client_cs, 'max_batch_up')
   c.routes = cfg.get('virtual','routes')
   c.max_queue_time = cfg.getint(client_cs, 'max_queue_time')
   c.max_batch_up   = cfg.getint(client_cs, 'max_batch_up')
-  c.http_timeout   = cfg.getint(client_cs, 'http_timeout')
   c.http_retry     = cfg.getint(client_cs, 'http_retry')
   c.http_retry     = cfg.getint(client_cs, 'http_retry')
+  c.http_timeout = (cfg.getint(client_cs, 'http_timeout') +
+                    cfg.getint(client_cs, 'http_timeout_grace'))
 
   process_cfg_ipif(client_cs,
                    (('local', 'client'),
 
   process_cfg_ipif(client_cs,
                    (('local', 'client'),
@@ -192,6 +193,7 @@ def check_outbound():
             str(c.client)             .encode('ascii')    + crlf +
             password                                      + crlf +
             str(c.target_outstanding) .encode('ascii')    + crlf +
             str(c.client)             .encode('ascii')    + crlf +
             password                                      + crlf +
             str(c.target_outstanding) .encode('ascii')    + crlf +
+            str(c.http_timeout)       .encode('ascii')    + crlf +
           ((
             b'--b'                                        + crlf +
             b'Content-Type: application/octet-stream'     + crlf +
           ((
             b'--b'                                        + crlf +
             b'Content-Type: application/octet-stream'     + crlf +
index 5d5129a..1e8a23f 100644 (file)
@@ -53,7 +53,7 @@ def log_debug(dflag, msg, idof=None, d=None):
   if idof is not None:
     msg = '[%#x] %s' % (id(idof), msg)
   if d is not None:
   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)
     d = _hex_codec(d)[0].decode('ascii')
     msg += ' ' + d
   log.info('{dflag} {msgcore}', dflag=dflag, msgcore=msg)
@@ -63,11 +63,11 @@ defcfg = '''
 #[<client>] overrides
 max_batch_down = 65536           # used by server, subject to [limits]
 max_queue_time = 10              # used by server, subject to [limits]
 #[<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
 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
 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
 http_retry = 5                   # used by client
 
 #[server] or [<client>] overrides
@@ -96,7 +96,7 @@ port = 80                  # used by server
 [limits]
 max_batch_down = 262144           # used by server
 max_queue_time = 121              # 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
 '''
 
 target_requests_outstanding = 10  # used by server
 '''
 
@@ -171,9 +171,8 @@ class SlipStreamDecoder():
 
   def inputdata(self, data):
     self._log('inputdata', d=data)
 
   def inputdata(self, data):
     self._log('inputdata', d=data)
-    data = self._buffer + data
-    self._buffer = b''
     packets = slip.decode(data)
     packets = slip.decode(data)
+    packets[0] = self._buffer + packets[0]
     self._buffer = packets.pop()
     for packet in packets:
       self._maybe_packet(packet)
     self._buffer = packets.pop()
     for packet in packets:
       self._maybe_packet(packet)
diff --git a/server b/server
index 8a16c34..3781d56 100755 (executable)
--- a/server
+++ b/server
@@ -47,13 +47,12 @@ class Client():
     # plus from config:
     #  .max_batch_down
     #  .max_queue_time
     # plus from config:
     #  .max_batch_down
     #  .max_queue_time
-    #  .max_request_time
     #  .target_requests_outstanding
 
     if ip not in c.network:
       raise ValueError('client %s not in network' % ip)
 
     #  .target_requests_outstanding
 
     if ip not in c.network:
       raise ValueError('client %s not in network' % ip)
 
-    for k in ('max_batch_down','max_queue_time','max_request_time',
+    for k in ('max_batch_down','max_queue_time','http_timeout',
               'target_requests_outstanding'):
       req = cfg.getint(cs, k)
       limit = cfg.getint('limits',k)
               'target_requests_outstanding'):
       req = cfg.getint(cs, k)
       limit = cfg.getint('limits',k)
@@ -93,7 +92,7 @@ class Client():
 
   def new_request(self, request):
     request.setHeader('Content-Type','application/octet-stream')
 
   def new_request(self, request):
     request.setHeader('Content-Type','application/octet-stream')
-    reactor.callLater(self.max_request_time, self._req_cancel, request)
+    reactor.callLater(self.http_timeout, self._req_cancel, request)
     request.notifyFinish().addErrback(self._req_error, request)
     self._rq.append(request)
     self._check_outbound()
     request.notifyFinish().addErrback(self._req_error, request)
     self._rq.append(request)
     self._check_outbound()
@@ -143,11 +142,11 @@ def process_request(request, desca):
   # find client, update config, etc.
   metadata = request.args[b'm'][0]
   metadata = metadata.split(b'\r\n')
   # find client, update config, etc.
   metadata = request.args[b'm'][0]
   metadata = metadata.split(b'\r\n')
-  (ci_s, pw, tro) = metadata[0:3]
-  desca['m[0,2]'] = [ci_s, tro]
+  (ci_s, pw, tro, cto) = metadata[0:4]
+  desca['m[0,2:3]'] = [ci_s, tro, cto]
   ci_s = ci_s.decode('utf-8')
   ci_s = ci_s.decode('utf-8')
-  tro = int(tro)
-  desca['tro']= tro
+  tro = int(tro); desca['tro']= tro
+  cto = int(cto); desca['cto']= cto
   ci = ipaddr(ci_s)
   desca['ci'] = ci
   cl = clients[ci]
   ci = ipaddr(ci_s)
   desca['ci'] = ci
   cl = clients[ci]
@@ -157,6 +156,9 @@ def process_request(request, desca):
   if tro != cl.target_requests_outstanding:
     raise ValueError('tro must be %d' % cl.target_requests_outstanding)
 
   if tro != cl.target_requests_outstanding:
     raise ValueError('tro must be %d' % cl.target_requests_outstanding)
 
+  if cto < cl.http_timeout:
+    raise ValueError('cto must be >= %d' % cl.http_timeout)
+
   try:
     d = request.args[b'd'][0]
     desca['d'] = d
   try:
     d = request.args[b'd'][0]
     desca['d'] = d