Skip to content

Commit b8f423f

Browse files
committed
fix: 更新forwardataTCP函数,随机化反代地址选择以提高连接成功率
1 parent 36e8234 commit b8f423f

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

_worker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,10 @@ async function forwardataTCP(host, portNum, rawData, ws, respHeader, remoteConnW
502502
async function connectDirect(address, port, data, 所有反代数组 = null) {
503503
let remoteSock;
504504
if (所有反代数组 && 所有反代数组.length > 0) {
505-
for (const [反代地址, 反代端口] of 所有反代数组) {
505+
const 打乱后数组 = [...所有反代数组].sort(() => Math.random() - 0.5);
506+
const 最大尝试次数 = Math.min(8, 打乱后数组.length);
507+
for (let i = 0; i < 最大尝试次数; i++) {
508+
const [反代地址, 反代端口] = 打乱后数组[i];
506509
try {
507510
remoteSock = connect({ hostname: 反代地址, port: 反代端口 });
508511
const testWriter = remoteSock.writable.getWriter();

0 commit comments

Comments
 (0)