change from review: inline _got_handshake
This commit is contained in:
parent
c8fbc22120
commit
c2147ee985
|
@ -74,25 +74,32 @@ class TransitConnection(LineReceiver):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def lineReceived(self, line):
|
def lineReceived(self, line):
|
||||||
|
"""
|
||||||
|
LineReceiver API
|
||||||
|
"""
|
||||||
# old: "please relay {64}\n"
|
# old: "please relay {64}\n"
|
||||||
|
token = None
|
||||||
old = re.search(br"^please relay (\w{64})$", line)
|
old = re.search(br"^please relay (\w{64})$", line)
|
||||||
if old:
|
if old:
|
||||||
token = old.group(1)
|
token = old.group(1)
|
||||||
return self._got_handshake(token, None)
|
self._state.please_relay(token)
|
||||||
|
|
||||||
# new: "please relay {64} for side {16}\n"
|
# new: "please relay {64} for side {16}\n"
|
||||||
new = re.search(br"^please relay (\w{64}) for side (\w{16})$", line)
|
new = re.search(br"^please relay (\w{64}) for side (\w{16})$", line)
|
||||||
if new:
|
if new:
|
||||||
token = new.group(1)
|
token = new.group(1)
|
||||||
side = new.group(2)
|
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
|
if token is None:
|
||||||
# line received (after which rawDataReceived() is called for
|
self._state.bad_token()
|
||||||
# all bytes) so getting here means a bad handshake.
|
else:
|
||||||
return self._state.bad_token()
|
self.setRawMode()
|
||||||
|
|
||||||
def rawDataReceived(self, data):
|
def rawDataReceived(self, data):
|
||||||
|
"""
|
||||||
|
LineReceiver API
|
||||||
|
"""
|
||||||
# We are an IPushProducer to our buddy's IConsumer, so they'll
|
# We are an IPushProducer to our buddy's IConsumer, so they'll
|
||||||
# throttle us (by calling pauseProducing()) when their outbound
|
# throttle us (by calling pauseProducing()) when their outbound
|
||||||
# buffer is full (e.g. when their downstream pipe is full). In
|
# buffer is full (e.g. when their downstream pipe is full). In
|
||||||
|
@ -101,13 +108,6 @@ class TransitConnection(LineReceiver):
|
||||||
# receiver can handle it.
|
# receiver can handle it.
|
||||||
self._state.got_bytes(data)
|
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):
|
def disconnect_error(self):
|
||||||
# we haven't finished the handshake, so there are no tokens tracking
|
# we haven't finished the handshake, so there are no tokens tracking
|
||||||
# us
|
# us
|
||||||
|
|
Loading…
Reference in New Issue
Block a user