@dxos/network-manager 0.6.1-main.ff751ec → 0.6.1-next.f8e935e
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-VCGCTQ7O.mjs → chunk-3UBXH53L.mjs} +79 -87
- package/dist/lib/browser/chunk-3UBXH53L.mjs.map +7 -0
- 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-KVS6UT25.cjs → chunk-VXLEPDWN.cjs} +82 -90
- package/dist/lib/node/chunk-VXLEPDWN.cjs.map +7 -0
- 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/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +1 -0
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/network-manager.ts +1 -1
- package/src/swarm/connection.ts +19 -30
- package/src/swarm/peer.ts +1 -1
- package/src/swarm/swarm.ts +13 -5
- package/dist/lib/browser/chunk-VCGCTQ7O.mjs.map +0 -7
- package/dist/lib/node/chunk-KVS6UT25.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_VXLEPDWN_exports = {};
|
|
30
|
+
__export(chunk_VXLEPDWN_exports, {
|
|
31
31
|
Connection: () => Connection,
|
|
32
32
|
ConnectionLimiter: () => ConnectionLimiter,
|
|
33
33
|
ConnectionLog: () => ConnectionLog,
|
|
@@ -55,7 +55,7 @@ __export(chunk_KVS6UT25_exports, {
|
|
|
55
55
|
createSimplePeerTransportFactory: () => createSimplePeerTransportFactory,
|
|
56
56
|
createTeleportProtocolFactory: () => createTeleportProtocolFactory
|
|
57
57
|
});
|
|
58
|
-
module.exports = __toCommonJS(
|
|
58
|
+
module.exports = __toCommonJS(chunk_VXLEPDWN_exports);
|
|
59
59
|
var import_async = require("@dxos/async");
|
|
60
60
|
var import_context = require("@dxos/context");
|
|
61
61
|
var import_debug = require("@dxos/debug");
|
|
@@ -413,7 +413,9 @@ var Connection = class {
|
|
|
413
413
|
}
|
|
414
414
|
await this._ctx.dispose();
|
|
415
415
|
try {
|
|
416
|
-
await this._closeProtocol(
|
|
416
|
+
await this._closeProtocol({
|
|
417
|
+
abort: true
|
|
418
|
+
});
|
|
417
419
|
} catch (err2) {
|
|
418
420
|
import_log.log.catch(err2, void 0, {
|
|
419
421
|
F: __dxlog_file,
|
|
@@ -465,80 +467,63 @@ var Connection = class {
|
|
|
465
467
|
S: this,
|
|
466
468
|
C: (f, a) => f(...a)
|
|
467
469
|
});
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
await this._closeProtocol();
|
|
471
|
-
} catch (err2) {
|
|
472
|
-
import_log.log.catch(err2, void 0, {
|
|
473
|
-
F: __dxlog_file,
|
|
474
|
-
L: 327,
|
|
475
|
-
S: this,
|
|
476
|
-
C: (f, a) => f(...a)
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
try {
|
|
480
|
-
await this._closeTransport();
|
|
481
|
-
} catch (err2) {
|
|
482
|
-
import_log.log.catch(err2, void 0, {
|
|
483
|
-
F: __dxlog_file,
|
|
484
|
-
L: 334,
|
|
485
|
-
S: this,
|
|
486
|
-
C: (f, a) => f(...a)
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
} else {
|
|
470
|
+
let abortProtocol = false;
|
|
471
|
+
if (lastState !== "CONNECTED") {
|
|
490
472
|
(0, import_log.log)(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
491
473
|
F: __dxlog_file,
|
|
492
|
-
L:
|
|
474
|
+
L: 324,
|
|
475
|
+
S: this,
|
|
476
|
+
C: (f, a) => f(...a)
|
|
477
|
+
});
|
|
478
|
+
abortProtocol = true;
|
|
479
|
+
}
|
|
480
|
+
try {
|
|
481
|
+
await this._closeProtocol({
|
|
482
|
+
abort: abortProtocol
|
|
483
|
+
});
|
|
484
|
+
} catch (err2) {
|
|
485
|
+
import_log.log.catch(err2, void 0, {
|
|
486
|
+
F: __dxlog_file,
|
|
487
|
+
L: 330,
|
|
488
|
+
S: this,
|
|
489
|
+
C: (f, a) => f(...a)
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
await this._closeTransport();
|
|
494
|
+
} catch (err2) {
|
|
495
|
+
import_log.log.catch(err2, void 0, {
|
|
496
|
+
F: __dxlog_file,
|
|
497
|
+
L: 336,
|
|
493
498
|
S: this,
|
|
494
499
|
C: (f, a) => f(...a)
|
|
495
500
|
});
|
|
496
|
-
try {
|
|
497
|
-
await this._closeProtocol();
|
|
498
|
-
} catch (err2) {
|
|
499
|
-
import_log.log.catch(err2, void 0, {
|
|
500
|
-
F: __dxlog_file,
|
|
501
|
-
L: 341,
|
|
502
|
-
S: this,
|
|
503
|
-
C: (f, a) => f(...a)
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
try {
|
|
507
|
-
await this._closeTransport();
|
|
508
|
-
} catch (err2) {
|
|
509
|
-
import_log.log.catch(err2, void 0, {
|
|
510
|
-
F: __dxlog_file,
|
|
511
|
-
L: 346,
|
|
512
|
-
S: this,
|
|
513
|
-
C: (f, a) => f(...a)
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
501
|
}
|
|
517
502
|
(0, import_log.log)("closed", {
|
|
518
503
|
peerId: this.ownId
|
|
519
504
|
}, {
|
|
520
505
|
F: __dxlog_file,
|
|
521
|
-
L:
|
|
506
|
+
L: 339,
|
|
522
507
|
S: this,
|
|
523
508
|
C: (f, a) => f(...a)
|
|
524
509
|
});
|
|
525
510
|
this._changeState("CLOSED");
|
|
526
511
|
this._callbacks?.onClosed?.(err);
|
|
527
512
|
}
|
|
528
|
-
async _closeProtocol() {
|
|
529
|
-
(0, import_log.log)("closing protocol",
|
|
513
|
+
async _closeProtocol(options) {
|
|
514
|
+
(0, import_log.log)("closing protocol", options, {
|
|
530
515
|
F: __dxlog_file,
|
|
531
|
-
L:
|
|
516
|
+
L: 345,
|
|
532
517
|
S: this,
|
|
533
518
|
C: (f, a) => f(...a)
|
|
534
519
|
});
|
|
535
520
|
await Promise.race([
|
|
536
|
-
this._protocol.close(),
|
|
521
|
+
options?.abort ? this._protocol.abort() : this._protocol.close(),
|
|
537
522
|
this._protocolClosed.wait()
|
|
538
523
|
]);
|
|
539
|
-
(0, import_log.log)("protocol closed",
|
|
524
|
+
(0, import_log.log)("protocol closed", options, {
|
|
540
525
|
F: __dxlog_file,
|
|
541
|
-
L:
|
|
526
|
+
L: 347,
|
|
542
527
|
S: this,
|
|
543
528
|
C: (f, a) => f(...a)
|
|
544
529
|
});
|
|
@@ -546,7 +531,7 @@ var Connection = class {
|
|
|
546
531
|
async _closeTransport() {
|
|
547
532
|
(0, import_log.log)("closing transport", void 0, {
|
|
548
533
|
F: __dxlog_file,
|
|
549
|
-
L:
|
|
534
|
+
L: 351,
|
|
550
535
|
S: this,
|
|
551
536
|
C: (f, a) => f(...a)
|
|
552
537
|
});
|
|
@@ -556,7 +541,7 @@ var Connection = class {
|
|
|
556
541
|
]);
|
|
557
542
|
(0, import_log.log)("transport closed", void 0, {
|
|
558
543
|
F: __dxlog_file,
|
|
559
|
-
L:
|
|
544
|
+
L: 353,
|
|
560
545
|
S: this,
|
|
561
546
|
C: (f, a) => f(...a)
|
|
562
547
|
});
|
|
@@ -597,7 +582,7 @@ var Connection = class {
|
|
|
597
582
|
err
|
|
598
583
|
}, {
|
|
599
584
|
F: __dxlog_file,
|
|
600
|
-
L:
|
|
585
|
+
L: 389,
|
|
601
586
|
S: this,
|
|
602
587
|
C: (f, a) => f(...a)
|
|
603
588
|
});
|
|
@@ -610,7 +595,7 @@ var Connection = class {
|
|
|
610
595
|
async signal(msg) {
|
|
611
596
|
(0, import_invariant.invariant)(msg.sessionId, void 0, {
|
|
612
597
|
F: __dxlog_file,
|
|
613
|
-
L:
|
|
598
|
+
L: 398,
|
|
614
599
|
S: this,
|
|
615
600
|
A: [
|
|
616
601
|
"msg.sessionId",
|
|
@@ -620,7 +605,7 @@ var Connection = class {
|
|
|
620
605
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
621
606
|
(0, import_log.log)("dropping signal for incorrect session id", void 0, {
|
|
622
607
|
F: __dxlog_file,
|
|
623
|
-
L:
|
|
608
|
+
L: 400,
|
|
624
609
|
S: this,
|
|
625
610
|
C: (f, a) => f(...a)
|
|
626
611
|
});
|
|
@@ -628,7 +613,7 @@ var Connection = class {
|
|
|
628
613
|
}
|
|
629
614
|
(0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
630
615
|
F: __dxlog_file,
|
|
631
|
-
L:
|
|
616
|
+
L: 403,
|
|
632
617
|
S: this,
|
|
633
618
|
A: [
|
|
634
619
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -637,7 +622,7 @@ var Connection = class {
|
|
|
637
622
|
});
|
|
638
623
|
(0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
|
|
639
624
|
F: __dxlog_file,
|
|
640
|
-
L:
|
|
625
|
+
L: 404,
|
|
641
626
|
S: this,
|
|
642
627
|
A: [
|
|
643
628
|
"msg.author?.equals(this.remoteId)",
|
|
@@ -646,7 +631,7 @@ var Connection = class {
|
|
|
646
631
|
});
|
|
647
632
|
(0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
|
|
648
633
|
F: __dxlog_file,
|
|
649
|
-
L:
|
|
634
|
+
L: 405,
|
|
650
635
|
S: this,
|
|
651
636
|
A: [
|
|
652
637
|
"msg.recipient?.equals(this.ownId)",
|
|
@@ -670,7 +655,7 @@ var Connection = class {
|
|
|
670
655
|
msg: msg.data
|
|
671
656
|
}, {
|
|
672
657
|
F: __dxlog_file,
|
|
673
|
-
L:
|
|
658
|
+
L: 414,
|
|
674
659
|
S: this,
|
|
675
660
|
C: (f, a) => f(...a)
|
|
676
661
|
});
|
|
@@ -678,7 +663,7 @@ var Connection = class {
|
|
|
678
663
|
} else {
|
|
679
664
|
(0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
|
|
680
665
|
F: __dxlog_file,
|
|
681
|
-
L:
|
|
666
|
+
L: 417,
|
|
682
667
|
S: this,
|
|
683
668
|
A: [
|
|
684
669
|
"this._transport",
|
|
@@ -691,7 +676,7 @@ var Connection = class {
|
|
|
691
676
|
msg: msg.data
|
|
692
677
|
}, {
|
|
693
678
|
F: __dxlog_file,
|
|
694
|
-
L:
|
|
679
|
+
L: 418,
|
|
695
680
|
S: this,
|
|
696
681
|
C: (f, a) => f(...a)
|
|
697
682
|
});
|
|
@@ -709,13 +694,13 @@ var Connection = class {
|
|
|
709
694
|
peerId: this.ownId
|
|
710
695
|
}, {
|
|
711
696
|
F: __dxlog_file,
|
|
712
|
-
L:
|
|
697
|
+
L: 429,
|
|
713
698
|
S: this,
|
|
714
699
|
C: (f, a) => f(...a)
|
|
715
700
|
});
|
|
716
701
|
(0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
|
|
717
702
|
F: __dxlog_file,
|
|
718
|
-
L:
|
|
703
|
+
L: 430,
|
|
719
704
|
S: this,
|
|
720
705
|
A: [
|
|
721
706
|
"state !== this._state",
|
|
@@ -1428,7 +1413,7 @@ var Peer = class {
|
|
|
1428
1413
|
}
|
|
1429
1414
|
await this.connection.signal(message);
|
|
1430
1415
|
}
|
|
1431
|
-
async
|
|
1416
|
+
async safeDestroy(reason) {
|
|
1432
1417
|
await this._ctx.dispose();
|
|
1433
1418
|
(0, import_log4.log)("Destroying peer", {
|
|
1434
1419
|
peerId: this.id,
|
|
@@ -1444,7 +1429,7 @@ var Peer = class {
|
|
|
1444
1429
|
};
|
|
1445
1430
|
_ts_decorate2([
|
|
1446
1431
|
import_async3.synchronized
|
|
1447
|
-
], Peer.prototype, "
|
|
1432
|
+
], Peer.prototype, "safeDestroy", null);
|
|
1448
1433
|
var increaseInterval = (interval) => {
|
|
1449
1434
|
if (interval === 0) {
|
|
1450
1435
|
return 50;
|
|
@@ -1636,15 +1621,15 @@ var Swarm = class {
|
|
|
1636
1621
|
}
|
|
1637
1622
|
if (swarmEvent.peerAvailable) {
|
|
1638
1623
|
const peerId = import_keys3.PublicKey.from(swarmEvent.peerAvailable.peer);
|
|
1639
|
-
(0, import_log3.log)("new peer", {
|
|
1640
|
-
peerId
|
|
1641
|
-
}, {
|
|
1642
|
-
F: __dxlog_file4,
|
|
1643
|
-
L: 180,
|
|
1644
|
-
S: this,
|
|
1645
|
-
C: (f, a) => f(...a)
|
|
1646
|
-
});
|
|
1647
1624
|
if (!peerId.equals(this._ownPeerId)) {
|
|
1625
|
+
(0, import_log3.log)("new peer", {
|
|
1626
|
+
peerId
|
|
1627
|
+
}, {
|
|
1628
|
+
F: __dxlog_file4,
|
|
1629
|
+
L: 181,
|
|
1630
|
+
S: this,
|
|
1631
|
+
C: (f, a) => f(...a)
|
|
1632
|
+
});
|
|
1648
1633
|
const peer = this._getOrCreatePeer(peerId);
|
|
1649
1634
|
peer.advertizing = true;
|
|
1650
1635
|
}
|
|
@@ -1806,6 +1791,9 @@ var Swarm = class {
|
|
|
1806
1791
|
this.connected.emit(peerId);
|
|
1807
1792
|
},
|
|
1808
1793
|
onDisconnected: async () => {
|
|
1794
|
+
if (this._isUnregistered(peer)) {
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1809
1797
|
if (!peer.advertizing) {
|
|
1810
1798
|
await this._destroyPeer(peer.id, "peer disconnected");
|
|
1811
1799
|
}
|
|
@@ -1813,12 +1801,12 @@ var Swarm = class {
|
|
|
1813
1801
|
this._topology.update();
|
|
1814
1802
|
},
|
|
1815
1803
|
onRejected: () => {
|
|
1816
|
-
if (this.
|
|
1804
|
+
if (!this._isUnregistered(peer)) {
|
|
1817
1805
|
(0, import_log3.log)("peer rejected connection", {
|
|
1818
1806
|
peerId
|
|
1819
1807
|
}, {
|
|
1820
1808
|
F: __dxlog_file4,
|
|
1821
|
-
L:
|
|
1809
|
+
L: 289,
|
|
1822
1810
|
S: this,
|
|
1823
1811
|
C: (f, a) => f(...a)
|
|
1824
1812
|
});
|
|
@@ -1840,17 +1828,18 @@ var Swarm = class {
|
|
|
1840
1828
|
return peer;
|
|
1841
1829
|
}
|
|
1842
1830
|
async _destroyPeer(peerId, reason) {
|
|
1843
|
-
|
|
1831
|
+
const peer = this._peers.get(peerId);
|
|
1832
|
+
(0, import_invariant3.invariant)(peer, void 0, {
|
|
1844
1833
|
F: __dxlog_file4,
|
|
1845
|
-
L:
|
|
1834
|
+
L: 312,
|
|
1846
1835
|
S: this,
|
|
1847
1836
|
A: [
|
|
1848
|
-
"
|
|
1837
|
+
"peer",
|
|
1849
1838
|
""
|
|
1850
1839
|
]
|
|
1851
1840
|
});
|
|
1852
|
-
await this._peers.get(peerId).destroy(new Error(reason));
|
|
1853
1841
|
this._peers.delete(peerId);
|
|
1842
|
+
await peer.safeDestroy(new Error(reason));
|
|
1854
1843
|
}
|
|
1855
1844
|
_getSwarmController() {
|
|
1856
1845
|
return {
|
|
@@ -1870,7 +1859,7 @@ var Swarm = class {
|
|
|
1870
1859
|
} catch (err) {
|
|
1871
1860
|
(0, import_log3.log)("initiation error", err, {
|
|
1872
1861
|
F: __dxlog_file4,
|
|
1873
|
-
L:
|
|
1862
|
+
L: 339,
|
|
1874
1863
|
S: this,
|
|
1875
1864
|
C: (f, a) => f(...a)
|
|
1876
1865
|
});
|
|
@@ -1899,7 +1888,7 @@ var Swarm = class {
|
|
|
1899
1888
|
remoteId
|
|
1900
1889
|
}, {
|
|
1901
1890
|
F: __dxlog_file4,
|
|
1902
|
-
L:
|
|
1891
|
+
L: 367,
|
|
1903
1892
|
S: this,
|
|
1904
1893
|
C: (f, a) => f(...a)
|
|
1905
1894
|
});
|
|
@@ -1908,7 +1897,7 @@ var Swarm = class {
|
|
|
1908
1897
|
if (ctx.disposed) {
|
|
1909
1898
|
return;
|
|
1910
1899
|
}
|
|
1911
|
-
if (this.
|
|
1900
|
+
if (this._isUnregistered(peer)) {
|
|
1912
1901
|
throw new Error("Peer left during initiation delay");
|
|
1913
1902
|
}
|
|
1914
1903
|
if (peer.connection) {
|
|
@@ -1918,7 +1907,7 @@ var Swarm = class {
|
|
|
1918
1907
|
remoteId
|
|
1919
1908
|
}, {
|
|
1920
1909
|
F: __dxlog_file4,
|
|
1921
|
-
L:
|
|
1910
|
+
L: 383,
|
|
1922
1911
|
S: this,
|
|
1923
1912
|
C: (f, a) => f(...a)
|
|
1924
1913
|
});
|
|
@@ -1928,7 +1917,7 @@ var Swarm = class {
|
|
|
1928
1917
|
remoteId
|
|
1929
1918
|
}, {
|
|
1930
1919
|
F: __dxlog_file4,
|
|
1931
|
-
L:
|
|
1920
|
+
L: 386,
|
|
1932
1921
|
S: this,
|
|
1933
1922
|
C: (f, a) => f(...a)
|
|
1934
1923
|
});
|
|
@@ -1940,6 +1929,9 @@ var Swarm = class {
|
|
|
1940
1929
|
}
|
|
1941
1930
|
await peer.closeConnection();
|
|
1942
1931
|
}
|
|
1932
|
+
_isUnregistered(peer) {
|
|
1933
|
+
return !peer || this._peers.get(peer.id) !== peer;
|
|
1934
|
+
}
|
|
1943
1935
|
};
|
|
1944
1936
|
_ts_decorate3([
|
|
1945
1937
|
import_log3.logInfo
|
|
@@ -2383,7 +2375,7 @@ var SwarmNetworkManager = class {
|
|
|
2383
2375
|
this._connectionLog?.leftSwarm(swarm);
|
|
2384
2376
|
await swarm.destroy();
|
|
2385
2377
|
this._swarms.delete(topic);
|
|
2386
|
-
|
|
2378
|
+
this.topicsUpdated.emit();
|
|
2387
2379
|
(0, import_log7.log)("left", {
|
|
2388
2380
|
topic: import_keys8.PublicKey.from(topic),
|
|
2389
2381
|
count: this._swarms.size
|
|
@@ -4203,4 +4195,4 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
|
|
|
4203
4195
|
createSimplePeerTransportFactory,
|
|
4204
4196
|
createTeleportProtocolFactory
|
|
4205
4197
|
});
|
|
4206
|
-
//# sourceMappingURL=chunk-
|
|
4198
|
+
//# sourceMappingURL=chunk-VXLEPDWN.cjs.map
|