@dxos/network-manager 0.1.56-main.c787da3 → 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.
Files changed (37) hide show
  1. package/dist/lib/browser/{chunk-MIYEP22D.mjs → chunk-5R7TDXUU.mjs} +323 -229
  2. package/dist/lib/browser/chunk-5R7TDXUU.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +5 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +1 -1
  6. package/dist/lib/node/index.cjs +318 -222
  7. package/dist/lib/node/index.cjs.map +4 -4
  8. package/dist/lib/node/meta.json +1 -1
  9. package/dist/lib/node/testing/index.cjs +314 -222
  10. package/dist/lib/node/testing/index.cjs.map +4 -4
  11. package/dist/types/src/network-manager.d.ts +1 -1
  12. package/dist/types/src/network-manager.d.ts.map +1 -1
  13. package/dist/types/src/swarm/connection-limiter.d.ts +28 -0
  14. package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -0
  15. package/dist/types/src/swarm/connection-limiter.test.d.ts +2 -0
  16. package/dist/types/src/swarm/connection-limiter.test.d.ts.map +1 -0
  17. package/dist/types/src/swarm/connection.d.ts +1 -1
  18. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  19. package/dist/types/src/swarm/connection.test.d.ts +2 -0
  20. package/dist/types/src/swarm/connection.test.d.ts.map +1 -0
  21. package/dist/types/src/swarm/index.d.ts +1 -0
  22. package/dist/types/src/swarm/index.d.ts.map +1 -1
  23. package/dist/types/src/swarm/peer.d.ts +3 -1
  24. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  25. package/dist/types/src/swarm/swarm.d.ts +3 -1
  26. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  27. package/package.json +17 -17
  28. package/src/network-manager.ts +18 -4
  29. package/src/swarm/connection-limiter.test.ts +44 -0
  30. package/src/swarm/connection-limiter.ts +71 -0
  31. package/src/swarm/connection.test.ts +72 -0
  32. package/src/swarm/connection.ts +1 -2
  33. package/src/swarm/index.ts +1 -0
  34. package/src/swarm/peer.ts +22 -7
  35. package/src/swarm/swarm.test.ts +140 -90
  36. package/src/swarm/swarm.ts +3 -1
  37. package/dist/lib/browser/chunk-MIYEP22D.mjs.map +0 -7
