@dxos/network-manager 0.3.9-main.14901ff → 0.3.9-main.1b9ffda
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/dist/lib/browser/{chunk-S2JHWVGQ.mjs → chunk-KGZ5C6JO.mjs} +93 -31
- package/dist/lib/browser/{chunk-S2JHWVGQ.mjs.map → chunk-KGZ5C6JO.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-DMWORJG3.cjs → chunk-JDKM4UPJ.cjs} +12 -13
- package/dist/lib/node/chunk-JDKM4UPJ.cjs.map +7 -0
- package/dist/lib/node/{chunk-3SCPMSHV.cjs → chunk-WUBZ4UOJ.cjs} +99 -37
- package/dist/lib/node/{chunk-3SCPMSHV.cjs.map → chunk-WUBZ4UOJ.cjs.map} +3 -3
- package/dist/lib/node/{datachannel-ABYQKZRC.cjs → datachannel-3VTTIMR5.cjs} +9 -9
- package/dist/lib/node/{datachannel-ABYQKZRC.cjs.map → datachannel-3VTTIMR5.cjs.map} +2 -2
- package/dist/lib/node/index.cjs +32 -32
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +19 -19
- package/dist/types/src/topology/mmst-topology.d.ts +1 -0
- package/dist/types/src/topology/mmst-topology.d.ts.map +1 -1
- package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts +3 -0
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/topology/mmst-topology.ts +34 -6
- package/src/transport/datachannel/rtc-peer-connection.ts +7 -11
- package/src/transport/libdatachannel-transport.test.ts +0 -4
- package/src/transport/simplepeer-transport.ts +5 -3
- package/dist/lib/node/chunk-DMWORJG3.cjs.map +0 -7
|
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_WUBZ4UOJ_exports = {};
|
|
30
|
+
__export(chunk_WUBZ4UOJ_exports, {
|
|
31
31
|
Connection: () => Connection,
|
|
32
32
|
ConnectionLimiter: () => ConnectionLimiter,
|
|
33
33
|
ConnectionLog: () => ConnectionLog,
|
|
@@ -55,8 +55,8 @@ __export(chunk_3SCPMSHV_exports, {
|
|
|
55
55
|
createSimplePeerTransportFactory: () => createSimplePeerTransportFactory,
|
|
56
56
|
createTeleportProtocolFactory: () => createTeleportProtocolFactory
|
|
57
57
|
});
|
|
58
|
-
module.exports = __toCommonJS(
|
|
59
|
-
var
|
|
58
|
+
module.exports = __toCommonJS(chunk_WUBZ4UOJ_exports);
|
|
59
|
+
var import_chunk_JDKM4UPJ = require("./chunk-JDKM4UPJ.cjs");
|
|
60
60
|
var import_async = require("@dxos/async");
|
|
61
61
|
var import_context = require("@dxos/context");
|
|
62
62
|
var import_debug = require("@dxos/debug");
|
|
@@ -2415,9 +2415,12 @@ var FullyConnectedTopology = class {
|
|
|
2415
2415
|
}
|
|
2416
2416
|
};
|
|
2417
2417
|
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2418
|
+
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2419
|
+
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2418
2420
|
var MMSTTopology = class {
|
|
2419
2421
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2420
2422
|
this._sampleCollected = false;
|
|
2423
|
+
this._lastAction = /* @__PURE__ */ new Date(0);
|
|
2421
2424
|
this._originateConnections = originateConnections;
|
|
2422
2425
|
this._maxPeers = maxPeers;
|
|
2423
2426
|
this._sampleSize = sampleSize;
|
|
@@ -2425,7 +2428,7 @@ var MMSTTopology = class {
|
|
|
2425
2428
|
init(controller) {
|
|
2426
2429
|
(0, import_invariant8.invariant)(!this._controller, "Already initialized", {
|
|
2427
2430
|
F: __dxlog_file9,
|
|
2428
|
-
L:
|
|
2431
|
+
L: 51,
|
|
2429
2432
|
S: this,
|
|
2430
2433
|
A: [
|
|
2431
2434
|
"!this._controller",
|
|
@@ -2437,7 +2440,7 @@ var MMSTTopology = class {
|
|
|
2437
2440
|
update() {
|
|
2438
2441
|
(0, import_invariant8.invariant)(this._controller, "Not initialized", {
|
|
2439
2442
|
F: __dxlog_file9,
|
|
2440
|
-
L:
|
|
2443
|
+
L: 56,
|
|
2441
2444
|
S: this,
|
|
2442
2445
|
A: [
|
|
2443
2446
|
"this._controller",
|
|
@@ -2448,7 +2451,7 @@ var MMSTTopology = class {
|
|
|
2448
2451
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2449
2452
|
(0, import_log8.log)("Running the algorithm.", void 0, {
|
|
2450
2453
|
F: __dxlog_file9,
|
|
2451
|
-
L:
|
|
2454
|
+
L: 60,
|
|
2452
2455
|
S: this,
|
|
2453
2456
|
C: (f, a) => f(...a)
|
|
2454
2457
|
});
|
|
@@ -2459,7 +2462,7 @@ var MMSTTopology = class {
|
|
|
2459
2462
|
async onOffer(peer) {
|
|
2460
2463
|
(0, import_invariant8.invariant)(this._controller, "Not initialized", {
|
|
2461
2464
|
F: __dxlog_file9,
|
|
2462
|
-
L:
|
|
2465
|
+
L: 67,
|
|
2463
2466
|
S: this,
|
|
2464
2467
|
A: [
|
|
2465
2468
|
"this._controller",
|
|
@@ -2470,7 +2473,7 @@ var MMSTTopology = class {
|
|
|
2470
2473
|
const accept = connected.length < this._maxPeers;
|
|
2471
2474
|
(0, import_log8.log)(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2472
2475
|
F: __dxlog_file9,
|
|
2473
|
-
L:
|
|
2476
|
+
L: 70,
|
|
2474
2477
|
S: this,
|
|
2475
2478
|
C: (f, a) => f(...a)
|
|
2476
2479
|
});
|
|
@@ -2481,7 +2484,7 @@ var MMSTTopology = class {
|
|
|
2481
2484
|
_runAlgorithm() {
|
|
2482
2485
|
(0, import_invariant8.invariant)(this._controller, "Not initialized", {
|
|
2483
2486
|
F: __dxlog_file9,
|
|
2484
|
-
L:
|
|
2487
|
+
L: 79,
|
|
2485
2488
|
S: this,
|
|
2486
2489
|
A: [
|
|
2487
2490
|
"this._controller",
|
|
@@ -2490,27 +2493,84 @@ var MMSTTopology = class {
|
|
|
2490
2493
|
});
|
|
2491
2494
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2492
2495
|
if (connected.length > this._maxPeers) {
|
|
2496
|
+
(0, import_log8.log)(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2497
|
+
F: __dxlog_file9,
|
|
2498
|
+
L: 85,
|
|
2499
|
+
S: this,
|
|
2500
|
+
C: (f, a) => f(...a)
|
|
2501
|
+
});
|
|
2493
2502
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2494
|
-
|
|
2495
|
-
|
|
2503
|
+
(0, import_invariant8.invariant)(sorted.length === 0, void 0, {
|
|
2504
|
+
F: __dxlog_file9,
|
|
2505
|
+
L: 89,
|
|
2506
|
+
S: this,
|
|
2507
|
+
A: [
|
|
2508
|
+
"sorted.length === 0",
|
|
2509
|
+
""
|
|
2510
|
+
]
|
|
2511
|
+
});
|
|
2512
|
+
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2513
|
+
(0, import_log8.log)(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2496
2514
|
F: __dxlog_file9,
|
|
2497
|
-
L:
|
|
2515
|
+
L: 92,
|
|
2516
|
+
S: this,
|
|
2517
|
+
C: (f, a) => f(...a)
|
|
2518
|
+
});
|
|
2519
|
+
}
|
|
2520
|
+
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2521
|
+
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2522
|
+
(0, import_log8.log)(`Disconnect ${peer}.`, void 0, {
|
|
2523
|
+
F: __dxlog_file9,
|
|
2524
|
+
L: 97,
|
|
2525
|
+
S: this,
|
|
2526
|
+
C: (f, a) => f(...a)
|
|
2527
|
+
});
|
|
2528
|
+
this._controller.disconnect(peer);
|
|
2529
|
+
}
|
|
2530
|
+
this._lastAction = /* @__PURE__ */ new Date();
|
|
2531
|
+
} else {
|
|
2532
|
+
(0, import_log8.log)("rate limited discconnect", void 0, {
|
|
2533
|
+
F: __dxlog_file9,
|
|
2534
|
+
L: 102,
|
|
2498
2535
|
S: this,
|
|
2499
2536
|
C: (f, a) => f(...a)
|
|
2500
2537
|
});
|
|
2501
|
-
this._controller.disconnect(peer);
|
|
2502
2538
|
}
|
|
2503
2539
|
} else if (connected.length < this._originateConnections) {
|
|
2540
|
+
(0, import_log8.log)(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2541
|
+
F: __dxlog_file9,
|
|
2542
|
+
L: 106,
|
|
2543
|
+
S: this,
|
|
2544
|
+
C: (f, a) => f(...a)
|
|
2545
|
+
});
|
|
2504
2546
|
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2505
2547
|
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2506
|
-
|
|
2507
|
-
(0, import_log8.log)(`
|
|
2548
|
+
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2549
|
+
(0, import_log8.log)(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2508
2550
|
F: __dxlog_file9,
|
|
2509
|
-
L:
|
|
2551
|
+
L: 111,
|
|
2552
|
+
S: this,
|
|
2553
|
+
C: (f, a) => f(...a)
|
|
2554
|
+
});
|
|
2555
|
+
}
|
|
2556
|
+
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2557
|
+
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2558
|
+
(0, import_log8.log)(`Connect ${peer}.`, void 0, {
|
|
2559
|
+
F: __dxlog_file9,
|
|
2560
|
+
L: 115,
|
|
2561
|
+
S: this,
|
|
2562
|
+
C: (f, a) => f(...a)
|
|
2563
|
+
});
|
|
2564
|
+
this._controller.connect(peer);
|
|
2565
|
+
}
|
|
2566
|
+
this._lastAction = /* @__PURE__ */ new Date();
|
|
2567
|
+
} else {
|
|
2568
|
+
(0, import_log8.log)("rate limited connect", void 0, {
|
|
2569
|
+
F: __dxlog_file9,
|
|
2570
|
+
L: 120,
|
|
2510
2571
|
S: this,
|
|
2511
2572
|
C: (f, a) => f(...a)
|
|
2512
2573
|
});
|
|
2513
|
-
this._controller.connect(peer);
|
|
2514
2574
|
}
|
|
2515
2575
|
}
|
|
2516
2576
|
}
|
|
@@ -2811,11 +2871,14 @@ var TransportKind;
|
|
|
2811
2871
|
})(TransportKind || (TransportKind = {}));
|
|
2812
2872
|
var wrtc = null;
|
|
2813
2873
|
try {
|
|
2814
|
-
wrtc = (0,
|
|
2874
|
+
wrtc = (0, import_chunk_JDKM4UPJ.__require)("@koush/wrtc");
|
|
2815
2875
|
} catch {
|
|
2816
2876
|
}
|
|
2817
2877
|
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
|
|
2818
2878
|
var SimplePeerTransport = class {
|
|
2879
|
+
/**
|
|
2880
|
+
* @params opts.config formatted as per https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
|
|
2881
|
+
*/
|
|
2819
2882
|
constructor(params) {
|
|
2820
2883
|
this.params = params;
|
|
2821
2884
|
this._closed = false;
|
|
@@ -2828,13 +2891,13 @@ var SimplePeerTransport = class {
|
|
|
2828
2891
|
id: this._instanceId
|
|
2829
2892
|
}), {
|
|
2830
2893
|
F: __dxlog_file12,
|
|
2831
|
-
L:
|
|
2894
|
+
L: 44,
|
|
2832
2895
|
S: this,
|
|
2833
2896
|
C: (f, a) => f(...a)
|
|
2834
2897
|
});
|
|
2835
2898
|
(0, import_log11.log)("created connection", params, {
|
|
2836
2899
|
F: __dxlog_file12,
|
|
2837
|
-
L:
|
|
2900
|
+
L: 45,
|
|
2838
2901
|
S: this,
|
|
2839
2902
|
C: (f, a) => f(...a)
|
|
2840
2903
|
});
|
|
@@ -2847,7 +2910,7 @@ var SimplePeerTransport = class {
|
|
|
2847
2910
|
this._peer.on("signal", async (data) => {
|
|
2848
2911
|
(0, import_log11.log)("signal", data, {
|
|
2849
2912
|
F: __dxlog_file12,
|
|
2850
|
-
L:
|
|
2913
|
+
L: 54,
|
|
2851
2914
|
S: this,
|
|
2852
2915
|
C: (f, a) => f(...a)
|
|
2853
2916
|
});
|
|
@@ -2860,7 +2923,7 @@ var SimplePeerTransport = class {
|
|
|
2860
2923
|
this._peer.on("connect", () => {
|
|
2861
2924
|
(0, import_log11.log)("connected", void 0, {
|
|
2862
2925
|
F: __dxlog_file12,
|
|
2863
|
-
L:
|
|
2926
|
+
L: 59,
|
|
2864
2927
|
S: this,
|
|
2865
2928
|
C: (f, a) => f(...a)
|
|
2866
2929
|
});
|
|
@@ -2871,7 +2934,7 @@ var SimplePeerTransport = class {
|
|
|
2871
2934
|
this._peer.on("close", async () => {
|
|
2872
2935
|
(0, import_log11.log)("closed", void 0, {
|
|
2873
2936
|
F: __dxlog_file12,
|
|
2874
|
-
L:
|
|
2937
|
+
L: 66,
|
|
2875
2938
|
S: this,
|
|
2876
2939
|
C: (f, a) => f(...a)
|
|
2877
2940
|
});
|
|
@@ -2886,7 +2949,7 @@ var SimplePeerTransport = class {
|
|
|
2886
2949
|
err
|
|
2887
2950
|
}, {
|
|
2888
2951
|
F: __dxlog_file12,
|
|
2889
|
-
L:
|
|
2952
|
+
L: 77,
|
|
2890
2953
|
S: this,
|
|
2891
2954
|
C: (f, a) => f(...a)
|
|
2892
2955
|
});
|
|
@@ -2895,7 +2958,7 @@ var SimplePeerTransport = class {
|
|
|
2895
2958
|
} else if ("code" in err) {
|
|
2896
2959
|
import_log11.log.info("simple-peer error", err, {
|
|
2897
2960
|
F: __dxlog_file12,
|
|
2898
|
-
L:
|
|
2961
|
+
L: 82,
|
|
2899
2962
|
S: this,
|
|
2900
2963
|
C: (f, a) => f(...a)
|
|
2901
2964
|
});
|
|
@@ -2925,7 +2988,7 @@ var SimplePeerTransport = class {
|
|
|
2925
2988
|
} else {
|
|
2926
2989
|
import_log11.log.info("unknown peer connection error", err, {
|
|
2927
2990
|
F: __dxlog_file12,
|
|
2928
|
-
L:
|
|
2991
|
+
L: 108,
|
|
2929
2992
|
S: this,
|
|
2930
2993
|
C: (f, a) => f(...a)
|
|
2931
2994
|
});
|
|
@@ -2939,7 +3002,7 @@ var SimplePeerTransport = class {
|
|
|
2939
3002
|
stats: Object.fromEntries(stats.entries())
|
|
2940
3003
|
}, {
|
|
2941
3004
|
F: __dxlog_file12,
|
|
2942
|
-
L:
|
|
3005
|
+
L: 116,
|
|
2943
3006
|
S: this,
|
|
2944
3007
|
C: (f, a) => f(...a)
|
|
2945
3008
|
});
|
|
@@ -2948,7 +3011,7 @@ var SimplePeerTransport = class {
|
|
|
2948
3011
|
} catch (err2) {
|
|
2949
3012
|
import_log11.log.catch(err2, void 0, {
|
|
2950
3013
|
F: __dxlog_file12,
|
|
2951
|
-
L:
|
|
3014
|
+
L: 123,
|
|
2952
3015
|
S: this,
|
|
2953
3016
|
C: (f, a) => f(...a)
|
|
2954
3017
|
});
|
|
@@ -2959,7 +3022,7 @@ var SimplePeerTransport = class {
|
|
|
2959
3022
|
id: this._instanceId
|
|
2960
3023
|
}), {
|
|
2961
3024
|
F: __dxlog_file12,
|
|
2962
|
-
L:
|
|
3025
|
+
L: 129,
|
|
2963
3026
|
S: this,
|
|
2964
3027
|
C: (f, a) => f(...a)
|
|
2965
3028
|
});
|
|
@@ -3012,29 +3075,28 @@ var SimplePeerTransport = class {
|
|
|
3012
3075
|
if (!rc) {
|
|
3013
3076
|
return "unavailable";
|
|
3014
3077
|
}
|
|
3015
|
-
if (rc.relay) {
|
|
3016
|
-
return `${rc.ip}:${rc.port}/${rc.protocol} relay for
|
|
3078
|
+
if (rc.candidateType === "relay") {
|
|
3079
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
3017
3080
|
}
|
|
3018
3081
|
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
3019
3082
|
}
|
|
3020
3083
|
async destroy() {
|
|
3021
3084
|
(0, import_log11.log)("closing...", void 0, {
|
|
3022
3085
|
F: __dxlog_file12,
|
|
3023
|
-
L:
|
|
3086
|
+
L: 192,
|
|
3024
3087
|
S: this,
|
|
3025
3088
|
C: (f, a) => f(...a)
|
|
3026
3089
|
});
|
|
3027
3090
|
if (this._closed) {
|
|
3028
3091
|
return;
|
|
3029
3092
|
}
|
|
3030
|
-
this._closed = true;
|
|
3031
3093
|
this._disconnectStreams();
|
|
3032
3094
|
this._peer.destroy();
|
|
3033
3095
|
this._closed = true;
|
|
3034
3096
|
this.closed.emit();
|
|
3035
3097
|
(0, import_log11.log)("closed", void 0, {
|
|
3036
3098
|
F: __dxlog_file12,
|
|
3037
|
-
L:
|
|
3099
|
+
L: 200,
|
|
3038
3100
|
S: this,
|
|
3039
3101
|
C: (f, a) => f(...a)
|
|
3040
3102
|
});
|
|
@@ -3455,7 +3517,7 @@ var LibDataChannelTransport = class {
|
|
|
3455
3517
|
this._readyForCandidates = new import_async11.Trigger();
|
|
3456
3518
|
this._writeCallback = null;
|
|
3457
3519
|
this._peer = (async () => {
|
|
3458
|
-
const { RTCPeerConnection: PeerConnection } = await import("./datachannel-
|
|
3520
|
+
const { RTCPeerConnection: PeerConnection } = await import("./datachannel-3VTTIMR5.cjs");
|
|
3459
3521
|
if (this._closed) {
|
|
3460
3522
|
this.errors.raise(new Error("connection already closed"));
|
|
3461
3523
|
}
|
|
@@ -3995,4 +4057,4 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
3995
4057
|
createSimplePeerTransportFactory,
|
|
3996
4058
|
createTeleportProtocolFactory
|
|
3997
4059
|
});
|
|
3998
|
-
//# sourceMappingURL=chunk-
|
|
4060
|
+
//# sourceMappingURL=chunk-WUBZ4UOJ.cjs.map
|