From d475076cdc924ac011b68422968d43b3300ce59f Mon Sep 17 00:00:00 2001 From: breakwa11 Date: Tue, 14 Jul 2015 19:03:50 +0800 Subject: [PATCH] listen ipv6 --- shadowsocks/server.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/shadowsocks/server.py b/shadowsocks/server.py index 429a20a..d919092 100755 --- a/shadowsocks/server.py +++ b/shadowsocks/server.py @@ -53,12 +53,35 @@ def main(): dns_resolver = asyncdns.DNSResolver() for port, password in config['port_password'].items(): a_config = config.copy() - a_config['server_port'] = int(port) - a_config['password'] = password - logging.info("starting server at %s:%d" % - (a_config['server'], int(port))) - tcp_servers.append(tcprelay.TCPRelay(a_config, dns_resolver, False)) - udp_servers.append(udprelay.UDPRelay(a_config, dns_resolver, False)) + ipv6_ok = False + logging.info("server start with password [%s] method [%s]" % (password, a_config['method'])) + if 'server_ipv6' in a_config: + try: + 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_port'] = int(port) + a_config['password'] = password + a_config['server'] = a_config['server_ipv6'] + logging.info("starting server at %s:%d" % + (a_config['server'], int(port))) + tcp_servers.append(tcprelay.TCPRelay(a_config, dns_resolver, False)) + udp_servers.append(udprelay.UDPRelay(a_config, dns_resolver, False)) + if a_config['server_ipv6'] == "::": + ipv6_ok = True + except Exception as e: + shell.print_exception(e) + + try: + a_config = config.copy() + a_config['server_port'] = int(port) + a_config['password'] = password + logging.info("starting server at %s:%d" % + (a_config['server'], int(port))) + tcp_servers.append(tcprelay.TCPRelay(a_config, dns_resolver, False)) + udp_servers.append(udprelay.UDPRelay(a_config, dns_resolver, False)) + except Exception as e: + if not ipv6_ok: + shell.print_exception(e) def run_server(): def child_handler(signum, _):