@dxos/network-manager 0.1.17 → 0.1.19

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 (60) hide show
  1. package/dist/lib/browser/index.mjs +221 -352
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/testing/index.mjs +222 -410
  5. package/dist/lib/browser/testing/index.mjs.map +4 -4
  6. package/dist/lib/node/index.cjs +222 -357
  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 +222 -413
  10. package/dist/lib/node/testing/index.cjs.map +4 -4
  11. package/dist/types/src/index.d.ts +0 -1
  12. package/dist/types/src/index.d.ts.map +1 -1
  13. package/dist/types/src/network-manager.d.ts +1 -5
  14. package/dist/types/src/network-manager.d.ts.map +1 -1
  15. package/dist/types/src/swarm/connection.d.ts +4 -0
  16. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  17. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  18. package/dist/types/src/swarm/swarm-mapper.d.ts +1 -3
  19. package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
  20. package/dist/types/src/testing/index.d.ts +0 -1
  21. package/dist/types/src/testing/index.d.ts.map +1 -1
  22. package/dist/types/src/testing/test-builder.d.ts +2 -2
  23. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  24. package/dist/types/src/testing/test-wire-protocol.d.ts +14 -0
  25. package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -0
  26. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  27. package/dist/types/src/tests/property-test-suite.d.ts.map +1 -1
  28. package/dist/types/src/tests/utils.d.ts.map +1 -1
  29. package/dist/types/src/transport/memory-transport.d.ts +3 -3
  30. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  31. package/dist/types/src/wire-protocol.d.ts +0 -10
  32. package/dist/types/src/wire-protocol.d.ts.map +1 -1
  33. package/package.json +16 -18
  34. package/src/connection-log.ts +26 -26
  35. package/src/index.ts +0 -1
  36. package/src/network-manager.ts +1 -8
  37. package/src/swarm/connection.ts +12 -1
  38. package/src/swarm/peer.ts +1 -3
  39. package/src/swarm/swarm-mapper.ts +29 -31
  40. package/src/swarm/swarm.test.ts +12 -34
  41. package/src/testing/index.ts +0 -1
  42. package/src/testing/test-builder.ts +4 -7
  43. package/src/testing/test-wire-protocol.ts +44 -0
  44. package/src/tests/basic-test-suite.ts +13 -53
  45. package/src/tests/property-test-suite.ts +13 -15
  46. package/src/tests/utils.ts +10 -37
  47. package/src/transport/memory-transport.test.ts +13 -52
  48. package/src/transport/memory-transport.ts +37 -29
  49. package/src/transport/webrtc-transport-proxy.test.ts +13 -73
  50. package/src/transport/webrtc-transport.test.ts +7 -38
  51. package/src/wire-protocol.ts +0 -24
  52. package/dist/types/src/protocol-factory.d.ts +0 -36
  53. package/dist/types/src/protocol-factory.d.ts.map +0 -1
  54. package/dist/types/src/testing/test-protocol.d.ts +0 -52
  55. package/dist/types/src/testing/test-protocol.d.ts.map +0 -1
  56. package/dist/types/src/tests/presence.test.d.ts +0 -2
  57. package/dist/types/src/tests/presence.test.d.ts.map +0 -1
  58. package/src/protocol-factory.ts +0 -88
  59. package/src/testing/test-protocol.ts +0 -166
  60. package/src/tests/presence.test.ts +0 -80
@@ -29,19 +29,16 @@ __export(testing_exports, {
29
29
  TEST_SIGNAL_URL: () => TEST_SIGNAL_URL,
30
30
  TestBuilder: () => TestBuilder,
31
31
  TestPeer: () => TestPeer,
32
- TestProtocolPlugin: () => TestProtocolPlugin,
33
- TestSwarmConnection: () => TestSwarmConnection,
34
- getPeerId: () => getPeerId,
35
- testProtocolProvider: () => testProtocolProvider
32
+ TestSwarmConnection: () => TestSwarmConnection
36
33
  });
37
34
  module.exports = __toCommonJS(testing_exports);
38
35
 
39
36
  // packages/core/mesh/network-manager/src/testing/test-builder.ts
40
- var import_keys12 = require("@dxos/keys");
37
+ var import_keys11 = require("@dxos/keys");
41
38
  var import_messaging2 = require("@dxos/messaging");
42
39
  var import_protocols2 = require("@dxos/protocols");
43
40
  var import_rpc = require("@dxos/rpc");
44
- var import_util8 = require("@dxos/util");
41
+ var import_util9 = require("@dxos/util");
45
42
 
46
43
  // packages/core/mesh/network-manager/src/network-manager.ts
47
44
  var import_node_assert5 = __toESM(require("node:assert"));
@@ -77,6 +74,7 @@ var ConnectionState;
77
74
  ConnectionState4["INITIAL"] = "INITIAL";
78
75
  ConnectionState4["CONNECTING"] = "CONNECTING";
79
76
  ConnectionState4["CONNECTED"] = "CONNECTED";
77
+ ConnectionState4["CLOSING"] = "CLOSING";
80
78
  ConnectionState4["CLOSED"] = "CLOSED";
81
79
  })(ConnectionState || (ConnectionState = {}));
82
80
  var Connection = class {
@@ -132,7 +130,11 @@ var Connection = class {
132
130
  this._transport = void 0;
133
131
  this.close().catch((err) => this.errors.raise(err));
134
132
  });
135
- this._transport.errors.pipeTo(this.errors);
133
+ this._transport.errors.handle((err) => {
134
+ if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
135
+ this.errors.raise(err);
136
+ }
137
+ });
136
138
  for (const signal of this._bufferedSignals) {
137
139
  void this._transport.signal(signal);
138
140
  }
