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