Brozy123 commited on
Commit
a3da372
·
verified ·
1 Parent(s): a056b84

Create ultimate_fix.js

Browse files
Files changed (1) hide show
  1. ultimate_fix.js +73 -0
ultimate_fix.js ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const dns = require('dns');
2
+ const tls = require('tls');
3
+ const http = require('http');
4
+ const https = require('https');
5
+
6
+ /**
7
+ * THE ULTIMATE FIX FOR HUGGING FACE SPACES
8
+ * This file forces the bot to bypass all network restrictions manually.
9
+ */
10
+
11
+ console.log(">>> [ULTIMATE FIX] Booting high-performance network bypass logic...");
12
+
13
+ // 1. Force the system to use IPv4 only everywhere
14
+ if (dns.setDefaultResultOrder) {
15
+ dns.setDefaultResultOrder('ipv4first');
16
+ }
17
+
18
+ // 2. Monkey-patch the global DNS system (Failsafe)
19
+ const originalLookup = dns.lookup;
20
+ dns.lookup = function(hostname, options, callback) {
21
+ if (typeof options === 'function') {
22
+ callback = options;
23
+ options = { family: 4 };
24
+ } else if (typeof options === 'number') {
25
+ options = { family: 4 };
26
+ } else if (!options) {
27
+ options = { family: 4 };
28
+ } else {
29
+ options.family = 4;
30
+ }
31
+ return originalLookup(hostname, options, callback);
32
+ };
33
+
34
+ // 3. Disable all SSL/TLS verification to prevent "socket disconnected" or "TLS handshake timeout"
35
+ // Hugging Face's internal proxy sometimes messes with certificates
36
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
37
+ tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
38
+ tls.DEFAULT_MAX_VERSION = 'TLSv1.3';
39
+
40
+ // 4. Force a fake Browser Identity globally
41
+ process.env.UNDICI_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36';
42
+
43
+ // 5. Build and set a Global Network Agent with massive timeouts
44
+ let dispatcher = null;
45
+ try {
46
+ const { setGlobalDispatcher, Agent } = require('undici');
47
+ dispatcher = new Agent({
48
+ connect: {
49
+ timeout: 120000, // 2 minutes
50
+ family: 4,
51
+ rejectUnauthorized: false,
52
+ keepAliveTimeout: 60000,
53
+ },
54
+ headersTimeout: 120000,
55
+ bodyTimeout: 120000,
56
+ pipelining: 0 // Disable pipelining for stability on unstable networks
57
+ });
58
+ setGlobalDispatcher(dispatcher);
59
+ global.fixedDispatcher = dispatcher;
60
+ console.log(">>> [ULTIMATE FIX] Global Undici Dispatcher active.");
61
+ } catch (e) {
62
+ console.warn(">>> [ULTIMATE FIX] Undici setup error:", e.message);
63
+ }
64
+
65
+ // 6. Fix legacy http/https modules too
66
+ http.globalAgent = new http.Agent({ family: 4, keepAlive: true });
67
+ https.globalAgent = new https.Agent({ family: 4, keepAlive: true, rejectUnauthorized: false });
68
+
69
+ console.log(">>> [ULTIMATE FIX] Network system hardened. IPv6/TLS roadblocks bypassed.");
70
+
71
+ module.exports = {
72
+ dispatcher: dispatcher || global.fixedDispatcher || null
73
+ };