|
@ -46,7 +46,6 @@ class ServerPool(object): |
|
|
shell.print_shadowsocks() |
|
|
shell.print_shadowsocks() |
|
|
self.dns_resolver = asyncdns.DNSResolver() |
|
|
self.dns_resolver = asyncdns.DNSResolver() |
|
|
self.mgr = asyncmgr.ServerMgr() |
|
|
self.mgr = asyncmgr.ServerMgr() |
|
|
self.udp_on = True ### UDP switch ===================================== |
|
|
|
|
|
|
|
|
|
|
|
self.tcp_servers_pool = {} |
|
|
self.tcp_servers_pool = {} |
|
|
self.tcp_ipv6_servers_pool = {} |
|
|
self.tcp_ipv6_servers_pool = {} |
|
@ -110,19 +109,21 @@ class ServerPool(object): |
|
|
a_config['password'] = password |
|
|
a_config['password'] = password |
|
|
try: |
|
|
try: |
|
|
logging.info("starting server at [%s]:%d" % (a_config['server'], port)) |
|
|
logging.info("starting server at [%s]:%d" % (a_config['server'], port)) |
|
|
|
|
|
|
|
|
tcp_server = tcprelay.TCPRelay(a_config, self.dns_resolver, False) |
|
|
tcp_server = tcprelay.TCPRelay(a_config, self.dns_resolver, False) |
|
|
tcp_server.add_to_loop(self.loop) |
|
|
tcp_server.add_to_loop(self.loop) |
|
|
self.tcp_ipv6_servers_pool.update({port: tcp_server}) |
|
|
self.tcp_ipv6_servers_pool.update({port: tcp_server}) |
|
|
if self.udp_on: |
|
|
|
|
|
udp_server = udprelay.UDPRelay(a_config, self.dns_resolver, False) |
|
|
udp_server = udprelay.UDPRelay(a_config, self.dns_resolver, False) |
|
|
udp_server.add_to_loop(self.loop) |
|
|
udp_server.add_to_loop(self.loop) |
|
|
self.udp_ipv6_servers_pool.update({port: udp_server}) |
|
|
self.udp_ipv6_servers_pool.update({port: udp_server}) |
|
|
|
|
|
|
|
|
if a_config['server_ipv6'] == "::": |
|
|
if a_config['server_ipv6'] == "::": |
|
|
ipv6_ok = True |
|
|
ipv6_ok = True |
|
|
except Exception, e: |
|
|
except Exception, e: |
|
|
logging.warn("IPV6 %s " % (e,)) |
|
|
logging.warn("IPV6 %s " % (e,)) |
|
|
|
|
|
|
|
|
if not ipv6_ok and 'server' in self.config: |
|
|
if 'server' in self.config: |
|
|
if port in self.tcp_servers_pool: |
|
|
if port in self.tcp_servers_pool: |
|
|
logging.info("server already at %s:%d" % (self.config['server'], port)) |
|
|
logging.info("server already at %s:%d" % (self.config['server'], port)) |
|
|
return 'this port server is already running' |
|
|
return 'this port server is already running' |
|
@ -132,13 +133,16 @@ class ServerPool(object): |
|
|
a_config['password'] = password |
|
|
a_config['password'] = password |
|
|
try: |
|
|
try: |
|
|
logging.info("starting server at %s:%d" % (a_config['server'], port)) |
|
|
logging.info("starting server at %s:%d" % (a_config['server'], port)) |
|
|
|
|
|
|
|
|
|
|
|
if not ipv6_ok: |
|
|
tcp_server = tcprelay.TCPRelay(a_config, self.dns_resolver, False) |
|
|
tcp_server = tcprelay.TCPRelay(a_config, self.dns_resolver, False) |
|
|
tcp_server.add_to_loop(self.loop) |
|
|
tcp_server.add_to_loop(self.loop) |
|
|
self.tcp_servers_pool.update({port: tcp_server}) |
|
|
self.tcp_servers_pool.update({port: tcp_server}) |
|
|
if self.udp_on: |
|
|
|
|
|
udp_server = udprelay.UDPRelay(a_config, self.dns_resolver, False) |
|
|
udp_server = udprelay.UDPRelay(a_config, self.dns_resolver, False) |
|
|
udp_server.add_to_loop(self.loop) |
|
|
udp_server.add_to_loop(self.loop) |
|
|
self.udp_servers_pool.update({port: udp_server}) |
|
|
self.udp_servers_pool.update({port: udp_server}) |
|
|
|
|
|
|
|
|
except Exception, e: |
|
|
except Exception, e: |
|
|
logging.warn("IPV4 %s " % (e,)) |
|
|
logging.warn("IPV4 %s " % (e,)) |
|
|
|
|
|
|
|
@ -167,7 +171,6 @@ class ServerPool(object): |
|
|
del self.tcp_servers_pool[port] |
|
|
del self.tcp_servers_pool[port] |
|
|
except Exception, e: |
|
|
except Exception, e: |
|
|
logging.warn(e) |
|
|
logging.warn(e) |
|
|
if self.udp_on: |
|
|
|
|
|
try: |
|
|
try: |
|
|
self.udp_servers_pool[port].close(True) |
|
|
self.udp_servers_pool[port].close(True) |
|
|
del self.udp_servers_pool[port] |
|
|
del self.udp_servers_pool[port] |
|
@ -184,7 +187,6 @@ class ServerPool(object): |
|
|
del self.tcp_ipv6_servers_pool[port] |
|
|
del self.tcp_ipv6_servers_pool[port] |
|
|
except Exception, e: |
|
|
except Exception, e: |
|
|
logging.warn(e) |
|
|
logging.warn(e) |
|
|
if self.udp_on: |
|
|
|
|
|
try: |
|
|
try: |
|
|
self.udp_ipv6_servers_pool[port].close(True) |
|
|
self.udp_ipv6_servers_pool[port].close(True) |
|
|
del self.udp_ipv6_servers_pool[port] |
|
|
del self.udp_ipv6_servers_pool[port] |
|
|