@@ -143,11 +145,12 @@ var Connection = class {
143
145
  if (this._state === ConnectionState.CLOSED) {
144
146
  return;
145
147
  }
148
+ this._changeState(ConnectionState.CLOSING);
146
149
  (0, import_log.log)("closing...", {
147
150
  peerId: this.ownId
148
151
  }, {
149
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
150
- line: 131,
152
+ file: "connection.ts",
153
+ line: 142,
151
154
  scope: this,
152
155
  callSite: (f, a) => f(...a)
153
156
  });
@@ -155,8 +158,8 @@ var Connection = class {
155
158
  await this._protocol.destroy();
156
159
  } catch (err) {
157
160
  import_log.log.catch(err, {}, {
158
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
159
- line: 137,
161
+ file: "connection.ts",
162
+ line: 148,
160
163
  scope: this,
161
164
  callSite: (f, a) => f(...a)
162
165
  });
@@ -165,8 +168,8 @@ var Connection = class {
165
168
  await ((_a = this._transport) == null ? void 0 : _a.destroy());
166
169
  } catch (err1) {
167
170
  import_log.log.catch(err1, {}, {
168
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
169
- line: 144,
171
+ file: "connection.ts",
172
+ line: 155,
170
173
  scope: this,
171
174
  callSite: (f, a) => f(...a)
172
175
  });
@@ -174,8 +177,8 @@ var Connection = class {
174
177
  (0, import_log.log)("closed", {
175
178
  peerId: this.ownId
176
179
  }, {
177
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
178
- line: 147,
180
+ file: "connection.ts",
181
+ line: 158,
179
182
  scope: this,
180
183
  callSite: (f, a) => f(...a)
181
184
  });
@@ -186,8 +189,8 @@ var Connection = class {
186
189
  (0, import_node_assert.default)(msg.sessionId);
187
190
  if (!msg.sessionId.equals(this.sessionId)) {
188
191
  (0, import_log.log)("dropping signal for incorrect session id", {}, {
189
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
190
- line: 154,
192
+ file: "connection.ts",
193
+ line: 165,
191
194
  scope: this,
192
195
  callSite: (f, a) => f(...a)
193
196
  });
@@ -202,8 +205,8 @@ var Connection = class {
202
205
  remoteId: this.remoteId,
203
206
  msg: msg.data
204
207
  }, {
205
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
206
- line: 162,
208
+ file: "connection.ts",
209
+ line: 173,
207
210
  scope: this,
208
211
  callSite: (f, a) => f(...a)
209
212
  });
@@ -216,8 +219,8 @@ var Connection = class {
216
219
  remoteId: this.remoteId,
217
220
  msg: msg.data
218
221
  }, {
219
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
220
- line: 168,
222
+ file: "connection.ts",
223
+ line: 179,
221
224
  scope: this,
222
225
  callSite: (f, a) => f(...a)
223
226
  });
@@ -270,7 +273,7 @@ var MessageRouter = class {
270
273
  to: recipient,
271
274
  msg: message
272
275
  }, {
273
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/message-router.ts",
276
+ file: "message-router.ts",
274
277
  line: 67,
275
278
  scope: this,
276
279
  callSite: (f, a) => f(...a)
@@ -328,7 +331,7 @@ var MessageRouter = class {
328
331
  to: recipient,
329
332
  msg: networkMessage
330
333
  }, {
331
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/message-router.ts",
334
+ file: "message-router.ts",
332
335
  line: 117,
333
336
  scope: this,
334
337
  callSite: (f, a) => f(...a)
@@ -359,7 +362,7 @@ var MessageRouter = class {
359
362
  (0, import_log2.log)("resolving", {
360
363
  answer: message.data.answer
361
364
  }, {
362
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/message-router.ts",
365
+ file: "message-router.ts",
363
366
  line: 146,
364
367
  scope: this,
365
368
  callSite: (f, a) => f(...a)
@@ -442,7 +445,7 @@ var Peer = class {
442
445
  topic: this.topic,
443
446
  peerId: this.localPeerId
444
447
  }, {
445
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
448
+ file: "peer.ts",
446
449
  line: 83,
447
450
  scope: this,
448
451
  callSite: (f, a) => f(...a)
@@ -469,7 +472,7 @@ var Peer = class {
469
472
  remoteId: this.id,
470
473
  err
471
474
  }, {
472
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
475
+ file: "peer.ts",
473
476
  line: 107,
474
477
  scope: this,
475
478
  callSite: (f, a) => f(...a)
@@ -495,7 +498,7 @@ var Peer = class {
495
498
  peerId: this.id,
496
499
  sessionId
497
500
  }, {
498
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
501
+ file: "peer.ts",
499
502
  line: 125,
500
503
  scope: this,
501
504
  callSite: (f, a) => f(...a)
@@ -518,14 +521,14 @@ var Peer = class {
518
521
  ownId: this.localPeerId,
519
522
  remoteId: this.id
520
523
  }, {
521
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
524
+ file: "peer.ts",
522
525
  line: 137,
523
526
  scope: this,
524
527
  callSite: (f, a) => f(...a)
525
528
  });
526
529
  if (connection.state !== ConnectionState.INITIAL) {
527
530
  (0, import_log3.log)("ignoring response", {}, {
528
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
531
+ file: "peer.ts",
529
532
  line: 139,
530
533
  scope: this,
531
534
  callSite: (f, a) => f(...a)
@@ -545,7 +548,7 @@ var Peer = class {
545
548
  remoteId: this.id,
546
549
  err
547
550
  }, {
548
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
551
+ file: "peer.ts",
549
552
  line: 150,
550
553
  scope: this,
551
554
  callSite: (f, a) => f(...a)
@@ -564,7 +567,7 @@ var Peer = class {
564
567
  initiator,
565
568
  sessionId
566
569
  }, {
567
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
570
+ file: "peer.ts",
568
571
  line: 164,
569
572
  scope: this,
570
573
  callSite: (f, a) => f(...a)
@@ -599,7 +602,7 @@ var Peer = class {
599
602
  remoteId: this.id,
600
603
  initiator
601
604
  }, {
602
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
605
+ file: "peer.ts",
603
606
  line: 193,
604
607
  scope: this,
605
608
  callSite: (f, a) => f(...a)
@@ -619,19 +622,12 @@ var Peer = class {
619
622
  initiator,
620
623
  err
621
624
  }, {
622
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
625
+ file: "peer.ts",
623
626
  line: 203,
624
627
  scope: this,
625
628
  callSite: (f, a) => f(...a)
626
629
  });
627
- void this.closeConnection().catch(() => {
628
- import_log3.log.catch(err, {}, {
629
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
630
- line: 207,
631
- scope: this,
632
- callSite: (f, a) => f(...a)
633
- });
634
- });
630
+ void this.closeConnection();
635
631
  });
636
632
  this.connection = connection;
637
633
  return connection;
@@ -645,8 +641,8 @@ var Peer = class {
645
641
  peerId: this.id,
646
642
  sessionId: connection.sessionId
647
643
  }, {
648
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
649
- line: 221,
644
+ file: "peer.ts",
645
+ line: 219,
650
646
  scope: this,
651
647
  callSite: (f, a) => f(...a)
652
648
  });
@@ -655,8 +651,8 @@ var Peer = class {
655
651
  peerId: this.id,
656
652
  sessionId: connection.sessionId
657
653
  }, {
658
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
659
- line: 227,
654
+ file: "peer.ts",
655
+ line: 225,
660
656
  scope: this,
661
657
  callSite: (f, a) => f(...a)
662
658
  });
@@ -666,8 +662,8 @@ var Peer = class {
666
662
  (0, import_log3.log)("dropping signal message for non-existent connection", {
667
663
  message
668
664
  }, {
669
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
670
- line: 232,
665
+ file: "peer.ts",
666
+ line: 230,
671
667
  scope: this,
672
668
  callSite: (f, a) => f(...a)
673
669
  });
@@ -681,8 +677,8 @@ var Peer = class {
681
677
  peerId: this.id,
682
678
  topic: this.topic
683
679
  }, {
684
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
685
- line: 240,
680
+ file: "peer.ts",
681
+ line: 238,
686
682
  scope: this,
687
683
  callSite: (f, a) => f(...a)
688
684
  });
@@ -725,7 +721,7 @@ var Swarm = class {
725
721
  (0, import_log4.log)("creating swarm", {
726
722
  peerId: _ownPeerId
727
723
  }, {
728
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
724
+ file: "swarm.ts",
729
725
  line: 80,
730
726
  scope: this,
731
727
  callSite: (f, a) => f(...a)
@@ -742,7 +738,7 @@ var Swarm = class {
742
738
  payloadType: "dxos.mesh.swarm.SwarmMessage",
743
739
  onMessage: async (message) => await this._swarmMessenger.receiveMessage(message)
744
740
  }).catch((error) => import_log4.log.catch(error, {}, {
745
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
741
+ file: "swarm.ts",
746
742
  line: 96,
747
743
  scope: this,
748
744
  callSite: (f, a) => f(...a)
@@ -762,7 +758,7 @@ var Swarm = class {
762
758
  }
763
759
  async destroy() {
764
760
  (0, import_log4.log)("destroying...", {}, {
765
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
761
+ file: "swarm.ts",
766
762
  line: 124,
767
763
  scope: this,
768
764
  callSite: (f, a) => f(...a)
@@ -771,7 +767,7 @@ var Swarm = class {
771
767
  await this._topology.destroy();
772
768
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
773
769
  (0, import_log4.log)("destroyed", {}, {
774
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
770
+ file: "swarm.ts",
775
771
  line: 128,
776
772
  scope: this,
777
773
  callSite: (f, a) => f(...a)
@@ -785,7 +781,7 @@ var Swarm = class {
785
781
  previous: getClassName(this._topology),
786
782
  topology: getClassName(topology)
787
783
  }, {
788
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
784
+ file: "swarm.ts",
789
785
  line: 135,
790
786
  scope: this,
791
787
  callSite: (f, a) => f(...a)
@@ -837,14 +833,14 @@ var Swarm = class {
837
833
  (0, import_log4.log)("swarm event", {
838
834
  swarmEvent
839
835
  }, {
840
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
836
+ file: "swarm.ts",
841
837
  line: 199,
842
838
  scope: this,
843
839
  callSite: (f, a) => f(...a)
844
840
  });
845
841
  if (this._ctx.disposed) {
846
842
  import_log4.log.warn("ignored for destroyed swarm", {}, {
847
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
843
+ file: "swarm.ts",
848
844
  line: 201,
849
845
  scope: this,
850
846
  callSite: (f, a) => f(...a)
@@ -856,7 +852,7 @@ var Swarm = class {
856
852
  (0, import_log4.log)("new peer", {
857
853
  peerId
858
854
  }, {
859
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
855
+ file: "swarm.ts",
860
856
  line: 207,
861
857
  scope: this,
862
858
  callSite: (f, a) => f(...a)
@@ -881,14 +877,14 @@ var Swarm = class {
881
877
  (0, import_log4.log)("offer", {
882
878
  message
883
879
  }, {
884
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
880
+ file: "swarm.ts",
885
881
  line: 226,
886
882
  scope: this,
887
883
  callSite: (f, a) => f(...a)
888
884
  });
889
885
  if (this._ctx.disposed) {
890
886
  import_log4.log.info("ignored for destroyed swarm", {}, {
891
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
887
+ file: "swarm.ts",
892
888
  line: 228,
893
889
  scope: this,
894
890
  callSite: (f, a) => f(...a)
@@ -902,7 +898,7 @@ var Swarm = class {
902
898
  (0, import_log4.log)("rejecting offer with incorrect peerId", {
903
899
  message
904
900
  }, {
905
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
901
+ file: "swarm.ts",
906
902
  line: 235,
907
903
  scope: this,
908
904
  callSite: (f, a) => f(...a)
@@ -915,7 +911,7 @@ var Swarm = class {
915
911
  (0, import_log4.log)("rejecting offer with incorrect topic", {
916
912
  message
917
913
  }, {
918
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
914
+ file: "swarm.ts",
919
915
  line: 239,
920
916
  scope: this,
921
917
  callSite: (f, a) => f(...a)
@@ -934,14 +930,14 @@ var Swarm = class {
934
930
  (0, import_log4.log)("signal", {
935
931
  message
936
932
  }, {
937
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
933
+ file: "swarm.ts",
938
934
  line: 250,
939
935
  scope: this,
940
936
  callSite: (f, a) => f(...a)
941
937
  });
942
938
  if (this._ctx.disposed) {
943
939
  import_log4.log.info("ignored for destroyed swarm", {}, {
944
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
940
+ file: "swarm.ts",
945
941
  line: 252,
946
942
  scope: this,
947
943
  callSite: (f, a) => f(...a)
@@ -970,7 +966,7 @@ var Swarm = class {
970
966
  await this._initiateConnection(peer);
971
967
  } catch (err) {
972
968
  import_log4.log.warn("initiation error", err, {
973
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
969
+ file: "swarm.ts",
974
970
  line: 287,
975
971
  scope: this,
976
972
  callSite: (f, a) => f(...a)
@@ -994,7 +990,7 @@ var Swarm = class {
994
990
  (0, import_log4.log)("initiation delay", {
995
991
  remoteId
996
992
  }, {
997
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
993
+ file: "swarm.ts",
998
994
  line: 312,
999
995
  scope: this,
1000
996
  callSite: (f, a) => f(...a)
@@ -1011,7 +1007,7 @@ var Swarm = class {
1011
1007
  (0, import_log4.log)("initiating connection...", {
1012
1008
  remoteId
1013
1009
  }, {
1014
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
1010
+ file: "swarm.ts",
1015
1011
  line: 326,
1016
1012
  scope: this,
1017
1013
  callSite: (f, a) => f(...a)
@@ -1021,7 +1017,7 @@ var Swarm = class {
1021
1017
  (0, import_log4.log)("initiated", {
1022
1018
  remoteId
1023
1019
  }, {
1024
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
1020
+ file: "swarm.ts",
1025
1021
  line: 329,
1026
1022
  scope: this,
1027
1023
  callSite: (f, a) => f(...a)
@@ -1054,9 +1050,8 @@ var SwarmMapper = class {
1054
1050
  get peers() {
1055
1051
  return Array.from(this._peers.values());
1056
1052
  }
1057
- constructor(_swarm, _presence) {
1053
+ constructor(_swarm) {
1058
1054
  this._swarm = _swarm;
1059
- this._presence = _presence;
1060
1055
  this._subscriptions = new import_async4.EventSubscriptions();
1061
1056
  this._connectionSubscriptions = new import_util3.ComplexMap(import_keys4.PublicKey.hash);
1062
1057
  this._peers = new import_util3.ComplexMap(import_keys4.PublicKey.hash);
@@ -1073,17 +1068,12 @@ var SwarmMapper = class {
1073
1068
  this._connectionSubscriptions.delete(peerId);
1074
1069
  this._update();
1075
1070
  }));
1076
- if (_presence) {
1077
- this._subscriptions.add(_presence.graphUpdated.on(() => {
1078
- this._update();
1079
- }));
1080
- }
1081
1071
  this._update();
1082
1072
  }
1083
1073
  _update() {
1084
1074
  (0, import_log5.log)("updating swarm", {}, {
1085
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts",
1086
- line: 77,
1075
+ file: "swarm-mapper.ts",
1076
+ line: 75,
1087
1077
  scope: this,
1088
1078
  callSite: (f, a) => f(...a)
1089
1079
  });
@@ -1102,32 +1092,12 @@ var SwarmMapper = class {
1102
1092
  ]
1103
1093
  });
1104
1094
  }
1105
- if (this._presence) {
1106
- this._presence.graph.forEachNode((node) => {
1107
- const id = import_keys4.PublicKey.fromHex(node.id);
1108
- if (this._peers.has(id)) {
1109
- return;
1110
- }
1111
- this._peers.set(id, {
1112
- id,
1113
- state: "INDIRECTLY_CONNECTED",
1114
- connections: []
1115
- });
1116
- });
1117
- this._presence.graph.forEachLink((link) => {
1118
- const from = import_keys4.PublicKey.from(link.fromId);
1119
- const to = import_keys4.PublicKey.from(link.toId);
1120
- if (!from.equals(this._swarm.ownPeerId) && !to.equals(this._swarm.ownPeerId)) {
1121
- this._peers.get(from).connections.push(to);
1122
- }
1123
- });
1124
- }
1125
1095
  (0, import_log5.log)("graph changed", {
1126
1096
  directConnections: this._swarm.connections.length,
1127
1097
  totalPeersInSwarm: this._peers.size
1128
1098
  }, {
1129
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts",
1130
- line: 118,
1099
+ file: "swarm-mapper.ts",
1100
+ line: 116,
1131
1101
  scope: this,
1132
1102
  callSite: (f, a) => f(...a)
1133
1103
  });
@@ -1171,13 +1141,12 @@ var ConnectionLog = class {
1171
1141
  this._swarms.set(swarm.instanceId, info);
1172
1142
  this.update.emit();
1173
1143
  swarm.connectionAdded.on((connection) => {
1174
- var _a, _b, _c, _d, _e;
1175
1144
  const connectionInfo = {
1176
1145
  state: ConnectionState.INITIAL,
1177
1146
  remotePeerId: connection.remoteId,
1178
1147
  sessionId: connection.sessionId,
1179
1148
  transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
1180
- protocolExtensions: (_a = connection.protocol.protocol) == null ? void 0 : _a.extensionNames,
1149
+ protocolExtensions: [],
1181
1150
  events: []
1182
1151
  };
1183
1152
  info.connections.push(connectionInfo);
@@ -1190,32 +1159,6 @@ var ConnectionLog = class {
1190
1159
  });
1191
1160
  this.update.emit();
1192
1161
  });
1193
- (_b = connection.protocol.protocol) == null ? void 0 : _b.error.on((error) => {
1194
- var _a2;
1195
- connectionInfo.events.push({
1196
- type: EventType.PROTOCOL_ERROR,
1197
- error: (_a2 = error.stack) != null ? _a2 : error.message
1198
- });
1199
- this.update.emit();
1200
- });
1201
- (_c = connection.protocol.protocol) == null ? void 0 : _c.extensionsInitialized.on(() => {
1202
- connectionInfo.events.push({
1203
- type: EventType.PROTOCOL_EXTENSIONS_INITIALIZED
1204
- });
1205
- this.update.emit();
1206
- });
1207
- (_d = connection.protocol.protocol) == null ? void 0 : _d.extensionsHandshake.on(() => {
1208
- connectionInfo.events.push({
1209
- type: EventType.PROTOCOL_EXTENSIONS_HANDSHAKE
1210
- });
1211
- this.update.emit();
1212
- });
1213
- (_e = connection.protocol.protocol) == null ? void 0 : _e.handshake.on(() => {
1214
- connectionInfo.events.push({
1215
- type: EventType.PROTOCOL_HANDSHAKE
1216
- });
1217
- this.update.emit();
1218
- });
1219
1162
  });
1220
1163
  }
1221
1164
  swarmLeft(swarm) {
@@ -1226,7 +1169,7 @@ var ConnectionLog = class {
1226
1169
 
1227
1170
  // packages/core/mesh/network-manager/src/network-manager.ts
1228
1171
  var NetworkManager = class {
1229
- constructor({ transportFactory, signalManager, log: log15 }) {
1172
+ constructor({ transportFactory, signalManager, log: log14 }) {
1230
1173
  this._swarms = new import_util5.ComplexMap(import_keys6.PublicKey.hash);
1231
1174
  this._mappers = new import_util5.ComplexMap(import_keys6.PublicKey.hash);
1232
1175
  this.topicsUpdated = new import_async6.Event();
@@ -1243,7 +1186,7 @@ var NetworkManager = class {
1243
1186
  join: (opts) => this._signalManager.join(opts),
1244
1187
  leave: (opts) => this._signalManager.leave(opts)
1245
1188
  };
1246
- if (log15) {
1189
+ if (log14) {
1247
1190
  this._connectionLog = new ConnectionLog();
1248
1191
  }
1249
1192
  }
@@ -1266,8 +1209,8 @@ var NetworkManager = class {
1266
1209
  for (const topic of this._swarms.keys()) {
1267
1210
  await this.leaveSwarm(topic).catch((err) => {
1268
1211
  (0, import_log6.log)(err, {}, {
1269
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1270
- line: 128,
1212
+ file: "network-manager.ts",
1213
+ line: 122,
1271
1214
  scope: this,
1272
1215
  callSite: (f, a) => f(...a)
1273
1216
  });
@@ -1275,7 +1218,7 @@ var NetworkManager = class {
1275
1218
  }
1276
1219
  await this._signalManager.destroy();
1277
1220
  }
1278
- async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, presence, label }) {
1221
+ async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
1279
1222
  var _a;
1280
1223
  (0, import_node_assert5.default)(import_keys6.PublicKey.isPublicKey(topic));
1281
1224
  (0, import_node_assert5.default)(import_keys6.PublicKey.isPublicKey(peerId));
@@ -1289,8 +1232,8 @@ var NetworkManager = class {
1289
1232
  peerId,
1290
1233
  topology: topology.toString()
1291
1234
  }, {
1292
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1293
- line: 155,
1235
+ file: "network-manager.ts",
1236
+ line: 148,
1294
1237
  scope: this,
1295
1238
  callSite: (f, a) => f(...a)
1296
1239
  });
@@ -1299,8 +1242,8 @@ var NetworkManager = class {
1299
1242
  (0, import_log6.log)("swarm error", {
1300
1243
  error
1301
1244
  }, {
1302
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1303
- line: 158,
1245
+ file: "network-manager.ts",
1246
+ line: 151,
1304
1247
  scope: this,
1305
1248
  callSite: (f, a) => f(...a)
1306
1249
  });
@@ -1310,20 +1253,20 @@ var NetworkManager = class {
1310
1253
  topic,
1311
1254
  peerId
1312
1255
  }).catch((error) => import_log6.log.catch(error, {}, {
1313
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1314
- line: 162,
1256
+ file: "network-manager.ts",
1257
+ line: 155,
1315
1258
  scope: this,
1316
1259
  callSite: (f, a) => f(...a)
1317
1260
  }));
1318
- this._mappers.set(topic, new SwarmMapper(swarm, presence));
1261
+ this._mappers.set(topic, new SwarmMapper(swarm));
1319
1262
  this.topicsUpdated.emit();
1320
1263
  (_a = this._connectionLog) == null ? void 0 : _a.swarmJoined(swarm);
1321
1264
  (0, import_log6.log)("joined", {
1322
1265
  topic: import_keys6.PublicKey.from(topic),
1323
1266
  count: this._swarms.size
1324
1267
  }, {
1325
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1326
- line: 167,
1268
+ file: "network-manager.ts",
1269
+ line: 160,
1327
1270
  scope: this,
1328
1271
  callSite: (f, a) => f(...a)
1329
1272
  });
@@ -1337,8 +1280,8 @@ var NetworkManager = class {
1337
1280
  import_log6.log.warn("swarm not open", {
1338
1281
  topic: import_keys6.PublicKey.from(topic)
1339
1282
  }, {
1340
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1341
- line: 179,
1283
+ file: "network-manager.ts",
1284
+ line: 172,
1342
1285
  scope: this,
1343
1286
  callSite: (f, a) => f(...a)
1344
1287
  });
@@ -1347,8 +1290,8 @@ var NetworkManager = class {
1347
1290
  (0, import_log6.log)("leaving", {
1348
1291
  topic: import_keys6.PublicKey.from(topic)
1349
1292
  }, {
1350
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1351
- line: 183,
1293
+ file: "network-manager.ts",
1294
+ line: 176,
1352
1295
  scope: this,
1353
1296
  callSite: (f, a) => f(...a)
1354
1297
  });
@@ -1368,8 +1311,8 @@ var NetworkManager = class {
1368
1311
  topic: import_keys6.PublicKey.from(topic),
1369
1312
  count: this._swarms.size
1370
1313
  }, {
1371
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1372
- line: 197,
1314
+ file: "network-manager.ts",
1315
+ line: 190,
1373
1316
  scope: this,
1374
1317
  callSite: (f, a) => f(...a)
1375
1318
  });
@@ -1415,6 +1358,16 @@ var import_debug4 = require("@dxos/debug");
1415
1358
  var import_keys7 = require("@dxos/keys");
1416
1359
  var import_log9 = require("@dxos/log");
1417
1360
  var import_util6 = require("@dxos/util");
1361
+ var __decorate4 = function(decorators, target, key, desc) {
1362
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1363
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1364
+ r = Reflect.decorate(decorators, target, key, desc);
1365
+ else
1366
+ for (var i = decorators.length - 1; i >= 0; i--)
1367
+ if (d = decorators[i])
1368
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1369
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1370
+ };
1418
1371
  var MEMORY_TRANSPORT_DELAY = 1;
1419
1372
  var createStreamDelay = (delay) => {
1420
1373
  return new import_node_stream.Transform({
@@ -1434,34 +1387,30 @@ var _MemoryTransport = class {
1434
1387
  this.closed = new import_async7.Event();
1435
1388
  this.connected = new import_async7.Event();
1436
1389
  this.errors = new import_debug4.ErrorStream();
1437
- this._id = import_keys7.PublicKey.random();
1438
1390
  this._remote = new import_async7.Trigger();
1439
1391
  this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
1440
1392
  this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
1441
1393
  this._destroyed = false;
1442
- (0, import_log9.log)("creating", {
1443
- id: this._id
1444
- }, {
1445
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1446
- line: 59,
1394
+ this._instanceId = import_keys7.PublicKey.random();
1395
+ (0, import_log9.log)("creating", {}, {
1396
+ file: "memory-transport.ts",
1397
+ line: 64,
1447
1398
  scope: this,
1448
1399
  callSite: (f, a) => f(...a)
1449
1400
  });
1450
- (0, import_node_assert7.default)(!_MemoryTransport._connections.has(this._id), "Duplicate memory connection");
1451
- _MemoryTransport._connections.set(this._id, this);
1401
+ (0, import_node_assert7.default)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
1402
+ _MemoryTransport._connections.set(this._instanceId, this);
1452
1403
  if (this.options.initiator) {
1453
1404
  setTimeout(async () => {
1454
- (0, import_log9.log)("sending signal", {
1455
- transportId: this._id
1456
- }, {
1457
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1458
- line: 68,
1405
+ (0, import_log9.log)("sending signal", {}, {
1406
+ file: "memory-transport.ts",
1407
+ line: 73,
1459
1408
  scope: this,
1460
1409
  callSite: (f, a) => f(...a)
1461
1410
  });
1462
1411
  void this.options.sendSignal({
1463
1412
  payload: {
1464
- transportId: this._id.toHex()
1413
+ transportId: this._instanceId.toHex()
1465
1414
  }
1466
1415
  });
1467
1416
  });
@@ -1472,22 +1421,19 @@ var _MemoryTransport = class {
1472
1421
  if (this._destroyed) {
1473
1422
  return;
1474
1423
  }
1475
- this._remoteId = remoteId;
1476
- this._remoteConnection = _MemoryTransport._connections.get(this._remoteId);
1424
+ this._remoteInstanceId = remoteId;
1425
+ this._remoteConnection = _MemoryTransport._connections.get(this._remoteInstanceId);
1477
1426
  if (!this._remoteConnection) {
1478
1427
  this._destroyed = true;
1479
1428
  this.closed.emit();
1480
1429
  return;
1481
1430
  }
1482
- (0, import_node_assert7.default)(!this._remoteConnection._remoteConnection, new Error(`Remote already connected: ${this._remoteId}`));
1431
+ (0, import_node_assert7.default)(!this._remoteConnection._remoteConnection, new Error(`Remote already connected: ${this._remoteInstanceId}`));
1483
1432
  this._remoteConnection._remoteConnection = this;
1484
- this._remoteConnection._remoteId = this._id;
1485
- (0, import_log9.log)("connected", {
1486
- id: this._id,
1487
- remote: this._remoteId
1488
- }, {
1489
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1490
- line: 94,
1433
+ this._remoteConnection._remoteInstanceId = this._instanceId;
1434
+ (0, import_log9.log)("connected", {}, {
1435
+ file: "memory-transport.ts",
1436
+ line: 102,
1491
1437
  scope: this,
1492
1438
  callSite: (f, a) => f(...a)
1493
1439
  });
@@ -1503,73 +1449,70 @@ var _MemoryTransport = class {
1503
1449
  }
1504
1450
  }
1505
1451
  async destroy() {
1506
- (0, import_log9.log)("closing", {
1507
- id: this._id
1508
- }, {
1509
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1510
- line: 115,
1452
+ (0, import_log9.log)("closing", {}, {
1453
+ file: "memory-transport.ts",
1454
+ line: 123,
1511
1455
  scope: this,
1512
1456
  callSite: (f, a) => f(...a)
1513
1457
  });
1514
1458
  this._destroyed = true;
1515
- _MemoryTransport._connections.delete(this._id);
1459
+ _MemoryTransport._connections.delete(this._instanceId);
1516
1460
  if (this._remoteConnection) {
1517
- (0, import_log9.log)("closing", {
1518
- id: this._remoteId
1519
- }, {
1520
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1521
- line: 120,
1461
+ (0, import_log9.log)("closing", {}, {
1462
+ file: "memory-transport.ts",
1463
+ line: 128,
1522
1464
  scope: this,
1523
1465
  callSite: (f, a) => f(...a)
1524
1466
  });
1525
1467
  this._remoteConnection._destroyed = true;
1526
- _MemoryTransport._connections.delete(this._remoteId);
1468
+ _MemoryTransport._connections.delete(this._remoteInstanceId);
1527
1469
  this._outgoingDelay.unpipe();
1528
1470
  this._incomingDelay.unpipe();
1529
1471
  this._remoteConnection.closed.emit();
1530
1472
  this._remoteConnection._remoteConnection = void 0;
1531
1473
  this._remoteConnection = void 0;
1532
- (0, import_log9.log)("closed", {
1533
- id: this._remoteId
1534
- }, {
1535
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1536
- line: 138,
1474
+ (0, import_log9.log)("closed", {}, {
1475
+ file: "memory-transport.ts",
1476
+ line: 146,
1537
1477
  scope: this,
1538
1478
  callSite: (f, a) => f(...a)
1539
1479
  });
1540
1480
  }
1541
1481
  this.closed.emit();
1542
- (0, import_log9.log)("closed", {
1543
- id: this._id
1544
- }, {
1545
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1546
- line: 142,
1482
+ (0, import_log9.log)("closed", {}, {
1483
+ file: "memory-transport.ts",
1484
+ line: 150,
1547
1485
  scope: this,
1548
1486
  callSite: (f, a) => f(...a)
1549
1487
  });
1550
1488
  }
1551
- signal(signal) {
1552
- const { payload: json } = signal;
1553
- if (json && json.transportId) {
1554
- const transportId = json.transportId;
1555
- if (transportId) {
1556
- const remoteId = import_keys7.PublicKey.fromHex(transportId);
1557
- (0, import_log9.log)("received signal", {
1558
- id: this._id,
1559
- remoteId
1560
- }, {
1561
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1562
- line: 152,
1563
- scope: this,
1564
- callSite: (f, a) => f(...a)
1565
- });
1566
- this._remote.wake(remoteId);
1567
- }
1489
+ signal({ payload }) {
1490
+ (0, import_log9.log)("received signal", {
1491
+ payload
1492
+ }, {
1493
+ file: "memory-transport.ts",
1494
+ line: 154,
1495
+ scope: this,
1496
+ callSite: (f, a) => f(...a)
1497
+ });
1498
+ if (!(payload == null ? void 0 : payload.transportId)) {
1499
+ return;
1500
+ }
1501
+ const transportId = payload.transportId;
1502
+ if (transportId) {
1503
+ const remoteId = import_keys7.PublicKey.fromHex(transportId);
1504
+ this._remote.wake(remoteId);
1568
1505
  }
1569
1506
  }
1570
1507
  };
1571
1508
  var MemoryTransport = _MemoryTransport;
1572
1509
  MemoryTransport._connections = new import_util6.ComplexMap(import_keys7.PublicKey.hash);
1510
+ __decorate4([
1511
+ import_log9.logInfo
1512
+ ], MemoryTransport.prototype, "_instanceId", void 0);
1513
+ __decorate4([
1514
+ import_log9.logInfo
1515
+ ], MemoryTransport.prototype, "_remoteInstanceId", void 0);
1573
1516
 
1574
1517
  // packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
1575
1518
  var import_node_assert8 = __toESM(require("node:assert"));
@@ -1594,7 +1537,7 @@ var WebRTCTransport = class {
1594
1537
  this.connected = new import_async8.Event();
1595
1538
  this.errors = new import_debug5.ErrorStream();
1596
1539
  (0, import_log10.log)("created connection", params, {
1597
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1540
+ file: "webrtc-transport.ts",
1598
1541
  line: 34,
1599
1542
  scope: this,
1600
1543
  callSite: (f, a) => f(...a)
@@ -1606,7 +1549,7 @@ var WebRTCTransport = class {
1606
1549
  });
1607
1550
  this._peer.on("signal", async (data) => {
1608
1551
  (0, import_log10.log)("signal", data, {
1609
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1552
+ file: "webrtc-transport.ts",
1610
1553
  line: 42,
1611
1554
  scope: this,
1612
1555
  callSite: (f, a) => f(...a)
@@ -1619,7 +1562,7 @@ var WebRTCTransport = class {
1619
1562
  });
1620
1563
  this._peer.on("connect", () => {
1621
1564
  (0, import_log10.log)("connected", {}, {
1622
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1565
+ file: "webrtc-transport.ts",
1623
1566
  line: 47,
1624
1567
  scope: this,
1625
1568
  callSite: (f, a) => f(...a)
@@ -1629,7 +1572,7 @@ var WebRTCTransport = class {
1629
1572
  });
1630
1573
  this._peer.on("close", async () => {
1631
1574
  (0, import_log10.log)("closed", {}, {
1632
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1575
+ file: "webrtc-transport.ts",
1633
1576
  line: 53,
1634
1577
  scope: this,
1635
1578
  callSite: (f, a) => f(...a)
@@ -1644,7 +1587,7 @@ var WebRTCTransport = class {
1644
1587
  }
1645
1588
  async destroy() {
1646
1589
  (0, import_log10.log)("closing...", {}, {
1647
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1590
+ file: "webrtc-transport.ts",
1648
1591
  line: 65,
1649
1592
  scope: this,
1650
1593
  callSite: (f, a) => f(...a)
@@ -1653,7 +1596,7 @@ var WebRTCTransport = class {
1653
1596
  this._peer.destroy();
1654
1597
  this.closed.emit();
1655
1598
  (0, import_log10.log)("closed", {}, {
1656
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1599
+ file: "webrtc-transport.ts",
1657
1600
  line: 69,
1658
1601
  scope: this,
1659
1602
  callSite: (f, a) => f(...a)
@@ -1759,7 +1702,7 @@ var WebRTCTransportService = class {
1759
1702
  await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
1760
1703
  this.transports.delete(proxyId);
1761
1704
  (0, import_log11.log)("Closed.", {}, {
1762
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts",
1705
+ file: "webrtc-transport-service.ts",
1763
1706
  line: 108,
1764
1707
  scope: this,
1765
1708
  callSite: (f, a) => f(...a)
@@ -1789,7 +1732,7 @@ var WebRTCTransportProxy = class {
1789
1732
  this._serviceStream.waitUntilReady().then(() => {
1790
1733
  this._serviceStream.subscribe(async (event) => {
1791
1734
  (0, import_log12.log)("WebRTCTransportProxy: event", event, {
1792
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
1735
+ file: "webrtc-transport-proxy.ts",
1793
1736
  line: 46,
1794
1737
  scope: this,
1795
1738
  callSite: (f, a) => f(...a)
@@ -1810,7 +1753,7 @@ var WebRTCTransportProxy = class {
1810
1753
  });
1811
1754
  } catch (err) {
1812
1755
  import_log12.log.catch(err, {}, {
1813
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
1756
+ file: "webrtc-transport-proxy.ts",
1814
1757
  line: 63,
1815
1758
  scope: this,
1816
1759
  callSite: (f, a) => f(...a)
@@ -1818,7 +1761,7 @@ var WebRTCTransportProxy = class {
1818
1761
  }
1819
1762
  });
1820
1763
  }, (error) => import_log12.log.catch(error, {}, {
1821
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
1764
+ file: "webrtc-transport-proxy.ts",
1822
1765
  line: 67,
1823
1766
  scope: this,
1824
1767
  callSite: (f, a) => f(...a)
@@ -1862,7 +1805,7 @@ var WebRTCTransportProxy = class {
1862
1805
  });
1863
1806
  } catch (err) {
1864
1807
  import_log12.log.catch(err, {}, {
1865
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
1808
+ file: "webrtc-transport-proxy.ts",
1866
1809
  line: 117,
1867
1810
  scope: this,
1868
1811
  callSite: (f, a) => f(...a)
@@ -1900,205 +1843,74 @@ var WebRTCTransportProxyFactory = class {
1900
1843
  }
1901
1844
  };
1902
1845
 
1903
- // packages/core/mesh/network-manager/src/wire-protocol.ts
1904
- var import_crypto = require("@dxos/crypto");
1905
- var import_teleport = require("@dxos/teleport");
1906
- var adaptProtocolProvider = (factory) => ({ initiator, localPeerId, remotePeerId, topic }) => {
1907
- const protocol = factory({
1908
- channel: (0, import_crypto.discoveryKey)(topic),
1909
- initiator
1910
- });
1911
- return {
1912
- initialize: () => protocol.open(),
1913
- destroy: () => protocol.close(),
1914
- stream: protocol.stream,
1915
- protocol
1916
- };
1917
- };
1918
-
1919
- // packages/core/mesh/network-manager/src/testing/test-protocol.ts
1920
- var import_node_assert12 = __toESM(require("node:assert"));
1921
- var import_node_events = require("node:events");
1922
- var import_keys11 = require("@dxos/keys");
1923
- var import_log14 = require("@dxos/log");
1924
- var import_mesh_protocol2 = require("@dxos/mesh-protocol");
1925
-
1926
- // packages/core/mesh/network-manager/src/protocol-factory.ts
1927
- var import_node_assert11 = __toESM(require("node:assert"));
1928
- var import_crypto2 = require("@dxos/crypto");
1846
+ // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
1847
+ var import_async10 = require("@dxos/async");
1929
1848
  var import_keys10 = require("@dxos/keys");
1930
1849
  var import_log13 = require("@dxos/log");
1931
- var import_mesh_protocol = require("@dxos/mesh-protocol");
1932
- var protocolFactory = ({ session = {}, plugins = [], getTopics }) => {
1933
- (0, import_node_assert11.default)(getTopics);
1934
- return ({ channel, initiator }) => {
1935
- (0, import_log13.log)("creating protocol", {}, {
1936
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/protocol-factory.ts",
1937
- line: 41,
1938
- scope: void 0,
1939
- callSite: (f, a) => f(...a)
1940
- });
1941
- const protocol = new import_mesh_protocol.Protocol({
1942
- streamOptions: {
1943
- live: true
1944
- },
1945
- discoveryToPublicKey: (dk) => {
1946
- const publicKey = getTopics().find((topic) => (0, import_crypto2.discoveryKey)(topic).equals(dk));
1947
- if (publicKey) {
1948
- protocol.setContext({
1949
- topic: import_keys10.PublicKey.stringify(publicKey)
1950
- });
1951
- }
1952
- (0, import_node_assert11.default)(publicKey, "PublicKey not found in discovery.");
1953
- return publicKey;
1850
+ var import_teleport2 = require("@dxos/teleport");
1851
+ var import_util8 = require("@dxos/util");
1852
+
1853
+ // packages/core/mesh/network-manager/src/wire-protocol.ts
1854
+ var import_teleport = require("@dxos/teleport");
1855
+ var createTeleportProtocolFactory = (onConnection) => {
1856
+ return (params) => {
1857
+ const teleport = new import_teleport.Teleport(params);
1858
+ return {
1859
+ stream: teleport.stream,
1860
+ initialize: async () => {
1861
+ await teleport.open();
1862
+ await onConnection(teleport);
1954
1863
  },
1955
- initiator,
1956
- userSession: session,
1957
- discoveryKey: channel
1958
- });
1959
- protocol.setExtensions(plugins.map((plugin) => plugin.createExtension())).init();
1960
- return protocol;
1864
+ destroy: async () => {
1865
+ await teleport.close();
1866
+ }
1867
+ };
1961
1868
  };
1962
1869
  };
1963
1870
 
1964
- // packages/core/mesh/network-manager/src/testing/test-protocol.ts
1965
- var EXTENSION_NAME = "test";
1966
- var getPeerId = (protocol) => {
1967
- var _a;
1968
- const { peerId } = (_a = protocol.getSession()) != null ? _a : {};
1969
- if (!peerId) {
1970
- return void 0;
1971
- }
1972
- return import_keys11.PublicKey.bufferize(peerId);
1973
- };
1974
- var testProtocolProvider = (topic, peerId, protocolPlugin) => {
1975
- (0, import_log14.log)("creating protocol-factory", {
1976
- topic: import_keys11.PublicKey.from(topic),
1977
- peerId
1978
- }, {
1979
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
1980
- line: 34,
1981
- scope: void 0,
1982
- callSite: (f, a) => f(...a)
1983
- });
1984
- return protocolFactory({
1985
- getTopics: () => [
1986
- topic
1987
- ],
1988
- session: {
1989
- peerId: peerId.toHex()
1990
- },
1991
- plugins: [
1992
- protocolPlugin
1993
- ]
1994
- });
1995
- };
1996
- var TestProtocolPlugin = class extends import_node_events.EventEmitter {
1997
- constructor(peerId, uppercase = false) {
1998
- super();
1999
- this._peers = /* @__PURE__ */ new Map();
2000
- this.initCalled = false;
2001
- (0, import_node_assert12.default)(Buffer.isBuffer(peerId));
2002
- this._peerId = peerId;
2003
- this._uppercase = uppercase;
2004
- }
2005
- get peerId() {
2006
- return this._peerId;
2007
- }
2008
- get peers() {
2009
- return Array.from(this._peers.values());
2010
- }
2011
- createExtension() {
2012
- (0, import_log14.log)("creating extension", {
2013
- peerId: import_keys11.PublicKey.from(this.peerId)
2014
- }, {
2015
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
2016
- line: 92,
2017
- scope: this,
2018
- callSite: (f, a) => f(...a)
2019
- });
2020
- return new import_mesh_protocol2.Extension(EXTENSION_NAME, {
2021
- binary: true
2022
- }).setInitHandler(this._init.bind(this)).setMessageHandler(this._receive.bind(this)).setHandshakeHandler(this._onPeerConnect.bind(this)).setCloseHandler(this._onPeerDisconnect.bind(this));
2023
- }
2024
- async _init(protocol) {
2025
- this.initCalled = true;
2026
- }
2027
- async send(peerId, payload) {
2028
- (0, import_node_assert12.default)(Buffer.isBuffer(peerId));
2029
- const peerIdStr = import_keys11.PublicKey.stringify(peerId);
2030
- const peer = this._peers.get(peerIdStr);
2031
- if (!peer) {
2032
- throw new Error(`peer not found: ${import_keys11.PublicKey.from(peerId).truncate()}`);
2033
- }
2034
- const extension = peer.getExtension(EXTENSION_NAME);
2035
- const encoded = Buffer.from(payload);
2036
- (0, import_log14.log)("sending", {
2037
- peerId: import_keys11.PublicKey.from(peerId),
2038
- payload
2039
- }, {
2040
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
2041
- line: 124,
2042
- scope: this,
2043
- callSite: (f, a) => f(...a)
2044
- });
2045
- return await extension.send(encoded, {
2046
- oneway: true
1871
+ // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
1872
+ var TestWireProtocol = class {
1873
+ constructor(peerId) {
1874
+ this.peerId = peerId;
1875
+ this.connections = new import_util8.ComplexMap(import_keys10.PublicKey.hash);
1876
+ this.connected = new import_async10.Event();
1877
+ this.factory = createTeleportProtocolFactory(async (teleport) => {
1878
+ (0, import_log13.log)("create", {
1879
+ remotePeerId: teleport.remotePeerId
1880
+ }, {
1881
+ file: "test-wire-protocol.ts",
1882
+ line: 20,
1883
+ scope: this,
1884
+ callSite: (f, a) => f(...a)
1885
+ });
1886
+ const extension = new import_teleport2.TestExtension({
1887
+ onClose: async () => {
1888
+ this.connections.delete(teleport.remotePeerId);
1889
+ }
1890
+ });
1891
+ this.connections.set(teleport.remotePeerId, extension);
1892
+ teleport.addExtension("test", extension);
1893
+ this.connected.emit(teleport.remotePeerId);
2047
1894
  });
2048
1895
  }
2049
- async _receive(protocol, data) {
2050
- const peerId = getPeerId(protocol);
2051
- (0, import_node_assert12.default)(peerId !== void 0);
2052
- let payload = data.data.toString();
2053
- if (this._uppercase) {
2054
- payload = payload.toUpperCase();
1896
+ async waitForConnection(peerId) {
1897
+ if (this.connections.has(peerId)) {
1898
+ return this.connections.get(peerId);
2055
1899
  }
2056
- (0, import_log14.log)("received", {
2057
- peerId: import_keys11.PublicKey.from(peerId),
2058
- payload
1900
+ (0, import_log13.log)("waitForConnection", {
1901
+ peerId
2059
1902
  }, {
2060
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
2061
- line: 136,
1903
+ file: "test-wire-protocol.ts",
1904
+ line: 35,
2062
1905
  scope: this,
2063
1906
  callSite: (f, a) => f(...a)
2064
1907
  });
2065
- this.emit("receive", protocol, payload);
1908
+ await this.connected.waitFor((connectedId) => connectedId.equals(peerId));
1909
+ return this.connections.get(peerId);
2066
1910
  }
2067
- async _onPeerConnect(protocol) {
2068
- (0, import_log14.log)("connecting", {
2069
- id: import_keys11.PublicKey.from(protocol.id)
2070
- }, {
2071
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
2072
- line: 141,
2073
- scope: this,
2074
- callSite: (f, a) => f(...a)
2075
- });
2076
- const peerId = getPeerId(protocol);
2077
- if (peerId === void 0) {
2078
- return;
2079
- }
2080
- const peerIdStr = import_keys11.PublicKey.stringify(peerId);
2081
- if (this._peers.has(peerIdStr)) {
2082
- return;
2083
- }
2084
- this._peers.set(peerIdStr, protocol);
2085
- this.emit("connect", protocol);
2086
- }
2087
- async _onPeerDisconnect(protocol) {
2088
- (0, import_log14.log)("disconnecting", {
2089
- id: import_keys11.PublicKey.from(protocol.id)
2090
- }, {
2091
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
2092
- line: 157,
2093
- scope: this,
2094
- callSite: (f, a) => f(...a)
2095
- });
2096
- const peerId = getPeerId(protocol);
2097
- if (peerId === void 0) {
2098
- return;
2099
- }
2100
- this._peers.delete(import_keys11.PublicKey.stringify(peerId));
2101
- this.emit("disconnect", peerId);
1911
+ async testConnection(peerId) {
1912
+ const connection = await this.waitForConnection(peerId);
1913
+ await connection.test();
2102
1914
  }
2103
1915
  };
2104
1916
 
@@ -2122,8 +1934,8 @@ var TestBuilder = class {
2122
1934
  var TestPeer = class {
2123
1935
  constructor(testBuilder) {
2124
1936
  this.testBuilder = testBuilder;
2125
- this.peerId = import_keys12.PublicKey.random();
2126
- this._swarms = new import_util8.ComplexMap(import_keys12.PublicKey.hash);
1937
+ this.peerId = import_keys11.PublicKey.random();
1938
+ this._swarms = new import_util9.ComplexMap(import_keys11.PublicKey.hash);
2127
1939
  this._networkManager = this.createNetworkManager();
2128
1940
  }
2129
1941
  createNetworkManager() {
@@ -2196,13 +2008,13 @@ var TestSwarmConnection = class {
2196
2008
  constructor(peer, topic) {
2197
2009
  this.peer = peer;
2198
2010
  this.topic = topic;
2199
- this.plugin = new TestProtocolPlugin(this.peer.peerId.asBuffer());
2011
+ this.protocol = new TestWireProtocol(this.peer.peerId);
2200
2012
  }
2201
2013
  async join(topology = new FullyConnectedTopology()) {
2202
2014
  await this.peer._networkManager.joinSwarm({
2203
2015
  topic: this.topic,
2204
2016
  peerId: this.peer.peerId,
2205
- protocolProvider: adaptProtocolProvider(testProtocolProvider(this.topic.asBuffer(), this.peer.peerId, this.plugin)),
2017
+ protocolProvider: this.protocol.factory,
2206
2018
  topology
2207
2019
  });
2208
2020
  return this;
@@ -2217,9 +2029,6 @@ var TestSwarmConnection = class {
2217
2029
  TEST_SIGNAL_URL,
2218
2030
  TestBuilder,
2219
2031
  TestPeer,
2220
- TestProtocolPlugin,
2221
- TestSwarmConnection,
2222
- getPeerId,
2223
- testProtocolProvider
2032
+ TestSwarmConnection
2224
2033
  });
2225
2034
  //# sourceMappingURL=index.cjs.map