Spaces:
Runtime error
Runtime error
Update network_fix.js
Browse files- network_fix.js +40 -11
network_fix.js
CHANGED
|
@@ -3,24 +3,34 @@ const http = require('http');
|
|
| 3 |
const dns = require('dns');
|
| 4 |
|
| 5 |
const DOMAINS = [
|
| 6 |
-
"discordapp.com",
|
| 7 |
"ptb.discord.com",
|
|
|
|
| 8 |
"canary.discord.com",
|
| 9 |
"discord.com"
|
| 10 |
];
|
| 11 |
let current_index = 0;
|
| 12 |
|
| 13 |
/**
|
| 14 |
-
*
|
| 15 |
-
*
|
| 16 |
*/
|
| 17 |
function applyAdvancedFixes() {
|
| 18 |
const target_domain = DOMAINS[current_index];
|
| 19 |
-
console.log(`[*] NetworkFix: Route -> ${target_domain}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36';
|
| 22 |
|
| 23 |
-
//
|
| 24 |
const _oldRequest = https.request;
|
| 25 |
https.request = function(options, callback) {
|
| 26 |
let opt = options;
|
|
@@ -31,14 +41,38 @@ function applyAdvancedFixes() {
|
|
| 31 |
} else {
|
| 32 |
opt.hostname = target_domain;
|
| 33 |
if (opt.host) opt.host = target_domain;
|
|
|
|
| 34 |
if (!opt.headers) opt.headers = {};
|
| 35 |
opt.headers['User-Agent'] = UA;
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
}
|
| 38 |
return _oldRequest.call(https, opt, callback);
|
| 39 |
};
|
| 40 |
|
| 41 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
| 43 |
if (globalObj.fetch) {
|
| 44 |
const _oldFetch = globalObj.fetch;
|
|
@@ -64,11 +98,6 @@ function applyAdvancedFixes() {
|
|
| 64 |
}
|
| 65 |
};
|
| 66 |
}
|
| 67 |
-
|
| 68 |
-
// Connectivity Tests
|
| 69 |
-
["google.com", "1.1.1.1"].forEach(d => {
|
| 70 |
-
dns.resolve4(d, (err, addrs) => console.log(`[*] DNS Check: ${d} -> ${err ? 'FAIL' : addrs[0]}`));
|
| 71 |
-
});
|
| 72 |
}
|
| 73 |
|
| 74 |
function rotateEndpoint() {
|
|
|
|
| 3 |
const dns = require('dns');
|
| 4 |
|
| 5 |
const DOMAINS = [
|
|
|
|
| 6 |
"ptb.discord.com",
|
| 7 |
+
"discordapp.com",
|
| 8 |
"canary.discord.com",
|
| 9 |
"discord.com"
|
| 10 |
];
|
| 11 |
let current_index = 0;
|
| 12 |
|
| 13 |
/**
|
| 14 |
+
* High-Stability Network Fix.
|
| 15 |
+
* Forces IPv4 and increases timeouts for slow cloud environments.
|
| 16 |
*/
|
| 17 |
function applyAdvancedFixes() {
|
| 18 |
const target_domain = DOMAINS[current_index];
|
| 19 |
+
console.log(`[*] NetworkFix: Active Route -> ${target_domain}`);
|
| 20 |
+
|
| 21 |
+
// 1. Force IPv4 for stability
|
| 22 |
+
dns.setDefaultResultOrder('ipv4first');
|
| 23 |
+
const _oldLookup = dns.lookup;
|
| 24 |
+
dns.lookup = function(hostname, options, callback) {
|
| 25 |
+
let opt = options || {};
|
| 26 |
+
if (typeof opt === 'function') { callback = opt; opt = { family: 4 }; }
|
| 27 |
+
else if (typeof opt === 'object') opt.family = 4;
|
| 28 |
+
return _oldLookup(hostname, opt, callback);
|
| 29 |
+
};
|
| 30 |
|
| 31 |
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36';
|
| 32 |
|
| 33 |
+
// 2. Patch https.request
|
| 34 |
const _oldRequest = https.request;
|
| 35 |
https.request = function(options, callback) {
|
| 36 |
let opt = options;
|
|
|
|
| 41 |
} else {
|
| 42 |
opt.hostname = target_domain;
|
| 43 |
if (opt.host) opt.host = target_domain;
|
| 44 |
+
opt.servername = target_domain;
|
| 45 |
if (!opt.headers) opt.headers = {};
|
| 46 |
opt.headers['User-Agent'] = UA;
|
| 47 |
+
opt.family = 4;
|
| 48 |
+
opt.timeout = 60000;
|
| 49 |
}
|
| 50 |
}
|
| 51 |
return _oldRequest.call(https, opt, callback);
|
| 52 |
};
|
| 53 |
|
| 54 |
+
// 3. Patch undici
|
| 55 |
+
try {
|
| 56 |
+
const undici = require('undici');
|
| 57 |
+
const connector = undici.buildConnector({ timeout: 60000 });
|
| 58 |
+
const dispatcher = new undici.Agent({
|
| 59 |
+
connect: (opts, cb) => {
|
| 60 |
+
let targetOpts = { ...opts };
|
| 61 |
+
if (opts.hostname.includes('discord')) {
|
| 62 |
+
targetOpts.hostname = target_domain;
|
| 63 |
+
targetOpts.servername = target_domain;
|
| 64 |
+
}
|
| 65 |
+
return connector(targetOpts, cb);
|
| 66 |
+
},
|
| 67 |
+
pipelining: 1,
|
| 68 |
+
keepAliveTimeout: 90000,
|
| 69 |
+
bodyTimeout: 90000,
|
| 70 |
+
headersTimeout: 90000
|
| 71 |
+
});
|
| 72 |
+
undici.setGlobalDispatcher(dispatcher);
|
| 73 |
+
} catch (e) {}
|
| 74 |
+
|
| 75 |
+
// 4. Patch global fetch
|
| 76 |
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
| 77 |
if (globalObj.fetch) {
|
| 78 |
const _oldFetch = globalObj.fetch;
|
|
|
|
| 98 |
}
|
| 99 |
};
|
| 100 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
}
|
| 102 |
|
| 103 |
function rotateEndpoint() {
|