@dxos/network-manager 0.5.1-main.f81ddc4 → 0.5.1-next.260c093

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.
@@ -15,7 +15,7 @@ import {
15
15
  } from "@dxos/node-std/inject-globals";
16
16
 
17
17
  // packages/core/mesh/network-manager/src/swarm/connection.ts
18
- import { DeferredTask, Event, sleep, scheduleTask, scheduleTaskInterval, synchronized, Trigger } from "@dxos/async";
18
+ import { DeferredTask, Event, sleep, scheduleTask, scheduleTaskInterval, synchronized } from "@dxos/async";
19
19
  import { Context, cancelWithContext } from "@dxos/context";
20
20
  import { ErrorStream } from "@dxos/debug";
21
21
  import { invariant } from "@dxos/invariant";
@@ -61,8 +61,6 @@ var Connection = class {
61
61
  this._callbacks = _callbacks;
62
62
  this._ctx = new Context();
63
63
  this.connectedTimeoutContext = new Context();
64
- this._protocolClosed = new Trigger();
65
- this._transportClosed = new Trigger();
66
64
  this._state = "CREATED";
67
65
  this._incomingSignalBuffer = [];
68
66
  this._outgoingSignalBuffer = [];
@@ -82,7 +80,7 @@ var Connection = class {
82
80
  initiator: this.initiator
83
81
  }, {
84
82
  F: __dxlog_file,
85
- L: 137,
83
+ L: 134,
86
84
  S: this,
87
85
  C: (f, a) => f(...a)
88
86
  });
