@dxos/network-manager 0.3.9-main.b676668 → 0.3.9-main.b7528e7

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 (58) hide show
  1. package/dist/lib/browser/{chunk-LA2ACGLR.mjs → chunk-J7KS7JMZ.mjs} +382 -102
  2. package/dist/lib/browser/chunk-J7KS7JMZ.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 +1 -1
  6. package/dist/lib/node/{chunk-QWUG7JSH.cjs → chunk-55WTPQV5.cjs} +384 -94
  7. package/dist/lib/node/chunk-55WTPQV5.cjs.map +7 -0
  8. package/dist/lib/node/{chunk-XE5JOIGD.cjs → chunk-JDKM4UPJ.cjs} +21 -13
  9. package/dist/lib/node/chunk-JDKM4UPJ.cjs.map +7 -0
  10. package/dist/lib/node/{datachannel-53JZPGFA.cjs → datachannel-3VTTIMR5.cjs} +9 -9
  11. package/dist/lib/node/{datachannel-53JZPGFA.cjs.map → datachannel-3VTTIMR5.cjs.map} +2 -2
  12. package/dist/lib/node/index.cjs +32 -32
  13. package/dist/lib/node/index.cjs.map +1 -1
  14. package/dist/lib/node/meta.json +1 -1
  15. package/dist/lib/node/testing/index.cjs +19 -19
  16. package/dist/types/src/connection-log.d.ts.map +1 -1
  17. package/dist/types/src/swarm/connection.d.ts +4 -1
  18. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  19. package/dist/types/src/topology/mmst-topology.d.ts +1 -0
  20. package/dist/types/src/topology/mmst-topology.d.ts.map +1 -1
  21. package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts +7 -0
  22. package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts.map +1 -1
  23. package/dist/types/src/transport/libdatachannel-transport.d.ts +3 -1
  24. package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
  25. package/dist/types/src/transport/memory-transport.d.ts +3 -1
  26. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  27. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts +3 -1
  28. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
  29. package/dist/types/src/transport/simplepeer-transport-service.d.ts +3 -1
  30. package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
  31. package/dist/types/src/transport/simplepeer-transport.d.ts +7 -1
  32. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  33. package/dist/types/src/transport/tcp-transport.browser.d.ts +3 -1
  34. package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -1
  35. package/dist/types/src/transport/tcp-transport.d.ts +3 -1
  36. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -1
  37. package/dist/types/src/transport/transport.d.ts +17 -0
  38. package/dist/types/src/transport/transport.d.ts.map +1 -1
  39. package/dist/types/src/wire-protocol.d.ts +1 -1
  40. package/dist/types/src/wire-protocol.d.ts.map +1 -1
  41. package/package.json +17 -17
  42. package/src/connection-log.ts +14 -1
  43. package/src/swarm/connection.ts +40 -6
  44. package/src/topology/mmst-topology.ts +35 -7
  45. package/src/transport/datachannel/rtc-peer-connection.ts +20 -12
  46. package/src/transport/libdatachannel-transport.test.ts +0 -4
  47. package/src/transport/libdatachannel-transport.ts +44 -4
  48. package/src/transport/memory-transport.ts +14 -1
  49. package/src/transport/simplepeer-transport-proxy.ts +9 -1
  50. package/src/transport/simplepeer-transport-service.ts +14 -0
  51. package/src/transport/simplepeer-transport.ts +70 -3
  52. package/src/transport/tcp-transport.browser.ts +9 -1
  53. package/src/transport/tcp-transport.ts +19 -1
  54. package/src/transport/transport.ts +19 -0
  55. package/src/wire-protocol.ts +3 -3
  56. package/dist/lib/browser/chunk-LA2ACGLR.mjs.map +0 -7
  57. package/dist/lib/node/chunk-QWUG7JSH.cjs.map +0 -7
  58. package/dist/lib/node/chunk-XE5JOIGD.cjs.map +0 -7
@@ -4,13 +4,13 @@ import {
4
4
  } from "./chunk-YERMWDRB.mjs";
5
5
 
6
6
  // packages/core/mesh/network-manager/src/swarm/connection.ts
7
- import { DeferredTask, Event, sleep, scheduleTask, synchronized } from "@dxos/async";
7
+ import { DeferredTask, Event, sleep, scheduleTask, scheduleTaskInterval, synchronized } from "@dxos/async";
8
8
  import { Context, cancelWithContext } from "@dxos/context";
9
9
  import { ErrorStream } from "@dxos/debug";
10
10
  import { invariant } from "@dxos/invariant";
11
11
  import { PublicKey } from "@dxos/keys";
