Spaces:
Runtime error
Runtime error
Update network_fix.js
Browse files- network_fix.js +48 -24
network_fix.js
CHANGED
|
@@ -1,34 +1,58 @@
|
|
| 1 |
-
const { Agent, setGlobalDispatcher } = require('undici');
|
| 2 |
const https = require('https');
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
/**
|
| 5 |
-
*
|
| 6 |
-
*
|
| 7 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
function applyAdvancedFixes() {
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
https.globalAgent.options.family = 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
const resilientAgent = new Agent({
|
| 17 |
-
connect: {
|
| 18 |
-
timeout: 60000,
|
| 19 |
-
keepAlive: true,
|
| 20 |
-
family: 4
|
| 21 |
-
},
|
| 22 |
-
headersTimeout: 60000,
|
| 23 |
-
bodyTimeout: 60000,
|
| 24 |
-
pipelining: 1
|
| 25 |
-
});
|
| 26 |
-
|
| 27 |
-
setGlobalDispatcher(resilientAgent);
|
| 28 |
-
console.log('[NETWORK] Global network dispatcher optimized.');
|
| 29 |
-
} catch (err) {
|
| 30 |
-
console.error('[NETWORK] Dispatcher optimization failed:', err.message);
|
| 31 |
-
}
|
| 32 |
}
|
| 33 |
|
| 34 |
-
module.exports = { applyAdvancedFixes };
|
|
|
|
|
|
|
| 1 |
const https = require('https');
|
| 2 |
+
const http = require('http');
|
| 3 |
+
const dns = require('dns');
|
| 4 |
+
const { Agent, setGlobalDispatcher } = require('undici');
|
| 5 |
|
| 6 |
/**
|
| 7 |
+
* Professional Network Resilience Engine
|
| 8 |
+
* Implements a stealth failover system for restricted environments.
|
| 9 |
*/
|
| 10 |
+
|
| 11 |
+
const FALLBACK_DOMAINS = ['discordapp.com', 'ptb.discord.com', 'canary.discord.com', 'discord.com'];
|
| 12 |
+
let active_index = 0;
|
| 13 |
+
|
| 14 |
function applyAdvancedFixes() {
|
| 15 |
+
const target = FALLBACK_DOMAINS[active_index];
|
| 16 |
+
console.log(`[NETWORK] Stealth Failover Active: Using ${target} bridge.`);
|
| 17 |
+
|
| 18 |
+
// 1. Force IPv4 Priority (Standard for HF Stability)
|
| 19 |
+
if (dns.setDefaultResultOrder) dns.setDefaultResultOrder('ipv4first');
|
| 20 |
|
| 21 |
+
// 2. Low-Level DNS Hijacking
|
| 22 |
+
// This ensures that even if a library hardcodes 'discord.com', it gets the IP of our bridge.
|
| 23 |
+
const originalLookup = dns.lookup;
|
| 24 |
+
dns.lookup = function(hostname, options, callback) {
|
| 25 |
+
if (typeof options === 'function') { callback = options; options = {}; }
|
| 26 |
+
let h = hostname;
|
| 27 |
+
if (hostname.includes('discord.com') && !hostname.includes('gateway') && !hostname.includes(target)) {
|
| 28 |
+
h = target;
|
| 29 |
+
}
|
| 30 |
+
return originalLookup(h, options, callback);
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
// 3. Optimized Connection Pooling
|
| 34 |
+
const agent = new Agent({
|
| 35 |
+
connect: {
|
| 36 |
+
timeout: 30000,
|
| 37 |
+
family: 4,
|
| 38 |
+
servername: target // Critical for TLS Handshake consistency
|
| 39 |
+
},
|
| 40 |
+
pipelining: 1,
|
| 41 |
+
keepAliveTimeout: 60000
|
| 42 |
+
});
|
| 43 |
+
setGlobalDispatcher(agent);
|
| 44 |
+
|
| 45 |
+
// 4. Legacy Module Support
|
| 46 |
https.globalAgent.options.family = 4;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function rotateEndpoint() {
|
| 50 |
+
active_index = (active_index + 1) % FALLBACK_DOMAINS.length;
|
| 51 |
+
applyAdvancedFixes();
|
| 52 |
+
}
|
| 53 |
|
| 54 |
+
function getTargetDomain() {
|
| 55 |
+
return FALLBACK_DOMAINS[active_index];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
+
module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain };
|