From c9dae2ba57daf33d1e0d6bde660c6c98b9dfdd33 Mon Sep 17 00:00:00 2001 From: Falseen Date: Wed, 1 Mar 2017 23:32:14 +0800 Subject: [PATCH] remove "both_tunnel_local" and fix some error for tunnel --- config.json.example | 1 - shadowsocks/local.py | 21 --------------------- shadowsocks/shell.py | 1 - shadowsocks/tcprelay.py | 11 ++++++----- shadowsocks/udprelay.py | 1 - 5 files changed, 6 insertions(+), 29 deletions(-) diff --git a/config.json.example b/config.json.example index 832cdd6..4006656 100644 --- a/config.json.example +++ b/config.json.example @@ -7,7 +7,6 @@ "method":"aes-256-cfb", "local_address":"127.0.0.1", "fast_open":false, - "both_tunnel_local":false, "tunnel_remote":"8.8.8.8", "tunnel_remote_port":53, "tunnel_port":53 diff --git a/shadowsocks/local.py b/shadowsocks/local.py index 9f8dc66..dfc8032 100755 --- a/shadowsocks/local.py +++ b/shadowsocks/local.py @@ -50,32 +50,11 @@ def main(): dns_resolver.add_to_loop(loop) tcp_server.add_to_loop(loop) udp_server.add_to_loop(loop) - has_tunnel = False - # if both_tunnel_local is True then run tunnel_udp_server - if config["both_tunnel_local"]: - _config = config.copy() - _config["local_port"] = _config["tunnel_port"] - logging.info("starting tcp tunnel at %s:%d forward to %s:%d" % - (_config['local_address'], _config['local_port'], - _config['tunnel_remote'], _config['tunnel_remote_port'])) - tunnel_tcp_server = tcprelay.TCPRelay(_config, dns_resolver, True) - tunnel_tcp_server.is_tunnel = True - tunnel_tcp_server.add_to_loop(loop) - logging.info("starting udp 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 def handler(signum, _): logging.warn('received SIGQUIT, doing graceful shutting down..') tcp_server.close(next_tick=True) udp_server.close(next_tick=True) - if has_tunnel: - tunnel_udp_server.close(next_tick=True) - tunnel_tcp_server.close(next_tick=True) signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM), handler) def int_handler(signum, _): diff --git a/shadowsocks/shell.py b/shadowsocks/shell.py index 535edc5..f7f4cda 100644 --- a/shadowsocks/shell.py +++ b/shadowsocks/shell.py @@ -310,7 +310,6 @@ def get_config(is_local): config['one_time_auth'] = config.get('one_time_auth', False) 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_remote'] = \ to_str(config.get('tunnel_remote', '8.8.8.8')) config['tunnel_remote_port'] = config.get('tunnel_remote_port', 53) diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index d45dbe5..dbd9c3d 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -116,7 +116,6 @@ class TCPRelayHandler(object): self._remote_sock = None self._config = config self._dns_resolver = dns_resolver - self.both_tunnel_local = config.get('both_tunnel_local', False) self.tunnel_remote = config.get('tunnel_remote', "8.8.8.8") self.tunnel_remote_port = config.get('tunnel_remote_port', 53) self.tunnel_port = config.get('tunnel_port', 53) @@ -568,14 +567,16 @@ class TCPRelayHandler(object): data = self._encryptor.decrypt(data) if not data: return - # jump over socks5 init - if self.is_tunnel: - self._stage = STAGE_ADDR if self._stage == STAGE_STREAM: self._handle_stage_stream(data) return elif is_local and self._stage == STAGE_INIT: - self._handle_stage_init(data) + # jump over socks5 init + if self.is_tunnel: + self._handle_stage_addr(data) + return + else: + self._handle_stage_init(data) elif self._stage == STAGE_CONNECTING: self._handle_stage_connecting(data) elif (is_local and self._stage == STAGE_ADDR) or \ diff --git a/shadowsocks/udprelay.py b/shadowsocks/udprelay.py index c603150..e2db886 100644 --- a/shadowsocks/udprelay.py +++ b/shadowsocks/udprelay.py @@ -95,7 +95,6 @@ class UDPRelay(object): self._listen_port = config['server_port'] self._remote_addr = None self._remote_port = None - self.both_tunnel_local = config.get('both_tunnel_local', False) self.tunnel_remote = config.get('tunnel_remote', "8.8.8.8") self.tunnel_remote_port = config.get('tunnel_remote_port', 53) self.tunnel_port = config.get('tunnel_port', 53)