Skip to content

Commit f589a7b

Browse files
committed
fix: 修复反代并发拨号数逻辑,确保实际并发数不小于1;优化DoH查询缓存逻辑
1 parent cf04c58 commit f589a7b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

_worker.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Version = '2026-07-11 02:23:18';
1+
const Version = '2026-07-11 02:23:18';
22
let config_JSON, 缓存SOCKS5白名单 = null, 调试日志打印 = false;
33
let SOCKS5白名单 = ['*tapecontent.net', '*cloudatacdn.com', '*loadshare.org', '*cdn-centaurus.com', 'scholar.google.com'];
44
const Pages静态页面 = 'https://edt-pages.github.io';
@@ -2084,9 +2084,10 @@ async function forwardataTCP(host, portNum, rawData, ws, respHeader, remoteConnW
20842084

20852085
async function connectProxyIP(address, port, data = null, 所有反代数组 = null, 启用反代失败兜底 = true) {
20862086
if (所有反代数组 && 所有反代数组.length > 0) {
2087-
for (let i = 0; i < 所有反代数组.length; i += 反代并发拨号数) {
2087+
const 实际并发数 = Math.max(1, 反代并发拨号数);
2088+
for (let i = 0; i < 所有反代数组.length; i += 实际并发数) {
20882089
const 候选列表 = [];
2089-
for (let j = 0; j < 反代并发拨号数 && i + j < 所有反代数组.length; j++) {
2090+
for (let j = 0; j < 实际并发数 && i + j < 所有反代数组.length; j++) {
20902091
const 索引 = (反代数组索引 + i + j) % 所有反代数组.length;
20912092
const [反代地址, 反代端口] = 所有反代数组[索引];
20922093
候选列表.push({ hostname: 反代地址, port: 反代端口, index: 索引 });
@@ -4936,7 +4937,7 @@ async function DoH查询(域名, 记录类型, DoH解析服务 = "https://cloudf
49364937
};
49374938

49384939
// 构建 DNS 查询报文
4939-
const qname = 编码域名(域名);
4940+
const qname = 编码域名(规范化域名);
49404941
const query = new Uint8Array(12 + qname.length + 4);
49414942
const qview = new DataView(query.buffer);
49424943
qview.setUint16(0, crypto.getRandomValues(new Uint16Array(1))[0]); // ID (random per RFC 1035)
@@ -5038,10 +5039,11 @@ async function DoH查询(域名, 记录类型, DoH解析服务 = "https://cloudf
50385039
const 耗时 = (performance.now() - 开始时间).toFixed(2);
50395040
log(`[DoH查询] 查询完成 ${域名} ${记录类型} via ${DoH解析服务} ${耗时}ms 共${answers.length}条结果${answers.length > 0 ? '\n' + answers.map((a, i) => ` ${i + 1}. ${a.name} type=${a.type} TTL=${a.TTL} data=${a.data}`).join('\n') : ''}`);
50405041
// DoH 缓存至少保留 5 分钟,响应 TTL 更长时尊重响应 TTL;空响应使用 5 分钟负缓存
5041-
const 最小TTL = answers.length > 0 ? Math.min(...answers.map(a => a.TTL)) : 0;
5042+
const 相关记录 = answers.filter(answer => answer.type === qtype);
5043+
const 最小TTL = 相关记录.length > 0 ? Math.min(...相关记录.map(a => a.TTL)) : 0;
50425044
const 缓存TTL = Math.max(最小TTL, 5 * 60);
50435045
const 缓存过期时间 = Date.now() + 缓存TTL * 1000;
5044-
const 缓存数据 = answers.filter(answer => answer.type === qtype).map(answer => answer.data);
5046+
const 缓存数据 = 相关记录.map(answer => answer.data);
50455047
if (缓存数据.length > 0 || answers.length === 0) {
50465048
if (Object.keys(DoH缓存).length >= DoH缓存最大条目) {
50475049
const 清理时间戳 = Date.now();

0 commit comments

Comments
 (0)