@@ -38,28 +38,28 @@ __export(testing_exports, {
38
38
  module.exports = __toCommonJS(testing_exports);
39
39
 
40
40
  // packages/core/mesh/network-manager/src/testing/test-builder.ts
41
- var import_keys13 = require("@dxos/keys");
41
+ var import_keys14 = require("@dxos/keys");
42
42
  var import_messaging2 = require("@dxos/messaging");
43
43
  var import_protocols6 = require("@dxos/protocols");
44
44
  var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
45
45
  var import_rpc = require("@dxos/rpc");
46
- var import_util10 = require("@dxos/util");
46
+ var import_util11 = require("@dxos/util");
47
47
 
48
48
  // packages/core/mesh/network-manager/src/network-manager.ts
49
49
  var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
50
- var import_async6 = require("@dxos/async");
51
- var import_keys7 = require("@dxos/keys");
52
- var import_log6 = require("@dxos/log");
50
+ var import_async7 = require("@dxos/async");
51
+ var import_keys8 = require("@dxos/keys");
52
+ var import_log7 = require("@dxos/log");
53
53
  var import_messaging = require("@dxos/messaging");
54
54
  var import_protocols4 = require("@dxos/protocols");
55
55
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
56
- var import_util5 = require("@dxos/util");
56
+ var import_util6 = require("@dxos/util");
57
57
 
58
58
  // packages/core/mesh/network-manager/src/connection-log.ts
59
- var import_async5 = require("@dxos/async");
59
+ var import_async6 = require("@dxos/async");
60
60
  var import_debug3 = require("@dxos/debug");
61
- var import_keys6 = require("@dxos/keys");
62
- var import_util4 = require("@dxos/util");
61
+ var import_keys7 = require("@dxos/keys");
62
+ var import_util5 = require("@dxos/util");
63
63
 
64
64
  // packages/core/mesh/network-manager/src/swarm/connection.ts
65
65
  var import_tiny_invariant = __toESM(require("tiny-invariant"));
@@ -151,14 +151,13 @@ var Connection = class {
151
151
  /**
152
152
  * Create an underlying transport and prepares it for the connection.
153
153
  */
154
- // TODO(burdon): Make async?
155
- openConnection() {
154
+ async openConnection() {
156
155
  (0, import_tiny_invariant.default)(this._state === ConnectionState.INITIAL, "Invalid state.");
157
156
  import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.begin({
158
157
  id: this._instanceId
159
158
  }), {
160
159
  F: __dxlog_file,
161
- L: 115,
160
+ L: 114,
162
161
  S: this,
163
162
  C: (f, a) => f(...a)
164
163
  });
@@ -169,7 +168,7 @@ var Connection = class {
169
168
  this._protocol.stream.on("close", () => {
170
169
  (0, import_log.log)("protocol stream closed", void 0, {
171
170
  F: __dxlog_file,
172
- L: 126,
171
+ L: 125,
173
172
  S: this,
174
173
  C: (f, a) => f(...a)
175
174
  });
@@ -201,7 +200,7 @@ var Connection = class {
201
200
  id: this._instanceId
202
201
  }), {
203
202
  F: __dxlog_file,
204
- L: 159,
203
+ L: 158,
205
204
  S: this,
206
205
  C: (f, a) => f(...a)
207
206
  });
@@ -217,7 +216,7 @@ var Connection = class {
217
216
  peerId: this.ownId
218
217
  }, {
219
218
  F: __dxlog_file,
220
- L: 171,
219
+ L: 170,
221
220
  S: this,
222
221
  C: (f, a) => f(...a)
223
222
  });
@@ -226,7 +225,7 @@ var Connection = class {
226
225
  } catch (err) {
227
226
  import_log.log.catch(err, void 0, {
228
227
  F: __dxlog_file,
229
- L: 177,
228
+ L: 176,
230
229
  S: this,
231
230
  C: (f, a) => f(...a)
232
231
  });
@@ -236,7 +235,7 @@ var Connection = class {
236
235
  } catch (err) {
237
236
  import_log.log.catch(err, void 0, {
238
237
  F: __dxlog_file,
239
- L: 184,
238
+ L: 183,
240
239
  S: this,
241
240
  C: (f, a) => f(...a)
242
241
  });
@@ -245,7 +244,7 @@ var Connection = class {
245
244
  peerId: this.ownId
246
245
  }, {
247
246
  F: __dxlog_file,
248
- L: 187,
247
+ L: 186,
249
248
  S: this,
250
249
  C: (f, a) => f(...a)
251
250
  });
@@ -285,7 +284,7 @@ var Connection = class {
285
284
  err
286
285
  }, {
287
286
  F: __dxlog_file,
288
- L: 221,
287
+ L: 220,
289
288
  S: this,
290
289
  C: (f, a) => f(...a)
291
290
  });
@@ -301,7 +300,7 @@ var Connection = class {
301
300
  if (!msg.sessionId.equals(this.sessionId)) {
302
301
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
303
302
  F: __dxlog_file,
304
- L: 232,
303
+ L: 231,
305
304
  S: this,
306
305
  C: (f, a) => f(...a)
307
306
  });
@@ -324,7 +323,7 @@ var Connection = class {
324
323
  msg: msg.data
325
324
  }, {
326
325
  F: __dxlog_file,
327
- L: 246,
326
+ L: 245,
328
327
  S: this,
329
328
  C: (f, a) => f(...a)
330
329
  });
@@ -337,7 +336,7 @@ var Connection = class {
337
336
  msg: msg.data
338
337
  }, {
339
338
  F: __dxlog_file,
340
- L: 250,
339
+ L: 249,
341
340
  S: this,
342
341
  C: (f, a) => f(...a)
343
342
  });
@@ -352,7 +351,7 @@ var Connection = class {
352
351
  peerId: this.ownId
353
352
  }, {
354
353
  F: __dxlog_file,
355
- L: 257,
354
+ L: 256,
356
355
  S: this,
357
356
  C: (f, a) => f(...a)
358
357
  });
@@ -567,6 +566,7 @@ var SwarmMessenger = class {
567
566
  var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
568
567
  var import_async2 = require("@dxos/async");
569
568
  var import_context3 = require("@dxos/context");
569
+ var import_errors2 = require("@dxos/errors");
570
570
  var import_keys3 = require("@dxos/keys");
571
571
  var import_log3 = require("@dxos/log");
572
572
  function _ts_decorate2(decorators, target, key, desc) {
@@ -582,13 +582,14 @@ function _ts_decorate2(decorators, target, key, desc) {
582
582
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
583
583
  var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
584
584
  var Peer = class {
585
- constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _callbacks) {
585
+ constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
586
586
  this.id = id;
587
587
  this.topic = topic;
588
588
  this.localPeerId = localPeerId;
589
589
  this._signalMessaging = _signalMessaging;
590
590
  this._protocolProvider = _protocolProvider;
591
591
  this._transportFactory = _transportFactory;
592
+ this._connectionLimiter = _connectionLimiter;
592
593
  this._callbacks = _callbacks;
593
594
  this._availableAfter = 0;
594
595
  this.availableToConnect = true;
@@ -600,16 +601,18 @@ var Peer = class {
600
601
  * Respond to remote offer.
601
602
  */
602
603
  async onOffer(message) {
604
+ var _a2;
603
605
  const remoteId = message.author;
604
606
  if (this.connection || this.initiating) {
605
607
  if (remoteId.toHex() < this.localPeerId.toHex()) {
606
- (0, import_log3.log)("closing local connection and accepting remote peer's offer", {
607
- id: this.id,
608
+ (0, import_log3.log)("close local connection", {
609
+ localPeerId: this.id,
608
610
  topic: this.topic,
609
- peerId: this.localPeerId
611
+ remotePeerId: this.localPeerId,
612
+ sessionId: (_a2 = this.connection) == null ? void 0 : _a2.sessionId
610
613
  }, {
611
614
  F: __dxlog_file3,
612
- L: 105,
615
+ L: 107,
613
616
  S: this,
614
617
  C: (f, a) => f(...a)
615
618
  });
@@ -627,19 +630,22 @@ var Peer = class {
627
630
  (0, import_tiny_invariant3.default)(message.sessionId);
628
631
  const connection = this._createConnection(false, message.sessionId);
629
632
  try {
630
- connection.openConnection();
633
+ await this._connectionLimiter.connecting(message.sessionId);
634
+ await connection.openConnection();
631
635
  } catch (err) {
632
- import_log3.log.warn("connection error", {
633
- topic: this.topic,
634
- peerId: this.localPeerId,
635
- remoteId: this.id,
636
- err
637
- }, {
638
- F: __dxlog_file3,
639
- L: 129,
640
- S: this,
641
- C: (f, a) => f(...a)
642
- });
636
+ if (!(err instanceof import_errors2.CancelledError)) {
637
+ import_log3.log.warn("connection error", {
638
+ topic: this.topic,
639
+ peerId: this.localPeerId,
640
+ remoteId: this.id,
641
+ err
642
+ }, {
643
+ F: __dxlog_file3,
644
+ L: 135,
645
+ S: this,
646
+ C: (f, a) => f(...a)
647
+ });
648
+ }
643
649
  await this.closeConnection();
644
650
  }
645
651
  return {
@@ -665,13 +671,14 @@ var Peer = class {
665
671
  sessionId
666
672
  }, {
667
673
  F: __dxlog_file3,
668
- L: 147,
674
+ L: 155,
669
675
  S: this,
670
676
  C: (f, a) => f(...a)
671
677
  });
672
678
  const connection = this._createConnection(true, sessionId);
673
679
  this.initiating = true;
674
680
  try {
681
+ await this._connectionLimiter.connecting(sessionId);
675
682
  const answer = await this._signalMessaging.offer({
676
683
  author: this.localPeerId,
677
684
  recipient: this.id,
@@ -688,14 +695,14 @@ var Peer = class {
688
695
  remoteId: this.id
689
696
  }, {
690
697
  F: __dxlog_file3,
691
- L: 159,
698
+ L: 170,
692
699
  S: this,
693
700
  C: (f, a) => f(...a)
694
701
  });
695
702
  if (connection.state !== ConnectionState.INITIAL) {
696
703
  (0, import_log3.log)("ignoring response", void 0, {
697
704
  F: __dxlog_file3,
698
- L: 161,
705
+ L: 172,
699
706
  S: this,
700
707
  C: (f, a) => f(...a)
701
708
  });
@@ -705,7 +712,7 @@ var Peer = class {
705
712
  this._callbacks.onRejected();
706
713
  return;
707
714
  }
708
- connection.openConnection();
715
+ await connection.openConnection();
709
716
  this._callbacks.onAccepted();
710
717
  } catch (err) {
711
718
  (0, import_log3.log)("initiation error", {
@@ -715,7 +722,7 @@ var Peer = class {
715
722
  remoteId: this.id
716
723
  }, {
717
724
  F: __dxlog_file3,
718
- L: 172,
725
+ L: 183,
719
726
  S: this,
720
727
  C: (f, a) => f(...a)
721
728
  });
@@ -739,7 +746,7 @@ var Peer = class {
739
746
  sessionId
740
747
  }, {
741
748
  F: __dxlog_file3,
742
- L: 186,
749
+ L: 197,
743
750
  S: this,
744
751
  C: (f, a) => f(...a)
745
752
  });
@@ -769,6 +776,7 @@ var Peer = class {
769
776
  this.availableToConnect = true;
770
777
  this._lastConnectionTime = Date.now();
771
778
  this._callbacks.onConnected();
779
+ this._connectionLimiter.doneConnecting(sessionId);
772
780
  break;
773
781
  }
774
782
  case ConnectionState.CLOSED: {
@@ -779,7 +787,7 @@ var Peer = class {
779
787
  initiator
780
788
  }, {
781
789
  F: __dxlog_file3,
782
- L: 221,
790
+ L: 234,
783
791
  S: this,
784
792
  C: (f, a) => f(...a)
785
793
  });
@@ -792,6 +800,7 @@ var Peer = class {
792
800
  }
793
801
  this.connection = void 0;
794
802
  this._callbacks.onDisconnected();
803
+ this._connectionLimiter.doneConnecting(sessionId);
795
804
  (0, import_async2.scheduleTask)(this._connectionCtx, () => {
796
805
  this.availableToConnect = true;
797
806
  this._callbacks.onPeerAvailable();
@@ -809,7 +818,7 @@ var Peer = class {
809
818
  err
810
819
  }, {
811
820
  F: __dxlog_file3,
812
- L: 249,
821
+ L: 263,
813
822
  S: this,
814
823
  C: (f, a) => f(...a)
815
824
  });
@@ -828,7 +837,7 @@ var Peer = class {
828
837
  sessionId: connection.sessionId
829
838
  }, {
830
839
  F: __dxlog_file3,
831
- L: 265,
840
+ L: 279,
832
841
  S: this,
833
842
  C: (f, a) => f(...a)
834
843
  });
@@ -838,7 +847,7 @@ var Peer = class {
838
847
  sessionId: connection.sessionId
839
848
  }, {
840
849
  F: __dxlog_file3,
841
- L: 271,
850
+ L: 285,
842
851
  S: this,
843
852
  C: (f, a) => f(...a)
844
853
  });
@@ -849,7 +858,7 @@ var Peer = class {
849
858
  message
850
859
  }, {
851
860
  F: __dxlog_file3,
852
- L: 276,
861
+ L: 290,
853
862
  S: this,
854
863
  C: (f, a) => f(...a)
855
864
  });
@@ -865,7 +874,7 @@ var Peer = class {
865
874
  topic: this.topic
866
875
  }, {
867
876
  F: __dxlog_file3,
868
- L: 285,
877
+ L: 300,
869
878
  S: this,
870
879
  C: (f, a) => f(...a)
871
880
  });
@@ -905,7 +914,7 @@ var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
905
914
  var Swarm = class {
906
915
  // TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
907
916
  // TODO(burdon): Split up properties.
908
- constructor(_topic, _ownPeerId, _topology, _protocolProvider, _messenger, _transportFactory, _label) {
917
+ constructor(_topic, _ownPeerId, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter) {
909
918
  this._topic = _topic;
910
919
  this._ownPeerId = _ownPeerId;
911
920
  this._topology = _topology;
@@ -913,6 +922,7 @@ var Swarm = class {
913
922
  this._messenger = _messenger;
914
923
  this._transportFactory = _transportFactory;
915
924
  this._label = _label;
925
+ this._connectionLimiter = _connectionLimiter;
916
926
  this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
917
927
  this._ctx = new import_context4.Context();
918
928
  this._listeningHandle = void 0;
@@ -929,7 +939,7 @@ var Swarm = class {
929
939
  }
930
940
  }), {
931
941
  F: __dxlog_file4,
932
- L: 86,
942
+ L: 88,
933
943
  S: this,
934
944
  C: (f, a) => f(...a)
935
945
  });
@@ -937,7 +947,7 @@ var Swarm = class {
937
947
  peerId: _ownPeerId
938
948
  }, {
939
949
  F: __dxlog_file4,
940
- L: 90,
950
+ L: 92,
941
951
  S: this,
942
952
  C: (f, a) => f(...a)
943
953
  });
@@ -952,7 +962,7 @@ var Swarm = class {
952
962
  id: this._instanceId
953
963
  }), {
954
964
  F: __dxlog_file4,
955
- L: 99,
965
+ L: 101,
956
966
  S: this,
957
967
  C: (f, a) => f(...a)
958
968
  });
@@ -982,7 +992,7 @@ var Swarm = class {
982
992
  err
983
993
  }, {
984
994
  F: __dxlog_file4,
985
- L: 133,
995
+ L: 135,
986
996
  S: this,
987
997
  C: (f, a) => f(...a)
988
998
  }));
@@ -993,7 +1003,7 @@ var Swarm = class {
993
1003
  var _a2;
994
1004
  (0, import_log4.log)("destroying...", void 0, {
995
1005
  F: __dxlog_file4,
996
- L: 139,
1006
+ L: 141,
997
1007
  S: this,
998
1008
  C: (f, a) => f(...a)
999
1009
  });
@@ -1004,7 +1014,7 @@ var Swarm = class {
1004
1014
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
1005
1015
  (0, import_log4.log)("destroyed", void 0, {
1006
1016
  F: __dxlog_file4,
1007
- L: 146,
1017
+ L: 148,
1008
1018
  S: this,
1009
1019
  C: (f, a) => f(...a)
1010
1020
  });
@@ -1019,7 +1029,7 @@ var Swarm = class {
1019
1029
  topology: getClassName(topology)
1020
1030
  }, {
1021
1031
  F: __dxlog_file4,
1022
- L: 154,
1032
+ L: 156,
1023
1033
  S: this,
1024
1034
  C: (f, a) => f(...a)
1025
1035
  });
@@ -1034,14 +1044,14 @@ var Swarm = class {
1034
1044
  swarmEvent
1035
1045
  }, {
1036
1046
  F: __dxlog_file4,
1037
- L: 167,
1047
+ L: 169,
1038
1048
  S: this,
1039
1049
  C: (f, a) => f(...a)
1040
1050
  });
1041
1051
  if (this._ctx.disposed) {
1042
1052
  (0, import_log4.log)("swarm event ignored for disposed swarm", void 0, {
1043
1053
  F: __dxlog_file4,
1044
- L: 170,
1054
+ L: 172,
1045
1055
  S: this,
1046
1056
  C: (f, a) => f(...a)
1047
1057
  });
@@ -1053,7 +1063,7 @@ var Swarm = class {
1053
1063
  peerId
1054
1064
  }, {
1055
1065
  F: __dxlog_file4,
1056
- L: 176,
1066
+ L: 178,
1057
1067
  S: this,
1058
1068
  C: (f, a) => f(...a)
1059
1069
  });
@@ -1068,7 +1078,7 @@ var Swarm = class {
1068
1078
  if (((_a2 = peer.connection) == null ? void 0 : _a2.state) !== ConnectionState.CONNECTED) {
1069
1079
  void this._destroyPeer(peer.id).catch((err) => import_log4.log.catch(err, void 0, {
1070
1080
  F: __dxlog_file4,
1071
- L: 187,
1081
+ L: 189,
1072
1082
  S: this,
1073
1083
  C: (f, a) => f(...a)
1074
1084
  }));
@@ -1083,14 +1093,14 @@ var Swarm = class {
1083
1093
  message
1084
1094
  }, {
1085
1095
  F: __dxlog_file4,
1086
- L: 197,
1096
+ L: 199,
1087
1097
  S: this,
1088
1098
  C: (f, a) => f(...a)
1089
1099
  });
1090
1100
  if (this._ctx.disposed) {
1091
1101
  (0, import_log4.log)("ignored for disposed swarm", void 0, {
1092
1102
  F: __dxlog_file4,
1093
- L: 199,
1103
+ L: 201,
1094
1104
  S: this,
1095
1105
  C: (f, a) => f(...a)
1096
1106
  });
@@ -1104,7 +1114,7 @@ var Swarm = class {
1104
1114
  message
1105
1115
  }, {
1106
1116
  F: __dxlog_file4,
1107
- L: 206,
1117
+ L: 208,
1108
1118
  S: this,
1109
1119
  C: (f, a) => f(...a)
1110
1120
  });
@@ -1117,7 +1127,7 @@ var Swarm = class {
1117
1127
  message
1118
1128
  }, {
1119
1129
  F: __dxlog_file4,
1120
- L: 210,
1130
+ L: 212,
1121
1131
  S: this,
1122
1132
  C: (f, a) => f(...a)
1123
1133
  });
@@ -1136,14 +1146,14 @@ var Swarm = class {
1136
1146
  message
1137
1147
  }, {
1138
1148
  F: __dxlog_file4,
1139
- L: 222,
1149
+ L: 223,
1140
1150
  S: this,
1141
1151
  C: (f, a) => f(...a)
1142
1152
  });
1143
1153
  if (this._ctx.disposed) {
1144
1154
  import_log4.log.info("ignored for offline swarm", void 0, {
1145
1155
  F: __dxlog_file4,
1146
- L: 224,
1156
+ L: 225,
1147
1157
  S: this,
1148
1158
  C: (f, a) => f(...a)
1149
1159
  });
@@ -1169,7 +1179,7 @@ var Swarm = class {
1169
1179
  _getOrCreatePeer(peerId) {
1170
1180
  let peer = this._peers.get(peerId);
1171
1181
  if (!peer) {
1172
- peer = new Peer(peerId, this._topic, this._ownPeerId, this._swarmMessenger, this._protocolProvider, this._transportFactory, {
1182
+ peer = new Peer(peerId, this._topic, this._ownPeerId, this._swarmMessenger, this._protocolProvider, this._transportFactory, this._connectionLimiter, {
1173
1183
  onInitiated: (connection) => {
1174
1184
  this.connectionAdded.emit(connection);
1175
1185
  },
@@ -1224,7 +1234,7 @@ var Swarm = class {
1224
1234
  } catch (err) {
1225
1235
  (0, import_log4.log)("initiation error", err, {
1226
1236
  F: __dxlog_file4,
1227
- L: 327,
1237
+ L: 329,
1228
1238
  S: this,
1229
1239
  C: (f, a) => f(...a)
1230
1240
  });
@@ -1252,7 +1262,7 @@ var Swarm = class {
1252
1262
  remoteId
1253
1263
  }, {
1254
1264
  F: __dxlog_file4,
1255
- L: 354,
1265
+ L: 356,
1256
1266
  S: this,
1257
1267
  C: (f, a) => f(...a)
1258
1268
  });
@@ -1269,7 +1279,7 @@ var Swarm = class {
1269
1279
  remoteId
1270
1280
  }, {
1271
1281
  F: __dxlog_file4,
1272
- L: 368,
1282
+ L: 370,
1273
1283
  S: this,
1274
1284
  C: (f, a) => f(...a)
1275
1285
  });
@@ -1279,7 +1289,7 @@ var Swarm = class {
1279
1289
  remoteId
1280
1290
  }, {
1281
1291
  F: __dxlog_file4,
1282
- L: 371,
1292
+ L: 373,
1283
1293
  S: this,
1284
1294
  C: (f, a) => f(...a)
1285
1295
  });
@@ -1307,9 +1317,6 @@ _ts_decorate3([
1307
1317
  _ts_decorate3([
1308
1318
  import_async3.synchronized
1309
1319
  ], Swarm.prototype, "onOffer", null);
1310
- _ts_decorate3([
1311
- import_async3.synchronized
1312
- ], Swarm.prototype, "onSignal", null);
1313
1320
  _ts_decorate3([
1314
1321
  import_async3.synchronized
1315
1322
  ], Swarm.prototype, "goOffline", null);
@@ -1388,6 +1395,87 @@ var SwarmMapper = class {
1388
1395
  }
1389
1396
  };
1390
1397
 
1398
+ // packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
1399
+ var import_async5 = require("@dxos/async");
1400
+ var import_context5 = require("@dxos/context");
1401
+ var import_errors3 = require("@dxos/errors");
1402
+ var import_keys6 = require("@dxos/keys");
1403
+ var import_log6 = require("@dxos/log");
1404
+ var import_util4 = require("@dxos/util");
1405
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1406
+ var MAX_CONCURRENT_INITIATING_CONNECTIONS = 3;
1407
+ var ConnectionLimiter = class {
1408
+ constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
1409
+ this._ctx = new import_context5.Context();
1410
+ /**
1411
+ * Queue of promises to resolve when initiating connections amount is below the limit.
1412
+ */
1413
+ this._waitingPromises = new import_util4.ComplexMap(import_keys6.PublicKey.hash);
1414
+ this.resolveWaitingPromises = new import_async5.DeferredTask(this._ctx, async () => {
1415
+ Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
1416
+ resolve();
1417
+ });
1418
+ });
1419
+ this._maxConcurrentInitConnections = maxConcurrentInitConnections;
1420
+ }
1421
+ /**
1422
+ * @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
1423
+ */
1424
+ async connecting(sessionId) {
1425
+ (0, import_log6.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
1426
+ F: __dxlog_file6,
1427
+ L: 47,
1428
+ S: this,
1429
+ A: [
1430
+ "!this._waitingPromises.has(sessionId)",
1431
+ "'Peer is already waiting for connection'"
1432
+ ]
1433
+ });
1434
+ (0, import_log6.log)("waiting", {
1435
+ sessionId
1436
+ }, {
1437
+ F: __dxlog_file6,
1438
+ L: 48,
1439
+ S: this,
1440
+ C: (f, a) => f(...a)
1441
+ });
1442
+ await new Promise((resolve, reject) => {
1443
+ this._waitingPromises.set(sessionId, {
1444
+ resolve,
1445
+ reject
1446
+ });
1447
+ this.resolveWaitingPromises.schedule();
1448
+ });
1449
+ (0, import_log6.log)("allow", {
1450
+ sessionId
1451
+ }, {
1452
+ F: __dxlog_file6,
1453
+ L: 56,
1454
+ S: this,
1455
+ C: (f, a) => f(...a)
1456
+ });
1457
+ }
1458
+ /**
1459
+ * Rejects promise returned by `connecting` method.
1460
+ */
1461
+ doneConnecting(sessionId) {
1462
+ (0, import_log6.log)("done", {
1463
+ sessionId
1464
+ }, {
1465
+ F: __dxlog_file6,
1466
+ L: 63,
1467
+ S: this,
1468
+ C: (f, a) => f(...a)
1469
+ });
1470
+ if (!this._waitingPromises.has(sessionId)) {
1471
+ return;
1472
+ }
1473
+ this._waitingPromises.get(sessionId).reject(new import_errors3.CancelledError());
1474
+ this._waitingPromises.delete(sessionId);
1475
+ this.resolveWaitingPromises.schedule();
1476
+ }
1477
+ };
1478
+
1391
1479
  // packages/core/mesh/network-manager/src/connection-log.ts
1392
1480
  var EventType;
1393
1481
  (function(EventType2) {
@@ -1402,8 +1490,8 @@ var ConnectionLog = class {
1402
1490
  /**
1403
1491
  * SwarmId => info
1404
1492
  */
1405
- this._swarms = new import_util4.ComplexMap(import_keys6.PublicKey.hash);
1406
- this.update = new import_async5.Event();
1493
+ this._swarms = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
1494
+ this.update = new import_async6.Event();
1407
1495
  }
1408
1496
  getSwarmInfo(swarmId) {
1409
1497
  var _a2;
@@ -1414,13 +1502,13 @@ var ConnectionLog = class {
1414
1502
  }
1415
1503
  joinedSwarm(swarm) {
1416
1504
  const info = {
1417
- id: import_keys6.PublicKey.from(swarm._instanceId),
1505
+ id: import_keys7.PublicKey.from(swarm._instanceId),
1418
1506
  topic: swarm.topic,
1419
1507
  isActive: true,
1420
1508
  label: swarm.label,
1421
1509
  connections: []
1422
1510
  };
1423
- this._swarms.set(import_keys6.PublicKey.from(swarm._instanceId), info);
1511
+ this._swarms.set(import_keys7.PublicKey.from(swarm._instanceId), info);
1424
1512
  this.update.emit();
1425
1513
  swarm.connectionAdded.on((connection) => {
1426
1514
  var _a2, _b;
@@ -1449,21 +1537,24 @@ var ConnectionLog = class {
1449
1537
  });
1450
1538
  }
1451
1539
  leftSwarm(swarm) {
1452
- this.getSwarmInfo(import_keys6.PublicKey.from(swarm._instanceId)).isActive = false;
1540
+ this.getSwarmInfo(import_keys7.PublicKey.from(swarm._instanceId)).isActive = false;
1453
1541
  this.update.emit();
1454
1542
  }
1455
1543
  };
1456
1544
 
1457
1545
  // packages/core/mesh/network-manager/src/network-manager.ts
1458
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
1546
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
1459
1547
  var NetworkManager = class {
1460
1548
  constructor({ transportFactory, signalManager, log: log1 }) {
1461
- this._swarms = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
1462
- this._mappers = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
1549
+ /**
1550
+ * @internal
1551
+ */
1552
+ this._swarms = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
1553
+ this._mappers = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
1463
1554
  this._connectionState = import_services.ConnectionState.ONLINE;
1464
- this.connectionStateChanged = new import_async6.Event();
1465
- this.topicsUpdated = new import_async6.Event();
1466
- this._instanceId = import_keys7.PublicKey.random().toHex();
1555
+ this.connectionStateChanged = new import_async7.Event();
1556
+ this.topicsUpdated = new import_async7.Event();
1557
+ this._instanceId = import_keys8.PublicKey.random().toHex();
1467
1558
  this._transportFactory = transportFactory;
1468
1559
  this._signalManager = signalManager;
1469
1560
  this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => {
@@ -1477,6 +1568,7 @@ var NetworkManager = class {
1477
1568
  join: (opts) => this._signalManager.join(opts),
1478
1569
  leave: (opts) => this._signalManager.leave(opts)
1479
1570
  };
1571
+ this._connectionLimiter = new ConnectionLimiter();
1480
1572
  if (log1) {
1481
1573
  this._connectionLog = new ConnectionLog();
1482
1574
  }
@@ -1499,21 +1591,21 @@ var NetworkManager = class {
1499
1591
  return this._swarms.get(topic);
1500
1592
  }
1501
1593
  async open() {
1502
- import_log6.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.begin({
1594
+ import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.begin({
1503
1595
  id: this._instanceId
1504
1596
  }), {
1505
- F: __dxlog_file6,
1506
- L: 127,
1597
+ F: __dxlog_file7,
1598
+ L: 131,
1507
1599
  S: this,
1508
1600
  C: (f, a) => f(...a)
1509
1601
  });
1510
1602
  await this._messenger.open();
1511
1603
  await this._signalManager.open();
1512
- import_log6.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.end({
1604
+ import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.end({
1513
1605
  id: this._instanceId
1514
1606
  }), {
1515
- F: __dxlog_file6,
1516
- L: 130,
1607
+ F: __dxlog_file7,
1608
+ L: 134,
1517
1609
  S: this,
1518
1610
  C: (f, a) => f(...a)
1519
1611
  });
@@ -1521,9 +1613,9 @@ var NetworkManager = class {
1521
1613
  async close() {
1522
1614
  for (const topic of this._swarms.keys()) {
1523
1615
  await this.leaveSwarm(topic).catch((err) => {
1524
- (0, import_log6.log)(err, void 0, {
1525
- F: __dxlog_file6,
1526
- L: 136,
1616
+ (0, import_log7.log)(err, void 0, {
1617
+ F: __dxlog_file7,
1618
+ L: 140,
1527
1619
  S: this,
1528
1620
  C: (f, a) => f(...a)
1529
1621
  });
@@ -1537,30 +1629,30 @@ var NetworkManager = class {
1537
1629
  */
1538
1630
  async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
1539
1631
  var _a2;
1540
- (0, import_tiny_invariant5.default)(import_keys7.PublicKey.isPublicKey(topic));
1541
- (0, import_tiny_invariant5.default)(import_keys7.PublicKey.isPublicKey(peerId));
1632
+ (0, import_tiny_invariant5.default)(import_keys8.PublicKey.isPublicKey(topic));
1633
+ (0, import_tiny_invariant5.default)(import_keys8.PublicKey.isPublicKey(peerId));
1542
1634
  (0, import_tiny_invariant5.default)(topology);
1543
1635
  (0, import_tiny_invariant5.default)(typeof protocol === "function");
1544
1636
  if (this._swarms.has(topic)) {
1545
- throw new Error(`Already connected to swarm: ${import_keys7.PublicKey.from(topic)}`);
1637
+ throw new Error(`Already connected to swarm: ${import_keys8.PublicKey.from(topic)}`);
1546
1638
  }
1547
- (0, import_log6.log)("joining", {
1548
- topic: import_keys7.PublicKey.from(topic),
1639
+ (0, import_log7.log)("joining", {
1640
+ topic: import_keys8.PublicKey.from(topic),
1549
1641
  peerId,
1550
1642
  topology: topology.toString()
1551
1643
  }, {
1552
- F: __dxlog_file6,
1553
- L: 162,
1644
+ F: __dxlog_file7,
1645
+ L: 166,
1554
1646
  S: this,
1555
1647
  C: (f, a) => f(...a)
1556
1648
  });
1557
- const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label);
1649
+ const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
1558
1650
  swarm.errors.handle((error) => {
1559
- (0, import_log6.log)("swarm error", {
1651
+ (0, import_log7.log)("swarm error", {
1560
1652
  error
1561
1653
  }, {
1562
- F: __dxlog_file6,
1563
- L: 165,
1654
+ F: __dxlog_file7,
1655
+ L: 179,
1564
1656
  S: this,
1565
1657
  C: (f, a) => f(...a)
1566
1658
  });
@@ -1571,20 +1663,20 @@ var NetworkManager = class {
1571
1663
  this._signalConnection.join({
1572
1664
  topic,
1573
1665
  peerId
1574
- }).catch((error) => import_log6.log.catch(error, void 0, {
1575
- F: __dxlog_file6,
1576
- L: 174,
1666
+ }).catch((error) => import_log7.log.catch(error, void 0, {
1667
+ F: __dxlog_file7,
1668
+ L: 188,
1577
1669
  S: this,
1578
1670
  C: (f, a) => f(...a)
1579
1671
  }));
1580
1672
  this.topicsUpdated.emit();
1581
1673
  (_a2 = this._connectionLog) == null ? void 0 : _a2.joinedSwarm(swarm);
1582
- (0, import_log6.log)("joined", {
1583
- topic: import_keys7.PublicKey.from(topic),
1674
+ (0, import_log7.log)("joined", {
1675
+ topic: import_keys8.PublicKey.from(topic),
1584
1676
  count: this._swarms.size
1585
1677
  }, {
1586
- F: __dxlog_file6,
1587
- L: 178,
1678
+ F: __dxlog_file7,
1679
+ L: 192,
1588
1680
  S: this,
1589
1681
  C: (f, a) => f(...a)
1590
1682
  });
@@ -1600,11 +1692,11 @@ var NetworkManager = class {
1600
1692
  if (!this._swarms.has(topic)) {
1601
1693
  return;
1602
1694
  }
1603
- (0, import_log6.log)("leaving", {
1604
- topic: import_keys7.PublicKey.from(topic)
1695
+ (0, import_log7.log)("leaving", {
1696
+ topic: import_keys8.PublicKey.from(topic)
1605
1697
  }, {
1606
- F: __dxlog_file6,
1607
- L: 194,
1698
+ F: __dxlog_file7,
1699
+ L: 208,
1608
1700
  S: this,
1609
1701
  C: (f, a) => f(...a)
1610
1702
  });
@@ -1620,12 +1712,12 @@ var NetworkManager = class {
1620
1712
  await swarm.destroy();
1621
1713
  this._swarms.delete(topic);
1622
1714
  await this.topicsUpdated.emit();
1623
- (0, import_log6.log)("left", {
1624
- topic: import_keys7.PublicKey.from(topic),
1715
+ (0, import_log7.log)("left", {
1716
+ topic: import_keys8.PublicKey.from(topic),
1625
1717
  count: this._swarms.size
1626
1718
  }, {
1627
- F: __dxlog_file6,
1628
- L: 208,
1719
+ F: __dxlog_file7,
1720
+ L: 222,
1629
1721
  S: this,
1630
1722
  C: (f, a) => f(...a)
1631
1723
  });
@@ -1685,20 +1777,20 @@ var FullyConnectedTopology = class {
1685
1777
  // packages/core/mesh/network-manager/src/topology/mmst-topology.ts
1686
1778
  var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
1687
1779
  var import_xor_distance = __toESM(require("xor-distance"));
1688
- var import_log7 = require("@dxos/log");
1780
+ var import_log8 = require("@dxos/log");
1689
1781
 
1690
1782
  // packages/core/mesh/network-manager/src/topology/star-topology.ts
1691
1783
  var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
1692
- var import_log8 = require("@dxos/log");
1784
+ var import_log9 = require("@dxos/log");
1693
1785
 
1694
1786
  // packages/core/mesh/network-manager/src/transport/memory-transport.ts
1695
1787
  var import_node_stream = require("node:stream");
1696
1788
  var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
1697
- var import_async7 = require("@dxos/async");
1789
+ var import_async8 = require("@dxos/async");
1698
1790
  var import_debug4 = require("@dxos/debug");
1699
- var import_keys8 = require("@dxos/keys");
1700
- var import_log9 = require("@dxos/log");
1701
- var import_util6 = require("@dxos/util");
1791
+ var import_keys9 = require("@dxos/keys");
1792
+ var import_log10 = require("@dxos/log");
1793
+ var import_util7 = require("@dxos/util");
1702
1794
  function _ts_decorate4(decorators, target, key, desc) {
1703
1795
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1704
1796
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -1709,7 +1801,7 @@ function _ts_decorate4(decorators, target, key, desc) {
1709
1801
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1710
1802
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1711
1803
  }
1712
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
1804
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
1713
1805
  var MEMORY_TRANSPORT_DELAY = 1;
1714
1806
  var createStreamDelay = (delay) => {
1715
1807
  return new import_node_stream.Transform({
@@ -1726,16 +1818,16 @@ var _MemoryTransport = class {
1726
1818
  constructor(options) {
1727
1819
  var _a2;
1728
1820
  this.options = options;
1729
- this.closed = new import_async7.Event();
1730
- this.connected = new import_async7.Event();
1821
+ this.closed = new import_async8.Event();
1822
+ this.connected = new import_async8.Event();
1731
1823
  this.errors = new import_debug4.ErrorStream();
1732
- this._instanceId = import_keys8.PublicKey.random();
1733
- this._remote = new import_async7.Trigger();
1824
+ this._instanceId = import_keys9.PublicKey.random();
1825
+ this._remote = new import_async8.Trigger();
1734
1826
  this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
1735
1827
  this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
1736
1828
  this._destroyed = false;
1737
- (0, import_log9.log)("creating", void 0, {
1738
- F: __dxlog_file7,
1829
+ (0, import_log10.log)("creating", void 0, {
1830
+ F: __dxlog_file8,
1739
1831
  L: 64,
1740
1832
  S: this,
1741
1833
  C: (f, a) => f(...a)
@@ -1744,8 +1836,8 @@ var _MemoryTransport = class {
1744
1836
  _MemoryTransport._connections.set(this._instanceId, this);
1745
1837
  if (this.options.initiator) {
1746
1838
  setTimeout(async () => {
1747
- (0, import_log9.log)("sending signal", void 0, {
1748
- F: __dxlog_file7,
1839
+ (0, import_log10.log)("sending signal", void 0, {
1840
+ F: __dxlog_file8,
1749
1841
  L: 73,
1750
1842
  S: this,
1751
1843
  C: (f, a) => f(...a)
@@ -1777,8 +1869,8 @@ var _MemoryTransport = class {
1777
1869
  (0, import_tiny_invariant9.default)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`);
1778
1870
  this._remoteConnection._remoteConnection = this;
1779
1871
  this._remoteConnection._remoteInstanceId = this._instanceId;
1780
- (0, import_log9.log)("connected", void 0, {
1781
- F: __dxlog_file7,
1872
+ (0, import_log10.log)("connected", void 0, {
1873
+ F: __dxlog_file8,
1782
1874
  L: 103,
1783
1875
  S: this,
1784
1876
  C: (f, a) => f(...a)
@@ -1795,8 +1887,8 @@ var _MemoryTransport = class {
1795
1887
  }
1796
1888
  }
1797
1889
  async destroy() {
1798
- (0, import_log9.log)("closing", void 0, {
1799
- F: __dxlog_file7,
1890
+ (0, import_log10.log)("closing", void 0, {
1891
+ F: __dxlog_file8,
1800
1892
  L: 124,
1801
1893
  S: this,
1802
1894
  C: (f, a) => f(...a)
@@ -1804,8 +1896,8 @@ var _MemoryTransport = class {
1804
1896
  this._destroyed = true;
1805
1897
  _MemoryTransport._connections.delete(this._instanceId);
1806
1898
  if (this._remoteConnection) {
1807
- (0, import_log9.log)("closing", void 0, {
1808
- F: __dxlog_file7,
1899
+ (0, import_log10.log)("closing", void 0, {
1900
+ F: __dxlog_file8,
1809
1901
  L: 129,
1810
1902
  S: this,
1811
1903
  C: (f, a) => f(...a)
@@ -1817,26 +1909,26 @@ var _MemoryTransport = class {
1817
1909
  this._remoteConnection.closed.emit();
1818
1910
  this._remoteConnection._remoteConnection = void 0;
1819
1911
  this._remoteConnection = void 0;
1820
- (0, import_log9.log)("closed", void 0, {
1821
- F: __dxlog_file7,
1912
+ (0, import_log10.log)("closed", void 0, {
1913
+ F: __dxlog_file8,
1822
1914
  L: 147,
1823
1915
  S: this,
1824
1916
  C: (f, a) => f(...a)
1825
1917
  });
1826
1918
  }
1827
1919
  this.closed.emit();
1828
- (0, import_log9.log)("closed", void 0, {
1829
- F: __dxlog_file7,
1920
+ (0, import_log10.log)("closed", void 0, {
1921
+ F: __dxlog_file8,
1830
1922
  L: 151,
1831
1923
  S: this,
1832
1924
  C: (f, a) => f(...a)
1833
1925
  });
1834
1926
  }
1835
1927
  signal({ payload }) {
1836
- (0, import_log9.log)("received signal", {
1928
+ (0, import_log10.log)("received signal", {
1837
1929
  payload
1838
1930
  }, {
1839
- F: __dxlog_file7,
1931
+ F: __dxlog_file8,
1840
1932
  L: 155,
1841
1933
  S: this,
1842
1934
  C: (f, a) => f(...a)
@@ -1846,28 +1938,28 @@ var _MemoryTransport = class {
1846
1938
  }
1847
1939
  const transportId = payload.transportId;
1848
1940
  if (transportId) {
1849
- const remoteId = import_keys8.PublicKey.fromHex(transportId);
1941
+ const remoteId = import_keys9.PublicKey.fromHex(transportId);
1850
1942
  this._remote.wake(remoteId);
1851
1943
  }
1852
1944
  }
1853
1945
  };
1854
1946
  var MemoryTransport = _MemoryTransport;
1855
1947
  // TODO(burdon): Remove static properties (inject context into constructor).
1856
- MemoryTransport._connections = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
1948
+ MemoryTransport._connections = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
1857
1949
  _ts_decorate4([
1858
- import_log9.logInfo
1950
+ import_log10.logInfo
1859
1951
  ], MemoryTransport.prototype, "_instanceId", void 0);
1860
1952
  _ts_decorate4([
1861
- import_log9.logInfo
1953
+ import_log10.logInfo
1862
1954
  ], MemoryTransport.prototype, "_remoteInstanceId", void 0);
1863
1955
 
1864
1956
  // packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
1865
1957
  var import_simple_peer = __toESM(require("simple-peer"));
1866
1958
  var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
1867
- var import_async8 = require("@dxos/async");
1959
+ var import_async9 = require("@dxos/async");
1868
1960
  var import_debug5 = require("@dxos/debug");
1869
- var import_keys9 = require("@dxos/keys");
1870
- var import_log10 = require("@dxos/log");
1961
+ var import_keys10 = require("@dxos/keys");
1962
+ var import_log11 = require("@dxos/log");
1871
1963
  var import_protocols5 = require("@dxos/protocols");
1872
1964
 
1873
1965
  // packages/core/mesh/network-manager/src/transport/webrtc.ts
@@ -1878,26 +1970,26 @@ try {
1878
1970
  }
1879
1971
 
1880
1972
  // packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
1881
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
1973
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
1882
1974
  var WebRTCTransport = class {
1883
1975
  constructor(params) {
1884
1976
  var _a2;
1885
1977
  this.params = params;
1886
1978
  this._closed = false;
1887
- this.closed = new import_async8.Event();
1888
- this.connected = new import_async8.Event();
1979
+ this.closed = new import_async9.Event();
1980
+ this.connected = new import_async9.Event();
1889
1981
  this.errors = new import_debug5.ErrorStream();
1890
- this._instanceId = import_keys9.PublicKey.random().toHex();
1891
- import_log10.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
1982
+ this._instanceId = import_keys10.PublicKey.random().toHex();
1983
+ import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
1892
1984
  id: this._instanceId
1893
1985
  }), {
1894
- F: __dxlog_file8,
1986
+ F: __dxlog_file9,
1895
1987
  L: 39,
1896
1988
  S: this,
1897
1989
  C: (f, a) => f(...a)
1898
1990
  });
1899
- (0, import_log10.log)("created connection", params, {
1900
- F: __dxlog_file8,
1991
+ (0, import_log11.log)("created connection", params, {
1992
+ F: __dxlog_file9,
1901
1993
  L: 40,
1902
1994
  S: this,
1903
1995
  C: (f, a) => f(...a)
@@ -1908,8 +2000,8 @@ var WebRTCTransport = class {
1908
2000
  config: this.params.webrtcConfig
1909
2001
  });
1910
2002
  this._peer.on("signal", async (data) => {
1911
- (0, import_log10.log)("signal", data, {
1912
- F: __dxlog_file8,
2003
+ (0, import_log11.log)("signal", data, {
2004
+ F: __dxlog_file9,
1913
2005
  L: 48,
1914
2006
  S: this,
1915
2007
  C: (f, a) => f(...a)
@@ -1921,8 +2013,8 @@ var WebRTCTransport = class {
1921
2013
  });
1922
2014
  });
1923
2015
  this._peer.on("connect", () => {
1924
- (0, import_log10.log)("connected", void 0, {
1925
- F: __dxlog_file8,
2016
+ (0, import_log11.log)("connected", void 0, {
2017
+ F: __dxlog_file9,
1926
2018
  L: 53,
1927
2019
  S: this,
1928
2020
  C: (f, a) => f(...a)
@@ -1931,8 +2023,8 @@ var WebRTCTransport = class {
1931
2023
  this.connected.emit();
1932
2024
  });
1933
2025
  this._peer.on("close", async () => {
1934
- (0, import_log10.log)("closed", void 0, {
1935
- F: __dxlog_file8,
2026
+ (0, import_log11.log)("closed", void 0, {
2027
+ F: __dxlog_file9,
1936
2028
  L: 59,
1937
2029
  S: this,
1938
2030
  C: (f, a) => f(...a)
@@ -1946,11 +2038,11 @@ var WebRTCTransport = class {
1946
2038
  try {
1947
2039
  if (typeof ((_a3 = this._peer) == null ? void 0 : _a3._pc.getStats) === "function") {
1948
2040
  this._peer._pc.getStats().then((stats) => {
1949
- import_log10.log.warn("report after webrtc error", {
2041
+ import_log11.log.warn("report after webrtc error", {
1950
2042
  config: this.params.webrtcConfig,
1951
2043
  stats
1952
2044
  }, {
1953
- F: __dxlog_file8,
2045
+ F: __dxlog_file9,
1954
2046
  L: 71,
1955
2047
  S: this,
1956
2048
  C: (f, a) => f(...a)
@@ -1961,18 +2053,18 @@ var WebRTCTransport = class {
1961
2053
  }
1962
2054
  await this.destroy();
1963
2055
  });
1964
- import_log10.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
2056
+ import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
1965
2057
  id: this._instanceId
1966
2058
  }), {
1967
- F: __dxlog_file8,
2059
+ F: __dxlog_file9,
1968
2060
  L: 81,
1969
2061
  S: this,
1970
2062
  C: (f, a) => f(...a)
1971
2063
  });
1972
2064
  }
1973
2065
  async destroy() {
1974
- (0, import_log10.log)("closing...", void 0, {
1975
- F: __dxlog_file8,
2066
+ (0, import_log11.log)("closing...", void 0, {
2067
+ F: __dxlog_file9,
1976
2068
  L: 85,
1977
2069
  S: this,
1978
2070
  C: (f, a) => f(...a)
@@ -1981,8 +2073,8 @@ var WebRTCTransport = class {
1981
2073
  await this._disconnectStreams();
1982
2074
  this._peer.destroy();
1983
2075
  this.closed.emit();
1984
- (0, import_log10.log)("closed", void 0, {
1985
- F: __dxlog_file8,
2076
+ (0, import_log11.log)("closed", void 0, {
2077
+ F: __dxlog_file9,
1986
2078
  L: 90,
1987
2079
  S: this,
1988
2080
  C: (f, a) => f(...a)
@@ -2005,16 +2097,16 @@ var WebRTCTransport = class {
2005
2097
  var import_node_stream2 = require("node:stream");
2006
2098
  var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
2007
2099
  var import_codec_protobuf = require("@dxos/codec-protobuf");
2008
- var import_keys10 = require("@dxos/keys");
2009
- var import_log11 = require("@dxos/log");
2100
+ var import_keys11 = require("@dxos/keys");
2101
+ var import_log12 = require("@dxos/log");
2010
2102
  var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
2011
- var import_util7 = require("@dxos/util");
2012
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
2103
+ var import_util8 = require("@dxos/util");
2104
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
2013
2105
  var WebRTCTransportService = class {
2014
2106
  // prettier-ignore
2015
2107
  constructor(_webrtcConfig) {
2016
2108
  this._webrtcConfig = _webrtcConfig;
2017
- this.transports = new import_util7.ComplexMap(import_keys10.PublicKey.hash);
2109
+ this.transports = new import_util8.ComplexMap(import_keys11.PublicKey.hash);
2018
2110
  }
2019
2111
  open(request) {
2020
2112
  const rpcStream = new import_codec_protobuf.Stream(({ ready, next, close }) => {
@@ -2092,8 +2184,8 @@ var WebRTCTransportService = class {
2092
2184
  await ((_a2 = this.transports.get(proxyId)) == null ? void 0 : _a2.transport.destroy());
2093
2185
  await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
2094
2186
  this.transports.delete(proxyId);
2095
- (0, import_log11.log)("Closed.", void 0, {
2096
- F: __dxlog_file9,
2187
+ (0, import_log12.log)("Closed.", void 0, {
2188
+ F: __dxlog_file10,
2097
2189
  L: 109,
2098
2190
  S: this,
2099
2191
  C: (f, a) => f(...a)
@@ -2103,23 +2195,23 @@ var WebRTCTransportService = class {
2103
2195
 
2104
2196
  // packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
2105
2197
  var import_tiny_invariant12 = __toESM(require("tiny-invariant"));
2106
- var import_async9 = require("@dxos/async");
2107
- var import_context5 = require("@dxos/context");
2198
+ var import_async10 = require("@dxos/async");
2199
+ var import_context6 = require("@dxos/context");
2108
2200
  var import_debug6 = require("@dxos/debug");
2109
- var import_keys11 = require("@dxos/keys");
2110
- var import_log12 = require("@dxos/log");
2201
+ var import_keys12 = require("@dxos/keys");
2202
+ var import_log13 = require("@dxos/log");
2111
2203
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
2112
- var import_util8 = require("@dxos/util");
2113
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
2204
+ var import_util9 = require("@dxos/util");
2205
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
2114
2206
  var WebRTCTransportProxy = class {
2115
2207
  // prettier-ignore
2116
2208
  constructor(_params) {
2117
2209
  this._params = _params;
2118
- this._proxyId = import_keys11.PublicKey.random();
2119
- this._ctx = new import_context5.Context();
2120
- this.closed = new import_async9.Event();
2210
+ this._proxyId = import_keys12.PublicKey.random();
2211
+ this._ctx = new import_context6.Context();
2212
+ this.closed = new import_async10.Event();
2121
2213
  this._closed = false;
2122
- this.connected = new import_async9.Event();
2214
+ this.connected = new import_async10.Event();
2123
2215
  this.errors = new import_debug6.ErrorStream();
2124
2216
  this._serviceStream = this._params.bridgeService.open({
2125
2217
  proxyId: this._proxyId,
@@ -2127,8 +2219,8 @@ var WebRTCTransportProxy = class {
2127
2219
  });
2128
2220
  this._serviceStream.waitUntilReady().then(() => {
2129
2221
  this._serviceStream.subscribe(async (event) => {
2130
- (0, import_log12.log)("WebRTCTransportProxy: event", event, {
2131
- F: __dxlog_file10,
2222
+ (0, import_log13.log)("WebRTCTransportProxy: event", event, {
2223
+ F: __dxlog_file11,
2132
2224
  L: 50,
2133
2225
  S: this,
2134
2226
  C: (f, a) => f(...a)
@@ -2148,8 +2240,8 @@ var WebRTCTransportProxy = class {
2148
2240
  payload: data
2149
2241
  });
2150
2242
  } catch (err) {
2151
- import_log12.log.catch(err, void 0, {
2152
- F: __dxlog_file10,
2243
+ import_log13.log.catch(err, void 0, {
2244
+ F: __dxlog_file11,
2153
2245
  L: 67,
2154
2246
  S: this,
2155
2247
  C: (f, a) => f(...a)
@@ -2160,8 +2252,8 @@ var WebRTCTransportProxy = class {
2160
2252
  this._ctx.onDispose(() => {
2161
2253
  this._params.stream.off("data", dataListener);
2162
2254
  });
2163
- }, (error) => import_log12.log.catch(error, void 0, {
2164
- F: __dxlog_file10,
2255
+ }, (error) => import_log13.log.catch(error, void 0, {
2256
+ F: __dxlog_file11,
2165
2257
  L: 73,
2166
2258
  S: this,
2167
2259
  C: (f, a) => f(...a)
@@ -2183,7 +2275,7 @@ var WebRTCTransportProxy = class {
2183
2275
  }
2184
2276
  }
2185
2277
  _handleData(dataEvent) {
2186
- this._params.stream.write((0, import_util8.arrayToBuffer)(dataEvent.payload));
2278
+ this._params.stream.write((0, import_util9.arrayToBuffer)(dataEvent.payload));
2187
2279
  }
2188
2280
  async _handleSignal(signalEvent) {
2189
2281
  await this._params.sendSignal(signalEvent.payload);
@@ -2206,8 +2298,8 @@ var WebRTCTransportProxy = class {
2206
2298
  proxyId: this._proxyId
2207
2299
  });
2208
2300
  } catch (err) {
2209
- import_log12.log.catch(err, void 0, {
2210
- F: __dxlog_file10,
2301
+ import_log13.log.catch(err, void 0, {
2302
+ F: __dxlog_file11,
2211
2303
  L: 124,
2212
2304
  S: this,
2213
2305
  C: (f, a) => f(...a)
@@ -2254,11 +2346,11 @@ var WebRTCTransportProxyFactory = class {
2254
2346
  };
2255
2347
 
2256
2348
  // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
2257
- var import_async10 = require("@dxos/async");
2258
- var import_keys12 = require("@dxos/keys");
2259
- var import_log13 = require("@dxos/log");
2349
+ var import_async11 = require("@dxos/async");
2350
+ var import_keys13 = require("@dxos/keys");
2351
+ var import_log14 = require("@dxos/log");
2260
2352
  var import_teleport2 = require("@dxos/teleport");
2261
- var import_util9 = require("@dxos/util");
2353
+ var import_util10 = require("@dxos/util");
2262
2354
 
2263
2355
  // packages/core/mesh/network-manager/src/wire-protocol.ts
2264
2356
  var import_teleport = require("@dxos/teleport");
@@ -2279,19 +2371,19 @@ var createTeleportProtocolFactory = (onConnection) => {
2279
2371
  };
2280
2372
 
2281
2373
  // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
2282
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
2374
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
2283
2375
  var TestWireProtocol = class {
2284
2376
  constructor(peerId) {
2285
2377
  this.peerId = peerId;
2286
- this.connections = new import_util9.ComplexMap(import_keys12.PublicKey.hash);
2287
- this.streamConnections = new import_util9.ComplexMap(import_keys12.PublicKey.hash);
2288
- this.connected = new import_async10.Event();
2289
- this.disconnected = new import_async10.Event();
2378
+ this.connections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
2379
+ this.streamConnections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
2380
+ this.connected = new import_async11.Event();
2381
+ this.disconnected = new import_async11.Event();
2290
2382
  this.factory = createTeleportProtocolFactory(async (teleport) => {
2291
- (0, import_log13.log)("create", {
2383
+ (0, import_log14.log)("create", {
2292
2384
  remotePeerId: teleport.remotePeerId
2293
2385
  }, {
2294
- F: __dxlog_file11,
2386
+ F: __dxlog_file12,
2295
2387
  L: 23,
2296
2388
  S: this,
2297
2389
  C: (f, a) => f(...a)
@@ -2318,15 +2410,15 @@ var TestWireProtocol = class {
2318
2410
  if (this.connections.has(peerId)) {
2319
2411
  return this.connections.get(peerId);
2320
2412
  }
2321
- (0, import_log13.log)("waitForConnection", {
2413
+ (0, import_log14.log)("waitForConnection", {
2322
2414
  peerId
2323
2415
  }, {
2324
- F: __dxlog_file11,
2416
+ F: __dxlog_file12,
2325
2417
  L: 47,
2326
2418
  S: this,
2327
2419
  C: (f, a) => f(...a)
2328
2420
  });
2329
- await (0, import_async10.asyncTimeout)(
2421
+ await (0, import_async11.asyncTimeout)(
2330
2422
  this.connected.waitFor((connectedId) => connectedId.equals(peerId)),
2331
2423
  // TODO(nf): Make this configurable.
2332
2424
  1e4
@@ -2372,7 +2464,7 @@ var TestBuilder = class {
2372
2464
  }
2373
2465
  return new import_messaging2.MemorySignalManager(this._signalContext);
2374
2466
  }
2375
- createPeer(peerId = import_keys13.PublicKey.random()) {
2467
+ createPeer(peerId = import_keys14.PublicKey.random()) {
2376
2468
  return new TestPeer(this, peerId);
2377
2469
  }
2378
2470
  };
@@ -2380,7 +2472,7 @@ var TestPeer = class {
2380
2472
  constructor(testBuilder, peerId) {
2381
2473
  this.testBuilder = testBuilder;
2382
2474
  this.peerId = peerId;
2383
- this._swarms = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
2475
+ this._swarms = new import_util11.ComplexMap(import_keys14.PublicKey.hash);
2384
2476
  this._signalManager = this.testBuilder.createSignalManager();
2385
2477
  this._networkManager = this.createNetworkManager();
2386
2478
  }