Spaces:
Runtime error
Runtime error
fix: revert to standard connection logic with minimal IPv4 enforcement
Browse files- Dockerfile +4 -6
- index.js +1 -10
- network_fix.js +6 -44
Dockerfile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
FROM node:
|
| 2 |
|
| 3 |
-
# Install native dependencies
|
| 4 |
USER root
|
| 5 |
RUN apt-get update && apt-get install -y \
|
| 6 |
libfontconfig1 \
|
|
@@ -12,7 +12,6 @@ RUN apt-get update && apt-get install -y \
|
|
| 12 |
libgif-dev \
|
| 13 |
librsvg2-dev \
|
| 14 |
fonts-dejavu-core \
|
| 15 |
-
ca-certificates \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
USER node
|
|
@@ -27,8 +26,7 @@ EXPOSE 7860
|
|
| 27 |
|
| 28 |
ENV PORT=7860
|
| 29 |
ENV NODE_ENV=production
|
| 30 |
-
#
|
| 31 |
-
ENV NODE_OPTIONS="--dns-result-order=ipv4first
|
| 32 |
|
| 33 |
-
# Start with a direct script that forces the DNS servers
|
| 34 |
CMD ["node", "index.js"]
|
|
|
|
| 1 |
+
FROM node:20
|
| 2 |
|
| 3 |
+
# Install basic native dependencies
|
| 4 |
USER root
|
| 5 |
RUN apt-get update && apt-get install -y \
|
| 6 |
libfontconfig1 \
|
|
|
|
| 12 |
libgif-dev \
|
| 13 |
librsvg2-dev \
|
| 14 |
fonts-dejavu-core \
|
|
|
|
| 15 |
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
USER node
|
|
|
|
| 26 |
|
| 27 |
ENV PORT=7860
|
| 28 |
ENV NODE_ENV=production
|
| 29 |
+
# Just force IPv4, it's the safest single setting
|
| 30 |
+
ENV NODE_OPTIONS="--dns-result-order=ipv4first"
|
| 31 |
|
|
|
|
| 32 |
CMD ["node", "index.js"]
|
index.js
CHANGED
|
@@ -52,17 +52,8 @@ const client = new Client({
|
|
| 52 |
],
|
| 53 |
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
|
| 54 |
rest: {
|
| 55 |
-
timeout:
|
| 56 |
-
agent: networkFix.getDispatcher(),
|
| 57 |
},
|
| 58 |
-
// Impersonate a desktop client to bypass firewall connection killing
|
| 59 |
-
ws: {
|
| 60 |
-
properties: {
|
| 61 |
-
os: 'linux',
|
| 62 |
-
browser: 'Discord Client',
|
| 63 |
-
device: 'desktop'
|
| 64 |
-
}
|
| 65 |
-
}
|
| 66 |
});
|
| 67 |
|
| 68 |
console.log(`[*] Discord Client Initialized. Network hijacker will handle redirections.`);
|
|
|
|
| 52 |
],
|
| 53 |
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
|
| 54 |
rest: {
|
| 55 |
+
timeout: 120_000,
|
|
|
|
| 56 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
});
|
| 58 |
|
| 59 |
console.log(`[*] Discord Client Initialized. Network hijacker will handle redirections.`);
|
network_fix.js
CHANGED
|
@@ -1,58 +1,20 @@
|
|
| 1 |
const dns = require('dns');
|
| 2 |
-
const fs = require('fs');
|
| 3 |
-
const tls = require('tls');
|
| 4 |
|
| 5 |
/**
|
| 6 |
-
*
|
| 7 |
-
*
|
| 8 |
-
* 1. Overrides TLS to prevent socket drops.
|
| 9 |
-
* 2. Forces IPv4 strictly.
|
| 10 |
-
* 3. Monkey-patches dns.lookup to mask connection.
|
| 11 |
*/
|
| 12 |
-
|
| 13 |
function applyAdvancedFixes() {
|
| 14 |
-
console.log(`[NETWORK]
|
| 15 |
-
|
| 16 |
-
// 1. Force TLS to be permissive
|
| 17 |
-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
| 18 |
-
tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
|
| 19 |
-
|
| 20 |
-
// 2. Strict IPv4
|
| 21 |
if (dns.setDefaultResultOrder) {
|
| 22 |
dns.setDefaultResultOrder('ipv4first');
|
| 23 |
}
|
| 24 |
-
|
| 25 |
-
dns.lookup = function(hostname, options, callback) {
|
| 26 |
-
if (typeof options === 'function') { callback = options; options = { family: 4 }; }
|
| 27 |
-
else if (typeof options === 'number') { options = { family: 4 }; }
|
| 28 |
-
else if (!options) { options = { family: 4 }; }
|
| 29 |
-
else { options.family = 4; }
|
| 30 |
-
return originalLookup(hostname, options, callback);
|
| 31 |
-
};
|
| 32 |
-
|
| 33 |
-
// 3. Configure Network Dispatcher with 120s timeouts
|
| 34 |
-
try {
|
| 35 |
-
const { setGlobalDispatcher, Agent } = require('undici');
|
| 36 |
-
const agent = new Agent({
|
| 37 |
-
connect: {
|
| 38 |
-
timeout: 120_000,
|
| 39 |
-
family: 4,
|
| 40 |
-
rejectUnauthorized: false
|
| 41 |
-
},
|
| 42 |
-
headersTimeout: 120_000,
|
| 43 |
-
bodyTimeout: 120_000
|
| 44 |
-
});
|
| 45 |
-
setGlobalDispatcher(agent);
|
| 46 |
-
this._dispatcher = agent;
|
| 47 |
-
|
| 48 |
-
// Desktop User Agent
|
| 49 |
-
process.env.UNDICI_UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36';
|
| 50 |
-
} catch (e) {}
|
| 51 |
|
| 52 |
-
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
-
function getDispatcher() { return this._dispatcher; }
|
| 56 |
function rotateEndpoint() {}
|
| 57 |
function getTargetDomain() { return 'discord.com'; }
|
| 58 |
|
|
|
|
| 1 |
const dns = require('dns');
|
|
|
|
|
|
|
| 2 |
|
| 3 |
/**
|
| 4 |
+
* Super Simple Network Fix.
|
| 5 |
+
* Just forces IPv4, nothing else.
|
|
|
|
|
|
|
|
|
|
| 6 |
*/
|
|
|
|
| 7 |
function applyAdvancedFixes() {
|
| 8 |
+
console.log(`[NETWORK] Simplifying: Only forcing IPv4.`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
if (dns.setDefaultResultOrder) {
|
| 10 |
dns.setDefaultResultOrder('ipv4first');
|
| 11 |
}
|
| 12 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
function getDispatcher() {
|
| 15 |
+
return null; // Don't use a special agent
|
| 16 |
}
|
| 17 |
|
|
|
|
| 18 |
function rotateEndpoint() {}
|
| 19 |
function getTargetDomain() { return 'discord.com'; }
|
| 20 |
|