make tcprelay.py less nested

This commit is contained in:
ahxxm 2016-09-06 10:13:10 +08:00
parent 5c11527e1b
commit 9f0c09463b

View file

@ -190,7 +190,9 @@ class TCPRelayHandler(object):
if self._upstream_status != status:
self._upstream_status = status
dirty = True
if dirty:
if not dirty:
return
if self._local_sock:
event = eventloop.POLL_ERR
if self._downstream_status & WAIT_STATUS_WRITING:
@ -247,19 +249,20 @@ class TCPRelayHandler(object):
return True
def _handle_stage_connecting(self, data):
if self._is_local:
if self._ota_enable_session:
data = self._ota_chunk_data_gen(data)
data = self._encryptor.encrypt(data)
self._data_to_write_to_remote.append(data)
else:
if not self._is_local:
if self._ota_enable_session:
self._ota_chunk_data(data,
self._data_to_write_to_remote.append)
else:
self._data_to_write_to_remote.append(data)
if self._is_local and not self._fastopen_connected and \
self._config['fast_open']:
return
if self._ota_enable_session:
data = self._ota_chunk_data_gen(data)
data = self._encryptor.encrypt(data)
self._data_to_write_to_remote.append(data)
if self._config['fast_open'] and not self._fastopen_connected:
# for sslocal and fastopen, we basically wait for data and use
# sendto to connect
try:
@ -403,7 +406,10 @@ class TCPRelayHandler(object):
self._log_error(error)
self.destroy()
return
if result and result[1]:
if not (result and result[1]):
self.destroy()
return
ip = result[1]
try:
self._stage = STAGE_CONNECTING
@ -442,7 +448,6 @@ class TCPRelayHandler(object):
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
self.destroy()
def _write_to_sock_remote(self, data):
self._write_to_sock(data, self._remote_sock)