Browse Source

detect thread status

add API params
dev
BreakWa11 9 years ago
parent
commit
91576d1e08
  1. 16
      Config.py
  2. 18
      db_transfer.py
  3. 4
      server.py
  4. 4
      server_pool.py
  5. 4
      shadowsocks/tcprelay.py

16
Config.py

@ -1,12 +1,24 @@
#Config # Config
TRANSFER_MUL = 1.0
API_INTERFACE = 'mysql'
# Mysql
MYSQL_HOST = 'mdss.mengsky.net' MYSQL_HOST = 'mdss.mengsky.net'
MYSQL_PORT = 3306 MYSQL_PORT = 3306
MYSQL_USER = 'ss' MYSQL_USER = 'ss'
MYSQL_PASS = 'ss' MYSQL_PASS = 'ss'
MYSQL_DB = 'shadowsocks' MYSQL_DB = 'shadowsocks'
MYSQL_TRANSFER_MUL = 1.0
MYSQL_UPDATE_TIME = 60 MYSQL_UPDATE_TIME = 60
# API
API_URL = 'breakwa11.org'
API_PORT = 80
API_PATH = '/mu/v2/'
API_TOKEN = 'abcdef'
API_NODE_ID = 'id001'
API_UPDATE_TIME = 60
# Manager (ignore this)
MANAGE_PASS = 'ss233333333' MANAGE_PASS = 'ss233333333'
#if you want manage in other server you should set this value to global ip #if you want manage in other server you should set this value to global ip
MANAGE_BIND_IP = '127.0.0.1' MANAGE_BIND_IP = '127.0.0.1'

18
db_transfer.py

@ -39,16 +39,16 @@ class DbTransfer(object):
continue continue
elif last_transfer[id][0] <= curr_transfer[id][0] and \ elif last_transfer[id][0] <= curr_transfer[id][0] and \
last_transfer[id][1] <= curr_transfer[id][1]: last_transfer[id][1] <= curr_transfer[id][1]:
dt_transfer[id] = [int((curr_transfer[id][0] - last_transfer[id][0]) * Config.MYSQL_TRANSFER_MUL), dt_transfer[id] = [int((curr_transfer[id][0] - last_transfer[id][0]) * Config.TRANSFER_MUL),
int((curr_transfer[id][1] - last_transfer[id][1]) * Config.MYSQL_TRANSFER_MUL)] int((curr_transfer[id][1] - last_transfer[id][1]) * Config.TRANSFER_MUL)]
else: else:
dt_transfer[id] = [int(curr_transfer[id][0] * Config.MYSQL_TRANSFER_MUL), dt_transfer[id] = [int(curr_transfer[id][0] * Config.TRANSFER_MUL),
int(curr_transfer[id][1] * Config.MYSQL_TRANSFER_MUL)] int(curr_transfer[id][1] * Config.TRANSFER_MUL)]
else: else:
if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0: if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
continue continue
dt_transfer[id] = [int(curr_transfer[id][0] * Config.MYSQL_TRANSFER_MUL), dt_transfer[id] = [int(curr_transfer[id][0] * Config.TRANSFER_MUL),
int(curr_transfer[id][1] * Config.MYSQL_TRANSFER_MUL)] int(curr_transfer[id][1] * Config.TRANSFER_MUL)]
query_head = 'UPDATE user' query_head = 'UPDATE user'
query_sub_when = '' query_sub_when = ''
@ -166,10 +166,10 @@ class DbTransfer(object):
def del_servers(): def del_servers():
for port in ServerPool.get_instance().tcp_servers_pool.keys(): for port in ServerPool.get_instance().tcp_servers_pool.keys():
if ServerPool.get_instance().server_is_run(port) > 0: if ServerPool.get_instance().server_is_run(port) > 0:
ServerPool.get_instance().cb_del_server(port) ServerPool.get_instance().cb_del_server(port)
for port in ServerPool.get_instance().tcp_ipv6_servers_pool.keys(): for port in ServerPool.get_instance().tcp_ipv6_servers_pool.keys():
if ServerPool.get_instance().server_is_run(port) > 0: if ServerPool.get_instance().server_is_run(port) > 0:
ServerPool.get_instance().cb_del_server(port) ServerPool.get_instance().cb_del_server(port)
@staticmethod @staticmethod
def thread_db(): def thread_db():
@ -190,7 +190,7 @@ class DbTransfer(object):
trace = traceback.format_exc() trace = traceback.format_exc()
logging.error(trace) logging.error(trace)
#logging.warn('db thread except:%s' % e) #logging.warn('db thread except:%s' % e)
if DbTransfer.get_instance().event.wait(Config.MYSQL_UPDATE_TIME): if DbTransfer.get_instance().event.wait(Config.MYSQL_UPDATE_TIME) or not ServerPool.get_instance().thread.is_alive():
break break
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
pass pass

4
server.py

@ -50,8 +50,8 @@ def main():
thread = MainThread() thread = MainThread()
thread.start() thread.start()
try: try:
while True: while thread.is_alive():
time.sleep(99999) time.sleep(10)
except (KeyboardInterrupt, IOError, OSError) as e: except (KeyboardInterrupt, IOError, OSError) as e:
import traceback import traceback
traceback.print_exc() traceback.print_exc()

4
server_pool.py

@ -64,8 +64,8 @@ class ServerPool(object):
self.stat_counter = {} self.stat_counter = {}
self.loop = eventloop.EventLoop() self.loop = eventloop.EventLoop()
thread = MainThread( (self.loop, self.dns_resolver, self.mgr) ) self.thread = MainThread( (self.loop, self.dns_resolver, self.mgr) )
thread.start() self.thread.start()
@staticmethod @staticmethod
def get_instance(): def get_instance():

4
shadowsocks/tcprelay.py

@ -170,7 +170,7 @@ class TCPRelayHandler(object):
self.last_activity = 0 self.last_activity = 0
self._update_activity() self._update_activity()
self._server.add_connection(1) self._server.add_connection(1)
self._server.stat_add(common.to_str(self._client_address[0]), 1) self._server.stat_add(self._client_address[0], 1)
def __hash__(self): def __hash__(self):
# default __hash__ is id / 16 # default __hash__ is id / 16
@ -878,7 +878,7 @@ class TCPRelayHandler(object):
self._dns_resolver.remove_callback(self._handle_dns_resolved) self._dns_resolver.remove_callback(self._handle_dns_resolved)
self._server.remove_handler(self) self._server.remove_handler(self)
self._server.add_connection(-1) self._server.add_connection(-1)
self._server.stat_add(common.to_str(self._client_address[0]), -1) self._server.stat_add(self._client_address[0], -1)
class TCPRelay(object): class TCPRelay(object):
def __init__(self, config, dns_resolver, is_local, stat_callback=None, stat_counter=None): def __init__(self, config, dns_resolver, is_local, stat_callback=None, stat_counter=None):

Loading…
Cancel
Save