Skip to content

Commit

Permalink
- remove tfo in relay
Browse files Browse the repository at this point in the history
- refine key exit
- remove unused
  • Loading branch information
esdeathlove committed Aug 6, 2017
1 parent 9feb847 commit f4bc2a3
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 27 deletions.
4 changes: 4 additions & 0 deletions auto_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self):
import threading
self.event = threading.Event()
self.start_line = self.file_len("/etc/hosts.deny")
self.has_stopped = False

def get_ip(self, text):
if common.match_ipv4_address(text) is not None:
Expand Down Expand Up @@ -293,11 +294,14 @@ def thread_db(obj):
#logging.warn('db thread except:%s' % e)
if db_instance.event.wait(60):
break
if db_instance.has_stopped:
break
except KeyboardInterrupt as e:
pass
db_instance = None

@staticmethod
def thread_db_stop():
global db_instance
db_instance.has_stopped = True
db_instance.event.set()
5 changes: 5 additions & 0 deletions auto_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(self):
self.import_result = self.gpg.import_keys(self.key_data)
self.public_keys = self.gpg.list_keys()

self.has_stopped = False

def run_command(self, command, id):
value = subprocess.check_output(command.split(' ')).decode('utf-8')
if configloader.get_config().API_INTERFACE == 'modwebapi':
Expand Down Expand Up @@ -181,11 +183,14 @@ def thread_db(obj):
#logging.warn('db thread except:%s' % e)
if db_instance.event.wait(60):
break
if db_instance.has_stopped:
break
except KeyboardInterrupt as e:
pass
db_instance = None

@staticmethod
def thread_db_stop():
global db_instance
db_instance.has_stopped = True
db_instance.event.set()
8 changes: 5 additions & 3 deletions db_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def __init__(self):
self.node_ip_list = []
self.mu_port_list = []

self.has_stopped = False

def update_all_user(self, dt_transfer):
import cymysql
update_transfer = {}
Expand Down Expand Up @@ -871,6 +873,8 @@ def thread_db(obj):
# logging.warn('db thread except:%s' % e)
if db_instance.event.wait(60) or not db_instance.is_all_thread_alive():
break
if db_instance.has_stopped:
break
except KeyboardInterrupt as e:
pass
db_instance.del_servers()
Expand All @@ -880,12 +884,10 @@ def thread_db(obj):
@staticmethod
def thread_db_stop():
global db_instance
db_instance.has_stopped = True
db_instance.event.set()

def is_all_thread_alive(self):
for port in ServerPool.get_instance().thread_pool:
if not ServerPool.get_instance().thread_pool[port].is_alive():
return False
if not ServerPool.get_instance().thread.is_alive():
return False
return True
4 changes: 0 additions & 4 deletions server_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def __init__(self):
self.mgr = None # asyncmgr.ServerMgr()

self.eventloop_pool = {}
self.thread_pool = {}
self.dns_resolver_pool = {}

self.dns_resolver = asyncdns.DNSResolver()
Expand Down Expand Up @@ -220,9 +219,6 @@ def cb_del_server(self, port):
if port in self.dns_resolver_pool:
del self.dns_resolver_pool[port]

if port in self.thread_pool:
del self.thread_pool[port]

if port not in self.tcp_servers_pool:
logging.info(
"stopped server at %s:%d already stop" %
Expand Down
19 changes: 2 additions & 17 deletions shadowsocks/tcprelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,23 +1122,8 @@ def _handle_dns_resolved(self, result, error):
self._server)
else:
try:
if self._is_relay and self._config[
'fast_open']:
data = b''.join(
self._data_to_write_to_remote)
l = len(data)
remote_sock.setblocking(True)
s = remote_sock.sendto(
data, MSG_FASTOPEN, (remote_addr, remote_port))
remote_sock.setblocking(False)
if s < l:
data = data[s:]
self._data_to_write_to_remote = [data]
else:
self._data_to_write_to_remote = []
else:
remote_sock.connect(
(remote_addr, remote_port))
remote_sock.connect(
(remote_addr, remote_port))
except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) in (
errno.EINPROGRESS, errno.EWOULDBLOCK):
Expand Down
4 changes: 4 additions & 0 deletions speedtest_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Speedtest(object):
def __init__(self):
import threading
self.event = threading.Event()
self.has_stopped = False

def speedtest_thread(self):
if self.event.wait(600):
Expand Down Expand Up @@ -180,11 +181,14 @@ def thread_db(obj):
#logging.warn('db thread except:%s' % e)
if db_instance.event.wait(configloader.get_config().SPEEDTEST * 3600):
break
if db_instance.has_stopped:
break
except KeyboardInterrupt as e:
pass
db_instance = None

@staticmethod
def thread_db_stop():
global db_instance
db_instance.has_stopped = True
db_instance.event.set()
8 changes: 5 additions & 3 deletions web_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def __init__(self):
self.node_ip_list = []
self.mu_port_list = []

self.has_stopped = False

def update_all_user(self, dt_transfer):
global webapi

Expand Down Expand Up @@ -673,6 +675,8 @@ def thread_db(obj):
# logging.warn('db thread except:%s' % e)
if db_instance.event.wait(60) or not db_instance.is_all_thread_alive():
break
if db_instance.has_stopped:
break
except KeyboardInterrupt as e:
pass
db_instance.del_servers()
Expand All @@ -682,12 +686,10 @@ def thread_db(obj):
@staticmethod
def thread_db_stop():
global db_instance
db_instance.has_stopped = True
db_instance.event.set()

def is_all_thread_alive(self):
for port in ServerPool.get_instance().thread_pool:
if not ServerPool.get_instance().thread_pool[port].is_alive():
return False
if not ServerPool.get_instance().thread.is_alive():
return False
return True

0 comments on commit f4bc2a3

Please sign in to comment.