diff --git a/app/build.gradle b/app/build.gradle index 12caa1f..a636bd6 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "net.xndroid" minSdkVersion 14 targetSdkVersion 23 - versionCode 26 - versionName "1.2.5" + versionCode 27 + versionName "1.2.6" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/net/xndroid/fqrouter/FqrouterManager.java b/app/src/main/java/net/xndroid/fqrouter/FqrouterManager.java index b2ac426..d394716 100755 --- a/app/src/main/java/net/xndroid/fqrouter/FqrouterManager.java +++ b/app/src/main/java/net/xndroid/fqrouter/FqrouterManager.java @@ -129,7 +129,7 @@ public static void prepareFqrouter(){ }else { sOriginIPv6 = originIPv6(); if (sOriginIPv6 != null) { - AppModel.showToast(AppModel.sContext.getString(R.string.available_origin_ipv6) + sOriginIPv6); + AppModel.showToast(AppModel.sContext.getString(R.string.available_origin_ipv6)); LogUtils.i("use origin ipv6 " + sOriginIPv6); } } @@ -191,8 +191,6 @@ public static String originIPv6(){ String output = ShellUtils.exec("ip route get 2001:13d2:2801::11"); if(ShellUtils.stdErr != null || output.contains("error") || output.contains("unreachable")) return null; - if(output.contains("via fe80")) - return null; String regex = "src\\s((\\w|:)+)"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(output); diff --git a/app/src/main/res/raw/xxnet b/app/src/main/res/raw/xxnet index 66700b2..08ed237 100755 Binary files a/app/src/main/res/raw/xxnet and b/app/src/main/res/raw/xxnet differ diff --git a/fqrouter/manager/fqsocks/config_file.py b/fqrouter/manager/fqsocks/config_file.py index edc8aaf..fa83f9a 100755 --- a/fqrouter/manager/fqsocks/config_file.py +++ b/fqrouter/manager/fqsocks/config_file.py @@ -8,6 +8,7 @@ DEFAULT_PUBLIC_SERVERS_SOURCE = 'no_available_source!' current_path = os.path.dirname(os.path.abspath(__file__)) home_path = os.path.abspath(current_path + "/../..") +multi_proxy = True def DEFAULT_CONFIG(): return { diff --git a/fqrouter/manager/fqsocks/gateways/proxy_client.py b/fqrouter/manager/fqsocks/gateways/proxy_client.py index 28a59b1..4e4f8b3 100755 --- a/fqrouter/manager/fqsocks/gateways/proxy_client.py +++ b/fqrouter/manager/fqsocks/gateways/proxy_client.py @@ -107,7 +107,9 @@ def add_resource(self, res): def forward(self, upstream_sock, timeout=7, after_started_timeout=360, encrypt=None, decrypt=None, delayed_penalty=None, on_forward_started=None): - + if not config_file.multi_proxy: + timeout = timeout * 6 + after_started_timeout = after_started_timeout * 6 if self.forward_started: if self.dst_port in [5228, 8883]: # Google Service and MQTT upstream_sock.settimeout(None) @@ -625,6 +627,11 @@ def get_refresh_interval(): def init_private_proxies(config): + if direct_access_enabled or china_shortcut_enabled or ipv6_direct_enable: + config_file.multi_proxy = True + else: + config_file.multi_proxy = False + private_proxy_num = 0 for proxy_id, private_server in config['private_servers'].items(): try: proxy_type = private_server.pop('proxy_type') @@ -633,6 +640,9 @@ def init_private_proxies(config): if isinstance(enabled, basestring): if enabled == 'enabled' or enabled == '1': enabled = True + private_proxy_num += 1 + if private_proxy_num > 1: + config_file.multi_proxy = True else: enabled = False else: @@ -736,6 +746,10 @@ def init_private_proxies(config): raise NotImplementedError('proxy type: %s' % proxy_type) except: LOGGER.exception('failed to init %s' % private_server) + if config_file.multi_proxy: + LOGGER.info('run in multi-proxy mode') + else: + LOGGER.info('run in single-proxy mode') def init_proxies(config): diff --git a/fqrouter/manager/fqsocks/proxies/direct.py b/fqrouter/manager/fqsocks/proxies/direct.py index 75bbf17..dafb697 100755 --- a/fqrouter/manager/fqsocks/proxies/direct.py +++ b/fqrouter/manager/fqsocks/proxies/direct.py @@ -2,6 +2,7 @@ import socket import time from .. import networking +from .. import config_file LOGGER = logging.getLogger(__name__) on_proxy_died = None @@ -35,6 +36,8 @@ def __init__(self): def increase_failed_time(self): LOGGER.error('failed once/%s: %s' % (self.failed_times, self)) + if not config_file.multi_proxy: + return self.failed_times += 1 if self.failed_times > 3: self.died = True diff --git a/fqrouter/manager/fqsocks/proxies/http_connect.py b/fqrouter/manager/fqsocks/proxies/http_connect.py index 8b6d52b..ab9074f 100755 --- a/fqrouter/manager/fqsocks/proxies/http_connect.py +++ b/fqrouter/manager/fqsocks/proxies/http_connect.py @@ -10,6 +10,7 @@ from .direct import to_bool from .direct import Proxy from .http_try import recv_till_double_newline +from .. import config_file LOGGER = logging.getLogger(__name__) @@ -38,7 +39,10 @@ def do_forward(self, client): LOGGER.info('[%s] http connect %s:%s' % (repr(client), self.proxy_ip, self.proxy_port)) begin_at = time.time() try: - upstream_sock = client.create_tcp_socket(self.proxy_ip, self.proxy_port, 5) + if config_file.multi_proxy: + upstream_sock = client.create_tcp_socket(self.proxy_ip, self.proxy_port, 5) + else: + upstream_sock = client.create_tcp_socket(self.proxy_ip, self.proxy_port, 30) if self.is_secured: counter = upstream_sock.counter upstream_sock = ssl.wrap_socket(upstream_sock) @@ -50,7 +54,10 @@ def do_forward(self, client): return client.fall_back( reason='http-connect upstream socket connect fail', delayed_penalty=self.increase_failed_time) - upstream_sock.settimeout(6.5) + if config_file.multi_proxy: + upstream_sock.settimeout(6) + else: + upstream_sock.settimeout(36) upstream_sock.sendall('CONNECT %s:%s HTTP/1.0\r\n' % (client.host if client.host else client.dst_ip, client.dst_port)) if self.username and self.password: auth = base64.b64encode('%s:%s' % (self.username, self.password)).strip() @@ -89,7 +96,7 @@ def do_forward(self, client): elif not client.host: LOGGER.info('disable HTTP connect access with ip') self.allow_ip_access = False - else: + elif config_file.multi_proxy: self.died = True self.die_time = time.time() client.fall_back( diff --git a/fqrouter/manager/fqsocks/proxies/http_relay.py b/fqrouter/manager/fqsocks/proxies/http_relay.py index a0f6e50..5df3d10 100755 --- a/fqrouter/manager/fqsocks/proxies/http_relay.py +++ b/fqrouter/manager/fqsocks/proxies/http_relay.py @@ -10,7 +10,7 @@ from .http_try import try_receive_response_header from .http_try import try_receive_response_body from .http_try import recv_and_parse_request - +from .. import config_file LOGGER = logging.getLogger(__name__) @@ -32,7 +32,10 @@ def do_forward(self, client): LOGGER.info('[%s] http relay %s:%s' % (repr(client), self.proxy_ip, self.proxy_port)) begin_at = time.time() try: - upstream_sock = client.create_tcp_socket(self.proxy_ip, self.proxy_port, 5) + if config_file.multi_proxy: + upstream_sock = client.create_tcp_socket(self.proxy_ip, self.proxy_port, 5) + else: + upstream_sock = client.create_tcp_socket(self.proxy_ip, self.proxy_port, 30) if self.is_secured: counter = upstream_sock.counter upstream_sock = ssl.wrap_socket(upstream_sock) @@ -44,7 +47,10 @@ def do_forward(self, client): return client.fall_back( reason='http-relay upstream socket connect timed out', delayed_penalty=self.increase_failed_time) - upstream_sock.settimeout(5) + if config_file.multi_proxy: + upstream_sock.settimeout(5) + else: + upstream_sock.settimeout(36) is_payload_complete = recv_and_parse_request(client) request_data = '%s %s HTTP/1.1\r\n' % (client.method, client.url) client.headers['Connection'] = 'close' # no keep-alive