Skip to content

Commit

Permalink
1.2.6 update xxnet
Browse files Browse the repository at this point in the history
  • Loading branch information
XndroidDev committed Dec 31, 2018
1 parent 66d0aaf commit 91124b4
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/net/xndroid/fqrouter/FqrouterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
Binary file modified app/src/main/res/raw/xxnet
Binary file not shown.
1 change: 1 addition & 0 deletions fqrouter/manager/fqsocks/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion fqrouter/manager/fqsocks/gateways/proxy_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions fqrouter/manager/fqsocks/proxies/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import socket
import time
from .. import networking
from .. import config_file

LOGGER = logging.getLogger(__name__)
on_proxy_died = None
Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions fqrouter/manager/fqsocks/proxies/http_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 9 additions & 3 deletions fqrouter/manager/fqsocks/proxies/http_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 91124b4

Please sign in to comment.