remove "both_tunnel_local" and fix some error for tunnel
This commit is contained in:
parent
57f55bf347
commit
c9dae2ba57
5 changed files with 6 additions and 29 deletions
|
@ -7,7 +7,6 @@
|
||||||
"method":"aes-256-cfb",
|
"method":"aes-256-cfb",
|
||||||
"local_address":"127.0.0.1",
|
"local_address":"127.0.0.1",
|
||||||
"fast_open":false,
|
"fast_open":false,
|
||||||
"both_tunnel_local":false,
|
|
||||||
"tunnel_remote":"8.8.8.8",
|
"tunnel_remote":"8.8.8.8",
|
||||||
"tunnel_remote_port":53,
|
"tunnel_remote_port":53,
|
||||||
"tunnel_port":53
|
"tunnel_port":53
|
||||||
|
|
|
@ -50,32 +50,11 @@ def main():
|
||||||
dns_resolver.add_to_loop(loop)
|
dns_resolver.add_to_loop(loop)
|
||||||
tcp_server.add_to_loop(loop)
|
tcp_server.add_to_loop(loop)
|
||||||
udp_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, _):
|
def handler(signum, _):
|
||||||
logging.warn('received SIGQUIT, doing graceful shutting down..')
|
logging.warn('received SIGQUIT, doing graceful shutting down..')
|
||||||
tcp_server.close(next_tick=True)
|
tcp_server.close(next_tick=True)
|
||||||
udp_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)
|
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM), handler)
|
||||||
|
|
||||||
def int_handler(signum, _):
|
def int_handler(signum, _):
|
||||||
|
|
|
@ -310,7 +310,6 @@ def get_config(is_local):
|
||||||
config['one_time_auth'] = config.get('one_time_auth', False)
|
config['one_time_auth'] = config.get('one_time_auth', False)
|
||||||
config['prefer_ipv6'] = config.get('prefer_ipv6', False)
|
config['prefer_ipv6'] = config.get('prefer_ipv6', False)
|
||||||
config['server_port'] = config.get('server_port', 8388)
|
config['server_port'] = config.get('server_port', 8388)
|
||||||
config['both_tunnel_local'] = config.get('both_tunnel_local', False)
|
|
||||||
config['tunnel_remote'] = \
|
config['tunnel_remote'] = \
|
||||||
to_str(config.get('tunnel_remote', '8.8.8.8'))
|
to_str(config.get('tunnel_remote', '8.8.8.8'))
|
||||||
config['tunnel_remote_port'] = config.get('tunnel_remote_port', 53)
|
config['tunnel_remote_port'] = config.get('tunnel_remote_port', 53)
|
||||||
|
|
|
@ -116,7 +116,6 @@ class TCPRelayHandler(object):
|
||||||
self._remote_sock = None
|
self._remote_sock = None
|
||||||
self._config = config
|
self._config = config
|
||||||
self._dns_resolver = dns_resolver
|
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 = config.get('tunnel_remote', "8.8.8.8")
|
||||||
self.tunnel_remote_port = config.get('tunnel_remote_port', 53)
|
self.tunnel_remote_port = config.get('tunnel_remote_port', 53)
|
||||||
self.tunnel_port = config.get('tunnel_port', 53)
|
self.tunnel_port = config.get('tunnel_port', 53)
|
||||||
|
@ -568,14 +567,16 @@ class TCPRelayHandler(object):
|
||||||
data = self._encryptor.decrypt(data)
|
data = self._encryptor.decrypt(data)
|
||||||
if not data:
|
if not data:
|
||||||
return
|
return
|
||||||
# jump over socks5 init
|
|
||||||
if self.is_tunnel:
|
|
||||||
self._stage = STAGE_ADDR
|
|
||||||
if self._stage == STAGE_STREAM:
|
if self._stage == STAGE_STREAM:
|
||||||
self._handle_stage_stream(data)
|
self._handle_stage_stream(data)
|
||||||
return
|
return
|
||||||
elif is_local and self._stage == STAGE_INIT:
|
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:
|
elif self._stage == STAGE_CONNECTING:
|
||||||
self._handle_stage_connecting(data)
|
self._handle_stage_connecting(data)
|
||||||
elif (is_local and self._stage == STAGE_ADDR) or \
|
elif (is_local and self._stage == STAGE_ADDR) or \
|
||||||
|
|
|
@ -95,7 +95,6 @@ class UDPRelay(object):
|
||||||
self._listen_port = config['server_port']
|
self._listen_port = config['server_port']
|
||||||
self._remote_addr = None
|
self._remote_addr = None
|
||||||
self._remote_port = 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 = config.get('tunnel_remote', "8.8.8.8")
|
||||||
self.tunnel_remote_port = config.get('tunnel_remote_port', 53)
|
self.tunnel_remote_port = config.get('tunnel_remote_port', 53)
|
||||||
self.tunnel_port = config.get('tunnel_port', 53)
|
self.tunnel_port = config.get('tunnel_port', 53)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue