Skip to content

Commit c6a2ddb

Browse files
committed
release 5.9.10
+ update blacklist. + add direct mode + query DNS from local first for unknown domain.
1 parent 65714fd commit c6a2ddb

19 files changed

+381
-30
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626

2727
### 最新公告:
28-
2024-02-25
29-
* 最新版5.9.9, 修复5.9.7智能策略更新的bug
28+
2024-03-06
29+
* 最新版5.9.10, 更新黑名单列表
3030
* 5.9.0 升级GAE服务端到python3
3131
* 5.8.8 改进iOS下连接性能
3232
* 5.7.0 为X-Tunnel增加新通道

code/default/launcher/web_control.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ def req_log_files(self):
923923
sys.path.append(x_tunnel_local)
924924
from upload_logs import pack_logs
925925

926-
data = pack_logs(10 * 1024 * 1024)
926+
data = pack_logs(200 * 1024 * 1024)
927927
self.send_response("application/zip", data)
928928

929929
def req_mem_info_handler(self):

code/default/lib/noarch/front_base/http1.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ def request(self, task):
6868
def keep_alive_thread(self):
6969
while time.time() - self.ssl_sock.create_time < self.config.http1_first_ping_wait:
7070
if not self.keep_running:
71-
self.close("exit ")
71+
self.close("exit")
7272
return
73+
7374
time.sleep(3)
7475

7576
if self.config.http1_first_ping_wait and self.processed_tasks == 0:
@@ -87,7 +88,7 @@ def keep_alive_thread(self):
8788

8889
elif self.config.http1_idle_time:
8990
while self.keep_running:
90-
time_to_sleep = max(self.config.http1_idle_time - (time.time() - self.last_recv_time), 0.2)
91+
time_to_sleep = max(self.config.http1_idle_time - (time.time() - self.last_recv_time), 3)
9192
time.sleep(time_to_sleep)
9293

9394
if not self.request_onway and time.time() - self.last_recv_time > self.config.http1_idle_time:
@@ -113,7 +114,6 @@ def work_loop(self):
113114
self.close("keep alive")
114115
return
115116

116-
self.last_recv_time = time.time()
117117
continue
118118

119119
# self.logger.debug("http1 get task")
@@ -127,7 +127,6 @@ def work_loop(self):
127127
self.request_task(task)
128128
self.request_onway = False
129129
self.last_send_time = time_now
130-
self.last_recv_time = time_now
131130

132131
life_end_reason = self.is_life_end()
133132
if life_end_reason:
@@ -138,7 +137,6 @@ def request_task(self, task):
138137
timeout = task.timeout
139138
self.request_onway = True
140139
start_time = time.time()
141-
self.last_recv_time = start_time
142140

143141
self.record_active("request")
144142
task.set_state("h1_req")
@@ -160,10 +158,11 @@ def request_task(self, task):
160158
sended = self.ssl_sock.send(task.body[start:start + send_size])
161159
start += sended
162160

163-
task.set_state("h1_req_sended")
161+
task.set_state("h1_req_sent")
164162
except Exception as e:
165-
self.logger.warn("%s h1_request send:%r inactive_time:%d task.timeout:%d",
166-
self.ip_str, e, time.time() - self.last_recv_time, task.timeout)
163+
self.logger.warn("%s %s h1_request send:%r inactive_time:%d task.timeout:%d",
164+
self.ip_str, self.ssl_sock.getsockname(),
165+
e, time.time() - self.last_recv_time, task.timeout)
167166
self.logger.warn('%s trace:%s', self.ip_str, self.get_trace())
168167

169168
self.retry_task_cb(task)
@@ -175,6 +174,7 @@ def request_task(self, task):
175174
response = simple_http_client.Response(self.ssl_sock)
176175
response.begin(timeout=timeout)
177176
task.set_state("response_begin")
177+
self.last_recv_time = time.time()
178178
except Exception as e:
179179
self.logger.warn("%s h1_request recv:%r inactive_time:%d task.timeout:%d",
180180
self.ip_str, e, time.time() - self.last_recv_time, task.timeout)
@@ -201,7 +201,7 @@ def request_task(self, task):
201201
task.queue.put(response)
202202
else:
203203
if self.config.http2_show_debug:
204-
self.logger.debug("got pong for %s status:%d", self.ip_str, response.status)
204+
self.logger.debug("got res for %s status:%d", self.ip_str, response.status)
205205

206206
try:
207207
read_target = int(response.content_length)
@@ -290,6 +290,7 @@ def head_request(self):
290290
self.record_active("head end")
291291
rtt = (time.time() - start_time) * 1000
292292
self.update_rtt(rtt)
293+
self.last_recv_time = time.time()
293294
return True
294295
except Exception as e:
295296
self.logger.warn("h1 %s HEAD keep alive request fail:%r", self.ssl_sock.ip_str, e)

code/default/lib/noarch/front_base/http_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def __init__(self, logger, ip_manager, config, ssl_sock, close_cb, retry_task_cb
217217
self.last_send_time = self.ssl_sock.create_time
218218
self.life_end_time = self.ssl_sock.create_time + \
219219
random.randint(self.config.connection_max_life, int(self.config.connection_max_life * 1.5))
220-
# self.logger.debug("worker.init %s", self.ip_str)
220+
# self.logger.debug("worker.init %s %s", self.ip_str, self.ssl_sock.getsockname())
221221

222222
def __str__(self):
223223
o = ""

code/default/smart_router/local/dns_query.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,10 @@ def query_blocked_domain(self, domain, dns_type):
635635
])
636636

637637
def query_unknown_domain(self, domain, dns_type):
638+
res = self.local_dns_resolve.query(domain, dns_type)
639+
if res:
640+
return res
641+
638642
return self.parallel_query.query(domain, dns_type, [
639643
self.https_query.query,
640644
self.tls_query.query,
@@ -662,7 +666,7 @@ def query(self, domain, dns_type=1, history=[]):
662666
xlog.debug("DNS query:%s in black", domain)
663667
return ips
664668

665-
elif b"." not in domain or g.gfwlist.in_white_list(domain) or rule in ["direct"]:
669+
elif b"." not in domain or g.gfwlist.in_white_list(domain) or rule in ["direct"] or g.config.pac_policy == "all_Direct":
666670
ips = self.local_dns_resolve.query(domain, timeout=1)
667671
g.domain_cache.set_ips(domain, ips, dns_type)
668672
return ips

code/default/smart_router/local/gfw_white_list.txt

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
178.com
77
2345.com
88
360safe.com
9+
51.la
910
56.com
1011
5eplay.com
1112
5ewin.com
@@ -26,6 +27,7 @@ alipay.com
2627
alipayobjects.com
2728
alivecdn.com
2829
aliyuncs.com
30+
aliyunddos1030.com
2931
allrace.com
3032
amap.com
3133
amemv.com
@@ -53,6 +55,10 @@ bokecs.net
5355
bootcss.com
5456
btigroup.io
5557
bytedance.com
58+
bytedns1.com
59+
bytefcdn.com
60+
byteimg.com
61+
bytegecko.co
5662
cccpan.com
5763
cdncl.net
5864
chiphell.com
@@ -76,6 +82,8 @@ douyin.com
7682
douyincdn.com
7783
douyinliving.com
7884
douyinpic.com
85+
douyinstatic.com.w.cdngslb.com
86+
douyinstatic.com.queniuuf.com
7987
douyinvod.com
8088
douyu.com
8189
duoduocdn.com
@@ -125,6 +133,7 @@ kmf.com
125133
ksyungslb.com
126134
kugou.com
127135
kuiniuca.com
136+
kunluncan.com
128137
le.com
129138
lecloud.com
130139
leisu.com
@@ -174,6 +183,7 @@ qq-zuidazy.com
174183
qq.com
175184
qqmail.com
176185
qtlglb.com
186+
queniusy.com
177187
remuxhdr.com
178188
ruioushang.com
179189
sandai.net
@@ -207,6 +217,7 @@ ubuntu.com
207217
uniqueway.com
208218
umeng.com
209219
videocc.net
220+
volcfcdndvs.com
210221
vzan.cc
211222
vzuu.com
212223
wangyuan.com

code/default/smart_router/local/ip_region.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def generate_db(self):
119119
'198.51.100.0/24', # TEST-NET-2
120120
'203.0.113.0/24', # TEST-NET-3
121121
# 连续地址直到 IP 结束,特殊处理
122-
# '224.0.0.0/4', #组播地址(D类)
122+
'224.0.0.0/4', #组播地址(D类)
123123
# '240.0.0.0/4', #保留地址(E类)
124124
)
125125
keeplist = []

code/default/smart_router/local/pac_server.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
gae_ca_file = os.path.join(env_info.data_path, "gae_proxy", "CA.crt")
2828

2929

30-
allow_policy = ["black_GAE", "black_X-Tunnel", "smart-router", "all_X-Tunnel"]
30+
allow_policy = ["black_GAE", "black_X-Tunnel", "smart-router", "all_X-Tunnel", "all_Direct"]
3131

3232

3333
def get_serving_pacfile():
@@ -52,6 +52,10 @@ def policy_all_to_proxy(self, host, port):
5252
content = content.replace(self.PROXY_LISTEN, proxy)
5353
return content
5454

55+
def policy_all_to_direct(self):
56+
content = """function FindProxyForURL(url, host) { return 'DIRECT';}"""
57+
return content
58+
5559
def policy_blacklist_to_proxy(self, host, port):
5660
content = get_serving_pacfile()
5761

@@ -89,6 +93,8 @@ def do_GET(self):
8993
content = self.policy_blacklist_to_proxy(host, "%s" % g.x_tunnel_socks_port)
9094
elif g.config.pac_policy == "all_X-Tunnel":
9195
content = self.policy_all_to_proxy(host, "%s" % g.x_tunnel_socks_port)
96+
elif g.config.pac_policy == "all_Direct":
97+
content = self.policy_all_to_direct()
9298
else:
9399
content = self.policy_all_to_proxy(host, g.config.proxy_port)
94100

code/default/smart_router/local/pipe_socks.py

+38-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import threading
22
import time
33
import sys
4+
import socket
5+
import errno
46

57
from xx_six import BlockingIOError
68
import utils
@@ -214,18 +216,21 @@ def flush_send_s(s2, d1):
214216

215217
try:
216218
d = s1.recv(65535)
219+
except BlockingIOError as e:
220+
xlog.debug("%s recv BlockingIOError:%r", s1, e)
221+
continue
217222
except Exception as e:
218-
# xlog.debug("%s recv e:%r", s1, e)
223+
xlog.debug("%s recv e:%r", s1, e)
219224
self.close(s1, "r")
220225
continue
221226

222227
if not d:
223228
# socket closed by peer.
224-
# xlog.debug("%s recv empty, close", s1)
229+
xlog.debug("%s recv empty, close", s1)
225230
self.close(s1, "r")
226231
continue
227232

228-
# xlog.debug("direct received %d bytes from:%s", len(d), s1)
233+
xlog.debug("direct received %d bytes from:%s", len(d), s1)
229234
s1.recved_data += len(d)
230235
s1.recved_times += 1
231236

@@ -253,6 +258,10 @@ def flush_send_s(s2, d1):
253258
flush_send_s(s2, d1)
254259
s2.sent_data += len(d1)
255260
s2.sent_times += 1
261+
except BlockingIOError as e:
262+
xlog.warn("Except %s flush_send_s BlockingIOError %r", s2, e)
263+
self.close(s2, "w")
264+
continue
256265
except Exception as e:
257266
xlog.warn("send split SNI:%s fail:%r", s2.host, e)
258267
self.close(s2, "w")
@@ -268,12 +277,24 @@ def flush_send_s(s2, d1):
268277
s2.sent_data += sent
269278
s2.sent_times += 1
270279
# xlog.debug("direct send %d to %s from:%s total:%d", sent, s2, s1, len(d))
280+
except BlockingIOError as e:
281+
xlog.warn("Except %s send BlockingIOError %r", s2, e)
282+
sent = 0
283+
except socket.error as e:
284+
if e.errno == errno.EAGAIN:
285+
# if str(e) == "[Errno 35] Resource temporarily unavailable":
286+
xlog.warn("%s send errno.EAGAIN %r", s2, e)
287+
time.sleep(0.1)
288+
sent = 0
289+
else:
290+
self.close(s2, "w")
291+
continue
271292
except Exception as e:
272293
# xlog.debug("%s send e:%r", s2, e)
273294
if sys.version_info[0] == 3 and isinstance(e, BlockingIOError):
274295
# This error happened on upload large file or speed test
275296
# Just ignore this error and will be fine
276-
# xlog.warn("%s send BlockingIOError %r", s2, e)
297+
xlog.warn("%s send BlockingIOError %r", s2, e)
277298
sent = 0
278299
else:
279300
# xlog.warn("%s send except:%r", s2, e)
@@ -320,11 +341,23 @@ def flush_send_s(s2, d1):
320341
s1.sent_data += sent
321342
s1.sent_times += 1
322343
# xlog.debug("send buffered %d bytes to %s", sent, s1)
344+
except BlockingIOError as e:
345+
xlog.warn("Except %s send BlockingIOError %r", s1, e)
346+
sent = 0
347+
except socket.error as e:
348+
if e.errno == errno.EAGAIN:
349+
# if str(e) == "[Errno 35] Resource temporarily unavailable":
350+
xlog.warn("%s send errno.EAGAIN %r", s1, e)
351+
time.sleep(0.1)
352+
sent = 0
353+
else:
354+
self.close(s1, "w")
355+
continue
323356
except Exception as e:
324357
if sys.version_info[0] == 3 and isinstance(e, BlockingIOError):
325358
# This error happened on upload large file or speed test
326359
# Just ignore this error and will be fine
327-
# xlog.debug("%s sent BlockingIOError %r", s1, e)
360+
xlog.debug("%s sent BlockingIOError %r", s1, e)
328361
sent = 0
329362
else:
330363
# xlog.debug("%s sent e:%r", s1, e)

code/default/smart_router/local/smart_route.py

+4
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ def handle_ip_proxy(sock, ip, port, client_address):
497497
rule = "direct"
498498
elif g.config.pac_policy == "all_X-Tunnel":
499499
rule = "socks"
500+
elif g.config.pac_policy == "all_Direct":
501+
rule = "direct"
500502

501503
if rule:
502504
return try_loop("ip user", [rule], sock, ip, port, client_address)
@@ -556,6 +558,8 @@ def handle_domain_proxy(sock, host, port, client_address, left_buf=""):
556558
rule = "gae"
557559
elif utils.check_ip_valid(host) and utils.is_private_ip(host):
558560
rule = "direct"
561+
elif g.config.pac_policy == "all_Direct":
562+
rule = "direct"
559563

560564
if not rule and (g.config.bypass_speedtest and g.gfwlist.in_speedtest_whitelist(host)):
561565
xlog.debug("speedtest %s", host)

0 commit comments

Comments
 (0)