@dxos/network-manager 0.1.56-main.d0c207f → 0.1.56-main.e47dfd1
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-MIYEP22D.mjs → chunk-5R7TDXUU.mjs} +323 -229
- package/dist/lib/browser/chunk-5R7TDXUU.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +5 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/index.cjs +318 -222
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +314 -222
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/network-manager.d.ts +1 -1
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/swarm/connection-limiter.d.ts +28 -0
- package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -0
- package/dist/types/src/swarm/connection-limiter.test.d.ts +2 -0
- package/dist/types/src/swarm/connection-limiter.test.d.ts.map +1 -0
- package/dist/types/src/swarm/connection.d.ts +1 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.test.d.ts +2 -0
- package/dist/types/src/swarm/connection.test.d.ts.map +1 -0
- package/dist/types/src/swarm/index.d.ts +1 -0
- package/dist/types/src/swarm/index.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +3 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +3 -1
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/network-manager.ts +18 -4
- package/src/swarm/connection-limiter.test.ts +44 -0
- package/src/swarm/connection-limiter.ts +71 -0
- package/src/swarm/connection.test.ts +72 -0
- package/src/swarm/connection.ts +1 -2
- package/src/swarm/index.ts +1 -0
- package/src/swarm/peer.ts +22 -7
- package/src/swarm/swarm.test.ts +140 -90
- package/src/swarm/swarm.ts +3 -1
- package/dist/lib/browser/chunk-MIYEP22D.mjs.map +0 -7
|
@@ -97,14 +97,13 @@ var Connection = class {
|
|
|
97
97
|
/**
|
|
98
98
|
* Create an underlying transport and prepares it for the connection.
|
|
99
99
|
*/
|
|
100
|
-
|
|
101
|
-
openConnection() {
|
|
100
|
+
async openConnection() {
|
|
102
101
|
invariant(this._state === ConnectionState.INITIAL, "Invalid state.");
|
|
103
102
|
log.trace("dxos.mesh.connection.open-connection", trace.begin({
|
|
104
103
|
id: this._instanceId
|
|
105
104
|
}), {
|
|
106
105
|
F: __dxlog_file,
|
|
107
|
-
L:
|
|
106
|
+
L: 114,
|
|
108
107
|
S: this,
|
|
109
108
|
C: (f, a) => f(...a)
|
|
110
109
|
});
|
|
@@ -115,7 +114,7 @@ var Connection = class {
|
|
|
115
114
|
this._protocol.stream.on("close", () => {
|
|
116
115
|
log("protocol stream closed", void 0, {
|
|
117
116
|
F: __dxlog_file,
|
|
118
|
-
L:
|
|
117
|
+
L: 125,
|
|
119
118
|
S: this,
|
|
120
119
|
C: (f, a) => f(...a)
|
|
121
120
|
});
|
|
@@ -147,7 +146,7 @@ var Connection = class {
|
|
|
147
146
|
id: this._instanceId
|
|
148
147
|
}), {
|
|
149
148
|
F: __dxlog_file,
|
|
150
|
-
L:
|
|
149
|
+
L: 158,
|
|
151
150
|
S: this,
|
|
152
151
|
C: (f, a) => f(...a)
|
|
153
152
|
});
|
|
@@ -163,7 +162,7 @@ var Connection = class {
|
|
|
163
162
|
peerId: this.ownId
|
|
164
163
|
}, {
|
|
165
164
|
F: __dxlog_file,
|
|
166
|
-
L:
|
|
165
|
+
L: 170,
|
|
167
166
|
S: this,
|
|
168
167
|
C: (f, a) => f(...a)
|
|
169
168
|
});
|
|
@@ -172,7 +171,7 @@ var Connection = class {
|
|
|
172
171
|
} catch (err) {
|
|
173
172
|
log.catch(err, void 0, {
|
|
174
173
|
F: __dxlog_file,
|
|
175
|
-
L:
|
|
174
|
+
L: 176,
|
|
176
175
|
S: this,
|
|
177
176
|
C: (f, a) => f(...a)
|
|
178
177
|
});
|
|
@@ -182,7 +181,7 @@ var Connection = class {
|
|
|
182
181
|
} catch (err) {
|
|
183
182
|
log.catch(err, void 0, {
|
|
184
183
|
F: __dxlog_file,
|
|
185
|
-
L:
|
|
184
|
+
L: 183,
|
|
186
185
|
S: this,
|
|
187
186
|
C: (f, a) => f(...a)
|
|
188
187
|
});
|
|
@@ -191,7 +190,7 @@ var Connection = class {
|
|
|
191
190
|
peerId: this.ownId
|
|
192
191
|
}, {
|
|
193
192
|
F: __dxlog_file,
|
|
194
|
-
L:
|
|
193
|
+
L: 186,
|
|
195
194
|
S: this,
|
|
196
195
|
C: (f, a) => f(...a)
|
|
197
196
|
});
|
|
@@ -231,7 +230,7 @@ var Connection = class {
|
|
|
231
230
|
err
|
|
232
231
|
}, {
|
|
233
232
|
F: __dxlog_file,
|
|
234
|
-
L:
|
|
233
|
+
L: 220,
|
|
235
234
|
S: this,
|
|
236
235
|
C: (f, a) => f(...a)
|
|
237
236
|
});
|
|
@@ -247,7 +246,7 @@ var Connection = class {
|
|
|
247
246
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
248
247
|
log("dropping signal for incorrect session id", void 0, {
|
|
249
248
|
F: __dxlog_file,
|
|
250
|
-
L:
|
|
249
|
+
L: 231,
|
|
251
250
|
S: this,
|
|
252
251
|
C: (f, a) => f(...a)
|
|
253
252
|
});
|
|
@@ -270,7 +269,7 @@ var Connection = class {
|
|
|
270
269
|
msg: msg.data
|
|
271
270
|
}, {
|
|
272
271
|
F: __dxlog_file,
|
|
273
|
-
L:
|
|
272
|
+
L: 245,
|
|
274
273
|
S: this,
|
|
275
274
|
C: (f, a) => f(...a)
|
|
276
275
|
});
|
|
@@ -283,7 +282,7 @@ var Connection = class {
|
|
|
283
282
|
msg: msg.data
|
|
284
283
|
}, {
|
|
285
284
|
F: __dxlog_file,
|
|
286
|
-
L:
|
|
285
|
+
L: 249,
|
|
287
286
|
S: this,
|
|
288
287
|
C: (f, a) => f(...a)
|
|
289
288
|
});
|
|
@@ -298,7 +297,7 @@ var Connection = class {
|
|
|
298
297
|
peerId: this.ownId
|
|
299
298
|
}, {
|
|
300
299
|
F: __dxlog_file,
|
|
301
|
-
L:
|
|
300
|
+
L: 256,
|
|
302
301
|
S: this,
|
|
303
302
|
C: (f, a) => f(...a)
|
|
304
303
|
});
|
|
@@ -513,6 +512,7 @@ import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
|
|
|
513
512
|
import invariant3 from "tiny-invariant";
|
|
514
513
|
import { scheduleTask, synchronized as synchronized2 } from "@dxos/async";
|
|
515
514
|
import { Context as Context3 } from "@dxos/context";
|
|
515
|
+
import { CancelledError as CancelledError2 } from "@dxos/errors";
|
|
516
516
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
517
517
|
import { log as log3 } from "@dxos/log";
|
|
518
518
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
@@ -528,13 +528,14 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
528
528
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
529
529
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
530
530
|
var Peer = class {
|
|
531
|
-
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _callbacks) {
|
|
531
|
+
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
532
532
|
this.id = id;
|
|
533
533
|
this.topic = topic;
|
|
534
534
|
this.localPeerId = localPeerId;
|
|
535
535
|
this._signalMessaging = _signalMessaging;
|
|
536
536
|
this._protocolProvider = _protocolProvider;
|
|
537
537
|
this._transportFactory = _transportFactory;
|
|
538
|
+
this._connectionLimiter = _connectionLimiter;
|
|
538
539
|
this._callbacks = _callbacks;
|
|
539
540
|
this._availableAfter = 0;
|
|
540
541
|
this.availableToConnect = true;
|
|
@@ -546,16 +547,18 @@ var Peer = class {
|
|
|
546
547
|
* Respond to remote offer.
|
|
547
548
|
*/
|
|
548
549
|
async onOffer(message) {
|
|
550
|
+
var _a;
|
|
549
551
|
const remoteId = message.author;
|
|
550
552
|
if (this.connection || this.initiating) {
|
|
551
553
|
if (remoteId.toHex() < this.localPeerId.toHex()) {
|
|
552
|
-
log3("
|
|
553
|
-
|
|
554
|
+
log3("close local connection", {
|
|
555
|
+
localPeerId: this.id,
|
|
554
556
|
topic: this.topic,
|
|
555
|
-
|
|
557
|
+
remotePeerId: this.localPeerId,
|
|
558
|
+
sessionId: (_a = this.connection) == null ? void 0 : _a.sessionId
|
|
556
559
|
}, {
|
|
557
560
|
F: __dxlog_file3,
|
|
558
|
-
L:
|
|
561
|
+
L: 107,
|
|
559
562
|
S: this,
|
|
560
563
|
C: (f, a) => f(...a)
|
|
561
564
|
});
|
|
@@ -573,19 +576,22 @@ var Peer = class {
|
|
|
573
576
|
invariant3(message.sessionId);
|
|
574
577
|
const connection = this._createConnection(false, message.sessionId);
|
|
575
578
|
try {
|
|
576
|
-
|
|
579
|
+
await this._connectionLimiter.connecting(message.sessionId);
|
|
580
|
+
await connection.openConnection();
|
|
577
581
|
} catch (err) {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
582
|
+
if (!(err instanceof CancelledError2)) {
|
|
583
|
+
log3.warn("connection error", {
|
|
584
|
+
topic: this.topic,
|
|
585
|
+
peerId: this.localPeerId,
|
|
586
|
+
remoteId: this.id,
|
|
587
|
+
err
|
|
588
|
+
}, {
|
|
589
|
+
F: __dxlog_file3,
|
|
590
|
+
L: 135,
|
|
591
|
+
S: this,
|
|
592
|
+
C: (f, a) => f(...a)
|
|
593
|
+
});
|
|
594
|
+
}
|
|
589
595
|
await this.closeConnection();
|
|
590
596
|
}
|
|
591
597
|
return {
|
|
@@ -611,13 +617,14 @@ var Peer = class {
|
|
|
611
617
|
sessionId
|
|
612
618
|
}, {
|
|
613
619
|
F: __dxlog_file3,
|
|
614
|
-
L:
|
|
620
|
+
L: 155,
|
|
615
621
|
S: this,
|
|
616
622
|
C: (f, a) => f(...a)
|
|
617
623
|
});
|
|
618
624
|
const connection = this._createConnection(true, sessionId);
|
|
619
625
|
this.initiating = true;
|
|
620
626
|
try {
|
|
627
|
+
await this._connectionLimiter.connecting(sessionId);
|
|
621
628
|
const answer = await this._signalMessaging.offer({
|
|
622
629
|
author: this.localPeerId,
|
|
623
630
|
recipient: this.id,
|
|
@@ -634,14 +641,14 @@ var Peer = class {
|
|
|
634
641
|
remoteId: this.id
|
|
635
642
|
}, {
|
|
636
643
|
F: __dxlog_file3,
|
|
637
|
-
L:
|
|
644
|
+
L: 170,
|
|
638
645
|
S: this,
|
|
639
646
|
C: (f, a) => f(...a)
|
|
640
647
|
});
|
|
641
648
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
642
649
|
log3("ignoring response", void 0, {
|
|
643
650
|
F: __dxlog_file3,
|
|
644
|
-
L:
|
|
651
|
+
L: 172,
|
|
645
652
|
S: this,
|
|
646
653
|
C: (f, a) => f(...a)
|
|
647
654
|
});
|
|
@@ -651,7 +658,7 @@ var Peer = class {
|
|
|
651
658
|
this._callbacks.onRejected();
|
|
652
659
|
return;
|
|
653
660
|
}
|
|
654
|
-
connection.openConnection();
|
|
661
|
+
await connection.openConnection();
|
|
655
662
|
this._callbacks.onAccepted();
|
|
656
663
|
} catch (err) {
|
|
657
664
|
log3("initiation error", {
|
|
@@ -661,7 +668,7 @@ var Peer = class {
|
|
|
661
668
|
remoteId: this.id
|
|
662
669
|
}, {
|
|
663
670
|
F: __dxlog_file3,
|
|
664
|
-
L:
|
|
671
|
+
L: 183,
|
|
665
672
|
S: this,
|
|
666
673
|
C: (f, a) => f(...a)
|
|
667
674
|
});
|
|
@@ -685,7 +692,7 @@ var Peer = class {
|
|
|
685
692
|
sessionId
|
|
686
693
|
}, {
|
|
687
694
|
F: __dxlog_file3,
|
|
688
|
-
L:
|
|
695
|
+
L: 197,
|
|
689
696
|
S: this,
|
|
690
697
|
C: (f, a) => f(...a)
|
|
691
698
|
});
|
|
@@ -715,6 +722,7 @@ var Peer = class {
|
|
|
715
722
|
this.availableToConnect = true;
|
|
716
723
|
this._lastConnectionTime = Date.now();
|
|
717
724
|
this._callbacks.onConnected();
|
|
725
|
+
this._connectionLimiter.doneConnecting(sessionId);
|
|
718
726
|
break;
|
|
719
727
|
}
|
|
720
728
|
case ConnectionState.CLOSED: {
|
|
@@ -725,7 +733,7 @@ var Peer = class {
|
|
|
725
733
|
initiator
|
|
726
734
|
}, {
|
|
727
735
|
F: __dxlog_file3,
|
|
728
|
-
L:
|
|
736
|
+
L: 234,
|
|
729
737
|
S: this,
|
|
730
738
|
C: (f, a) => f(...a)
|
|
731
739
|
});
|
|
@@ -738,6 +746,7 @@ var Peer = class {
|
|
|
738
746
|
}
|
|
739
747
|
this.connection = void 0;
|
|
740
748
|
this._callbacks.onDisconnected();
|
|
749
|
+
this._connectionLimiter.doneConnecting(sessionId);
|
|
741
750
|
scheduleTask(this._connectionCtx, () => {
|
|
742
751
|
this.availableToConnect = true;
|
|
743
752
|
this._callbacks.onPeerAvailable();
|
|
@@ -755,7 +764,7 @@ var Peer = class {
|
|
|
755
764
|
err
|
|
756
765
|
}, {
|
|
757
766
|
F: __dxlog_file3,
|
|
758
|
-
L:
|
|
767
|
+
L: 263,
|
|
759
768
|
S: this,
|
|
760
769
|
C: (f, a) => f(...a)
|
|
761
770
|
});
|
|
@@ -774,7 +783,7 @@ var Peer = class {
|
|
|
774
783
|
sessionId: connection.sessionId
|
|
775
784
|
}, {
|
|
776
785
|
F: __dxlog_file3,
|
|
777
|
-
L:
|
|
786
|
+
L: 279,
|
|
778
787
|
S: this,
|
|
779
788
|
C: (f, a) => f(...a)
|
|
780
789
|
});
|
|
@@ -784,7 +793,7 @@ var Peer = class {
|
|
|
784
793
|
sessionId: connection.sessionId
|
|
785
794
|
}, {
|
|
786
795
|
F: __dxlog_file3,
|
|
787
|
-
L:
|
|
796
|
+
L: 285,
|
|
788
797
|
S: this,
|
|
789
798
|
C: (f, a) => f(...a)
|
|
790
799
|
});
|
|
@@ -795,7 +804,7 @@ var Peer = class {
|
|
|
795
804
|
message
|
|
796
805
|
}, {
|
|
797
806
|
F: __dxlog_file3,
|
|
798
|
-
L:
|
|
807
|
+
L: 290,
|
|
799
808
|
S: this,
|
|
800
809
|
C: (f, a) => f(...a)
|
|
801
810
|
});
|
|
@@ -811,7 +820,7 @@ var Peer = class {
|
|
|
811
820
|
topic: this.topic
|
|
812
821
|
}, {
|
|
813
822
|
F: __dxlog_file3,
|
|
814
|
-
L:
|
|
823
|
+
L: 300,
|
|
815
824
|
S: this,
|
|
816
825
|
C: (f, a) => f(...a)
|
|
817
826
|
});
|
|
@@ -851,7 +860,7 @@ var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
|
851
860
|
var Swarm = class {
|
|
852
861
|
// TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
|
|
853
862
|
// TODO(burdon): Split up properties.
|
|
854
|
-
constructor(_topic, _ownPeerId, _topology, _protocolProvider, _messenger, _transportFactory, _label) {
|
|
863
|
+
constructor(_topic, _ownPeerId, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter) {
|
|
855
864
|
this._topic = _topic;
|
|
856
865
|
this._ownPeerId = _ownPeerId;
|
|
857
866
|
this._topology = _topology;
|
|
@@ -859,6 +868,7 @@ var Swarm = class {
|
|
|
859
868
|
this._messenger = _messenger;
|
|
860
869
|
this._transportFactory = _transportFactory;
|
|
861
870
|
this._label = _label;
|
|
871
|
+
this._connectionLimiter = _connectionLimiter;
|
|
862
872
|
this._peers = new ComplexMap2(PublicKey4.hash);
|
|
863
873
|
this._ctx = new Context4();
|
|
864
874
|
this._listeningHandle = void 0;
|
|
@@ -875,7 +885,7 @@ var Swarm = class {
|
|
|
875
885
|
}
|
|
876
886
|
}), {
|
|
877
887
|
F: __dxlog_file4,
|
|
878
|
-
L:
|
|
888
|
+
L: 88,
|
|
879
889
|
S: this,
|
|
880
890
|
C: (f, a) => f(...a)
|
|
881
891
|
});
|
|
@@ -883,7 +893,7 @@ var Swarm = class {
|
|
|
883
893
|
peerId: _ownPeerId
|
|
884
894
|
}, {
|
|
885
895
|
F: __dxlog_file4,
|
|
886
|
-
L:
|
|
896
|
+
L: 92,
|
|
887
897
|
S: this,
|
|
888
898
|
C: (f, a) => f(...a)
|
|
889
899
|
});
|
|
@@ -898,7 +908,7 @@ var Swarm = class {
|
|
|
898
908
|
id: this._instanceId
|
|
899
909
|
}), {
|
|
900
910
|
F: __dxlog_file4,
|
|
901
|
-
L:
|
|
911
|
+
L: 101,
|
|
902
912
|
S: this,
|
|
903
913
|
C: (f, a) => f(...a)
|
|
904
914
|
});
|
|
@@ -928,7 +938,7 @@ var Swarm = class {
|
|
|
928
938
|
err
|
|
929
939
|
}, {
|
|
930
940
|
F: __dxlog_file4,
|
|
931
|
-
L:
|
|
941
|
+
L: 135,
|
|
932
942
|
S: this,
|
|
933
943
|
C: (f, a) => f(...a)
|
|
934
944
|
}));
|
|
@@ -939,7 +949,7 @@ var Swarm = class {
|
|
|
939
949
|
var _a;
|
|
940
950
|
log4("destroying...", void 0, {
|
|
941
951
|
F: __dxlog_file4,
|
|
942
|
-
L:
|
|
952
|
+
L: 141,
|
|
943
953
|
S: this,
|
|
944
954
|
C: (f, a) => f(...a)
|
|
945
955
|
});
|
|
@@ -950,7 +960,7 @@ var Swarm = class {
|
|
|
950
960
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
951
961
|
log4("destroyed", void 0, {
|
|
952
962
|
F: __dxlog_file4,
|
|
953
|
-
L:
|
|
963
|
+
L: 148,
|
|
954
964
|
S: this,
|
|
955
965
|
C: (f, a) => f(...a)
|
|
956
966
|
});
|
|
@@ -965,7 +975,7 @@ var Swarm = class {
|
|
|
965
975
|
topology: getClassName(topology)
|
|
966
976
|
}, {
|
|
967
977
|
F: __dxlog_file4,
|
|
968
|
-
L:
|
|
978
|
+
L: 156,
|
|
969
979
|
S: this,
|
|
970
980
|
C: (f, a) => f(...a)
|
|
971
981
|
});
|
|
@@ -980,14 +990,14 @@ var Swarm = class {
|
|
|
980
990
|
swarmEvent
|
|
981
991
|
}, {
|
|
982
992
|
F: __dxlog_file4,
|
|
983
|
-
L:
|
|
993
|
+
L: 169,
|
|
984
994
|
S: this,
|
|
985
995
|
C: (f, a) => f(...a)
|
|
986
996
|
});
|
|
987
997
|
if (this._ctx.disposed) {
|
|
988
998
|
log4("swarm event ignored for disposed swarm", void 0, {
|
|
989
999
|
F: __dxlog_file4,
|
|
990
|
-
L:
|
|
1000
|
+
L: 172,
|
|
991
1001
|
S: this,
|
|
992
1002
|
C: (f, a) => f(...a)
|
|
993
1003
|
});
|
|
@@ -999,7 +1009,7 @@ var Swarm = class {
|
|
|
999
1009
|
peerId
|
|
1000
1010
|
}, {
|
|
1001
1011
|
F: __dxlog_file4,
|
|
1002
|
-
L:
|
|
1012
|
+
L: 178,
|
|
1003
1013
|
S: this,
|
|
1004
1014
|
C: (f, a) => f(...a)
|
|
1005
1015
|
});
|
|
@@ -1014,7 +1024,7 @@ var Swarm = class {
|
|
|
1014
1024
|
if (((_a = peer.connection) == null ? void 0 : _a.state) !== ConnectionState.CONNECTED) {
|
|
1015
1025
|
void this._destroyPeer(peer.id).catch((err) => log4.catch(err, void 0, {
|
|
1016
1026
|
F: __dxlog_file4,
|
|
1017
|
-
L:
|
|
1027
|
+
L: 189,
|
|
1018
1028
|
S: this,
|
|
1019
1029
|
C: (f, a) => f(...a)
|
|
1020
1030
|
}));
|
|
@@ -1029,14 +1039,14 @@ var Swarm = class {
|
|
|
1029
1039
|
message
|
|
1030
1040
|
}, {
|
|
1031
1041
|
F: __dxlog_file4,
|
|
1032
|
-
L:
|
|
1042
|
+
L: 199,
|
|
1033
1043
|
S: this,
|
|
1034
1044
|
C: (f, a) => f(...a)
|
|
1035
1045
|
});
|
|
1036
1046
|
if (this._ctx.disposed) {
|
|
1037
1047
|
log4("ignored for disposed swarm", void 0, {
|
|
1038
1048
|
F: __dxlog_file4,
|
|
1039
|
-
L:
|
|
1049
|
+
L: 201,
|
|
1040
1050
|
S: this,
|
|
1041
1051
|
C: (f, a) => f(...a)
|
|
1042
1052
|
});
|
|
@@ -1050,7 +1060,7 @@ var Swarm = class {
|
|
|
1050
1060
|
message
|
|
1051
1061
|
}, {
|
|
1052
1062
|
F: __dxlog_file4,
|
|
1053
|
-
L:
|
|
1063
|
+
L: 208,
|
|
1054
1064
|
S: this,
|
|
1055
1065
|
C: (f, a) => f(...a)
|
|
1056
1066
|
});
|
|
@@ -1063,7 +1073,7 @@ var Swarm = class {
|
|
|
1063
1073
|
message
|
|
1064
1074
|
}, {
|
|
1065
1075
|
F: __dxlog_file4,
|
|
1066
|
-
L:
|
|
1076
|
+
L: 212,
|
|
1067
1077
|
S: this,
|
|
1068
1078
|
C: (f, a) => f(...a)
|
|
1069
1079
|
});
|
|
@@ -1082,14 +1092,14 @@ var Swarm = class {
|
|
|
1082
1092
|
message
|
|
1083
1093
|
}, {
|
|
1084
1094
|
F: __dxlog_file4,
|
|
1085
|
-
L:
|
|
1095
|
+
L: 223,
|
|
1086
1096
|
S: this,
|
|
1087
1097
|
C: (f, a) => f(...a)
|
|
1088
1098
|
});
|
|
1089
1099
|
if (this._ctx.disposed) {
|
|
1090
1100
|
log4.info("ignored for offline swarm", void 0, {
|
|
1091
1101
|
F: __dxlog_file4,
|
|
1092
|
-
L:
|
|
1102
|
+
L: 225,
|
|
1093
1103
|
S: this,
|
|
1094
1104
|
C: (f, a) => f(...a)
|
|
1095
1105
|
});
|
|
@@ -1115,7 +1125,7 @@ var Swarm = class {
|
|
|
1115
1125
|
_getOrCreatePeer(peerId) {
|
|
1116
1126
|
let peer = this._peers.get(peerId);
|
|
1117
1127
|
if (!peer) {
|
|
1118
|
-
peer = new Peer(peerId, this._topic, this._ownPeerId, this._swarmMessenger, this._protocolProvider, this._transportFactory, {
|
|
1128
|
+
peer = new Peer(peerId, this._topic, this._ownPeerId, this._swarmMessenger, this._protocolProvider, this._transportFactory, this._connectionLimiter, {
|
|
1119
1129
|
onInitiated: (connection) => {
|
|
1120
1130
|
this.connectionAdded.emit(connection);
|
|
1121
1131
|
},
|
|
@@ -1170,7 +1180,7 @@ var Swarm = class {
|
|
|
1170
1180
|
} catch (err) {
|
|
1171
1181
|
log4("initiation error", err, {
|
|
1172
1182
|
F: __dxlog_file4,
|
|
1173
|
-
L:
|
|
1183
|
+
L: 329,
|
|
1174
1184
|
S: this,
|
|
1175
1185
|
C: (f, a) => f(...a)
|
|
1176
1186
|
});
|
|
@@ -1198,7 +1208,7 @@ var Swarm = class {
|
|
|
1198
1208
|
remoteId
|
|
1199
1209
|
}, {
|
|
1200
1210
|
F: __dxlog_file4,
|
|
1201
|
-
L:
|
|
1211
|
+
L: 356,
|
|
1202
1212
|
S: this,
|
|
1203
1213
|
C: (f, a) => f(...a)
|
|
1204
1214
|
});
|
|
@@ -1215,7 +1225,7 @@ var Swarm = class {
|
|
|
1215
1225
|
remoteId
|
|
1216
1226
|
}, {
|
|
1217
1227
|
F: __dxlog_file4,
|
|
1218
|
-
L:
|
|
1228
|
+
L: 370,
|
|
1219
1229
|
S: this,
|
|
1220
1230
|
C: (f, a) => f(...a)
|
|
1221
1231
|
});
|
|
@@ -1225,7 +1235,7 @@ var Swarm = class {
|
|
|
1225
1235
|
remoteId
|
|
1226
1236
|
}, {
|
|
1227
1237
|
F: __dxlog_file4,
|
|
1228
|
-
L:
|
|
1238
|
+
L: 373,
|
|
1229
1239
|
S: this,
|
|
1230
1240
|
C: (f, a) => f(...a)
|
|
1231
1241
|
});
|
|
@@ -1253,9 +1263,6 @@ _ts_decorate3([
|
|
|
1253
1263
|
_ts_decorate3([
|
|
1254
1264
|
synchronized3
|
|
1255
1265
|
], Swarm.prototype, "onOffer", null);
|
|
1256
|
-
_ts_decorate3([
|
|
1257
|
-
synchronized3
|
|
1258
|
-
], Swarm.prototype, "onSignal", null);
|
|
1259
1266
|
_ts_decorate3([
|
|
1260
1267
|
synchronized3
|
|
1261
1268
|
], Swarm.prototype, "goOffline", null);
|
|
@@ -1334,11 +1341,92 @@ var SwarmMapper = class {
|
|
|
1334
1341
|
}
|
|
1335
1342
|
};
|
|
1336
1343
|
|
|
1344
|
+
// packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
|
|
1345
|
+
import { DeferredTask as DeferredTask2 } from "@dxos/async";
|
|
1346
|
+
import { Context as Context5 } from "@dxos/context";
|
|
1347
|
+
import { CancelledError as CancelledError3 } from "@dxos/errors";
|
|
1348
|
+
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
1349
|
+
import { invariant as invariant5, log as log6 } from "@dxos/log";
|
|
1350
|
+
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
1351
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
1352
|
+
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 3;
|
|
1353
|
+
var ConnectionLimiter = class {
|
|
1354
|
+
constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
|
|
1355
|
+
this._ctx = new Context5();
|
|
1356
|
+
/**
|
|
1357
|
+
* Queue of promises to resolve when initiating connections amount is below the limit.
|
|
1358
|
+
*/
|
|
1359
|
+
this._waitingPromises = new ComplexMap4(PublicKey6.hash);
|
|
1360
|
+
this.resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
|
|
1361
|
+
Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
|
|
1362
|
+
resolve();
|
|
1363
|
+
});
|
|
1364
|
+
});
|
|
1365
|
+
this._maxConcurrentInitConnections = maxConcurrentInitConnections;
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
|
|
1369
|
+
*/
|
|
1370
|
+
async connecting(sessionId) {
|
|
1371
|
+
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
1372
|
+
F: __dxlog_file6,
|
|
1373
|
+
L: 47,
|
|
1374
|
+
S: this,
|
|
1375
|
+
A: [
|
|
1376
|
+
"!this._waitingPromises.has(sessionId)",
|
|
1377
|
+
"'Peer is already waiting for connection'"
|
|
1378
|
+
]
|
|
1379
|
+
});
|
|
1380
|
+
log6("waiting", {
|
|
1381
|
+
sessionId
|
|
1382
|
+
}, {
|
|
1383
|
+
F: __dxlog_file6,
|
|
1384
|
+
L: 48,
|
|
1385
|
+
S: this,
|
|
1386
|
+
C: (f, a) => f(...a)
|
|
1387
|
+
});
|
|
1388
|
+
await new Promise((resolve, reject) => {
|
|
1389
|
+
this._waitingPromises.set(sessionId, {
|
|
1390
|
+
resolve,
|
|
1391
|
+
reject
|
|
1392
|
+
});
|
|
1393
|
+
this.resolveWaitingPromises.schedule();
|
|
1394
|
+
});
|
|
1395
|
+
log6("allow", {
|
|
1396
|
+
sessionId
|
|
1397
|
+
}, {
|
|
1398
|
+
F: __dxlog_file6,
|
|
1399
|
+
L: 56,
|
|
1400
|
+
S: this,
|
|
1401
|
+
C: (f, a) => f(...a)
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Rejects promise returned by `connecting` method.
|
|
1406
|
+
*/
|
|
1407
|
+
doneConnecting(sessionId) {
|
|
1408
|
+
log6("done", {
|
|
1409
|
+
sessionId
|
|
1410
|
+
}, {
|
|
1411
|
+
F: __dxlog_file6,
|
|
1412
|
+
L: 63,
|
|
1413
|
+
S: this,
|
|
1414
|
+
C: (f, a) => f(...a)
|
|
1415
|
+
});
|
|
1416
|
+
if (!this._waitingPromises.has(sessionId)) {
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
this._waitingPromises.get(sessionId).reject(new CancelledError3());
|
|
1420
|
+
this._waitingPromises.delete(sessionId);
|
|
1421
|
+
this.resolveWaitingPromises.schedule();
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
|
|
1337
1425
|
// packages/core/mesh/network-manager/src/connection-log.ts
|
|
1338
1426
|
import { Event as Event4 } from "@dxos/async";
|
|
1339
1427
|
import { raise } from "@dxos/debug";
|
|
1340
|
-
import { PublicKey as
|
|
1341
|
-
import { ComplexMap as
|
|
1428
|
+
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
1429
|
+
import { ComplexMap as ComplexMap5 } from "@dxos/util";
|
|
1342
1430
|
var EventType;
|
|
1343
1431
|
(function(EventType2) {
|
|
1344
1432
|
EventType2["CONNECTION_STATE_CHANGED"] = "CONNECTION_STATE_CHANGED";
|
|
@@ -1352,7 +1440,7 @@ var ConnectionLog = class {
|
|
|
1352
1440
|
/**
|
|
1353
1441
|
* SwarmId => info
|
|
1354
1442
|
*/
|
|
1355
|
-
this._swarms = new
|
|
1443
|
+
this._swarms = new ComplexMap5(PublicKey7.hash);
|
|
1356
1444
|
this.update = new Event4();
|
|
1357
1445
|
}
|
|
1358
1446
|
getSwarmInfo(swarmId) {
|
|
@@ -1364,13 +1452,13 @@ var ConnectionLog = class {
|
|
|
1364
1452
|
}
|
|
1365
1453
|
joinedSwarm(swarm) {
|
|
1366
1454
|
const info = {
|
|
1367
|
-
id:
|
|
1455
|
+
id: PublicKey7.from(swarm._instanceId),
|
|
1368
1456
|
topic: swarm.topic,
|
|
1369
1457
|
isActive: true,
|
|
1370
1458
|
label: swarm.label,
|
|
1371
1459
|
connections: []
|
|
1372
1460
|
};
|
|
1373
|
-
this._swarms.set(
|
|
1461
|
+
this._swarms.set(PublicKey7.from(swarm._instanceId), info);
|
|
1374
1462
|
this.update.emit();
|
|
1375
1463
|
swarm.connectionAdded.on((connection) => {
|
|
1376
1464
|
var _a, _b;
|
|
@@ -1399,29 +1487,32 @@ var ConnectionLog = class {
|
|
|
1399
1487
|
});
|
|
1400
1488
|
}
|
|
1401
1489
|
leftSwarm(swarm) {
|
|
1402
|
-
this.getSwarmInfo(
|
|
1490
|
+
this.getSwarmInfo(PublicKey7.from(swarm._instanceId)).isActive = false;
|
|
1403
1491
|
this.update.emit();
|
|
1404
1492
|
}
|
|
1405
1493
|
};
|
|
1406
1494
|
|
|
1407
1495
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
1408
|
-
import
|
|
1496
|
+
import invariant6 from "tiny-invariant";
|
|
1409
1497
|
import { Event as Event5 } from "@dxos/async";
|
|
1410
|
-
import { PublicKey as
|
|
1411
|
-
import { log as
|
|
1498
|
+
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
1499
|
+
import { log as log7 } from "@dxos/log";
|
|
1412
1500
|
import { Messenger } from "@dxos/messaging";
|
|
1413
1501
|
import { trace as trace3 } from "@dxos/protocols";
|
|
1414
1502
|
import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1415
|
-
import { ComplexMap as
|
|
1416
|
-
var
|
|
1503
|
+
import { ComplexMap as ComplexMap6 } from "@dxos/util";
|
|
1504
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
1417
1505
|
var NetworkManager = class {
|
|
1418
1506
|
constructor({ transportFactory, signalManager, log: log1 }) {
|
|
1419
|
-
|
|
1420
|
-
|
|
1507
|
+
/**
|
|
1508
|
+
* @internal
|
|
1509
|
+
*/
|
|
1510
|
+
this._swarms = new ComplexMap6(PublicKey8.hash);
|
|
1511
|
+
this._mappers = new ComplexMap6(PublicKey8.hash);
|
|
1421
1512
|
this._connectionState = ConnectionState2.ONLINE;
|
|
1422
1513
|
this.connectionStateChanged = new Event5();
|
|
1423
1514
|
this.topicsUpdated = new Event5();
|
|
1424
|
-
this._instanceId =
|
|
1515
|
+
this._instanceId = PublicKey8.random().toHex();
|
|
1425
1516
|
this._transportFactory = transportFactory;
|
|
1426
1517
|
this._signalManager = signalManager;
|
|
1427
1518
|
this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => {
|
|
@@ -1435,6 +1526,7 @@ var NetworkManager = class {
|
|
|
1435
1526
|
join: (opts) => this._signalManager.join(opts),
|
|
1436
1527
|
leave: (opts) => this._signalManager.leave(opts)
|
|
1437
1528
|
};
|
|
1529
|
+
this._connectionLimiter = new ConnectionLimiter();
|
|
1438
1530
|
if (log1) {
|
|
1439
1531
|
this._connectionLog = new ConnectionLog();
|
|
1440
1532
|
}
|
|
@@ -1457,21 +1549,21 @@ var NetworkManager = class {
|
|
|
1457
1549
|
return this._swarms.get(topic);
|
|
1458
1550
|
}
|
|
1459
1551
|
async open() {
|
|
1460
|
-
|
|
1552
|
+
log7.trace("dxos.mesh.network-manager.open", trace3.begin({
|
|
1461
1553
|
id: this._instanceId
|
|
1462
1554
|
}), {
|
|
1463
|
-
F:
|
|
1464
|
-
L:
|
|
1555
|
+
F: __dxlog_file7,
|
|
1556
|
+
L: 131,
|
|
1465
1557
|
S: this,
|
|
1466
1558
|
C: (f, a) => f(...a)
|
|
1467
1559
|
});
|
|
1468
1560
|
await this._messenger.open();
|
|
1469
1561
|
await this._signalManager.open();
|
|
1470
|
-
|
|
1562
|
+
log7.trace("dxos.mesh.network-manager.open", trace3.end({
|
|
1471
1563
|
id: this._instanceId
|
|
1472
1564
|
}), {
|
|
1473
|
-
F:
|
|
1474
|
-
L:
|
|
1565
|
+
F: __dxlog_file7,
|
|
1566
|
+
L: 134,
|
|
1475
1567
|
S: this,
|
|
1476
1568
|
C: (f, a) => f(...a)
|
|
1477
1569
|
});
|
|
@@ -1479,9 +1571,9 @@ var NetworkManager = class {
|
|
|
1479
1571
|
async close() {
|
|
1480
1572
|
for (const topic of this._swarms.keys()) {
|
|
1481
1573
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1482
|
-
|
|
1483
|
-
F:
|
|
1484
|
-
L:
|
|
1574
|
+
log7(err, void 0, {
|
|
1575
|
+
F: __dxlog_file7,
|
|
1576
|
+
L: 140,
|
|
1485
1577
|
S: this,
|
|
1486
1578
|
C: (f, a) => f(...a)
|
|
1487
1579
|
});
|
|
@@ -1495,30 +1587,30 @@ var NetworkManager = class {
|
|
|
1495
1587
|
*/
|
|
1496
1588
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1497
1589
|
var _a;
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1590
|
+
invariant6(PublicKey8.isPublicKey(topic));
|
|
1591
|
+
invariant6(PublicKey8.isPublicKey(peerId));
|
|
1592
|
+
invariant6(topology);
|
|
1593
|
+
invariant6(typeof protocol === "function");
|
|
1502
1594
|
if (this._swarms.has(topic)) {
|
|
1503
|
-
throw new Error(`Already connected to swarm: ${
|
|
1595
|
+
throw new Error(`Already connected to swarm: ${PublicKey8.from(topic)}`);
|
|
1504
1596
|
}
|
|
1505
|
-
|
|
1506
|
-
topic:
|
|
1597
|
+
log7("joining", {
|
|
1598
|
+
topic: PublicKey8.from(topic),
|
|
1507
1599
|
peerId,
|
|
1508
1600
|
topology: topology.toString()
|
|
1509
1601
|
}, {
|
|
1510
|
-
F:
|
|
1511
|
-
L:
|
|
1602
|
+
F: __dxlog_file7,
|
|
1603
|
+
L: 166,
|
|
1512
1604
|
S: this,
|
|
1513
1605
|
C: (f, a) => f(...a)
|
|
1514
1606
|
});
|
|
1515
|
-
const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label);
|
|
1607
|
+
const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
1516
1608
|
swarm.errors.handle((error) => {
|
|
1517
|
-
|
|
1609
|
+
log7("swarm error", {
|
|
1518
1610
|
error
|
|
1519
1611
|
}, {
|
|
1520
|
-
F:
|
|
1521
|
-
L:
|
|
1612
|
+
F: __dxlog_file7,
|
|
1613
|
+
L: 179,
|
|
1522
1614
|
S: this,
|
|
1523
1615
|
C: (f, a) => f(...a)
|
|
1524
1616
|
});
|
|
@@ -1529,20 +1621,20 @@ var NetworkManager = class {
|
|
|
1529
1621
|
this._signalConnection.join({
|
|
1530
1622
|
topic,
|
|
1531
1623
|
peerId
|
|
1532
|
-
}).catch((error) =>
|
|
1533
|
-
F:
|
|
1534
|
-
L:
|
|
1624
|
+
}).catch((error) => log7.catch(error, void 0, {
|
|
1625
|
+
F: __dxlog_file7,
|
|
1626
|
+
L: 188,
|
|
1535
1627
|
S: this,
|
|
1536
1628
|
C: (f, a) => f(...a)
|
|
1537
1629
|
}));
|
|
1538
1630
|
this.topicsUpdated.emit();
|
|
1539
1631
|
(_a = this._connectionLog) == null ? void 0 : _a.joinedSwarm(swarm);
|
|
1540
|
-
|
|
1541
|
-
topic:
|
|
1632
|
+
log7("joined", {
|
|
1633
|
+
topic: PublicKey8.from(topic),
|
|
1542
1634
|
count: this._swarms.size
|
|
1543
1635
|
}, {
|
|
1544
|
-
F:
|
|
1545
|
-
L:
|
|
1636
|
+
F: __dxlog_file7,
|
|
1637
|
+
L: 192,
|
|
1546
1638
|
S: this,
|
|
1547
1639
|
C: (f, a) => f(...a)
|
|
1548
1640
|
});
|
|
@@ -1558,11 +1650,11 @@ var NetworkManager = class {
|
|
|
1558
1650
|
if (!this._swarms.has(topic)) {
|
|
1559
1651
|
return;
|
|
1560
1652
|
}
|
|
1561
|
-
|
|
1562
|
-
topic:
|
|
1653
|
+
log7("leaving", {
|
|
1654
|
+
topic: PublicKey8.from(topic)
|
|
1563
1655
|
}, {
|
|
1564
|
-
F:
|
|
1565
|
-
L:
|
|
1656
|
+
F: __dxlog_file7,
|
|
1657
|
+
L: 208,
|
|
1566
1658
|
S: this,
|
|
1567
1659
|
C: (f, a) => f(...a)
|
|
1568
1660
|
});
|
|
@@ -1578,12 +1670,12 @@ var NetworkManager = class {
|
|
|
1578
1670
|
await swarm.destroy();
|
|
1579
1671
|
this._swarms.delete(topic);
|
|
1580
1672
|
await this.topicsUpdated.emit();
|
|
1581
|
-
|
|
1582
|
-
topic:
|
|
1673
|
+
log7("left", {
|
|
1674
|
+
topic: PublicKey8.from(topic),
|
|
1583
1675
|
count: this._swarms.size
|
|
1584
1676
|
}, {
|
|
1585
|
-
F:
|
|
1586
|
-
L:
|
|
1677
|
+
F: __dxlog_file7,
|
|
1678
|
+
L: 222,
|
|
1587
1679
|
S: this,
|
|
1588
1680
|
C: (f, a) => f(...a)
|
|
1589
1681
|
});
|
|
@@ -1617,17 +1709,17 @@ var NetworkManager = class {
|
|
|
1617
1709
|
};
|
|
1618
1710
|
|
|
1619
1711
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1620
|
-
import
|
|
1712
|
+
import invariant7 from "tiny-invariant";
|
|
1621
1713
|
var FullyConnectedTopology = class {
|
|
1622
1714
|
toString() {
|
|
1623
1715
|
return "FullyConnectedTopology";
|
|
1624
1716
|
}
|
|
1625
1717
|
init(controller) {
|
|
1626
|
-
|
|
1718
|
+
invariant7(!this._controller, "Already initialized");
|
|
1627
1719
|
this._controller = controller;
|
|
1628
1720
|
}
|
|
1629
1721
|
update() {
|
|
1630
|
-
|
|
1722
|
+
invariant7(this._controller, "Not initialized");
|
|
1631
1723
|
const { candidates: discovered } = this._controller.getState();
|
|
1632
1724
|
for (const peer of discovered) {
|
|
1633
1725
|
this._controller.connect(peer);
|
|
@@ -1641,10 +1733,10 @@ var FullyConnectedTopology = class {
|
|
|
1641
1733
|
};
|
|
1642
1734
|
|
|
1643
1735
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1644
|
-
import
|
|
1736
|
+
import invariant8 from "tiny-invariant";
|
|
1645
1737
|
import distance from "xor-distance";
|
|
1646
|
-
import { log as
|
|
1647
|
-
var
|
|
1738
|
+
import { log as log8 } from "@dxos/log";
|
|
1739
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
1648
1740
|
var MMSTTopology = class {
|
|
1649
1741
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
1650
1742
|
this._sampleCollected = false;
|
|
@@ -1653,15 +1745,15 @@ var MMSTTopology = class {
|
|
|
1653
1745
|
this._sampleSize = sampleSize;
|
|
1654
1746
|
}
|
|
1655
1747
|
init(controller) {
|
|
1656
|
-
|
|
1748
|
+
invariant8(!this._controller, "Already initialized");
|
|
1657
1749
|
this._controller = controller;
|
|
1658
1750
|
}
|
|
1659
1751
|
update() {
|
|
1660
|
-
|
|
1752
|
+
invariant8(this._controller, "Not initialized");
|
|
1661
1753
|
const { connected, candidates } = this._controller.getState();
|
|
1662
1754
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
1663
|
-
|
|
1664
|
-
F:
|
|
1755
|
+
log8("Running the algorithm.", void 0, {
|
|
1756
|
+
F: __dxlog_file8,
|
|
1665
1757
|
L: 55,
|
|
1666
1758
|
S: this,
|
|
1667
1759
|
C: (f, a) => f(...a)
|
|
@@ -1671,11 +1763,11 @@ var MMSTTopology = class {
|
|
|
1671
1763
|
}
|
|
1672
1764
|
}
|
|
1673
1765
|
async onOffer(peer) {
|
|
1674
|
-
|
|
1766
|
+
invariant8(this._controller, "Not initialized");
|
|
1675
1767
|
const { connected } = this._controller.getState();
|
|
1676
1768
|
const accept = connected.length < this._maxPeers;
|
|
1677
|
-
|
|
1678
|
-
F:
|
|
1769
|
+
log8(`Offer ${peer} accept=${accept}`, void 0, {
|
|
1770
|
+
F: __dxlog_file8,
|
|
1679
1771
|
L: 65,
|
|
1680
1772
|
S: this,
|
|
1681
1773
|
C: (f, a) => f(...a)
|
|
@@ -1685,13 +1777,13 @@ var MMSTTopology = class {
|
|
|
1685
1777
|
async destroy() {
|
|
1686
1778
|
}
|
|
1687
1779
|
_runAlgorithm() {
|
|
1688
|
-
|
|
1780
|
+
invariant8(this._controller, "Not initialized");
|
|
1689
1781
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
1690
1782
|
if (connected.length > this._maxPeers) {
|
|
1691
1783
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
1692
1784
|
for (const peer of sorted) {
|
|
1693
|
-
|
|
1694
|
-
F:
|
|
1785
|
+
log8(`Disconnect ${peer}.`, void 0, {
|
|
1786
|
+
F: __dxlog_file8,
|
|
1695
1787
|
L: 83,
|
|
1696
1788
|
S: this,
|
|
1697
1789
|
C: (f, a) => f(...a)
|
|
@@ -1702,8 +1794,8 @@ var MMSTTopology = class {
|
|
|
1702
1794
|
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
1703
1795
|
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
1704
1796
|
for (const peer of sorted) {
|
|
1705
|
-
|
|
1706
|
-
F:
|
|
1797
|
+
log8(`Connect ${peer}.`, void 0, {
|
|
1798
|
+
F: __dxlog_file8,
|
|
1707
1799
|
L: 91,
|
|
1708
1800
|
S: this,
|
|
1709
1801
|
C: (f, a) => f(...a)
|
|
@@ -1719,9 +1811,9 @@ var MMSTTopology = class {
|
|
|
1719
1811
|
var sortByXorDistance = (keys, reference) => keys.sort((a, b) => distance.gt(distance(a.asBuffer(), reference.asBuffer()), distance(b.asBuffer(), reference.asBuffer())));
|
|
1720
1812
|
|
|
1721
1813
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1722
|
-
import
|
|
1723
|
-
import { log as
|
|
1724
|
-
var
|
|
1814
|
+
import invariant9 from "tiny-invariant";
|
|
1815
|
+
import { log as log9 } from "@dxos/log";
|
|
1816
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
1725
1817
|
var StarTopology = class {
|
|
1726
1818
|
// prettier-ignore
|
|
1727
1819
|
constructor(_centralPeer) {
|
|
@@ -1731,25 +1823,25 @@ var StarTopology = class {
|
|
|
1731
1823
|
return `StarTopology(${this._centralPeer.truncate()})`;
|
|
1732
1824
|
}
|
|
1733
1825
|
init(controller) {
|
|
1734
|
-
|
|
1826
|
+
invariant9(!this._controller, "Already initialized.");
|
|
1735
1827
|
this._controller = controller;
|
|
1736
1828
|
}
|
|
1737
1829
|
update() {
|
|
1738
|
-
|
|
1830
|
+
invariant9(this._controller, "Not initialized.");
|
|
1739
1831
|
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
1740
1832
|
if (!ownPeerId.equals(this._centralPeer)) {
|
|
1741
|
-
|
|
1742
|
-
F:
|
|
1833
|
+
log9("leaf peer dropping all connections apart from central peer.", void 0, {
|
|
1834
|
+
F: __dxlog_file9,
|
|
1743
1835
|
L: 33,
|
|
1744
1836
|
S: this,
|
|
1745
1837
|
C: (f, a) => f(...a)
|
|
1746
1838
|
});
|
|
1747
1839
|
for (const peer of connected) {
|
|
1748
1840
|
if (!peer.equals(this._centralPeer)) {
|
|
1749
|
-
|
|
1841
|
+
log9("dropping connection", {
|
|
1750
1842
|
peer
|
|
1751
1843
|
}, {
|
|
1752
|
-
F:
|
|
1844
|
+
F: __dxlog_file9,
|
|
1753
1845
|
L: 38,
|
|
1754
1846
|
S: this,
|
|
1755
1847
|
C: (f, a) => f(...a)
|
|
@@ -1760,10 +1852,10 @@ var StarTopology = class {
|
|
|
1760
1852
|
}
|
|
1761
1853
|
for (const peer of candidates) {
|
|
1762
1854
|
if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
|
|
1763
|
-
|
|
1855
|
+
log9("connecting to peer", {
|
|
1764
1856
|
peer
|
|
1765
1857
|
}, {
|
|
1766
|
-
F:
|
|
1858
|
+
F: __dxlog_file9,
|
|
1767
1859
|
L: 47,
|
|
1768
1860
|
S: this,
|
|
1769
1861
|
C: (f, a) => f(...a)
|
|
@@ -1773,14 +1865,14 @@ var StarTopology = class {
|
|
|
1773
1865
|
}
|
|
1774
1866
|
}
|
|
1775
1867
|
async onOffer(peer) {
|
|
1776
|
-
|
|
1868
|
+
invariant9(this._controller, "Not initialized.");
|
|
1777
1869
|
const { ownPeerId } = this._controller.getState();
|
|
1778
|
-
|
|
1870
|
+
log9("offer", {
|
|
1779
1871
|
peer,
|
|
1780
1872
|
isCentral: peer.equals(this._centralPeer),
|
|
1781
1873
|
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
1782
1874
|
}, {
|
|
1783
|
-
F:
|
|
1875
|
+
F: __dxlog_file9,
|
|
1784
1876
|
L: 56,
|
|
1785
1877
|
S: this,
|
|
1786
1878
|
C: (f, a) => f(...a)
|
|
@@ -1793,12 +1885,12 @@ var StarTopology = class {
|
|
|
1793
1885
|
|
|
1794
1886
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1795
1887
|
import { Transform } from "@dxos/node-std/stream";
|
|
1796
|
-
import
|
|
1888
|
+
import invariant10 from "tiny-invariant";
|
|
1797
1889
|
import { Event as Event6, Trigger } from "@dxos/async";
|
|
1798
1890
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
1799
|
-
import { PublicKey as
|
|
1800
|
-
import { log as
|
|
1801
|
-
import { ComplexMap as
|
|
1891
|
+
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
1892
|
+
import { log as log10, logInfo as logInfo2 } from "@dxos/log";
|
|
1893
|
+
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
1802
1894
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
1803
1895
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1804
1896
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1809,7 +1901,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
1809
1901
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1810
1902
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1811
1903
|
}
|
|
1812
|
-
var
|
|
1904
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
1813
1905
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1814
1906
|
var createStreamDelay = (delay) => {
|
|
1815
1907
|
return new Transform({
|
|
@@ -1829,23 +1921,23 @@ var _MemoryTransport = class {
|
|
|
1829
1921
|
this.closed = new Event6();
|
|
1830
1922
|
this.connected = new Event6();
|
|
1831
1923
|
this.errors = new ErrorStream3();
|
|
1832
|
-
this._instanceId =
|
|
1924
|
+
this._instanceId = PublicKey9.random();
|
|
1833
1925
|
this._remote = new Trigger();
|
|
1834
1926
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1835
1927
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1836
1928
|
this._destroyed = false;
|
|
1837
|
-
|
|
1838
|
-
F:
|
|
1929
|
+
log10("creating", void 0, {
|
|
1930
|
+
F: __dxlog_file10,
|
|
1839
1931
|
L: 64,
|
|
1840
1932
|
S: this,
|
|
1841
1933
|
C: (f, a) => f(...a)
|
|
1842
1934
|
});
|
|
1843
|
-
|
|
1935
|
+
invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
|
|
1844
1936
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1845
1937
|
if (this.options.initiator) {
|
|
1846
1938
|
setTimeout(async () => {
|
|
1847
|
-
|
|
1848
|
-
F:
|
|
1939
|
+
log10("sending signal", void 0, {
|
|
1940
|
+
F: __dxlog_file10,
|
|
1849
1941
|
L: 73,
|
|
1850
1942
|
S: this,
|
|
1851
1943
|
C: (f, a) => f(...a)
|
|
@@ -1874,11 +1966,11 @@ var _MemoryTransport = class {
|
|
|
1874
1966
|
this.closed.emit();
|
|
1875
1967
|
return;
|
|
1876
1968
|
}
|
|
1877
|
-
|
|
1969
|
+
invariant10(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`);
|
|
1878
1970
|
this._remoteConnection._remoteConnection = this;
|
|
1879
1971
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1880
|
-
|
|
1881
|
-
F:
|
|
1972
|
+
log10("connected", void 0, {
|
|
1973
|
+
F: __dxlog_file10,
|
|
1882
1974
|
L: 103,
|
|
1883
1975
|
S: this,
|
|
1884
1976
|
C: (f, a) => f(...a)
|
|
@@ -1895,8 +1987,8 @@ var _MemoryTransport = class {
|
|
|
1895
1987
|
}
|
|
1896
1988
|
}
|
|
1897
1989
|
async destroy() {
|
|
1898
|
-
|
|
1899
|
-
F:
|
|
1990
|
+
log10("closing", void 0, {
|
|
1991
|
+
F: __dxlog_file10,
|
|
1900
1992
|
L: 124,
|
|
1901
1993
|
S: this,
|
|
1902
1994
|
C: (f, a) => f(...a)
|
|
@@ -1904,8 +1996,8 @@ var _MemoryTransport = class {
|
|
|
1904
1996
|
this._destroyed = true;
|
|
1905
1997
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
1906
1998
|
if (this._remoteConnection) {
|
|
1907
|
-
|
|
1908
|
-
F:
|
|
1999
|
+
log10("closing", void 0, {
|
|
2000
|
+
F: __dxlog_file10,
|
|
1909
2001
|
L: 129,
|
|
1910
2002
|
S: this,
|
|
1911
2003
|
C: (f, a) => f(...a)
|
|
@@ -1917,26 +2009,26 @@ var _MemoryTransport = class {
|
|
|
1917
2009
|
this._remoteConnection.closed.emit();
|
|
1918
2010
|
this._remoteConnection._remoteConnection = void 0;
|
|
1919
2011
|
this._remoteConnection = void 0;
|
|
1920
|
-
|
|
1921
|
-
F:
|
|
2012
|
+
log10("closed", void 0, {
|
|
2013
|
+
F: __dxlog_file10,
|
|
1922
2014
|
L: 147,
|
|
1923
2015
|
S: this,
|
|
1924
2016
|
C: (f, a) => f(...a)
|
|
1925
2017
|
});
|
|
1926
2018
|
}
|
|
1927
2019
|
this.closed.emit();
|
|
1928
|
-
|
|
1929
|
-
F:
|
|
2020
|
+
log10("closed", void 0, {
|
|
2021
|
+
F: __dxlog_file10,
|
|
1930
2022
|
L: 151,
|
|
1931
2023
|
S: this,
|
|
1932
2024
|
C: (f, a) => f(...a)
|
|
1933
2025
|
});
|
|
1934
2026
|
}
|
|
1935
2027
|
signal({ payload }) {
|
|
1936
|
-
|
|
2028
|
+
log10("received signal", {
|
|
1937
2029
|
payload
|
|
1938
2030
|
}, {
|
|
1939
|
-
F:
|
|
2031
|
+
F: __dxlog_file10,
|
|
1940
2032
|
L: 155,
|
|
1941
2033
|
S: this,
|
|
1942
2034
|
C: (f, a) => f(...a)
|
|
@@ -1946,14 +2038,14 @@ var _MemoryTransport = class {
|
|
|
1946
2038
|
}
|
|
1947
2039
|
const transportId = payload.transportId;
|
|
1948
2040
|
if (transportId) {
|
|
1949
|
-
const remoteId =
|
|
2041
|
+
const remoteId = PublicKey9.fromHex(transportId);
|
|
1950
2042
|
this._remote.wake(remoteId);
|
|
1951
2043
|
}
|
|
1952
2044
|
}
|
|
1953
2045
|
};
|
|
1954
2046
|
var MemoryTransport = _MemoryTransport;
|
|
1955
2047
|
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
1956
|
-
MemoryTransport._connections = new
|
|
2048
|
+
MemoryTransport._connections = new ComplexMap7(PublicKey9.hash);
|
|
1957
2049
|
_ts_decorate4([
|
|
1958
2050
|
logInfo2
|
|
1959
2051
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
@@ -1963,11 +2055,11 @@ _ts_decorate4([
|
|
|
1963
2055
|
|
|
1964
2056
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1965
2057
|
import SimplePeerConstructor from "simple-peer";
|
|
1966
|
-
import
|
|
2058
|
+
import invariant11 from "tiny-invariant";
|
|
1967
2059
|
import { Event as Event7 } from "@dxos/async";
|
|
1968
2060
|
import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
|
|
1969
|
-
import { PublicKey as
|
|
1970
|
-
import { log as
|
|
2061
|
+
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
2062
|
+
import { log as log11 } from "@dxos/log";
|
|
1971
2063
|
import { trace as trace4 } from "@dxos/protocols";
|
|
1972
2064
|
|
|
1973
2065
|
// packages/core/mesh/network-manager/src/transport/webrtc.ts
|
|
@@ -1978,7 +2070,7 @@ try {
|
|
|
1978
2070
|
}
|
|
1979
2071
|
|
|
1980
2072
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1981
|
-
var
|
|
2073
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
|
|
1982
2074
|
var WebRTCTransport = class {
|
|
1983
2075
|
constructor(params) {
|
|
1984
2076
|
var _a;
|
|
@@ -1987,17 +2079,17 @@ var WebRTCTransport = class {
|
|
|
1987
2079
|
this.closed = new Event7();
|
|
1988
2080
|
this.connected = new Event7();
|
|
1989
2081
|
this.errors = new ErrorStream4();
|
|
1990
|
-
this._instanceId =
|
|
1991
|
-
|
|
2082
|
+
this._instanceId = PublicKey10.random().toHex();
|
|
2083
|
+
log11.trace("dxos.mesh.webrtc-transport.constructor", trace4.begin({
|
|
1992
2084
|
id: this._instanceId
|
|
1993
2085
|
}), {
|
|
1994
|
-
F:
|
|
2086
|
+
F: __dxlog_file11,
|
|
1995
2087
|
L: 39,
|
|
1996
2088
|
S: this,
|
|
1997
2089
|
C: (f, a) => f(...a)
|
|
1998
2090
|
});
|
|
1999
|
-
|
|
2000
|
-
F:
|
|
2091
|
+
log11("created connection", params, {
|
|
2092
|
+
F: __dxlog_file11,
|
|
2001
2093
|
L: 40,
|
|
2002
2094
|
S: this,
|
|
2003
2095
|
C: (f, a) => f(...a)
|
|
@@ -2008,8 +2100,8 @@ var WebRTCTransport = class {
|
|
|
2008
2100
|
config: this.params.webrtcConfig
|
|
2009
2101
|
});
|
|
2010
2102
|
this._peer.on("signal", async (data) => {
|
|
2011
|
-
|
|
2012
|
-
F:
|
|
2103
|
+
log11("signal", data, {
|
|
2104
|
+
F: __dxlog_file11,
|
|
2013
2105
|
L: 48,
|
|
2014
2106
|
S: this,
|
|
2015
2107
|
C: (f, a) => f(...a)
|
|
@@ -2021,8 +2113,8 @@ var WebRTCTransport = class {
|
|
|
2021
2113
|
});
|
|
2022
2114
|
});
|
|
2023
2115
|
this._peer.on("connect", () => {
|
|
2024
|
-
|
|
2025
|
-
F:
|
|
2116
|
+
log11("connected", void 0, {
|
|
2117
|
+
F: __dxlog_file11,
|
|
2026
2118
|
L: 53,
|
|
2027
2119
|
S: this,
|
|
2028
2120
|
C: (f, a) => f(...a)
|
|
@@ -2031,8 +2123,8 @@ var WebRTCTransport = class {
|
|
|
2031
2123
|
this.connected.emit();
|
|
2032
2124
|
});
|
|
2033
2125
|
this._peer.on("close", async () => {
|
|
2034
|
-
|
|
2035
|
-
F:
|
|
2126
|
+
log11("closed", void 0, {
|
|
2127
|
+
F: __dxlog_file11,
|
|
2036
2128
|
L: 59,
|
|
2037
2129
|
S: this,
|
|
2038
2130
|
C: (f, a) => f(...a)
|
|
@@ -2046,11 +2138,11 @@ var WebRTCTransport = class {
|
|
|
2046
2138
|
try {
|
|
2047
2139
|
if (typeof ((_a2 = this._peer) == null ? void 0 : _a2._pc.getStats) === "function") {
|
|
2048
2140
|
this._peer._pc.getStats().then((stats) => {
|
|
2049
|
-
|
|
2141
|
+
log11.warn("report after webrtc error", {
|
|
2050
2142
|
config: this.params.webrtcConfig,
|
|
2051
2143
|
stats
|
|
2052
2144
|
}, {
|
|
2053
|
-
F:
|
|
2145
|
+
F: __dxlog_file11,
|
|
2054
2146
|
L: 71,
|
|
2055
2147
|
S: this,
|
|
2056
2148
|
C: (f, a) => f(...a)
|
|
@@ -2061,18 +2153,18 @@ var WebRTCTransport = class {
|
|
|
2061
2153
|
}
|
|
2062
2154
|
await this.destroy();
|
|
2063
2155
|
});
|
|
2064
|
-
|
|
2156
|
+
log11.trace("dxos.mesh.webrtc-transport.constructor", trace4.end({
|
|
2065
2157
|
id: this._instanceId
|
|
2066
2158
|
}), {
|
|
2067
|
-
F:
|
|
2159
|
+
F: __dxlog_file11,
|
|
2068
2160
|
L: 81,
|
|
2069
2161
|
S: this,
|
|
2070
2162
|
C: (f, a) => f(...a)
|
|
2071
2163
|
});
|
|
2072
2164
|
}
|
|
2073
2165
|
async destroy() {
|
|
2074
|
-
|
|
2075
|
-
F:
|
|
2166
|
+
log11("closing...", void 0, {
|
|
2167
|
+
F: __dxlog_file11,
|
|
2076
2168
|
L: 85,
|
|
2077
2169
|
S: this,
|
|
2078
2170
|
C: (f, a) => f(...a)
|
|
@@ -2081,8 +2173,8 @@ var WebRTCTransport = class {
|
|
|
2081
2173
|
await this._disconnectStreams();
|
|
2082
2174
|
this._peer.destroy();
|
|
2083
2175
|
this.closed.emit();
|
|
2084
|
-
|
|
2085
|
-
F:
|
|
2176
|
+
log11("closed", void 0, {
|
|
2177
|
+
F: __dxlog_file11,
|
|
2086
2178
|
L: 90,
|
|
2087
2179
|
S: this,
|
|
2088
2180
|
C: (f, a) => f(...a)
|
|
@@ -2092,7 +2184,7 @@ var WebRTCTransport = class {
|
|
|
2092
2184
|
if (this._closed) {
|
|
2093
2185
|
return;
|
|
2094
2186
|
}
|
|
2095
|
-
|
|
2187
|
+
invariant11(signal.payload.data, "Signal message must contain signal data.");
|
|
2096
2188
|
this._peer.signal(signal.payload.data);
|
|
2097
2189
|
}
|
|
2098
2190
|
async _disconnectStreams() {
|
|
@@ -2109,18 +2201,18 @@ var createWebRTCTransportFactory = (webrtcConfig) => ({
|
|
|
2109
2201
|
|
|
2110
2202
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
2111
2203
|
import { Duplex } from "@dxos/node-std/stream";
|
|
2112
|
-
import
|
|
2204
|
+
import invariant12 from "tiny-invariant";
|
|
2113
2205
|
import { Stream } from "@dxos/codec-protobuf";
|
|
2114
|
-
import { PublicKey as
|
|
2115
|
-
import { log as
|
|
2206
|
+
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
2207
|
+
import { log as log12 } from "@dxos/log";
|
|
2116
2208
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
2117
|
-
import { ComplexMap as
|
|
2118
|
-
var
|
|
2209
|
+
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
2210
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
|
|
2119
2211
|
var WebRTCTransportService = class {
|
|
2120
2212
|
// prettier-ignore
|
|
2121
2213
|
constructor(_webrtcConfig) {
|
|
2122
2214
|
this._webrtcConfig = _webrtcConfig;
|
|
2123
|
-
this.transports = new
|
|
2215
|
+
this.transports = new ComplexMap8(PublicKey11.hash);
|
|
2124
2216
|
}
|
|
2125
2217
|
open(request) {
|
|
2126
2218
|
const rpcStream = new Stream(({ ready, next, close }) => {
|
|
@@ -2186,11 +2278,11 @@ var WebRTCTransportService = class {
|
|
|
2186
2278
|
return rpcStream;
|
|
2187
2279
|
}
|
|
2188
2280
|
async sendSignal({ proxyId, signal }) {
|
|
2189
|
-
|
|
2281
|
+
invariant12(this.transports.has(proxyId));
|
|
2190
2282
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2191
2283
|
}
|
|
2192
2284
|
async sendData({ proxyId, payload }) {
|
|
2193
|
-
|
|
2285
|
+
invariant12(this.transports.has(proxyId));
|
|
2194
2286
|
await this.transports.get(proxyId).stream.push(payload);
|
|
2195
2287
|
}
|
|
2196
2288
|
async close({ proxyId }) {
|
|
@@ -2198,8 +2290,8 @@ var WebRTCTransportService = class {
|
|
|
2198
2290
|
await ((_a = this.transports.get(proxyId)) == null ? void 0 : _a.transport.destroy());
|
|
2199
2291
|
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
2200
2292
|
this.transports.delete(proxyId);
|
|
2201
|
-
|
|
2202
|
-
F:
|
|
2293
|
+
log12("Closed.", void 0, {
|
|
2294
|
+
F: __dxlog_file12,
|
|
2203
2295
|
L: 109,
|
|
2204
2296
|
S: this,
|
|
2205
2297
|
C: (f, a) => f(...a)
|
|
@@ -2208,21 +2300,21 @@ var WebRTCTransportService = class {
|
|
|
2208
2300
|
};
|
|
2209
2301
|
|
|
2210
2302
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2211
|
-
import
|
|
2303
|
+
import invariant13 from "tiny-invariant";
|
|
2212
2304
|
import { Event as Event8 } from "@dxos/async";
|
|
2213
|
-
import { Context as
|
|
2305
|
+
import { Context as Context6 } from "@dxos/context";
|
|
2214
2306
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
2215
|
-
import { PublicKey as
|
|
2216
|
-
import { log as
|
|
2307
|
+
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
2308
|
+
import { log as log13 } from "@dxos/log";
|
|
2217
2309
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
2218
2310
|
import { arrayToBuffer } from "@dxos/util";
|
|
2219
|
-
var
|
|
2311
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
|
|
2220
2312
|
var WebRTCTransportProxy = class {
|
|
2221
2313
|
// prettier-ignore
|
|
2222
2314
|
constructor(_params) {
|
|
2223
2315
|
this._params = _params;
|
|
2224
|
-
this._proxyId =
|
|
2225
|
-
this._ctx = new
|
|
2316
|
+
this._proxyId = PublicKey12.random();
|
|
2317
|
+
this._ctx = new Context6();
|
|
2226
2318
|
this.closed = new Event8();
|
|
2227
2319
|
this._closed = false;
|
|
2228
2320
|
this.connected = new Event8();
|
|
@@ -2233,8 +2325,8 @@ var WebRTCTransportProxy = class {
|
|
|
2233
2325
|
});
|
|
2234
2326
|
this._serviceStream.waitUntilReady().then(() => {
|
|
2235
2327
|
this._serviceStream.subscribe(async (event) => {
|
|
2236
|
-
|
|
2237
|
-
F:
|
|
2328
|
+
log13("WebRTCTransportProxy: event", event, {
|
|
2329
|
+
F: __dxlog_file13,
|
|
2238
2330
|
L: 50,
|
|
2239
2331
|
S: this,
|
|
2240
2332
|
C: (f, a) => f(...a)
|
|
@@ -2254,8 +2346,8 @@ var WebRTCTransportProxy = class {
|
|
|
2254
2346
|
payload: data
|
|
2255
2347
|
});
|
|
2256
2348
|
} catch (err) {
|
|
2257
|
-
|
|
2258
|
-
F:
|
|
2349
|
+
log13.catch(err, void 0, {
|
|
2350
|
+
F: __dxlog_file13,
|
|
2259
2351
|
L: 67,
|
|
2260
2352
|
S: this,
|
|
2261
2353
|
C: (f, a) => f(...a)
|
|
@@ -2266,8 +2358,8 @@ var WebRTCTransportProxy = class {
|
|
|
2266
2358
|
this._ctx.onDispose(() => {
|
|
2267
2359
|
this._params.stream.off("data", dataListener);
|
|
2268
2360
|
});
|
|
2269
|
-
}, (error) =>
|
|
2270
|
-
F:
|
|
2361
|
+
}, (error) => log13.catch(error, void 0, {
|
|
2362
|
+
F: __dxlog_file13,
|
|
2271
2363
|
L: 73,
|
|
2272
2364
|
S: this,
|
|
2273
2365
|
C: (f, a) => f(...a)
|
|
@@ -2312,8 +2404,8 @@ var WebRTCTransportProxy = class {
|
|
|
2312
2404
|
proxyId: this._proxyId
|
|
2313
2405
|
});
|
|
2314
2406
|
} catch (err) {
|
|
2315
|
-
|
|
2316
|
-
F:
|
|
2407
|
+
log13.catch(err, void 0, {
|
|
2408
|
+
F: __dxlog_file13,
|
|
2317
2409
|
L: 124,
|
|
2318
2410
|
S: this,
|
|
2319
2411
|
C: (f, a) => f(...a)
|
|
@@ -2348,7 +2440,7 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2348
2440
|
return this;
|
|
2349
2441
|
}
|
|
2350
2442
|
createTransport(options) {
|
|
2351
|
-
|
|
2443
|
+
invariant13(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections");
|
|
2352
2444
|
const transport = new WebRTCTransportProxy({
|
|
2353
2445
|
...options,
|
|
2354
2446
|
bridgeService: this._bridgeService
|
|
@@ -2383,6 +2475,8 @@ export {
|
|
|
2383
2475
|
SwarmMessenger,
|
|
2384
2476
|
Swarm,
|
|
2385
2477
|
SwarmMapper,
|
|
2478
|
+
MAX_CONCURRENT_INITIATING_CONNECTIONS,
|
|
2479
|
+
ConnectionLimiter,
|
|
2386
2480
|
EventType,
|
|
2387
2481
|
ConnectionLog,
|
|
2388
2482
|
NetworkManager,
|
|
@@ -2398,4 +2492,4 @@ export {
|
|
|
2398
2492
|
WebRTCTransportProxyFactory,
|
|
2399
2493
|
createTeleportProtocolFactory
|
|
2400
2494
|
};
|
|
2401
|
-
//# sourceMappingURL=chunk-
|
|
2495
|
+
//# sourceMappingURL=chunk-5R7TDXUU.mjs.map
|