@@ -105,7 +103,7 @@ var Connection = class {
105
103
  async openConnection() {
106
104
  invariant(this._state === "INITIAL", "Invalid state.", {
107
105
  F: __dxlog_file,
108
- L: 167,
106
+ L: 164,
109
107
  S: this,
110
108
  A: [
111
109
  "this._state === ConnectionState.INITIAL",
@@ -116,7 +114,7 @@ var Connection = class {
116
114
  id: this._instanceId
117
115
  }), {
118
116
  F: __dxlog_file,
119
- L: 168,
117
+ L: 165,
120
118
  S: this,
121
119
  C: (f, a) => f(...a)
122
120
  });
@@ -128,7 +126,7 @@ var Connection = class {
128
126
  initiator: this.initiator
129
127
  }, {
130
128
  F: __dxlog_file,
131
- L: 169,
129
+ L: 166,
132
130
  S: this,
133
131
  C: (f, a) => f(...a)
134
132
  });
@@ -139,17 +137,16 @@ var Connection = class {
139
137
  this._protocol.stream.on("close", () => {
140
138
  log("protocol stream closed", void 0, {
141
139
  F: __dxlog_file,
142
- L: 186,
140
+ L: 183,
143
141
  S: this,
144
142
  C: (f, a) => f(...a)
145
143
  });
146
- this._protocolClosed.wake();
147
144
  this.close(new ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
148
145
  });
149
146
  scheduleTask(this.connectedTimeoutContext, async () => {
150
147
  log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
151
148
  F: __dxlog_file,
152
- L: 194,
149
+ L: 190,
153
150
  S: this,
154
151
  C: (f, a) => f(...a)
155
152
  });
@@ -157,7 +154,7 @@ var Connection = class {
157
154
  }, TRANSPORT_CONNECTION_TIMEOUT);
158
155
  invariant(!this._transport, void 0, {
159
156
  F: __dxlog_file,
160
- L: 202,
157
+ L: 198,
161
158
  S: this,
162
159
  A: [
163
160
  "!this._transport",
@@ -179,10 +176,9 @@ var Connection = class {
179
176
  });
180
177
  this._transport.closed.once(() => {
181
178
  this._transport = void 0;
182
- this._transportClosed.wake();
183
179
  log("abort triggered by transport close", void 0, {
184
180
  F: __dxlog_file,
185
- L: 223,
181
+ L: 218,
186
182
  S: this,
187
183
  C: (f, a) => f(...a)
188
184
  });
@@ -193,7 +189,7 @@ var Connection = class {
193
189
  err
194
190
  }, {
195
191
  F: __dxlog_file,
196
- L: 228,
192
+ L: 223,
197
193
  S: this,
198
194
  C: (f, a) => f(...a)
199
195
  });
@@ -203,7 +199,7 @@ var Connection = class {
203
199
  if (err instanceof ConnectionResetError) {
204
200
  log.info("aborting due to transport ConnectionResetError", void 0, {
205
201
  F: __dxlog_file,
206
- L: 235,
202
+ L: 230,
207
203
  S: this,
208
204
  C: (f, a) => f(...a)
209
205
  });
@@ -211,7 +207,7 @@ var Connection = class {
211
207
  } else if (err instanceof ConnectivityError) {
212
208
  log.info("aborting due to transport ConnectivityError", void 0, {
213
209
  F: __dxlog_file,
214
- L: 238,
210
+ L: 233,
215
211
  S: this,
216
212
  C: (f, a) => f(...a)
217
213
  });
@@ -221,7 +217,7 @@ var Connection = class {
221
217
  err
222
218
  }, {
223
219
  F: __dxlog_file,
224
- L: 241,
220
+ L: 236,
225
221
  S: this,
226
222
  C: (f, a) => f(...a)
227
223
  });
@@ -239,7 +235,7 @@ var Connection = class {
239
235
  id: this._instanceId
240
236
  }), {
241
237
  F: __dxlog_file,
242
- L: 257,
238
+ L: 252,
243
239
  S: this,
244
240
  C: (f, a) => f(...a)
245
241
  });
@@ -249,14 +245,14 @@ var Connection = class {
249
245
  err
250
246
  }, {
251
247
  F: __dxlog_file,
252
- L: 264,
248
+ L: 259,
253
249
  S: this,
254
250
  C: (f, a) => f(...a)
255
251
  });
256
252
  if (this._state === "CLOSED" || this._state === "ABORTED") {
257
253
  log(`abort ignored: already ${this._state}`, this.closeReason, {
258
254
  F: __dxlog_file,
259
- L: 266,
255
+ L: 261,
260
256
  S: this,
261
257
  C: (f, a) => f(...a)
262
258
  });
@@ -269,21 +265,27 @@ var Connection = class {
269
265
  }
270
266
  await this._ctx.dispose();
271
267
  try {
272
- await this._closeProtocol();
268
+ log("aborting protocol... ", void 0, {
269
+ F: __dxlog_file,
270
+ L: 275,
271
+ S: this,
272
+ C: (f, a) => f(...a)
273
+ });
274
+ await this._protocol.abort();
273
275
  } catch (err2) {
274
276
  log.catch(err2, void 0, {
275
277
  F: __dxlog_file,
276
- L: 282,
278
+ L: 278,
277
279
  S: this,
278
280
  C: (f, a) => f(...a)
279
281
  });
280
282
  }
281
283
  try {
282
- await this._closeTransport();
284
+ await this._transport?.close();
283
285
  } catch (err2) {
284
286
  log.catch(err2, void 0, {
285
287
  F: __dxlog_file,
286
- L: 289,
288
+ L: 285,
287
289
  S: this,
288
290
  C: (f, a) => f(...a)
289
291
  });
@@ -293,7 +295,7 @@ var Connection = class {
293
295
  } catch (err2) {
294
296
  log.catch(err2, void 0, {
295
297
  F: __dxlog_file,
296
- L: 295,
298
+ L: 291,
297
299
  S: this,
298
300
  C: (f, a) => f(...a)
299
301
  });
@@ -317,27 +319,27 @@ var Connection = class {
317
319
  peerId: this.ownId
318
320
  }, {
319
321
  F: __dxlog_file,
320
- L: 320,
322
+ L: 316,
321
323
  S: this,
322
324
  C: (f, a) => f(...a)
323
325
  });
324
326
  if (lastState === "CONNECTED") {
325
327
  try {
326
- await this._closeProtocol();
328
+ await this._protocol.close();
327
329
  } catch (err2) {
328
330
  log.catch(err2, void 0, {
329
331
  F: __dxlog_file,
330
- L: 327,
332
+ L: 323,
331
333
  S: this,
332
334
  C: (f, a) => f(...a)
333
335
  });
334
336
  }
335
337
  try {
336
- await this._closeTransport();
338
+ await this._transport?.close();
337
339
  } catch (err2) {
338
340
  log.catch(err2, void 0, {
339
341
  F: __dxlog_file,
340
- L: 334,
342
+ L: 330,
341
343
  S: this,
342
344
  C: (f, a) => f(...a)
343
345
  });
@@ -345,26 +347,26 @@ var Connection = class {
345
347
  } else {
346
348
  log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
347
349
  F: __dxlog_file,
348
- L: 337,
350
+ L: 333,
349
351
  S: this,
350
352
  C: (f, a) => f(...a)
351
353
  });
352
354
  try {
353
- await this._closeProtocol();
355
+ await this._protocol.abort();
354
356
  } catch (err2) {
355
357
  log.catch(err2, void 0, {
356
358
  F: __dxlog_file,
357
- L: 341,
359
+ L: 337,
358
360
  S: this,
359
361
  C: (f, a) => f(...a)
360
362
  });
361
363
  }
362
364
  try {
363
- await this._closeTransport();
365
+ await this._transport?.close();
364
366
  } catch (err2) {
365
367
  log.catch(err2, void 0, {
366
368
  F: __dxlog_file,
367
- L: 346,
369
+ L: 342,
368
370
  S: this,
369
371
  C: (f, a) => f(...a)
370
372
  });
@@ -374,49 +376,13 @@ var Connection = class {
374
376
  peerId: this.ownId
375
377
  }, {
376
378
  F: __dxlog_file,
377
- L: 350,
379
+ L: 346,
378
380
  S: this,
379
381
  C: (f, a) => f(...a)
380
382
  });
381
383
  this._changeState("CLOSED");
382
384
  this._callbacks?.onClosed?.(err);
383
385
  }
384
- async _closeProtocol() {
385
- log("closing protocol", void 0, {
386
- F: __dxlog_file,
387
- L: 356,
388
- S: this,
389
- C: (f, a) => f(...a)
390
- });
391
- await Promise.race([
392
- this._protocol.close(),
393
- this._protocolClosed.wait()
394
- ]);
395
- log("protocol closed", void 0, {
396
- F: __dxlog_file,
397
- L: 358,
398
- S: this,
399
- C: (f, a) => f(...a)
400
- });
401
- }
402
- async _closeTransport() {
403
- log("closing transport", void 0, {
404
- F: __dxlog_file,
405
- L: 362,
406
- S: this,
407
- C: (f, a) => f(...a)
408
- });
409
- await Promise.race([
410
- this._transport?.close(),
411
- this._transportClosed.wait()
412
- ]);
413
- log("transport closed", void 0, {
414
- F: __dxlog_file,
415
- L: 364,
416
- S: this,
417
- C: (f, a) => f(...a)
418
- });
419
- }
420
386
  _sendSignal(signal) {
421
387
  this._outgoingSignalBuffer.push(signal);
422
388
  this._signalSendTask.schedule();
@@ -453,7 +419,7 @@ var Connection = class {
453
419
  err
454
420
  }, {
455
421
  F: __dxlog_file,
456
- L: 400,
422
+ L: 384,
457
423
  S: this,
458
424
  C: (f, a) => f(...a)
459
425
  });
@@ -466,7 +432,7 @@ var Connection = class {
466
432
  async signal(msg) {
467
433
  invariant(msg.sessionId, void 0, {
468
434
  F: __dxlog_file,
469
- L: 409,
435
+ L: 393,
470
436
  S: this,
471
437
  A: [
472
438
  "msg.sessionId",
@@ -476,7 +442,7 @@ var Connection = class {
476
442
  if (!msg.sessionId.equals(this.sessionId)) {
477
443
  log("dropping signal for incorrect session id", void 0, {
478
444
  F: __dxlog_file,
479
- L: 411,
445
+ L: 395,
480
446
  S: this,
481
447
  C: (f, a) => f(...a)
482
448
  });
@@ -484,7 +450,7 @@ var Connection = class {
484
450
  }
485
451
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
486
452
  F: __dxlog_file,
487
- L: 414,
453
+ L: 398,
488
454
  S: this,
489
455
  A: [
490
456
  "msg.data.signal || msg.data.signalBatch",
@@ -493,7 +459,7 @@ var Connection = class {
493
459
  });
494
460
  invariant(msg.author?.equals(this.remoteId), void 0, {
495
461
  F: __dxlog_file,
496
- L: 415,
462
+ L: 399,
497
463
  S: this,
498
464
  A: [
499
465
  "msg.author?.equals(this.remoteId)",
@@ -502,7 +468,7 @@ var Connection = class {
502
468
  });
503
469
  invariant(msg.recipient?.equals(this.ownId), void 0, {
504
470
  F: __dxlog_file,
505
- L: 416,
471
+ L: 400,
506
472
  S: this,
507
473
  A: [
508
474
  "msg.recipient?.equals(this.ownId)",
@@ -526,7 +492,7 @@ var Connection = class {
526
492
  msg: msg.data
527
493
  }, {
528
494
  F: __dxlog_file,
529
- L: 425,
495
+ L: 409,
530
496
  S: this,
531
497
  C: (f, a) => f(...a)
532
498
  });
@@ -534,7 +500,7 @@ var Connection = class {
534
500
  } else {
535
501
  invariant(this._transport, "Connection not ready to accept signals.", {
536
502
  F: __dxlog_file,
537
- L: 428,
503
+ L: 412,
538
504
  S: this,
539
505
  A: [
540
506
  "this._transport",
@@ -547,7 +513,7 @@ var Connection = class {
547
513
  msg: msg.data
548
514
  }, {
549
515
  F: __dxlog_file,
550
- L: 429,
516
+ L: 413,
551
517
  S: this,
552
518
  C: (f, a) => f(...a)
553
519
  });
@@ -565,13 +531,13 @@ var Connection = class {
565
531
  peerId: this.ownId
566
532
  }, {
567
533
  F: __dxlog_file,
568
- L: 440,
534
+ L: 424,
569
535
  S: this,
570
536
  C: (f, a) => f(...a)
571
537
  });
572
538
  invariant(state !== this._state, "Already in this state.", {
573
539
  F: __dxlog_file,
574
- L: 441,
540
+ L: 425,
575
541
  S: this,
576
542
  A: [
577
543
  "state !== this._state",
@@ -999,9 +965,9 @@ var Peer = class {
999
965
  });
1000
966
  const sessionId = PublicKey3.random();
1001
967
  log3("initiating...", {
1002
- ownPeerId: this.localPeerId,
968
+ id: this.id,
1003
969
  topic: this.topic,
1004
- remotePeerId: this.id,
970
+ peerId: this.id,
1005
971
  sessionId
1006
972
  }, {
1007
973
  F: __dxlog_file3,
@@ -1729,8 +1695,7 @@ var Swarm = class {
1729
1695
  getState: () => ({
1730
1696
  ownPeerId: this._ownPeerId,
1731
1697
  connected: Array.from(this._peers.values()).filter((peer) => peer.connection).map((peer) => peer.id),
1732
- candidates: Array.from(this._peers.values()).filter((peer) => !peer.connection && peer.advertizing && peer.availableToConnect).map((peer) => peer.id),
1733
- allPeers: Array.from(this._peers.values()).map((peer) => peer.id)
1698
+ candidates: Array.from(this._peers.values()).filter((peer) => !peer.connection && peer.advertizing && peer.availableToConnect).map((peer) => peer.id)
1734
1699
  }),
1735
1700
  connect: (peer) => {
1736
1701
  if (this._ctx.disposed) {
@@ -1742,7 +1707,7 @@ var Swarm = class {
1742
1707
  } catch (err) {
1743
1708
  log4("initiation error", err, {
1744
1709
  F: __dxlog_file4,
1745
- L: 335,
1710
+ L: 334,
1746
1711
  S: this,
1747
1712
  C: (f, a) => f(...a)
1748
1713
  });
@@ -1765,13 +1730,12 @@ var Swarm = class {
1765
1730
  */
1766
1731
  async _initiateConnection(remoteId) {
1767
1732
  const ctx = this._ctx;
1768
- const peer = this._getOrCreatePeer(remoteId);
1769
1733
  if (remoteId.toHex() < this._ownPeerId.toHex()) {
1770
1734
  log4("initiation delay", {
1771
1735
  remoteId
1772
1736
  }, {
1773
1737
  F: __dxlog_file4,
1774
- L: 363,
1738
+ L: 361,
1775
1739
  S: this,
1776
1740
  C: (f, a) => f(...a)
1777
1741
  });
@@ -1780,9 +1744,7 @@ var Swarm = class {
1780
1744
  if (ctx.disposed) {
1781
1745
  return;
1782
1746
  }
1783
- if (this._peers.get(remoteId) == null) {
1784
- throw new Error("Peer left during initiation delay");
1785
- }
1747
+ const peer = this._getOrCreatePeer(remoteId);
1786
1748
  if (peer.connection) {
1787
1749
  return;
1788
1750
  }
@@ -1790,7 +1752,7 @@ var Swarm = class {
1790
1752
  remoteId
1791
1753
  }, {
1792
1754
  F: __dxlog_file4,
1793
- L: 379,
1755
+ L: 375,
1794
1756
  S: this,
1795
1757
  C: (f, a) => f(...a)
1796
1758
  });
@@ -1800,7 +1762,7 @@ var Swarm = class {
1800
1762
  remoteId
1801
1763
  }, {
1802
1764
  F: __dxlog_file4,
1803
- L: 382,
1765
+ L: 378,
1804
1766
  S: this,
1805
1767
  C: (f, a) => f(...a)
1806
1768
  });
@@ -2630,7 +2592,7 @@ var StarTopology = class {
2630
2592
 
2631
2593
  // packages/core/mesh/network-manager/src/transport/memory-transport.ts
2632
2594
  import { Transform } from "@dxos/node-std/stream";
2633
- import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
2595
+ import { Event as Event7, Trigger } from "@dxos/async";
2634
2596
  import { ErrorStream as ErrorStream3 } from "@dxos/debug";
2635
2597
  import { invariant as invariant10 } from "@dxos/invariant";
2636
2598
  import { PublicKey as PublicKey9 } from "@dxos/keys";
@@ -2667,7 +2629,7 @@ var MemoryTransport = class _MemoryTransport {
2667
2629
  constructor(_options) {
2668
2630
  this._options = _options;
2669
2631
  this._instanceId = PublicKey9.random();
2670
- this._remote = new Trigger2();
2632
+ this._remote = new Trigger();
2671
2633
  this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2672
2634
  this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2673
2635
  this._closed = false;
@@ -3514,7 +3476,7 @@ var decodeError = (err) => {
3514
3476
 
3515
3477
  // packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts
3516
3478
  import { Duplex as Duplex2 } from "stream";
3517
- import { Event as Event10, Trigger as Trigger3, synchronized as synchronized4 } from "@dxos/async";
3479
+ import { Event as Event10, Trigger as Trigger2, synchronized as synchronized4 } from "@dxos/async";
3518
3480
  import { ErrorStream as ErrorStream6 } from "@dxos/debug";
3519
3481
  import { invariant as invariant14 } from "@dxos/invariant";
3520
3482
  import { log as log14 } from "@dxos/log";
@@ -3547,7 +3509,7 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
3547
3509
  this._closed = false;
3548
3510
  this._connected = false;
3549
3511
  this._writeCallback = null;
3550
- this._readyForCandidates = new Trigger3();
3512
+ this._readyForCandidates = new Trigger2();
3551
3513
  this.closed = new Event10();
3552
3514
  this.connected = new Event10();
3553
3515
  this.errors = new ErrorStream6();
@@ -3992,12 +3954,9 @@ var TcpTransport = class {
3992
3954
 
3993
3955
  // packages/core/mesh/network-manager/src/wire-protocol.ts
3994
3956
  import { Teleport } from "@dxos/teleport";
3995
- var createTeleportProtocolFactory = (onConnection, defaultParams) => {
3957
+ var createTeleportProtocolFactory = (onConnection) => {
3996
3958
  return (params) => {
3997
- const teleport = new Teleport({
3998
- ...defaultParams,
3999
- ...params
4000
- });
3959
+ const teleport = new Teleport(params);
4001
3960
  return {
4002
3961
  stream: teleport.stream,
4003
3962
  open: async (sessionId) => {
@@ -4043,4 +4002,4 @@ export {
4043
4002
  TcpTransport,
4044
4003
  createTeleportProtocolFactory
4045
4004
  };
4046
- //# sourceMappingURL=chunk-H5NZQMNB.mjs.map
4005
+ //# sourceMappingURL=chunk-TVNVOM33.mjs.map