Barza commited on
Commit
e0115e1
·
1 Parent(s): 1a21773

fix: downgrade to Node 18 and apply Deep Handshake fix for stubborn HF networking

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. network_fix.js +22 -19
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM node:20
2
 
3
  # Install native dependencies required by @napi-rs/canvas for image rendering
4
  USER root
 
1
+ FROM node:18-slim
2
 
3
  # Install native dependencies required by @napi-rs/canvas for image rendering
4
  USER root
network_fix.js CHANGED
@@ -1,25 +1,28 @@
1
  const dns = require('dns');
2
  const fs = require('fs');
 
3
 
4
  /**
5
- * GHOST MODE Fix for Hugging Face.
6
  *
7
- * This fix masks the bot's connection and ignores all TLS security checks
8
- * to prevent the firewall from dropping the socket.
 
 
9
  */
10
 
11
  function applyAdvancedFixes() {
12
- console.log(`[NETWORK] Activating Ghost Mode (TLS Bypass)...`);
13
 
14
- // 1. Force IPv4
 
 
 
 
 
15
  if (dns.setDefaultResultOrder) {
16
  dns.setDefaultResultOrder('ipv4first');
17
  }
18
-
19
- // 2. Disable TLS verification globally - prevents "socket disconnected before secure TLS"
20
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
21
-
22
- // 3. Force DNS lookup to family 4
23
  const originalLookup = dns.lookup;
24
  dns.lookup = function(hostname, options, callback) {
25
  if (typeof options === 'function') { callback = options; options = { family: 4 }; }
@@ -29,31 +32,31 @@ function applyAdvancedFixes() {
29
  return originalLookup(hostname, options, callback);
30
  };
31
 
32
- // 4. Configure Undici with a Browser User-Agent
33
  try {
34
  const { setGlobalDispatcher, Agent } = require('undici');
35
  const agent = new Agent({
36
  connect: {
37
- timeout: 60_000,
38
  family: 4,
39
  rejectUnauthorized: false
40
  },
41
- // Impersonate a real browser
42
- headersTimeout: 60_000,
43
- bodyTimeout: 60_000
44
  });
45
  setGlobalDispatcher(agent);
46
  this._dispatcher = agent;
47
 
48
- // Globally set a browser-like User Agent
49
- process.env.UNDICI_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
50
  } catch (e) {}
51
 
52
- console.log('[NETWORK] Ghost Mode Active. TLS checks disabled.');
53
  }
54
 
55
  function getDispatcher() { return this._dispatcher; }
56
  function rotateEndpoint() {}
57
- function getTargetDomain() { return 'discord.com'; }
58
 
59
  module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain, getDispatcher };
 
1
  const dns = require('dns');
2
  const fs = require('fs');
3
+ const tls = require('tls');
4
 
5
  /**
6
+ * DEEP HANDSHAKE Fix for Hugging Face.
7
  *
8
+ * This is the ultimate connection attempt:
9
+ * 1. Forces IPv4 strictly.
10
+ * 2. Overrides TLS protocols to allow older handshakes.
11
+ * 3. Impersonates a stable browser environment.
12
  */
13
 
14
  function applyAdvancedFixes() {
15
+ console.log(`[NETWORK] Activating Deep Handshake fix...`);
16
 
17
+ // 1. Force TLS/SSL to be extremely permissive
18
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
19
+ tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
20
+ tls.DEFAULT_MAX_VERSION = 'TLSv1.3';
21
+
22
+ // 2. Strict IPv4 DNS
23
  if (dns.setDefaultResultOrder) {
24
  dns.setDefaultResultOrder('ipv4first');
25
  }
 
 
 
 
 
26
  const originalLookup = dns.lookup;
27
  dns.lookup = function(hostname, options, callback) {
28
  if (typeof options === 'function') { callback = options; options = { family: 4 }; }
 
32
  return originalLookup(hostname, options, callback);
33
  };
34
 
35
+ // 3. Configure Network Dispatcher
36
  try {
37
  const { setGlobalDispatcher, Agent } = require('undici');
38
  const agent = new Agent({
39
  connect: {
40
+ timeout: 90_000,
41
  family: 4,
42
  rejectUnauthorized: false
43
  },
44
+ headersTimeout: 90_000,
45
+ bodyTimeout: 90_000,
46
+ maxRedirections: 10
47
  });
48
  setGlobalDispatcher(agent);
49
  this._dispatcher = agent;
50
 
51
+ // Browser masking headers
52
+ 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';
53
  } catch (e) {}
54
 
55
+ console.log('[NETWORK] Handshake protocols relaxed. Outbound IPv4 ready.');
56
  }
57
 
58
  function getDispatcher() { return this._dispatcher; }
59
  function rotateEndpoint() {}
60
+ function getTargetDomain() { return 'discord.gg'; } // Try targeting gateway domain for status checks
61
 
62
  module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain, getDispatcher };