diff --git a/server_pool.py b/server_pool.py index 0f0052e..c75655a 100644 --- a/server_pool.py +++ b/server_pool.py @@ -95,6 +95,7 @@ class ServerPool(object): def new_server(self, port, password): ret = True port = int(port) + ipv6_ok = False if 'server_ipv6' in self.config: if port in self.tcp_ipv6_servers_pool: @@ -102,11 +103,13 @@ class ServerPool(object): return 'this port server is already running' else: 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_port'] = port a_config['password'] = password 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.add_to_loop(self.loop) 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.add_to_loop(self.loop) self.udp_ipv6_servers_pool.update({port: udp_server}) + if a_config['server_ipv6'] == "::": + ipv6_ok = True except Exception, 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: logging.info("server already at %s:%d" % (self.config['server'], port)) return 'this port server is already running' @@ -158,13 +163,13 @@ class ServerPool(object): else: logging.info("stopped server at %s:%d" % (self.config['server'], port)) try: - self.tcp_servers_pool[port].close() + self.tcp_servers_pool[port].close(True) del self.tcp_servers_pool[port] except Exception, e: logging.warn(e) if self.udp_on: try: - self.udp_servers_pool[port].close() + self.udp_servers_pool[port].close(True) del self.udp_servers_pool[port] except Exception, e: logging.warn(e) @@ -175,13 +180,13 @@ class ServerPool(object): else: logging.info("stopped server at %s:%d" % (self.config['server_ipv6'], port)) try: - self.tcp_ipv6_servers_pool[port].close() + self.tcp_ipv6_servers_pool[port].close(True) del self.tcp_ipv6_servers_pool[port] except Exception, e: logging.warn(e) if self.udp_on: try: - self.udp_ipv6_servers_pool[port].close() + self.udp_ipv6_servers_pool[port].close(True) del self.udp_ipv6_servers_pool[port] except Exception, e: logging.warn(e)