From c2147ee9850701c818c50281cb907e2a60891390 Mon Sep 17 00:00:00 2001 From: meejah Date: Fri, 19 Feb 2021 17:18:08 -0700 Subject: [PATCH] change from review: inline _got_handshake --- src/wormhole_transit_relay/transit_server.py | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/wormhole_transit_relay/transit_server.py b/src/wormhole_transit_relay/transit_server.py index 0b23a66..d9dabfd 100644 --- a/src/wormhole_transit_relay/transit_server.py +++ b/src/wormhole_transit_relay/transit_server.py @@ -74,25 +74,32 @@ class TransitConnection(LineReceiver): pass def lineReceived(self, line): + """ + LineReceiver API + """ # old: "please relay {64}\n" + token = None old = re.search(br"^please relay (\w{64})$", line) if old: token = old.group(1) - return self._got_handshake(token, None) + self._state.please_relay(token) # new: "please relay {64} for side {16}\n" new = re.search(br"^please relay (\w{64}) for side (\w{16})$", line) if new: token = new.group(1) side = new.group(2) - return self._got_handshake(token, side) + self._state.please_relay_for_side(token, side) - # we should have been switched to "raw data" mode on the first - # line received (after which rawDataReceived() is called for - # all bytes) so getting here means a bad handshake. - return self._state.bad_token() + if token is None: + self._state.bad_token() + else: + self.setRawMode() def rawDataReceived(self, data): + """ + LineReceiver API + """ # We are an IPushProducer to our buddy's IConsumer, so they'll # throttle us (by calling pauseProducing()) when their outbound # buffer is full (e.g. when their downstream pipe is full). In @@ -101,13 +108,6 @@ class TransitConnection(LineReceiver): # receiver can handle it. self._state.got_bytes(data) - def _got_handshake(self, token, side): - if side is not None: - self._state.please_relay_for_side(token, side) - else: - self._state.please_relay(token) - self.setRawMode() - def disconnect_error(self): # we haven't finished the handshake, so there are no tokens tracking # us