From aa58b85ace2fb52a0899b2ee24fd6eb933da4e47 Mon Sep 17 00:00:00 2001 From: meejah Date: Thu, 15 Apr 2021 12:28:23 -0600 Subject: [PATCH] honour log_requests as original code did --- src/wormhole_transit_relay/server_state.py | 5 +++++ src/wormhole_transit_relay/server_tap.py | 2 ++ src/wormhole_transit_relay/test/common.py | 1 + src/wormhole_transit_relay/test/test_transit_server.py | 2 ++ src/wormhole_transit_relay/transit_server.py | 6 ++++-- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/wormhole_transit_relay/server_state.py b/src/wormhole_transit_relay/server_state.py index 3bc112e..60ea710 100644 --- a/src/wormhole_transit_relay/server_state.py +++ b/src/wormhole_transit_relay/server_state.py @@ -1,6 +1,7 @@ from collections import defaultdict import automat +from twisted.python import log from zope.interface import ( Interface, Attribute, @@ -265,6 +266,8 @@ class TransitServerState(object): def _send_bad(self): self._mood = "errory" self._client.send(b"bad handshake\n") + if self._client.factory.log_requests: + log.msg("transit handshake failure") @_machine.output() def _send_ok(self): @@ -273,6 +276,8 @@ class TransitServerState(object): @_machine.output() def _send_impatient(self): self._client.send(b"impatient\n") + if self._client.factory.log_requests: + log.msg("transit impatience failure") @_machine.output() def _count_bytes(self, data): diff --git a/src/wormhole_transit_relay/server_tap.py b/src/wormhole_transit_relay/server_tap.py index 8198674..0db3ef6 100644 --- a/src/wormhole_transit_relay/server_tap.py +++ b/src/wormhole_transit_relay/server_tap.py @@ -59,6 +59,7 @@ def makeService(config, reactor=reactor): transit = transit_server.Transit(usage, reactor.seconds) tcp_factory = protocol.ServerFactory() tcp_factory.protocol = transit_server.TransitConnection + tcp_factory.log_requests = False if ws_ep is not None: ws_url = config["websocket-url"] @@ -71,6 +72,7 @@ def makeService(config, reactor=reactor): ws_factory = WebSocketServerFactory(ws_url) ws_factory.protocol = transit_server.WebSocketTransitConnection ws_factory.transit = transit + ws_factory.log_requests = False tcp_factory.transit = transit parent = MultiService() diff --git a/src/wormhole_transit_relay/test/common.py b/src/wormhole_transit_relay/test/common.py index cb84de1..4b2469f 100644 --- a/src/wormhole_transit_relay/test/common.py +++ b/src/wormhole_transit_relay/test/common.py @@ -88,6 +88,7 @@ class ServerBase: server_factory = ServerFactory() server_factory.protocol = TransitConnection server_factory.transit = self._transit_server + server_factory.log_requests = self.log_requests server_protocol = server_factory.buildProtocol(('127.0.0.1', 0)) @implementer(IRelayTestClient) diff --git a/src/wormhole_transit_relay/test/test_transit_server.py b/src/wormhole_transit_relay/test/test_transit_server.py index 1333781..c46b936 100644 --- a/src/wormhole_transit_relay/test/test_transit_server.py +++ b/src/wormhole_transit_relay/test/test_transit_server.py @@ -440,6 +440,7 @@ class TransitWebSockets(_Transit, ServerBase, unittest.TestCase): ws_factory = WebSocketServerFactory("ws://localhost:4002") ws_factory.protocol = WebSocketTransitConnection ws_factory.transit = self._transit_server + ws_factory.log_requests = self.log_requests ws_protocol = ws_factory.buildProtocol(('127.0.0.1', 0)) @implementer(IRelayTestClient) @@ -656,6 +657,7 @@ class UsageWebSockets(Usage): ws_factory = WebSocketServerFactory("ws://localhost:4002") ws_factory.protocol = WebSocketTransitConnection ws_factory.transit = self._transit_server + ws_factory.log_requests = self.log_requests ws_protocol = ws_factory.buildProtocol(('127.0.0.1', 0)) class TransitWebSocketClientProtocol(WebSocketClientProtocol): diff --git a/src/wormhole_transit_relay/transit_server.py b/src/wormhole_transit_relay/transit_server.py index c7baffb..35a2853 100644 --- a/src/wormhole_transit_relay/transit_server.py +++ b/src/wormhole_transit_relay/transit_server.py @@ -53,7 +53,8 @@ class TransitConnection(LineReceiver): ITransitClient API """ if self._buddy is not None: - log.msg("buddy_disconnected {}".format(self._buddy.get_token())) + if self.factory.log_requests: + log.msg("buddy_disconnected {}".format(self._buddy.get_token())) self._buddy._client.disconnect() self._buddy = None @@ -203,7 +204,8 @@ class WebSocketTransitConnection(WebSocketServerProtocol): ITransitClient API """ if self._buddy is not None: - log.msg("buddy_disconnected {}".format(self._buddy.get_token())) + if self.factory.log_requests: + log.msg("buddy_disconnected {}".format(self._buddy.get_token())) self._buddy._client.disconnect() self._buddy = None