@dxos/network-manager 0.1.56-main.83e9b8a → 0.1.56-main.a25bb93
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.
- package/dist/lib/browser/{chunk-5R7TDXUU.mjs → chunk-FC6CWDES.mjs} +622 -187
- package/dist/lib/browser/chunk-FC6CWDES.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/index.cjs +621 -186
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +547 -168
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/topology/fully-connected-topology.d.ts.map +1 -1
- package/dist/types/src/topology/star-topology.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/network-manager.ts +1 -2
- package/src/signal/swarm-messenger.ts +1 -2
- package/src/swarm/connection-limiter.ts +2 -1
- package/src/swarm/connection.ts +17 -3
- package/src/swarm/peer.ts +24 -2
- package/src/swarm/swarm.ts +1 -2
- package/src/topology/fully-connected-topology.ts +1 -2
- package/src/topology/mmst-topology.ts +1 -1
- package/src/topology/star-topology.ts +1 -2
- package/src/transport/memory-transport.ts +1 -1
- package/src/transport/webrtc-transport-proxy.ts +14 -12
- package/src/transport/webrtc-transport-service.ts +31 -8
- package/src/transport/webrtc-transport.ts +1 -1
- package/dist/lib/browser/chunk-5R7TDXUU.mjs.map +0 -7
|
@@ -46,8 +46,8 @@ var import_rpc = require("@dxos/rpc");
|
|
|
46
46
|
var import_util11 = require("@dxos/util");
|
|
47
47
|
|
|
48
48
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
49
|
-
var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
|
|
50
49
|
var import_async7 = require("@dxos/async");
|
|
50
|
+
var import_invariant6 = require("@dxos/invariant");
|
|
51
51
|
var import_keys8 = require("@dxos/keys");
|
|
52
52
|
var import_log7 = require("@dxos/log");
|
|
53
53
|
var import_messaging = require("@dxos/messaging");
|
|
@@ -62,11 +62,11 @@ var import_keys7 = require("@dxos/keys");
|
|
|
62
62
|
var import_util5 = require("@dxos/util");
|
|
63
63
|
|
|
64
64
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
65
|
-
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
66
65
|
var import_async = require("@dxos/async");
|
|
67
66
|
var import_context = require("@dxos/context");
|
|
68
67
|
var import_debug = require("@dxos/debug");
|
|
69
68
|
var import_errors = require("@dxos/errors");
|
|
69
|
+
var import_invariant = require("@dxos/invariant");
|
|
70
70
|
var import_keys = require("@dxos/keys");
|
|
71
71
|
var import_log = require("@dxos/log");
|
|
72
72
|
var import_protocols = require("@dxos/protocols");
|
|
@@ -138,6 +138,18 @@ var Connection = class {
|
|
|
138
138
|
await this._flushSignalBuffer();
|
|
139
139
|
});
|
|
140
140
|
this._signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
141
|
+
import_log.log.trace("dxos.mesh.connection.construct", {
|
|
142
|
+
sessionId: this.sessionId,
|
|
143
|
+
topic: this.topic,
|
|
144
|
+
localPeerId: this.ownId,
|
|
145
|
+
remotePeerId: this.remoteId,
|
|
146
|
+
initiator: this.initiator
|
|
147
|
+
}, {
|
|
148
|
+
F: __dxlog_file,
|
|
149
|
+
L: 95,
|
|
150
|
+
S: this,
|
|
151
|
+
C: (f, a) => f(...a)
|
|
152
|
+
});
|
|
141
153
|
}
|
|
142
154
|
get state() {
|
|
143
155
|
return this._state;
|
|
@@ -152,12 +164,32 @@ var Connection = class {
|
|
|
152
164
|
* Create an underlying transport and prepares it for the connection.
|
|
153
165
|
*/
|
|
154
166
|
async openConnection() {
|
|
155
|
-
(0,
|
|
167
|
+
(0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
|
|
168
|
+
F: __dxlog_file,
|
|
169
|
+
L: 120,
|
|
170
|
+
S: this,
|
|
171
|
+
A: [
|
|
172
|
+
"this._state === ConnectionState.INITIAL",
|
|
173
|
+
"'Invalid state.'"
|
|
174
|
+
]
|
|
175
|
+
});
|
|
156
176
|
import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.begin({
|
|
157
177
|
id: this._instanceId
|
|
158
178
|
}), {
|
|
159
179
|
F: __dxlog_file,
|
|
160
|
-
L:
|
|
180
|
+
L: 121,
|
|
181
|
+
S: this,
|
|
182
|
+
C: (f, a) => f(...a)
|
|
183
|
+
});
|
|
184
|
+
import_log.log.trace("dxos.mesh.connection.open", {
|
|
185
|
+
sessionId: this.sessionId,
|
|
186
|
+
topic: this.topic,
|
|
187
|
+
localPeerId: this.ownId,
|
|
188
|
+
remotePeerId: this.remoteId,
|
|
189
|
+
initiator: this.initiator
|
|
190
|
+
}, {
|
|
191
|
+
F: __dxlog_file,
|
|
192
|
+
L: 122,
|
|
161
193
|
S: this,
|
|
162
194
|
C: (f, a) => f(...a)
|
|
163
195
|
});
|
|
@@ -168,13 +200,21 @@ var Connection = class {
|
|
|
168
200
|
this._protocol.stream.on("close", () => {
|
|
169
201
|
(0, import_log.log)("protocol stream closed", void 0, {
|
|
170
202
|
F: __dxlog_file,
|
|
171
|
-
L:
|
|
203
|
+
L: 139,
|
|
172
204
|
S: this,
|
|
173
205
|
C: (f, a) => f(...a)
|
|
174
206
|
});
|
|
175
207
|
this.close().catch((err) => this.errors.raise(err));
|
|
176
208
|
});
|
|
177
|
-
(0,
|
|
209
|
+
(0, import_invariant.invariant)(!this._transport, void 0, {
|
|
210
|
+
F: __dxlog_file,
|
|
211
|
+
L: 143,
|
|
212
|
+
S: this,
|
|
213
|
+
A: [
|
|
214
|
+
"!this._transport",
|
|
215
|
+
""
|
|
216
|
+
]
|
|
217
|
+
});
|
|
178
218
|
this._transport = this._transportFactory.createTransport({
|
|
179
219
|
initiator: this.initiator,
|
|
180
220
|
stream: this._protocol.stream,
|
|
@@ -200,7 +240,7 @@ var Connection = class {
|
|
|
200
240
|
id: this._instanceId
|
|
201
241
|
}), {
|
|
202
242
|
F: __dxlog_file,
|
|
203
|
-
L:
|
|
243
|
+
L: 172,
|
|
204
244
|
S: this,
|
|
205
245
|
C: (f, a) => f(...a)
|
|
206
246
|
});
|
|
@@ -216,7 +256,7 @@ var Connection = class {
|
|
|
216
256
|
peerId: this.ownId
|
|
217
257
|
}, {
|
|
218
258
|
F: __dxlog_file,
|
|
219
|
-
L:
|
|
259
|
+
L: 184,
|
|
220
260
|
S: this,
|
|
221
261
|
C: (f, a) => f(...a)
|
|
222
262
|
});
|
|
@@ -225,7 +265,7 @@ var Connection = class {
|
|
|
225
265
|
} catch (err) {
|
|
226
266
|
import_log.log.catch(err, void 0, {
|
|
227
267
|
F: __dxlog_file,
|
|
228
|
-
L:
|
|
268
|
+
L: 190,
|
|
229
269
|
S: this,
|
|
230
270
|
C: (f, a) => f(...a)
|
|
231
271
|
});
|
|
@@ -235,7 +275,7 @@ var Connection = class {
|
|
|
235
275
|
} catch (err) {
|
|
236
276
|
import_log.log.catch(err, void 0, {
|
|
237
277
|
F: __dxlog_file,
|
|
238
|
-
L:
|
|
278
|
+
L: 197,
|
|
239
279
|
S: this,
|
|
240
280
|
C: (f, a) => f(...a)
|
|
241
281
|
});
|
|
@@ -244,7 +284,7 @@ var Connection = class {
|
|
|
244
284
|
peerId: this.ownId
|
|
245
285
|
}, {
|
|
246
286
|
F: __dxlog_file,
|
|
247
|
-
L:
|
|
287
|
+
L: 200,
|
|
248
288
|
S: this,
|
|
249
289
|
C: (f, a) => f(...a)
|
|
250
290
|
});
|
|
@@ -284,7 +324,7 @@ var Connection = class {
|
|
|
284
324
|
err
|
|
285
325
|
}, {
|
|
286
326
|
F: __dxlog_file,
|
|
287
|
-
L:
|
|
327
|
+
L: 234,
|
|
288
328
|
S: this,
|
|
289
329
|
C: (f, a) => f(...a)
|
|
290
330
|
});
|
|
@@ -296,19 +336,51 @@ var Connection = class {
|
|
|
296
336
|
*/
|
|
297
337
|
async signal(msg) {
|
|
298
338
|
var _a2, _b, _c;
|
|
299
|
-
(0,
|
|
339
|
+
(0, import_invariant.invariant)(msg.sessionId, void 0, {
|
|
340
|
+
F: __dxlog_file,
|
|
341
|
+
L: 243,
|
|
342
|
+
S: this,
|
|
343
|
+
A: [
|
|
344
|
+
"msg.sessionId",
|
|
345
|
+
""
|
|
346
|
+
]
|
|
347
|
+
});
|
|
300
348
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
301
349
|
(0, import_log.log)("dropping signal for incorrect session id", void 0, {
|
|
302
350
|
F: __dxlog_file,
|
|
303
|
-
L:
|
|
351
|
+
L: 245,
|
|
304
352
|
S: this,
|
|
305
353
|
C: (f, a) => f(...a)
|
|
306
354
|
});
|
|
307
355
|
return;
|
|
308
356
|
}
|
|
309
|
-
(0,
|
|
310
|
-
|
|
311
|
-
|
|
357
|
+
(0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
358
|
+
F: __dxlog_file,
|
|
359
|
+
L: 248,
|
|
360
|
+
S: this,
|
|
361
|
+
A: [
|
|
362
|
+
"msg.data.signal || msg.data.signalBatch",
|
|
363
|
+
""
|
|
364
|
+
]
|
|
365
|
+
});
|
|
366
|
+
(0, import_invariant.invariant)((_a2 = msg.author) == null ? void 0 : _a2.equals(this.remoteId), void 0, {
|
|
367
|
+
F: __dxlog_file,
|
|
368
|
+
L: 249,
|
|
369
|
+
S: this,
|
|
370
|
+
A: [
|
|
371
|
+
"msg.author?.equals(this.remoteId)",
|
|
372
|
+
""
|
|
373
|
+
]
|
|
374
|
+
});
|
|
375
|
+
(0, import_invariant.invariant)((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId), void 0, {
|
|
376
|
+
F: __dxlog_file,
|
|
377
|
+
L: 250,
|
|
378
|
+
S: this,
|
|
379
|
+
A: [
|
|
380
|
+
"msg.recipient?.equals(this.ownId)",
|
|
381
|
+
""
|
|
382
|
+
]
|
|
383
|
+
});
|
|
312
384
|
const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
|
|
313
385
|
msg.data.signal
|
|
314
386
|
];
|
|
@@ -323,20 +395,28 @@ var Connection = class {
|
|
|
323
395
|
msg: msg.data
|
|
324
396
|
}, {
|
|
325
397
|
F: __dxlog_file,
|
|
326
|
-
L:
|
|
398
|
+
L: 259,
|
|
327
399
|
S: this,
|
|
328
400
|
C: (f, a) => f(...a)
|
|
329
401
|
});
|
|
330
402
|
this._incomingSignalBuffer.push(signal);
|
|
331
403
|
} else {
|
|
332
|
-
(0,
|
|
404
|
+
(0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
|
|
405
|
+
F: __dxlog_file,
|
|
406
|
+
L: 262,
|
|
407
|
+
S: this,
|
|
408
|
+
A: [
|
|
409
|
+
"this._transport",
|
|
410
|
+
"'Connection not ready to accept signals.'"
|
|
411
|
+
]
|
|
412
|
+
});
|
|
333
413
|
(0, import_log.log)("received signal", {
|
|
334
414
|
peerId: this.ownId,
|
|
335
415
|
remoteId: this.remoteId,
|
|
336
416
|
msg: msg.data
|
|
337
417
|
}, {
|
|
338
418
|
F: __dxlog_file,
|
|
339
|
-
L:
|
|
419
|
+
L: 263,
|
|
340
420
|
S: this,
|
|
341
421
|
C: (f, a) => f(...a)
|
|
342
422
|
});
|
|
@@ -351,11 +431,19 @@ var Connection = class {
|
|
|
351
431
|
peerId: this.ownId
|
|
352
432
|
}, {
|
|
353
433
|
F: __dxlog_file,
|
|
354
|
-
L:
|
|
434
|
+
L: 270,
|
|
355
435
|
S: this,
|
|
356
436
|
C: (f, a) => f(...a)
|
|
357
437
|
});
|
|
358
|
-
(0,
|
|
438
|
+
(0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
|
|
439
|
+
F: __dxlog_file,
|
|
440
|
+
L: 271,
|
|
441
|
+
S: this,
|
|
442
|
+
A: [
|
|
443
|
+
"state !== this._state",
|
|
444
|
+
"'Already in this state.'"
|
|
445
|
+
]
|
|
446
|
+
});
|
|
359
447
|
this._state = state;
|
|
360
448
|
this.stateChanged.emit(state);
|
|
361
449
|
}
|
|
@@ -365,18 +453,18 @@ _ts_decorate([
|
|
|
365
453
|
], Connection.prototype, "close", null);
|
|
366
454
|
|
|
367
455
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
368
|
-
var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
|
|
369
456
|
var import_async3 = require("@dxos/async");
|
|
370
457
|
var import_context4 = require("@dxos/context");
|
|
371
458
|
var import_debug2 = require("@dxos/debug");
|
|
459
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
372
460
|
var import_keys4 = require("@dxos/keys");
|
|
373
461
|
var import_log4 = require("@dxos/log");
|
|
374
462
|
var import_protocols3 = require("@dxos/protocols");
|
|
375
463
|
var import_util2 = require("@dxos/util");
|
|
376
464
|
|
|
377
465
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
378
|
-
var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
|
|
379
466
|
var import_context2 = require("@dxos/context");
|
|
467
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
380
468
|
var import_keys2 = require("@dxos/keys");
|
|
381
469
|
var import_log2 = require("@dxos/log");
|
|
382
470
|
var import_protocols2 = require("@dxos/protocols");
|
|
@@ -407,7 +495,7 @@ var SwarmMessenger = class {
|
|
|
407
495
|
msg: message
|
|
408
496
|
}, {
|
|
409
497
|
F: __dxlog_file2,
|
|
410
|
-
L:
|
|
498
|
+
L: 69,
|
|
411
499
|
S: this,
|
|
412
500
|
C: (f, a) => f(...a)
|
|
413
501
|
});
|
|
@@ -436,7 +524,7 @@ var SwarmMessenger = class {
|
|
|
436
524
|
message
|
|
437
525
|
}, {
|
|
438
526
|
F: __dxlog_file2,
|
|
439
|
-
L:
|
|
527
|
+
L: 80,
|
|
440
528
|
S: this,
|
|
441
529
|
C: (f, a) => f(...a)
|
|
442
530
|
});
|
|
@@ -444,7 +532,15 @@ var SwarmMessenger = class {
|
|
|
444
532
|
}
|
|
445
533
|
async signal(message) {
|
|
446
534
|
var _a2, _b;
|
|
447
|
-
(0,
|
|
535
|
+
(0, import_invariant2.invariant)(((_a2 = message.data) == null ? void 0 : _a2.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message", {
|
|
536
|
+
F: __dxlog_file2,
|
|
537
|
+
L: 85,
|
|
538
|
+
S: this,
|
|
539
|
+
A: [
|
|
540
|
+
"message.data?.signal || message.data?.signalBatch",
|
|
541
|
+
"'Invalid message'"
|
|
542
|
+
]
|
|
543
|
+
});
|
|
448
544
|
await this._sendReliableMessage({
|
|
449
545
|
author: message.author,
|
|
450
546
|
recipient: message.recipient,
|
|
@@ -480,7 +576,7 @@ var SwarmMessenger = class {
|
|
|
480
576
|
msg: networkMessage
|
|
481
577
|
}, {
|
|
482
578
|
F: __dxlog_file2,
|
|
483
|
-
L:
|
|
579
|
+
L: 123,
|
|
484
580
|
S: this,
|
|
485
581
|
C: (f, a) => f(...a)
|
|
486
582
|
});
|
|
@@ -495,16 +591,32 @@ var SwarmMessenger = class {
|
|
|
495
591
|
}
|
|
496
592
|
async _resolveAnswers(message) {
|
|
497
593
|
var _a2, _b, _c;
|
|
498
|
-
(0,
|
|
594
|
+
(0, import_invariant2.invariant)((_b = (_a2 = message.data) == null ? void 0 : _a2.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId", {
|
|
595
|
+
F: __dxlog_file2,
|
|
596
|
+
L: 135,
|
|
597
|
+
S: this,
|
|
598
|
+
A: [
|
|
599
|
+
"message.data?.answer?.offerMessageId",
|
|
600
|
+
"'No offerMessageId'"
|
|
601
|
+
]
|
|
602
|
+
});
|
|
499
603
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
500
604
|
if (offerRecord) {
|
|
501
605
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
502
|
-
(0,
|
|
606
|
+
(0, import_invariant2.invariant)((_c = message.data) == null ? void 0 : _c.answer, "No answer", {
|
|
607
|
+
F: __dxlog_file2,
|
|
608
|
+
L: 139,
|
|
609
|
+
S: this,
|
|
610
|
+
A: [
|
|
611
|
+
"message.data?.answer",
|
|
612
|
+
"'No answer'"
|
|
613
|
+
]
|
|
614
|
+
});
|
|
503
615
|
(0, import_log2.log)("resolving", {
|
|
504
616
|
answer: message.data.answer
|
|
505
617
|
}, {
|
|
506
618
|
F: __dxlog_file2,
|
|
507
|
-
L:
|
|
619
|
+
L: 140,
|
|
508
620
|
S: this,
|
|
509
621
|
C: (f, a) => f(...a)
|
|
510
622
|
});
|
|
@@ -512,7 +624,15 @@ var SwarmMessenger = class {
|
|
|
512
624
|
}
|
|
513
625
|
}
|
|
514
626
|
async _handleOffer({ author, recipient, message }) {
|
|
515
|
-
(0,
|
|
627
|
+
(0, import_invariant2.invariant)(message.data.offer, "No offer", {
|
|
628
|
+
F: __dxlog_file2,
|
|
629
|
+
L: 154,
|
|
630
|
+
S: this,
|
|
631
|
+
A: [
|
|
632
|
+
"message.data.offer",
|
|
633
|
+
"'No offer'"
|
|
634
|
+
]
|
|
635
|
+
});
|
|
516
636
|
const offerMessage = {
|
|
517
637
|
author,
|
|
518
638
|
recipient,
|
|
@@ -540,15 +660,31 @@ var SwarmMessenger = class {
|
|
|
540
660
|
err
|
|
541
661
|
}, {
|
|
542
662
|
F: __dxlog_file2,
|
|
543
|
-
L:
|
|
663
|
+
L: 174,
|
|
544
664
|
S: this,
|
|
545
665
|
C: (f, a) => f(...a)
|
|
546
666
|
});
|
|
547
667
|
}
|
|
548
668
|
}
|
|
549
669
|
async _handleSignal({ author, recipient, message }) {
|
|
550
|
-
(0,
|
|
551
|
-
|
|
670
|
+
(0, import_invariant2.invariant)(message.messageId, void 0, {
|
|
671
|
+
F: __dxlog_file2,
|
|
672
|
+
L: 187,
|
|
673
|
+
S: this,
|
|
674
|
+
A: [
|
|
675
|
+
"message.messageId",
|
|
676
|
+
""
|
|
677
|
+
]
|
|
678
|
+
});
|
|
679
|
+
(0, import_invariant2.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
680
|
+
F: __dxlog_file2,
|
|
681
|
+
L: 188,
|
|
682
|
+
S: this,
|
|
683
|
+
A: [
|
|
684
|
+
"message.data.signal || message.data.signalBatch",
|
|
685
|
+
"'Invalid message'"
|
|
686
|
+
]
|
|
687
|
+
});
|
|
552
688
|
const signalMessage = {
|
|
553
689
|
author,
|
|
554
690
|
recipient,
|
|
@@ -563,10 +699,10 @@ var SwarmMessenger = class {
|
|
|
563
699
|
};
|
|
564
700
|
|
|
565
701
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
566
|
-
var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
|
|
567
702
|
var import_async2 = require("@dxos/async");
|
|
568
703
|
var import_context3 = require("@dxos/context");
|
|
569
704
|
var import_errors2 = require("@dxos/errors");
|
|
705
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
570
706
|
var import_keys3 = require("@dxos/keys");
|
|
571
707
|
var import_log3 = require("@dxos/log");
|
|
572
708
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
@@ -612,7 +748,7 @@ var Peer = class {
|
|
|
612
748
|
sessionId: (_a2 = this.connection) == null ? void 0 : _a2.sessionId
|
|
613
749
|
}, {
|
|
614
750
|
F: __dxlog_file3,
|
|
615
|
-
L:
|
|
751
|
+
L: 106,
|
|
616
752
|
S: this,
|
|
617
753
|
C: (f, a) => f(...a)
|
|
618
754
|
});
|
|
@@ -627,7 +763,15 @@ var Peer = class {
|
|
|
627
763
|
}
|
|
628
764
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
629
765
|
if (!this.connection) {
|
|
630
|
-
(0,
|
|
766
|
+
(0, import_invariant3.invariant)(message.sessionId, void 0, {
|
|
767
|
+
F: __dxlog_file3,
|
|
768
|
+
L: 126,
|
|
769
|
+
S: this,
|
|
770
|
+
A: [
|
|
771
|
+
"message.sessionId",
|
|
772
|
+
""
|
|
773
|
+
]
|
|
774
|
+
});
|
|
631
775
|
const connection = this._createConnection(false, message.sessionId);
|
|
632
776
|
try {
|
|
633
777
|
await this._connectionLimiter.connecting(message.sessionId);
|
|
@@ -641,7 +785,7 @@ var Peer = class {
|
|
|
641
785
|
err
|
|
642
786
|
}, {
|
|
643
787
|
F: __dxlog_file3,
|
|
644
|
-
L:
|
|
788
|
+
L: 134,
|
|
645
789
|
S: this,
|
|
646
790
|
C: (f, a) => f(...a)
|
|
647
791
|
});
|
|
@@ -661,8 +805,24 @@ var Peer = class {
|
|
|
661
805
|
* Initiate a connection to the remote peer.
|
|
662
806
|
*/
|
|
663
807
|
async initiateConnection() {
|
|
664
|
-
(0,
|
|
665
|
-
|
|
808
|
+
(0, import_invariant3.invariant)(!this.initiating, "Initiation in progress.", {
|
|
809
|
+
F: __dxlog_file3,
|
|
810
|
+
L: 151,
|
|
811
|
+
S: this,
|
|
812
|
+
A: [
|
|
813
|
+
"!this.initiating",
|
|
814
|
+
"'Initiation in progress.'"
|
|
815
|
+
]
|
|
816
|
+
});
|
|
817
|
+
(0, import_invariant3.invariant)(!this.connection, "Already connected.", {
|
|
818
|
+
F: __dxlog_file3,
|
|
819
|
+
L: 152,
|
|
820
|
+
S: this,
|
|
821
|
+
A: [
|
|
822
|
+
"!this.connection",
|
|
823
|
+
"'Already connected.'"
|
|
824
|
+
]
|
|
825
|
+
});
|
|
666
826
|
const sessionId = import_keys3.PublicKey.random();
|
|
667
827
|
(0, import_log3.log)("initiating...", {
|
|
668
828
|
id: this.id,
|
|
@@ -671,7 +831,7 @@ var Peer = class {
|
|
|
671
831
|
sessionId
|
|
672
832
|
}, {
|
|
673
833
|
F: __dxlog_file3,
|
|
674
|
-
L:
|
|
834
|
+
L: 154,
|
|
675
835
|
S: this,
|
|
676
836
|
C: (f, a) => f(...a)
|
|
677
837
|
});
|
|
@@ -695,14 +855,14 @@ var Peer = class {
|
|
|
695
855
|
remoteId: this.id
|
|
696
856
|
}, {
|
|
697
857
|
F: __dxlog_file3,
|
|
698
|
-
L:
|
|
858
|
+
L: 169,
|
|
699
859
|
S: this,
|
|
700
860
|
C: (f, a) => f(...a)
|
|
701
861
|
});
|
|
702
862
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
703
863
|
(0, import_log3.log)("ignoring response", void 0, {
|
|
704
864
|
F: __dxlog_file3,
|
|
705
|
-
L:
|
|
865
|
+
L: 171,
|
|
706
866
|
S: this,
|
|
707
867
|
C: (f, a) => f(...a)
|
|
708
868
|
});
|
|
@@ -722,7 +882,7 @@ var Peer = class {
|
|
|
722
882
|
remoteId: this.id
|
|
723
883
|
}, {
|
|
724
884
|
F: __dxlog_file3,
|
|
725
|
-
L:
|
|
885
|
+
L: 182,
|
|
726
886
|
S: this,
|
|
727
887
|
C: (f, a) => f(...a)
|
|
728
888
|
});
|
|
@@ -746,11 +906,19 @@ var Peer = class {
|
|
|
746
906
|
sessionId
|
|
747
907
|
}, {
|
|
748
908
|
F: __dxlog_file3,
|
|
749
|
-
L:
|
|
909
|
+
L: 196,
|
|
750
910
|
S: this,
|
|
751
911
|
C: (f, a) => f(...a)
|
|
752
912
|
});
|
|
753
|
-
(0,
|
|
913
|
+
(0, import_invariant3.invariant)(!this.connection, "Already connected.", {
|
|
914
|
+
F: __dxlog_file3,
|
|
915
|
+
L: 203,
|
|
916
|
+
S: this,
|
|
917
|
+
A: [
|
|
918
|
+
"!this.connection",
|
|
919
|
+
"'Already connected.'"
|
|
920
|
+
]
|
|
921
|
+
});
|
|
754
922
|
const connection = new Connection(
|
|
755
923
|
this.topic,
|
|
756
924
|
this.localPeerId,
|
|
@@ -777,6 +945,18 @@ var Peer = class {
|
|
|
777
945
|
this._lastConnectionTime = Date.now();
|
|
778
946
|
this._callbacks.onConnected();
|
|
779
947
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
948
|
+
import_log3.log.trace("dxos.mesh.connection.connected", {
|
|
949
|
+
topic: this.topic,
|
|
950
|
+
localPeerId: this.localPeerId,
|
|
951
|
+
remotePeerId: this.id,
|
|
952
|
+
sessionId,
|
|
953
|
+
initiator
|
|
954
|
+
}, {
|
|
955
|
+
F: __dxlog_file3,
|
|
956
|
+
L: 229,
|
|
957
|
+
S: this,
|
|
958
|
+
C: (f, a) => f(...a)
|
|
959
|
+
});
|
|
780
960
|
break;
|
|
781
961
|
}
|
|
782
962
|
case ConnectionState.CLOSED: {
|
|
@@ -787,11 +967,31 @@ var Peer = class {
|
|
|
787
967
|
initiator
|
|
788
968
|
}, {
|
|
789
969
|
F: __dxlog_file3,
|
|
790
|
-
L:
|
|
970
|
+
L: 240,
|
|
971
|
+
S: this,
|
|
972
|
+
C: (f, a) => f(...a)
|
|
973
|
+
});
|
|
974
|
+
(0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
|
|
975
|
+
F: __dxlog_file3,
|
|
976
|
+
L: 241,
|
|
977
|
+
S: this,
|
|
978
|
+
A: [
|
|
979
|
+
"this.connection === connection",
|
|
980
|
+
"'Connection mismatch (race condition).'"
|
|
981
|
+
]
|
|
982
|
+
});
|
|
983
|
+
import_log3.log.trace("dxos.mesh.connection.closed", {
|
|
984
|
+
topic: this.topic,
|
|
985
|
+
localPeerId: this.localPeerId,
|
|
986
|
+
remotePeerId: this.id,
|
|
987
|
+
sessionId,
|
|
988
|
+
initiator
|
|
989
|
+
}, {
|
|
990
|
+
F: __dxlog_file3,
|
|
991
|
+
L: 243,
|
|
791
992
|
S: this,
|
|
792
993
|
C: (f, a) => f(...a)
|
|
793
994
|
});
|
|
794
|
-
(0, import_tiny_invariant3.default)(this.connection === connection, "Connection mismatch (race condition).");
|
|
795
995
|
if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
|
|
796
996
|
this._availableAfter = 0;
|
|
797
997
|
} else {
|
|
@@ -818,7 +1018,20 @@ var Peer = class {
|
|
|
818
1018
|
err
|
|
819
1019
|
}, {
|
|
820
1020
|
F: __dxlog_file3,
|
|
821
|
-
L:
|
|
1021
|
+
L: 277,
|
|
1022
|
+
S: this,
|
|
1023
|
+
C: (f, a) => f(...a)
|
|
1024
|
+
});
|
|
1025
|
+
import_log3.log.trace("dxos.mesh.connection.error", {
|
|
1026
|
+
topic: this.topic,
|
|
1027
|
+
localPeerId: this.localPeerId,
|
|
1028
|
+
remotePeerId: this.id,
|
|
1029
|
+
sessionId,
|
|
1030
|
+
initiator,
|
|
1031
|
+
err
|
|
1032
|
+
}, {
|
|
1033
|
+
F: __dxlog_file3,
|
|
1034
|
+
L: 278,
|
|
822
1035
|
S: this,
|
|
823
1036
|
C: (f, a) => f(...a)
|
|
824
1037
|
});
|
|
@@ -837,7 +1050,7 @@ var Peer = class {
|
|
|
837
1050
|
sessionId: connection.sessionId
|
|
838
1051
|
}, {
|
|
839
1052
|
F: __dxlog_file3,
|
|
840
|
-
L:
|
|
1053
|
+
L: 301,
|
|
841
1054
|
S: this,
|
|
842
1055
|
C: (f, a) => f(...a)
|
|
843
1056
|
});
|
|
@@ -847,7 +1060,7 @@ var Peer = class {
|
|
|
847
1060
|
sessionId: connection.sessionId
|
|
848
1061
|
}, {
|
|
849
1062
|
F: __dxlog_file3,
|
|
850
|
-
L:
|
|
1063
|
+
L: 307,
|
|
851
1064
|
S: this,
|
|
852
1065
|
C: (f, a) => f(...a)
|
|
853
1066
|
});
|
|
@@ -858,7 +1071,7 @@ var Peer = class {
|
|
|
858
1071
|
message
|
|
859
1072
|
}, {
|
|
860
1073
|
F: __dxlog_file3,
|
|
861
|
-
L:
|
|
1074
|
+
L: 312,
|
|
862
1075
|
S: this,
|
|
863
1076
|
C: (f, a) => f(...a)
|
|
864
1077
|
});
|
|
@@ -874,7 +1087,7 @@ var Peer = class {
|
|
|
874
1087
|
topic: this.topic
|
|
875
1088
|
}, {
|
|
876
1089
|
F: __dxlog_file3,
|
|
877
|
-
L:
|
|
1090
|
+
L: 322,
|
|
878
1091
|
S: this,
|
|
879
1092
|
C: (f, a) => f(...a)
|
|
880
1093
|
});
|
|
@@ -939,7 +1152,7 @@ var Swarm = class {
|
|
|
939
1152
|
}
|
|
940
1153
|
}), {
|
|
941
1154
|
F: __dxlog_file4,
|
|
942
|
-
L:
|
|
1155
|
+
L: 87,
|
|
943
1156
|
S: this,
|
|
944
1157
|
C: (f, a) => f(...a)
|
|
945
1158
|
});
|
|
@@ -947,7 +1160,7 @@ var Swarm = class {
|
|
|
947
1160
|
peerId: _ownPeerId
|
|
948
1161
|
}, {
|
|
949
1162
|
F: __dxlog_file4,
|
|
950
|
-
L:
|
|
1163
|
+
L: 91,
|
|
951
1164
|
S: this,
|
|
952
1165
|
C: (f, a) => f(...a)
|
|
953
1166
|
});
|
|
@@ -962,7 +1175,7 @@ var Swarm = class {
|
|
|
962
1175
|
id: this._instanceId
|
|
963
1176
|
}), {
|
|
964
1177
|
F: __dxlog_file4,
|
|
965
|
-
L:
|
|
1178
|
+
L: 100,
|
|
966
1179
|
S: this,
|
|
967
1180
|
C: (f, a) => f(...a)
|
|
968
1181
|
});
|
|
@@ -983,7 +1196,15 @@ var Swarm = class {
|
|
|
983
1196
|
return this._topic;
|
|
984
1197
|
}
|
|
985
1198
|
async open() {
|
|
986
|
-
(0,
|
|
1199
|
+
(0, import_invariant4.invariant)(!this._listeningHandle, void 0, {
|
|
1200
|
+
F: __dxlog_file4,
|
|
1201
|
+
L: 127,
|
|
1202
|
+
S: this,
|
|
1203
|
+
A: [
|
|
1204
|
+
"!this._listeningHandle",
|
|
1205
|
+
""
|
|
1206
|
+
]
|
|
1207
|
+
});
|
|
987
1208
|
this._listeningHandle = await this._messenger.listen({
|
|
988
1209
|
peerId: this._ownPeerId,
|
|
989
1210
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
@@ -992,7 +1213,7 @@ var Swarm = class {
|
|
|
992
1213
|
err
|
|
993
1214
|
}, {
|
|
994
1215
|
F: __dxlog_file4,
|
|
995
|
-
L:
|
|
1216
|
+
L: 134,
|
|
996
1217
|
S: this,
|
|
997
1218
|
C: (f, a) => f(...a)
|
|
998
1219
|
}));
|
|
@@ -1003,7 +1224,7 @@ var Swarm = class {
|
|
|
1003
1224
|
var _a2;
|
|
1004
1225
|
(0, import_log4.log)("destroying...", void 0, {
|
|
1005
1226
|
F: __dxlog_file4,
|
|
1006
|
-
L:
|
|
1227
|
+
L: 140,
|
|
1007
1228
|
S: this,
|
|
1008
1229
|
C: (f, a) => f(...a)
|
|
1009
1230
|
});
|
|
@@ -1014,13 +1235,21 @@ var Swarm = class {
|
|
|
1014
1235
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
1015
1236
|
(0, import_log4.log)("destroyed", void 0, {
|
|
1016
1237
|
F: __dxlog_file4,
|
|
1017
|
-
L:
|
|
1238
|
+
L: 147,
|
|
1018
1239
|
S: this,
|
|
1019
1240
|
C: (f, a) => f(...a)
|
|
1020
1241
|
});
|
|
1021
1242
|
}
|
|
1022
1243
|
async setTopology(topology) {
|
|
1023
|
-
(0,
|
|
1244
|
+
(0, import_invariant4.invariant)(!this._ctx.disposed, "Swarm is offline", {
|
|
1245
|
+
F: __dxlog_file4,
|
|
1246
|
+
L: 151,
|
|
1247
|
+
S: this,
|
|
1248
|
+
A: [
|
|
1249
|
+
"!this._ctx.disposed",
|
|
1250
|
+
"'Swarm is offline'"
|
|
1251
|
+
]
|
|
1252
|
+
});
|
|
1024
1253
|
if (topology === this._topology) {
|
|
1025
1254
|
return;
|
|
1026
1255
|
}
|
|
@@ -1029,7 +1258,7 @@ var Swarm = class {
|
|
|
1029
1258
|
topology: getClassName(topology)
|
|
1030
1259
|
}, {
|
|
1031
1260
|
F: __dxlog_file4,
|
|
1032
|
-
L:
|
|
1261
|
+
L: 155,
|
|
1033
1262
|
S: this,
|
|
1034
1263
|
C: (f, a) => f(...a)
|
|
1035
1264
|
});
|
|
@@ -1044,14 +1273,14 @@ var Swarm = class {
|
|
|
1044
1273
|
swarmEvent
|
|
1045
1274
|
}, {
|
|
1046
1275
|
F: __dxlog_file4,
|
|
1047
|
-
L:
|
|
1276
|
+
L: 168,
|
|
1048
1277
|
S: this,
|
|
1049
1278
|
C: (f, a) => f(...a)
|
|
1050
1279
|
});
|
|
1051
1280
|
if (this._ctx.disposed) {
|
|
1052
1281
|
(0, import_log4.log)("swarm event ignored for disposed swarm", void 0, {
|
|
1053
1282
|
F: __dxlog_file4,
|
|
1054
|
-
L:
|
|
1283
|
+
L: 171,
|
|
1055
1284
|
S: this,
|
|
1056
1285
|
C: (f, a) => f(...a)
|
|
1057
1286
|
});
|
|
@@ -1063,7 +1292,7 @@ var Swarm = class {
|
|
|
1063
1292
|
peerId
|
|
1064
1293
|
}, {
|
|
1065
1294
|
F: __dxlog_file4,
|
|
1066
|
-
L:
|
|
1295
|
+
L: 177,
|
|
1067
1296
|
S: this,
|
|
1068
1297
|
C: (f, a) => f(...a)
|
|
1069
1298
|
});
|
|
@@ -1078,7 +1307,7 @@ var Swarm = class {
|
|
|
1078
1307
|
if (((_a2 = peer.connection) == null ? void 0 : _a2.state) !== ConnectionState.CONNECTED) {
|
|
1079
1308
|
void this._destroyPeer(peer.id).catch((err) => import_log4.log.catch(err, void 0, {
|
|
1080
1309
|
F: __dxlog_file4,
|
|
1081
|
-
L:
|
|
1310
|
+
L: 188,
|
|
1082
1311
|
S: this,
|
|
1083
1312
|
C: (f, a) => f(...a)
|
|
1084
1313
|
}));
|
|
@@ -1093,14 +1322,14 @@ var Swarm = class {
|
|
|
1093
1322
|
message
|
|
1094
1323
|
}, {
|
|
1095
1324
|
F: __dxlog_file4,
|
|
1096
|
-
L:
|
|
1325
|
+
L: 198,
|
|
1097
1326
|
S: this,
|
|
1098
1327
|
C: (f, a) => f(...a)
|
|
1099
1328
|
});
|
|
1100
1329
|
if (this._ctx.disposed) {
|
|
1101
1330
|
(0, import_log4.log)("ignored for disposed swarm", void 0, {
|
|
1102
1331
|
F: __dxlog_file4,
|
|
1103
|
-
L:
|
|
1332
|
+
L: 200,
|
|
1104
1333
|
S: this,
|
|
1105
1334
|
C: (f, a) => f(...a)
|
|
1106
1335
|
});
|
|
@@ -1108,13 +1337,21 @@ var Swarm = class {
|
|
|
1108
1337
|
accept: false
|
|
1109
1338
|
};
|
|
1110
1339
|
}
|
|
1111
|
-
(0,
|
|
1340
|
+
(0, import_invariant4.invariant)(message.author, void 0, {
|
|
1341
|
+
F: __dxlog_file4,
|
|
1342
|
+
L: 205,
|
|
1343
|
+
S: this,
|
|
1344
|
+
A: [
|
|
1345
|
+
"message.author",
|
|
1346
|
+
""
|
|
1347
|
+
]
|
|
1348
|
+
});
|
|
1112
1349
|
if (!((_a2 = message.recipient) == null ? void 0 : _a2.equals(this._ownPeerId))) {
|
|
1113
1350
|
(0, import_log4.log)("rejecting offer with incorrect peerId", {
|
|
1114
1351
|
message
|
|
1115
1352
|
}, {
|
|
1116
1353
|
F: __dxlog_file4,
|
|
1117
|
-
L:
|
|
1354
|
+
L: 207,
|
|
1118
1355
|
S: this,
|
|
1119
1356
|
C: (f, a) => f(...a)
|
|
1120
1357
|
});
|
|
@@ -1127,7 +1364,7 @@ var Swarm = class {
|
|
|
1127
1364
|
message
|
|
1128
1365
|
}, {
|
|
1129
1366
|
F: __dxlog_file4,
|
|
1130
|
-
L:
|
|
1367
|
+
L: 211,
|
|
1131
1368
|
S: this,
|
|
1132
1369
|
C: (f, a) => f(...a)
|
|
1133
1370
|
});
|
|
@@ -1146,22 +1383,46 @@ var Swarm = class {
|
|
|
1146
1383
|
message
|
|
1147
1384
|
}, {
|
|
1148
1385
|
F: __dxlog_file4,
|
|
1149
|
-
L:
|
|
1386
|
+
L: 222,
|
|
1150
1387
|
S: this,
|
|
1151
1388
|
C: (f, a) => f(...a)
|
|
1152
1389
|
});
|
|
1153
1390
|
if (this._ctx.disposed) {
|
|
1154
1391
|
import_log4.log.info("ignored for offline swarm", void 0, {
|
|
1155
1392
|
F: __dxlog_file4,
|
|
1156
|
-
L:
|
|
1393
|
+
L: 224,
|
|
1157
1394
|
S: this,
|
|
1158
1395
|
C: (f, a) => f(...a)
|
|
1159
1396
|
});
|
|
1160
1397
|
return;
|
|
1161
1398
|
}
|
|
1162
|
-
(0,
|
|
1163
|
-
|
|
1164
|
-
|
|
1399
|
+
(0, import_invariant4.invariant)((_a2 = message.recipient) == null ? void 0 : _a2.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1400
|
+
F: __dxlog_file4,
|
|
1401
|
+
L: 227,
|
|
1402
|
+
S: this,
|
|
1403
|
+
A: [
|
|
1404
|
+
"message.recipient?.equals(this._ownPeerId)",
|
|
1405
|
+
"`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
|
|
1406
|
+
]
|
|
1407
|
+
});
|
|
1408
|
+
(0, import_invariant4.invariant)((_b = message.topic) == null ? void 0 : _b.equals(this._topic), void 0, {
|
|
1409
|
+
F: __dxlog_file4,
|
|
1410
|
+
L: 231,
|
|
1411
|
+
S: this,
|
|
1412
|
+
A: [
|
|
1413
|
+
"message.topic?.equals(this._topic)",
|
|
1414
|
+
""
|
|
1415
|
+
]
|
|
1416
|
+
});
|
|
1417
|
+
(0, import_invariant4.invariant)(message.author, void 0, {
|
|
1418
|
+
F: __dxlog_file4,
|
|
1419
|
+
L: 232,
|
|
1420
|
+
S: this,
|
|
1421
|
+
A: [
|
|
1422
|
+
"message.author",
|
|
1423
|
+
""
|
|
1424
|
+
]
|
|
1425
|
+
});
|
|
1165
1426
|
const peer = this._getOrCreatePeer(message.author);
|
|
1166
1427
|
await peer.onSignal(message);
|
|
1167
1428
|
}
|
|
@@ -1213,7 +1474,15 @@ var Swarm = class {
|
|
|
1213
1474
|
return peer;
|
|
1214
1475
|
}
|
|
1215
1476
|
async _destroyPeer(peerId) {
|
|
1216
|
-
(0,
|
|
1477
|
+
(0, import_invariant4.invariant)(this._peers.has(peerId), void 0, {
|
|
1478
|
+
F: __dxlog_file4,
|
|
1479
|
+
L: 302,
|
|
1480
|
+
S: this,
|
|
1481
|
+
A: [
|
|
1482
|
+
"this._peers.has(peerId)",
|
|
1483
|
+
""
|
|
1484
|
+
]
|
|
1485
|
+
});
|
|
1217
1486
|
await this._peers.get(peerId).destroy();
|
|
1218
1487
|
this._peers.delete(peerId);
|
|
1219
1488
|
}
|
|
@@ -1234,7 +1503,7 @@ var Swarm = class {
|
|
|
1234
1503
|
} catch (err) {
|
|
1235
1504
|
(0, import_log4.log)("initiation error", err, {
|
|
1236
1505
|
F: __dxlog_file4,
|
|
1237
|
-
L:
|
|
1506
|
+
L: 328,
|
|
1238
1507
|
S: this,
|
|
1239
1508
|
C: (f, a) => f(...a)
|
|
1240
1509
|
});
|
|
@@ -1262,7 +1531,7 @@ var Swarm = class {
|
|
|
1262
1531
|
remoteId
|
|
1263
1532
|
}, {
|
|
1264
1533
|
F: __dxlog_file4,
|
|
1265
|
-
L:
|
|
1534
|
+
L: 355,
|
|
1266
1535
|
S: this,
|
|
1267
1536
|
C: (f, a) => f(...a)
|
|
1268
1537
|
});
|
|
@@ -1279,7 +1548,7 @@ var Swarm = class {
|
|
|
1279
1548
|
remoteId
|
|
1280
1549
|
}, {
|
|
1281
1550
|
F: __dxlog_file4,
|
|
1282
|
-
L:
|
|
1551
|
+
L: 369,
|
|
1283
1552
|
S: this,
|
|
1284
1553
|
C: (f, a) => f(...a)
|
|
1285
1554
|
});
|
|
@@ -1289,7 +1558,7 @@ var Swarm = class {
|
|
|
1289
1558
|
remoteId
|
|
1290
1559
|
}, {
|
|
1291
1560
|
F: __dxlog_file4,
|
|
1292
|
-
L:
|
|
1561
|
+
L: 372,
|
|
1293
1562
|
S: this,
|
|
1294
1563
|
C: (f, a) => f(...a)
|
|
1295
1564
|
});
|
|
@@ -1399,6 +1668,7 @@ var SwarmMapper = class {
|
|
|
1399
1668
|
var import_async5 = require("@dxos/async");
|
|
1400
1669
|
var import_context5 = require("@dxos/context");
|
|
1401
1670
|
var import_errors3 = require("@dxos/errors");
|
|
1671
|
+
var import_invariant5 = require("@dxos/invariant");
|
|
1402
1672
|
var import_keys6 = require("@dxos/keys");
|
|
1403
1673
|
var import_log6 = require("@dxos/log");
|
|
1404
1674
|
var import_util4 = require("@dxos/util");
|
|
@@ -1422,9 +1692,9 @@ var ConnectionLimiter = class {
|
|
|
1422
1692
|
* @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
|
|
1423
1693
|
*/
|
|
1424
1694
|
async connecting(sessionId) {
|
|
1425
|
-
(0,
|
|
1695
|
+
(0, import_invariant5.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
1426
1696
|
F: __dxlog_file6,
|
|
1427
|
-
L:
|
|
1697
|
+
L: 48,
|
|
1428
1698
|
S: this,
|
|
1429
1699
|
A: [
|
|
1430
1700
|
"!this._waitingPromises.has(sessionId)",
|
|
@@ -1435,7 +1705,7 @@ var ConnectionLimiter = class {
|
|
|
1435
1705
|
sessionId
|
|
1436
1706
|
}, {
|
|
1437
1707
|
F: __dxlog_file6,
|
|
1438
|
-
L:
|
|
1708
|
+
L: 49,
|
|
1439
1709
|
S: this,
|
|
1440
1710
|
C: (f, a) => f(...a)
|
|
1441
1711
|
});
|
|
@@ -1450,7 +1720,7 @@ var ConnectionLimiter = class {
|
|
|
1450
1720
|
sessionId
|
|
1451
1721
|
}, {
|
|
1452
1722
|
F: __dxlog_file6,
|
|
1453
|
-
L:
|
|
1723
|
+
L: 57,
|
|
1454
1724
|
S: this,
|
|
1455
1725
|
C: (f, a) => f(...a)
|
|
1456
1726
|
});
|
|
@@ -1463,7 +1733,7 @@ var ConnectionLimiter = class {
|
|
|
1463
1733
|
sessionId
|
|
1464
1734
|
}, {
|
|
1465
1735
|
F: __dxlog_file6,
|
|
1466
|
-
L:
|
|
1736
|
+
L: 64,
|
|
1467
1737
|
S: this,
|
|
1468
1738
|
C: (f, a) => f(...a)
|
|
1469
1739
|
});
|
|
@@ -1595,7 +1865,7 @@ var NetworkManager = class {
|
|
|
1595
1865
|
id: this._instanceId
|
|
1596
1866
|
}), {
|
|
1597
1867
|
F: __dxlog_file7,
|
|
1598
|
-
L:
|
|
1868
|
+
L: 130,
|
|
1599
1869
|
S: this,
|
|
1600
1870
|
C: (f, a) => f(...a)
|
|
1601
1871
|
});
|
|
@@ -1605,7 +1875,7 @@ var NetworkManager = class {
|
|
|
1605
1875
|
id: this._instanceId
|
|
1606
1876
|
}), {
|
|
1607
1877
|
F: __dxlog_file7,
|
|
1608
|
-
L:
|
|
1878
|
+
L: 133,
|
|
1609
1879
|
S: this,
|
|
1610
1880
|
C: (f, a) => f(...a)
|
|
1611
1881
|
});
|
|
@@ -1615,7 +1885,7 @@ var NetworkManager = class {
|
|
|
1615
1885
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1616
1886
|
(0, import_log7.log)(err, void 0, {
|
|
1617
1887
|
F: __dxlog_file7,
|
|
1618
|
-
L:
|
|
1888
|
+
L: 139,
|
|
1619
1889
|
S: this,
|
|
1620
1890
|
C: (f, a) => f(...a)
|
|
1621
1891
|
});
|
|
@@ -1629,10 +1899,42 @@ var NetworkManager = class {
|
|
|
1629
1899
|
*/
|
|
1630
1900
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1631
1901
|
var _a2;
|
|
1632
|
-
(0,
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1902
|
+
(0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(topic), void 0, {
|
|
1903
|
+
F: __dxlog_file7,
|
|
1904
|
+
L: 157,
|
|
1905
|
+
S: this,
|
|
1906
|
+
A: [
|
|
1907
|
+
"PublicKey.isPublicKey(topic)",
|
|
1908
|
+
""
|
|
1909
|
+
]
|
|
1910
|
+
});
|
|
1911
|
+
(0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(peerId), void 0, {
|
|
1912
|
+
F: __dxlog_file7,
|
|
1913
|
+
L: 158,
|
|
1914
|
+
S: this,
|
|
1915
|
+
A: [
|
|
1916
|
+
"PublicKey.isPublicKey(peerId)",
|
|
1917
|
+
""
|
|
1918
|
+
]
|
|
1919
|
+
});
|
|
1920
|
+
(0, import_invariant6.invariant)(topology, void 0, {
|
|
1921
|
+
F: __dxlog_file7,
|
|
1922
|
+
L: 159,
|
|
1923
|
+
S: this,
|
|
1924
|
+
A: [
|
|
1925
|
+
"topology",
|
|
1926
|
+
""
|
|
1927
|
+
]
|
|
1928
|
+
});
|
|
1929
|
+
(0, import_invariant6.invariant)(typeof protocol === "function", void 0, {
|
|
1930
|
+
F: __dxlog_file7,
|
|
1931
|
+
L: 160,
|
|
1932
|
+
S: this,
|
|
1933
|
+
A: [
|
|
1934
|
+
"typeof protocol === 'function'",
|
|
1935
|
+
""
|
|
1936
|
+
]
|
|
1937
|
+
});
|
|
1636
1938
|
if (this._swarms.has(topic)) {
|
|
1637
1939
|
throw new Error(`Already connected to swarm: ${import_keys8.PublicKey.from(topic)}`);
|
|
1638
1940
|
}
|
|
@@ -1642,7 +1944,7 @@ var NetworkManager = class {
|
|
|
1642
1944
|
topology: topology.toString()
|
|
1643
1945
|
}, {
|
|
1644
1946
|
F: __dxlog_file7,
|
|
1645
|
-
L:
|
|
1947
|
+
L: 165,
|
|
1646
1948
|
S: this,
|
|
1647
1949
|
C: (f, a) => f(...a)
|
|
1648
1950
|
});
|
|
@@ -1652,7 +1954,7 @@ var NetworkManager = class {
|
|
|
1652
1954
|
error
|
|
1653
1955
|
}, {
|
|
1654
1956
|
F: __dxlog_file7,
|
|
1655
|
-
L:
|
|
1957
|
+
L: 178,
|
|
1656
1958
|
S: this,
|
|
1657
1959
|
C: (f, a) => f(...a)
|
|
1658
1960
|
});
|
|
@@ -1665,7 +1967,7 @@ var NetworkManager = class {
|
|
|
1665
1967
|
peerId
|
|
1666
1968
|
}).catch((error) => import_log7.log.catch(error, void 0, {
|
|
1667
1969
|
F: __dxlog_file7,
|
|
1668
|
-
L:
|
|
1970
|
+
L: 187,
|
|
1669
1971
|
S: this,
|
|
1670
1972
|
C: (f, a) => f(...a)
|
|
1671
1973
|
}));
|
|
@@ -1676,7 +1978,7 @@ var NetworkManager = class {
|
|
|
1676
1978
|
count: this._swarms.size
|
|
1677
1979
|
}, {
|
|
1678
1980
|
F: __dxlog_file7,
|
|
1679
|
-
L:
|
|
1981
|
+
L: 191,
|
|
1680
1982
|
S: this,
|
|
1681
1983
|
C: (f, a) => f(...a)
|
|
1682
1984
|
});
|
|
@@ -1696,7 +1998,7 @@ var NetworkManager = class {
|
|
|
1696
1998
|
topic: import_keys8.PublicKey.from(topic)
|
|
1697
1999
|
}, {
|
|
1698
2000
|
F: __dxlog_file7,
|
|
1699
|
-
L:
|
|
2001
|
+
L: 207,
|
|
1700
2002
|
S: this,
|
|
1701
2003
|
C: (f, a) => f(...a)
|
|
1702
2004
|
});
|
|
@@ -1717,7 +2019,7 @@ var NetworkManager = class {
|
|
|
1717
2019
|
count: this._swarms.size
|
|
1718
2020
|
}, {
|
|
1719
2021
|
F: __dxlog_file7,
|
|
1720
|
-
L:
|
|
2022
|
+
L: 221,
|
|
1721
2023
|
S: this,
|
|
1722
2024
|
C: (f, a) => f(...a)
|
|
1723
2025
|
});
|
|
@@ -1751,17 +2053,34 @@ var NetworkManager = class {
|
|
|
1751
2053
|
};
|
|
1752
2054
|
|
|
1753
2055
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1754
|
-
var
|
|
2056
|
+
var import_invariant7 = require("@dxos/invariant");
|
|
2057
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
1755
2058
|
var FullyConnectedTopology = class {
|
|
1756
2059
|
toString() {
|
|
1757
2060
|
return "FullyConnectedTopology";
|
|
1758
2061
|
}
|
|
1759
2062
|
init(controller) {
|
|
1760
|
-
(0,
|
|
2063
|
+
(0, import_invariant7.invariant)(!this._controller, "Already initialized", {
|
|
2064
|
+
F: __dxlog_file8,
|
|
2065
|
+
L: 18,
|
|
2066
|
+
S: this,
|
|
2067
|
+
A: [
|
|
2068
|
+
"!this._controller",
|
|
2069
|
+
"'Already initialized'"
|
|
2070
|
+
]
|
|
2071
|
+
});
|
|
1761
2072
|
this._controller = controller;
|
|
1762
2073
|
}
|
|
1763
2074
|
update() {
|
|
1764
|
-
(0,
|
|
2075
|
+
(0, import_invariant7.invariant)(this._controller, "Not initialized", {
|
|
2076
|
+
F: __dxlog_file8,
|
|
2077
|
+
L: 23,
|
|
2078
|
+
S: this,
|
|
2079
|
+
A: [
|
|
2080
|
+
"this._controller",
|
|
2081
|
+
"'Not initialized'"
|
|
2082
|
+
]
|
|
2083
|
+
});
|
|
1765
2084
|
const { candidates: discovered } = this._controller.getState();
|
|
1766
2085
|
for (const peer of discovered) {
|
|
1767
2086
|
this._controller.connect(peer);
|
|
@@ -1775,19 +2094,19 @@ var FullyConnectedTopology = class {
|
|
|
1775
2094
|
};
|
|
1776
2095
|
|
|
1777
2096
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1778
|
-
var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
|
|
1779
2097
|
var import_xor_distance = __toESM(require("xor-distance"));
|
|
2098
|
+
var import_invariant8 = require("@dxos/invariant");
|
|
1780
2099
|
var import_log8 = require("@dxos/log");
|
|
1781
2100
|
|
|
1782
2101
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1783
|
-
var
|
|
2102
|
+
var import_invariant9 = require("@dxos/invariant");
|
|
1784
2103
|
var import_log9 = require("@dxos/log");
|
|
1785
2104
|
|
|
1786
2105
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1787
2106
|
var import_node_stream = require("node:stream");
|
|
1788
|
-
var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
|
|
1789
2107
|
var import_async8 = require("@dxos/async");
|
|
1790
2108
|
var import_debug4 = require("@dxos/debug");
|
|
2109
|
+
var import_invariant10 = require("@dxos/invariant");
|
|
1791
2110
|
var import_keys9 = require("@dxos/keys");
|
|
1792
2111
|
var import_log10 = require("@dxos/log");
|
|
1793
2112
|
var import_util7 = require("@dxos/util");
|
|
@@ -1801,7 +2120,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
1801
2120
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1802
2121
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1803
2122
|
}
|
|
1804
|
-
var
|
|
2123
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
1805
2124
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1806
2125
|
var createStreamDelay = (delay) => {
|
|
1807
2126
|
return new import_node_stream.Transform({
|
|
@@ -1827,17 +2146,25 @@ var _MemoryTransport = class {
|
|
|
1827
2146
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1828
2147
|
this._destroyed = false;
|
|
1829
2148
|
(0, import_log10.log)("creating", void 0, {
|
|
1830
|
-
F:
|
|
2149
|
+
F: __dxlog_file9,
|
|
1831
2150
|
L: 64,
|
|
1832
2151
|
S: this,
|
|
1833
2152
|
C: (f, a) => f(...a)
|
|
1834
2153
|
});
|
|
1835
|
-
(0,
|
|
2154
|
+
(0, import_invariant10.invariant)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2155
|
+
F: __dxlog_file9,
|
|
2156
|
+
L: 66,
|
|
2157
|
+
S: this,
|
|
2158
|
+
A: [
|
|
2159
|
+
"!MemoryTransport._connections.has(this._instanceId)",
|
|
2160
|
+
"'Duplicate memory connection'"
|
|
2161
|
+
]
|
|
2162
|
+
});
|
|
1836
2163
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1837
2164
|
if (this.options.initiator) {
|
|
1838
2165
|
setTimeout(async () => {
|
|
1839
2166
|
(0, import_log10.log)("sending signal", void 0, {
|
|
1840
|
-
F:
|
|
2167
|
+
F: __dxlog_file9,
|
|
1841
2168
|
L: 73,
|
|
1842
2169
|
S: this,
|
|
1843
2170
|
C: (f, a) => f(...a)
|
|
@@ -1866,11 +2193,19 @@ var _MemoryTransport = class {
|
|
|
1866
2193
|
this.closed.emit();
|
|
1867
2194
|
return;
|
|
1868
2195
|
}
|
|
1869
|
-
(0,
|
|
2196
|
+
(0, import_invariant10.invariant)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2197
|
+
F: __dxlog_file9,
|
|
2198
|
+
L: 99,
|
|
2199
|
+
S: this,
|
|
2200
|
+
A: [
|
|
2201
|
+
"!this._remoteConnection._remoteConnection",
|
|
2202
|
+
"`Remote already connected: ${this._remoteInstanceId}`"
|
|
2203
|
+
]
|
|
2204
|
+
});
|
|
1870
2205
|
this._remoteConnection._remoteConnection = this;
|
|
1871
2206
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1872
2207
|
(0, import_log10.log)("connected", void 0, {
|
|
1873
|
-
F:
|
|
2208
|
+
F: __dxlog_file9,
|
|
1874
2209
|
L: 103,
|
|
1875
2210
|
S: this,
|
|
1876
2211
|
C: (f, a) => f(...a)
|
|
@@ -1888,7 +2223,7 @@ var _MemoryTransport = class {
|
|
|
1888
2223
|
}
|
|
1889
2224
|
async destroy() {
|
|
1890
2225
|
(0, import_log10.log)("closing", void 0, {
|
|
1891
|
-
F:
|
|
2226
|
+
F: __dxlog_file9,
|
|
1892
2227
|
L: 124,
|
|
1893
2228
|
S: this,
|
|
1894
2229
|
C: (f, a) => f(...a)
|
|
@@ -1897,7 +2232,7 @@ var _MemoryTransport = class {
|
|
|
1897
2232
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
1898
2233
|
if (this._remoteConnection) {
|
|
1899
2234
|
(0, import_log10.log)("closing", void 0, {
|
|
1900
|
-
F:
|
|
2235
|
+
F: __dxlog_file9,
|
|
1901
2236
|
L: 129,
|
|
1902
2237
|
S: this,
|
|
1903
2238
|
C: (f, a) => f(...a)
|
|
@@ -1910,7 +2245,7 @@ var _MemoryTransport = class {
|
|
|
1910
2245
|
this._remoteConnection._remoteConnection = void 0;
|
|
1911
2246
|
this._remoteConnection = void 0;
|
|
1912
2247
|
(0, import_log10.log)("closed", void 0, {
|
|
1913
|
-
F:
|
|
2248
|
+
F: __dxlog_file9,
|
|
1914
2249
|
L: 147,
|
|
1915
2250
|
S: this,
|
|
1916
2251
|
C: (f, a) => f(...a)
|
|
@@ -1918,7 +2253,7 @@ var _MemoryTransport = class {
|
|
|
1918
2253
|
}
|
|
1919
2254
|
this.closed.emit();
|
|
1920
2255
|
(0, import_log10.log)("closed", void 0, {
|
|
1921
|
-
F:
|
|
2256
|
+
F: __dxlog_file9,
|
|
1922
2257
|
L: 151,
|
|
1923
2258
|
S: this,
|
|
1924
2259
|
C: (f, a) => f(...a)
|
|
@@ -1928,7 +2263,7 @@ var _MemoryTransport = class {
|
|
|
1928
2263
|
(0, import_log10.log)("received signal", {
|
|
1929
2264
|
payload
|
|
1930
2265
|
}, {
|
|
1931
|
-
F:
|
|
2266
|
+
F: __dxlog_file9,
|
|
1932
2267
|
L: 155,
|
|
1933
2268
|
S: this,
|
|
1934
2269
|
C: (f, a) => f(...a)
|
|
@@ -1955,9 +2290,9 @@ _ts_decorate4([
|
|
|
1955
2290
|
|
|
1956
2291
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1957
2292
|
var import_simple_peer = __toESM(require("simple-peer"));
|
|
1958
|
-
var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
|
|
1959
2293
|
var import_async9 = require("@dxos/async");
|
|
1960
2294
|
var import_debug5 = require("@dxos/debug");
|
|
2295
|
+
var import_invariant11 = require("@dxos/invariant");
|
|
1961
2296
|
var import_keys10 = require("@dxos/keys");
|
|
1962
2297
|
var import_log11 = require("@dxos/log");
|
|
1963
2298
|
var import_protocols5 = require("@dxos/protocols");
|
|
@@ -1970,7 +2305,7 @@ try {
|
|
|
1970
2305
|
}
|
|
1971
2306
|
|
|
1972
2307
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1973
|
-
var
|
|
2308
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
|
|
1974
2309
|
var WebRTCTransport = class {
|
|
1975
2310
|
constructor(params) {
|
|
1976
2311
|
var _a2;
|
|
@@ -1983,13 +2318,13 @@ var WebRTCTransport = class {
|
|
|
1983
2318
|
import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
|
|
1984
2319
|
id: this._instanceId
|
|
1985
2320
|
}), {
|
|
1986
|
-
F:
|
|
2321
|
+
F: __dxlog_file10,
|
|
1987
2322
|
L: 39,
|
|
1988
2323
|
S: this,
|
|
1989
2324
|
C: (f, a) => f(...a)
|
|
1990
2325
|
});
|
|
1991
2326
|
(0, import_log11.log)("created connection", params, {
|
|
1992
|
-
F:
|
|
2327
|
+
F: __dxlog_file10,
|
|
1993
2328
|
L: 40,
|
|
1994
2329
|
S: this,
|
|
1995
2330
|
C: (f, a) => f(...a)
|
|
@@ -2001,7 +2336,7 @@ var WebRTCTransport = class {
|
|
|
2001
2336
|
});
|
|
2002
2337
|
this._peer.on("signal", async (data) => {
|
|
2003
2338
|
(0, import_log11.log)("signal", data, {
|
|
2004
|
-
F:
|
|
2339
|
+
F: __dxlog_file10,
|
|
2005
2340
|
L: 48,
|
|
2006
2341
|
S: this,
|
|
2007
2342
|
C: (f, a) => f(...a)
|
|
@@ -2014,7 +2349,7 @@ var WebRTCTransport = class {
|
|
|
2014
2349
|
});
|
|
2015
2350
|
this._peer.on("connect", () => {
|
|
2016
2351
|
(0, import_log11.log)("connected", void 0, {
|
|
2017
|
-
F:
|
|
2352
|
+
F: __dxlog_file10,
|
|
2018
2353
|
L: 53,
|
|
2019
2354
|
S: this,
|
|
2020
2355
|
C: (f, a) => f(...a)
|
|
@@ -2024,7 +2359,7 @@ var WebRTCTransport = class {
|
|
|
2024
2359
|
});
|
|
2025
2360
|
this._peer.on("close", async () => {
|
|
2026
2361
|
(0, import_log11.log)("closed", void 0, {
|
|
2027
|
-
F:
|
|
2362
|
+
F: __dxlog_file10,
|
|
2028
2363
|
L: 59,
|
|
2029
2364
|
S: this,
|
|
2030
2365
|
C: (f, a) => f(...a)
|
|
@@ -2042,7 +2377,7 @@ var WebRTCTransport = class {
|
|
|
2042
2377
|
config: this.params.webrtcConfig,
|
|
2043
2378
|
stats
|
|
2044
2379
|
}, {
|
|
2045
|
-
F:
|
|
2380
|
+
F: __dxlog_file10,
|
|
2046
2381
|
L: 71,
|
|
2047
2382
|
S: this,
|
|
2048
2383
|
C: (f, a) => f(...a)
|
|
@@ -2056,7 +2391,7 @@ var WebRTCTransport = class {
|
|
|
2056
2391
|
import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
|
|
2057
2392
|
id: this._instanceId
|
|
2058
2393
|
}), {
|
|
2059
|
-
F:
|
|
2394
|
+
F: __dxlog_file10,
|
|
2060
2395
|
L: 81,
|
|
2061
2396
|
S: this,
|
|
2062
2397
|
C: (f, a) => f(...a)
|
|
@@ -2064,7 +2399,7 @@ var WebRTCTransport = class {
|
|
|
2064
2399
|
}
|
|
2065
2400
|
async destroy() {
|
|
2066
2401
|
(0, import_log11.log)("closing...", void 0, {
|
|
2067
|
-
F:
|
|
2402
|
+
F: __dxlog_file10,
|
|
2068
2403
|
L: 85,
|
|
2069
2404
|
S: this,
|
|
2070
2405
|
C: (f, a) => f(...a)
|
|
@@ -2074,7 +2409,7 @@ var WebRTCTransport = class {
|
|
|
2074
2409
|
this._peer.destroy();
|
|
2075
2410
|
this.closed.emit();
|
|
2076
2411
|
(0, import_log11.log)("closed", void 0, {
|
|
2077
|
-
F:
|
|
2412
|
+
F: __dxlog_file10,
|
|
2078
2413
|
L: 90,
|
|
2079
2414
|
S: this,
|
|
2080
2415
|
C: (f, a) => f(...a)
|
|
@@ -2084,7 +2419,15 @@ var WebRTCTransport = class {
|
|
|
2084
2419
|
if (this._closed) {
|
|
2085
2420
|
return;
|
|
2086
2421
|
}
|
|
2087
|
-
(0,
|
|
2422
|
+
(0, import_invariant11.invariant)(signal.payload.data, "Signal message must contain signal data.", {
|
|
2423
|
+
F: __dxlog_file10,
|
|
2424
|
+
L: 98,
|
|
2425
|
+
S: this,
|
|
2426
|
+
A: [
|
|
2427
|
+
"signal.payload.data",
|
|
2428
|
+
"'Signal message must contain signal data.'"
|
|
2429
|
+
]
|
|
2430
|
+
});
|
|
2088
2431
|
this._peer.signal(signal.payload.data);
|
|
2089
2432
|
}
|
|
2090
2433
|
async _disconnectStreams() {
|
|
@@ -2095,13 +2438,13 @@ var WebRTCTransport = class {
|
|
|
2095
2438
|
|
|
2096
2439
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
2097
2440
|
var import_node_stream2 = require("node:stream");
|
|
2098
|
-
var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
|
|
2099
2441
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
2442
|
+
var import_invariant12 = require("@dxos/invariant");
|
|
2100
2443
|
var import_keys11 = require("@dxos/keys");
|
|
2101
2444
|
var import_log12 = require("@dxos/log");
|
|
2102
2445
|
var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2103
2446
|
var import_util8 = require("@dxos/util");
|
|
2104
|
-
var
|
|
2447
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
|
|
2105
2448
|
var WebRTCTransportService = class {
|
|
2106
2449
|
// prettier-ignore
|
|
2107
2450
|
constructor(_webrtcConfig) {
|
|
@@ -2112,6 +2455,13 @@ var WebRTCTransportService = class {
|
|
|
2112
2455
|
const rpcStream = new import_codec_protobuf.Stream(({ ready, next, close }) => {
|
|
2113
2456
|
const duplex = new import_node_stream2.Duplex({
|
|
2114
2457
|
read: () => {
|
|
2458
|
+
const callbacks = [
|
|
2459
|
+
...transportState.writeCallbacks
|
|
2460
|
+
];
|
|
2461
|
+
transportState.writeCallbacks.length = 0;
|
|
2462
|
+
for (const cb of callbacks) {
|
|
2463
|
+
cb();
|
|
2464
|
+
}
|
|
2115
2465
|
},
|
|
2116
2466
|
write: function(chunk, _, callback) {
|
|
2117
2467
|
next({
|
|
@@ -2163,21 +2513,45 @@ var WebRTCTransportService = class {
|
|
|
2163
2513
|
});
|
|
2164
2514
|
close();
|
|
2165
2515
|
});
|
|
2166
|
-
|
|
2167
|
-
this.transports.set(request.proxyId, {
|
|
2516
|
+
const transportState = {
|
|
2168
2517
|
transport,
|
|
2169
|
-
stream: duplex
|
|
2170
|
-
|
|
2518
|
+
stream: duplex,
|
|
2519
|
+
writeCallbacks: []
|
|
2520
|
+
};
|
|
2521
|
+
ready();
|
|
2522
|
+
this.transports.set(request.proxyId, transportState);
|
|
2171
2523
|
});
|
|
2172
2524
|
return rpcStream;
|
|
2173
2525
|
}
|
|
2174
2526
|
async sendSignal({ proxyId, signal }) {
|
|
2175
|
-
(0,
|
|
2527
|
+
(0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
|
|
2528
|
+
F: __dxlog_file11,
|
|
2529
|
+
L: 113,
|
|
2530
|
+
S: this,
|
|
2531
|
+
A: [
|
|
2532
|
+
"this.transports.has(proxyId)",
|
|
2533
|
+
""
|
|
2534
|
+
]
|
|
2535
|
+
});
|
|
2176
2536
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2177
2537
|
}
|
|
2178
2538
|
async sendData({ proxyId, payload }) {
|
|
2179
|
-
(0,
|
|
2180
|
-
|
|
2539
|
+
(0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
|
|
2540
|
+
F: __dxlog_file11,
|
|
2541
|
+
L: 118,
|
|
2542
|
+
S: this,
|
|
2543
|
+
A: [
|
|
2544
|
+
"this.transports.has(proxyId)",
|
|
2545
|
+
""
|
|
2546
|
+
]
|
|
2547
|
+
});
|
|
2548
|
+
const state = this.transports.get(proxyId);
|
|
2549
|
+
const bufferHasSpace = state.stream.push(payload);
|
|
2550
|
+
if (!bufferHasSpace) {
|
|
2551
|
+
await new Promise((resolve) => {
|
|
2552
|
+
state.writeCallbacks.push(resolve);
|
|
2553
|
+
});
|
|
2554
|
+
}
|
|
2181
2555
|
}
|
|
2182
2556
|
async close({ proxyId }) {
|
|
2183
2557
|
var _a2, _b;
|
|
@@ -2185,8 +2559,8 @@ var WebRTCTransportService = class {
|
|
|
2185
2559
|
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
2186
2560
|
this.transports.delete(proxyId);
|
|
2187
2561
|
(0, import_log12.log)("Closed.", void 0, {
|
|
2188
|
-
F:
|
|
2189
|
-
L:
|
|
2562
|
+
F: __dxlog_file11,
|
|
2563
|
+
L: 132,
|
|
2190
2564
|
S: this,
|
|
2191
2565
|
C: (f, a) => f(...a)
|
|
2192
2566
|
});
|
|
@@ -2194,15 +2568,16 @@ var WebRTCTransportService = class {
|
|
|
2194
2568
|
};
|
|
2195
2569
|
|
|
2196
2570
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2197
|
-
var
|
|
2571
|
+
var import_node_stream3 = require("node:stream");
|
|
2198
2572
|
var import_async10 = require("@dxos/async");
|
|
2199
2573
|
var import_context6 = require("@dxos/context");
|
|
2200
2574
|
var import_debug6 = require("@dxos/debug");
|
|
2575
|
+
var import_invariant13 = require("@dxos/invariant");
|
|
2201
2576
|
var import_keys12 = require("@dxos/keys");
|
|
2202
2577
|
var import_log13 = require("@dxos/log");
|
|
2203
2578
|
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2204
2579
|
var import_util9 = require("@dxos/util");
|
|
2205
|
-
var
|
|
2580
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
|
|
2206
2581
|
var WebRTCTransportProxy = class {
|
|
2207
2582
|
// prettier-ignore
|
|
2208
2583
|
constructor(_params) {
|
|
@@ -2220,8 +2595,8 @@ var WebRTCTransportProxy = class {
|
|
|
2220
2595
|
this._serviceStream.waitUntilReady().then(() => {
|
|
2221
2596
|
this._serviceStream.subscribe(async (event) => {
|
|
2222
2597
|
(0, import_log13.log)("WebRTCTransportProxy: event", event, {
|
|
2223
|
-
F:
|
|
2224
|
-
L:
|
|
2598
|
+
F: __dxlog_file12,
|
|
2599
|
+
L: 51,
|
|
2225
2600
|
S: this,
|
|
2226
2601
|
C: (f, a) => f(...a)
|
|
2227
2602
|
});
|
|
@@ -2233,28 +2608,24 @@ var WebRTCTransportProxy = class {
|
|
|
2233
2608
|
await this._handleSignal(event.signal);
|
|
2234
2609
|
}
|
|
2235
2610
|
});
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2611
|
+
this._params.stream.pipe(new import_node_stream3.Writable({
|
|
2612
|
+
write: (chunk, _, callback) => {
|
|
2613
|
+
this._params.bridgeService.sendData({
|
|
2239
2614
|
proxyId: this._proxyId,
|
|
2240
|
-
payload:
|
|
2241
|
-
})
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2615
|
+
payload: chunk
|
|
2616
|
+
}).then(() => callback(), (err) => {
|
|
2617
|
+
import_log13.log.catch(err, void 0, {
|
|
2618
|
+
F: __dxlog_file12,
|
|
2619
|
+
L: 69,
|
|
2620
|
+
S: this,
|
|
2621
|
+
C: (f, a) => f(...a)
|
|
2622
|
+
});
|
|
2248
2623
|
});
|
|
2249
2624
|
}
|
|
2250
|
-
};
|
|
2251
|
-
this._params.stream.on("data", dataListener);
|
|
2252
|
-
this._ctx.onDispose(() => {
|
|
2253
|
-
this._params.stream.off("data", dataListener);
|
|
2254
|
-
});
|
|
2625
|
+
}));
|
|
2255
2626
|
}, (error) => import_log13.log.catch(error, void 0, {
|
|
2256
|
-
F:
|
|
2257
|
-
L:
|
|
2627
|
+
F: __dxlog_file12,
|
|
2628
|
+
L: 75,
|
|
2258
2629
|
S: this,
|
|
2259
2630
|
C: (f, a) => f(...a)
|
|
2260
2631
|
}));
|
|
@@ -2299,8 +2670,8 @@ var WebRTCTransportProxy = class {
|
|
|
2299
2670
|
});
|
|
2300
2671
|
} catch (err) {
|
|
2301
2672
|
import_log13.log.catch(err, void 0, {
|
|
2302
|
-
F:
|
|
2303
|
-
L:
|
|
2673
|
+
F: __dxlog_file12,
|
|
2674
|
+
L: 126,
|
|
2304
2675
|
S: this,
|
|
2305
2676
|
C: (f, a) => f(...a)
|
|
2306
2677
|
});
|
|
@@ -2334,7 +2705,15 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2334
2705
|
return this;
|
|
2335
2706
|
}
|
|
2336
2707
|
createTransport(options) {
|
|
2337
|
-
(0,
|
|
2708
|
+
(0, import_invariant13.invariant)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections", {
|
|
2709
|
+
F: __dxlog_file12,
|
|
2710
|
+
L: 163,
|
|
2711
|
+
S: this,
|
|
2712
|
+
A: [
|
|
2713
|
+
"this._bridgeService",
|
|
2714
|
+
"'WebRTCTransportProxyFactory is not ready to open connections'"
|
|
2715
|
+
]
|
|
2716
|
+
});
|
|
2338
2717
|
const transport = new WebRTCTransportProxy({
|
|
2339
2718
|
...options,
|
|
2340
2719
|
bridgeService: this._bridgeService
|
|
@@ -2371,7 +2750,7 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
2371
2750
|
};
|
|
2372
2751
|
|
|
2373
2752
|
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
2374
|
-
var
|
|
2753
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
|
|
2375
2754
|
var TestWireProtocol = class {
|
|
2376
2755
|
constructor(peerId) {
|
|
2377
2756
|
this.peerId = peerId;
|
|
@@ -2383,7 +2762,7 @@ var TestWireProtocol = class {
|
|
|
2383
2762
|
(0, import_log14.log)("create", {
|
|
2384
2763
|
remotePeerId: teleport.remotePeerId
|
|
2385
2764
|
}, {
|
|
2386
|
-
F:
|
|
2765
|
+
F: __dxlog_file13,
|
|
2387
2766
|
L: 23,
|
|
2388
2767
|
S: this,
|
|
2389
2768
|
C: (f, a) => f(...a)
|
|
@@ -2413,7 +2792,7 @@ var TestWireProtocol = class {
|
|
|
2413
2792
|
(0, import_log14.log)("waitForConnection", {
|
|
2414
2793
|
peerId
|
|
2415
2794
|
}, {
|
|
2416
|
-
F:
|
|
2795
|
+
F: __dxlog_file13,
|
|
2417
2796
|
L: 47,
|
|
2418
2797
|
S: this,
|
|
2419
2798
|
C: (f, a) => f(...a)
|