From 4af94729864bea8042139747051c767a9ceb4920 Mon Sep 17 00:00:00 2001 From: BreakWa11 Date: Sun, 12 Jun 2016 22:46:47 +0800 Subject: [PATCH] detect cfg modification --- db_transfer.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/db_transfer.py b/db_transfer.py index 5d315eb..b4d596e 100644 --- a/db_transfer.py +++ b/db_transfer.py @@ -124,7 +124,7 @@ class DbTransfer(object): port = row['port'] passwd = common.to_bytes(row['passwd']) - cfg = {} + cfg = {'password': passwd} for name in ['method', 'obfs', 'protocol']: if name in row: cfg[name] = row[name] @@ -139,12 +139,25 @@ class DbTransfer(object): if not allow: logging.info('db stop server at port [%s]' % (port,)) ServerPool.get_instance().cb_del_server(port) - elif (port in ServerPool.get_instance().tcp_servers_pool and ServerPool.get_instance().tcp_servers_pool[port]._config['password'] != passwd) \ - or (port in ServerPool.get_instance().tcp_ipv6_servers_pool and ServerPool.get_instance().tcp_ipv6_servers_pool[port]._config['password'] != passwd): - #password changed - logging.info('db stop server at port [%s] reason: password changed' % (port,)) - ServerPool.get_instance().cb_del_server(port) - new_servers[port] = (passwd, cfg) + else: + cfgchange = False + if (port in ServerPool.get_instance().tcp_servers_pool): + relay = ServerPool.get_instance().tcp_servers_pool[port] + for name in ['password', 'method', 'obfs', 'protocol']: + if name in cfg and cfg[name] != relay._config[name]: + cfgchange = True + break; + if (port in ServerPool.get_instance().tcp_ipv6_servers_pool): + relay = ServerPool.get_instance().tcp_ipv6_servers_pool[port] + for name in ['password', 'method', 'obfs', 'protocol']: + if name in cfg and cfg[name] != relay._config[name]: + cfgchange = True + break; + #config changed + if cfgchange: + logging.info('db stop server at port [%s] reason: config changed: %s' % (port, cfg)) + ServerPool.get_instance().cb_del_server(port) + new_servers[port] = (passwd, cfg) elif allow and ServerPool.get_instance().server_run_status(port) is False: #new_servers[port] = passwd