From 909e0ff30ecd0e3fe26f58189df9d174a48b7d32 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 2 Apr 2017 23:06:08 +0100 Subject: [PATCH] wip --- client | 20 +++++++++++++------- hippotat/__init__.py | 4 ++-- server | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/client b/client index f26d46b..062b992 100755 --- a/client +++ b/client @@ -23,9 +23,8 @@ class ResponseConsumer(GeneralResponseConsumer): def __init__(self, cl, req): super().__init__(cl, req, 'RC') ssddesc = '[%s] %s' % (id(req), self._desc) - self._ssd = SlipStreamDecoder(ssddesc, cl.queue_inbound) + self._ssd = SlipStreamDecoder(ssddesc, partial(queue_inbound, cl.ipif)) self._log(DBG.HTTP_CTRL, '__init__') - self._success_reported = False def dataReceived(self, data): self._log(DBG.HTTP, 'dataReceived', d=data) @@ -45,9 +44,7 @@ class ResponseConsumer(GeneralResponseConsumer): self._cl.req_fin(self._req) except Exception as e: self._handleexception() - if not self._success_reported: - log.info(cl.desc + 'running OK', dflag=False) - self._success_reported = True + self._cl.report_running() def _handleexception(self): self._latefailure(traceback.format_exc()) @@ -87,7 +84,16 @@ class Client(): cl.c = c cl.outstanding = { } cl.desc = '[%s %s] ' % (ss,cs) - log.info(cl.desc + 'setting up', dflag=False) + cl.running_reported = False + cl.log_info('setting up') + + def log_info(cl, msg): + log.info(cl.desc + msg, dflag=False) + + def report_running(cl): + if not cl.running_reported: + cl.log_info('running OK') + cl.running_reported = True def log(cl, dflag, msg, **kwargs): log_debug(dflag, cl.desc + msg, **kwargs) @@ -245,7 +251,7 @@ common_startup(process_cfg) for cl in clients: cl.start() - start_ipif(cl.c.ipif_command, cl.outbound) + cl.ipif = start_ipif(cl.c.ipif_command, cl.outbound) cl.check_outbound() common_run() diff --git a/hippotat/__init__.py b/hippotat/__init__.py index 9f72b48..cc77cf6 100644 --- a/hippotat/__init__.py +++ b/hippotat/__init__.py @@ -240,14 +240,14 @@ class _IpifProcessProtocol(twisted.internet.protocol.ProcessProtocol): status.raiseException() def start_ipif(command, router): - global ipif ipif = _IpifProcessProtocol(router) reactor.spawnProcess(ipif, '/bin/sh',['sh','-xc', command], childFDs={0:'w', 1:'r', 2:2}, env=None) + return ipif -def queue_inbound(packet): +def queue_inbound(ipif, packet): log_debug(DBG.FLOW, "queue_inbound", d=packet) ipif.transport.write(slip.delimiter) ipif.transport.write(slip.encode(packet)) diff --git a/server b/server index 9772679..c83e6b2 100755 --- a/server +++ b/server @@ -26,7 +26,7 @@ def route(packet, iface, saddr, daddr): dclient.queue_outbound(packet) elif daddr == c.vaddr or daddr not in c.vnetwork: lt('inbound') - queue_inbound(packet) + queue_inbound(ipif, packet) elif daddr == c.relay: lt('discard relay') log_discard(packet, iface, saddr, daddr, 'relay') @@ -240,6 +240,6 @@ def process_cfg(putative_servers, putative_clients): ('rnets','vnetwork'))) common_startup(process_cfg) -start_ipif(c.ipif_command, (lambda p,s,d: route(p,"[ipif]",s,d))) +ipif = start_ipif(c.ipif_command, (lambda p,s,d: route(p,"[ipif]",s,d))) start_http() common_run() -- 2.30.2