@dxos/network-manager 0.1.56-next.a63ce79 → 0.1.56

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 (42) hide show
  1. package/dist/lib/browser/{chunk-5TRIVLI6.mjs → chunk-BYYPWP6O.mjs} +105 -89
  2. package/dist/lib/browser/chunk-BYYPWP6O.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +19 -9
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +104 -88
  8. package/dist/lib/node/index.cjs.map +3 -3
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +120 -94
  11. package/dist/lib/node/testing/index.cjs.map +3 -3
  12. package/dist/types/src/connection-log.d.ts.map +1 -1
  13. package/dist/types/src/signal/swarm-messenger.d.ts +1 -1
  14. package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
  15. package/dist/types/src/swarm/connection-limiter.d.ts +1 -1
  16. package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
  17. package/dist/types/src/swarm/connection.d.ts +2 -1
  18. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  19. package/dist/types/src/swarm/peer.d.ts +1 -1
  20. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  21. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  22. package/dist/types/src/testing/test-builder.d.ts +4 -3
  23. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  24. package/dist/types/src/testing/test-wire-protocol.d.ts +13 -2
  25. package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
  26. package/dist/types/src/transport/webrtc-transport-proxy.d.ts +1 -1
  27. package/dist/types/src/transport/webrtc-transport-proxy.d.ts.map +1 -1
  28. package/dist/types/src/transport/webrtc-transport.d.ts +3 -3
  29. package/dist/types/src/transport/webrtc-transport.d.ts.map +1 -1
  30. package/package.json +18 -18
  31. package/src/connection-log.ts +2 -0
  32. package/src/signal/swarm-messenger.ts +2 -2
  33. package/src/swarm/connection-limiter.ts +1 -1
  34. package/src/swarm/connection.ts +12 -3
  35. package/src/swarm/peer.ts +8 -6
  36. package/src/swarm/swarm.ts +5 -5
  37. package/src/testing/test-builder.ts +9 -5
  38. package/src/testing/test-wire-protocol.ts +22 -2
  39. package/src/tests/memory-transport.test.ts +1 -1
  40. package/src/transport/webrtc-transport-proxy.ts +4 -4
  41. package/src/transport/webrtc-transport.ts +20 -6
  42. package/dist/lib/browser/chunk-5TRIVLI6.mjs.map +0 -7
@@ -80,7 +80,7 @@ function _ts_decorate(decorators, target, key, desc) {
80
80
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
81
81
  return c > 3 && r && Object.defineProperty(target, key, r), r;
82
82
  }
83
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
83
+ var __dxlog_file = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection.ts";
84
84
  var STARTING_SIGNALLING_DELAY = 10;
85
85
  var MAX_SIGNALLING_DELAY = 300;
86
86
  var ConnectionState;
@@ -146,7 +146,7 @@ var Connection = class {
146
146
  initiator: this.initiator
147
147
  }, {
148
148
  F: __dxlog_file,
149
- L: 95,
149
+ L: 96,
150
150
  S: this,
151
151
  C: (f, a) => f(...a)
152
152
  });
