@dxos/network-manager 0.1.53 → 0.1.54-main.270ec56
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-6CP5XM3F.mjs → chunk-HDCPX2MD.mjs} +512 -499
- package/dist/lib/browser/chunk-HDCPX2MD.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +34 -11
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +510 -497
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +488 -452
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/testing/test-wire-protocol.d.ts +4 -1
- package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/package.json +19 -18
- package/src/network-manager.ts +5 -5
- package/src/signal/swarm-messenger.ts +11 -9
- package/src/swarm/connection.ts +9 -9
- package/src/swarm/peer.ts +6 -6
- package/src/swarm/swarm.ts +8 -8
- package/src/testing/test-wire-protocol.ts +32 -1
- package/src/topology/fully-connected-topology.ts +3 -3
- package/src/topology/mmst-topology.ts +5 -5
- package/src/topology/star-topology.ts +4 -4
- package/src/transport/memory-transport.ts +3 -6
- package/src/transport/webrtc-transport-proxy.ts +2 -2
- package/src/transport/webrtc-transport-service.ts +3 -3
- package/src/transport/webrtc-transport.ts +2 -2
- package/dist/lib/browser/chunk-6CP5XM3F.mjs.map +0 -7
|
@@ -46,7 +46,7 @@ var import_rpc = require("@dxos/rpc");
|
|
|
46
46
|
var import_util10 = require("@dxos/util");
|
|
47
47
|
|
|
48
48
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
49
|
-
var
|
|
49
|
+
var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
|
|
50
50
|
var import_async6 = require("@dxos/async");
|
|
51
51
|
var import_keys7 = require("@dxos/keys");
|
|
52
52
|
var import_log6 = require("@dxos/log");
|
|
@@ -62,7 +62,7 @@ var import_keys6 = require("@dxos/keys");
|
|
|
62
62
|
var import_util4 = require("@dxos/util");
|
|
63
63
|
|
|
64
64
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
65
|
-
var
|
|
65
|
+
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
66
66
|
var import_async = require("@dxos/async");
|
|
67
67
|
var import_context = require("@dxos/context");
|
|
68
68
|
var import_debug = require("@dxos/debug");
|
|
@@ -70,7 +70,7 @@ var import_errors = require("@dxos/errors");
|
|
|
70
70
|
var import_keys = require("@dxos/keys");
|
|
71
71
|
var import_log = require("@dxos/log");
|
|
72
72
|
var import_protocols = require("@dxos/protocols");
|
|
73
|
-
|
|
73
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
74
74
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
75
75
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
76
76
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -79,7 +79,8 @@ var __decorate = function(decorators, target, key, desc) {
|
|
|
79
79
|
if (d = decorators[i])
|
|
80
80
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
81
81
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
82
|
-
}
|
|
82
|
+
}
|
|
83
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
|
|
83
84
|
var STARTING_SIGNALLING_DELAY = 10;
|
|
84
85
|
var MAX_SIGNALLING_DELAY = 300;
|
|
85
86
|
var ConnectionState;
|
|
@@ -152,29 +153,29 @@ var Connection = class {
|
|
|
152
153
|
*/
|
|
153
154
|
// TODO(burdon): Make async?
|
|
154
155
|
openConnection() {
|
|
155
|
-
(0,
|
|
156
|
+
(0, import_tiny_invariant.default)(this._state === ConnectionState.INITIAL, "Invalid state.");
|
|
156
157
|
import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.begin({
|
|
157
158
|
id: this._instanceId
|
|
158
159
|
}), {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
F: __dxlog_file,
|
|
161
|
+
L: 115,
|
|
162
|
+
S: this,
|
|
163
|
+
C: (f, a) => f(...a)
|
|
163
164
|
});
|
|
164
165
|
this._changeState(ConnectionState.CONNECTING);
|
|
165
166
|
this._protocol.initialize().catch((err) => {
|
|
166
167
|
this.errors.raise(err);
|
|
167
168
|
});
|
|
168
169
|
this._protocol.stream.on("close", () => {
|
|
169
|
-
(0, import_log.log)("protocol stream closed",
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
(0, import_log.log)("protocol stream closed", void 0, {
|
|
171
|
+
F: __dxlog_file,
|
|
172
|
+
L: 126,
|
|
173
|
+
S: this,
|
|
174
|
+
C: (f, a) => f(...a)
|
|
174
175
|
});
|
|
175
176
|
this.close().catch((err) => this.errors.raise(err));
|
|
176
177
|
});
|
|
177
|
-
(0,
|
|
178
|
+
(0, import_tiny_invariant.default)(!this._transport);
|
|
178
179
|
this._transport = this._transportFactory.createTransport({
|
|
179
180
|
initiator: this.initiator,
|
|
180
181
|
stream: this._protocol.stream,
|
|
@@ -199,10 +200,10 @@ var Connection = class {
|
|
|
199
200
|
import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.end({
|
|
200
201
|
id: this._instanceId
|
|
201
202
|
}), {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
F: __dxlog_file,
|
|
204
|
+
L: 159,
|
|
205
|
+
S: this,
|
|
206
|
+
C: (f, a) => f(...a)
|
|
206
207
|
});
|
|
207
208
|
}
|
|
208
209
|
async close() {
|
|
@@ -215,38 +216,38 @@ var Connection = class {
|
|
|
215
216
|
(0, import_log.log)("closing...", {
|
|
216
217
|
peerId: this.ownId
|
|
217
218
|
}, {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
219
|
+
F: __dxlog_file,
|
|
220
|
+
L: 171,
|
|
221
|
+
S: this,
|
|
222
|
+
C: (f, a) => f(...a)
|
|
222
223
|
});
|
|
223
224
|
try {
|
|
224
225
|
await this._protocol.destroy();
|
|
225
226
|
} catch (err) {
|
|
226
|
-
import_log.log.catch(err,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
import_log.log.catch(err, void 0, {
|
|
228
|
+
F: __dxlog_file,
|
|
229
|
+
L: 177,
|
|
230
|
+
S: this,
|
|
231
|
+
C: (f, a) => f(...a)
|
|
231
232
|
});
|
|
232
233
|
}
|
|
233
234
|
try {
|
|
234
235
|
await ((_a2 = this._transport) == null ? void 0 : _a2.destroy());
|
|
235
|
-
} catch (
|
|
236
|
-
import_log.log.catch(
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
236
|
+
} catch (err) {
|
|
237
|
+
import_log.log.catch(err, void 0, {
|
|
238
|
+
F: __dxlog_file,
|
|
239
|
+
L: 184,
|
|
240
|
+
S: this,
|
|
241
|
+
C: (f, a) => f(...a)
|
|
241
242
|
});
|
|
242
243
|
}
|
|
243
244
|
(0, import_log.log)("closed", {
|
|
244
245
|
peerId: this.ownId
|
|
245
246
|
}, {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
247
|
+
F: __dxlog_file,
|
|
248
|
+
L: 187,
|
|
249
|
+
S: this,
|
|
250
|
+
C: (f, a) => f(...a)
|
|
250
251
|
});
|
|
251
252
|
this._changeState(ConnectionState.CLOSED);
|
|
252
253
|
}
|
|
@@ -283,10 +284,10 @@ var Connection = class {
|
|
|
283
284
|
import_log.log.warn("Signal failed", {
|
|
284
285
|
err
|
|
285
286
|
}, {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
287
|
+
F: __dxlog_file,
|
|
288
|
+
L: 221,
|
|
289
|
+
S: this,
|
|
290
|
+
C: (f, a) => f(...a)
|
|
290
291
|
});
|
|
291
292
|
await this.close();
|
|
292
293
|
}
|
|
@@ -296,19 +297,19 @@ var Connection = class {
|
|
|
296
297
|
*/
|
|
297
298
|
async signal(msg) {
|
|
298
299
|
var _a2, _b, _c;
|
|
299
|
-
(0,
|
|
300
|
+
(0, import_tiny_invariant.default)(msg.sessionId);
|
|
300
301
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
301
|
-
(0, import_log.log)("dropping signal for incorrect session id",
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
302
|
+
(0, import_log.log)("dropping signal for incorrect session id", void 0, {
|
|
303
|
+
F: __dxlog_file,
|
|
304
|
+
L: 232,
|
|
305
|
+
S: this,
|
|
306
|
+
C: (f, a) => f(...a)
|
|
306
307
|
});
|
|
307
308
|
return;
|
|
308
309
|
}
|
|
309
|
-
(0,
|
|
310
|
-
(0,
|
|
311
|
-
(0,
|
|
310
|
+
(0, import_tiny_invariant.default)(msg.data.signal || msg.data.signalBatch);
|
|
311
|
+
(0, import_tiny_invariant.default)((_a2 = msg.author) == null ? void 0 : _a2.equals(this.remoteId));
|
|
312
|
+
(0, import_tiny_invariant.default)((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId));
|
|
312
313
|
const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
|
|
313
314
|
msg.data.signal
|
|
314
315
|
];
|
|
@@ -322,23 +323,23 @@ var Connection = class {
|
|
|
322
323
|
remoteId: this.remoteId,
|
|
323
324
|
msg: msg.data
|
|
324
325
|
}, {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
326
|
+
F: __dxlog_file,
|
|
327
|
+
L: 246,
|
|
328
|
+
S: this,
|
|
329
|
+
C: (f, a) => f(...a)
|
|
329
330
|
});
|
|
330
331
|
this._incomingSignalBuffer.push(signal);
|
|
331
332
|
} else {
|
|
332
|
-
(0,
|
|
333
|
+
(0, import_tiny_invariant.default)(this._transport, "Connection not ready to accept signals.");
|
|
333
334
|
(0, import_log.log)("received signal", {
|
|
334
335
|
peerId: this.ownId,
|
|
335
336
|
remoteId: this.remoteId,
|
|
336
337
|
msg: msg.data
|
|
337
338
|
}, {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
F: __dxlog_file,
|
|
340
|
+
L: 250,
|
|
341
|
+
S: this,
|
|
342
|
+
C: (f, a) => f(...a)
|
|
342
343
|
});
|
|
343
344
|
await this._transport.signal(signal);
|
|
344
345
|
}
|
|
@@ -350,22 +351,22 @@ var Connection = class {
|
|
|
350
351
|
too: state,
|
|
351
352
|
peerId: this.ownId
|
|
352
353
|
}, {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
354
|
+
F: __dxlog_file,
|
|
355
|
+
L: 257,
|
|
356
|
+
S: this,
|
|
357
|
+
C: (f, a) => f(...a)
|
|
357
358
|
});
|
|
358
|
-
(0,
|
|
359
|
+
(0, import_tiny_invariant.default)(state !== this._state, "Already in this state.");
|
|
359
360
|
this._state = state;
|
|
360
361
|
this.stateChanged.emit(state);
|
|
361
362
|
}
|
|
362
363
|
};
|
|
363
|
-
|
|
364
|
+
_ts_decorate([
|
|
364
365
|
import_async.synchronized
|
|
365
366
|
], Connection.prototype, "close", null);
|
|
366
367
|
|
|
367
368
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
368
|
-
var
|
|
369
|
+
var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
|
|
369
370
|
var import_async3 = require("@dxos/async");
|
|
370
371
|
var import_context4 = require("@dxos/context");
|
|
371
372
|
var import_debug2 = require("@dxos/debug");
|
|
@@ -375,12 +376,14 @@ var import_protocols3 = require("@dxos/protocols");
|
|
|
375
376
|
var import_util2 = require("@dxos/util");
|
|
376
377
|
|
|
377
378
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
378
|
-
var
|
|
379
|
+
var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
|
|
379
380
|
var import_context2 = require("@dxos/context");
|
|
380
381
|
var import_keys2 = require("@dxos/keys");
|
|
381
382
|
var import_log2 = require("@dxos/log");
|
|
382
383
|
var import_protocols2 = require("@dxos/protocols");
|
|
383
384
|
var import_util = require("@dxos/util");
|
|
385
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
386
|
+
var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
384
387
|
var SwarmMessenger = class {
|
|
385
388
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
386
389
|
this._ctx = new import_context2.Context();
|
|
@@ -395,7 +398,7 @@ var SwarmMessenger = class {
|
|
|
395
398
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
396
399
|
return;
|
|
397
400
|
}
|
|
398
|
-
const message =
|
|
401
|
+
const message = SwarmMessage.decode(payload.value);
|
|
399
402
|
if (!this._topic.equals(message.topic)) {
|
|
400
403
|
return;
|
|
401
404
|
}
|
|
@@ -404,10 +407,10 @@ var SwarmMessenger = class {
|
|
|
404
407
|
to: recipient,
|
|
405
408
|
msg: message
|
|
406
409
|
}, {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
410
|
+
F: __dxlog_file2,
|
|
411
|
+
L: 70,
|
|
412
|
+
S: this,
|
|
413
|
+
C: (f, a) => f(...a)
|
|
411
414
|
});
|
|
412
415
|
if ((_a2 = message.data) == null ? void 0 : _a2.offer) {
|
|
413
416
|
await this._handleOffer({
|
|
@@ -433,16 +436,16 @@ var SwarmMessenger = class {
|
|
|
433
436
|
import_log2.log.warn("unknown message", {
|
|
434
437
|
message
|
|
435
438
|
}, {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
439
|
+
F: __dxlog_file2,
|
|
440
|
+
L: 81,
|
|
441
|
+
S: this,
|
|
442
|
+
C: (f, a) => f(...a)
|
|
440
443
|
});
|
|
441
444
|
}
|
|
442
445
|
}
|
|
443
446
|
async signal(message) {
|
|
444
447
|
var _a2, _b;
|
|
445
|
-
(0,
|
|
448
|
+
(0, import_tiny_invariant2.default)(((_a2 = message.data) == null ? void 0 : _a2.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message");
|
|
446
449
|
await this._sendReliableMessage({
|
|
447
450
|
author: message.author,
|
|
448
451
|
recipient: message.recipient,
|
|
@@ -477,40 +480,40 @@ var SwarmMessenger = class {
|
|
|
477
480
|
to: recipient,
|
|
478
481
|
msg: networkMessage
|
|
479
482
|
}, {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
483
|
+
F: __dxlog_file2,
|
|
484
|
+
L: 124,
|
|
485
|
+
S: this,
|
|
486
|
+
C: (f, a) => f(...a)
|
|
484
487
|
});
|
|
485
488
|
await this._sendMessage({
|
|
486
489
|
author,
|
|
487
490
|
recipient,
|
|
488
491
|
payload: {
|
|
489
492
|
type_url: "dxos.mesh.swarm.SwarmMessage",
|
|
490
|
-
value:
|
|
493
|
+
value: SwarmMessage.encode(networkMessage)
|
|
491
494
|
}
|
|
492
495
|
});
|
|
493
496
|
}
|
|
494
497
|
async _resolveAnswers(message) {
|
|
495
498
|
var _a2, _b, _c;
|
|
496
|
-
(0,
|
|
499
|
+
(0, import_tiny_invariant2.default)((_b = (_a2 = message.data) == null ? void 0 : _a2.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId");
|
|
497
500
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
498
501
|
if (offerRecord) {
|
|
499
502
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
500
|
-
(0,
|
|
503
|
+
(0, import_tiny_invariant2.default)((_c = message.data) == null ? void 0 : _c.answer, "No answer");
|
|
501
504
|
(0, import_log2.log)("resolving", {
|
|
502
505
|
answer: message.data.answer
|
|
503
506
|
}, {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
507
|
+
F: __dxlog_file2,
|
|
508
|
+
L: 141,
|
|
509
|
+
S: this,
|
|
510
|
+
C: (f, a) => f(...a)
|
|
508
511
|
});
|
|
509
512
|
offerRecord.resolve(message.data.answer);
|
|
510
513
|
}
|
|
511
514
|
}
|
|
512
515
|
async _handleOffer({ author, recipient, message }) {
|
|
513
|
-
(0,
|
|
516
|
+
(0, import_tiny_invariant2.default)(message.data.offer, "No offer");
|
|
514
517
|
const offerMessage = {
|
|
515
518
|
author,
|
|
516
519
|
recipient,
|
|
@@ -537,16 +540,16 @@ var SwarmMessenger = class {
|
|
|
537
540
|
import_log2.log.warn("error sending answer", {
|
|
538
541
|
err
|
|
539
542
|
}, {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
543
|
+
F: __dxlog_file2,
|
|
544
|
+
L: 175,
|
|
545
|
+
S: this,
|
|
546
|
+
C: (f, a) => f(...a)
|
|
544
547
|
});
|
|
545
548
|
}
|
|
546
549
|
}
|
|
547
550
|
async _handleSignal({ author, recipient, message }) {
|
|
548
|
-
(0,
|
|
549
|
-
(0,
|
|
551
|
+
(0, import_tiny_invariant2.default)(message.messageId);
|
|
552
|
+
(0, import_tiny_invariant2.default)(message.data.signal || message.data.signalBatch, "Invalid message");
|
|
550
553
|
const signalMessage = {
|
|
551
554
|
author,
|
|
552
555
|
recipient,
|
|
@@ -561,12 +564,12 @@ var SwarmMessenger = class {
|
|
|
561
564
|
};
|
|
562
565
|
|
|
563
566
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
564
|
-
var
|
|
567
|
+
var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
|
|
565
568
|
var import_async2 = require("@dxos/async");
|
|
566
569
|
var import_context3 = require("@dxos/context");
|
|
567
570
|
var import_keys3 = require("@dxos/keys");
|
|
568
571
|
var import_log3 = require("@dxos/log");
|
|
569
|
-
|
|
572
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
570
573
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
571
574
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
572
575
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -575,7 +578,8 @@ var __decorate2 = function(decorators, target, key, desc) {
|
|
|
575
578
|
if (d = decorators[i])
|
|
576
579
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
577
580
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
578
|
-
}
|
|
581
|
+
}
|
|
582
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
579
583
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
580
584
|
var Peer = class {
|
|
581
585
|
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _callbacks) {
|
|
@@ -604,10 +608,10 @@ var Peer = class {
|
|
|
604
608
|
topic: this.topic,
|
|
605
609
|
peerId: this.localPeerId
|
|
606
610
|
}, {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
+
F: __dxlog_file3,
|
|
612
|
+
L: 105,
|
|
613
|
+
S: this,
|
|
614
|
+
C: (f, a) => f(...a)
|
|
611
615
|
});
|
|
612
616
|
if (this.connection) {
|
|
613
617
|
await this.closeConnection();
|
|
@@ -620,7 +624,7 @@ var Peer = class {
|
|
|
620
624
|
}
|
|
621
625
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
622
626
|
if (!this.connection) {
|
|
623
|
-
(0,
|
|
627
|
+
(0, import_tiny_invariant3.default)(message.sessionId);
|
|
624
628
|
const connection = this._createConnection(false, message.sessionId);
|
|
625
629
|
try {
|
|
626
630
|
connection.openConnection();
|
|
@@ -631,10 +635,10 @@ var Peer = class {
|
|
|
631
635
|
remoteId: this.id,
|
|
632
636
|
err
|
|
633
637
|
}, {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
+
F: __dxlog_file3,
|
|
639
|
+
L: 129,
|
|
640
|
+
S: this,
|
|
641
|
+
C: (f, a) => f(...a)
|
|
638
642
|
});
|
|
639
643
|
await this.closeConnection();
|
|
640
644
|
}
|
|
@@ -651,8 +655,8 @@ var Peer = class {
|
|
|
651
655
|
* Initiate a connection to the remote peer.
|
|
652
656
|
*/
|
|
653
657
|
async initiateConnection() {
|
|
654
|
-
(0,
|
|
655
|
-
(0,
|
|
658
|
+
(0, import_tiny_invariant3.default)(!this.initiating, "Initiation in progress.");
|
|
659
|
+
(0, import_tiny_invariant3.default)(!this.connection, "Already connected.");
|
|
656
660
|
const sessionId = import_keys3.PublicKey.random();
|
|
657
661
|
(0, import_log3.log)("initiating...", {
|
|
658
662
|
id: this.id,
|
|
@@ -660,10 +664,10 @@ var Peer = class {
|
|
|
660
664
|
peerId: this.id,
|
|
661
665
|
sessionId
|
|
662
666
|
}, {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
+
F: __dxlog_file3,
|
|
668
|
+
L: 147,
|
|
669
|
+
S: this,
|
|
670
|
+
C: (f, a) => f(...a)
|
|
667
671
|
});
|
|
668
672
|
const connection = this._createConnection(true, sessionId);
|
|
669
673
|
this.initiating = true;
|
|
@@ -683,17 +687,17 @@ var Peer = class {
|
|
|
683
687
|
ownId: this.localPeerId,
|
|
684
688
|
remoteId: this.id
|
|
685
689
|
}, {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
+
F: __dxlog_file3,
|
|
691
|
+
L: 159,
|
|
692
|
+
S: this,
|
|
693
|
+
C: (f, a) => f(...a)
|
|
690
694
|
});
|
|
691
695
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
692
|
-
(0, import_log3.log)("ignoring response",
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
696
|
+
(0, import_log3.log)("ignoring response", void 0, {
|
|
697
|
+
F: __dxlog_file3,
|
|
698
|
+
L: 161,
|
|
699
|
+
S: this,
|
|
700
|
+
C: (f, a) => f(...a)
|
|
697
701
|
});
|
|
698
702
|
return;
|
|
699
703
|
}
|
|
@@ -710,10 +714,10 @@ var Peer = class {
|
|
|
710
714
|
peerId: this.localPeerId,
|
|
711
715
|
remoteId: this.id
|
|
712
716
|
}, {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
+
F: __dxlog_file3,
|
|
718
|
+
L: 172,
|
|
719
|
+
S: this,
|
|
720
|
+
C: (f, a) => f(...a)
|
|
717
721
|
});
|
|
718
722
|
await this.closeConnection();
|
|
719
723
|
throw err;
|
|
@@ -734,12 +738,12 @@ var Peer = class {
|
|
|
734
738
|
initiator,
|
|
735
739
|
sessionId
|
|
736
740
|
}, {
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
+
F: __dxlog_file3,
|
|
742
|
+
L: 186,
|
|
743
|
+
S: this,
|
|
744
|
+
C: (f, a) => f(...a)
|
|
741
745
|
});
|
|
742
|
-
(0,
|
|
746
|
+
(0, import_tiny_invariant3.default)(!this.connection, "Already connected.");
|
|
743
747
|
const connection = new Connection(
|
|
744
748
|
this.topic,
|
|
745
749
|
this.localPeerId,
|
|
@@ -774,12 +778,12 @@ var Peer = class {
|
|
|
774
778
|
remoteId: this.id,
|
|
775
779
|
initiator
|
|
776
780
|
}, {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
+
F: __dxlog_file3,
|
|
782
|
+
L: 221,
|
|
783
|
+
S: this,
|
|
784
|
+
C: (f, a) => f(...a)
|
|
781
785
|
});
|
|
782
|
-
(0,
|
|
786
|
+
(0, import_tiny_invariant3.default)(this.connection === connection, "Connection mismatch (race condition).");
|
|
783
787
|
if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
|
|
784
788
|
this._availableAfter = 0;
|
|
785
789
|
} else {
|
|
@@ -804,10 +808,10 @@ var Peer = class {
|
|
|
804
808
|
initiator,
|
|
805
809
|
err
|
|
806
810
|
}, {
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
+
F: __dxlog_file3,
|
|
812
|
+
L: 249,
|
|
813
|
+
S: this,
|
|
814
|
+
C: (f, a) => f(...a)
|
|
811
815
|
});
|
|
812
816
|
void this.closeConnection();
|
|
813
817
|
});
|
|
@@ -823,20 +827,20 @@ var Peer = class {
|
|
|
823
827
|
peerId: this.id,
|
|
824
828
|
sessionId: connection.sessionId
|
|
825
829
|
}, {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
+
F: __dxlog_file3,
|
|
831
|
+
L: 265,
|
|
832
|
+
S: this,
|
|
833
|
+
C: (f, a) => f(...a)
|
|
830
834
|
});
|
|
831
835
|
await connection.close();
|
|
832
836
|
(0, import_log3.log)("closed", {
|
|
833
837
|
peerId: this.id,
|
|
834
838
|
sessionId: connection.sessionId
|
|
835
839
|
}, {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
+
F: __dxlog_file3,
|
|
841
|
+
L: 271,
|
|
842
|
+
S: this,
|
|
843
|
+
C: (f, a) => f(...a)
|
|
840
844
|
});
|
|
841
845
|
}
|
|
842
846
|
async onSignal(message) {
|
|
@@ -844,10 +848,10 @@ var Peer = class {
|
|
|
844
848
|
(0, import_log3.log)("dropping signal message for non-existent connection", {
|
|
845
849
|
message
|
|
846
850
|
}, {
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
+
F: __dxlog_file3,
|
|
852
|
+
L: 276,
|
|
853
|
+
S: this,
|
|
854
|
+
C: (f, a) => f(...a)
|
|
851
855
|
});
|
|
852
856
|
return;
|
|
853
857
|
}
|
|
@@ -860,15 +864,15 @@ var Peer = class {
|
|
|
860
864
|
peerId: this.id,
|
|
861
865
|
topic: this.topic
|
|
862
866
|
}, {
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
+
F: __dxlog_file3,
|
|
868
|
+
L: 285,
|
|
869
|
+
S: this,
|
|
870
|
+
C: (f, a) => f(...a)
|
|
867
871
|
});
|
|
868
872
|
await ((_a2 = this == null ? void 0 : this.connection) == null ? void 0 : _a2.close());
|
|
869
873
|
}
|
|
870
874
|
};
|
|
871
|
-
|
|
875
|
+
_ts_decorate2([
|
|
872
876
|
import_async2.synchronized
|
|
873
877
|
], Peer.prototype, "destroy", null);
|
|
874
878
|
var increaseInterval = (interval) => {
|
|
@@ -885,7 +889,7 @@ var increaseInterval = (interval) => {
|
|
|
885
889
|
};
|
|
886
890
|
|
|
887
891
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
888
|
-
|
|
892
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
889
893
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
890
894
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
891
895
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -894,7 +898,8 @@ var __decorate3 = function(decorators, target, key, desc) {
|
|
|
894
898
|
if (d = decorators[i])
|
|
895
899
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
896
900
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
897
|
-
}
|
|
901
|
+
}
|
|
902
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
898
903
|
var INITIATION_DELAY = 100;
|
|
899
904
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
900
905
|
var Swarm = class {
|
|
@@ -911,11 +916,11 @@ var Swarm = class {
|
|
|
911
916
|
this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
|
|
912
917
|
this._ctx = new import_context4.Context();
|
|
913
918
|
this._listeningHandle = void 0;
|
|
919
|
+
this._instanceId = import_keys4.PublicKey.random().toHex();
|
|
914
920
|
this.connectionAdded = new import_async3.Event();
|
|
915
921
|
this.disconnected = new import_async3.Event();
|
|
916
922
|
this.connected = new import_async3.Event();
|
|
917
923
|
this.errors = new import_debug2.ErrorStream();
|
|
918
|
-
this._instanceId = import_keys4.PublicKey.random().toHex();
|
|
919
924
|
import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.begin({
|
|
920
925
|
id: this._instanceId,
|
|
921
926
|
data: {
|
|
@@ -923,18 +928,18 @@ var Swarm = class {
|
|
|
923
928
|
peerId: this._ownPeerId.toHex()
|
|
924
929
|
}
|
|
925
930
|
}), {
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
931
|
+
F: __dxlog_file4,
|
|
932
|
+
L: 86,
|
|
933
|
+
S: this,
|
|
934
|
+
C: (f, a) => f(...a)
|
|
930
935
|
});
|
|
931
936
|
(0, import_log4.log)("creating swarm", {
|
|
932
937
|
peerId: _ownPeerId
|
|
933
938
|
}, {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
939
|
+
F: __dxlog_file4,
|
|
940
|
+
L: 90,
|
|
941
|
+
S: this,
|
|
942
|
+
C: (f, a) => f(...a)
|
|
938
943
|
});
|
|
939
944
|
_topology.init(this._getSwarmController());
|
|
940
945
|
this._swarmMessenger = new SwarmMessenger({
|
|
@@ -946,10 +951,10 @@ var Swarm = class {
|
|
|
946
951
|
import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.end({
|
|
947
952
|
id: this._instanceId
|
|
948
953
|
}), {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
954
|
+
F: __dxlog_file4,
|
|
955
|
+
L: 99,
|
|
956
|
+
S: this,
|
|
957
|
+
C: (f, a) => f(...a)
|
|
953
958
|
});
|
|
954
959
|
}
|
|
955
960
|
get connections() {
|
|
@@ -968,7 +973,7 @@ var Swarm = class {
|
|
|
968
973
|
return this._topic;
|
|
969
974
|
}
|
|
970
975
|
async open() {
|
|
971
|
-
(0,
|
|
976
|
+
(0, import_tiny_invariant4.default)(!this._listeningHandle);
|
|
972
977
|
this._listeningHandle = await this._messenger.listen({
|
|
973
978
|
peerId: this._ownPeerId,
|
|
974
979
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
@@ -976,36 +981,36 @@ var Swarm = class {
|
|
|
976
981
|
await this._swarmMessenger.receiveMessage(message).catch((err) => import_log4.log.warn("Error while receiving message", {
|
|
977
982
|
err
|
|
978
983
|
}, {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
984
|
+
F: __dxlog_file4,
|
|
985
|
+
L: 133,
|
|
986
|
+
S: this,
|
|
987
|
+
C: (f, a) => f(...a)
|
|
983
988
|
}));
|
|
984
989
|
}
|
|
985
990
|
});
|
|
986
991
|
}
|
|
987
992
|
async destroy() {
|
|
988
993
|
var _a2;
|
|
989
|
-
(0, import_log4.log)("destroying...",
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
+
(0, import_log4.log)("destroying...", void 0, {
|
|
995
|
+
F: __dxlog_file4,
|
|
996
|
+
L: 139,
|
|
997
|
+
S: this,
|
|
998
|
+
C: (f, a) => f(...a)
|
|
994
999
|
});
|
|
995
1000
|
await ((_a2 = this._listeningHandle) == null ? void 0 : _a2.unsubscribe());
|
|
996
1001
|
this._listeningHandle = void 0;
|
|
997
1002
|
await this._ctx.dispose();
|
|
998
1003
|
await this._topology.destroy();
|
|
999
1004
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
1000
|
-
(0, import_log4.log)("destroyed",
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
+
(0, import_log4.log)("destroyed", void 0, {
|
|
1006
|
+
F: __dxlog_file4,
|
|
1007
|
+
L: 146,
|
|
1008
|
+
S: this,
|
|
1009
|
+
C: (f, a) => f(...a)
|
|
1005
1010
|
});
|
|
1006
1011
|
}
|
|
1007
1012
|
async setTopology(topology) {
|
|
1008
|
-
(0,
|
|
1013
|
+
(0, import_tiny_invariant4.default)(!this._ctx.disposed, "Swarm is offline");
|
|
1009
1014
|
if (topology === this._topology) {
|
|
1010
1015
|
return;
|
|
1011
1016
|
}
|
|
@@ -1013,10 +1018,10 @@ var Swarm = class {
|
|
|
1013
1018
|
previous: getClassName(this._topology),
|
|
1014
1019
|
topology: getClassName(topology)
|
|
1015
1020
|
}, {
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1021
|
+
F: __dxlog_file4,
|
|
1022
|
+
L: 154,
|
|
1023
|
+
S: this,
|
|
1024
|
+
C: (f, a) => f(...a)
|
|
1020
1025
|
});
|
|
1021
1026
|
await this._topology.destroy();
|
|
1022
1027
|
this._topology = topology;
|
|
@@ -1028,17 +1033,17 @@ var Swarm = class {
|
|
|
1028
1033
|
(0, import_log4.log)("swarm event", {
|
|
1029
1034
|
swarmEvent
|
|
1030
1035
|
}, {
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1036
|
+
F: __dxlog_file4,
|
|
1037
|
+
L: 167,
|
|
1038
|
+
S: this,
|
|
1039
|
+
C: (f, a) => f(...a)
|
|
1035
1040
|
});
|
|
1036
1041
|
if (this._ctx.disposed) {
|
|
1037
|
-
(0, import_log4.log)("swarm event ignored for disposed swarm",
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
+
(0, import_log4.log)("swarm event ignored for disposed swarm", void 0, {
|
|
1043
|
+
F: __dxlog_file4,
|
|
1044
|
+
L: 170,
|
|
1045
|
+
S: this,
|
|
1046
|
+
C: (f, a) => f(...a)
|
|
1042
1047
|
});
|
|
1043
1048
|
return;
|
|
1044
1049
|
}
|
|
@@ -1047,25 +1052,25 @@ var Swarm = class {
|
|
|
1047
1052
|
(0, import_log4.log)("new peer", {
|
|
1048
1053
|
peerId
|
|
1049
1054
|
}, {
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1055
|
+
F: __dxlog_file4,
|
|
1056
|
+
L: 176,
|
|
1057
|
+
S: this,
|
|
1058
|
+
C: (f, a) => f(...a)
|
|
1054
1059
|
});
|
|
1055
1060
|
if (!peerId.equals(this._ownPeerId)) {
|
|
1056
1061
|
const peer = this._getOrCreatePeer(peerId);
|
|
1057
1062
|
peer.advertizing = true;
|
|
1058
1063
|
}
|
|
1059
1064
|
} else if (swarmEvent.peerLeft) {
|
|
1060
|
-
const
|
|
1061
|
-
if (
|
|
1062
|
-
|
|
1063
|
-
if (((_a2 =
|
|
1064
|
-
void this._destroyPeer(
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1065
|
+
const peer = this._peers.get(import_keys4.PublicKey.from(swarmEvent.peerLeft.peer));
|
|
1066
|
+
if (peer) {
|
|
1067
|
+
peer.advertizing = false;
|
|
1068
|
+
if (((_a2 = peer.connection) == null ? void 0 : _a2.state) !== ConnectionState.CONNECTED) {
|
|
1069
|
+
void this._destroyPeer(peer.id).catch((err) => import_log4.log.catch(err, void 0, {
|
|
1070
|
+
F: __dxlog_file4,
|
|
1071
|
+
L: 187,
|
|
1072
|
+
S: this,
|
|
1073
|
+
C: (f, a) => f(...a)
|
|
1069
1074
|
}));
|
|
1070
1075
|
}
|
|
1071
1076
|
}
|
|
@@ -1077,31 +1082,31 @@ var Swarm = class {
|
|
|
1077
1082
|
(0, import_log4.log)("offer", {
|
|
1078
1083
|
message
|
|
1079
1084
|
}, {
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1085
|
+
F: __dxlog_file4,
|
|
1086
|
+
L: 197,
|
|
1087
|
+
S: this,
|
|
1088
|
+
C: (f, a) => f(...a)
|
|
1084
1089
|
});
|
|
1085
1090
|
if (this._ctx.disposed) {
|
|
1086
|
-
(0, import_log4.log)("ignored for disposed swarm",
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
+
(0, import_log4.log)("ignored for disposed swarm", void 0, {
|
|
1092
|
+
F: __dxlog_file4,
|
|
1093
|
+
L: 199,
|
|
1094
|
+
S: this,
|
|
1095
|
+
C: (f, a) => f(...a)
|
|
1091
1096
|
});
|
|
1092
1097
|
return {
|
|
1093
1098
|
accept: false
|
|
1094
1099
|
};
|
|
1095
1100
|
}
|
|
1096
|
-
(0,
|
|
1101
|
+
(0, import_tiny_invariant4.default)(message.author);
|
|
1097
1102
|
if (!((_a2 = message.recipient) == null ? void 0 : _a2.equals(this._ownPeerId))) {
|
|
1098
1103
|
(0, import_log4.log)("rejecting offer with incorrect peerId", {
|
|
1099
1104
|
message
|
|
1100
1105
|
}, {
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1106
|
+
F: __dxlog_file4,
|
|
1107
|
+
L: 206,
|
|
1108
|
+
S: this,
|
|
1109
|
+
C: (f, a) => f(...a)
|
|
1105
1110
|
});
|
|
1106
1111
|
return {
|
|
1107
1112
|
accept: false
|
|
@@ -1111,10 +1116,10 @@ var Swarm = class {
|
|
|
1111
1116
|
(0, import_log4.log)("rejecting offer with incorrect topic", {
|
|
1112
1117
|
message
|
|
1113
1118
|
}, {
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1119
|
+
F: __dxlog_file4,
|
|
1120
|
+
L: 210,
|
|
1121
|
+
S: this,
|
|
1122
|
+
C: (f, a) => f(...a)
|
|
1118
1123
|
});
|
|
1119
1124
|
return {
|
|
1120
1125
|
accept: false
|
|
@@ -1130,23 +1135,23 @@ var Swarm = class {
|
|
|
1130
1135
|
(0, import_log4.log)("signal", {
|
|
1131
1136
|
message
|
|
1132
1137
|
}, {
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1138
|
+
F: __dxlog_file4,
|
|
1139
|
+
L: 222,
|
|
1140
|
+
S: this,
|
|
1141
|
+
C: (f, a) => f(...a)
|
|
1137
1142
|
});
|
|
1138
1143
|
if (this._ctx.disposed) {
|
|
1139
|
-
import_log4.log.info("ignored for offline swarm",
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
+
import_log4.log.info("ignored for offline swarm", void 0, {
|
|
1145
|
+
F: __dxlog_file4,
|
|
1146
|
+
L: 224,
|
|
1147
|
+
S: this,
|
|
1148
|
+
C: (f, a) => f(...a)
|
|
1144
1149
|
});
|
|
1145
1150
|
return;
|
|
1146
1151
|
}
|
|
1147
|
-
(0,
|
|
1148
|
-
(0,
|
|
1149
|
-
(0,
|
|
1152
|
+
(0, import_tiny_invariant4.default)((_a2 = message.recipient) == null ? void 0 : _a2.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`);
|
|
1153
|
+
(0, import_tiny_invariant4.default)((_b = message.topic) == null ? void 0 : _b.equals(this._topic));
|
|
1154
|
+
(0, import_tiny_invariant4.default)(message.author);
|
|
1150
1155
|
const peer = this._getOrCreatePeer(message.author);
|
|
1151
1156
|
await peer.onSignal(message);
|
|
1152
1157
|
}
|
|
@@ -1198,7 +1203,7 @@ var Swarm = class {
|
|
|
1198
1203
|
return peer;
|
|
1199
1204
|
}
|
|
1200
1205
|
async _destroyPeer(peerId) {
|
|
1201
|
-
(0,
|
|
1206
|
+
(0, import_tiny_invariant4.default)(this._peers.has(peerId));
|
|
1202
1207
|
await this._peers.get(peerId).destroy();
|
|
1203
1208
|
this._peers.delete(peerId);
|
|
1204
1209
|
}
|
|
@@ -1218,10 +1223,10 @@ var Swarm = class {
|
|
|
1218
1223
|
await this._initiateConnection(peer);
|
|
1219
1224
|
} catch (err) {
|
|
1220
1225
|
(0, import_log4.log)("initiation error", err, {
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1226
|
+
F: __dxlog_file4,
|
|
1227
|
+
L: 327,
|
|
1228
|
+
S: this,
|
|
1229
|
+
C: (f, a) => f(...a)
|
|
1225
1230
|
});
|
|
1226
1231
|
}
|
|
1227
1232
|
});
|
|
@@ -1246,10 +1251,10 @@ var Swarm = class {
|
|
|
1246
1251
|
(0, import_log4.log)("initiation delay", {
|
|
1247
1252
|
remoteId
|
|
1248
1253
|
}, {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1254
|
+
F: __dxlog_file4,
|
|
1255
|
+
L: 354,
|
|
1256
|
+
S: this,
|
|
1257
|
+
C: (f, a) => f(...a)
|
|
1253
1258
|
});
|
|
1254
1259
|
await (0, import_async3.sleep)(INITIATION_DELAY);
|
|
1255
1260
|
}
|
|
@@ -1263,20 +1268,20 @@ var Swarm = class {
|
|
|
1263
1268
|
(0, import_log4.log)("initiating connection...", {
|
|
1264
1269
|
remoteId
|
|
1265
1270
|
}, {
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1271
|
+
F: __dxlog_file4,
|
|
1272
|
+
L: 368,
|
|
1273
|
+
S: this,
|
|
1274
|
+
C: (f, a) => f(...a)
|
|
1270
1275
|
});
|
|
1271
1276
|
await peer.initiateConnection();
|
|
1272
1277
|
this._topology.update();
|
|
1273
1278
|
(0, import_log4.log)("initiated", {
|
|
1274
1279
|
remoteId
|
|
1275
1280
|
}, {
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1281
|
+
F: __dxlog_file4,
|
|
1282
|
+
L: 371,
|
|
1283
|
+
S: this,
|
|
1284
|
+
C: (f, a) => f(...a)
|
|
1280
1285
|
});
|
|
1281
1286
|
}
|
|
1282
1287
|
async _closeConnection(peerId) {
|
|
@@ -1287,28 +1292,28 @@ var Swarm = class {
|
|
|
1287
1292
|
await peer.closeConnection();
|
|
1288
1293
|
}
|
|
1289
1294
|
};
|
|
1290
|
-
|
|
1295
|
+
_ts_decorate3([
|
|
1291
1296
|
import_log4.logInfo
|
|
1292
1297
|
], Swarm.prototype, "_instanceId", void 0);
|
|
1293
|
-
|
|
1298
|
+
_ts_decorate3([
|
|
1294
1299
|
import_log4.logInfo
|
|
1295
1300
|
], Swarm.prototype, "ownPeerId", null);
|
|
1296
|
-
|
|
1301
|
+
_ts_decorate3([
|
|
1297
1302
|
import_log4.logInfo
|
|
1298
1303
|
], Swarm.prototype, "topic", null);
|
|
1299
|
-
|
|
1304
|
+
_ts_decorate3([
|
|
1300
1305
|
import_async3.synchronized
|
|
1301
1306
|
], Swarm.prototype, "onSwarmEvent", null);
|
|
1302
|
-
|
|
1307
|
+
_ts_decorate3([
|
|
1303
1308
|
import_async3.synchronized
|
|
1304
1309
|
], Swarm.prototype, "onOffer", null);
|
|
1305
|
-
|
|
1310
|
+
_ts_decorate3([
|
|
1306
1311
|
import_async3.synchronized
|
|
1307
1312
|
], Swarm.prototype, "onSignal", null);
|
|
1308
|
-
|
|
1313
|
+
_ts_decorate3([
|
|
1309
1314
|
import_async3.synchronized
|
|
1310
1315
|
], Swarm.prototype, "goOffline", null);
|
|
1311
|
-
|
|
1316
|
+
_ts_decorate3([
|
|
1312
1317
|
import_async3.synchronized
|
|
1313
1318
|
], Swarm.prototype, "goOnline", null);
|
|
1314
1319
|
|
|
@@ -1317,6 +1322,7 @@ var import_async4 = require("@dxos/async");
|
|
|
1317
1322
|
var import_keys5 = require("@dxos/keys");
|
|
1318
1323
|
var import_log5 = require("@dxos/log");
|
|
1319
1324
|
var import_util3 = require("@dxos/util");
|
|
1325
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
1320
1326
|
var SwarmMapper = class {
|
|
1321
1327
|
get peers() {
|
|
1322
1328
|
return Array.from(this._peers.values());
|
|
@@ -1343,11 +1349,11 @@ var SwarmMapper = class {
|
|
|
1343
1349
|
this._update();
|
|
1344
1350
|
}
|
|
1345
1351
|
_update() {
|
|
1346
|
-
(0, import_log5.log)("updating swarm",
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1352
|
+
(0, import_log5.log)("updating swarm", void 0, {
|
|
1353
|
+
F: __dxlog_file5,
|
|
1354
|
+
L: 75,
|
|
1355
|
+
S: this,
|
|
1356
|
+
C: (f, a) => f(...a)
|
|
1351
1357
|
});
|
|
1352
1358
|
this._peers.clear();
|
|
1353
1359
|
this._peers.set(this._swarm.ownPeerId, {
|
|
@@ -1368,10 +1374,10 @@ var SwarmMapper = class {
|
|
|
1368
1374
|
directConnections: this._swarm.connections.length,
|
|
1369
1375
|
totalPeersInSwarm: this._peers.size
|
|
1370
1376
|
}, {
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1377
|
+
F: __dxlog_file5,
|
|
1378
|
+
L: 116,
|
|
1379
|
+
S: this,
|
|
1380
|
+
C: (f, a) => f(...a)
|
|
1375
1381
|
});
|
|
1376
1382
|
this.mapUpdated.emit(Array.from(this._peers.values()));
|
|
1377
1383
|
}
|
|
@@ -1449,8 +1455,9 @@ var ConnectionLog = class {
|
|
|
1449
1455
|
};
|
|
1450
1456
|
|
|
1451
1457
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
1458
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
1452
1459
|
var NetworkManager = class {
|
|
1453
|
-
constructor({ transportFactory, signalManager, log:
|
|
1460
|
+
constructor({ transportFactory, signalManager, log: log1 }) {
|
|
1454
1461
|
this._swarms = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
|
|
1455
1462
|
this._mappers = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
|
|
1456
1463
|
this._connectionState = import_services.ConnectionState.ONLINE;
|
|
@@ -1470,7 +1477,7 @@ var NetworkManager = class {
|
|
|
1470
1477
|
join: (opts) => this._signalManager.join(opts),
|
|
1471
1478
|
leave: (opts) => this._signalManager.leave(opts)
|
|
1472
1479
|
};
|
|
1473
|
-
if (
|
|
1480
|
+
if (log1) {
|
|
1474
1481
|
this._connectionLog = new ConnectionLog();
|
|
1475
1482
|
}
|
|
1476
1483
|
}
|
|
@@ -1495,30 +1502,30 @@ var NetworkManager = class {
|
|
|
1495
1502
|
import_log6.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.begin({
|
|
1496
1503
|
id: this._instanceId
|
|
1497
1504
|
}), {
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1505
|
+
F: __dxlog_file6,
|
|
1506
|
+
L: 127,
|
|
1507
|
+
S: this,
|
|
1508
|
+
C: (f, a) => f(...a)
|
|
1502
1509
|
});
|
|
1503
1510
|
await this._messenger.open();
|
|
1504
1511
|
await this._signalManager.open();
|
|
1505
1512
|
import_log6.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.end({
|
|
1506
1513
|
id: this._instanceId
|
|
1507
1514
|
}), {
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1515
|
+
F: __dxlog_file6,
|
|
1516
|
+
L: 130,
|
|
1517
|
+
S: this,
|
|
1518
|
+
C: (f, a) => f(...a)
|
|
1512
1519
|
});
|
|
1513
1520
|
}
|
|
1514
1521
|
async close() {
|
|
1515
1522
|
for (const topic of this._swarms.keys()) {
|
|
1516
1523
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1517
|
-
(0, import_log6.log)(err,
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1524
|
+
(0, import_log6.log)(err, void 0, {
|
|
1525
|
+
F: __dxlog_file6,
|
|
1526
|
+
L: 136,
|
|
1527
|
+
S: this,
|
|
1528
|
+
C: (f, a) => f(...a)
|
|
1522
1529
|
});
|
|
1523
1530
|
});
|
|
1524
1531
|
}
|
|
@@ -1530,10 +1537,10 @@ var NetworkManager = class {
|
|
|
1530
1537
|
*/
|
|
1531
1538
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1532
1539
|
var _a2;
|
|
1533
|
-
(0,
|
|
1534
|
-
(0,
|
|
1535
|
-
(0,
|
|
1536
|
-
(0,
|
|
1540
|
+
(0, import_tiny_invariant5.default)(import_keys7.PublicKey.isPublicKey(topic));
|
|
1541
|
+
(0, import_tiny_invariant5.default)(import_keys7.PublicKey.isPublicKey(peerId));
|
|
1542
|
+
(0, import_tiny_invariant5.default)(topology);
|
|
1543
|
+
(0, import_tiny_invariant5.default)(typeof protocol === "function");
|
|
1537
1544
|
if (this._swarms.has(topic)) {
|
|
1538
1545
|
throw new Error(`Already connected to swarm: ${import_keys7.PublicKey.from(topic)}`);
|
|
1539
1546
|
}
|
|
@@ -1542,20 +1549,20 @@ var NetworkManager = class {
|
|
|
1542
1549
|
peerId,
|
|
1543
1550
|
topology: topology.toString()
|
|
1544
1551
|
}, {
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1552
|
+
F: __dxlog_file6,
|
|
1553
|
+
L: 162,
|
|
1554
|
+
S: this,
|
|
1555
|
+
C: (f, a) => f(...a)
|
|
1549
1556
|
});
|
|
1550
1557
|
const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label);
|
|
1551
1558
|
swarm.errors.handle((error) => {
|
|
1552
1559
|
(0, import_log6.log)("swarm error", {
|
|
1553
1560
|
error
|
|
1554
1561
|
}, {
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1562
|
+
F: __dxlog_file6,
|
|
1563
|
+
L: 165,
|
|
1564
|
+
S: this,
|
|
1565
|
+
C: (f, a) => f(...a)
|
|
1559
1566
|
});
|
|
1560
1567
|
});
|
|
1561
1568
|
this._swarms.set(topic, swarm);
|
|
@@ -1564,11 +1571,11 @@ var NetworkManager = class {
|
|
|
1564
1571
|
this._signalConnection.join({
|
|
1565
1572
|
topic,
|
|
1566
1573
|
peerId
|
|
1567
|
-
}).catch((error) => import_log6.log.catch(error,
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1574
|
+
}).catch((error) => import_log6.log.catch(error, void 0, {
|
|
1575
|
+
F: __dxlog_file6,
|
|
1576
|
+
L: 174,
|
|
1577
|
+
S: this,
|
|
1578
|
+
C: (f, a) => f(...a)
|
|
1572
1579
|
}));
|
|
1573
1580
|
this.topicsUpdated.emit();
|
|
1574
1581
|
(_a2 = this._connectionLog) == null ? void 0 : _a2.joinedSwarm(swarm);
|
|
@@ -1576,10 +1583,10 @@ var NetworkManager = class {
|
|
|
1576
1583
|
topic: import_keys7.PublicKey.from(topic),
|
|
1577
1584
|
count: this._swarms.size
|
|
1578
1585
|
}, {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1586
|
+
F: __dxlog_file6,
|
|
1587
|
+
L: 178,
|
|
1588
|
+
S: this,
|
|
1589
|
+
C: (f, a) => f(...a)
|
|
1583
1590
|
});
|
|
1584
1591
|
return {
|
|
1585
1592
|
close: () => this.leaveSwarm(topic)
|
|
@@ -1596,10 +1603,10 @@ var NetworkManager = class {
|
|
|
1596
1603
|
(0, import_log6.log)("leaving", {
|
|
1597
1604
|
topic: import_keys7.PublicKey.from(topic)
|
|
1598
1605
|
}, {
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1606
|
+
F: __dxlog_file6,
|
|
1607
|
+
L: 194,
|
|
1608
|
+
S: this,
|
|
1609
|
+
C: (f, a) => f(...a)
|
|
1603
1610
|
});
|
|
1604
1611
|
const swarm = this._swarms.get(topic);
|
|
1605
1612
|
await this._signalConnection.leave({
|
|
@@ -1617,10 +1624,10 @@ var NetworkManager = class {
|
|
|
1617
1624
|
topic: import_keys7.PublicKey.from(topic),
|
|
1618
1625
|
count: this._swarms.size
|
|
1619
1626
|
}, {
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1627
|
+
F: __dxlog_file6,
|
|
1628
|
+
L: 208,
|
|
1629
|
+
S: this,
|
|
1630
|
+
C: (f, a) => f(...a)
|
|
1624
1631
|
});
|
|
1625
1632
|
}
|
|
1626
1633
|
async setConnectionState(state) {
|
|
@@ -1652,17 +1659,17 @@ var NetworkManager = class {
|
|
|
1652
1659
|
};
|
|
1653
1660
|
|
|
1654
1661
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1655
|
-
var
|
|
1662
|
+
var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
|
|
1656
1663
|
var FullyConnectedTopology = class {
|
|
1657
1664
|
toString() {
|
|
1658
1665
|
return "FullyConnectedTopology";
|
|
1659
1666
|
}
|
|
1660
1667
|
init(controller) {
|
|
1661
|
-
(0,
|
|
1668
|
+
(0, import_tiny_invariant6.default)(!this._controller, "Already initialized");
|
|
1662
1669
|
this._controller = controller;
|
|
1663
1670
|
}
|
|
1664
1671
|
update() {
|
|
1665
|
-
(0,
|
|
1672
|
+
(0, import_tiny_invariant6.default)(this._controller, "Not initialized");
|
|
1666
1673
|
const { candidates: discovered } = this._controller.getState();
|
|
1667
1674
|
for (const peer of discovered) {
|
|
1668
1675
|
this._controller.connect(peer);
|
|
@@ -1676,21 +1683,23 @@ var FullyConnectedTopology = class {
|
|
|
1676
1683
|
};
|
|
1677
1684
|
|
|
1678
1685
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1686
|
+
var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
|
|
1679
1687
|
var import_xor_distance = __toESM(require("xor-distance"));
|
|
1680
1688
|
var import_log7 = require("@dxos/log");
|
|
1681
1689
|
|
|
1682
1690
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1691
|
+
var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
|
|
1683
1692
|
var import_log8 = require("@dxos/log");
|
|
1684
1693
|
|
|
1685
1694
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1686
|
-
var import_node_assert7 = __toESM(require("node:assert"));
|
|
1687
1695
|
var import_node_stream = require("node:stream");
|
|
1696
|
+
var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
|
|
1688
1697
|
var import_async7 = require("@dxos/async");
|
|
1689
1698
|
var import_debug4 = require("@dxos/debug");
|
|
1690
1699
|
var import_keys8 = require("@dxos/keys");
|
|
1691
1700
|
var import_log9 = require("@dxos/log");
|
|
1692
1701
|
var import_util6 = require("@dxos/util");
|
|
1693
|
-
|
|
1702
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
1694
1703
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1695
1704
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1696
1705
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1699,7 +1708,8 @@ var __decorate4 = function(decorators, target, key, desc) {
|
|
|
1699
1708
|
if (d = decorators[i])
|
|
1700
1709
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1701
1710
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1702
|
-
}
|
|
1711
|
+
}
|
|
1712
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
1703
1713
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1704
1714
|
var createStreamDelay = (delay) => {
|
|
1705
1715
|
return new import_node_stream.Transform({
|
|
@@ -1719,26 +1729,26 @@ var _MemoryTransport = class {
|
|
|
1719
1729
|
this.closed = new import_async7.Event();
|
|
1720
1730
|
this.connected = new import_async7.Event();
|
|
1721
1731
|
this.errors = new import_debug4.ErrorStream();
|
|
1732
|
+
this._instanceId = import_keys8.PublicKey.random();
|
|
1722
1733
|
this._remote = new import_async7.Trigger();
|
|
1723
1734
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1724
1735
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1725
1736
|
this._destroyed = false;
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
callSite: (f, a) => f(...a)
|
|
1737
|
+
(0, import_log9.log)("creating", void 0, {
|
|
1738
|
+
F: __dxlog_file7,
|
|
1739
|
+
L: 64,
|
|
1740
|
+
S: this,
|
|
1741
|
+
C: (f, a) => f(...a)
|
|
1732
1742
|
});
|
|
1733
|
-
(0,
|
|
1743
|
+
(0, import_tiny_invariant9.default)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
|
|
1734
1744
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1735
1745
|
if (this.options.initiator) {
|
|
1736
1746
|
setTimeout(async () => {
|
|
1737
|
-
(0, import_log9.log)("sending signal",
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1747
|
+
(0, import_log9.log)("sending signal", void 0, {
|
|
1748
|
+
F: __dxlog_file7,
|
|
1749
|
+
L: 73,
|
|
1750
|
+
S: this,
|
|
1751
|
+
C: (f, a) => f(...a)
|
|
1742
1752
|
});
|
|
1743
1753
|
void this.options.sendSignal({
|
|
1744
1754
|
payload: {
|
|
@@ -1764,14 +1774,14 @@ var _MemoryTransport = class {
|
|
|
1764
1774
|
this.closed.emit();
|
|
1765
1775
|
return;
|
|
1766
1776
|
}
|
|
1767
|
-
(0,
|
|
1777
|
+
(0, import_tiny_invariant9.default)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`);
|
|
1768
1778
|
this._remoteConnection._remoteConnection = this;
|
|
1769
1779
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1770
|
-
(0, import_log9.log)("connected",
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1780
|
+
(0, import_log9.log)("connected", void 0, {
|
|
1781
|
+
F: __dxlog_file7,
|
|
1782
|
+
L: 103,
|
|
1783
|
+
S: this,
|
|
1784
|
+
C: (f, a) => f(...a)
|
|
1775
1785
|
});
|
|
1776
1786
|
this.options.stream.pipe(this._outgoingDelay).pipe(this._remoteConnection.options.stream).pipe(this._incomingDelay).pipe(this.options.stream);
|
|
1777
1787
|
this.connected.emit();
|
|
@@ -1785,20 +1795,20 @@ var _MemoryTransport = class {
|
|
|
1785
1795
|
}
|
|
1786
1796
|
}
|
|
1787
1797
|
async destroy() {
|
|
1788
|
-
(0, import_log9.log)("closing",
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1798
|
+
(0, import_log9.log)("closing", void 0, {
|
|
1799
|
+
F: __dxlog_file7,
|
|
1800
|
+
L: 124,
|
|
1801
|
+
S: this,
|
|
1802
|
+
C: (f, a) => f(...a)
|
|
1793
1803
|
});
|
|
1794
1804
|
this._destroyed = true;
|
|
1795
1805
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
1796
1806
|
if (this._remoteConnection) {
|
|
1797
|
-
(0, import_log9.log)("closing",
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1807
|
+
(0, import_log9.log)("closing", void 0, {
|
|
1808
|
+
F: __dxlog_file7,
|
|
1809
|
+
L: 129,
|
|
1810
|
+
S: this,
|
|
1811
|
+
C: (f, a) => f(...a)
|
|
1802
1812
|
});
|
|
1803
1813
|
this._remoteConnection._destroyed = true;
|
|
1804
1814
|
_MemoryTransport._connections.delete(this._remoteInstanceId);
|
|
@@ -1807,29 +1817,29 @@ var _MemoryTransport = class {
|
|
|
1807
1817
|
this._remoteConnection.closed.emit();
|
|
1808
1818
|
this._remoteConnection._remoteConnection = void 0;
|
|
1809
1819
|
this._remoteConnection = void 0;
|
|
1810
|
-
(0, import_log9.log)("closed",
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1820
|
+
(0, import_log9.log)("closed", void 0, {
|
|
1821
|
+
F: __dxlog_file7,
|
|
1822
|
+
L: 147,
|
|
1823
|
+
S: this,
|
|
1824
|
+
C: (f, a) => f(...a)
|
|
1815
1825
|
});
|
|
1816
1826
|
}
|
|
1817
1827
|
this.closed.emit();
|
|
1818
|
-
(0, import_log9.log)("closed",
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1828
|
+
(0, import_log9.log)("closed", void 0, {
|
|
1829
|
+
F: __dxlog_file7,
|
|
1830
|
+
L: 151,
|
|
1831
|
+
S: this,
|
|
1832
|
+
C: (f, a) => f(...a)
|
|
1823
1833
|
});
|
|
1824
1834
|
}
|
|
1825
1835
|
signal({ payload }) {
|
|
1826
1836
|
(0, import_log9.log)("received signal", {
|
|
1827
1837
|
payload
|
|
1828
1838
|
}, {
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1839
|
+
F: __dxlog_file7,
|
|
1840
|
+
L: 155,
|
|
1841
|
+
S: this,
|
|
1842
|
+
C: (f, a) => f(...a)
|
|
1833
1843
|
});
|
|
1834
1844
|
if (!(payload == null ? void 0 : payload.transportId)) {
|
|
1835
1845
|
return;
|
|
@@ -1844,16 +1854,16 @@ var _MemoryTransport = class {
|
|
|
1844
1854
|
var MemoryTransport = _MemoryTransport;
|
|
1845
1855
|
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
1846
1856
|
MemoryTransport._connections = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
|
|
1847
|
-
|
|
1857
|
+
_ts_decorate4([
|
|
1848
1858
|
import_log9.logInfo
|
|
1849
1859
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
1850
|
-
|
|
1860
|
+
_ts_decorate4([
|
|
1851
1861
|
import_log9.logInfo
|
|
1852
1862
|
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
1853
1863
|
|
|
1854
1864
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1855
|
-
var import_node_assert8 = __toESM(require("node:assert"));
|
|
1856
1865
|
var import_simple_peer = __toESM(require("simple-peer"));
|
|
1866
|
+
var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
|
|
1857
1867
|
var import_async8 = require("@dxos/async");
|
|
1858
1868
|
var import_debug5 = require("@dxos/debug");
|
|
1859
1869
|
var import_keys9 = require("@dxos/keys");
|
|
@@ -1868,6 +1878,7 @@ try {
|
|
|
1868
1878
|
}
|
|
1869
1879
|
|
|
1870
1880
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1881
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
|
|
1871
1882
|
var WebRTCTransport = class {
|
|
1872
1883
|
constructor(params) {
|
|
1873
1884
|
var _a2;
|
|
@@ -1880,16 +1891,16 @@ var WebRTCTransport = class {
|
|
|
1880
1891
|
import_log10.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
|
|
1881
1892
|
id: this._instanceId
|
|
1882
1893
|
}), {
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1894
|
+
F: __dxlog_file8,
|
|
1895
|
+
L: 39,
|
|
1896
|
+
S: this,
|
|
1897
|
+
C: (f, a) => f(...a)
|
|
1887
1898
|
});
|
|
1888
1899
|
(0, import_log10.log)("created connection", params, {
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1900
|
+
F: __dxlog_file8,
|
|
1901
|
+
L: 40,
|
|
1902
|
+
S: this,
|
|
1903
|
+
C: (f, a) => f(...a)
|
|
1893
1904
|
});
|
|
1894
1905
|
this._peer = new import_simple_peer.default({
|
|
1895
1906
|
initiator: this.params.initiator,
|
|
@@ -1898,10 +1909,10 @@ var WebRTCTransport = class {
|
|
|
1898
1909
|
});
|
|
1899
1910
|
this._peer.on("signal", async (data) => {
|
|
1900
1911
|
(0, import_log10.log)("signal", data, {
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1912
|
+
F: __dxlog_file8,
|
|
1913
|
+
L: 48,
|
|
1914
|
+
S: this,
|
|
1915
|
+
C: (f, a) => f(...a)
|
|
1905
1916
|
});
|
|
1906
1917
|
await this.params.sendSignal({
|
|
1907
1918
|
payload: {
|
|
@@ -1910,21 +1921,21 @@ var WebRTCTransport = class {
|
|
|
1910
1921
|
});
|
|
1911
1922
|
});
|
|
1912
1923
|
this._peer.on("connect", () => {
|
|
1913
|
-
(0, import_log10.log)("connected",
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1924
|
+
(0, import_log10.log)("connected", void 0, {
|
|
1925
|
+
F: __dxlog_file8,
|
|
1926
|
+
L: 53,
|
|
1927
|
+
S: this,
|
|
1928
|
+
C: (f, a) => f(...a)
|
|
1918
1929
|
});
|
|
1919
1930
|
this.params.stream.pipe(this._peer).pipe(this.params.stream);
|
|
1920
1931
|
this.connected.emit();
|
|
1921
1932
|
});
|
|
1922
1933
|
this._peer.on("close", async () => {
|
|
1923
|
-
(0, import_log10.log)("closed",
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1934
|
+
(0, import_log10.log)("closed", void 0, {
|
|
1935
|
+
F: __dxlog_file8,
|
|
1936
|
+
L: 59,
|
|
1937
|
+
S: this,
|
|
1938
|
+
C: (f, a) => f(...a)
|
|
1928
1939
|
});
|
|
1929
1940
|
await this._disconnectStreams();
|
|
1930
1941
|
this.closed.emit();
|
|
@@ -1939,10 +1950,10 @@ var WebRTCTransport = class {
|
|
|
1939
1950
|
config: this.params.webrtcConfig,
|
|
1940
1951
|
stats
|
|
1941
1952
|
}, {
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1953
|
+
F: __dxlog_file8,
|
|
1954
|
+
L: 71,
|
|
1955
|
+
S: this,
|
|
1956
|
+
C: (f, a) => f(...a)
|
|
1946
1957
|
});
|
|
1947
1958
|
});
|
|
1948
1959
|
}
|
|
@@ -1953,35 +1964,35 @@ var WebRTCTransport = class {
|
|
|
1953
1964
|
import_log10.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
|
|
1954
1965
|
id: this._instanceId
|
|
1955
1966
|
}), {
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1967
|
+
F: __dxlog_file8,
|
|
1968
|
+
L: 81,
|
|
1969
|
+
S: this,
|
|
1970
|
+
C: (f, a) => f(...a)
|
|
1960
1971
|
});
|
|
1961
1972
|
}
|
|
1962
1973
|
async destroy() {
|
|
1963
|
-
(0, import_log10.log)("closing...",
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1974
|
+
(0, import_log10.log)("closing...", void 0, {
|
|
1975
|
+
F: __dxlog_file8,
|
|
1976
|
+
L: 85,
|
|
1977
|
+
S: this,
|
|
1978
|
+
C: (f, a) => f(...a)
|
|
1968
1979
|
});
|
|
1969
1980
|
this._closed = true;
|
|
1970
1981
|
await this._disconnectStreams();
|
|
1971
1982
|
this._peer.destroy();
|
|
1972
1983
|
this.closed.emit();
|
|
1973
|
-
(0, import_log10.log)("closed",
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1984
|
+
(0, import_log10.log)("closed", void 0, {
|
|
1985
|
+
F: __dxlog_file8,
|
|
1986
|
+
L: 90,
|
|
1987
|
+
S: this,
|
|
1988
|
+
C: (f, a) => f(...a)
|
|
1978
1989
|
});
|
|
1979
1990
|
}
|
|
1980
1991
|
signal(signal) {
|
|
1981
1992
|
if (this._closed) {
|
|
1982
1993
|
return;
|
|
1983
1994
|
}
|
|
1984
|
-
(0,
|
|
1995
|
+
(0, import_tiny_invariant10.default)(signal.payload.data, "Signal message must contain signal data.");
|
|
1985
1996
|
this._peer.signal(signal.payload.data);
|
|
1986
1997
|
}
|
|
1987
1998
|
async _disconnectStreams() {
|
|
@@ -1991,13 +2002,14 @@ var WebRTCTransport = class {
|
|
|
1991
2002
|
};
|
|
1992
2003
|
|
|
1993
2004
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
1994
|
-
var import_node_assert9 = __toESM(require("node:assert"));
|
|
1995
2005
|
var import_node_stream2 = require("node:stream");
|
|
2006
|
+
var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
|
|
1996
2007
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
1997
2008
|
var import_keys10 = require("@dxos/keys");
|
|
1998
2009
|
var import_log11 = require("@dxos/log");
|
|
1999
2010
|
var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2000
2011
|
var import_util7 = require("@dxos/util");
|
|
2012
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
|
|
2001
2013
|
var WebRTCTransportService = class {
|
|
2002
2014
|
// prettier-ignore
|
|
2003
2015
|
constructor(_webrtcConfig) {
|
|
@@ -2068,11 +2080,11 @@ var WebRTCTransportService = class {
|
|
|
2068
2080
|
return rpcStream;
|
|
2069
2081
|
}
|
|
2070
2082
|
async sendSignal({ proxyId, signal }) {
|
|
2071
|
-
(0,
|
|
2083
|
+
(0, import_tiny_invariant11.default)(this.transports.has(proxyId));
|
|
2072
2084
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2073
2085
|
}
|
|
2074
2086
|
async sendData({ proxyId, payload }) {
|
|
2075
|
-
(0,
|
|
2087
|
+
(0, import_tiny_invariant11.default)(this.transports.has(proxyId));
|
|
2076
2088
|
await this.transports.get(proxyId).stream.push(payload);
|
|
2077
2089
|
}
|
|
2078
2090
|
async close({ proxyId }) {
|
|
@@ -2080,17 +2092,17 @@ var WebRTCTransportService = class {
|
|
|
2080
2092
|
await ((_a2 = this.transports.get(proxyId)) == null ? void 0 : _a2.transport.destroy());
|
|
2081
2093
|
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
2082
2094
|
this.transports.delete(proxyId);
|
|
2083
|
-
(0, import_log11.log)("Closed.",
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2095
|
+
(0, import_log11.log)("Closed.", void 0, {
|
|
2096
|
+
F: __dxlog_file9,
|
|
2097
|
+
L: 109,
|
|
2098
|
+
S: this,
|
|
2099
|
+
C: (f, a) => f(...a)
|
|
2088
2100
|
});
|
|
2089
2101
|
}
|
|
2090
2102
|
};
|
|
2091
2103
|
|
|
2092
2104
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2093
|
-
var
|
|
2105
|
+
var import_tiny_invariant12 = __toESM(require("tiny-invariant"));
|
|
2094
2106
|
var import_async9 = require("@dxos/async");
|
|
2095
2107
|
var import_context5 = require("@dxos/context");
|
|
2096
2108
|
var import_debug6 = require("@dxos/debug");
|
|
@@ -2098,6 +2110,7 @@ var import_keys11 = require("@dxos/keys");
|
|
|
2098
2110
|
var import_log12 = require("@dxos/log");
|
|
2099
2111
|
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2100
2112
|
var import_util8 = require("@dxos/util");
|
|
2113
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
|
|
2101
2114
|
var WebRTCTransportProxy = class {
|
|
2102
2115
|
// prettier-ignore
|
|
2103
2116
|
constructor(_params) {
|
|
@@ -2115,10 +2128,10 @@ var WebRTCTransportProxy = class {
|
|
|
2115
2128
|
this._serviceStream.waitUntilReady().then(() => {
|
|
2116
2129
|
this._serviceStream.subscribe(async (event) => {
|
|
2117
2130
|
(0, import_log12.log)("WebRTCTransportProxy: event", event, {
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2131
|
+
F: __dxlog_file10,
|
|
2132
|
+
L: 50,
|
|
2133
|
+
S: this,
|
|
2134
|
+
C: (f, a) => f(...a)
|
|
2122
2135
|
});
|
|
2123
2136
|
if (event.connection) {
|
|
2124
2137
|
await this._handleConnection(event.connection);
|
|
@@ -2135,11 +2148,11 @@ var WebRTCTransportProxy = class {
|
|
|
2135
2148
|
payload: data
|
|
2136
2149
|
});
|
|
2137
2150
|
} catch (err) {
|
|
2138
|
-
import_log12.log.catch(err,
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2151
|
+
import_log12.log.catch(err, void 0, {
|
|
2152
|
+
F: __dxlog_file10,
|
|
2153
|
+
L: 67,
|
|
2154
|
+
S: this,
|
|
2155
|
+
C: (f, a) => f(...a)
|
|
2143
2156
|
});
|
|
2144
2157
|
}
|
|
2145
2158
|
};
|
|
@@ -2147,11 +2160,11 @@ var WebRTCTransportProxy = class {
|
|
|
2147
2160
|
this._ctx.onDispose(() => {
|
|
2148
2161
|
this._params.stream.off("data", dataListener);
|
|
2149
2162
|
});
|
|
2150
|
-
}, (error) => import_log12.log.catch(error,
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2163
|
+
}, (error) => import_log12.log.catch(error, void 0, {
|
|
2164
|
+
F: __dxlog_file10,
|
|
2165
|
+
L: 73,
|
|
2166
|
+
S: this,
|
|
2167
|
+
C: (f, a) => f(...a)
|
|
2155
2168
|
}));
|
|
2156
2169
|
}
|
|
2157
2170
|
async _handleConnection(connectionEvent) {
|
|
@@ -2193,11 +2206,11 @@ var WebRTCTransportProxy = class {
|
|
|
2193
2206
|
proxyId: this._proxyId
|
|
2194
2207
|
});
|
|
2195
2208
|
} catch (err) {
|
|
2196
|
-
import_log12.log.catch(err,
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2209
|
+
import_log12.log.catch(err, void 0, {
|
|
2210
|
+
F: __dxlog_file10,
|
|
2211
|
+
L: 124,
|
|
2212
|
+
S: this,
|
|
2213
|
+
C: (f, a) => f(...a)
|
|
2201
2214
|
});
|
|
2202
2215
|
}
|
|
2203
2216
|
this.closed.emit();
|
|
@@ -2229,7 +2242,7 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2229
2242
|
return this;
|
|
2230
2243
|
}
|
|
2231
2244
|
createTransport(options) {
|
|
2232
|
-
(0,
|
|
2245
|
+
(0, import_tiny_invariant12.default)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections");
|
|
2233
2246
|
const transport = new WebRTCTransportProxy({
|
|
2234
2247
|
...options,
|
|
2235
2248
|
bridgeService: this._bridgeService
|
|
@@ -2266,20 +2279,22 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
2266
2279
|
};
|
|
2267
2280
|
|
|
2268
2281
|
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
2282
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
|
|
2269
2283
|
var TestWireProtocol = class {
|
|
2270
2284
|
constructor(peerId) {
|
|
2271
2285
|
this.peerId = peerId;
|
|
2272
2286
|
this.connections = new import_util9.ComplexMap(import_keys12.PublicKey.hash);
|
|
2287
|
+
this.streamConnections = new import_util9.ComplexMap(import_keys12.PublicKey.hash);
|
|
2273
2288
|
this.connected = new import_async10.Event();
|
|
2274
2289
|
this.disconnected = new import_async10.Event();
|
|
2275
2290
|
this.factory = createTeleportProtocolFactory(async (teleport) => {
|
|
2276
2291
|
(0, import_log13.log)("create", {
|
|
2277
2292
|
remotePeerId: teleport.remotePeerId
|
|
2278
2293
|
}, {
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2294
|
+
F: __dxlog_file11,
|
|
2295
|
+
L: 23,
|
|
2296
|
+
S: this,
|
|
2297
|
+
C: (f, a) => f(...a)
|
|
2283
2298
|
});
|
|
2284
2299
|
const extension = new import_teleport2.TestExtension({
|
|
2285
2300
|
onClose: async () => {
|
|
@@ -2290,6 +2305,13 @@ var TestWireProtocol = class {
|
|
|
2290
2305
|
this.connections.set(teleport.remotePeerId, extension);
|
|
2291
2306
|
teleport.addExtension("test", extension);
|
|
2292
2307
|
this.connected.emit(teleport.remotePeerId);
|
|
2308
|
+
const streamExtension = new import_teleport2.TestExtensionWithStreams({
|
|
2309
|
+
onClose: async () => {
|
|
2310
|
+
this.streamConnections.delete(teleport.remotePeerId);
|
|
2311
|
+
}
|
|
2312
|
+
});
|
|
2313
|
+
this.streamConnections.set(teleport.remotePeerId, streamExtension);
|
|
2314
|
+
teleport.addExtension("test-stream", streamExtension);
|
|
2293
2315
|
});
|
|
2294
2316
|
}
|
|
2295
2317
|
async waitForConnection(peerId) {
|
|
@@ -2299,10 +2321,10 @@ var TestWireProtocol = class {
|
|
|
2299
2321
|
(0, import_log13.log)("waitForConnection", {
|
|
2300
2322
|
peerId
|
|
2301
2323
|
}, {
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2324
|
+
F: __dxlog_file11,
|
|
2325
|
+
L: 47,
|
|
2326
|
+
S: this,
|
|
2327
|
+
C: (f, a) => f(...a)
|
|
2306
2328
|
});
|
|
2307
2329
|
await (0, import_async10.asyncTimeout)(
|
|
2308
2330
|
this.connected.waitFor((connectedId) => connectedId.equals(peerId)),
|
|
@@ -2315,6 +2337,20 @@ var TestWireProtocol = class {
|
|
|
2315
2337
|
const connection = await this.waitForConnection(peerId);
|
|
2316
2338
|
await connection.test(message);
|
|
2317
2339
|
}
|
|
2340
|
+
async startStream(peerId, streamTag, streamLoadInterval, streamLoadChunkSize) {
|
|
2341
|
+
if (!this.streamConnections.has(peerId)) {
|
|
2342
|
+
throw new Error("Connection does not exist.");
|
|
2343
|
+
}
|
|
2344
|
+
const connection = this.streamConnections.get(peerId);
|
|
2345
|
+
return connection.addNewStream(streamLoadInterval, streamLoadChunkSize, streamTag);
|
|
2346
|
+
}
|
|
2347
|
+
async closeStream(peerId, streamTag) {
|
|
2348
|
+
if (!this.streamConnections.has(peerId)) {
|
|
2349
|
+
throw new Error("Connection does not exist.");
|
|
2350
|
+
}
|
|
2351
|
+
const connection = this.streamConnections.get(peerId);
|
|
2352
|
+
return connection.closeStream(streamTag);
|
|
2353
|
+
}
|
|
2318
2354
|
};
|
|
2319
2355
|
|
|
2320
2356
|
// packages/core/mesh/network-manager/src/testing/test-builder.ts
|