From 74934d63b06bf4fc045ac9aabac381cedfe9f10f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 2 Apr 2017 22:53:41 +0100 Subject: [PATCH] wip fixes --- README.config | 2 +- client | 10 +++++----- hippotat/__init__.py | 2 +- server | 34 ++++++++++++++-------------------- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/README.config b/README.config index fc2922f..04d94ca 100644 --- a/README.config +++ b/README.config @@ -114,7 +114,7 @@ Ordinary settings, used by both, not client-specific: On client: used only to construct default url. mtu - Must match exactly. (checked) [1500 bytes] + Must match exactly. (UNCHECKED) [1500 bytes] Ordinary settings, used by client only: diff --git a/client b/client index e9bce7c..f26d46b 100755 --- a/client +++ b/client @@ -14,7 +14,7 @@ class GeneralResponseConsumer(twisted.internet.protocol.Protocol): self._desc = desc def _log(self, dflag, msg, **kwargs): - self.cl.log(dflag, '%s: %s' % (self._desc, msg), idof=self._req, **kwargs) + self._cl.log(dflag, '%s: %s' % (self._desc, msg), idof=self._req, **kwargs) def connectionMade(self): self._log(DBG.HTTP_CTRL, 'connectionMade') @@ -42,7 +42,7 @@ class ResponseConsumer(GeneralResponseConsumer): try: self._log(DBG.HTTP, 'ResponseDone') self._ssd.flush() - self.cl.req_fin(self._req) + self._cl.req_fin(self._req) except Exception as e: self._handleexception() if not self._success_reported: @@ -54,9 +54,9 @@ class ResponseConsumer(GeneralResponseConsumer): def _latefailure(self, reason): self._log(DBG.HTTP_CTRL, '_latefailure ' + str(reason)) - self.cl.req_err(self._req, reason) + self._cl.req_err(self._req, reason) -class ErrorResponseConsumer(twisted.internet.protocol.Protocol): +class ErrorResponseConsumer(GeneralResponseConsumer): def __init__(self, cl, req, resp): super().__init__(cl, req, 'ERROR-RC') self._resp = resp @@ -78,7 +78,7 @@ class ErrorResponseConsumer(twisted.internet.protocol.Protocol): mbody = repr(self._m) if not reason.check(twisted.web.client.ResponseDone): mbody += ' || ' + str(reason) - self.cl.req_err(self._req, + self._cl.req_err(self._req, "FAILED %d %s | %s" % (self._resp.code, self._phrase, mbody)) diff --git a/hippotat/__init__.py b/hippotat/__init__.py index 8a21966..9f72b48 100644 --- a/hippotat/__init__.py +++ b/hippotat/__init__.py @@ -400,7 +400,7 @@ def _cfg_process_putatives(): return (servers, clients) -def cfg_process_common(ss): +def cfg_process_common(c, ss): c.mtu = cfg.getint(ss, 'mtu') def cfg_process_saddrs(c, ss): diff --git a/server b/server index 5bce0f3..9772679 100755 --- a/server +++ b/server @@ -27,7 +27,7 @@ def route(packet, iface, saddr, daddr): elif daddr == c.vaddr or daddr not in c.vnetwork: lt('inbound') queue_inbound(packet) - elif daddr == relay: + elif daddr == c.relay: lt('discard relay') log_discard(packet, iface, saddr, daddr, 'relay') else: @@ -42,17 +42,11 @@ class Client(): self._ip = ip self.cc = cc self._rq = collections.deque() # requests - # self._pq = PacketQueue(...) - # plus from config: - # .max_batch_down - # .max_queue_time - # .target_requests_outstanding + self._pq = PacketQueue(str(ip), self.cc.max_queue_time) if ip not in c.vnetwork: raise ValueError('client %s not in vnetwork' % ip) - self._pq = PacketQueue(str(ip), self.max_queue_time) - if ip in clients: raise ValueError('multiple client cfg sections for %s' % ip) clients[ip] = self @@ -90,7 +84,7 @@ class Client(): def new_request(self, request): request.setHeader('Content-Type','application/octet-stream') - cl = reactor.callLater(self.http_timeout, self._req_cancel, request) + cl = reactor.callLater(self.cc.http_timeout, self._req_cancel, request) nf = request.notifyFinish() nf.addErrback(self._req_error, request) nf.addCallback(self._req_fin, request, cl) @@ -125,7 +119,7 @@ class Client(): # request, and also some non-expired packets self._pq.process((lambda: request.sentLength), (lambda d: self._req_write(request, d)), - self.max_batch_down) + self.cc.max_batch_down) assert(request.sentLength) self._rq.popleft() @@ -133,7 +127,7 @@ class Client(): self._log(DBG.HTTP, 'complete', idof=request) # round again, looking for more to do - while len(self._rq) > self.target_requests_outstanding: + while len(self._rq) > self.cc.target_requests_outstanding: request = self._rq.popleft() self._log(DBG.HTTP, 'CHKO above target, returning empty', idof=request) request.finish() @@ -150,14 +144,14 @@ def process_request(request, desca): ci = ipaddr(ci_s) desca['ci'] = ci cl = clients[ci] - if pw != cl.pw: raise ValueError('bad password') + if pw != cl.cc.password: raise ValueError('bad password') desca['pwok']=True - if tro != cl.target_requests_outstanding: - raise ValueError('tro must be %d' % cl.target_requests_outstanding) + if tro != cl.cc.target_requests_outstanding: + raise ValueError('tro must be %d' % cl.cc.target_requests_outstanding) - if cto < cl.http_timeout: - raise ValueError('cto must be >= %d' % cl.http_timeout) + if cto < cl.cc.http_timeout: + raise ValueError('cto must be >= %d' % cl.cc.http_timeout) try: d = request.args[b'd'][0] @@ -225,18 +219,18 @@ def process_cfg(putative_servers, putative_clients): for (ci,cs) in putative_clients.items(): cc = ConfigResults() - sections = cfg_process_client_common(cc,c.server,cs,ci): + sections = cfg_process_client_common(cc,c.server,cs,ci) if not sections: continue cfg_process_client_limited(cc,c.server,sections, 'max_batch_down') cfg_process_client_limited(cc,c.server,sections, 'max_queue_time') - Client(ci) + Client(ci, cc) try: - c.relay = cfg.get(c.server, 'relay') + c.vrelay = cfg.get(c.server, 'vrelay') except NoOptionError: for search in c.vnetwork.hosts(): if search == c.vaddr: continue - c.relay = search + c.vrelay = search break cfg_process_ipif(c, -- 2.30.2