|
@ -95,6 +95,7 @@ class ServerPool(object): |
|
|
def new_server(self, port, password): |
|
|
def new_server(self, port, password): |
|
|
ret = True |
|
|
ret = True |
|
|
port = int(port) |
|
|
port = int(port) |
|
|
|
|
|
ipv6_ok = False |
|
|
|
|
|
|
|
|
if 'server_ipv6' in self.config: |
|
|
if 'server_ipv6' in self.config: |
|
|
if port in self.tcp_ipv6_servers_pool: |
|
|
if port in self.tcp_ipv6_servers_pool: |
|
@ -102,11 +103,13 @@ class ServerPool(object): |
|
|
return 'this port server is already running' |
|
|
return 'this port server is already running' |
|
|
else: |
|
|
else: |
|
|
a_config = self.config.copy() |
|
|
a_config = self.config.copy() |
|
|
|
|
|
if len(a_config['server_ipv6']) > 2 and a_config['server_ipv6'][0] == "[" and a_config['server_ipv6'][-1] == "]": |
|
|
|
|
|
a_config['server_ipv6'] = a_config['server_ipv6'][1:-1] |
|
|
a_config['server'] = a_config['server_ipv6'] |
|
|
a_config['server'] = a_config['server_ipv6'] |
|
|
a_config['server_port'] = port |
|
|
a_config['server_port'] = port |
|
|
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}) |
|
@ -114,10 +117,12 @@ class ServerPool(object): |
|
|
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'] == "::": |
|
|
|
|
|
ipv6_ok = True |
|
|
except Exception, e: |
|
|
except Exception, e: |
|
|
logging.warn("IPV6 %s " % (e,)) |
|
|
logging.warn("IPV6 %s " % (e,)) |
|
|
|
|
|
|
|
|
if 'server' in self.config: |
|
|
if not ipv6_ok and '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' |
|
@ -158,13 +163,13 @@ class ServerPool(object): |
|
|
else: |
|
|
else: |
|
|
logging.info("stopped server at %s:%d" % (self.config['server'], port)) |
|
|
logging.info("stopped server at %s:%d" % (self.config['server'], port)) |
|
|
try: |
|
|
try: |
|
|
self.tcp_servers_pool[port].close() |
|
|
self.tcp_servers_pool[port].close(True) |
|
|
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: |
|
|
if self.udp_on: |
|
|
try: |
|
|
try: |
|
|
self.udp_servers_pool[port].close() |
|
|
self.udp_servers_pool[port].close(True) |
|
|
del self.udp_servers_pool[port] |
|
|
del self.udp_servers_pool[port] |
|
|
except Exception, e: |
|
|
except Exception, e: |
|
|
logging.warn(e) |
|
|
logging.warn(e) |
|
@ -175,13 +180,13 @@ class ServerPool(object): |
|
|
else: |
|
|
else: |
|
|
logging.info("stopped server at %s:%d" % (self.config['server_ipv6'], port)) |
|
|
logging.info("stopped server at %s:%d" % (self.config['server_ipv6'], port)) |
|
|
try: |
|
|
try: |
|
|
self.tcp_ipv6_servers_pool[port].close() |
|
|
self.tcp_ipv6_servers_pool[port].close(True) |
|
|
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: |
|
|
if self.udp_on: |
|
|
try: |
|
|
try: |
|
|
self.udp_ipv6_servers_pool[port].close() |
|
|
self.udp_ipv6_servers_pool[port].close(True) |
|
|
del self.udp_ipv6_servers_pool[port] |
|
|
del self.udp_ipv6_servers_pool[port] |
|
|
except Exception, e: |
|
|
except Exception, e: |
|
|
logging.warn(e) |
|
|
logging.warn(e) |
|
|