@@ -166,7 +166,7 @@ var Connection = class {
166
166
  async openConnection() {
167
167
  (0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
168
168
  F: __dxlog_file,
169
- L: 120,
169
+ L: 121,
170
170
  S: this,
171
171
  A: [
172
172
  "this._state === ConnectionState.INITIAL",
@@ -177,7 +177,7 @@ var Connection = class {
177
177
  id: this._instanceId
178
178
  }), {
179
179
  F: __dxlog_file,
180
- L: 121,
180
+ L: 122,
181
181
  S: this,
182
182
  C: (f, a) => f(...a)
183
183
  });
@@ -189,7 +189,7 @@ var Connection = class {
189
189
  initiator: this.initiator
190
190
  }, {
191
191
  F: __dxlog_file,
192
- L: 122,
192
+ L: 123,
193
193
  S: this,
194
194
  C: (f, a) => f(...a)
195
195
  });
@@ -200,7 +200,7 @@ var Connection = class {
200
200
  this._protocol.stream.on("close", () => {
201
201
  (0, import_log.log)("protocol stream closed", void 0, {
202
202
  F: __dxlog_file,
203
- L: 139,
203
+ L: 140,
204
204
  S: this,
205
205
  C: (f, a) => f(...a)
206
206
  });
@@ -208,7 +208,7 @@ var Connection = class {
208
208
  });
209
209
  (0, import_invariant.invariant)(!this._transport, void 0, {
210
210
  F: __dxlog_file,
211
- L: 143,
211
+ L: 144,
212
212
  S: this,
213
213
  A: [
214
214
  "!this._transport",
@@ -228,6 +228,9 @@ var Connection = class {
228
228
  this.close().catch((err) => this.errors.raise(err));
229
229
  });
230
230
  this._transport.errors.handle((err) => {
231
+ if (!this.closeReason) {
232
+ this.closeReason = err?.message;
233
+ }
231
234
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
232
235
  this.errors.raise(err);
233
236
  }
@@ -240,12 +243,15 @@ var Connection = class {
240
243
  id: this._instanceId
241
244
  }), {
242
245
  F: __dxlog_file,
243
- L: 172,
246
+ L: 176,
244
247
  S: this,
245
248
  C: (f, a) => f(...a)
246
249
  });
247
250
  }
248
- async close() {
251
+ async close(err) {
252
+ if (!this.closeReason) {
253
+ this.closeReason = err?.message;
254
+ }
249
255
  if (this._state === ConnectionState.CLOSED) {
250
256
  return;
251
257
  }
@@ -255,26 +261,26 @@ var Connection = class {
255
261
  peerId: this.ownId
256
262
  }, {
257
263
  F: __dxlog_file,
258
- L: 184,
264
+ L: 191,
259
265
  S: this,
260
266
  C: (f, a) => f(...a)
261
267
  });
262
268
  try {
263
269
  await this._protocol.destroy();
264
- } catch (err) {
265
- import_log.log.catch(err, void 0, {
270
+ } catch (err2) {
271
+ import_log.log.catch(err2, void 0, {
266
272
  F: __dxlog_file,
267
- L: 190,
273
+ L: 197,
268
274
  S: this,
269
275
  C: (f, a) => f(...a)
270
276
  });
271
277
  }
272
278
  try {
273
279
  await this._transport?.destroy();
274
- } catch (err) {
275
- import_log.log.catch(err, void 0, {
280
+ } catch (err2) {
281
+ import_log.log.catch(err2, void 0, {
276
282
  F: __dxlog_file,
277
- L: 197,
283
+ L: 204,
278
284
  S: this,
279
285
  C: (f, a) => f(...a)
280
286
  });
@@ -283,7 +289,7 @@ var Connection = class {
283
289
  peerId: this.ownId
284
290
  }, {
285
291
  F: __dxlog_file,
286
- L: 200,
292
+ L: 207,
287
293
  S: this,
288
294
  C: (f, a) => f(...a)
289
295
  });
@@ -298,8 +304,10 @@ var Connection = class {
298
304
  return;
299
305
  }
300
306
  try {
301
- await (0, import_context.cancelWithContext)(this._ctx, (0, import_async.sleep)(this._signallingDelay));
302
- this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
307
+ if (process.env.NODE_ENV !== "test") {
308
+ await (0, import_context.cancelWithContext)(this._ctx, (0, import_async.sleep)(this._signallingDelay));
309
+ this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
310
+ }
303
311
  const signals = [
304
312
  ...this._outgoingSignalBuffer
305
313
  ];
@@ -323,7 +331,7 @@ var Connection = class {
323
331
  err
324
332
  }, {
325
333
  F: __dxlog_file,
326
- L: 234,
334
+ L: 243,
327
335
  S: this,
328
336
  C: (f, a) => f(...a)
329
337
  });
@@ -336,7 +344,7 @@ var Connection = class {
336
344
  async signal(msg) {
337
345
  (0, import_invariant.invariant)(msg.sessionId, void 0, {
338
346
  F: __dxlog_file,
339
- L: 243,
347
+ L: 252,
340
348
  S: this,
341
349
  A: [
342
350
  "msg.sessionId",
@@ -346,7 +354,7 @@ var Connection = class {
346
354
  if (!msg.sessionId.equals(this.sessionId)) {
347
355
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
348
356
  F: __dxlog_file,
349
- L: 245,
357
+ L: 254,
350
358
  S: this,
351
359
  C: (f, a) => f(...a)
352
360
  });
@@ -354,7 +362,7 @@ var Connection = class {
354
362
  }
355
363
  (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
356
364
  F: __dxlog_file,
357
- L: 248,
365
+ L: 257,
358
366
  S: this,
359
367
  A: [
360
368
  "msg.data.signal || msg.data.signalBatch",
@@ -363,7 +371,7 @@ var Connection = class {
363
371
  });
364
372
  (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
365
373
  F: __dxlog_file,
366
- L: 249,
374
+ L: 258,
367
375
  S: this,
368
376
  A: [
369
377
  "msg.author?.equals(this.remoteId)",
@@ -372,7 +380,7 @@ var Connection = class {
372
380
  });
373
381
  (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
374
382
  F: __dxlog_file,
375
- L: 250,
383
+ L: 259,
376
384
  S: this,
377
385
  A: [
378
386
  "msg.recipient?.equals(this.ownId)",
@@ -393,7 +401,7 @@ var Connection = class {
393
401
  msg: msg.data
394
402
  }, {
395
403
  F: __dxlog_file,
396
- L: 259,
404
+ L: 268,
397
405
  S: this,
398
406
  C: (f, a) => f(...a)
399
407
  });
@@ -401,7 +409,7 @@ var Connection = class {
401
409
  } else {
402
410
  (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
403
411
  F: __dxlog_file,
404
- L: 262,
412
+ L: 271,
405
413
  S: this,
406
414
  A: [
407
415
  "this._transport",
@@ -414,7 +422,7 @@ var Connection = class {
414
422
  msg: msg.data
415
423
  }, {
416
424
  F: __dxlog_file,
417
- L: 263,
425
+ L: 272,
418
426
  S: this,
419
427
  C: (f, a) => f(...a)
420
428
  });
@@ -429,13 +437,13 @@ var Connection = class {
429
437
  peerId: this.ownId
430
438
  }, {
431
439
  F: __dxlog_file,
432
- L: 270,
440
+ L: 279,
433
441
  S: this,
434
442
  C: (f, a) => f(...a)
435
443
  });
436
444
  (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
437
445
  F: __dxlog_file,
438
- L: 271,
446
+ L: 280,
439
447
  S: this,
440
448
  A: [
441
449
  "state !== this._state",
@@ -467,7 +475,7 @@ var import_keys2 = require("@dxos/keys");
467
475
  var import_log2 = require("@dxos/log");
468
476
  var import_protocols2 = require("@dxos/protocols");
469
477
  var import_util = require("@dxos/util");
470
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
478
+ var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
471
479
  var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
472
480
  var SwarmMessenger = class {
473
481
  constructor({ sendMessage, onSignal, onOffer, topic }) {
@@ -709,9 +717,10 @@ function _ts_decorate2(decorators, target, key, desc) {
709
717
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
710
718
  return c > 3 && r && Object.defineProperty(target, key, r), r;
711
719
  }
712
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
720
+ var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/peer.ts";
713
721
  var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
714
722
  var Peer = class {
723
+ // TODO(burdon): Convert to map?
715
724
  constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
716
725
  this.id = id;
717
726
  this.topic = topic;
@@ -741,12 +750,12 @@ var Peer = class {
741
750
  sessionId: this.connection?.sessionId
742
751
  }, {
743
752
  F: __dxlog_file3,
744
- L: 106,
753
+ L: 108,
745
754
  S: this,
746
755
  C: (f, a) => f(...a)
747
756
  });
748
757
  if (this.connection) {
749
- await this.closeConnection();
758
+ await this.closeConnection(new Error("Connection displaced by remote initiator."));
750
759
  }
751
760
  } else {
752
761
  return {
@@ -758,7 +767,7 @@ var Peer = class {
758
767
  if (!this.connection) {
759
768
  (0, import_invariant3.invariant)(message.sessionId, void 0, {
760
769
  F: __dxlog_file3,
761
- L: 126,
770
+ L: 128,
762
771
  S: this,
763
772
  A: [
764
773
  "message.sessionId",
@@ -778,12 +787,12 @@ var Peer = class {
778
787
  err
779
788
  }, {
780
789
  F: __dxlog_file3,
781
- L: 134,
790
+ L: 136,
782
791
  S: this,
783
792
  C: (f, a) => f(...a)
784
793
  });
785
794
  }
786
- await this.closeConnection();
795
+ await this.closeConnection(err);
787
796
  }
788
797
  return {
789
798
  accept: true
@@ -800,7 +809,7 @@ var Peer = class {
800
809
  async initiateConnection() {
801
810
  (0, import_invariant3.invariant)(!this.initiating, "Initiation in progress.", {
802
811
  F: __dxlog_file3,
803
- L: 151,
812
+ L: 153,
804
813
  S: this,
805
814
  A: [
806
815
  "!this.initiating",
@@ -809,7 +818,7 @@ var Peer = class {
809
818
  });
810
819
  (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
811
820
  F: __dxlog_file3,
812
- L: 152,
821
+ L: 154,
813
822
  S: this,
814
823
  A: [
815
824
  "!this.connection",
@@ -824,7 +833,7 @@ var Peer = class {
824
833
  sessionId
825
834
  }, {
826
835
  F: __dxlog_file3,
827
- L: 154,
836
+ L: 156,
828
837
  S: this,
829
838
  C: (f, a) => f(...a)
830
839
  });
@@ -848,14 +857,14 @@ var Peer = class {
848
857
  remoteId: this.id
849
858
  }, {
850
859
  F: __dxlog_file3,
851
- L: 169,
860
+ L: 171,
852
861
  S: this,
853
862
  C: (f, a) => f(...a)
854
863
  });
855
864
  if (connection.state !== ConnectionState.INITIAL) {
856
865
  (0, import_log3.log)("ignoring response", void 0, {
857
866
  F: __dxlog_file3,
858
- L: 171,
867
+ L: 173,
859
868
  S: this,
860
869
  C: (f, a) => f(...a)
861
870
  });
@@ -875,11 +884,11 @@ var Peer = class {
875
884
  remoteId: this.id
876
885
  }, {
877
886
  F: __dxlog_file3,
878
- L: 182,
887
+ L: 184,
879
888
  S: this,
880
889
  C: (f, a) => f(...a)
881
890
  });
882
- await this.closeConnection();
891
+ await this.closeConnection(err);
883
892
  throw err;
884
893
  } finally {
885
894
  this.initiating = false;
@@ -898,13 +907,13 @@ var Peer = class {
898
907
  sessionId
899
908
  }, {
900
909
  F: __dxlog_file3,
901
- L: 196,
910
+ L: 198,
902
911
  S: this,
903
912
  C: (f, a) => f(...a)
904
913
  });
905
914
  (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
906
915
  F: __dxlog_file3,
907
- L: 203,
916
+ L: 205,
908
917
  S: this,
909
918
  A: [
910
919
  "!this.connection",
@@ -945,7 +954,7 @@ var Peer = class {
945
954
  initiator
946
955
  }, {
947
956
  F: __dxlog_file3,
948
- L: 229,
957
+ L: 231,
949
958
  S: this,
950
959
  C: (f, a) => f(...a)
951
960
  });
@@ -959,13 +968,13 @@ var Peer = class {
959
968
  initiator
960
969
  }, {
961
970
  F: __dxlog_file3,
962
- L: 240,
971
+ L: 242,
963
972
  S: this,
964
973
  C: (f, a) => f(...a)
965
974
  });
966
975
  (0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
967
976
  F: __dxlog_file3,
968
- L: 241,
977
+ L: 243,
969
978
  S: this,
970
979
  A: [
971
980
  "this.connection === connection",
@@ -980,7 +989,7 @@ var Peer = class {
980
989
  initiator
981
990
  }, {
982
991
  F: __dxlog_file3,
983
- L: 243,
992
+ L: 245,
984
993
  S: this,
985
994
  C: (f, a) => f(...a)
986
995
  });
@@ -1010,7 +1019,7 @@ var Peer = class {
1010
1019
  err
1011
1020
  }, {
1012
1021
  F: __dxlog_file3,
1013
- L: 277,
1022
+ L: 279,
1014
1023
  S: this,
1015
1024
  C: (f, a) => f(...a)
1016
1025
  });
@@ -1023,16 +1032,16 @@ var Peer = class {
1023
1032
  err
1024
1033
  }, {
1025
1034
  F: __dxlog_file3,
1026
- L: 278,
1035
+ L: 280,
1027
1036
  S: this,
1028
1037
  C: (f, a) => f(...a)
1029
1038
  });
1030
- void this.closeConnection();
1039
+ void this.closeConnection(err);
1031
1040
  });
1032
1041
  this.connection = connection;
1033
1042
  return connection;
1034
1043
  }
1035
- async closeConnection() {
1044
+ async closeConnection(err) {
1036
1045
  if (!this.connection) {
1037
1046
  return;
1038
1047
  }
@@ -1042,17 +1051,17 @@ var Peer = class {
1042
1051
  sessionId: connection.sessionId
1043
1052
  }, {
1044
1053
  F: __dxlog_file3,
1045
- L: 301,
1054
+ L: 303,
1046
1055
  S: this,
1047
1056
  C: (f, a) => f(...a)
1048
1057
  });
1049
- await connection.close();
1058
+ await connection.close(err);
1050
1059
  (0, import_log3.log)("closed", {
1051
1060
  peerId: this.id,
1052
1061
  sessionId: connection.sessionId
1053
1062
  }, {
1054
1063
  F: __dxlog_file3,
1055
- L: 307,
1064
+ L: 309,
1056
1065
  S: this,
1057
1066
  C: (f, a) => f(...a)
1058
1067
  });
@@ -1063,7 +1072,7 @@ var Peer = class {
1063
1072
  message
1064
1073
  }, {
1065
1074
  F: __dxlog_file3,
1066
- L: 312,
1075
+ L: 314,
1067
1076
  S: this,
1068
1077
  C: (f, a) => f(...a)
1069
1078
  });
@@ -1078,7 +1087,7 @@ var Peer = class {
1078
1087
  topic: this.topic
1079
1088
  }, {
1080
1089
  F: __dxlog_file3,
1081
- L: 322,
1090
+ L: 324,
1082
1091
  S: this,
1083
1092
  C: (f, a) => f(...a)
1084
1093
  });
@@ -1112,7 +1121,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1112
1121
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1113
1122
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1114
1123
  }
1115
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1124
+ var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1116
1125
  var INITIATION_DELAY = 100;
1117
1126
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1118
1127
  var Swarm = class {
@@ -1127,9 +1136,9 @@ var Swarm = class {
1127
1136
  this._transportFactory = _transportFactory;
1128
1137
  this._label = _label;
1129
1138
  this._connectionLimiter = _connectionLimiter;
1130
- this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
1131
1139
  this._ctx = new import_context4.Context();
1132
1140
  this._listeningHandle = void 0;
1141
+ this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
1133
1142
  this._instanceId = import_keys4.PublicKey.random().toHex();
1134
1143
  this.connectionAdded = new import_async3.Event();
1135
1144
  this.disconnected = new import_async3.Event();
@@ -1585,7 +1594,7 @@ var import_async4 = require("@dxos/async");
1585
1594
  var import_keys5 = require("@dxos/keys");
1586
1595
  var import_log5 = require("@dxos/log");
1587
1596
  var import_util3 = require("@dxos/util");
1588
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1597
+ var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1589
1598
  var SwarmMapper = class {
1590
1599
  get peers() {
1591
1600
  return Array.from(this._peers.values());
@@ -1658,8 +1667,8 @@ var import_invariant5 = require("@dxos/invariant");
1658
1667
  var import_keys6 = require("@dxos/keys");
1659
1668
  var import_log6 = require("@dxos/log");
1660
1669
  var import_util4 = require("@dxos/util");
1661
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1662
- var MAX_CONCURRENT_INITIATING_CONNECTIONS = 3;
1670
+ var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1671
+ var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
1663
1672
  var ConnectionLimiter = class {
1664
1673
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
1665
1674
  this._ctx = new import_context5.Context();
@@ -1768,6 +1777,7 @@ var ConnectionLog = class {
1768
1777
  swarm.connectionAdded.on((connection) => {
1769
1778
  const connectionInfo = {
1770
1779
  state: ConnectionState.INITIAL,
1780
+ closeReason: connection.closeReason,
1771
1781
  remotePeerId: connection.remoteId,
1772
1782
  sessionId: connection.sessionId,
1773
1783
  transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
@@ -1778,6 +1788,7 @@ var ConnectionLog = class {
1778
1788
  this.update.emit();
1779
1789
  connection.stateChanged.on((state) => {
1780
1790
  connectionInfo.state = state;
1791
+ connectionInfo.closeReason = connection.closeReason;
1781
1792
  connectionInfo.events.push({
1782
1793
  type: EventType.CONNECTION_STATE_CHANGED,
1783
1794
  newState: state
@@ -1797,7 +1808,7 @@ var ConnectionLog = class {
1797
1808
  };
1798
1809
 
1799
1810
  // packages/core/mesh/network-manager/src/network-manager.ts
1800
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
1811
+ var __dxlog_file7 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/network-manager.ts";
1801
1812
  var NetworkManager = class {
1802
1813
  constructor({ transportFactory, signalManager, log: log1 }) {
1803
1814
  /**
@@ -2033,7 +2044,7 @@ var NetworkManager = class {
2033
2044
 
2034
2045
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2035
2046
  var import_invariant7 = require("@dxos/invariant");
2036
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2047
+ var __dxlog_file8 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2037
2048
  var FullyConnectedTopology = class {
2038
2049
  toString() {
2039
2050
  return "FullyConnectedTopology";
@@ -2099,7 +2110,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2099
2110
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2100
2111
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2101
2112
  }
2102
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2113
+ var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2103
2114
  var MEMORY_TRANSPORT_DELAY = 1;
2104
2115
  var createStreamDelay = (delay) => {
2105
2116
  return new import_node_stream.Transform({
@@ -2284,38 +2295,43 @@ try {
2284
2295
  }
2285
2296
 
2286
2297
  // packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
2287
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
2298
+ var __dxlog_file10 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
2288
2299
  var WebRTCTransport = class {
2289
2300
  constructor(params) {
2290
2301
  this.params = params;
2302
+ this._instanceId = import_keys10.PublicKey.random().toHex();
2291
2303
  this._closed = false;
2292
2304
  this.closed = new import_async9.Event();
2293
2305
  this.connected = new import_async9.Event();
2294
2306
  this.errors = new import_debug5.ErrorStream();
2295
- this._instanceId = import_keys10.PublicKey.random().toHex();
2296
2307
  import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
2297
2308
  id: this._instanceId
2298
2309
  }), {
2299
2310
  F: __dxlog_file10,
2300
- L: 39,
2311
+ L: 44,
2301
2312
  S: this,
2302
2313
  C: (f, a) => f(...a)
2303
2314
  });
2304
2315
  (0, import_log11.log)("created connection", params, {
2305
2316
  F: __dxlog_file10,
2306
- L: 40,
2317
+ L: 45,
2307
2318
  S: this,
2308
2319
  C: (f, a) => f(...a)
2309
2320
  });
2310
2321
  this._peer = new import_simple_peer.default({
2311
2322
  initiator: this.params.initiator,
2312
- wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 : wrtc ?? (0, import_debug5.raise)(new Error("wrtc not available")),
2313
- config: this.params.webrtcConfig
2323
+ config: this.params.webrtcConfig,
2324
+ // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createDataChannel
2325
+ channelConfig: {
2326
+ protocol: "dxos.mesh"
2327
+ },
2328
+ // Custom WebRTC implementation (for Node); otherwise get-browser-rtc.
2329
+ wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 : wrtc ?? (0, import_debug5.raise)(new Error("wrtc not available"))
2314
2330
  });
2315
2331
  this._peer.on("signal", async (data) => {
2316
2332
  (0, import_log11.log)("signal", data, {
2317
2333
  F: __dxlog_file10,
2318
- L: 48,
2334
+ L: 62,
2319
2335
  S: this,
2320
2336
  C: (f, a) => f(...a)
2321
2337
  });
@@ -2328,7 +2344,7 @@ var WebRTCTransport = class {
2328
2344
  this._peer.on("connect", () => {
2329
2345
  (0, import_log11.log)("connected", void 0, {
2330
2346
  F: __dxlog_file10,
2331
- L: 53,
2347
+ L: 67,
2332
2348
  S: this,
2333
2349
  C: (f, a) => f(...a)
2334
2350
  });
@@ -2338,7 +2354,7 @@ var WebRTCTransport = class {
2338
2354
  this._peer.on("close", async () => {
2339
2355
  (0, import_log11.log)("closed", void 0, {
2340
2356
  F: __dxlog_file10,
2341
- L: 59,
2357
+ L: 73,
2342
2358
  S: this,
2343
2359
  C: (f, a) => f(...a)
2344
2360
  });
@@ -2355,7 +2371,7 @@ var WebRTCTransport = class {
2355
2371
  stats
2356
2372
  }, {
2357
2373
  F: __dxlog_file10,
2358
- L: 71,
2374
+ L: 85,
2359
2375
  S: this,
2360
2376
  C: (f, a) => f(...a)
2361
2377
  });
@@ -2369,7 +2385,7 @@ var WebRTCTransport = class {
2369
2385
  id: this._instanceId
2370
2386
  }), {
2371
2387
  F: __dxlog_file10,
2372
- L: 81,
2388
+ L: 95,
2373
2389
  S: this,
2374
2390
  C: (f, a) => f(...a)
2375
2391
  });
@@ -2377,7 +2393,7 @@ var WebRTCTransport = class {
2377
2393
  async destroy() {
2378
2394
  (0, import_log11.log)("closing...", void 0, {
2379
2395
  F: __dxlog_file10,
2380
- L: 85,
2396
+ L: 99,
2381
2397
  S: this,
2382
2398
  C: (f, a) => f(...a)
2383
2399
  });
@@ -2387,7 +2403,7 @@ var WebRTCTransport = class {
2387
2403
  this.closed.emit();
2388
2404
  (0, import_log11.log)("closed", void 0, {
2389
2405
  F: __dxlog_file10,
2390
- L: 90,
2406
+ L: 104,
2391
2407
  S: this,
2392
2408
  C: (f, a) => f(...a)
2393
2409
  });
@@ -2398,7 +2414,7 @@ var WebRTCTransport = class {
2398
2414
  }
2399
2415
  (0, import_invariant11.invariant)(signal.payload.data, "Signal message must contain signal data.", {
2400
2416
  F: __dxlog_file10,
2401
- L: 98,
2417
+ L: 112,
2402
2418
  S: this,
2403
2419
  A: [
2404
2420
  "signal.payload.data",
@@ -2420,7 +2436,7 @@ var import_keys11 = require("@dxos/keys");
2420
2436
  var import_log12 = require("@dxos/log");
2421
2437
  var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
2422
2438
  var import_util8 = require("@dxos/util");
2423
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
2439
+ var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
2424
2440
  var WebRTCTransportService = class {
2425
2441
  // prettier-ignore
2426
2442
  constructor(_webrtcConfig) {
@@ -2552,7 +2568,7 @@ var import_keys12 = require("@dxos/keys");
2552
2568
  var import_log13 = require("@dxos/log");
2553
2569
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
2554
2570
  var import_util9 = require("@dxos/util");
2555
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
2571
+ var __dxlog_file12 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
2556
2572
  var WebRTCTransportProxy = class {
2557
2573
  // prettier-ignore
2558
2574
  constructor(_params) {
@@ -2560,9 +2576,9 @@ var WebRTCTransportProxy = class {
2560
2576
  this._proxyId = import_keys12.PublicKey.random();
2561
2577
  this._ctx = new import_context6.Context();
2562
2578
  this.closed = new import_async10.Event();
2563
- this._closed = false;
2564
2579
  this.connected = new import_async10.Event();
2565
2580
  this.errors = new import_debug6.ErrorStream();
2581
+ this._closed = false;
2566
2582
  this._serviceStream = this._params.bridgeService.open({
2567
2583
  proxyId: this._proxyId,
2568
2584
  initiator: this._params.initiator
@@ -2638,7 +2654,7 @@ var WebRTCTransportProxy = class {
2638
2654
  if (this._closed) {
2639
2655
  return;
2640
2656
  }
2641
- this._serviceStream.close();
2657
+ await this._serviceStream.close();
2642
2658
  try {
2643
2659
  await this._params.bridgeService.close({
2644
2660
  proxyId: this._proxyId
@@ -2659,7 +2675,7 @@ var WebRTCTransportProxy = class {
2659
2675
  */
2660
2676
  // TODO(burdon): Option on close method.
2661
2677
  forceClose() {
2662
- this._serviceStream.close();
2678
+ void this._serviceStream.close();
2663
2679
  this.closed.emit();
2664
2680
  this._closed = true;
2665
2681
  }
@@ -2725,20 +2741,22 @@ var createTeleportProtocolFactory = (onConnection) => {
2725
2741
  };
2726
2742
 
2727
2743
  // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
2728
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
2744
+ var __dxlog_file13 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
2729
2745
  var TestWireProtocol = class {
2730
- constructor(peerId) {
2746
+ constructor(peerId, _extensionFactory = () => []) {
2731
2747
  this.peerId = peerId;
2748
+ this._extensionFactory = _extensionFactory;
2732
2749
  this.connections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
2733
2750
  this.streamConnections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
2734
2751
  this.connected = new import_async11.Event();
2735
2752
  this.disconnected = new import_async11.Event();
2753
+ this.otherConnections = new import_util10.ComplexMap(({ remotePeerId, extension }) => remotePeerId.toHex() + extension);
2736
2754
  this.factory = createTeleportProtocolFactory(async (teleport) => {
2737
2755
  (0, import_log14.log)("create", {
2738
2756
  remotePeerId: teleport.remotePeerId
2739
2757
  }, {
2740
2758
  F: __dxlog_file13,
2741
- L: 23,
2759
+ L: 38,
2742
2760
  S: this,
2743
2761
  C: (f, a) => f(...a)
2744
2762
  });
@@ -2758,6 +2776,13 @@ var TestWireProtocol = class {
2758
2776
  });
2759
2777
  this.streamConnections.set(teleport.remotePeerId, streamExtension);
2760
2778
  teleport.addExtension("test-stream", streamExtension);
2779
+ for (const { name, extension: extension2 } of this._extensionFactory()) {
2780
+ this.otherConnections.set({
2781
+ remotePeerId: teleport.remotePeerId,
2782
+ extension: name
2783
+ }, extension2);
2784
+ teleport.addExtension(name, extension2);
2785
+ }
2761
2786
  });
2762
2787
  }
2763
2788
  async waitForConnection(peerId) {
@@ -2768,7 +2793,7 @@ var TestWireProtocol = class {
2768
2793
  peerId
2769
2794
  }, {
2770
2795
  F: __dxlog_file13,
2771
- L: 47,
2796
+ L: 67,
2772
2797
  S: this,
2773
2798
  C: (f, a) => f(...a)
2774
2799
  });
@@ -2889,8 +2914,8 @@ var TestPeer = class {
2889
2914
  }
2890
2915
  return swarm;
2891
2916
  }
2892
- createSwarm(topic) {
2893
- const swarm = new TestSwarmConnection(this, topic);
2917
+ createSwarm(topic, extensionFactory = () => []) {
2918
+ const swarm = new TestSwarmConnection(this, topic, extensionFactory);
2894
2919
  this._swarms.set(topic, swarm);
2895
2920
  return swarm;
2896
2921
  }
@@ -2902,10 +2927,11 @@ var TestPeer = class {
2902
2927
  }
2903
2928
  };
2904
2929
  var TestSwarmConnection = class {
2905
- constructor(peer, topic) {
2930
+ constructor(peer, topic, extensionFactory) {
2906
2931
  this.peer = peer;
2907
2932
  this.topic = topic;
2908
- this.protocol = new TestWireProtocol(this.peer.peerId);
2933
+ this.extensionFactory = extensionFactory;
2934
+ this.protocol = new TestWireProtocol(this.peer.peerId, this.extensionFactory);
2909
2935
  }
2910
2936
  // TODO(burdon): Need to create new plugin instance per swarm?
2911
2937
  // If so, then perhaps joinSwarm should return swarm object with access to plugins.