@dxos/network-manager 0.3.9-main.3ced312 → 0.3.9-main.4e30508
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-HJ6JLRZM.mjs → chunk-J7KS7JMZ.mjs} +76 -16
- package/dist/lib/browser/{chunk-HJ6JLRZM.mjs.map → chunk-J7KS7JMZ.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-XZF4MAFB.cjs → chunk-55WTPQV5.cjs} +79 -19
- package/dist/lib/node/{chunk-XZF4MAFB.cjs.map → chunk-55WTPQV5.cjs.map} +3 -3
- package/dist/lib/node/index.cjs +27 -27
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +18 -18
- package/dist/types/src/topology/mmst-topology.d.ts +1 -0
- package/dist/types/src/topology/mmst-topology.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/topology/mmst-topology.ts +35 -7
|
@@ -2349,9 +2349,12 @@ import distance from "xor-distance";
|
|
|
2349
2349
|
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2350
2350
|
import { log as log8 } from "@dxos/log";
|
|
2351
2351
|
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2352
|
+
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2353
|
+
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2352
2354
|
var MMSTTopology = class {
|
|
2353
2355
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2354
2356
|
this._sampleCollected = false;
|
|
2357
|
+
this._lastAction = /* @__PURE__ */ new Date(0);
|
|
2355
2358
|
this._originateConnections = originateConnections;
|
|
2356
2359
|
this._maxPeers = maxPeers;
|
|
2357
2360
|
this._sampleSize = sampleSize;
|
|
@@ -2359,7 +2362,7 @@ var MMSTTopology = class {
|
|
|
2359
2362
|
init(controller) {
|
|
2360
2363
|
invariant8(!this._controller, "Already initialized", {
|
|
2361
2364
|
F: __dxlog_file9,
|
|
2362
|
-
L:
|
|
2365
|
+
L: 51,
|
|
2363
2366
|
S: this,
|
|
2364
2367
|
A: [
|
|
2365
2368
|
"!this._controller",
|
|
@@ -2371,7 +2374,7 @@ var MMSTTopology = class {
|
|
|
2371
2374
|
update() {
|
|
2372
2375
|
invariant8(this._controller, "Not initialized", {
|
|
2373
2376
|
F: __dxlog_file9,
|
|
2374
|
-
L:
|
|
2377
|
+
L: 56,
|
|
2375
2378
|
S: this,
|
|
2376
2379
|
A: [
|
|
2377
2380
|
"this._controller",
|
|
@@ -2380,9 +2383,9 @@ var MMSTTopology = class {
|
|
|
2380
2383
|
});
|
|
2381
2384
|
const { connected, candidates } = this._controller.getState();
|
|
2382
2385
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2383
|
-
log8("Running the algorithm.", void 0, {
|
|
2386
|
+
log8.info("Running the algorithm.", void 0, {
|
|
2384
2387
|
F: __dxlog_file9,
|
|
2385
|
-
L:
|
|
2388
|
+
L: 60,
|
|
2386
2389
|
S: this,
|
|
2387
2390
|
C: (f, a) => f(...a)
|
|
2388
2391
|
});
|
|
@@ -2393,7 +2396,7 @@ var MMSTTopology = class {
|
|
|
2393
2396
|
async onOffer(peer) {
|
|
2394
2397
|
invariant8(this._controller, "Not initialized", {
|
|
2395
2398
|
F: __dxlog_file9,
|
|
2396
|
-
L:
|
|
2399
|
+
L: 67,
|
|
2397
2400
|
S: this,
|
|
2398
2401
|
A: [
|
|
2399
2402
|
"this._controller",
|
|
@@ -2404,7 +2407,7 @@ var MMSTTopology = class {
|
|
|
2404
2407
|
const accept = connected.length < this._maxPeers;
|
|
2405
2408
|
log8(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2406
2409
|
F: __dxlog_file9,
|
|
2407
|
-
L:
|
|
2410
|
+
L: 70,
|
|
2408
2411
|
S: this,
|
|
2409
2412
|
C: (f, a) => f(...a)
|
|
2410
2413
|
});
|
|
@@ -2415,7 +2418,7 @@ var MMSTTopology = class {
|
|
|
2415
2418
|
_runAlgorithm() {
|
|
2416
2419
|
invariant8(this._controller, "Not initialized", {
|
|
2417
2420
|
F: __dxlog_file9,
|
|
2418
|
-
L:
|
|
2421
|
+
L: 79,
|
|
2419
2422
|
S: this,
|
|
2420
2423
|
A: [
|
|
2421
2424
|
"this._controller",
|
|
@@ -2424,27 +2427,84 @@ var MMSTTopology = class {
|
|
|
2424
2427
|
});
|
|
2425
2428
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2426
2429
|
if (connected.length > this._maxPeers) {
|
|
2430
|
+
log8.info(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2431
|
+
F: __dxlog_file9,
|
|
2432
|
+
L: 85,
|
|
2433
|
+
S: this,
|
|
2434
|
+
C: (f, a) => f(...a)
|
|
2435
|
+
});
|
|
2427
2436
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2428
|
-
|
|
2429
|
-
|
|
2437
|
+
invariant8(sorted.length === 0, void 0, {
|
|
2438
|
+
F: __dxlog_file9,
|
|
2439
|
+
L: 89,
|
|
2440
|
+
S: this,
|
|
2441
|
+
A: [
|
|
2442
|
+
"sorted.length === 0",
|
|
2443
|
+
""
|
|
2444
|
+
]
|
|
2445
|
+
});
|
|
2446
|
+
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2447
|
+
log8(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2430
2448
|
F: __dxlog_file9,
|
|
2431
|
-
L:
|
|
2449
|
+
L: 92,
|
|
2450
|
+
S: this,
|
|
2451
|
+
C: (f, a) => f(...a)
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2455
|
+
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2456
|
+
log8.info(`Disconnect ${peer}.`, void 0, {
|
|
2457
|
+
F: __dxlog_file9,
|
|
2458
|
+
L: 97,
|
|
2459
|
+
S: this,
|
|
2460
|
+
C: (f, a) => f(...a)
|
|
2461
|
+
});
|
|
2462
|
+
this._controller.disconnect(peer);
|
|
2463
|
+
}
|
|
2464
|
+
this._lastAction = /* @__PURE__ */ new Date();
|
|
2465
|
+
} else {
|
|
2466
|
+
log8.info("rate limited discconnect", void 0, {
|
|
2467
|
+
F: __dxlog_file9,
|
|
2468
|
+
L: 102,
|
|
2432
2469
|
S: this,
|
|
2433
2470
|
C: (f, a) => f(...a)
|
|
2434
2471
|
});
|
|
2435
|
-
this._controller.disconnect(peer);
|
|
2436
2472
|
}
|
|
2437
2473
|
} else if (connected.length < this._originateConnections) {
|
|
2474
|
+
log8.info(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2475
|
+
F: __dxlog_file9,
|
|
2476
|
+
L: 106,
|
|
2477
|
+
S: this,
|
|
2478
|
+
C: (f, a) => f(...a)
|
|
2479
|
+
});
|
|
2438
2480
|
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2439
2481
|
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2440
|
-
|
|
2441
|
-
log8(`
|
|
2482
|
+
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2483
|
+
log8(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2442
2484
|
F: __dxlog_file9,
|
|
2443
|
-
L:
|
|
2485
|
+
L: 111,
|
|
2486
|
+
S: this,
|
|
2487
|
+
C: (f, a) => f(...a)
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2491
|
+
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2492
|
+
log8.info(`Connect ${peer}.`, void 0, {
|
|
2493
|
+
F: __dxlog_file9,
|
|
2494
|
+
L: 115,
|
|
2495
|
+
S: this,
|
|
2496
|
+
C: (f, a) => f(...a)
|
|
2497
|
+
});
|
|
2498
|
+
this._controller.connect(peer);
|
|
2499
|
+
}
|
|
2500
|
+
this._lastAction = /* @__PURE__ */ new Date();
|
|
2501
|
+
} else {
|
|
2502
|
+
log8.info("rate limited connect", void 0, {
|
|
2503
|
+
F: __dxlog_file9,
|
|
2504
|
+
L: 120,
|
|
2444
2505
|
S: this,
|
|
2445
2506
|
C: (f, a) => f(...a)
|
|
2446
2507
|
});
|
|
2447
|
-
this._controller.connect(peer);
|
|
2448
2508
|
}
|
|
2449
2509
|
}
|
|
2450
2510
|
}
|
|
@@ -3877,4 +3937,4 @@ export {
|
|
|
3877
3937
|
TcpTransport,
|
|
3878
3938
|
createTeleportProtocolFactory
|
|
3879
3939
|
};
|
|
3880
|
-
//# sourceMappingURL=chunk-
|
|
3940
|
+
//# sourceMappingURL=chunk-J7KS7JMZ.mjs.map
|