12
- import { log } from "@dxos/log";
13
- import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, UnknownProtocolError, trace } from "@dxos/protocols";
12
+ import { log, logInfo } from "@dxos/log";
13
+ import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, TimeoutError, UnknownProtocolError, trace } from "@dxos/protocols";
14
14
  function _ts_decorate(decorators, target, key, desc) {
15
15
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
16
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -24,6 +24,7 @@ function _ts_decorate(decorators, target, key, desc) {
24
24
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
25
25
  var STARTING_SIGNALLING_DELAY = 10;
26
26
  var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
27
+ var TRANSPORT_STATS_INTERVAL = 5e3;
27
28
  var MAX_SIGNALLING_DELAY = 300;
28
29
  var ConnectionState;
29
30
  (function(ConnectionState5) {
@@ -86,6 +87,7 @@ var Connection = class {
86
87
  this.stateChanged = new Event();
87
88
  this.errors = new ErrorStream();
88
89
  this._instanceId = PublicKey.random().toHex();
90
+ this.transportStats = new Event();
89
91
  this._signalSendTask = new DeferredTask(this._ctx, async () => {
90
92
  await this._flushSignalBuffer();
91
93
  });
@@ -98,11 +100,14 @@ var Connection = class {
98
100
  initiator: this.initiator
99
101
  }, {
100
102
  F: __dxlog_file,
101
- L: 129,
103
+ L: 134,
102
104
  S: this,
103
105
  C: (f, a) => f(...a)
104
106
  });
105
107
  }
108
+ get sessionIdString() {
109
+ return this.sessionId.truncate();
110
+ }
106
111
  get state() {
107
112
  return this._state;
108
113
  }
@@ -118,7 +123,7 @@ var Connection = class {
118
123
  async openConnection() {
119
124
  invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
120
125
  F: __dxlog_file,
121
- L: 154,
126
+ L: 164,
122
127
  S: this,
123
128
  A: [
124
129
  "this._state === ConnectionState.INITIAL",
@@ -129,7 +134,7 @@ var Connection = class {
129
134
  id: this._instanceId
130
135
  }), {
131
136
  F: __dxlog_file,
132
- L: 155,
137
+ L: 165,
133
138
  S: this,
134
139
  C: (f, a) => f(...a)
135
140
  });
@@ -141,35 +146,35 @@ var Connection = class {
141
146
  initiator: this.initiator
142
147
  }, {
143
148
  F: __dxlog_file,
144
- L: 156,
149
+ L: 166,
145
150
  S: this,
146
151
  C: (f, a) => f(...a)
147
152
  });
148
153
  this._changeState(ConnectionState.CONNECTING);
149
- this._protocol.open().catch((err) => {
154
+ this._protocol.open(this.sessionId).catch((err) => {
150
155
  this.errors.raise(err);
151
156
  });
152
157
  this._protocol.stream.on("close", () => {
153
158
  log("protocol stream closed", void 0, {
154
159
  F: __dxlog_file,
155
- L: 173,
160
+ L: 183,
156
161
  S: this,
157
162
  C: (f, a) => f(...a)
158
163
  });
159
164
  this.close(new ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
160
165
  });
161
166
  scheduleTask(this.connectedTimeoutContext, async () => {
162
- log.info("timeout waiting for transport to connect, aborting", void 0, {
167
+ log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
163
168
  F: __dxlog_file,
164
- L: 180,
169
+ L: 190,
165
170
  S: this,
166
171
  C: (f, a) => f(...a)
167
172
  });
168
- await this.abort().catch((err) => this.errors.raise(err));
173
+ await this.abort(new TimeoutError(`${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`)).catch((err) => this.errors.raise(err));
169
174
  }, TRANSPORT_CONNECTION_TIMEOUT);
170
175
  invariant(!this._transport, void 0, {
171
176
  F: __dxlog_file,
172
- L: 186,
177
+ L: 198,
173
178
  S: this,
174
179
  A: [
175
180
  "!this._transport",
@@ -179,18 +184,20 @@ var Connection = class {
179
184
  this._transport = this._transportFactory.createTransport({
180
185
  initiator: this.initiator,
181
186
  stream: this._protocol.stream,
182
- sendSignal: async (signal) => this._sendSignal(signal)
187
+ sendSignal: async (signal) => this._sendSignal(signal),
188
+ sessionId: this.sessionId
183
189
  });
184
190
  this._transport.connected.once(async () => {
185
191
  this._changeState(ConnectionState.CONNECTED);
186
192
  await this.connectedTimeoutContext.dispose();
187
193
  this._callbacks?.onConnected?.();
194
+ scheduleTaskInterval(this._ctx, async () => this._emitTransportStats(), TRANSPORT_STATS_INTERVAL);
188
195
  });
189
196
  this._transport.closed.once(() => {
190
197
  this._transport = void 0;
191
198
  log("abort triggered by transport close", void 0, {
192
199
  F: __dxlog_file,
193
- L: 201,
200
+ L: 216,
194
201
  S: this,
195
202
  C: (f, a) => f(...a)
196
203
  });
@@ -201,7 +208,7 @@ var Connection = class {
201
208
  err
202
209
  }, {
203
210
  F: __dxlog_file,
204
- L: 206,
211
+ L: 221,
205
212
  S: this,
206
213
  C: (f, a) => f(...a)
207
214
  });
@@ -211,7 +218,7 @@ var Connection = class {
211
218
  if (err instanceof ConnectionResetError) {
212
219
  log.info("aborting due to transport ConnectionResetError", void 0, {
213
220
  F: __dxlog_file,
214
- L: 213,
221
+ L: 228,
215
222
  S: this,
216
223
  C: (f, a) => f(...a)
217
224
  });
@@ -219,7 +226,7 @@ var Connection = class {
219
226
  } else if (err instanceof ConnectivityError) {
220
227
  log.info("aborting due to transport ConnectivityError", void 0, {
221
228
  F: __dxlog_file,
222
- L: 216,
229
+ L: 231,
223
230
  S: this,
224
231
  C: (f, a) => f(...a)
225
232
  });
@@ -229,7 +236,7 @@ var Connection = class {
229
236
  err
230
237
  }, {
231
238
  F: __dxlog_file,
232
- L: 219,
239
+ L: 234,
233
240
  S: this,
234
241
  C: (f, a) => f(...a)
235
242
  });
@@ -247,7 +254,7 @@ var Connection = class {
247
254
  id: this._instanceId
248
255
  }), {
249
256
  F: __dxlog_file,
250
- L: 235,
257
+ L: 250,
251
258
  S: this,
252
259
  C: (f, a) => f(...a)
253
260
  });
@@ -257,14 +264,14 @@ var Connection = class {
257
264
  err
258
265
  }, {
259
266
  F: __dxlog_file,
260
- L: 242,
267
+ L: 257,
261
268
  S: this,
262
269
  C: (f, a) => f(...a)
263
270
  });
264
271
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
265
272
  log(`abort ignored: already ${this._state}`, this.closeReason, {
266
273
  F: __dxlog_file,
267
- L: 244,
274
+ L: 259,
268
275
  S: this,
269
276
  C: (f, a) => f(...a)
270
277
  });
@@ -279,7 +286,7 @@ var Connection = class {
279
286
  try {
280
287
  log("aborting protocol... ", void 0, {
281
288
  F: __dxlog_file,
282
- L: 258,
289
+ L: 273,
283
290
  S: this,
284
291
  C: (f, a) => f(...a)
285
292
  });
@@ -287,7 +294,7 @@ var Connection = class {
287
294
  } catch (err2) {
288
295
  log.catch(err2, void 0, {
289
296
  F: __dxlog_file,
290
- L: 261,
297
+ L: 276,
291
298
  S: this,
292
299
  C: (f, a) => f(...a)
293
300
  });
@@ -297,7 +304,7 @@ var Connection = class {
297
304
  } catch (err2) {
298
305
  log.catch(err2, void 0, {
299
306
  F: __dxlog_file,
300
- L: 268,
307
+ L: 283,
301
308
  S: this,
302
309
  C: (f, a) => f(...a)
303
310
  });
@@ -307,7 +314,7 @@ var Connection = class {
307
314
  } catch (err2) {
308
315
  log.catch(err2, void 0, {
309
316
  F: __dxlog_file,
310
- L: 274,
317
+ L: 289,
311
318
  S: this,
312
319
  C: (f, a) => f(...a)
313
320
  });
@@ -331,7 +338,7 @@ var Connection = class {
331
338
  peerId: this.ownId
332
339
  }, {
333
340
  F: __dxlog_file,
334
- L: 299,
341
+ L: 314,
335
342
  S: this,
336
343
  C: (f, a) => f(...a)
337
344
  });
@@ -341,7 +348,7 @@ var Connection = class {
341
348
  } catch (err2) {
342
349
  log.catch(err2, void 0, {
343
350
  F: __dxlog_file,
344
- L: 306,
351
+ L: 321,
345
352
  S: this,
346
353
  C: (f, a) => f(...a)
347
354
  });
@@ -351,7 +358,34 @@ var Connection = class {
351
358
  } catch (err2) {
352
359
  log.catch(err2, void 0, {
353
360
  F: __dxlog_file,
354
- L: 313,
361
+ L: 328,
362
+ S: this,
363
+ C: (f, a) => f(...a)
364
+ });
365
+ }
366
+ } else {
367
+ log.info(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
368
+ F: __dxlog_file,
369
+ L: 331,
370
+ S: this,
371
+ C: (f, a) => f(...a)
372
+ });
373
+ try {
374
+ await this._protocol.abort();
375
+ } catch (err2) {
376
+ log.catch(err2, void 0, {
377
+ F: __dxlog_file,
378
+ L: 335,
379
+ S: this,
380
+ C: (f, a) => f(...a)
381
+ });
382
+ }
383
+ try {
384
+ await this._transport?.destroy();
385
+ } catch (err2) {
386
+ log.catch(err2, void 0, {
387
+ F: __dxlog_file,
388
+ L: 340,
355
389
  S: this,
356
390
  C: (f, a) => f(...a)
357
391
  });
@@ -361,7 +395,7 @@ var Connection = class {
361
395
  peerId: this.ownId
362
396
  }, {
363
397
  F: __dxlog_file,
364
- L: 317,
398
+ L: 344,
365
399
  S: this,
366
400
  C: (f, a) => f(...a)
367
401
  });
@@ -404,7 +438,7 @@ var Connection = class {
404
438
  err
405
439
  }, {
406
440
  F: __dxlog_file,
407
- L: 355,
441
+ L: 382,
408
442
  S: this,
409
443
  C: (f, a) => f(...a)
410
444
  });
@@ -417,7 +451,7 @@ var Connection = class {
417
451
  async signal(msg) {
418
452
  invariant(msg.sessionId, void 0, {
419
453
  F: __dxlog_file,
420
- L: 364,
454
+ L: 391,
421
455
  S: this,
422
456
  A: [
423
457
  "msg.sessionId",
@@ -427,7 +461,7 @@ var Connection = class {
427
461
  if (!msg.sessionId.equals(this.sessionId)) {
428
462
  log("dropping signal for incorrect session id", void 0, {
429
463
  F: __dxlog_file,
430
- L: 366,
464
+ L: 393,
431
465
  S: this,
432
466
  C: (f, a) => f(...a)
433
467
  });
@@ -435,7 +469,7 @@ var Connection = class {
435
469
  }
436
470
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
437
471
  F: __dxlog_file,
438
- L: 369,
472
+ L: 396,
439
473
  S: this,
440
474
  A: [
441
475
  "msg.data.signal || msg.data.signalBatch",
@@ -444,7 +478,7 @@ var Connection = class {
444
478
  });
445
479
  invariant(msg.author?.equals(this.remoteId), void 0, {
446
480
  F: __dxlog_file,
447
- L: 370,
481
+ L: 397,
448
482
  S: this,
449
483
  A: [
450
484
  "msg.author?.equals(this.remoteId)",
@@ -453,7 +487,7 @@ var Connection = class {
453
487
  });
454
488
  invariant(msg.recipient?.equals(this.ownId), void 0, {
455
489
  F: __dxlog_file,
456
- L: 371,
490
+ L: 398,
457
491
  S: this,
458
492
  A: [
459
493
  "msg.recipient?.equals(this.ownId)",
@@ -477,7 +511,7 @@ var Connection = class {
477
511
  msg: msg.data
478
512
  }, {
479
513
  F: __dxlog_file,
480
- L: 380,
514
+ L: 407,
481
515
  S: this,
482
516
  C: (f, a) => f(...a)
483
517
  });
@@ -485,7 +519,7 @@ var Connection = class {
485
519
  } else {
486
520
  invariant(this._transport, "Connection not ready to accept signals.", {
487
521
  F: __dxlog_file,
488
- L: 383,
522
+ L: 410,
489
523
  S: this,
490
524
  A: [
491
525
  "this._transport",
@@ -498,7 +532,7 @@ var Connection = class {
498
532
  msg: msg.data
499
533
  }, {
500
534
  F: __dxlog_file,
501
- L: 384,
535
+ L: 411,
502
536
  S: this,
503
537
  C: (f, a) => f(...a)
504
538
  });
@@ -516,13 +550,13 @@ var Connection = class {
516
550
  peerId: this.ownId
517
551
  }, {
518
552
  F: __dxlog_file,
519
- L: 395,
553
+ L: 422,
520
554
  S: this,
521
555
  C: (f, a) => f(...a)
522
556
  });
523
557
  invariant(state !== this._state, "Already in this state.", {
524
558
  F: __dxlog_file,
525
- L: 396,
559
+ L: 423,
526
560
  S: this,
527
561
  A: [
528
562
  "state !== this._state",
@@ -532,7 +566,16 @@ var Connection = class {
532
566
  this._state = state;
533
567
  this.stateChanged.emit(state);
534
568
  }
569
+ async _emitTransportStats() {
570
+ const stats = await this.transport?.getStats();
571
+ if (stats) {
572
+ this.transportStats.emit(stats);
573
+ }
574
+ }
535
575
  };
576
+ _ts_decorate([
577
+ logInfo
578
+ ], Connection.prototype, "sessionIdString", null);
536
579
  _ts_decorate([
537
580
  synchronized
538
581
  ], Connection.prototype, "abort", null);
@@ -545,7 +588,7 @@ import { Context as Context2 } from "@dxos/context";
545
588
  import { invariant as invariant2 } from "@dxos/invariant";
546
589
  import { PublicKey as PublicKey2 } from "@dxos/keys";
547
590
  import { log as log2 } from "@dxos/log";
548
- import { schema, TimeoutError } from "@dxos/protocols";
591
+ import { schema, TimeoutError as TimeoutError2 } from "@dxos/protocols";
549
592
  import { ComplexMap } from "@dxos/util";
550
593
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
551
594
  var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
@@ -730,7 +773,7 @@ var SwarmMessenger = class {
730
773
  }
731
774
  });
732
775
  } catch (err) {
733
- if (err instanceof TimeoutError) {
776
+ if (err instanceof TimeoutError2) {
734
777
  log2.info("timeout sending answer to offer", {
735
778
  err
736
779
  }, {
@@ -789,7 +832,7 @@ import { Context as Context4 } from "@dxos/context";
789
832
  import { ErrorStream as ErrorStream2 } from "@dxos/debug";
790
833
  import { invariant as invariant4 } from "@dxos/invariant";
791
834
  import { PublicKey as PublicKey4 } from "@dxos/keys";
792
- import { log as log4, logInfo } from "@dxos/log";
835
+ import { log as log4, logInfo as logInfo2 } from "@dxos/log";
793
836
  import { trace as trace2 } from "@dxos/protocols";
794
837
  import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
795
838
 
@@ -1753,13 +1796,13 @@ var Swarm = class {
1753
1796
  }
1754
1797
  };
1755
1798
  _ts_decorate3([
1756
- logInfo
1799
+ logInfo2
1757
1800
  ], Swarm.prototype, "_instanceId", void 0);
1758
1801
  _ts_decorate3([
1759
- logInfo
1802
+ logInfo2
1760
1803
  ], Swarm.prototype, "ownPeerId", null);
1761
1804
  _ts_decorate3([
1762
- logInfo
1805
+ logInfo2
1763
1806
  ], Swarm.prototype, "topic", null);
1764
1807
  _ts_decorate3([
1765
1808
  synchronized3
@@ -1976,7 +2019,7 @@ var ConnectionLog = class {
1976
2019
  };
1977
2020
  info.connections.push(connectionInfo);
1978
2021
  this.update.emit();
1979
- connection.stateChanged.on((state) => {
2022
+ connection.stateChanged.on(async (state) => {
1980
2023
  connectionInfo.state = state;
1981
2024
  connectionInfo.closeReason = connection.closeReason;
1982
2025
  connectionInfo.lastUpdate = /* @__PURE__ */ new Date();
@@ -1984,6 +2027,10 @@ var ConnectionLog = class {
1984
2027
  type: EventType.CONNECTION_STATE_CHANGED,
1985
2028
  newState: state
1986
2029
  });
2030
+ if (state === ConnectionState.CONNECTED) {
2031
+ const details = await connection.transport?.getDetails();
2032
+ connectionInfo.transportDetails = details;
2033
+ }
1987
2034
  this.update.emit();
1988
2035
  });
1989
2036
  connection.protocol?.stats?.on((stats) => {
@@ -1993,6 +2040,12 @@ var ConnectionLog = class {
1993
2040
  connectionInfo.lastUpdate = /* @__PURE__ */ new Date();
1994
2041
  this.update.emit();
1995
2042
  });
2043
+ connection.transportStats?.on((stats) => {
2044
+ connectionInfo.transportBytesSent = stats.bytesSent;
2045
+ connectionInfo.transportBytesReceived = stats.bytesReceived;
2046
+ connectionInfo.transportPacketsSent = stats.packetsSent;
2047
+ connectionInfo.transportPacketsReceived = stats.packetsReceived;
2048
+ });
1996
2049
  gcSwarm(info);
1997
2050
  });
1998
2051
  }
@@ -2296,9 +2349,12 @@ import distance from "xor-distance";
2296
2349
  import { invariant as invariant8 } from "@dxos/invariant";
2297
2350
  import { log as log8 } from "@dxos/log";
2298
2351
  var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2352
+ var MIN_UPDATE_INTERVAL = 1e3 * 10;
2353
+ var MAX_CHANGES_PER_UPDATE = 1;
2299
2354
  var MMSTTopology = class {
2300
2355
  constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2301
2356
  this._sampleCollected = false;
2357
+ this._lastAction = /* @__PURE__ */ new Date(0);
2302
2358
  this._originateConnections = originateConnections;
2303
2359
  this._maxPeers = maxPeers;
2304
2360
  this._sampleSize = sampleSize;
@@ -2306,7 +2362,7 @@ var MMSTTopology = class {
2306
2362
  init(controller) {
2307
2363
  invariant8(!this._controller, "Already initialized", {
2308
2364
  F: __dxlog_file9,
2309
- L: 46,
2365
+ L: 51,
2310
2366
  S: this,
2311
2367
  A: [
2312
2368
  "!this._controller",
@@ -2318,7 +2374,7 @@ var MMSTTopology = class {
2318
2374
  update() {
2319
2375
  invariant8(this._controller, "Not initialized", {
2320
2376
  F: __dxlog_file9,
2321
- L: 51,
2377
+ L: 56,
2322
2378
  S: this,
2323
2379
  A: [
2324
2380
  "this._controller",
@@ -2327,9 +2383,9 @@ var MMSTTopology = class {
2327
2383
  });
2328
2384
  const { connected, candidates } = this._controller.getState();
2329
2385
  if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
2330
- log8("Running the algorithm.", void 0, {
2386
+ log8.info("Running the algorithm.", void 0, {
2331
2387
  F: __dxlog_file9,
2332
- L: 55,
2388
+ L: 60,
2333
2389
  S: this,
2334
2390
  C: (f, a) => f(...a)
2335
2391
  });
@@ -2340,7 +2396,7 @@ var MMSTTopology = class {
2340
2396
  async onOffer(peer) {
2341
2397
  invariant8(this._controller, "Not initialized", {
2342
2398
  F: __dxlog_file9,
2343
- L: 62,
2399
+ L: 67,
2344
2400
  S: this,
2345
2401
  A: [
2346
2402
  "this._controller",
@@ -2351,7 +2407,7 @@ var MMSTTopology = class {
2351
2407
  const accept = connected.length < this._maxPeers;
2352
2408
  log8(`Offer ${peer} accept=${accept}`, void 0, {
2353
2409
  F: __dxlog_file9,
2354
- L: 65,
2410
+ L: 70,
2355
2411
  S: this,
2356
2412
  C: (f, a) => f(...a)
2357
2413
  });
@@ -2362,7 +2418,7 @@ var MMSTTopology = class {
2362
2418
  _runAlgorithm() {
2363
2419
  invariant8(this._controller, "Not initialized", {
2364
2420
  F: __dxlog_file9,
2365
- L: 74,
2421
+ L: 79,
2366
2422
  S: this,
2367
2423
  A: [
2368
2424
  "this._controller",
@@ -2371,27 +2427,84 @@ var MMSTTopology = class {
2371
2427
  });
2372
2428
  const { connected, candidates, ownPeerId } = this._controller.getState();
2373
2429
  if (connected.length > this._maxPeers) {
2430
+ log8.info(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
2431
+ F: __dxlog_file9,
2432
+ L: 85,
2433
+ S: this,
2434
+ C: (f, a) => f(...a)
2435
+ });
2374
2436
  const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
2375
- for (const peer of sorted) {
2376
- log8(`Disconnect ${peer}.`, void 0, {
2437
+ invariant8(sorted.length === 0, void 0, {
2438
+ F: __dxlog_file9,
2439
+ L: 89,
2440
+ S: this,
2441
+ A: [
2442
+ "sorted.length === 0",
2443
+ ""
2444
+ ]
2445
+ });
2446
+ if (sorted.length > MAX_CHANGES_PER_UPDATE) {
2447
+ log8(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
2377
2448
  F: __dxlog_file9,
2378
- L: 83,
2449
+ L: 92,
2450
+ S: this,
2451
+ C: (f, a) => f(...a)
2452
+ });
2453
+ }
2454
+ if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
2455
+ for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
2456
+ log8.info(`Disconnect ${peer}.`, void 0, {
2457
+ F: __dxlog_file9,
2458
+ L: 97,
2459
+ S: this,
2460
+ C: (f, a) => f(...a)
2461
+ });
2462
+ this._controller.disconnect(peer);
2463
+ }
2464
+ this._lastAction = /* @__PURE__ */ new Date();
2465
+ } else {
2466
+ log8.info("rate limited discconnect", void 0, {
2467
+ F: __dxlog_file9,
2468
+ L: 102,
2379
2469
  S: this,
2380
2470
  C: (f, a) => f(...a)
2381
2471
  });
2382
- this._controller.disconnect(peer);
2383
2472
  }
2384
2473
  } else if (connected.length < this._originateConnections) {
2474
+ log8.info(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
2475
+ F: __dxlog_file9,
2476
+ L: 106,
2477
+ S: this,
2478
+ C: (f, a) => f(...a)
2479
+ });
2385
2480
  const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
2386
2481
  const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
2387
- for (const peer of sorted) {
2388
- log8(`Connect ${peer}.`, void 0, {
2482
+ if (sorted.length > MAX_CHANGES_PER_UPDATE) {
2483
+ log8(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
2389
2484
  F: __dxlog_file9,
2390
- L: 91,
2485
+ L: 111,
2486
+ S: this,
2487
+ C: (f, a) => f(...a)
2488
+ });
2489
+ }
2490
+ if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
2491
+ for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
2492
+ log8.info(`Connect ${peer}.`, void 0, {
2493
+ F: __dxlog_file9,
2494
+ L: 115,
2495
+ S: this,
2496
+ C: (f, a) => f(...a)
2497
+ });
2498
+ this._controller.connect(peer);
2499
+ }
2500
+ this._lastAction = /* @__PURE__ */ new Date();
2501
+ } else {
2502
+ log8.info("rate limited connect", void 0, {
2503
+ F: __dxlog_file9,
2504
+ L: 120,
2391
2505
  S: this,
2392
2506
  C: (f, a) => f(...a)
2393
2507
  });
2394
- this._controller.connect(peer);
2395
2508
  }
2396
2509
  }
2397
2510
  }
@@ -2503,7 +2616,7 @@ import { Event as Event7, Trigger } from "@dxos/async";
2503
2616
  import { ErrorStream as ErrorStream3 } from "@dxos/debug";
2504
2617
  import { invariant as invariant10 } from "@dxos/invariant";
2505
2618
  import { PublicKey as PublicKey9 } from "@dxos/keys";
2506
- import { log as log10, logInfo as logInfo2 } from "@dxos/log";
2619
+ import { log as log10, logInfo as logInfo3 } from "@dxos/log";
2507
2620
  import { ComplexMap as ComplexMap7 } from "@dxos/util";
2508
2621
  function _ts_decorate4(decorators, target, key, desc) {
2509
2622
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -2678,12 +2791,23 @@ var MemoryTransport = class _MemoryTransport {
2678
2791
  this._remote.wake(remoteId);
2679
2792
  }
2680
2793
  }
2794
+ async getDetails() {
2795
+ return this._instanceId.toHex();
2796
+ }
2797
+ async getStats() {
2798
+ return {
2799
+ bytesSent: 0,
2800
+ bytesReceived: 0,
2801
+ packetsSent: 0,
2802
+ packetsReceived: 0
2803
+ };
2804
+ }
2681
2805
  };
2682
2806
  _ts_decorate4([
2683
- logInfo2
2807
+ logInfo3
2684
2808
  ], MemoryTransport.prototype, "_instanceId", void 0);
2685
2809
  _ts_decorate4([
2686
- logInfo2
2810
+ logInfo3
2687
2811
  ], MemoryTransport.prototype, "_remoteInstanceId", void 0);
2688
2812
 
2689
2813
  // packages/core/mesh/network-manager/src/transport/transport.ts
@@ -2715,6 +2839,9 @@ try {
2715
2839
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
2716
2840
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2717
2841
  var SimplePeerTransport = class {
2842
+ /**
2843
+ * @params opts.config formatted as per https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
2844
+ */
2718
2845
  constructor(params) {
2719
2846
  this.params = params;
2720
2847
  this._closed = false;
@@ -2727,13 +2854,13 @@ var SimplePeerTransport = class {
2727
2854
  id: this._instanceId
2728
2855
  }), {
2729
2856
  F: __dxlog_file12,
2730
- L: 41,
2857
+ L: 44,
2731
2858
  S: this,
2732
2859
  C: (f, a) => f(...a)
2733
2860
  });
2734
2861
  log11("created connection", params, {
2735
2862
  F: __dxlog_file12,
2736
- L: 42,
2863
+ L: 45,
2737
2864
  S: this,
2738
2865
  C: (f, a) => f(...a)
2739
2866
  });
@@ -2746,7 +2873,7 @@ var SimplePeerTransport = class {
2746
2873
  this._peer.on("signal", async (data) => {
2747
2874
  log11("signal", data, {
2748
2875
  F: __dxlog_file12,
2749
- L: 51,
2876
+ L: 54,
2750
2877
  S: this,
2751
2878
  C: (f, a) => f(...a)
2752
2879
  });
@@ -2759,7 +2886,7 @@ var SimplePeerTransport = class {
2759
2886
  this._peer.on("connect", () => {
2760
2887
  log11("connected", void 0, {
2761
2888
  F: __dxlog_file12,
2762
- L: 56,
2889
+ L: 59,
2763
2890
  S: this,
2764
2891
  C: (f, a) => f(...a)
2765
2892
  });
@@ -2770,7 +2897,7 @@ var SimplePeerTransport = class {
2770
2897
  this._peer.on("close", async () => {
2771
2898
  log11("closed", void 0, {
2772
2899
  F: __dxlog_file12,
2773
- L: 63,
2900
+ L: 66,
2774
2901
  S: this,
2775
2902
  C: (f, a) => f(...a)
2776
2903
  });
@@ -2781,12 +2908,20 @@ var SimplePeerTransport = class {
2781
2908
  if (err.errorDetail === "sctp-failure") {
2782
2909
  this.errors.raise(new ConnectionResetError2("sctp-failure from RTCError", err));
2783
2910
  } else {
2911
+ log11.info("unknown RTCError", {
2912
+ err
2913
+ }, {
2914
+ F: __dxlog_file12,
2915
+ L: 77,
2916
+ S: this,
2917
+ C: (f, a) => f(...a)
2918
+ });
2784
2919
  this.errors.raise(new UnknownProtocolError2("unknown RTCError", err));
2785
2920
  }
2786
2921
  } else if ("code" in err) {
2787
2922
  log11.info("simple-peer error", err, {
2788
2923
  F: __dxlog_file12,
2789
- L: 78,
2924
+ L: 82,
2790
2925
  S: this,
2791
2926
  C: (f, a) => f(...a)
2792
2927
  });
@@ -2794,10 +2929,12 @@ var SimplePeerTransport = class {
2794
2929
  case "ERR_WEBRTC_SUPPORT":
2795
2930
  this.errors.raise(new ProtocolError2("WebRTC not supported", err));
2796
2931
  break;
2932
+ case "ERR_SIGNALING":
2933
+ this.errors.raise(new ConnectivityError2("signaling failure", err));
2934
+ break;
2797
2935
  case "ERR_ICE_CONNECTION_FAILURE":
2798
2936
  case "ERR_DATA_CHANNEL":
2799
2937
  case "ERR_CONNECTION_FAILURE":
2800
- case "ERR_SIGNALING":
2801
2938
  this.errors.raise(new ConnectivityError2("unknown communication failure", err));
2802
2939
  break;
2803
2940
  case "ERR_CREATE_OFFER":
@@ -2814,7 +2951,7 @@ var SimplePeerTransport = class {
2814
2951
  } else {
2815
2952
  log11.info("unknown peer connection error", err, {
2816
2953
  F: __dxlog_file12,
2817
- L: 102,
2954
+ L: 108,
2818
2955
  S: this,
2819
2956
  C: (f, a) => f(...a)
2820
2957
  });
@@ -2825,10 +2962,10 @@ var SimplePeerTransport = class {
2825
2962
  this._peer._pc.getStats().then((stats) => {
2826
2963
  log11.info("report after webrtc error", {
2827
2964
  config: this.params.webrtcConfig,
2828
- stats
2965
+ stats: Object.fromEntries(stats.entries())
2829
2966
  }, {
2830
2967
  F: __dxlog_file12,
2831
- L: 110,
2968
+ L: 116,
2832
2969
  S: this,
2833
2970
  C: (f, a) => f(...a)
2834
2971
  });
@@ -2837,7 +2974,7 @@ var SimplePeerTransport = class {
2837
2974
  } catch (err2) {
2838
2975
  log11.catch(err2, void 0, {
2839
2976
  F: __dxlog_file12,
2840
- L: 117,
2977
+ L: 123,
2841
2978
  S: this,
2842
2979
  C: (f, a) => f(...a)
2843
2980
  });
@@ -2848,15 +2985,68 @@ var SimplePeerTransport = class {
2848
2985
  id: this._instanceId
2849
2986
  }), {
2850
2987
  F: __dxlog_file12,
2851
- L: 122,
2988
+ L: 129,
2852
2989
  S: this,
2853
2990
  C: (f, a) => f(...a)
2854
2991
  });
2855
2992
  }
2993
+ async getStats() {
2994
+ const stats = await this._getStats();
2995
+ if (!stats) {
2996
+ return {
2997
+ bytesSent: 0,
2998
+ bytesReceived: 0,
2999
+ packetsSent: 0,
3000
+ packetsReceived: 0,
3001
+ rawStats: {}
3002
+ };
3003
+ }
3004
+ return {
3005
+ bytesSent: stats.transport.bytesSent,
3006
+ bytesReceived: stats.transport.bytesReceived,
3007
+ packetsSent: stats.transport.messagesSent,
3008
+ packetsReceived: stats.transport.messagesReceived,
3009
+ rawStats: stats.raw
3010
+ };
3011
+ }
3012
+ async _getStats() {
3013
+ if (typeof this._peer?._pc?.getStats !== "function") {
3014
+ return null;
3015
+ }
3016
+ return await this._peer._pc.getStats().then((stats) => {
3017
+ const statsEntries = Array.from(stats.entries());
3018
+ const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
3019
+ const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
3020
+ let selectedCandidatePair;
3021
+ let remoteCandidate;
3022
+ if (candidatePair.length > 0) {
3023
+ selectedCandidatePair = candidatePair[0][1];
3024
+ remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
3025
+ }
3026
+ return {
3027
+ datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
3028
+ transport,
3029
+ selectedCandidatePair,
3030
+ remoteCandidate,
3031
+ raw: Object.fromEntries(stats.entries())
3032
+ };
3033
+ });
3034
+ }
3035
+ async getDetails() {
3036
+ const stats = await this._getStats();
3037
+ const rc = stats?.remoteCandidate;
3038
+ if (!rc) {
3039
+ return "unavailable";
3040
+ }
3041
+ if (rc.relay) {
3042
+ return `${rc.ip}:${rc.port}/${rc.protocol} relay for XXX ${rc.candidateType}`;
3043
+ }
3044
+ return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
3045
+ }
2856
3046
  async destroy() {
2857
3047
  log11("closing...", void 0, {
2858
3048
  F: __dxlog_file12,
2859
- L: 126,
3049
+ L: 192,
2860
3050
  S: this,
2861
3051
  C: (f, a) => f(...a)
2862
3052
  });
@@ -2866,10 +3056,11 @@ var SimplePeerTransport = class {
2866
3056
  this._closed = true;
2867
3057
  this._disconnectStreams();
2868
3058
  this._peer.destroy();
3059
+ this._closed = true;
2869
3060
  this.closed.emit();
2870
3061
  log11("closed", void 0, {
2871
3062
  F: __dxlog_file12,
2872
- L: 134,
3063
+ L: 201,
2873
3064
  S: this,
2874
3065
  C: (f, a) => f(...a)
2875
3066
  });
@@ -2984,7 +3175,7 @@ var SimplePeerTransportService = class {
2984
3175
  async sendSignal({ proxyId, signal }) {
2985
3176
  invariant12(this.transports.has(proxyId), void 0, {
2986
3177
  F: __dxlog_file13,
2987
- L: 112,
3178
+ L: 116,
2988
3179
  S: this,
2989
3180
  A: [
2990
3181
  "this.transports.has(proxyId)",
@@ -2993,18 +3184,46 @@ var SimplePeerTransportService = class {
2993
3184
  });
2994
3185
  await this.transports.get(proxyId).transport.signal(signal);
2995
3186
  }
3187
+ async getDetails({ proxyId }) {
3188
+ invariant12(this.transports.has(proxyId), void 0, {
3189
+ F: __dxlog_file13,
3190
+ L: 121,
3191
+ S: this,
3192
+ A: [
3193
+ "this.transports.has(proxyId)",
3194
+ ""
3195
+ ]
3196
+ });
3197
+ return {
3198
+ details: await this.transports.get(proxyId).transport.getDetails()
3199
+ };
3200
+ }
3201
+ async getStats({ proxyId }) {
3202
+ invariant12(this.transports.has(proxyId), void 0, {
3203
+ F: __dxlog_file13,
3204
+ L: 126,
3205
+ S: this,
3206
+ A: [
3207
+ "this.transports.has(proxyId)",
3208
+ ""
3209
+ ]
3210
+ });
3211
+ return {
3212
+ stats: await this.transports.get(proxyId).transport.getStats()
3213
+ };
3214
+ }
2996
3215
  async sendData({ proxyId, payload }) {
2997
3216
  if (this.transports.get(proxyId)?.state !== "OPEN") {
2998
3217
  log12.debug("transport is closed", void 0, {
2999
3218
  F: __dxlog_file13,
3000
- L: 118,
3219
+ L: 132,
3001
3220
  S: this,
3002
3221
  C: (f, a) => f(...a)
3003
3222
  });
3004
3223
  }
3005
3224
  invariant12(this.transports.has(proxyId), void 0, {
3006
3225
  F: __dxlog_file13,
3007
- L: 120,
3226
+ L: 134,
3008
3227
  S: this,
3009
3228
  A: [
3010
3229
  "this.transports.has(proxyId)",
@@ -3027,7 +3246,7 @@ var SimplePeerTransportService = class {
3027
3246
  }
3028
3247
  log12("Closed.", void 0, {
3029
3248
  F: __dxlog_file13,
3030
- L: 136,
3249
+ L: 150,
3031
3250
  S: this,
3032
3251
  C: (f, a) => f(...a)
3033
3252
  });
@@ -3042,7 +3261,7 @@ import { ErrorStream as ErrorStream5 } from "@dxos/debug";
3042
3261
  import { invariant as invariant13 } from "@dxos/invariant";
3043
3262
  import { PublicKey as PublicKey12 } from "@dxos/keys";
3044
3263
  import { log as log13 } from "@dxos/log";
3045
- import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError2, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
3264
+ import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError3, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
3046
3265
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
3047
3266
  import { arrayToBuffer } from "@dxos/util";
3048
3267
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
@@ -3098,9 +3317,9 @@ var SimplePeerTransportProxy = class {
3098
3317
  }
3099
3318
  this._timeoutCount = 0;
3100
3319
  }, (err) => {
3101
- if (err instanceof TimeoutError2 || err.constructor.name === "TimeoutError") {
3320
+ if (err instanceof TimeoutError3 || err.constructor.name === "TimeoutError") {
3102
3321
  if (this._timeoutCount++ > TIMEOUT_THRESHOLD) {
3103
- throw new TimeoutError2(`too many timeoutes (${this._timeoutCount} > ${TIMEOUT_THRESHOLD}`);
3322
+ throw new TimeoutError3(`too many timeoutes (${this._timeoutCount} > ${TIMEOUT_THRESHOLD}`);
3104
3323
  } else {
3105
3324
  log13("timeout error, but still invoking callback", void 0, {
3106
3325
  F: __dxlog_file14,
@@ -3166,6 +3385,16 @@ var SimplePeerTransportProxy = class {
3166
3385
  signal
3167
3386
  }).catch((err) => this.errors.raise(decodeError(err)));
3168
3387
  }
3388
+ async getDetails() {
3389
+ return (await this._params.bridgeService.getDetails({
3390
+ proxyId: this._proxyId
3391
+ })).details;
3392
+ }
3393
+ async getStats() {
3394
+ return (await this._params.bridgeService.getStats({
3395
+ proxyId: this._proxyId
3396
+ })).stats;
3397
+ }
3169
3398
  // TODO(burdon): Move open from constructor.
3170
3399
  async destroy() {
3171
3400
  await this._ctx.dispose();
@@ -3180,7 +3409,7 @@ var SimplePeerTransportProxy = class {
3180
3409
  } catch (err) {
3181
3410
  log13.catch(err, void 0, {
3182
3411
  F: __dxlog_file14,
3183
- L: 160,
3412
+ L: 168,
3184
3413
  S: this,
3185
3414
  C: (f, a) => f(...a)
3186
3415
  });
@@ -3216,7 +3445,7 @@ var SimplePeerTransportProxyFactory = class {
3216
3445
  createTransport(options) {
3217
3446
  invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3218
3447
  F: __dxlog_file14,
3219
- L: 197,
3448
+ L: 205,
3220
3449
  S: this,
3221
3450
  A: [
3222
3451
  "this._bridgeService",
@@ -3237,7 +3466,7 @@ var decodeError = (err) => {
3237
3466
  if (message.includes("CONNECTION_RESET")) {
3238
3467
  return new ConnectionResetError3(message);
3239
3468
  } else if (message.includes("TIMEOUT")) {
3240
- return new TimeoutError2(message);
3469
+ return new TimeoutError3(message);
3241
3470
  } else if (message.includes("PROTOCOL_ERROR")) {
3242
3471
  return new ProtocolError3(message);
3243
3472
  } else if (message.includes("CONNECTIVITY_ERROR")) {
@@ -3417,16 +3646,21 @@ var LibDataChannelTransport = class {
3417
3646
  const duplex = new Duplex2({
3418
3647
  read: () => {
3419
3648
  },
3420
- write: (chunk, encoding, callback) => {
3649
+ write: async (chunk, encoding, callback) => {
3421
3650
  if (chunk.length > MAX_MESSAGE_SIZE) {
3422
3651
  this.errors.raise(new Error(`message too large: ${chunk.length} > ${MAX_MESSAGE_SIZE}`));
3423
3652
  }
3424
- dataChannel.send(chunk);
3653
+ try {
3654
+ dataChannel.send(chunk);
3655
+ } catch (err) {
3656
+ this.errors.raise(err);
3657
+ await this._close();
3658
+ }
3425
3659
  if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
3426
3660
  if (this._writeCallback !== null) {
3427
3661
  log14.error("consumer trying to write before we're ready for more data", void 0, {
3428
3662
  F: __dxlog_file15,
3429
- L: 139,
3663
+ L: 143,
3430
3664
  S: this,
3431
3665
  C: (f, a) => f(...a)
3432
3666
  });
@@ -3451,7 +3685,7 @@ var LibDataChannelTransport = class {
3451
3685
  err
3452
3686
  }, {
3453
3687
  F: __dxlog_file15,
3454
- L: 159,
3688
+ L: 163,
3455
3689
  S: this,
3456
3690
  C: (f, a) => f(...a)
3457
3691
  });
@@ -3488,7 +3722,7 @@ var LibDataChannelTransport = class {
3488
3722
  peer
3489
3723
  }, {
3490
3724
  F: __dxlog_file15,
3491
- L: 194,
3725
+ L: 198,
3492
3726
  S: this,
3493
3727
  C: (f, a) => f(...a)
3494
3728
  });
@@ -3516,7 +3750,7 @@ var LibDataChannelTransport = class {
3516
3750
  err
3517
3751
  }, {
3518
3752
  F: __dxlog_file15,
3519
- L: 205,
3753
+ L: 209,
3520
3754
  S: this,
3521
3755
  C: (f, a) => f(...a)
3522
3756
  });
@@ -3536,7 +3770,7 @@ var LibDataChannelTransport = class {
3536
3770
  err
3537
3771
  }, {
3538
3772
  F: __dxlog_file15,
3539
- L: 216,
3773
+ L: 220,
3540
3774
  S: this,
3541
3775
  C: (f, a) => f(...a)
3542
3776
  });
@@ -3555,7 +3789,7 @@ var LibDataChannelTransport = class {
3555
3789
  signal
3556
3790
  }, {
3557
3791
  F: __dxlog_file15,
3558
- L: 227,
3792
+ L: 231,
3559
3793
  S: this,
3560
3794
  C: (f, a) => f(...a)
3561
3795
  });
@@ -3564,12 +3798,52 @@ var LibDataChannelTransport = class {
3564
3798
  }).catch((err) => {
3565
3799
  log14.catch(err, void 0, {
3566
3800
  F: __dxlog_file15,
3567
- L: 232,
3801
+ L: 236,
3568
3802
  S: this,
3569
3803
  C: (f, a) => f(...a)
3570
3804
  });
3571
3805
  });
3572
3806
  }
3807
+ async getDetails() {
3808
+ return this._peer.then(async (peer) => {
3809
+ const cp = await peer.getSelectedCandidatePair();
3810
+ if (!cp) {
3811
+ return "unavailable";
3812
+ }
3813
+ return `${cp.remote.address}:${cp.remote.port}/${cp.remote.transportType} ${cp.remote.type}`;
3814
+ }).catch((err) => {
3815
+ log14.catch(err, void 0, {
3816
+ F: __dxlog_file15,
3817
+ L: 250,
3818
+ S: this,
3819
+ C: (f, a) => f(...a)
3820
+ });
3821
+ return "unavailable";
3822
+ });
3823
+ }
3824
+ async getStats() {
3825
+ return this._peer.then((peer) => {
3826
+ return {
3827
+ bytesSent: peer.bytesSent(),
3828
+ bytesReceived: peer.bytesReceived(),
3829
+ packetsSent: 0,
3830
+ packetsReceived: 0
3831
+ };
3832
+ }).catch((err) => {
3833
+ log14.catch(err, void 0, {
3834
+ F: __dxlog_file15,
3835
+ L: 266,
3836
+ S: this,
3837
+ C: (f, a) => f(...a)
3838
+ });
3839
+ return {
3840
+ bytesSent: 0,
3841
+ bytesReceived: 0,
3842
+ packetsSent: 0,
3843
+ packetsReceived: 0
3844
+ };
3845
+ });
3846
+ }
3573
3847
  // TODO(nf): add classmethod to call node-datachannel.cleanup() when all instances have been destroyed?
3574
3848
  async destroy() {
3575
3849
  await this._close();
@@ -3606,6 +3880,12 @@ var TcpTransport = class {
3606
3880
  signal() {
3607
3881
  throw new Error("Method not implemented.");
3608
3882
  }
3883
+ async getStats() {
3884
+ throw new Error("Method not implemented.");
3885
+ }
3886
+ async getDetails() {
3887
+ throw new Error("Method not implemented.");
3888
+ }
3609
3889
  };
3610
3890
 
3611
3891
  // packages/core/mesh/network-manager/src/wire-protocol.ts
@@ -3615,8 +3895,8 @@ var createTeleportProtocolFactory = (onConnection) => {
3615
3895
  const teleport = new Teleport(params);
3616
3896
  return {
3617
3897
  stream: teleport.stream,
3618
- open: async () => {
3619
- await teleport.open();
3898
+ open: async (sessionId) => {
3899
+ await teleport.open(sessionId);
3620
3900
  await onConnection(teleport);
3621
3901
  },
3622
3902
  close: async () => {
@@ -3657,4 +3937,4 @@ export {
3657
3937
  TcpTransport,
3658
3938
  createTeleportProtocolFactory
3659
3939
  };
3660
- //# sourceMappingURL=chunk-LA2ACGLR.mjs.map
3940
+ //# sourceMappingURL=chunk-J7KS7JMZ.mjs.map