@dxos/network-manager 0.1.56-main.e47dfd1 → 0.1.56-main.ed2f871
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-5TRIVLI6.mjs} +657 -247
- package/dist/lib/browser/chunk-5TRIVLI6.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 +23 -16
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +655 -245
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +603 -242
- 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/testing/test-builder.d.ts +4 -3
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-wire-protocol.d.ts +13 -2
- package/dist/types/src/testing/test-wire-protocol.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/testing/test-builder.ts +9 -5
- package/src/testing/test-wire-protocol.ts +22 -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,13 +240,12 @@ 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
|
});
|
|
207
247
|
}
|
|
208
248
|
async close() {
|
|
209
|
-
var _a2;
|
|
210
249
|
if (this._state === ConnectionState.CLOSED) {
|
|
211
250
|
return;
|
|
212
251
|
}
|
|
@@ -216,7 +255,7 @@ var Connection = class {
|
|
|
216
255
|
peerId: this.ownId
|
|
217
256
|
}, {
|
|
218
257
|
F: __dxlog_file,
|
|
219
|
-
L:
|
|
258
|
+
L: 184,
|
|
220
259
|
S: this,
|
|
221
260
|
C: (f, a) => f(...a)
|
|
222
261
|
});
|
|
@@ -225,17 +264,17 @@ var Connection = class {
|
|
|
225
264
|
} catch (err) {
|
|
226
265
|
import_log.log.catch(err, void 0, {
|
|
227
266
|
F: __dxlog_file,
|
|
228
|
-
L:
|
|
267
|
+
L: 190,
|
|
229
268
|
S: this,
|
|
230
269
|
C: (f, a) => f(...a)
|
|
231
270
|
});
|
|
232
271
|
}
|
|
233
272
|
try {
|
|
234
|
-
await
|
|
273
|
+
await this._transport?.destroy();
|
|
235
274
|
} catch (err) {
|
|
236
275
|
import_log.log.catch(err, void 0, {
|
|
237
276
|
F: __dxlog_file,
|
|
238
|
-
L:
|
|
277
|
+
L: 197,
|
|
239
278
|
S: this,
|
|
240
279
|
C: (f, a) => f(...a)
|
|
241
280
|
});
|
|
@@ -244,7 +283,7 @@ var Connection = class {
|
|
|
244
283
|
peerId: this.ownId
|
|
245
284
|
}, {
|
|
246
285
|
F: __dxlog_file,
|
|
247
|
-
L:
|
|
286
|
+
L: 200,
|
|
248
287
|
S: this,
|
|
249
288
|
C: (f, a) => f(...a)
|
|
250
289
|
});
|
|
@@ -284,7 +323,7 @@ var Connection = class {
|
|
|
284
323
|
err
|
|
285
324
|
}, {
|
|
286
325
|
F: __dxlog_file,
|
|
287
|
-
L:
|
|
326
|
+
L: 234,
|
|
288
327
|
S: this,
|
|
289
328
|
C: (f, a) => f(...a)
|
|
290
329
|
});
|
|
@@ -295,21 +334,52 @@ var Connection = class {
|
|
|
295
334
|
* Receive a signal from the remote peer.
|
|
296
335
|
*/
|
|
297
336
|
async signal(msg) {
|
|
298
|
-
|
|
299
|
-
|
|
337
|
+
(0, import_invariant.invariant)(msg.sessionId, void 0, {
|
|
338
|
+
F: __dxlog_file,
|
|
339
|
+
L: 243,
|
|
340
|
+
S: this,
|
|
341
|
+
A: [
|
|
342
|
+
"msg.sessionId",
|
|
343
|
+
""
|
|
344
|
+
]
|
|
345
|
+
});
|
|
300
346
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
301
347
|
(0, import_log.log)("dropping signal for incorrect session id", void 0, {
|
|
302
348
|
F: __dxlog_file,
|
|
303
|
-
L:
|
|
349
|
+
L: 245,
|
|
304
350
|
S: this,
|
|
305
351
|
C: (f, a) => f(...a)
|
|
306
352
|
});
|
|
307
353
|
return;
|
|
308
354
|
}
|
|
309
|
-
(0,
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
355
|
+
(0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
356
|
+
F: __dxlog_file,
|
|
357
|
+
L: 248,
|
|
358
|
+
S: this,
|
|
359
|
+
A: [
|
|
360
|
+
"msg.data.signal || msg.data.signalBatch",
|
|
361
|
+
""
|
|
362
|
+
]
|
|
363
|
+
});
|
|
364
|
+
(0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
|
|
365
|
+
F: __dxlog_file,
|
|
366
|
+
L: 249,
|
|
367
|
+
S: this,
|
|
368
|
+
A: [
|
|
369
|
+
"msg.author?.equals(this.remoteId)",
|
|
370
|
+
""
|
|
371
|
+
]
|
|
372
|
+
});
|
|
373
|
+
(0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
|
|
374
|
+
F: __dxlog_file,
|
|
375
|
+
L: 250,
|
|
376
|
+
S: this,
|
|
377
|
+
A: [
|
|
378
|
+
"msg.recipient?.equals(this.ownId)",
|
|
379
|
+
""
|
|
380
|
+
]
|
|
381
|
+
});
|
|
382
|
+
const signals = msg.data.signalBatch ? msg.data.signalBatch.signals ?? [] : [
|
|
313
383
|
msg.data.signal
|
|
314
384
|
];
|
|
315
385
|
for (const signal of signals) {
|
|
@@ -323,20 +393,28 @@ var Connection = class {
|
|
|
323
393
|
msg: msg.data
|
|
324
394
|
}, {
|
|
325
395
|
F: __dxlog_file,
|
|
326
|
-
L:
|
|
396
|
+
L: 259,
|
|
327
397
|
S: this,
|
|
328
398
|
C: (f, a) => f(...a)
|
|
329
399
|
});
|
|
330
400
|
this._incomingSignalBuffer.push(signal);
|
|
331
401
|
} else {
|
|
332
|
-
(0,
|
|
402
|
+
(0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
|
|
403
|
+
F: __dxlog_file,
|
|
404
|
+
L: 262,
|
|
405
|
+
S: this,
|
|
406
|
+
A: [
|
|
407
|
+
"this._transport",
|
|
408
|
+
"'Connection not ready to accept signals.'"
|
|
409
|
+
]
|
|
410
|
+
});
|
|
333
411
|
(0, import_log.log)("received signal", {
|
|
334
412
|
peerId: this.ownId,
|
|
335
413
|
remoteId: this.remoteId,
|
|
336
414
|
msg: msg.data
|
|
337
415
|
}, {
|
|
338
416
|
F: __dxlog_file,
|
|
339
|
-
L:
|
|
417
|
+
L: 263,
|
|
340
418
|
S: this,
|
|
341
419
|
C: (f, a) => f(...a)
|
|
342
420
|
});
|
|
@@ -351,11 +429,19 @@ var Connection = class {
|
|
|
351
429
|
peerId: this.ownId
|
|
352
430
|
}, {
|
|
353
431
|
F: __dxlog_file,
|
|
354
|
-
L:
|
|
432
|
+
L: 270,
|
|
355
433
|
S: this,
|
|
356
434
|
C: (f, a) => f(...a)
|
|
357
435
|
});
|
|
358
|
-
(0,
|
|
436
|
+
(0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
|
|
437
|
+
F: __dxlog_file,
|
|
438
|
+
L: 271,
|
|
439
|
+
S: this,
|
|
440
|
+
A: [
|
|
441
|
+
"state !== this._state",
|
|
442
|
+
"'Already in this state.'"
|
|
443
|
+
]
|
|
444
|
+
});
|
|
359
445
|
this._state = state;
|
|
360
446
|
this.stateChanged.emit(state);
|
|
361
447
|
}
|
|
@@ -365,18 +451,18 @@ _ts_decorate([
|
|
|
365
451
|
], Connection.prototype, "close", null);
|
|
366
452
|
|
|
367
453
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
368
|
-
var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
|
|
369
454
|
var import_async3 = require("@dxos/async");
|
|
370
455
|
var import_context4 = require("@dxos/context");
|
|
371
456
|
var import_debug2 = require("@dxos/debug");
|
|
457
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
372
458
|
var import_keys4 = require("@dxos/keys");
|
|
373
459
|
var import_log4 = require("@dxos/log");
|
|
374
460
|
var import_protocols3 = require("@dxos/protocols");
|
|
375
461
|
var import_util2 = require("@dxos/util");
|
|
376
462
|
|
|
377
463
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
378
|
-
var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
|
|
379
464
|
var import_context2 = require("@dxos/context");
|
|
465
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
380
466
|
var import_keys2 = require("@dxos/keys");
|
|
381
467
|
var import_log2 = require("@dxos/log");
|
|
382
468
|
var import_protocols2 = require("@dxos/protocols");
|
|
@@ -393,7 +479,6 @@ var SwarmMessenger = class {
|
|
|
393
479
|
this._topic = topic;
|
|
394
480
|
}
|
|
395
481
|
async receiveMessage({ author, recipient, payload }) {
|
|
396
|
-
var _a2, _b, _c, _d;
|
|
397
482
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
398
483
|
return;
|
|
399
484
|
}
|
|
@@ -407,25 +492,25 @@ var SwarmMessenger = class {
|
|
|
407
492
|
msg: message
|
|
408
493
|
}, {
|
|
409
494
|
F: __dxlog_file2,
|
|
410
|
-
L:
|
|
495
|
+
L: 69,
|
|
411
496
|
S: this,
|
|
412
497
|
C: (f, a) => f(...a)
|
|
413
498
|
});
|
|
414
|
-
if (
|
|
499
|
+
if (message.data?.offer) {
|
|
415
500
|
await this._handleOffer({
|
|
416
501
|
author,
|
|
417
502
|
recipient,
|
|
418
503
|
message
|
|
419
504
|
});
|
|
420
|
-
} else if (
|
|
505
|
+
} else if (message.data?.answer) {
|
|
421
506
|
await this._resolveAnswers(message);
|
|
422
|
-
} else if (
|
|
507
|
+
} else if (message.data?.signal) {
|
|
423
508
|
await this._handleSignal({
|
|
424
509
|
author,
|
|
425
510
|
recipient,
|
|
426
511
|
message
|
|
427
512
|
});
|
|
428
|
-
} else if (
|
|
513
|
+
} else if (message.data?.signalBatch) {
|
|
429
514
|
await this._handleSignal({
|
|
430
515
|
author,
|
|
431
516
|
recipient,
|
|
@@ -436,15 +521,22 @@ var SwarmMessenger = class {
|
|
|
436
521
|
message
|
|
437
522
|
}, {
|
|
438
523
|
F: __dxlog_file2,
|
|
439
|
-
L:
|
|
524
|
+
L: 80,
|
|
440
525
|
S: this,
|
|
441
526
|
C: (f, a) => f(...a)
|
|
442
527
|
});
|
|
443
528
|
}
|
|
444
529
|
}
|
|
445
530
|
async signal(message) {
|
|
446
|
-
|
|
447
|
-
|
|
531
|
+
(0, import_invariant2.invariant)(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
532
|
+
F: __dxlog_file2,
|
|
533
|
+
L: 85,
|
|
534
|
+
S: this,
|
|
535
|
+
A: [
|
|
536
|
+
"message.data?.signal || message.data?.signalBatch",
|
|
537
|
+
"'Invalid message'"
|
|
538
|
+
]
|
|
539
|
+
});
|
|
448
540
|
await this._sendReliableMessage({
|
|
449
541
|
author: message.author,
|
|
450
542
|
recipient: message.recipient,
|
|
@@ -468,11 +560,10 @@ var SwarmMessenger = class {
|
|
|
468
560
|
});
|
|
469
561
|
}
|
|
470
562
|
async _sendReliableMessage({ author, recipient, message }) {
|
|
471
|
-
var _a2;
|
|
472
563
|
const networkMessage = {
|
|
473
564
|
...message,
|
|
474
565
|
// Setting unique message_id if it not specified yet.
|
|
475
|
-
messageId:
|
|
566
|
+
messageId: message.messageId ?? import_keys2.PublicKey.random()
|
|
476
567
|
};
|
|
477
568
|
(0, import_log2.log)("sending", {
|
|
478
569
|
from: author,
|
|
@@ -480,7 +571,7 @@ var SwarmMessenger = class {
|
|
|
480
571
|
msg: networkMessage
|
|
481
572
|
}, {
|
|
482
573
|
F: __dxlog_file2,
|
|
483
|
-
L:
|
|
574
|
+
L: 123,
|
|
484
575
|
S: this,
|
|
485
576
|
C: (f, a) => f(...a)
|
|
486
577
|
});
|
|
@@ -494,17 +585,32 @@ var SwarmMessenger = class {
|
|
|
494
585
|
});
|
|
495
586
|
}
|
|
496
587
|
async _resolveAnswers(message) {
|
|
497
|
-
|
|
498
|
-
|
|
588
|
+
(0, import_invariant2.invariant)(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
589
|
+
F: __dxlog_file2,
|
|
590
|
+
L: 135,
|
|
591
|
+
S: this,
|
|
592
|
+
A: [
|
|
593
|
+
"message.data?.answer?.offerMessageId",
|
|
594
|
+
"'No offerMessageId'"
|
|
595
|
+
]
|
|
596
|
+
});
|
|
499
597
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
500
598
|
if (offerRecord) {
|
|
501
599
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
502
|
-
(0,
|
|
600
|
+
(0, import_invariant2.invariant)(message.data?.answer, "No answer", {
|
|
601
|
+
F: __dxlog_file2,
|
|
602
|
+
L: 139,
|
|
603
|
+
S: this,
|
|
604
|
+
A: [
|
|
605
|
+
"message.data?.answer",
|
|
606
|
+
"'No answer'"
|
|
607
|
+
]
|
|
608
|
+
});
|
|
503
609
|
(0, import_log2.log)("resolving", {
|
|
504
610
|
answer: message.data.answer
|
|
505
611
|
}, {
|
|
506
612
|
F: __dxlog_file2,
|
|
507
|
-
L:
|
|
613
|
+
L: 140,
|
|
508
614
|
S: this,
|
|
509
615
|
C: (f, a) => f(...a)
|
|
510
616
|
});
|
|
@@ -512,7 +618,15 @@ var SwarmMessenger = class {
|
|
|
512
618
|
}
|
|
513
619
|
}
|
|
514
620
|
async _handleOffer({ author, recipient, message }) {
|
|
515
|
-
(0,
|
|
621
|
+
(0, import_invariant2.invariant)(message.data.offer, "No offer", {
|
|
622
|
+
F: __dxlog_file2,
|
|
623
|
+
L: 154,
|
|
624
|
+
S: this,
|
|
625
|
+
A: [
|
|
626
|
+
"message.data.offer",
|
|
627
|
+
"'No offer'"
|
|
628
|
+
]
|
|
629
|
+
});
|
|
516
630
|
const offerMessage = {
|
|
517
631
|
author,
|
|
518
632
|
recipient,
|
|
@@ -540,15 +654,31 @@ var SwarmMessenger = class {
|
|
|
540
654
|
err
|
|
541
655
|
}, {
|
|
542
656
|
F: __dxlog_file2,
|
|
543
|
-
L:
|
|
657
|
+
L: 174,
|
|
544
658
|
S: this,
|
|
545
659
|
C: (f, a) => f(...a)
|
|
546
660
|
});
|
|
547
661
|
}
|
|
548
662
|
}
|
|
549
663
|
async _handleSignal({ author, recipient, message }) {
|
|
550
|
-
(0,
|
|
551
|
-
|
|
664
|
+
(0, import_invariant2.invariant)(message.messageId, void 0, {
|
|
665
|
+
F: __dxlog_file2,
|
|
666
|
+
L: 187,
|
|
667
|
+
S: this,
|
|
668
|
+
A: [
|
|
669
|
+
"message.messageId",
|
|
670
|
+
""
|
|
671
|
+
]
|
|
672
|
+
});
|
|
673
|
+
(0, import_invariant2.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
674
|
+
F: __dxlog_file2,
|
|
675
|
+
L: 188,
|
|
676
|
+
S: this,
|
|
677
|
+
A: [
|
|
678
|
+
"message.data.signal || message.data.signalBatch",
|
|
679
|
+
"'Invalid message'"
|
|
680
|
+
]
|
|
681
|
+
});
|
|
552
682
|
const signalMessage = {
|
|
553
683
|
author,
|
|
554
684
|
recipient,
|
|
@@ -563,10 +693,10 @@ var SwarmMessenger = class {
|
|
|
563
693
|
};
|
|
564
694
|
|
|
565
695
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
566
|
-
var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
|
|
567
696
|
var import_async2 = require("@dxos/async");
|
|
568
697
|
var import_context3 = require("@dxos/context");
|
|
569
698
|
var import_errors2 = require("@dxos/errors");
|
|
699
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
570
700
|
var import_keys3 = require("@dxos/keys");
|
|
571
701
|
var import_log3 = require("@dxos/log");
|
|
572
702
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
@@ -601,7 +731,6 @@ var Peer = class {
|
|
|
601
731
|
* Respond to remote offer.
|
|
602
732
|
*/
|
|
603
733
|
async onOffer(message) {
|
|
604
|
-
var _a2;
|
|
605
734
|
const remoteId = message.author;
|
|
606
735
|
if (this.connection || this.initiating) {
|
|
607
736
|
if (remoteId.toHex() < this.localPeerId.toHex()) {
|
|
@@ -609,10 +738,10 @@ var Peer = class {
|
|
|
609
738
|
localPeerId: this.id,
|
|
610
739
|
topic: this.topic,
|
|
611
740
|
remotePeerId: this.localPeerId,
|
|
612
|
-
sessionId:
|
|
741
|
+
sessionId: this.connection?.sessionId
|
|
613
742
|
}, {
|
|
614
743
|
F: __dxlog_file3,
|
|
615
|
-
L:
|
|
744
|
+
L: 106,
|
|
616
745
|
S: this,
|
|
617
746
|
C: (f, a) => f(...a)
|
|
618
747
|
});
|
|
@@ -627,7 +756,15 @@ var Peer = class {
|
|
|
627
756
|
}
|
|
628
757
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
629
758
|
if (!this.connection) {
|
|
630
|
-
(0,
|
|
759
|
+
(0, import_invariant3.invariant)(message.sessionId, void 0, {
|
|
760
|
+
F: __dxlog_file3,
|
|
761
|
+
L: 126,
|
|
762
|
+
S: this,
|
|
763
|
+
A: [
|
|
764
|
+
"message.sessionId",
|
|
765
|
+
""
|
|
766
|
+
]
|
|
767
|
+
});
|
|
631
768
|
const connection = this._createConnection(false, message.sessionId);
|
|
632
769
|
try {
|
|
633
770
|
await this._connectionLimiter.connecting(message.sessionId);
|
|
@@ -641,7 +778,7 @@ var Peer = class {
|
|
|
641
778
|
err
|
|
642
779
|
}, {
|
|
643
780
|
F: __dxlog_file3,
|
|
644
|
-
L:
|
|
781
|
+
L: 134,
|
|
645
782
|
S: this,
|
|
646
783
|
C: (f, a) => f(...a)
|
|
647
784
|
});
|
|
@@ -661,8 +798,24 @@ var Peer = class {
|
|
|
661
798
|
* Initiate a connection to the remote peer.
|
|
662
799
|
*/
|
|
663
800
|
async initiateConnection() {
|
|
664
|
-
(0,
|
|
665
|
-
|
|
801
|
+
(0, import_invariant3.invariant)(!this.initiating, "Initiation in progress.", {
|
|
802
|
+
F: __dxlog_file3,
|
|
803
|
+
L: 151,
|
|
804
|
+
S: this,
|
|
805
|
+
A: [
|
|
806
|
+
"!this.initiating",
|
|
807
|
+
"'Initiation in progress.'"
|
|
808
|
+
]
|
|
809
|
+
});
|
|
810
|
+
(0, import_invariant3.invariant)(!this.connection, "Already connected.", {
|
|
811
|
+
F: __dxlog_file3,
|
|
812
|
+
L: 152,
|
|
813
|
+
S: this,
|
|
814
|
+
A: [
|
|
815
|
+
"!this.connection",
|
|
816
|
+
"'Already connected.'"
|
|
817
|
+
]
|
|
818
|
+
});
|
|
666
819
|
const sessionId = import_keys3.PublicKey.random();
|
|
667
820
|
(0, import_log3.log)("initiating...", {
|
|
668
821
|
id: this.id,
|
|
@@ -671,7 +824,7 @@ var Peer = class {
|
|
|
671
824
|
sessionId
|
|
672
825
|
}, {
|
|
673
826
|
F: __dxlog_file3,
|
|
674
|
-
L:
|
|
827
|
+
L: 154,
|
|
675
828
|
S: this,
|
|
676
829
|
C: (f, a) => f(...a)
|
|
677
830
|
});
|
|
@@ -695,14 +848,14 @@ var Peer = class {
|
|
|
695
848
|
remoteId: this.id
|
|
696
849
|
}, {
|
|
697
850
|
F: __dxlog_file3,
|
|
698
|
-
L:
|
|
851
|
+
L: 169,
|
|
699
852
|
S: this,
|
|
700
853
|
C: (f, a) => f(...a)
|
|
701
854
|
});
|
|
702
855
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
703
856
|
(0, import_log3.log)("ignoring response", void 0, {
|
|
704
857
|
F: __dxlog_file3,
|
|
705
|
-
L:
|
|
858
|
+
L: 171,
|
|
706
859
|
S: this,
|
|
707
860
|
C: (f, a) => f(...a)
|
|
708
861
|
});
|
|
@@ -722,7 +875,7 @@ var Peer = class {
|
|
|
722
875
|
remoteId: this.id
|
|
723
876
|
}, {
|
|
724
877
|
F: __dxlog_file3,
|
|
725
|
-
L:
|
|
878
|
+
L: 182,
|
|
726
879
|
S: this,
|
|
727
880
|
C: (f, a) => f(...a)
|
|
728
881
|
});
|
|
@@ -737,7 +890,6 @@ var Peer = class {
|
|
|
737
890
|
* Either we're initiating a connection or creating one in response to an offer from the other peer.
|
|
738
891
|
*/
|
|
739
892
|
_createConnection(initiator, sessionId) {
|
|
740
|
-
var _a2;
|
|
741
893
|
(0, import_log3.log)("creating connection", {
|
|
742
894
|
topic: this.topic,
|
|
743
895
|
peerId: this.localPeerId,
|
|
@@ -746,11 +898,19 @@ var Peer = class {
|
|
|
746
898
|
sessionId
|
|
747
899
|
}, {
|
|
748
900
|
F: __dxlog_file3,
|
|
749
|
-
L:
|
|
901
|
+
L: 196,
|
|
750
902
|
S: this,
|
|
751
903
|
C: (f, a) => f(...a)
|
|
752
904
|
});
|
|
753
|
-
(0,
|
|
905
|
+
(0, import_invariant3.invariant)(!this.connection, "Already connected.", {
|
|
906
|
+
F: __dxlog_file3,
|
|
907
|
+
L: 203,
|
|
908
|
+
S: this,
|
|
909
|
+
A: [
|
|
910
|
+
"!this.connection",
|
|
911
|
+
"'Already connected.'"
|
|
912
|
+
]
|
|
913
|
+
});
|
|
754
914
|
const connection = new Connection(
|
|
755
915
|
this.topic,
|
|
756
916
|
this.localPeerId,
|
|
@@ -768,7 +928,7 @@ var Peer = class {
|
|
|
768
928
|
this._transportFactory
|
|
769
929
|
);
|
|
770
930
|
this._callbacks.onInitiated(connection);
|
|
771
|
-
void
|
|
931
|
+
void this._connectionCtx?.dispose();
|
|
772
932
|
this._connectionCtx = this._ctx.derive();
|
|
773
933
|
connection.stateChanged.on((state) => {
|
|
774
934
|
switch (state) {
|
|
@@ -777,6 +937,18 @@ var Peer = class {
|
|
|
777
937
|
this._lastConnectionTime = Date.now();
|
|
778
938
|
this._callbacks.onConnected();
|
|
779
939
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
940
|
+
import_log3.log.trace("dxos.mesh.connection.connected", {
|
|
941
|
+
topic: this.topic,
|
|
942
|
+
localPeerId: this.localPeerId,
|
|
943
|
+
remotePeerId: this.id,
|
|
944
|
+
sessionId,
|
|
945
|
+
initiator
|
|
946
|
+
}, {
|
|
947
|
+
F: __dxlog_file3,
|
|
948
|
+
L: 229,
|
|
949
|
+
S: this,
|
|
950
|
+
C: (f, a) => f(...a)
|
|
951
|
+
});
|
|
780
952
|
break;
|
|
781
953
|
}
|
|
782
954
|
case ConnectionState.CLOSED: {
|
|
@@ -787,11 +959,31 @@ var Peer = class {
|
|
|
787
959
|
initiator
|
|
788
960
|
}, {
|
|
789
961
|
F: __dxlog_file3,
|
|
790
|
-
L:
|
|
962
|
+
L: 240,
|
|
963
|
+
S: this,
|
|
964
|
+
C: (f, a) => f(...a)
|
|
965
|
+
});
|
|
966
|
+
(0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
|
|
967
|
+
F: __dxlog_file3,
|
|
968
|
+
L: 241,
|
|
969
|
+
S: this,
|
|
970
|
+
A: [
|
|
971
|
+
"this.connection === connection",
|
|
972
|
+
"'Connection mismatch (race condition).'"
|
|
973
|
+
]
|
|
974
|
+
});
|
|
975
|
+
import_log3.log.trace("dxos.mesh.connection.closed", {
|
|
976
|
+
topic: this.topic,
|
|
977
|
+
localPeerId: this.localPeerId,
|
|
978
|
+
remotePeerId: this.id,
|
|
979
|
+
sessionId,
|
|
980
|
+
initiator
|
|
981
|
+
}, {
|
|
982
|
+
F: __dxlog_file3,
|
|
983
|
+
L: 243,
|
|
791
984
|
S: this,
|
|
792
985
|
C: (f, a) => f(...a)
|
|
793
986
|
});
|
|
794
|
-
(0, import_tiny_invariant3.default)(this.connection === connection, "Connection mismatch (race condition).");
|
|
795
987
|
if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
|
|
796
988
|
this._availableAfter = 0;
|
|
797
989
|
} else {
|
|
@@ -818,7 +1010,20 @@ var Peer = class {
|
|
|
818
1010
|
err
|
|
819
1011
|
}, {
|
|
820
1012
|
F: __dxlog_file3,
|
|
821
|
-
L:
|
|
1013
|
+
L: 277,
|
|
1014
|
+
S: this,
|
|
1015
|
+
C: (f, a) => f(...a)
|
|
1016
|
+
});
|
|
1017
|
+
import_log3.log.trace("dxos.mesh.connection.error", {
|
|
1018
|
+
topic: this.topic,
|
|
1019
|
+
localPeerId: this.localPeerId,
|
|
1020
|
+
remotePeerId: this.id,
|
|
1021
|
+
sessionId,
|
|
1022
|
+
initiator,
|
|
1023
|
+
err
|
|
1024
|
+
}, {
|
|
1025
|
+
F: __dxlog_file3,
|
|
1026
|
+
L: 278,
|
|
822
1027
|
S: this,
|
|
823
1028
|
C: (f, a) => f(...a)
|
|
824
1029
|
});
|
|
@@ -837,7 +1042,7 @@ var Peer = class {
|
|
|
837
1042
|
sessionId: connection.sessionId
|
|
838
1043
|
}, {
|
|
839
1044
|
F: __dxlog_file3,
|
|
840
|
-
L:
|
|
1045
|
+
L: 301,
|
|
841
1046
|
S: this,
|
|
842
1047
|
C: (f, a) => f(...a)
|
|
843
1048
|
});
|
|
@@ -847,7 +1052,7 @@ var Peer = class {
|
|
|
847
1052
|
sessionId: connection.sessionId
|
|
848
1053
|
}, {
|
|
849
1054
|
F: __dxlog_file3,
|
|
850
|
-
L:
|
|
1055
|
+
L: 307,
|
|
851
1056
|
S: this,
|
|
852
1057
|
C: (f, a) => f(...a)
|
|
853
1058
|
});
|
|
@@ -858,7 +1063,7 @@ var Peer = class {
|
|
|
858
1063
|
message
|
|
859
1064
|
}, {
|
|
860
1065
|
F: __dxlog_file3,
|
|
861
|
-
L:
|
|
1066
|
+
L: 312,
|
|
862
1067
|
S: this,
|
|
863
1068
|
C: (f, a) => f(...a)
|
|
864
1069
|
});
|
|
@@ -867,18 +1072,17 @@ var Peer = class {
|
|
|
867
1072
|
await this.connection.signal(message);
|
|
868
1073
|
}
|
|
869
1074
|
async destroy() {
|
|
870
|
-
var _a2;
|
|
871
1075
|
await this._ctx.dispose();
|
|
872
1076
|
(0, import_log3.log)("Destroying peer", {
|
|
873
1077
|
peerId: this.id,
|
|
874
1078
|
topic: this.topic
|
|
875
1079
|
}, {
|
|
876
1080
|
F: __dxlog_file3,
|
|
877
|
-
L:
|
|
1081
|
+
L: 322,
|
|
878
1082
|
S: this,
|
|
879
1083
|
C: (f, a) => f(...a)
|
|
880
1084
|
});
|
|
881
|
-
await
|
|
1085
|
+
await this?.connection?.close();
|
|
882
1086
|
}
|
|
883
1087
|
};
|
|
884
1088
|
_ts_decorate2([
|
|
@@ -939,7 +1143,7 @@ var Swarm = class {
|
|
|
939
1143
|
}
|
|
940
1144
|
}), {
|
|
941
1145
|
F: __dxlog_file4,
|
|
942
|
-
L:
|
|
1146
|
+
L: 87,
|
|
943
1147
|
S: this,
|
|
944
1148
|
C: (f, a) => f(...a)
|
|
945
1149
|
});
|
|
@@ -947,7 +1151,7 @@ var Swarm = class {
|
|
|
947
1151
|
peerId: _ownPeerId
|
|
948
1152
|
}, {
|
|
949
1153
|
F: __dxlog_file4,
|
|
950
|
-
L:
|
|
1154
|
+
L: 91,
|
|
951
1155
|
S: this,
|
|
952
1156
|
C: (f, a) => f(...a)
|
|
953
1157
|
});
|
|
@@ -962,7 +1166,7 @@ var Swarm = class {
|
|
|
962
1166
|
id: this._instanceId
|
|
963
1167
|
}), {
|
|
964
1168
|
F: __dxlog_file4,
|
|
965
|
-
L:
|
|
1169
|
+
L: 100,
|
|
966
1170
|
S: this,
|
|
967
1171
|
C: (f, a) => f(...a)
|
|
968
1172
|
});
|
|
@@ -983,7 +1187,15 @@ var Swarm = class {
|
|
|
983
1187
|
return this._topic;
|
|
984
1188
|
}
|
|
985
1189
|
async open() {
|
|
986
|
-
(0,
|
|
1190
|
+
(0, import_invariant4.invariant)(!this._listeningHandle, void 0, {
|
|
1191
|
+
F: __dxlog_file4,
|
|
1192
|
+
L: 127,
|
|
1193
|
+
S: this,
|
|
1194
|
+
A: [
|
|
1195
|
+
"!this._listeningHandle",
|
|
1196
|
+
""
|
|
1197
|
+
]
|
|
1198
|
+
});
|
|
987
1199
|
this._listeningHandle = await this._messenger.listen({
|
|
988
1200
|
peerId: this._ownPeerId,
|
|
989
1201
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
@@ -992,7 +1204,7 @@ var Swarm = class {
|
|
|
992
1204
|
err
|
|
993
1205
|
}, {
|
|
994
1206
|
F: __dxlog_file4,
|
|
995
|
-
L:
|
|
1207
|
+
L: 134,
|
|
996
1208
|
S: this,
|
|
997
1209
|
C: (f, a) => f(...a)
|
|
998
1210
|
}));
|
|
@@ -1000,27 +1212,34 @@ var Swarm = class {
|
|
|
1000
1212
|
});
|
|
1001
1213
|
}
|
|
1002
1214
|
async destroy() {
|
|
1003
|
-
var _a2;
|
|
1004
1215
|
(0, import_log4.log)("destroying...", void 0, {
|
|
1005
1216
|
F: __dxlog_file4,
|
|
1006
|
-
L:
|
|
1217
|
+
L: 140,
|
|
1007
1218
|
S: this,
|
|
1008
1219
|
C: (f, a) => f(...a)
|
|
1009
1220
|
});
|
|
1010
|
-
await
|
|
1221
|
+
await this._listeningHandle?.unsubscribe();
|
|
1011
1222
|
this._listeningHandle = void 0;
|
|
1012
1223
|
await this._ctx.dispose();
|
|
1013
1224
|
await this._topology.destroy();
|
|
1014
1225
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
1015
1226
|
(0, import_log4.log)("destroyed", void 0, {
|
|
1016
1227
|
F: __dxlog_file4,
|
|
1017
|
-
L:
|
|
1228
|
+
L: 147,
|
|
1018
1229
|
S: this,
|
|
1019
1230
|
C: (f, a) => f(...a)
|
|
1020
1231
|
});
|
|
1021
1232
|
}
|
|
1022
1233
|
async setTopology(topology) {
|
|
1023
|
-
(0,
|
|
1234
|
+
(0, import_invariant4.invariant)(!this._ctx.disposed, "Swarm is offline", {
|
|
1235
|
+
F: __dxlog_file4,
|
|
1236
|
+
L: 151,
|
|
1237
|
+
S: this,
|
|
1238
|
+
A: [
|
|
1239
|
+
"!this._ctx.disposed",
|
|
1240
|
+
"'Swarm is offline'"
|
|
1241
|
+
]
|
|
1242
|
+
});
|
|
1024
1243
|
if (topology === this._topology) {
|
|
1025
1244
|
return;
|
|
1026
1245
|
}
|
|
@@ -1029,7 +1248,7 @@ var Swarm = class {
|
|
|
1029
1248
|
topology: getClassName(topology)
|
|
1030
1249
|
}, {
|
|
1031
1250
|
F: __dxlog_file4,
|
|
1032
|
-
L:
|
|
1251
|
+
L: 155,
|
|
1033
1252
|
S: this,
|
|
1034
1253
|
C: (f, a) => f(...a)
|
|
1035
1254
|
});
|
|
@@ -1039,19 +1258,18 @@ var Swarm = class {
|
|
|
1039
1258
|
this._topology.update();
|
|
1040
1259
|
}
|
|
1041
1260
|
onSwarmEvent(swarmEvent) {
|
|
1042
|
-
var _a2;
|
|
1043
1261
|
(0, import_log4.log)("swarm event", {
|
|
1044
1262
|
swarmEvent
|
|
1045
1263
|
}, {
|
|
1046
1264
|
F: __dxlog_file4,
|
|
1047
|
-
L:
|
|
1265
|
+
L: 168,
|
|
1048
1266
|
S: this,
|
|
1049
1267
|
C: (f, a) => f(...a)
|
|
1050
1268
|
});
|
|
1051
1269
|
if (this._ctx.disposed) {
|
|
1052
1270
|
(0, import_log4.log)("swarm event ignored for disposed swarm", void 0, {
|
|
1053
1271
|
F: __dxlog_file4,
|
|
1054
|
-
L:
|
|
1272
|
+
L: 171,
|
|
1055
1273
|
S: this,
|
|
1056
1274
|
C: (f, a) => f(...a)
|
|
1057
1275
|
});
|
|
@@ -1063,7 +1281,7 @@ var Swarm = class {
|
|
|
1063
1281
|
peerId
|
|
1064
1282
|
}, {
|
|
1065
1283
|
F: __dxlog_file4,
|
|
1066
|
-
L:
|
|
1284
|
+
L: 177,
|
|
1067
1285
|
S: this,
|
|
1068
1286
|
C: (f, a) => f(...a)
|
|
1069
1287
|
});
|
|
@@ -1075,10 +1293,10 @@ var Swarm = class {
|
|
|
1075
1293
|
const peer = this._peers.get(import_keys4.PublicKey.from(swarmEvent.peerLeft.peer));
|
|
1076
1294
|
if (peer) {
|
|
1077
1295
|
peer.advertizing = false;
|
|
1078
|
-
if (
|
|
1296
|
+
if (peer.connection?.state !== ConnectionState.CONNECTED) {
|
|
1079
1297
|
void this._destroyPeer(peer.id).catch((err) => import_log4.log.catch(err, void 0, {
|
|
1080
1298
|
F: __dxlog_file4,
|
|
1081
|
-
L:
|
|
1299
|
+
L: 188,
|
|
1082
1300
|
S: this,
|
|
1083
1301
|
C: (f, a) => f(...a)
|
|
1084
1302
|
}));
|
|
@@ -1088,19 +1306,18 @@ var Swarm = class {
|
|
|
1088
1306
|
this._topology.update();
|
|
1089
1307
|
}
|
|
1090
1308
|
async onOffer(message) {
|
|
1091
|
-
var _a2, _b;
|
|
1092
1309
|
(0, import_log4.log)("offer", {
|
|
1093
1310
|
message
|
|
1094
1311
|
}, {
|
|
1095
1312
|
F: __dxlog_file4,
|
|
1096
|
-
L:
|
|
1313
|
+
L: 198,
|
|
1097
1314
|
S: this,
|
|
1098
1315
|
C: (f, a) => f(...a)
|
|
1099
1316
|
});
|
|
1100
1317
|
if (this._ctx.disposed) {
|
|
1101
1318
|
(0, import_log4.log)("ignored for disposed swarm", void 0, {
|
|
1102
1319
|
F: __dxlog_file4,
|
|
1103
|
-
L:
|
|
1320
|
+
L: 200,
|
|
1104
1321
|
S: this,
|
|
1105
1322
|
C: (f, a) => f(...a)
|
|
1106
1323
|
});
|
|
@@ -1108,13 +1325,21 @@ var Swarm = class {
|
|
|
1108
1325
|
accept: false
|
|
1109
1326
|
};
|
|
1110
1327
|
}
|
|
1111
|
-
(0,
|
|
1112
|
-
|
|
1328
|
+
(0, import_invariant4.invariant)(message.author, void 0, {
|
|
1329
|
+
F: __dxlog_file4,
|
|
1330
|
+
L: 205,
|
|
1331
|
+
S: this,
|
|
1332
|
+
A: [
|
|
1333
|
+
"message.author",
|
|
1334
|
+
""
|
|
1335
|
+
]
|
|
1336
|
+
});
|
|
1337
|
+
if (!message.recipient?.equals(this._ownPeerId)) {
|
|
1113
1338
|
(0, import_log4.log)("rejecting offer with incorrect peerId", {
|
|
1114
1339
|
message
|
|
1115
1340
|
}, {
|
|
1116
1341
|
F: __dxlog_file4,
|
|
1117
|
-
L:
|
|
1342
|
+
L: 207,
|
|
1118
1343
|
S: this,
|
|
1119
1344
|
C: (f, a) => f(...a)
|
|
1120
1345
|
});
|
|
@@ -1122,12 +1347,12 @@ var Swarm = class {
|
|
|
1122
1347
|
accept: false
|
|
1123
1348
|
};
|
|
1124
1349
|
}
|
|
1125
|
-
if (!
|
|
1350
|
+
if (!message.topic?.equals(this._topic)) {
|
|
1126
1351
|
(0, import_log4.log)("rejecting offer with incorrect topic", {
|
|
1127
1352
|
message
|
|
1128
1353
|
}, {
|
|
1129
1354
|
F: __dxlog_file4,
|
|
1130
|
-
L:
|
|
1355
|
+
L: 211,
|
|
1131
1356
|
S: this,
|
|
1132
1357
|
C: (f, a) => f(...a)
|
|
1133
1358
|
});
|
|
@@ -1141,27 +1366,50 @@ var Swarm = class {
|
|
|
1141
1366
|
return answer;
|
|
1142
1367
|
}
|
|
1143
1368
|
async onSignal(message) {
|
|
1144
|
-
var _a2, _b;
|
|
1145
1369
|
(0, import_log4.log)("signal", {
|
|
1146
1370
|
message
|
|
1147
1371
|
}, {
|
|
1148
1372
|
F: __dxlog_file4,
|
|
1149
|
-
L:
|
|
1373
|
+
L: 222,
|
|
1150
1374
|
S: this,
|
|
1151
1375
|
C: (f, a) => f(...a)
|
|
1152
1376
|
});
|
|
1153
1377
|
if (this._ctx.disposed) {
|
|
1154
1378
|
import_log4.log.info("ignored for offline swarm", void 0, {
|
|
1155
1379
|
F: __dxlog_file4,
|
|
1156
|
-
L:
|
|
1380
|
+
L: 224,
|
|
1157
1381
|
S: this,
|
|
1158
1382
|
C: (f, a) => f(...a)
|
|
1159
1383
|
});
|
|
1160
1384
|
return;
|
|
1161
1385
|
}
|
|
1162
|
-
(0,
|
|
1163
|
-
|
|
1164
|
-
|
|
1386
|
+
(0, import_invariant4.invariant)(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1387
|
+
F: __dxlog_file4,
|
|
1388
|
+
L: 227,
|
|
1389
|
+
S: this,
|
|
1390
|
+
A: [
|
|
1391
|
+
"message.recipient?.equals(this._ownPeerId)",
|
|
1392
|
+
"`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
|
|
1393
|
+
]
|
|
1394
|
+
});
|
|
1395
|
+
(0, import_invariant4.invariant)(message.topic?.equals(this._topic), void 0, {
|
|
1396
|
+
F: __dxlog_file4,
|
|
1397
|
+
L: 231,
|
|
1398
|
+
S: this,
|
|
1399
|
+
A: [
|
|
1400
|
+
"message.topic?.equals(this._topic)",
|
|
1401
|
+
""
|
|
1402
|
+
]
|
|
1403
|
+
});
|
|
1404
|
+
(0, import_invariant4.invariant)(message.author, void 0, {
|
|
1405
|
+
F: __dxlog_file4,
|
|
1406
|
+
L: 232,
|
|
1407
|
+
S: this,
|
|
1408
|
+
A: [
|
|
1409
|
+
"message.author",
|
|
1410
|
+
""
|
|
1411
|
+
]
|
|
1412
|
+
});
|
|
1165
1413
|
const peer = this._getOrCreatePeer(message.author);
|
|
1166
1414
|
await peer.onSignal(message);
|
|
1167
1415
|
}
|
|
@@ -1213,7 +1461,15 @@ var Swarm = class {
|
|
|
1213
1461
|
return peer;
|
|
1214
1462
|
}
|
|
1215
1463
|
async _destroyPeer(peerId) {
|
|
1216
|
-
(0,
|
|
1464
|
+
(0, import_invariant4.invariant)(this._peers.has(peerId), void 0, {
|
|
1465
|
+
F: __dxlog_file4,
|
|
1466
|
+
L: 302,
|
|
1467
|
+
S: this,
|
|
1468
|
+
A: [
|
|
1469
|
+
"this._peers.has(peerId)",
|
|
1470
|
+
""
|
|
1471
|
+
]
|
|
1472
|
+
});
|
|
1217
1473
|
await this._peers.get(peerId).destroy();
|
|
1218
1474
|
this._peers.delete(peerId);
|
|
1219
1475
|
}
|
|
@@ -1234,7 +1490,7 @@ var Swarm = class {
|
|
|
1234
1490
|
} catch (err) {
|
|
1235
1491
|
(0, import_log4.log)("initiation error", err, {
|
|
1236
1492
|
F: __dxlog_file4,
|
|
1237
|
-
L:
|
|
1493
|
+
L: 328,
|
|
1238
1494
|
S: this,
|
|
1239
1495
|
C: (f, a) => f(...a)
|
|
1240
1496
|
});
|
|
@@ -1262,7 +1518,7 @@ var Swarm = class {
|
|
|
1262
1518
|
remoteId
|
|
1263
1519
|
}, {
|
|
1264
1520
|
F: __dxlog_file4,
|
|
1265
|
-
L:
|
|
1521
|
+
L: 355,
|
|
1266
1522
|
S: this,
|
|
1267
1523
|
C: (f, a) => f(...a)
|
|
1268
1524
|
});
|
|
@@ -1279,7 +1535,7 @@ var Swarm = class {
|
|
|
1279
1535
|
remoteId
|
|
1280
1536
|
}, {
|
|
1281
1537
|
F: __dxlog_file4,
|
|
1282
|
-
L:
|
|
1538
|
+
L: 369,
|
|
1283
1539
|
S: this,
|
|
1284
1540
|
C: (f, a) => f(...a)
|
|
1285
1541
|
});
|
|
@@ -1289,7 +1545,7 @@ var Swarm = class {
|
|
|
1289
1545
|
remoteId
|
|
1290
1546
|
}, {
|
|
1291
1547
|
F: __dxlog_file4,
|
|
1292
|
-
L:
|
|
1548
|
+
L: 372,
|
|
1293
1549
|
S: this,
|
|
1294
1550
|
C: (f, a) => f(...a)
|
|
1295
1551
|
});
|
|
@@ -1348,8 +1604,7 @@ var SwarmMapper = class {
|
|
|
1348
1604
|
}));
|
|
1349
1605
|
}));
|
|
1350
1606
|
this._subscriptions.add(_swarm.disconnected.on((peerId) => {
|
|
1351
|
-
|
|
1352
|
-
(_a2 = this._connectionSubscriptions.get(peerId)) == null ? void 0 : _a2();
|
|
1607
|
+
this._connectionSubscriptions.get(peerId)?.();
|
|
1353
1608
|
this._connectionSubscriptions.delete(peerId);
|
|
1354
1609
|
this._update();
|
|
1355
1610
|
}));
|
|
@@ -1399,6 +1654,7 @@ var SwarmMapper = class {
|
|
|
1399
1654
|
var import_async5 = require("@dxos/async");
|
|
1400
1655
|
var import_context5 = require("@dxos/context");
|
|
1401
1656
|
var import_errors3 = require("@dxos/errors");
|
|
1657
|
+
var import_invariant5 = require("@dxos/invariant");
|
|
1402
1658
|
var import_keys6 = require("@dxos/keys");
|
|
1403
1659
|
var import_log6 = require("@dxos/log");
|
|
1404
1660
|
var import_util4 = require("@dxos/util");
|
|
@@ -1422,9 +1678,9 @@ var ConnectionLimiter = class {
|
|
|
1422
1678
|
* @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
|
|
1423
1679
|
*/
|
|
1424
1680
|
async connecting(sessionId) {
|
|
1425
|
-
(0,
|
|
1681
|
+
(0, import_invariant5.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
1426
1682
|
F: __dxlog_file6,
|
|
1427
|
-
L:
|
|
1683
|
+
L: 48,
|
|
1428
1684
|
S: this,
|
|
1429
1685
|
A: [
|
|
1430
1686
|
"!this._waitingPromises.has(sessionId)",
|
|
@@ -1435,7 +1691,7 @@ var ConnectionLimiter = class {
|
|
|
1435
1691
|
sessionId
|
|
1436
1692
|
}, {
|
|
1437
1693
|
F: __dxlog_file6,
|
|
1438
|
-
L:
|
|
1694
|
+
L: 49,
|
|
1439
1695
|
S: this,
|
|
1440
1696
|
C: (f, a) => f(...a)
|
|
1441
1697
|
});
|
|
@@ -1450,7 +1706,7 @@ var ConnectionLimiter = class {
|
|
|
1450
1706
|
sessionId
|
|
1451
1707
|
}, {
|
|
1452
1708
|
F: __dxlog_file6,
|
|
1453
|
-
L:
|
|
1709
|
+
L: 57,
|
|
1454
1710
|
S: this,
|
|
1455
1711
|
C: (f, a) => f(...a)
|
|
1456
1712
|
});
|
|
@@ -1463,7 +1719,7 @@ var ConnectionLimiter = class {
|
|
|
1463
1719
|
sessionId
|
|
1464
1720
|
}, {
|
|
1465
1721
|
F: __dxlog_file6,
|
|
1466
|
-
L:
|
|
1722
|
+
L: 64,
|
|
1467
1723
|
S: this,
|
|
1468
1724
|
C: (f, a) => f(...a)
|
|
1469
1725
|
});
|
|
@@ -1494,8 +1750,7 @@ var ConnectionLog = class {
|
|
|
1494
1750
|
this.update = new import_async6.Event();
|
|
1495
1751
|
}
|
|
1496
1752
|
getSwarmInfo(swarmId) {
|
|
1497
|
-
|
|
1498
|
-
return (_a2 = this._swarms.get(swarmId)) != null ? _a2 : (0, import_debug3.raise)(new Error(`Swarm not found: ${swarmId}`));
|
|
1753
|
+
return this._swarms.get(swarmId) ?? (0, import_debug3.raise)(new Error(`Swarm not found: ${swarmId}`));
|
|
1499
1754
|
}
|
|
1500
1755
|
get swarms() {
|
|
1501
1756
|
return Array.from(this._swarms.values());
|
|
@@ -1511,7 +1766,6 @@ var ConnectionLog = class {
|
|
|
1511
1766
|
this._swarms.set(import_keys7.PublicKey.from(swarm._instanceId), info);
|
|
1512
1767
|
this.update.emit();
|
|
1513
1768
|
swarm.connectionAdded.on((connection) => {
|
|
1514
|
-
var _a2, _b;
|
|
1515
1769
|
const connectionInfo = {
|
|
1516
1770
|
state: ConnectionState.INITIAL,
|
|
1517
1771
|
remotePeerId: connection.remoteId,
|
|
@@ -1530,7 +1784,7 @@ var ConnectionLog = class {
|
|
|
1530
1784
|
});
|
|
1531
1785
|
this.update.emit();
|
|
1532
1786
|
});
|
|
1533
|
-
|
|
1787
|
+
connection.protocol?.stats?.on((stats) => {
|
|
1534
1788
|
connectionInfo.streams = stats.channels;
|
|
1535
1789
|
this.update.emit();
|
|
1536
1790
|
});
|
|
@@ -1557,10 +1811,7 @@ var NetworkManager = class {
|
|
|
1557
1811
|
this._instanceId = import_keys8.PublicKey.random().toHex();
|
|
1558
1812
|
this._transportFactory = transportFactory;
|
|
1559
1813
|
this._signalManager = signalManager;
|
|
1560
|
-
this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) =>
|
|
1561
|
-
var _a2;
|
|
1562
|
-
return (_a2 = this._swarms.get(topic)) == null ? void 0 : _a2.onSwarmEvent(event);
|
|
1563
|
-
});
|
|
1814
|
+
this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => this._swarms.get(topic)?.onSwarmEvent(event));
|
|
1564
1815
|
this._messenger = new import_messaging.Messenger({
|
|
1565
1816
|
signalManager: this._signalManager
|
|
1566
1817
|
});
|
|
@@ -1595,7 +1846,7 @@ var NetworkManager = class {
|
|
|
1595
1846
|
id: this._instanceId
|
|
1596
1847
|
}), {
|
|
1597
1848
|
F: __dxlog_file7,
|
|
1598
|
-
L:
|
|
1849
|
+
L: 130,
|
|
1599
1850
|
S: this,
|
|
1600
1851
|
C: (f, a) => f(...a)
|
|
1601
1852
|
});
|
|
@@ -1605,7 +1856,7 @@ var NetworkManager = class {
|
|
|
1605
1856
|
id: this._instanceId
|
|
1606
1857
|
}), {
|
|
1607
1858
|
F: __dxlog_file7,
|
|
1608
|
-
L:
|
|
1859
|
+
L: 133,
|
|
1609
1860
|
S: this,
|
|
1610
1861
|
C: (f, a) => f(...a)
|
|
1611
1862
|
});
|
|
@@ -1615,7 +1866,7 @@ var NetworkManager = class {
|
|
|
1615
1866
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1616
1867
|
(0, import_log7.log)(err, void 0, {
|
|
1617
1868
|
F: __dxlog_file7,
|
|
1618
|
-
L:
|
|
1869
|
+
L: 139,
|
|
1619
1870
|
S: this,
|
|
1620
1871
|
C: (f, a) => f(...a)
|
|
1621
1872
|
});
|
|
@@ -1628,11 +1879,42 @@ var NetworkManager = class {
|
|
|
1628
1879
|
* Join the swarm.
|
|
1629
1880
|
*/
|
|
1630
1881
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1882
|
+
(0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(topic), void 0, {
|
|
1883
|
+
F: __dxlog_file7,
|
|
1884
|
+
L: 157,
|
|
1885
|
+
S: this,
|
|
1886
|
+
A: [
|
|
1887
|
+
"PublicKey.isPublicKey(topic)",
|
|
1888
|
+
""
|
|
1889
|
+
]
|
|
1890
|
+
});
|
|
1891
|
+
(0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(peerId), void 0, {
|
|
1892
|
+
F: __dxlog_file7,
|
|
1893
|
+
L: 158,
|
|
1894
|
+
S: this,
|
|
1895
|
+
A: [
|
|
1896
|
+
"PublicKey.isPublicKey(peerId)",
|
|
1897
|
+
""
|
|
1898
|
+
]
|
|
1899
|
+
});
|
|
1900
|
+
(0, import_invariant6.invariant)(topology, void 0, {
|
|
1901
|
+
F: __dxlog_file7,
|
|
1902
|
+
L: 159,
|
|
1903
|
+
S: this,
|
|
1904
|
+
A: [
|
|
1905
|
+
"topology",
|
|
1906
|
+
""
|
|
1907
|
+
]
|
|
1908
|
+
});
|
|
1909
|
+
(0, import_invariant6.invariant)(typeof protocol === "function", void 0, {
|
|
1910
|
+
F: __dxlog_file7,
|
|
1911
|
+
L: 160,
|
|
1912
|
+
S: this,
|
|
1913
|
+
A: [
|
|
1914
|
+
"typeof protocol === 'function'",
|
|
1915
|
+
""
|
|
1916
|
+
]
|
|
1917
|
+
});
|
|
1636
1918
|
if (this._swarms.has(topic)) {
|
|
1637
1919
|
throw new Error(`Already connected to swarm: ${import_keys8.PublicKey.from(topic)}`);
|
|
1638
1920
|
}
|
|
@@ -1642,7 +1924,7 @@ var NetworkManager = class {
|
|
|
1642
1924
|
topology: topology.toString()
|
|
1643
1925
|
}, {
|
|
1644
1926
|
F: __dxlog_file7,
|
|
1645
|
-
L:
|
|
1927
|
+
L: 165,
|
|
1646
1928
|
S: this,
|
|
1647
1929
|
C: (f, a) => f(...a)
|
|
1648
1930
|
});
|
|
@@ -1652,7 +1934,7 @@ var NetworkManager = class {
|
|
|
1652
1934
|
error
|
|
1653
1935
|
}, {
|
|
1654
1936
|
F: __dxlog_file7,
|
|
1655
|
-
L:
|
|
1937
|
+
L: 178,
|
|
1656
1938
|
S: this,
|
|
1657
1939
|
C: (f, a) => f(...a)
|
|
1658
1940
|
});
|
|
@@ -1665,18 +1947,18 @@ var NetworkManager = class {
|
|
|
1665
1947
|
peerId
|
|
1666
1948
|
}).catch((error) => import_log7.log.catch(error, void 0, {
|
|
1667
1949
|
F: __dxlog_file7,
|
|
1668
|
-
L:
|
|
1950
|
+
L: 187,
|
|
1669
1951
|
S: this,
|
|
1670
1952
|
C: (f, a) => f(...a)
|
|
1671
1953
|
}));
|
|
1672
1954
|
this.topicsUpdated.emit();
|
|
1673
|
-
|
|
1955
|
+
this._connectionLog?.joinedSwarm(swarm);
|
|
1674
1956
|
(0, import_log7.log)("joined", {
|
|
1675
1957
|
topic: import_keys8.PublicKey.from(topic),
|
|
1676
1958
|
count: this._swarms.size
|
|
1677
1959
|
}, {
|
|
1678
1960
|
F: __dxlog_file7,
|
|
1679
|
-
L:
|
|
1961
|
+
L: 191,
|
|
1680
1962
|
S: this,
|
|
1681
1963
|
C: (f, a) => f(...a)
|
|
1682
1964
|
});
|
|
@@ -1688,7 +1970,6 @@ var NetworkManager = class {
|
|
|
1688
1970
|
* Close the connection.
|
|
1689
1971
|
*/
|
|
1690
1972
|
async leaveSwarm(topic) {
|
|
1691
|
-
var _a2;
|
|
1692
1973
|
if (!this._swarms.has(topic)) {
|
|
1693
1974
|
return;
|
|
1694
1975
|
}
|
|
@@ -1696,7 +1977,7 @@ var NetworkManager = class {
|
|
|
1696
1977
|
topic: import_keys8.PublicKey.from(topic)
|
|
1697
1978
|
}, {
|
|
1698
1979
|
F: __dxlog_file7,
|
|
1699
|
-
L:
|
|
1980
|
+
L: 207,
|
|
1700
1981
|
S: this,
|
|
1701
1982
|
C: (f, a) => f(...a)
|
|
1702
1983
|
});
|
|
@@ -1708,7 +1989,7 @@ var NetworkManager = class {
|
|
|
1708
1989
|
const map = this._mappers.get(topic);
|
|
1709
1990
|
map.destroy();
|
|
1710
1991
|
this._mappers.delete(topic);
|
|
1711
|
-
|
|
1992
|
+
this._connectionLog?.leftSwarm(swarm);
|
|
1712
1993
|
await swarm.destroy();
|
|
1713
1994
|
this._swarms.delete(topic);
|
|
1714
1995
|
await this.topicsUpdated.emit();
|
|
@@ -1717,7 +1998,7 @@ var NetworkManager = class {
|
|
|
1717
1998
|
count: this._swarms.size
|
|
1718
1999
|
}, {
|
|
1719
2000
|
F: __dxlog_file7,
|
|
1720
|
-
L:
|
|
2001
|
+
L: 221,
|
|
1721
2002
|
S: this,
|
|
1722
2003
|
C: (f, a) => f(...a)
|
|
1723
2004
|
});
|
|
@@ -1751,17 +2032,34 @@ var NetworkManager = class {
|
|
|
1751
2032
|
};
|
|
1752
2033
|
|
|
1753
2034
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1754
|
-
var
|
|
2035
|
+
var import_invariant7 = require("@dxos/invariant");
|
|
2036
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
1755
2037
|
var FullyConnectedTopology = class {
|
|
1756
2038
|
toString() {
|
|
1757
2039
|
return "FullyConnectedTopology";
|
|
1758
2040
|
}
|
|
1759
2041
|
init(controller) {
|
|
1760
|
-
(0,
|
|
2042
|
+
(0, import_invariant7.invariant)(!this._controller, "Already initialized", {
|
|
2043
|
+
F: __dxlog_file8,
|
|
2044
|
+
L: 18,
|
|
2045
|
+
S: this,
|
|
2046
|
+
A: [
|
|
2047
|
+
"!this._controller",
|
|
2048
|
+
"'Already initialized'"
|
|
2049
|
+
]
|
|
2050
|
+
});
|
|
1761
2051
|
this._controller = controller;
|
|
1762
2052
|
}
|
|
1763
2053
|
update() {
|
|
1764
|
-
(0,
|
|
2054
|
+
(0, import_invariant7.invariant)(this._controller, "Not initialized", {
|
|
2055
|
+
F: __dxlog_file8,
|
|
2056
|
+
L: 23,
|
|
2057
|
+
S: this,
|
|
2058
|
+
A: [
|
|
2059
|
+
"this._controller",
|
|
2060
|
+
"'Not initialized'"
|
|
2061
|
+
]
|
|
2062
|
+
});
|
|
1765
2063
|
const { candidates: discovered } = this._controller.getState();
|
|
1766
2064
|
for (const peer of discovered) {
|
|
1767
2065
|
this._controller.connect(peer);
|
|
@@ -1775,19 +2073,19 @@ var FullyConnectedTopology = class {
|
|
|
1775
2073
|
};
|
|
1776
2074
|
|
|
1777
2075
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1778
|
-
var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
|
|
1779
2076
|
var import_xor_distance = __toESM(require("xor-distance"));
|
|
2077
|
+
var import_invariant8 = require("@dxos/invariant");
|
|
1780
2078
|
var import_log8 = require("@dxos/log");
|
|
1781
2079
|
|
|
1782
2080
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1783
|
-
var
|
|
2081
|
+
var import_invariant9 = require("@dxos/invariant");
|
|
1784
2082
|
var import_log9 = require("@dxos/log");
|
|
1785
2083
|
|
|
1786
2084
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1787
2085
|
var import_node_stream = require("node:stream");
|
|
1788
|
-
var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
|
|
1789
2086
|
var import_async8 = require("@dxos/async");
|
|
1790
2087
|
var import_debug4 = require("@dxos/debug");
|
|
2088
|
+
var import_invariant10 = require("@dxos/invariant");
|
|
1791
2089
|
var import_keys9 = require("@dxos/keys");
|
|
1792
2090
|
var import_log10 = require("@dxos/log");
|
|
1793
2091
|
var import_util7 = require("@dxos/util");
|
|
@@ -1801,7 +2099,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
1801
2099
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1802
2100
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1803
2101
|
}
|
|
1804
|
-
var
|
|
2102
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
1805
2103
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1806
2104
|
var createStreamDelay = (delay) => {
|
|
1807
2105
|
return new import_node_stream.Transform({
|
|
@@ -1814,9 +2112,12 @@ var createStreamDelay = (delay) => {
|
|
|
1814
2112
|
var MemoryTransportFactory = {
|
|
1815
2113
|
createTransport: (params) => new MemoryTransport(params)
|
|
1816
2114
|
};
|
|
1817
|
-
var
|
|
2115
|
+
var MemoryTransport = class _MemoryTransport {
|
|
2116
|
+
static {
|
|
2117
|
+
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
2118
|
+
this._connections = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
|
|
2119
|
+
}
|
|
1818
2120
|
constructor(options) {
|
|
1819
|
-
var _a2;
|
|
1820
2121
|
this.options = options;
|
|
1821
2122
|
this.closed = new import_async8.Event();
|
|
1822
2123
|
this.connected = new import_async8.Event();
|
|
@@ -1827,17 +2128,25 @@ var _MemoryTransport = class {
|
|
|
1827
2128
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1828
2129
|
this._destroyed = false;
|
|
1829
2130
|
(0, import_log10.log)("creating", void 0, {
|
|
1830
|
-
F:
|
|
2131
|
+
F: __dxlog_file9,
|
|
1831
2132
|
L: 64,
|
|
1832
2133
|
S: this,
|
|
1833
2134
|
C: (f, a) => f(...a)
|
|
1834
2135
|
});
|
|
1835
|
-
(0,
|
|
2136
|
+
(0, import_invariant10.invariant)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2137
|
+
F: __dxlog_file9,
|
|
2138
|
+
L: 66,
|
|
2139
|
+
S: this,
|
|
2140
|
+
A: [
|
|
2141
|
+
"!MemoryTransport._connections.has(this._instanceId)",
|
|
2142
|
+
"'Duplicate memory connection'"
|
|
2143
|
+
]
|
|
2144
|
+
});
|
|
1836
2145
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1837
2146
|
if (this.options.initiator) {
|
|
1838
2147
|
setTimeout(async () => {
|
|
1839
2148
|
(0, import_log10.log)("sending signal", void 0, {
|
|
1840
|
-
F:
|
|
2149
|
+
F: __dxlog_file9,
|
|
1841
2150
|
L: 73,
|
|
1842
2151
|
S: this,
|
|
1843
2152
|
C: (f, a) => f(...a)
|
|
@@ -1854,7 +2163,7 @@ var _MemoryTransport = class {
|
|
|
1854
2163
|
});
|
|
1855
2164
|
} else {
|
|
1856
2165
|
this._remote.wait({
|
|
1857
|
-
timeout:
|
|
2166
|
+
timeout: this.options.timeout ?? 1e3
|
|
1858
2167
|
}).then((remoteId) => {
|
|
1859
2168
|
if (this._destroyed) {
|
|
1860
2169
|
return;
|
|
@@ -1866,11 +2175,19 @@ var _MemoryTransport = class {
|
|
|
1866
2175
|
this.closed.emit();
|
|
1867
2176
|
return;
|
|
1868
2177
|
}
|
|
1869
|
-
(0,
|
|
2178
|
+
(0, import_invariant10.invariant)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2179
|
+
F: __dxlog_file9,
|
|
2180
|
+
L: 99,
|
|
2181
|
+
S: this,
|
|
2182
|
+
A: [
|
|
2183
|
+
"!this._remoteConnection._remoteConnection",
|
|
2184
|
+
"`Remote already connected: ${this._remoteInstanceId}`"
|
|
2185
|
+
]
|
|
2186
|
+
});
|
|
1870
2187
|
this._remoteConnection._remoteConnection = this;
|
|
1871
2188
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1872
2189
|
(0, import_log10.log)("connected", void 0, {
|
|
1873
|
-
F:
|
|
2190
|
+
F: __dxlog_file9,
|
|
1874
2191
|
L: 103,
|
|
1875
2192
|
S: this,
|
|
1876
2193
|
C: (f, a) => f(...a)
|
|
@@ -1888,7 +2205,7 @@ var _MemoryTransport = class {
|
|
|
1888
2205
|
}
|
|
1889
2206
|
async destroy() {
|
|
1890
2207
|
(0, import_log10.log)("closing", void 0, {
|
|
1891
|
-
F:
|
|
2208
|
+
F: __dxlog_file9,
|
|
1892
2209
|
L: 124,
|
|
1893
2210
|
S: this,
|
|
1894
2211
|
C: (f, a) => f(...a)
|
|
@@ -1897,7 +2214,7 @@ var _MemoryTransport = class {
|
|
|
1897
2214
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
1898
2215
|
if (this._remoteConnection) {
|
|
1899
2216
|
(0, import_log10.log)("closing", void 0, {
|
|
1900
|
-
F:
|
|
2217
|
+
F: __dxlog_file9,
|
|
1901
2218
|
L: 129,
|
|
1902
2219
|
S: this,
|
|
1903
2220
|
C: (f, a) => f(...a)
|
|
@@ -1910,7 +2227,7 @@ var _MemoryTransport = class {
|
|
|
1910
2227
|
this._remoteConnection._remoteConnection = void 0;
|
|
1911
2228
|
this._remoteConnection = void 0;
|
|
1912
2229
|
(0, import_log10.log)("closed", void 0, {
|
|
1913
|
-
F:
|
|
2230
|
+
F: __dxlog_file9,
|
|
1914
2231
|
L: 147,
|
|
1915
2232
|
S: this,
|
|
1916
2233
|
C: (f, a) => f(...a)
|
|
@@ -1918,7 +2235,7 @@ var _MemoryTransport = class {
|
|
|
1918
2235
|
}
|
|
1919
2236
|
this.closed.emit();
|
|
1920
2237
|
(0, import_log10.log)("closed", void 0, {
|
|
1921
|
-
F:
|
|
2238
|
+
F: __dxlog_file9,
|
|
1922
2239
|
L: 151,
|
|
1923
2240
|
S: this,
|
|
1924
2241
|
C: (f, a) => f(...a)
|
|
@@ -1928,12 +2245,12 @@ var _MemoryTransport = class {
|
|
|
1928
2245
|
(0, import_log10.log)("received signal", {
|
|
1929
2246
|
payload
|
|
1930
2247
|
}, {
|
|
1931
|
-
F:
|
|
2248
|
+
F: __dxlog_file9,
|
|
1932
2249
|
L: 155,
|
|
1933
2250
|
S: this,
|
|
1934
2251
|
C: (f, a) => f(...a)
|
|
1935
2252
|
});
|
|
1936
|
-
if (!
|
|
2253
|
+
if (!payload?.transportId) {
|
|
1937
2254
|
return;
|
|
1938
2255
|
}
|
|
1939
2256
|
const transportId = payload.transportId;
|
|
@@ -1943,9 +2260,6 @@ var _MemoryTransport = class {
|
|
|
1943
2260
|
}
|
|
1944
2261
|
}
|
|
1945
2262
|
};
|
|
1946
|
-
var MemoryTransport = _MemoryTransport;
|
|
1947
|
-
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
1948
|
-
MemoryTransport._connections = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
|
|
1949
2263
|
_ts_decorate4([
|
|
1950
2264
|
import_log10.logInfo
|
|
1951
2265
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
@@ -1955,9 +2269,9 @@ _ts_decorate4([
|
|
|
1955
2269
|
|
|
1956
2270
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1957
2271
|
var import_simple_peer = __toESM(require("simple-peer"));
|
|
1958
|
-
var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
|
|
1959
2272
|
var import_async9 = require("@dxos/async");
|
|
1960
2273
|
var import_debug5 = require("@dxos/debug");
|
|
2274
|
+
var import_invariant11 = require("@dxos/invariant");
|
|
1961
2275
|
var import_keys10 = require("@dxos/keys");
|
|
1962
2276
|
var import_log11 = require("@dxos/log");
|
|
1963
2277
|
var import_protocols5 = require("@dxos/protocols");
|
|
@@ -1966,14 +2280,13 @@ var import_protocols5 = require("@dxos/protocols");
|
|
|
1966
2280
|
var wrtc = null;
|
|
1967
2281
|
try {
|
|
1968
2282
|
wrtc = require("@koush/wrtc");
|
|
1969
|
-
} catch
|
|
2283
|
+
} catch {
|
|
1970
2284
|
}
|
|
1971
2285
|
|
|
1972
2286
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1973
|
-
var
|
|
2287
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
|
|
1974
2288
|
var WebRTCTransport = class {
|
|
1975
2289
|
constructor(params) {
|
|
1976
|
-
var _a2;
|
|
1977
2290
|
this.params = params;
|
|
1978
2291
|
this._closed = false;
|
|
1979
2292
|
this.closed = new import_async9.Event();
|
|
@@ -1983,25 +2296,25 @@ var WebRTCTransport = class {
|
|
|
1983
2296
|
import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
|
|
1984
2297
|
id: this._instanceId
|
|
1985
2298
|
}), {
|
|
1986
|
-
F:
|
|
2299
|
+
F: __dxlog_file10,
|
|
1987
2300
|
L: 39,
|
|
1988
2301
|
S: this,
|
|
1989
2302
|
C: (f, a) => f(...a)
|
|
1990
2303
|
});
|
|
1991
2304
|
(0, import_log11.log)("created connection", params, {
|
|
1992
|
-
F:
|
|
2305
|
+
F: __dxlog_file10,
|
|
1993
2306
|
L: 40,
|
|
1994
2307
|
S: this,
|
|
1995
2308
|
C: (f, a) => f(...a)
|
|
1996
2309
|
});
|
|
1997
2310
|
this._peer = new import_simple_peer.default({
|
|
1998
2311
|
initiator: this.params.initiator,
|
|
1999
|
-
wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 :
|
|
2312
|
+
wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 : wrtc ?? (0, import_debug5.raise)(new Error("wrtc not available")),
|
|
2000
2313
|
config: this.params.webrtcConfig
|
|
2001
2314
|
});
|
|
2002
2315
|
this._peer.on("signal", async (data) => {
|
|
2003
2316
|
(0, import_log11.log)("signal", data, {
|
|
2004
|
-
F:
|
|
2317
|
+
F: __dxlog_file10,
|
|
2005
2318
|
L: 48,
|
|
2006
2319
|
S: this,
|
|
2007
2320
|
C: (f, a) => f(...a)
|
|
@@ -2014,7 +2327,7 @@ var WebRTCTransport = class {
|
|
|
2014
2327
|
});
|
|
2015
2328
|
this._peer.on("connect", () => {
|
|
2016
2329
|
(0, import_log11.log)("connected", void 0, {
|
|
2017
|
-
F:
|
|
2330
|
+
F: __dxlog_file10,
|
|
2018
2331
|
L: 53,
|
|
2019
2332
|
S: this,
|
|
2020
2333
|
C: (f, a) => f(...a)
|
|
@@ -2024,7 +2337,7 @@ var WebRTCTransport = class {
|
|
|
2024
2337
|
});
|
|
2025
2338
|
this._peer.on("close", async () => {
|
|
2026
2339
|
(0, import_log11.log)("closed", void 0, {
|
|
2027
|
-
F:
|
|
2340
|
+
F: __dxlog_file10,
|
|
2028
2341
|
L: 59,
|
|
2029
2342
|
S: this,
|
|
2030
2343
|
C: (f, a) => f(...a)
|
|
@@ -2033,30 +2346,29 @@ var WebRTCTransport = class {
|
|
|
2033
2346
|
this.closed.emit();
|
|
2034
2347
|
});
|
|
2035
2348
|
this._peer.on("error", async (err) => {
|
|
2036
|
-
var _a3;
|
|
2037
2349
|
this.errors.raise(err);
|
|
2038
2350
|
try {
|
|
2039
|
-
if (typeof
|
|
2351
|
+
if (typeof this._peer?._pc.getStats === "function") {
|
|
2040
2352
|
this._peer._pc.getStats().then((stats) => {
|
|
2041
2353
|
import_log11.log.warn("report after webrtc error", {
|
|
2042
2354
|
config: this.params.webrtcConfig,
|
|
2043
2355
|
stats
|
|
2044
2356
|
}, {
|
|
2045
|
-
F:
|
|
2357
|
+
F: __dxlog_file10,
|
|
2046
2358
|
L: 71,
|
|
2047
2359
|
S: this,
|
|
2048
2360
|
C: (f, a) => f(...a)
|
|
2049
2361
|
});
|
|
2050
2362
|
});
|
|
2051
2363
|
}
|
|
2052
|
-
} catch
|
|
2364
|
+
} catch {
|
|
2053
2365
|
}
|
|
2054
2366
|
await this.destroy();
|
|
2055
2367
|
});
|
|
2056
2368
|
import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
|
|
2057
2369
|
id: this._instanceId
|
|
2058
2370
|
}), {
|
|
2059
|
-
F:
|
|
2371
|
+
F: __dxlog_file10,
|
|
2060
2372
|
L: 81,
|
|
2061
2373
|
S: this,
|
|
2062
2374
|
C: (f, a) => f(...a)
|
|
@@ -2064,7 +2376,7 @@ var WebRTCTransport = class {
|
|
|
2064
2376
|
}
|
|
2065
2377
|
async destroy() {
|
|
2066
2378
|
(0, import_log11.log)("closing...", void 0, {
|
|
2067
|
-
F:
|
|
2379
|
+
F: __dxlog_file10,
|
|
2068
2380
|
L: 85,
|
|
2069
2381
|
S: this,
|
|
2070
2382
|
C: (f, a) => f(...a)
|
|
@@ -2074,7 +2386,7 @@ var WebRTCTransport = class {
|
|
|
2074
2386
|
this._peer.destroy();
|
|
2075
2387
|
this.closed.emit();
|
|
2076
2388
|
(0, import_log11.log)("closed", void 0, {
|
|
2077
|
-
F:
|
|
2389
|
+
F: __dxlog_file10,
|
|
2078
2390
|
L: 90,
|
|
2079
2391
|
S: this,
|
|
2080
2392
|
C: (f, a) => f(...a)
|
|
@@ -2084,24 +2396,31 @@ var WebRTCTransport = class {
|
|
|
2084
2396
|
if (this._closed) {
|
|
2085
2397
|
return;
|
|
2086
2398
|
}
|
|
2087
|
-
(0,
|
|
2399
|
+
(0, import_invariant11.invariant)(signal.payload.data, "Signal message must contain signal data.", {
|
|
2400
|
+
F: __dxlog_file10,
|
|
2401
|
+
L: 98,
|
|
2402
|
+
S: this,
|
|
2403
|
+
A: [
|
|
2404
|
+
"signal.payload.data",
|
|
2405
|
+
"'Signal message must contain signal data.'"
|
|
2406
|
+
]
|
|
2407
|
+
});
|
|
2088
2408
|
this._peer.signal(signal.payload.data);
|
|
2089
2409
|
}
|
|
2090
2410
|
async _disconnectStreams() {
|
|
2091
|
-
|
|
2092
|
-
(_d = (_c = (_b = (_a2 = this.params.stream).unpipe) == null ? void 0 : _b.call(_a2, this._peer)) == null ? void 0 : _c.unpipe) == null ? void 0 : _d.call(_c, this.params.stream);
|
|
2411
|
+
this.params.stream.unpipe?.(this._peer)?.unpipe?.(this.params.stream);
|
|
2093
2412
|
}
|
|
2094
2413
|
};
|
|
2095
2414
|
|
|
2096
2415
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
2097
2416
|
var import_node_stream2 = require("node:stream");
|
|
2098
|
-
var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
|
|
2099
2417
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
2418
|
+
var import_invariant12 = require("@dxos/invariant");
|
|
2100
2419
|
var import_keys11 = require("@dxos/keys");
|
|
2101
2420
|
var import_log12 = require("@dxos/log");
|
|
2102
2421
|
var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2103
2422
|
var import_util8 = require("@dxos/util");
|
|
2104
|
-
var
|
|
2423
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
|
|
2105
2424
|
var WebRTCTransportService = class {
|
|
2106
2425
|
// prettier-ignore
|
|
2107
2426
|
constructor(_webrtcConfig) {
|
|
@@ -2112,6 +2431,13 @@ var WebRTCTransportService = class {
|
|
|
2112
2431
|
const rpcStream = new import_codec_protobuf.Stream(({ ready, next, close }) => {
|
|
2113
2432
|
const duplex = new import_node_stream2.Duplex({
|
|
2114
2433
|
read: () => {
|
|
2434
|
+
const callbacks = [
|
|
2435
|
+
...transportState.writeCallbacks
|
|
2436
|
+
];
|
|
2437
|
+
transportState.writeCallbacks.length = 0;
|
|
2438
|
+
for (const cb of callbacks) {
|
|
2439
|
+
cb();
|
|
2440
|
+
}
|
|
2115
2441
|
},
|
|
2116
2442
|
write: function(chunk, _, callback) {
|
|
2117
2443
|
next({
|
|
@@ -2163,30 +2489,53 @@ var WebRTCTransportService = class {
|
|
|
2163
2489
|
});
|
|
2164
2490
|
close();
|
|
2165
2491
|
});
|
|
2166
|
-
|
|
2167
|
-
this.transports.set(request.proxyId, {
|
|
2492
|
+
const transportState = {
|
|
2168
2493
|
transport,
|
|
2169
|
-
stream: duplex
|
|
2170
|
-
|
|
2494
|
+
stream: duplex,
|
|
2495
|
+
writeCallbacks: []
|
|
2496
|
+
};
|
|
2497
|
+
ready();
|
|
2498
|
+
this.transports.set(request.proxyId, transportState);
|
|
2171
2499
|
});
|
|
2172
2500
|
return rpcStream;
|
|
2173
2501
|
}
|
|
2174
2502
|
async sendSignal({ proxyId, signal }) {
|
|
2175
|
-
(0,
|
|
2503
|
+
(0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
|
|
2504
|
+
F: __dxlog_file11,
|
|
2505
|
+
L: 113,
|
|
2506
|
+
S: this,
|
|
2507
|
+
A: [
|
|
2508
|
+
"this.transports.has(proxyId)",
|
|
2509
|
+
""
|
|
2510
|
+
]
|
|
2511
|
+
});
|
|
2176
2512
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2177
2513
|
}
|
|
2178
2514
|
async sendData({ proxyId, payload }) {
|
|
2179
|
-
(0,
|
|
2180
|
-
|
|
2515
|
+
(0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
|
|
2516
|
+
F: __dxlog_file11,
|
|
2517
|
+
L: 118,
|
|
2518
|
+
S: this,
|
|
2519
|
+
A: [
|
|
2520
|
+
"this.transports.has(proxyId)",
|
|
2521
|
+
""
|
|
2522
|
+
]
|
|
2523
|
+
});
|
|
2524
|
+
const state = this.transports.get(proxyId);
|
|
2525
|
+
const bufferHasSpace = state.stream.push(payload);
|
|
2526
|
+
if (!bufferHasSpace) {
|
|
2527
|
+
await new Promise((resolve) => {
|
|
2528
|
+
state.writeCallbacks.push(resolve);
|
|
2529
|
+
});
|
|
2530
|
+
}
|
|
2181
2531
|
}
|
|
2182
2532
|
async close({ proxyId }) {
|
|
2183
|
-
|
|
2184
|
-
await
|
|
2185
|
-
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
2533
|
+
await this.transports.get(proxyId)?.transport.destroy();
|
|
2534
|
+
await this.transports.get(proxyId)?.stream.end();
|
|
2186
2535
|
this.transports.delete(proxyId);
|
|
2187
2536
|
(0, import_log12.log)("Closed.", void 0, {
|
|
2188
|
-
F:
|
|
2189
|
-
L:
|
|
2537
|
+
F: __dxlog_file11,
|
|
2538
|
+
L: 132,
|
|
2190
2539
|
S: this,
|
|
2191
2540
|
C: (f, a) => f(...a)
|
|
2192
2541
|
});
|
|
@@ -2194,15 +2543,16 @@ var WebRTCTransportService = class {
|
|
|
2194
2543
|
};
|
|
2195
2544
|
|
|
2196
2545
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2197
|
-
var
|
|
2546
|
+
var import_node_stream3 = require("node:stream");
|
|
2198
2547
|
var import_async10 = require("@dxos/async");
|
|
2199
2548
|
var import_context6 = require("@dxos/context");
|
|
2200
2549
|
var import_debug6 = require("@dxos/debug");
|
|
2550
|
+
var import_invariant13 = require("@dxos/invariant");
|
|
2201
2551
|
var import_keys12 = require("@dxos/keys");
|
|
2202
2552
|
var import_log13 = require("@dxos/log");
|
|
2203
2553
|
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2204
2554
|
var import_util9 = require("@dxos/util");
|
|
2205
|
-
var
|
|
2555
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
|
|
2206
2556
|
var WebRTCTransportProxy = class {
|
|
2207
2557
|
// prettier-ignore
|
|
2208
2558
|
constructor(_params) {
|
|
@@ -2220,8 +2570,8 @@ var WebRTCTransportProxy = class {
|
|
|
2220
2570
|
this._serviceStream.waitUntilReady().then(() => {
|
|
2221
2571
|
this._serviceStream.subscribe(async (event) => {
|
|
2222
2572
|
(0, import_log13.log)("WebRTCTransportProxy: event", event, {
|
|
2223
|
-
F:
|
|
2224
|
-
L:
|
|
2573
|
+
F: __dxlog_file12,
|
|
2574
|
+
L: 51,
|
|
2225
2575
|
S: this,
|
|
2226
2576
|
C: (f, a) => f(...a)
|
|
2227
2577
|
});
|
|
@@ -2233,28 +2583,24 @@ var WebRTCTransportProxy = class {
|
|
|
2233
2583
|
await this._handleSignal(event.signal);
|
|
2234
2584
|
}
|
|
2235
2585
|
});
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2586
|
+
this._params.stream.pipe(new import_node_stream3.Writable({
|
|
2587
|
+
write: (chunk, _, callback) => {
|
|
2588
|
+
this._params.bridgeService.sendData({
|
|
2239
2589
|
proxyId: this._proxyId,
|
|
2240
|
-
payload:
|
|
2241
|
-
})
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2590
|
+
payload: chunk
|
|
2591
|
+
}).then(() => callback(), (err) => {
|
|
2592
|
+
import_log13.log.catch(err, void 0, {
|
|
2593
|
+
F: __dxlog_file12,
|
|
2594
|
+
L: 69,
|
|
2595
|
+
S: this,
|
|
2596
|
+
C: (f, a) => f(...a)
|
|
2597
|
+
});
|
|
2248
2598
|
});
|
|
2249
2599
|
}
|
|
2250
|
-
};
|
|
2251
|
-
this._params.stream.on("data", dataListener);
|
|
2252
|
-
this._ctx.onDispose(() => {
|
|
2253
|
-
this._params.stream.off("data", dataListener);
|
|
2254
|
-
});
|
|
2600
|
+
}));
|
|
2255
2601
|
}, (error) => import_log13.log.catch(error, void 0, {
|
|
2256
|
-
F:
|
|
2257
|
-
L:
|
|
2602
|
+
F: __dxlog_file12,
|
|
2603
|
+
L: 75,
|
|
2258
2604
|
S: this,
|
|
2259
2605
|
C: (f, a) => f(...a)
|
|
2260
2606
|
}));
|
|
@@ -2299,8 +2645,8 @@ var WebRTCTransportProxy = class {
|
|
|
2299
2645
|
});
|
|
2300
2646
|
} catch (err) {
|
|
2301
2647
|
import_log13.log.catch(err, void 0, {
|
|
2302
|
-
F:
|
|
2303
|
-
L:
|
|
2648
|
+
F: __dxlog_file12,
|
|
2649
|
+
L: 126,
|
|
2304
2650
|
S: this,
|
|
2305
2651
|
C: (f, a) => f(...a)
|
|
2306
2652
|
});
|
|
@@ -2334,7 +2680,15 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2334
2680
|
return this;
|
|
2335
2681
|
}
|
|
2336
2682
|
createTransport(options) {
|
|
2337
|
-
(0,
|
|
2683
|
+
(0, import_invariant13.invariant)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections", {
|
|
2684
|
+
F: __dxlog_file12,
|
|
2685
|
+
L: 163,
|
|
2686
|
+
S: this,
|
|
2687
|
+
A: [
|
|
2688
|
+
"this._bridgeService",
|
|
2689
|
+
"'WebRTCTransportProxyFactory is not ready to open connections'"
|
|
2690
|
+
]
|
|
2691
|
+
});
|
|
2338
2692
|
const transport = new WebRTCTransportProxy({
|
|
2339
2693
|
...options,
|
|
2340
2694
|
bridgeService: this._bridgeService
|
|
@@ -2371,20 +2725,22 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
2371
2725
|
};
|
|
2372
2726
|
|
|
2373
2727
|
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
2374
|
-
var
|
|
2728
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
|
|
2375
2729
|
var TestWireProtocol = class {
|
|
2376
|
-
constructor(peerId) {
|
|
2730
|
+
constructor(peerId, _extensionFactory = () => []) {
|
|
2377
2731
|
this.peerId = peerId;
|
|
2732
|
+
this._extensionFactory = _extensionFactory;
|
|
2378
2733
|
this.connections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
|
|
2379
2734
|
this.streamConnections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
|
|
2380
2735
|
this.connected = new import_async11.Event();
|
|
2381
2736
|
this.disconnected = new import_async11.Event();
|
|
2737
|
+
this.otherConnections = new import_util10.ComplexMap(({ remotePeerId, extension }) => remotePeerId.toHex() + extension);
|
|
2382
2738
|
this.factory = createTeleportProtocolFactory(async (teleport) => {
|
|
2383
2739
|
(0, import_log14.log)("create", {
|
|
2384
2740
|
remotePeerId: teleport.remotePeerId
|
|
2385
2741
|
}, {
|
|
2386
|
-
F:
|
|
2387
|
-
L:
|
|
2742
|
+
F: __dxlog_file13,
|
|
2743
|
+
L: 38,
|
|
2388
2744
|
S: this,
|
|
2389
2745
|
C: (f, a) => f(...a)
|
|
2390
2746
|
});
|
|
@@ -2404,6 +2760,13 @@ var TestWireProtocol = class {
|
|
|
2404
2760
|
});
|
|
2405
2761
|
this.streamConnections.set(teleport.remotePeerId, streamExtension);
|
|
2406
2762
|
teleport.addExtension("test-stream", streamExtension);
|
|
2763
|
+
for (const { name, extension: extension2 } of this._extensionFactory()) {
|
|
2764
|
+
this.otherConnections.set({
|
|
2765
|
+
remotePeerId: teleport.remotePeerId,
|
|
2766
|
+
extension: name
|
|
2767
|
+
}, extension2);
|
|
2768
|
+
teleport.addExtension(name, extension2);
|
|
2769
|
+
}
|
|
2407
2770
|
});
|
|
2408
2771
|
}
|
|
2409
2772
|
async waitForConnection(peerId) {
|
|
@@ -2413,8 +2776,8 @@ var TestWireProtocol = class {
|
|
|
2413
2776
|
(0, import_log14.log)("waitForConnection", {
|
|
2414
2777
|
peerId
|
|
2415
2778
|
}, {
|
|
2416
|
-
F:
|
|
2417
|
-
L:
|
|
2779
|
+
F: __dxlog_file13,
|
|
2780
|
+
L: 67,
|
|
2418
2781
|
S: this,
|
|
2419
2782
|
C: (f, a) => f(...a)
|
|
2420
2783
|
});
|
|
@@ -2446,8 +2809,7 @@ var TestWireProtocol = class {
|
|
|
2446
2809
|
};
|
|
2447
2810
|
|
|
2448
2811
|
// packages/core/mesh/network-manager/src/testing/test-builder.ts
|
|
2449
|
-
var
|
|
2450
|
-
var port = (_a = process.env.SIGNAL_PORT) != null ? _a : 4e3;
|
|
2812
|
+
var port = process.env.SIGNAL_PORT ?? 4e3;
|
|
2451
2813
|
var TEST_SIGNAL_HOSTS = [
|
|
2452
2814
|
{
|
|
2453
2815
|
server: `ws://localhost:${port}/.well-known/dx/signal`
|
|
@@ -2518,17 +2880,15 @@ var TestPeer = class {
|
|
|
2518
2880
|
});
|
|
2519
2881
|
}
|
|
2520
2882
|
async open() {
|
|
2521
|
-
var _a2, _b;
|
|
2522
2883
|
await this._networkManager.open();
|
|
2523
|
-
await
|
|
2524
|
-
await
|
|
2884
|
+
await this._proxy?.open();
|
|
2885
|
+
await this._service?.open();
|
|
2525
2886
|
}
|
|
2526
2887
|
async close() {
|
|
2527
|
-
var _a2, _b;
|
|
2528
2888
|
await Promise.all(Array.from(this._swarms.values()).map((swarm) => swarm.leave()));
|
|
2529
2889
|
this._swarms.clear();
|
|
2530
|
-
await
|
|
2531
|
-
await
|
|
2890
|
+
await this._proxy?.close();
|
|
2891
|
+
await this._service?.close();
|
|
2532
2892
|
await this._networkManager.close();
|
|
2533
2893
|
}
|
|
2534
2894
|
getSwarm(topic) {
|
|
@@ -2538,8 +2898,8 @@ var TestPeer = class {
|
|
|
2538
2898
|
}
|
|
2539
2899
|
return swarm;
|
|
2540
2900
|
}
|
|
2541
|
-
createSwarm(topic) {
|
|
2542
|
-
const swarm = new TestSwarmConnection(this, topic);
|
|
2901
|
+
createSwarm(topic, extensionFactory = () => []) {
|
|
2902
|
+
const swarm = new TestSwarmConnection(this, topic, extensionFactory);
|
|
2543
2903
|
this._swarms.set(topic, swarm);
|
|
2544
2904
|
return swarm;
|
|
2545
2905
|
}
|
|
@@ -2551,10 +2911,11 @@ var TestPeer = class {
|
|
|
2551
2911
|
}
|
|
2552
2912
|
};
|
|
2553
2913
|
var TestSwarmConnection = class {
|
|
2554
|
-
constructor(peer, topic) {
|
|
2914
|
+
constructor(peer, topic, extensionFactory) {
|
|
2555
2915
|
this.peer = peer;
|
|
2556
2916
|
this.topic = topic;
|
|
2557
|
-
this.
|
|
2917
|
+
this.extensionFactory = extensionFactory;
|
|
2918
|
+
this.protocol = new TestWireProtocol(this.peer.peerId, this.extensionFactory);
|
|
2558
2919
|
}
|
|
2559
2920
|
// TODO(burdon): Need to create new plugin instance per swarm?
|
|
2560
2921
|
// If so, then perhaps joinSwarm should return swarm object with access to plugins.
|