diff --git a/shadowsocks/local.py b/shadowsocks/local.py index 37d39ac..7138046 100755 --- a/shadowsocks/local.py +++ b/shadowsocks/local.py @@ -25,7 +25,6 @@ import signal sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../')) from shadowsocks import shell, daemon, eventloop, tcprelay, udprelay, asyncdns -from tunnel import get_tunnel_udp_server @shell.exception_handle(self_=False, exit_code=1) @@ -52,9 +51,14 @@ def main(): tcp_server.add_to_loop(loop) udp_server.add_to_loop(loop) has_tunnel = False - # if tunnel_service is True then run tunnel_udp_server - if config["tunnel_service"]: - tunnel_udp_server = get_tunnel_udp_server(config.copy(), dns_resolver) + # if both_tunnel_local is True then run tunnel_udp_server + if config["both_tunnel_local"]: + config["local_port"] = config.copy()["tunnel_port"] + logging.info("starting tunnel at %s:%d forward to %s:%d" % \ + (config['local_address'], config['local_port'], config['tunnel_remote'], \ + config['tunnel_remote_port'])) + tunnel_udp_server = udprelay.UDPRelay(config, dns_resolver, True) + tunnel_udp_server.is_tunnel = True tunnel_udp_server.add_to_loop(loop) has_tunnel = True diff --git a/shadowsocks/shell.py b/shadowsocks/shell.py index 78cf367..97ad2c7 100644 --- a/shadowsocks/shell.py +++ b/shadowsocks/shell.py @@ -304,8 +304,8 @@ def get_config(is_local): config['prefer_ipv6'] = config.get('prefer_ipv6', False) config['server_port'] = config.get('server_port', 8388) config['both_tunnel_local'] = config.get('both_tunnel_local', False) - config['tunnel_server'] = \ - to_str(config.get('tunnel_server', "8.8.8.8")) + config['tunnel_remote'] = \ + to_str(config.get('tunnel_remote', '8.8.8.8')) config['tunnel_remote_port'] = config.get('tunnel_remote_port', 53) config['tunnel_port'] = config.get('tunnel_port', 53) diff --git a/shadowsocks/tunnel.py b/shadowsocks/tunnel.py index 55a9dcf..a073213 100644 --- a/shadowsocks/tunnel.py +++ b/shadowsocks/tunnel.py @@ -27,16 +27,6 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../')) from shadowsocks import shell, daemon, eventloop, udprelay, asyncdns -def get_tunnel_udp_server(config, dns_resolver): - config["local_port"] = config.copy()["tunnel_port"] - logging.info("starting tunnel at %s:%d" % \ - (config['local_address'], config['local_port'])) - # tcp_server = tcprelay.TCPRelay(config, dns_resolver, True) - tunnel_udp_server = udprelay.UDPRelay(config, dns_resolver, True) - tunnel_udp_server.is_tunnel = True - return tunnel_udp_server - - @shell.exception_handle(self_=False, exit_code=1) def main(): shell.check_python() @@ -50,12 +40,15 @@ def main(): config = shell.get_config(True) daemon.daemon_exec(config) dns_resolver = asyncdns.DNSResolver() - # if running tunnel then update tunnel_service to True - config["tunnel_service"] = True - tunnel_udp_server = get_tunnel_udp_server(config, dns_resolver) loop = eventloop.EventLoop() dns_resolver.add_to_loop(loop) # tcp_server.add_to_loop(loop) + config["local_port"] = config.copy()["tunnel_port"] + logging.info("starting tunnel at %s:%d forward to %s:%d" % \ + (config['local_address'], config['local_port'], config['tunnel_remote'], \ + config['tunnel_remote_port'])) + tunnel_udp_server = udprelay.UDPRelay(config, dns_resolver, True) + tunnel_udp_server.is_tunnel = True tunnel_udp_server.add_to_loop(loop) def handler(signum, _):