magnetk 2.2.5 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +37 -2
- package/download.js +1 -1
- package/package.json +1 -1
- package/share.js +3 -3
package/client.js
CHANGED
|
@@ -62,19 +62,30 @@ DISCOVERY_PRIORITY=dht,relay,direct
|
|
|
62
62
|
|
|
63
63
|
# ===== Chunking =====
|
|
64
64
|
CHUNK_SIZE_MB=1
|
|
65
|
+
ADAPTIVE_CHUNKING=true
|
|
65
66
|
MAX_PARALLEL_CHUNKS=10
|
|
67
|
+
|
|
68
|
+
# ===== Connection Strategy =====
|
|
69
|
+
# RELAY_ASSISTED: auto | true | false
|
|
70
|
+
# auto = try direct P2P first, fall back to relay if unreachable
|
|
71
|
+
# true = always route data through relay (privacy mode)
|
|
72
|
+
# false = direct P2P only, fail if unreachable
|
|
73
|
+
RELAY_ASSISTED=auto
|
|
74
|
+
# HOLE_PUNCH: Enable NAT traversal via STUN + libp2p hole punching
|
|
75
|
+
HOLE_PUNCH=true
|
|
76
|
+
# RELAY_TIMEOUT_MS: How long to wait for direct connection before relay fallback
|
|
77
|
+
RELAY_TIMEOUT_MS=5000
|
|
66
78
|
`;
|
|
67
79
|
|
|
68
80
|
export class MagnetkClient extends EventEmitter {
|
|
69
81
|
constructor(config = {}) {
|
|
70
82
|
super();
|
|
71
83
|
this.config = {
|
|
72
|
-
// Relay settings (supports multiple relays for failover)
|
|
84
|
+
// Relay settings (supports multiple relays for failover/scaling)
|
|
73
85
|
relayUrl: '69.169.109.243',
|
|
74
86
|
relayPort: 4003,
|
|
75
87
|
relays: [], // Array of {host, port} for multi-relay failover
|
|
76
88
|
seedPort: 4002,
|
|
77
|
-
enableSTUN: true,
|
|
78
89
|
seederPath: null,
|
|
79
90
|
configPath: null,
|
|
80
91
|
|
|
@@ -83,6 +94,13 @@ export class MagnetkClient extends EventEmitter {
|
|
|
83
94
|
dhtBootstrapPeers: [], // Custom bootstrap peer multiaddrs
|
|
84
95
|
discoveryPriority: ['dht', 'relay', 'direct'], // Discovery order
|
|
85
96
|
|
|
97
|
+
// Connection strategy
|
|
98
|
+
stunServers: ['stun:stun.l.google.com:19302'], // STUN servers for NAT traversal
|
|
99
|
+
holePunch: true, // Enable NAT hole punching (STUN first, relay fallback)
|
|
100
|
+
relayAssisted: 'auto', // 'auto' | true | false — relay-assisted data transfer
|
|
101
|
+
enableRelayFallback: true, // Fall back to relay if direct P2P fails
|
|
102
|
+
relayTimeout: 5000, // ms to wait for direct connection before relay fallback
|
|
103
|
+
|
|
86
104
|
// Auto-config: create settings.conf if missing
|
|
87
105
|
autoConfig: true,
|
|
88
106
|
...config
|
|
@@ -307,6 +325,23 @@ export class MagnetkClient extends EventEmitter {
|
|
|
307
325
|
args.push('-bootstrap', this.config.dhtBootstrapPeers.join(','));
|
|
308
326
|
}
|
|
309
327
|
|
|
328
|
+
// Connection strategy flags
|
|
329
|
+
if (this.config.holePunch) {
|
|
330
|
+
args.push('-holepunch');
|
|
331
|
+
}
|
|
332
|
+
if (this.config.relayAssisted !== undefined) {
|
|
333
|
+
const mode = this.config.relayAssisted === true ? 'true'
|
|
334
|
+
: this.config.relayAssisted === false ? 'false'
|
|
335
|
+
: this.config.relayAssisted;
|
|
336
|
+
args.push('-relay-assisted', mode);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Multi-relay: pass additional relay addresses
|
|
340
|
+
if (this.config.relays && this.config.relays.length > 0) {
|
|
341
|
+
const relayAddrs = this.config.relays.map(r => `${r.host}:${r.port}`).join(',');
|
|
342
|
+
args.push('-relay-addresses', relayAddrs);
|
|
343
|
+
}
|
|
344
|
+
|
|
310
345
|
console.log(`[Magnetk-JS] Spawning seeder: ${binPath} ${args.join(' ')}`);
|
|
311
346
|
|
|
312
347
|
return new Promise((resolve, reject) => {
|
package/download.js
CHANGED
package/package.json
CHANGED
package/share.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MagnetkClient } from '
|
|
1
|
+
import { MagnetkClient } from './client.js';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import 'dotenv/config';
|
|
3
|
+
// import 'dotenv/config';
|
|
4
4
|
|
|
5
5
|
const filePath = "./app.txt";
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ async function share() {
|
|
|
9
9
|
relayUrl: '69.169.109.243', // Default to local for dev, change to public IPs for prod
|
|
10
10
|
relayPort: 4003,
|
|
11
11
|
seederPath: process.env.MAGNETK_SEEDER_PATH,
|
|
12
|
-
seedPort:
|
|
12
|
+
seedPort: 4002 // Data transfer port (must not conflict with relay 4003)
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
console.log(`[Share] Preparing to share: ${filePath}`);
|