@dxos/network-manager 0.3.8 → 0.3.9-main.14901ff

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 (54) hide show
  1. package/dist/lib/browser/{chunk-H7XJ7HES.mjs → chunk-S2JHWVGQ.mjs} +325 -98
  2. package/dist/lib/browser/chunk-S2JHWVGQ.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 +3 -3
  6. package/dist/lib/node/{chunk-RBHZCZH4.cjs → chunk-3SCPMSHV.cjs} +328 -91
  7. package/dist/lib/node/chunk-3SCPMSHV.cjs.map +7 -0
  8. package/dist/lib/node/{chunk-XE5JOIGD.cjs → chunk-DMWORJG3.cjs} +13 -4
  9. package/dist/lib/node/chunk-DMWORJG3.cjs.map +7 -0
  10. package/dist/lib/node/{datachannel-53JZPGFA.cjs → datachannel-ABYQKZRC.cjs} +9 -9
  11. package/dist/lib/node/{datachannel-53JZPGFA.cjs.map → datachannel-ABYQKZRC.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 +21 -21
  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/transport/datachannel/rtc-peer-connection.d.ts +7 -0
  20. package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts.map +1 -1
  21. package/dist/types/src/transport/libdatachannel-transport.d.ts +3 -1
  22. package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
  23. package/dist/types/src/transport/memory-transport.d.ts +3 -1
  24. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  25. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts +3 -1
  26. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
  27. package/dist/types/src/transport/simplepeer-transport-service.d.ts +3 -1
  28. package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
  29. package/dist/types/src/transport/simplepeer-transport.d.ts +4 -1
  30. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  31. package/dist/types/src/transport/tcp-transport.browser.d.ts +3 -1
  32. package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -1
  33. package/dist/types/src/transport/tcp-transport.d.ts +3 -1
  34. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -1
  35. package/dist/types/src/transport/transport.d.ts +17 -0
  36. package/dist/types/src/transport/transport.d.ts.map +1 -1
  37. package/dist/types/src/wire-protocol.d.ts +1 -1
  38. package/dist/types/src/wire-protocol.d.ts.map +1 -1
  39. package/package.json +17 -17
  40. package/src/connection-log.ts +27 -1
  41. package/src/swarm/connection.ts +40 -6
  42. package/src/transport/datachannel/rtc-peer-connection.ts +13 -1
  43. package/src/transport/libdatachannel-transport.ts +44 -4
  44. package/src/transport/memory-transport.ts +14 -1
  45. package/src/transport/simplepeer-transport-proxy.ts +9 -1
  46. package/src/transport/simplepeer-transport-service.ts +14 -0
  47. package/src/transport/simplepeer-transport.ts +67 -3
  48. package/src/transport/tcp-transport.browser.ts +9 -1
  49. package/src/transport/tcp-transport.ts +19 -1
  50. package/src/transport/transport.ts +19 -0
  51. package/src/wire-protocol.ts +3 -3
  52. package/dist/lib/browser/chunk-H7XJ7HES.mjs.map +0 -7
  53. package/dist/lib/node/chunk-RBHZCZH4.cjs.map +0 -7
  54. 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")
@@ -21,9 +21,10 @@ function _ts_decorate(decorators, target, key, desc) {
21
21
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
23
23
  }
24
- var __dxlog_file = "/home/circleci/project/packages/core/mesh/network-manager/src/swarm/connection.ts";
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,9 +588,9 @@ 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
- var __dxlog_file2 = "/home/circleci/project/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
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");
552
595
  var SwarmMessenger = class {
553
596
  constructor({ sendMessage, onSignal, onOffer, topic }) {
@@ -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
 
@@ -810,7 +853,7 @@ function _ts_decorate2(decorators, target, key, desc) {
810
853
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
811
854
  return c > 3 && r && Object.defineProperty(target, key, r), r;
812
855
  }
813
- var __dxlog_file3 = "/home/circleci/project/packages/core/mesh/network-manager/src/swarm/peer.ts";
856
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
814
857
  var ConnectionDisplacedError = class extends SystemError {
815
858
  constructor() {
816
859
  super("Connection displaced by remote initiator.");
@@ -1288,7 +1331,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1288
1331
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1289
1332
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1290
1333
  }
1291
- var __dxlog_file4 = "/home/circleci/project/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1334
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1292
1335
  var INITIATION_DELAY = 100;
1293
1336
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1294
1337
  var Swarm = class {
@@ -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
@@ -1779,7 +1822,7 @@ import { Event as Event4, EventSubscriptions } from "@dxos/async";
1779
1822
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1780
1823
  import { log as log5 } from "@dxos/log";
1781
1824
  import { ComplexMap as ComplexMap3 } from "@dxos/util";
1782
- var __dxlog_file5 = "/home/circleci/project/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1825
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1783
1826
  var SwarmMapper = class {
1784
1827
  get peers() {
1785
1828
  return Array.from(this._peers.values());
@@ -1851,7 +1894,7 @@ import { PublicKey as PublicKey6 } from "@dxos/keys";
1851
1894
  import { log as log6 } from "@dxos/log";
1852
1895
  import { CancelledError as CancelledError3 } from "@dxos/protocols";
1853
1896
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
1854
- var __dxlog_file6 = "/home/circleci/project/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1897
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1855
1898
  var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
1856
1899
  var ConnectionLimiter = class {
1857
1900
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
@@ -1930,6 +1973,7 @@ import { Event as Event5 } from "@dxos/async";
1930
1973
  import { raise } from "@dxos/debug";
1931
1974
  import { PublicKey as PublicKey7 } from "@dxos/keys";
1932
1975
  import { ComplexMap as ComplexMap5 } from "@dxos/util";
1976
+ var CONNECTION_GC_THRESHOLD = 1e3 * 60 * 15;
1933
1977
  var EventType;
1934
1978
  (function(EventType2) {
1935
1979
  EventType2["CONNECTION_STATE_CHANGED"] = "CONNECTION_STATE_CHANGED";
@@ -1970,25 +2014,39 @@ var ConnectionLog = class {
1970
2014
  sessionId: connection.sessionId,
1971
2015
  transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
1972
2016
  protocolExtensions: [],
1973
- events: []
2017
+ events: [],
2018
+ lastUpdate: /* @__PURE__ */ new Date()
1974
2019
  };
1975
2020
  info.connections.push(connectionInfo);
1976
2021
  this.update.emit();
1977
- connection.stateChanged.on((state) => {
2022
+ connection.stateChanged.on(async (state) => {
1978
2023
  connectionInfo.state = state;
1979
2024
  connectionInfo.closeReason = connection.closeReason;
2025
+ connectionInfo.lastUpdate = /* @__PURE__ */ new Date();
1980
2026
  connectionInfo.events.push({
1981
2027
  type: EventType.CONNECTION_STATE_CHANGED,
1982
2028
  newState: state
1983
2029
  });
2030
+ if (state === ConnectionState.CONNECTED) {
2031
+ const details = await connection.transport?.getDetails();
2032
+ connectionInfo.transportDetails = details;
2033
+ }
1984
2034
  this.update.emit();
1985
2035
  });
1986
2036
  connection.protocol?.stats?.on((stats) => {
1987
2037
  connectionInfo.readBufferSize = stats.readBufferSize;
1988
2038
  connectionInfo.writeBufferSize = stats.writeBufferSize;
1989
2039
  connectionInfo.streams = stats.channels;
2040
+ connectionInfo.lastUpdate = /* @__PURE__ */ new Date();
1990
2041
  this.update.emit();
1991
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
+ });
2049
+ gcSwarm(info);
1992
2050
  });
1993
2051
  }
1994
2052
  leftSwarm(swarm) {
@@ -1996,6 +2054,11 @@ var ConnectionLog = class {
1996
2054
  this.update.emit();
1997
2055
  }
1998
2056
  };
2057
+ var gcSwarm = (swarm) => {
2058
+ swarm.connections = swarm.connections?.filter((connection) => {
2059
+ return connection.lastUpdate ? Date.now() - connection.lastUpdate.getTime() < CONNECTION_GC_THRESHOLD : true;
2060
+ });
2061
+ };
1999
2062
 
2000
2063
  // packages/core/mesh/network-manager/src/network-manager.ts
2001
2064
  import { Event as Event6 } from "@dxos/async";
@@ -2006,7 +2069,7 @@ import { Messenger } from "@dxos/messaging";
2006
2069
  import { trace as trace3 } from "@dxos/protocols";
2007
2070
  import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
2008
2071
  import { ComplexMap as ComplexMap6 } from "@dxos/util";
2009
- var __dxlog_file7 = "/home/circleci/project/packages/core/mesh/network-manager/src/network-manager.ts";
2072
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2010
2073
  var NetworkManager = class {
2011
2074
  constructor({ transportFactory, signalManager, log: log1 }) {
2012
2075
  /**
@@ -2242,7 +2305,7 @@ var NetworkManager = class {
2242
2305
 
2243
2306
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2244
2307
  import { invariant as invariant7 } from "@dxos/invariant";
2245
- var __dxlog_file8 = "/home/circleci/project/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2308
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2246
2309
  var FullyConnectedTopology = class {
2247
2310
  toString() {
2248
2311
  return "FullyConnectedTopology";
@@ -2285,7 +2348,7 @@ var FullyConnectedTopology = class {
2285
2348
  import distance from "xor-distance";
2286
2349
  import { invariant as invariant8 } from "@dxos/invariant";
2287
2350
  import { log as log8 } from "@dxos/log";
2288
- var __dxlog_file9 = "/home/circleci/project/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2351
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2289
2352
  var MMSTTopology = class {
2290
2353
  constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2291
2354
  this._sampleCollected = false;
@@ -2394,7 +2457,7 @@ var sortByXorDistance = (keys, reference) => keys.sort((a, b) => distance.gt(dis
2394
2457
  // packages/core/mesh/network-manager/src/topology/star-topology.ts
2395
2458
  import { invariant as invariant9 } from "@dxos/invariant";
2396
2459
  import { log as log9 } from "@dxos/log";
2397
- var __dxlog_file10 = "/home/circleci/project/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2460
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2398
2461
  var StarTopology = class {
2399
2462
  constructor(_centralPeer) {
2400
2463
  this._centralPeer = _centralPeer;
@@ -2493,7 +2556,7 @@ import { Event as Event7, Trigger } from "@dxos/async";
2493
2556
  import { ErrorStream as ErrorStream3 } from "@dxos/debug";
2494
2557
  import { invariant as invariant10 } from "@dxos/invariant";
2495
2558
  import { PublicKey as PublicKey9 } from "@dxos/keys";
2496
- import { log as log10, logInfo as logInfo2 } from "@dxos/log";
2559
+ import { log as log10, logInfo as logInfo3 } from "@dxos/log";
2497
2560
  import { ComplexMap as ComplexMap7 } from "@dxos/util";
2498
2561
  function _ts_decorate4(decorators, target, key, desc) {
2499
2562
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -2505,7 +2568,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2505
2568
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2506
2569
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2507
2570
  }
2508
- var __dxlog_file11 = "/home/circleci/project/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2571
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2509
2572
  var MEMORY_TRANSPORT_DELAY = 1;
2510
2573
  var createStreamDelay = (delay) => {
2511
2574
  return new Transform({
@@ -2668,12 +2731,23 @@ var MemoryTransport = class _MemoryTransport {
2668
2731
  this._remote.wake(remoteId);
2669
2732
  }
2670
2733
  }
2734
+ async getDetails() {
2735
+ return this._instanceId.toHex();
2736
+ }
2737
+ async getStats() {
2738
+ return {
2739
+ bytesSent: 0,
2740
+ bytesReceived: 0,
2741
+ packetsSent: 0,
2742
+ packetsReceived: 0
2743
+ };
2744
+ }
2671
2745
  };
2672
2746
  _ts_decorate4([
2673
- logInfo2
2747
+ logInfo3
2674
2748
  ], MemoryTransport.prototype, "_instanceId", void 0);
2675
2749
  _ts_decorate4([
2676
- logInfo2
2750
+ logInfo3
2677
2751
  ], MemoryTransport.prototype, "_remoteInstanceId", void 0);
2678
2752
 
2679
2753
  // packages/core/mesh/network-manager/src/transport/transport.ts
@@ -2703,7 +2777,7 @@ try {
2703
2777
  }
2704
2778
 
2705
2779
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
2706
- var __dxlog_file12 = "/home/circleci/project/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2780
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2707
2781
  var SimplePeerTransport = class {
2708
2782
  constructor(params) {
2709
2783
  this.params = params;
@@ -2771,12 +2845,20 @@ var SimplePeerTransport = class {
2771
2845
  if (err.errorDetail === "sctp-failure") {
2772
2846
  this.errors.raise(new ConnectionResetError2("sctp-failure from RTCError", err));
2773
2847
  } else {
2848
+ log11.info("unknown RTCError", {
2849
+ err
2850
+ }, {
2851
+ F: __dxlog_file12,
2852
+ L: 74,
2853
+ S: this,
2854
+ C: (f, a) => f(...a)
2855
+ });
2774
2856
  this.errors.raise(new UnknownProtocolError2("unknown RTCError", err));
2775
2857
  }
2776
2858
  } else if ("code" in err) {
2777
2859
  log11.info("simple-peer error", err, {
2778
2860
  F: __dxlog_file12,
2779
- L: 78,
2861
+ L: 79,
2780
2862
  S: this,
2781
2863
  C: (f, a) => f(...a)
2782
2864
  });
@@ -2784,10 +2866,12 @@ var SimplePeerTransport = class {
2784
2866
  case "ERR_WEBRTC_SUPPORT":
2785
2867
  this.errors.raise(new ProtocolError2("WebRTC not supported", err));
2786
2868
  break;
2869
+ case "ERR_SIGNALING":
2870
+ this.errors.raise(new ConnectivityError2("signaling failure", err));
2871
+ break;
2787
2872
  case "ERR_ICE_CONNECTION_FAILURE":
2788
2873
  case "ERR_DATA_CHANNEL":
2789
2874
  case "ERR_CONNECTION_FAILURE":
2790
- case "ERR_SIGNALING":
2791
2875
  this.errors.raise(new ConnectivityError2("unknown communication failure", err));
2792
2876
  break;
2793
2877
  case "ERR_CREATE_OFFER":
@@ -2804,7 +2888,7 @@ var SimplePeerTransport = class {
2804
2888
  } else {
2805
2889
  log11.info("unknown peer connection error", err, {
2806
2890
  F: __dxlog_file12,
2807
- L: 102,
2891
+ L: 105,
2808
2892
  S: this,
2809
2893
  C: (f, a) => f(...a)
2810
2894
  });
@@ -2815,10 +2899,10 @@ var SimplePeerTransport = class {
2815
2899
  this._peer._pc.getStats().then((stats) => {
2816
2900
  log11.info("report after webrtc error", {
2817
2901
  config: this.params.webrtcConfig,
2818
- stats
2902
+ stats: Object.fromEntries(stats.entries())
2819
2903
  }, {
2820
2904
  F: __dxlog_file12,
2821
- L: 110,
2905
+ L: 113,
2822
2906
  S: this,
2823
2907
  C: (f, a) => f(...a)
2824
2908
  });
@@ -2827,7 +2911,7 @@ var SimplePeerTransport = class {
2827
2911
  } catch (err2) {
2828
2912
  log11.catch(err2, void 0, {
2829
2913
  F: __dxlog_file12,
2830
- L: 117,
2914
+ L: 120,
2831
2915
  S: this,
2832
2916
  C: (f, a) => f(...a)
2833
2917
  });
@@ -2838,15 +2922,68 @@ var SimplePeerTransport = class {
2838
2922
  id: this._instanceId
2839
2923
  }), {
2840
2924
  F: __dxlog_file12,
2841
- L: 122,
2925
+ L: 126,
2842
2926
  S: this,
2843
2927
  C: (f, a) => f(...a)
2844
2928
  });
2845
2929
  }
2930
+ async getStats() {
2931
+ const stats = await this._getStats();
2932
+ if (!stats) {
2933
+ return {
2934
+ bytesSent: 0,
2935
+ bytesReceived: 0,
2936
+ packetsSent: 0,
2937
+ packetsReceived: 0,
2938
+ rawStats: {}
2939
+ };
2940
+ }
2941
+ return {
2942
+ bytesSent: stats.transport.bytesSent,
2943
+ bytesReceived: stats.transport.bytesReceived,
2944
+ packetsSent: stats.transport.messagesSent,
2945
+ packetsReceived: stats.transport.messagesReceived,
2946
+ rawStats: stats.raw
2947
+ };
2948
+ }
2949
+ async _getStats() {
2950
+ if (typeof this._peer?._pc?.getStats !== "function") {
2951
+ return null;
2952
+ }
2953
+ return await this._peer._pc.getStats().then((stats) => {
2954
+ const statsEntries = Array.from(stats.entries());
2955
+ const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
2956
+ const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
2957
+ let selectedCandidatePair;
2958
+ let remoteCandidate;
2959
+ if (candidatePair.length > 0) {
2960
+ selectedCandidatePair = candidatePair[0][1];
2961
+ remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
2962
+ }
2963
+ return {
2964
+ datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
2965
+ transport,
2966
+ selectedCandidatePair,
2967
+ remoteCandidate,
2968
+ raw: Object.fromEntries(stats.entries())
2969
+ };
2970
+ });
2971
+ }
2972
+ async getDetails() {
2973
+ const stats = await this._getStats();
2974
+ const rc = stats?.remoteCandidate;
2975
+ if (!rc) {
2976
+ return "unavailable";
2977
+ }
2978
+ if (rc.relay) {
2979
+ return `${rc.ip}:${rc.port}/${rc.protocol} relay for XXX ${rc.candidateType}`;
2980
+ }
2981
+ return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
2982
+ }
2846
2983
  async destroy() {
2847
2984
  log11("closing...", void 0, {
2848
2985
  F: __dxlog_file12,
2849
- L: 126,
2986
+ L: 189,
2850
2987
  S: this,
2851
2988
  C: (f, a) => f(...a)
2852
2989
  });
@@ -2856,10 +2993,11 @@ var SimplePeerTransport = class {
2856
2993
  this._closed = true;
2857
2994
  this._disconnectStreams();
2858
2995
  this._peer.destroy();
2996
+ this._closed = true;
2859
2997
  this.closed.emit();
2860
2998
  log11("closed", void 0, {
2861
2999
  F: __dxlog_file12,
2862
- L: 134,
3000
+ L: 198,
2863
3001
  S: this,
2864
3002
  C: (f, a) => f(...a)
2865
3003
  });
@@ -2892,7 +3030,7 @@ import { PublicKey as PublicKey11 } from "@dxos/keys";
2892
3030
  import { log as log12 } from "@dxos/log";
2893
3031
  import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
2894
3032
  import { ComplexMap as ComplexMap8 } from "@dxos/util";
2895
- var __dxlog_file13 = "/home/circleci/project/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3033
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
2896
3034
  var SimplePeerTransportService = class {
2897
3035
  constructor(_webrtcConfig) {
2898
3036
  this._webrtcConfig = _webrtcConfig;
@@ -2974,7 +3112,7 @@ var SimplePeerTransportService = class {
2974
3112
  async sendSignal({ proxyId, signal }) {
2975
3113
  invariant12(this.transports.has(proxyId), void 0, {
2976
3114
  F: __dxlog_file13,
2977
- L: 112,
3115
+ L: 116,
2978
3116
  S: this,
2979
3117
  A: [
2980
3118
  "this.transports.has(proxyId)",
@@ -2983,18 +3121,46 @@ var SimplePeerTransportService = class {
2983
3121
  });
2984
3122
  await this.transports.get(proxyId).transport.signal(signal);
2985
3123
  }
3124
+ async getDetails({ proxyId }) {
3125
+ invariant12(this.transports.has(proxyId), void 0, {
3126
+ F: __dxlog_file13,
3127
+ L: 121,
3128
+ S: this,
3129
+ A: [
3130
+ "this.transports.has(proxyId)",
3131
+ ""
3132
+ ]
3133
+ });
3134
+ return {
3135
+ details: await this.transports.get(proxyId).transport.getDetails()
3136
+ };
3137
+ }
3138
+ async getStats({ proxyId }) {
3139
+ invariant12(this.transports.has(proxyId), void 0, {
3140
+ F: __dxlog_file13,
3141
+ L: 126,
3142
+ S: this,
3143
+ A: [
3144
+ "this.transports.has(proxyId)",
3145
+ ""
3146
+ ]
3147
+ });
3148
+ return {
3149
+ stats: await this.transports.get(proxyId).transport.getStats()
3150
+ };
3151
+ }
2986
3152
  async sendData({ proxyId, payload }) {
2987
3153
  if (this.transports.get(proxyId)?.state !== "OPEN") {
2988
3154
  log12.debug("transport is closed", void 0, {
2989
3155
  F: __dxlog_file13,
2990
- L: 118,
3156
+ L: 132,
2991
3157
  S: this,
2992
3158
  C: (f, a) => f(...a)
2993
3159
  });
2994
3160
  }
2995
3161
  invariant12(this.transports.has(proxyId), void 0, {
2996
3162
  F: __dxlog_file13,
2997
- L: 120,
3163
+ L: 134,
2998
3164
  S: this,
2999
3165
  A: [
3000
3166
  "this.transports.has(proxyId)",
@@ -3017,7 +3183,7 @@ var SimplePeerTransportService = class {
3017
3183
  }
3018
3184
  log12("Closed.", void 0, {
3019
3185
  F: __dxlog_file13,
3020
- L: 136,
3186
+ L: 150,
3021
3187
  S: this,
3022
3188
  C: (f, a) => f(...a)
3023
3189
  });
@@ -3032,10 +3198,10 @@ import { ErrorStream as ErrorStream5 } from "@dxos/debug";
3032
3198
  import { invariant as invariant13 } from "@dxos/invariant";
3033
3199
  import { PublicKey as PublicKey12 } from "@dxos/keys";
3034
3200
  import { log as log13 } from "@dxos/log";
3035
- import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError2, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
3201
+ import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError3, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
3036
3202
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
3037
3203
  import { arrayToBuffer } from "@dxos/util";
3038
- var __dxlog_file14 = "/home/circleci/project/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3204
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3039
3205
  var RESP_MIN_THRESHOLD = 500;
3040
3206
  var TIMEOUT_THRESHOLD = 10;
3041
3207
  var SimplePeerTransportProxy = class {
@@ -3088,9 +3254,9 @@ var SimplePeerTransportProxy = class {
3088
3254
  }
3089
3255
  this._timeoutCount = 0;
3090
3256
  }, (err) => {
3091
- if (err instanceof TimeoutError2 || err.constructor.name === "TimeoutError") {
3257
+ if (err instanceof TimeoutError3 || err.constructor.name === "TimeoutError") {
3092
3258
  if (this._timeoutCount++ > TIMEOUT_THRESHOLD) {
3093
- throw new TimeoutError2(`too many timeoutes (${this._timeoutCount} > ${TIMEOUT_THRESHOLD}`);
3259
+ throw new TimeoutError3(`too many timeoutes (${this._timeoutCount} > ${TIMEOUT_THRESHOLD}`);
3094
3260
  } else {
3095
3261
  log13("timeout error, but still invoking callback", void 0, {
3096
3262
  F: __dxlog_file14,
@@ -3156,6 +3322,16 @@ var SimplePeerTransportProxy = class {
3156
3322
  signal
3157
3323
  }).catch((err) => this.errors.raise(decodeError(err)));
3158
3324
  }
3325
+ async getDetails() {
3326
+ return (await this._params.bridgeService.getDetails({
3327
+ proxyId: this._proxyId
3328
+ })).details;
3329
+ }
3330
+ async getStats() {
3331
+ return (await this._params.bridgeService.getStats({
3332
+ proxyId: this._proxyId
3333
+ })).stats;
3334
+ }
3159
3335
  // TODO(burdon): Move open from constructor.
3160
3336
  async destroy() {
3161
3337
  await this._ctx.dispose();
@@ -3170,7 +3346,7 @@ var SimplePeerTransportProxy = class {
3170
3346
  } catch (err) {
3171
3347
  log13.catch(err, void 0, {
3172
3348
  F: __dxlog_file14,
3173
- L: 160,
3349
+ L: 168,
3174
3350
  S: this,
3175
3351
  C: (f, a) => f(...a)
3176
3352
  });
@@ -3206,7 +3382,7 @@ var SimplePeerTransportProxyFactory = class {
3206
3382
  createTransport(options) {
3207
3383
  invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3208
3384
  F: __dxlog_file14,
3209
- L: 197,
3385
+ L: 205,
3210
3386
  S: this,
3211
3387
  A: [
3212
3388
  "this._bridgeService",
@@ -3227,7 +3403,7 @@ var decodeError = (err) => {
3227
3403
  if (message.includes("CONNECTION_RESET")) {
3228
3404
  return new ConnectionResetError3(message);
3229
3405
  } else if (message.includes("TIMEOUT")) {
3230
- return new TimeoutError2(message);
3406
+ return new TimeoutError3(message);
3231
3407
  } else if (message.includes("PROTOCOL_ERROR")) {
3232
3408
  return new ProtocolError3(message);
3233
3409
  } else if (message.includes("CONNECTIVITY_ERROR")) {
@@ -3254,7 +3430,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3254
3430
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3255
3431
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3256
3432
  }
3257
- var __dxlog_file15 = "/home/circleci/project/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3433
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3258
3434
  var DATACHANNEL_LABEL = "dxos.mesh.transport";
3259
3435
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3260
3436
  var MAX_MESSAGE_SIZE = 64 * 1024;
@@ -3407,16 +3583,21 @@ var LibDataChannelTransport = class {
3407
3583
  const duplex = new Duplex2({
3408
3584
  read: () => {
3409
3585
  },
3410
- write: (chunk, encoding, callback) => {
3586
+ write: async (chunk, encoding, callback) => {
3411
3587
  if (chunk.length > MAX_MESSAGE_SIZE) {
3412
3588
  this.errors.raise(new Error(`message too large: ${chunk.length} > ${MAX_MESSAGE_SIZE}`));
3413
3589
  }
3414
- dataChannel.send(chunk);
3590
+ try {
3591
+ dataChannel.send(chunk);
3592
+ } catch (err) {
3593
+ this.errors.raise(err);
3594
+ await this._close();
3595
+ }
3415
3596
  if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
3416
3597
  if (this._writeCallback !== null) {
3417
3598
  log14.error("consumer trying to write before we're ready for more data", void 0, {
3418
3599
  F: __dxlog_file15,
3419
- L: 139,
3600
+ L: 143,
3420
3601
  S: this,
3421
3602
  C: (f, a) => f(...a)
3422
3603
  });
@@ -3441,7 +3622,7 @@ var LibDataChannelTransport = class {
3441
3622
  err
3442
3623
  }, {
3443
3624
  F: __dxlog_file15,
3444
- L: 159,
3625
+ L: 163,
3445
3626
  S: this,
3446
3627
  C: (f, a) => f(...a)
3447
3628
  });
@@ -3478,7 +3659,7 @@ var LibDataChannelTransport = class {
3478
3659
  peer
3479
3660
  }, {
3480
3661
  F: __dxlog_file15,
3481
- L: 194,
3662
+ L: 198,
3482
3663
  S: this,
3483
3664
  C: (f, a) => f(...a)
3484
3665
  });
@@ -3506,7 +3687,7 @@ var LibDataChannelTransport = class {
3506
3687
  err
3507
3688
  }, {
3508
3689
  F: __dxlog_file15,
3509
- L: 205,
3690
+ L: 209,
3510
3691
  S: this,
3511
3692
  C: (f, a) => f(...a)
3512
3693
  });
@@ -3526,7 +3707,7 @@ var LibDataChannelTransport = class {
3526
3707
  err
3527
3708
  }, {
3528
3709
  F: __dxlog_file15,
3529
- L: 216,
3710
+ L: 220,
3530
3711
  S: this,
3531
3712
  C: (f, a) => f(...a)
3532
3713
  });
@@ -3545,7 +3726,7 @@ var LibDataChannelTransport = class {
3545
3726
  signal
3546
3727
  }, {
3547
3728
  F: __dxlog_file15,
3548
- L: 227,
3729
+ L: 231,
3549
3730
  S: this,
3550
3731
  C: (f, a) => f(...a)
3551
3732
  });
@@ -3554,10 +3735,50 @@ var LibDataChannelTransport = class {
3554
3735
  }).catch((err) => {
3555
3736
  log14.catch(err, void 0, {
3556
3737
  F: __dxlog_file15,
3557
- L: 232,
3738
+ L: 236,
3739
+ S: this,
3740
+ C: (f, a) => f(...a)
3741
+ });
3742
+ });
3743
+ }
3744
+ async getDetails() {
3745
+ return this._peer.then(async (peer) => {
3746
+ const cp = await peer.getSelectedCandidatePair();
3747
+ if (!cp) {
3748
+ return "unavailable";
3749
+ }
3750
+ return `${cp.remote.address}:${cp.remote.port}/${cp.remote.transportType} ${cp.remote.type}`;
3751
+ }).catch((err) => {
3752
+ log14.catch(err, void 0, {
3753
+ F: __dxlog_file15,
3754
+ L: 250,
3558
3755
  S: this,
3559
3756
  C: (f, a) => f(...a)
3560
3757
  });
3758
+ return "unavailable";
3759
+ });
3760
+ }
3761
+ async getStats() {
3762
+ return this._peer.then((peer) => {
3763
+ return {
3764
+ bytesSent: peer.bytesSent(),
3765
+ bytesReceived: peer.bytesReceived(),
3766
+ packetsSent: 0,
3767
+ packetsReceived: 0
3768
+ };
3769
+ }).catch((err) => {
3770
+ log14.catch(err, void 0, {
3771
+ F: __dxlog_file15,
3772
+ L: 266,
3773
+ S: this,
3774
+ C: (f, a) => f(...a)
3775
+ });
3776
+ return {
3777
+ bytesSent: 0,
3778
+ bytesReceived: 0,
3779
+ packetsSent: 0,
3780
+ packetsReceived: 0
3781
+ };
3561
3782
  });
3562
3783
  }
3563
3784
  // TODO(nf): add classmethod to call node-datachannel.cleanup() when all instances have been destroyed?
@@ -3596,6 +3817,12 @@ var TcpTransport = class {
3596
3817
  signal() {
3597
3818
  throw new Error("Method not implemented.");
3598
3819
  }
3820
+ async getStats() {
3821
+ throw new Error("Method not implemented.");
3822
+ }
3823
+ async getDetails() {
3824
+ throw new Error("Method not implemented.");
3825
+ }
3599
3826
  };
3600
3827
 
3601
3828
  // packages/core/mesh/network-manager/src/wire-protocol.ts
@@ -3605,8 +3832,8 @@ var createTeleportProtocolFactory = (onConnection) => {
3605
3832
  const teleport = new Teleport(params);
3606
3833
  return {
3607
3834
  stream: teleport.stream,
3608
- open: async () => {
3609
- await teleport.open();
3835
+ open: async (sessionId) => {
3836
+ await teleport.open(sessionId);
3610
3837
  await onConnection(teleport);
3611
3838
  },
3612
3839
  close: async () => {
@@ -3647,4 +3874,4 @@ export {
3647
3874
  TcpTransport,
3648
3875
  createTeleportProtocolFactory
3649
3876
  };
3650
- //# sourceMappingURL=chunk-H7XJ7HES.mjs.map
3877
+ //# sourceMappingURL=chunk-S2JHWVGQ.mjs.map