make tcprelay.py less nested
This commit is contained in:
parent
5c11527e1b
commit
9f0c09463b
1 changed files with 67 additions and 62 deletions
|
@ -190,7 +190,9 @@ class TCPRelayHandler(object):
|
||||||
if self._upstream_status != status:
|
if self._upstream_status != status:
|
||||||
self._upstream_status = status
|
self._upstream_status = status
|
||||||
dirty = True
|
dirty = True
|
||||||
if dirty:
|
if not dirty:
|
||||||
|
return
|
||||||
|
|
||||||
if self._local_sock:
|
if self._local_sock:
|
||||||
event = eventloop.POLL_ERR
|
event = eventloop.POLL_ERR
|
||||||
if self._downstream_status & WAIT_STATUS_WRITING:
|
if self._downstream_status & WAIT_STATUS_WRITING:
|
||||||
|
@ -247,19 +249,20 @@ class TCPRelayHandler(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _handle_stage_connecting(self, data):
|
def _handle_stage_connecting(self, data):
|
||||||
if self._is_local:
|
if not 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 self._ota_enable_session:
|
if self._ota_enable_session:
|
||||||
self._ota_chunk_data(data,
|
self._ota_chunk_data(data,
|
||||||
self._data_to_write_to_remote.append)
|
self._data_to_write_to_remote.append)
|
||||||
else:
|
else:
|
||||||
self._data_to_write_to_remote.append(data)
|
self._data_to_write_to_remote.append(data)
|
||||||
if self._is_local and not self._fastopen_connected and \
|
return
|
||||||
self._config['fast_open']:
|
|
||||||
|
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
|
# for sslocal and fastopen, we basically wait for data and use
|
||||||
# sendto to connect
|
# sendto to connect
|
||||||
try:
|
try:
|
||||||
|
@ -403,7 +406,10 @@ class TCPRelayHandler(object):
|
||||||
self._log_error(error)
|
self._log_error(error)
|
||||||
self.destroy()
|
self.destroy()
|
||||||
return
|
return
|
||||||
if result and result[1]:
|
if not (result and result[1]):
|
||||||
|
self.destroy()
|
||||||
|
return
|
||||||
|
|
||||||
ip = result[1]
|
ip = result[1]
|
||||||
try:
|
try:
|
||||||
self._stage = STAGE_CONNECTING
|
self._stage = STAGE_CONNECTING
|
||||||
|
@ -442,7 +448,6 @@ class TCPRelayHandler(object):
|
||||||
shell.print_exception(e)
|
shell.print_exception(e)
|
||||||
if self._config['verbose']:
|
if self._config['verbose']:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
self.destroy()
|
|
||||||
|
|
||||||
def _write_to_sock_remote(self, data):
|
def _write_to_sock_remote(self, data):
|
||||||
self._write_to_sock(data, self._remote_sock)
|
self._write_to_sock(data, self._remote_sock)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue