@dxos/network-manager 0.1.52 → 0.1.53-main.01c99c0
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-U73XV3EJ.mjs → chunk-HDCPX2MD.mjs} +519 -500
- 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 +11 -10
- package/dist/lib/browser/testing/index.mjs.map +1 -1
- package/dist/lib/node/index.cjs +517 -498
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +477 -457
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/connection-log.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport-proxy.d.ts.map +1 -1
- package/package.json +19 -18
- package/src/connection-log.ts +6 -0
- 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/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 +4 -3
- package/src/transport/webrtc-transport-service.ts +3 -3
- package/src/transport/webrtc-transport.ts +2 -2
- package/dist/lib/browser/chunk-U73XV3EJ.mjs.map +0 -7
|
@@ -43,10 +43,10 @@ var import_messaging2 = require("@dxos/messaging");
|
|
|
43
43
|
var import_protocols6 = require("@dxos/protocols");
|
|
44
44
|
var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
|
|
45
45
|
var import_rpc = require("@dxos/rpc");
|
|
46
|
-
var
|
|
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
|
}
|
|
@@ -1417,6 +1423,7 @@ var ConnectionLog = class {
|
|
|
1417
1423
|
this._swarms.set(import_keys6.PublicKey.from(swarm._instanceId), info);
|
|
1418
1424
|
this.update.emit();
|
|
1419
1425
|
swarm.connectionAdded.on((connection) => {
|
|
1426
|
+
var _a2, _b;
|
|
1420
1427
|
const connectionInfo = {
|
|
1421
1428
|
state: ConnectionState.INITIAL,
|
|
1422
1429
|
remotePeerId: connection.remoteId,
|
|
@@ -1435,6 +1442,10 @@ var ConnectionLog = class {
|
|
|
1435
1442
|
});
|
|
1436
1443
|
this.update.emit();
|
|
1437
1444
|
});
|
|
1445
|
+
(_b = (_a2 = connection.protocol) == null ? void 0 : _a2.stats) == null ? void 0 : _b.on((stats) => {
|
|
1446
|
+
connectionInfo.streams = stats;
|
|
1447
|
+
this.update.emit();
|
|
1448
|
+
});
|
|
1438
1449
|
});
|
|
1439
1450
|
}
|
|
1440
1451
|
leftSwarm(swarm) {
|
|
@@ -1444,8 +1455,9 @@ var ConnectionLog = class {
|
|
|
1444
1455
|
};
|
|
1445
1456
|
|
|
1446
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";
|
|
1447
1459
|
var NetworkManager = class {
|
|
1448
|
-
constructor({ transportFactory, signalManager, log:
|
|
1460
|
+
constructor({ transportFactory, signalManager, log: log1 }) {
|
|
1449
1461
|
this._swarms = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
|
|
1450
1462
|
this._mappers = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
|
|
1451
1463
|
this._connectionState = import_services.ConnectionState.ONLINE;
|
|
@@ -1465,7 +1477,7 @@ var NetworkManager = class {
|
|
|
1465
1477
|
join: (opts) => this._signalManager.join(opts),
|
|
1466
1478
|
leave: (opts) => this._signalManager.leave(opts)
|
|
1467
1479
|
};
|
|
1468
|
-
if (
|
|
1480
|
+
if (log1) {
|
|
1469
1481
|
this._connectionLog = new ConnectionLog();
|
|
1470
1482
|
}
|
|
1471
1483
|
}
|
|
@@ -1490,30 +1502,30 @@ var NetworkManager = class {
|
|
|
1490
1502
|
import_log6.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.begin({
|
|
1491
1503
|
id: this._instanceId
|
|
1492
1504
|
}), {
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1505
|
+
F: __dxlog_file6,
|
|
1506
|
+
L: 127,
|
|
1507
|
+
S: this,
|
|
1508
|
+
C: (f, a) => f(...a)
|
|
1497
1509
|
});
|
|
1498
1510
|
await this._messenger.open();
|
|
1499
1511
|
await this._signalManager.open();
|
|
1500
1512
|
import_log6.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.end({
|
|
1501
1513
|
id: this._instanceId
|
|
1502
1514
|
}), {
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1515
|
+
F: __dxlog_file6,
|
|
1516
|
+
L: 130,
|
|
1517
|
+
S: this,
|
|
1518
|
+
C: (f, a) => f(...a)
|
|
1507
1519
|
});
|
|
1508
1520
|
}
|
|
1509
1521
|
async close() {
|
|
1510
1522
|
for (const topic of this._swarms.keys()) {
|
|
1511
1523
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1512
|
-
(0, import_log6.log)(err,
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1524
|
+
(0, import_log6.log)(err, void 0, {
|
|
1525
|
+
F: __dxlog_file6,
|
|
1526
|
+
L: 136,
|
|
1527
|
+
S: this,
|
|
1528
|
+
C: (f, a) => f(...a)
|
|
1517
1529
|
});
|
|
1518
1530
|
});
|
|
1519
1531
|
}
|
|
@@ -1525,10 +1537,10 @@ var NetworkManager = class {
|
|
|
1525
1537
|
*/
|
|
1526
1538
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1527
1539
|
var _a2;
|
|
1528
|
-
(0,
|
|
1529
|
-
(0,
|
|
1530
|
-
(0,
|
|
1531
|
-
(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");
|
|
1532
1544
|
if (this._swarms.has(topic)) {
|
|
1533
1545
|
throw new Error(`Already connected to swarm: ${import_keys7.PublicKey.from(topic)}`);
|
|
1534
1546
|
}
|
|
@@ -1537,20 +1549,20 @@ var NetworkManager = class {
|
|
|
1537
1549
|
peerId,
|
|
1538
1550
|
topology: topology.toString()
|
|
1539
1551
|
}, {
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1552
|
+
F: __dxlog_file6,
|
|
1553
|
+
L: 162,
|
|
1554
|
+
S: this,
|
|
1555
|
+
C: (f, a) => f(...a)
|
|
1544
1556
|
});
|
|
1545
1557
|
const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label);
|
|
1546
1558
|
swarm.errors.handle((error) => {
|
|
1547
1559
|
(0, import_log6.log)("swarm error", {
|
|
1548
1560
|
error
|
|
1549
1561
|
}, {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1562
|
+
F: __dxlog_file6,
|
|
1563
|
+
L: 165,
|
|
1564
|
+
S: this,
|
|
1565
|
+
C: (f, a) => f(...a)
|
|
1554
1566
|
});
|
|
1555
1567
|
});
|
|
1556
1568
|
this._swarms.set(topic, swarm);
|
|
@@ -1559,11 +1571,11 @@ var NetworkManager = class {
|
|
|
1559
1571
|
this._signalConnection.join({
|
|
1560
1572
|
topic,
|
|
1561
1573
|
peerId
|
|
1562
|
-
}).catch((error) => import_log6.log.catch(error,
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
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)
|
|
1567
1579
|
}));
|
|
1568
1580
|
this.topicsUpdated.emit();
|
|
1569
1581
|
(_a2 = this._connectionLog) == null ? void 0 : _a2.joinedSwarm(swarm);
|
|
@@ -1571,10 +1583,10 @@ var NetworkManager = class {
|
|
|
1571
1583
|
topic: import_keys7.PublicKey.from(topic),
|
|
1572
1584
|
count: this._swarms.size
|
|
1573
1585
|
}, {
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1586
|
+
F: __dxlog_file6,
|
|
1587
|
+
L: 178,
|
|
1588
|
+
S: this,
|
|
1589
|
+
C: (f, a) => f(...a)
|
|
1578
1590
|
});
|
|
1579
1591
|
return {
|
|
1580
1592
|
close: () => this.leaveSwarm(topic)
|
|
@@ -1591,10 +1603,10 @@ var NetworkManager = class {
|
|
|
1591
1603
|
(0, import_log6.log)("leaving", {
|
|
1592
1604
|
topic: import_keys7.PublicKey.from(topic)
|
|
1593
1605
|
}, {
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1606
|
+
F: __dxlog_file6,
|
|
1607
|
+
L: 194,
|
|
1608
|
+
S: this,
|
|
1609
|
+
C: (f, a) => f(...a)
|
|
1598
1610
|
});
|
|
1599
1611
|
const swarm = this._swarms.get(topic);
|
|
1600
1612
|
await this._signalConnection.leave({
|
|
@@ -1612,10 +1624,10 @@ var NetworkManager = class {
|
|
|
1612
1624
|
topic: import_keys7.PublicKey.from(topic),
|
|
1613
1625
|
count: this._swarms.size
|
|
1614
1626
|
}, {
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1627
|
+
F: __dxlog_file6,
|
|
1628
|
+
L: 208,
|
|
1629
|
+
S: this,
|
|
1630
|
+
C: (f, a) => f(...a)
|
|
1619
1631
|
});
|
|
1620
1632
|
}
|
|
1621
1633
|
async setConnectionState(state) {
|
|
@@ -1647,17 +1659,17 @@ var NetworkManager = class {
|
|
|
1647
1659
|
};
|
|
1648
1660
|
|
|
1649
1661
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1650
|
-
var
|
|
1662
|
+
var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
|
|
1651
1663
|
var FullyConnectedTopology = class {
|
|
1652
1664
|
toString() {
|
|
1653
1665
|
return "FullyConnectedTopology";
|
|
1654
1666
|
}
|
|
1655
1667
|
init(controller) {
|
|
1656
|
-
(0,
|
|
1668
|
+
(0, import_tiny_invariant6.default)(!this._controller, "Already initialized");
|
|
1657
1669
|
this._controller = controller;
|
|
1658
1670
|
}
|
|
1659
1671
|
update() {
|
|
1660
|
-
(0,
|
|
1672
|
+
(0, import_tiny_invariant6.default)(this._controller, "Not initialized");
|
|
1661
1673
|
const { candidates: discovered } = this._controller.getState();
|
|
1662
1674
|
for (const peer of discovered) {
|
|
1663
1675
|
this._controller.connect(peer);
|
|
@@ -1671,21 +1683,23 @@ var FullyConnectedTopology = class {
|
|
|
1671
1683
|
};
|
|
1672
1684
|
|
|
1673
1685
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1686
|
+
var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
|
|
1674
1687
|
var import_xor_distance = __toESM(require("xor-distance"));
|
|
1675
1688
|
var import_log7 = require("@dxos/log");
|
|
1676
1689
|
|
|
1677
1690
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1691
|
+
var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
|
|
1678
1692
|
var import_log8 = require("@dxos/log");
|
|
1679
1693
|
|
|
1680
1694
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1681
|
-
var import_node_assert7 = __toESM(require("node:assert"));
|
|
1682
1695
|
var import_node_stream = require("node:stream");
|
|
1696
|
+
var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
|
|
1683
1697
|
var import_async7 = require("@dxos/async");
|
|
1684
1698
|
var import_debug4 = require("@dxos/debug");
|
|
1685
1699
|
var import_keys8 = require("@dxos/keys");
|
|
1686
1700
|
var import_log9 = require("@dxos/log");
|
|
1687
1701
|
var import_util6 = require("@dxos/util");
|
|
1688
|
-
|
|
1702
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
1689
1703
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1690
1704
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1691
1705
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1694,7 +1708,8 @@ var __decorate4 = function(decorators, target, key, desc) {
|
|
|
1694
1708
|
if (d = decorators[i])
|
|
1695
1709
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1696
1710
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1697
|
-
}
|
|
1711
|
+
}
|
|
1712
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
1698
1713
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1699
1714
|
var createStreamDelay = (delay) => {
|
|
1700
1715
|
return new import_node_stream.Transform({
|
|
@@ -1714,26 +1729,26 @@ var _MemoryTransport = class {
|
|
|
1714
1729
|
this.closed = new import_async7.Event();
|
|
1715
1730
|
this.connected = new import_async7.Event();
|
|
1716
1731
|
this.errors = new import_debug4.ErrorStream();
|
|
1732
|
+
this._instanceId = import_keys8.PublicKey.random();
|
|
1717
1733
|
this._remote = new import_async7.Trigger();
|
|
1718
1734
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1719
1735
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1720
1736
|
this._destroyed = false;
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
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)
|
|
1727
1742
|
});
|
|
1728
|
-
(0,
|
|
1743
|
+
(0, import_tiny_invariant9.default)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
|
|
1729
1744
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1730
1745
|
if (this.options.initiator) {
|
|
1731
1746
|
setTimeout(async () => {
|
|
1732
|
-
(0, import_log9.log)("sending signal",
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
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)
|
|
1737
1752
|
});
|
|
1738
1753
|
void this.options.sendSignal({
|
|
1739
1754
|
payload: {
|
|
@@ -1759,14 +1774,14 @@ var _MemoryTransport = class {
|
|
|
1759
1774
|
this.closed.emit();
|
|
1760
1775
|
return;
|
|
1761
1776
|
}
|
|
1762
|
-
(0,
|
|
1777
|
+
(0, import_tiny_invariant9.default)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`);
|
|
1763
1778
|
this._remoteConnection._remoteConnection = this;
|
|
1764
1779
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1765
|
-
(0, import_log9.log)("connected",
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1780
|
+
(0, import_log9.log)("connected", void 0, {
|
|
1781
|
+
F: __dxlog_file7,
|
|
1782
|
+
L: 103,
|
|
1783
|
+
S: this,
|
|
1784
|
+
C: (f, a) => f(...a)
|
|
1770
1785
|
});
|
|
1771
1786
|
this.options.stream.pipe(this._outgoingDelay).pipe(this._remoteConnection.options.stream).pipe(this._incomingDelay).pipe(this.options.stream);
|
|
1772
1787
|
this.connected.emit();
|
|
@@ -1780,20 +1795,20 @@ var _MemoryTransport = class {
|
|
|
1780
1795
|
}
|
|
1781
1796
|
}
|
|
1782
1797
|
async destroy() {
|
|
1783
|
-
(0, import_log9.log)("closing",
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1798
|
+
(0, import_log9.log)("closing", void 0, {
|
|
1799
|
+
F: __dxlog_file7,
|
|
1800
|
+
L: 124,
|
|
1801
|
+
S: this,
|
|
1802
|
+
C: (f, a) => f(...a)
|
|
1788
1803
|
});
|
|
1789
1804
|
this._destroyed = true;
|
|
1790
1805
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
1791
1806
|
if (this._remoteConnection) {
|
|
1792
|
-
(0, import_log9.log)("closing",
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1807
|
+
(0, import_log9.log)("closing", void 0, {
|
|
1808
|
+
F: __dxlog_file7,
|
|
1809
|
+
L: 129,
|
|
1810
|
+
S: this,
|
|
1811
|
+
C: (f, a) => f(...a)
|
|
1797
1812
|
});
|
|
1798
1813
|
this._remoteConnection._destroyed = true;
|
|
1799
1814
|
_MemoryTransport._connections.delete(this._remoteInstanceId);
|
|
@@ -1802,29 +1817,29 @@ var _MemoryTransport = class {
|
|
|
1802
1817
|
this._remoteConnection.closed.emit();
|
|
1803
1818
|
this._remoteConnection._remoteConnection = void 0;
|
|
1804
1819
|
this._remoteConnection = void 0;
|
|
1805
|
-
(0, import_log9.log)("closed",
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1820
|
+
(0, import_log9.log)("closed", void 0, {
|
|
1821
|
+
F: __dxlog_file7,
|
|
1822
|
+
L: 147,
|
|
1823
|
+
S: this,
|
|
1824
|
+
C: (f, a) => f(...a)
|
|
1810
1825
|
});
|
|
1811
1826
|
}
|
|
1812
1827
|
this.closed.emit();
|
|
1813
|
-
(0, import_log9.log)("closed",
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1828
|
+
(0, import_log9.log)("closed", void 0, {
|
|
1829
|
+
F: __dxlog_file7,
|
|
1830
|
+
L: 151,
|
|
1831
|
+
S: this,
|
|
1832
|
+
C: (f, a) => f(...a)
|
|
1818
1833
|
});
|
|
1819
1834
|
}
|
|
1820
1835
|
signal({ payload }) {
|
|
1821
1836
|
(0, import_log9.log)("received signal", {
|
|
1822
1837
|
payload
|
|
1823
1838
|
}, {
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1839
|
+
F: __dxlog_file7,
|
|
1840
|
+
L: 155,
|
|
1841
|
+
S: this,
|
|
1842
|
+
C: (f, a) => f(...a)
|
|
1828
1843
|
});
|
|
1829
1844
|
if (!(payload == null ? void 0 : payload.transportId)) {
|
|
1830
1845
|
return;
|
|
@@ -1839,16 +1854,16 @@ var _MemoryTransport = class {
|
|
|
1839
1854
|
var MemoryTransport = _MemoryTransport;
|
|
1840
1855
|
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
1841
1856
|
MemoryTransport._connections = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
|
|
1842
|
-
|
|
1857
|
+
_ts_decorate4([
|
|
1843
1858
|
import_log9.logInfo
|
|
1844
1859
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
1845
|
-
|
|
1860
|
+
_ts_decorate4([
|
|
1846
1861
|
import_log9.logInfo
|
|
1847
1862
|
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
1848
1863
|
|
|
1849
1864
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1850
|
-
var import_node_assert8 = __toESM(require("node:assert"));
|
|
1851
1865
|
var import_simple_peer = __toESM(require("simple-peer"));
|
|
1866
|
+
var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
|
|
1852
1867
|
var import_async8 = require("@dxos/async");
|
|
1853
1868
|
var import_debug5 = require("@dxos/debug");
|
|
1854
1869
|
var import_keys9 = require("@dxos/keys");
|
|
@@ -1863,6 +1878,7 @@ try {
|
|
|
1863
1878
|
}
|
|
1864
1879
|
|
|
1865
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";
|
|
1866
1882
|
var WebRTCTransport = class {
|
|
1867
1883
|
constructor(params) {
|
|
1868
1884
|
var _a2;
|
|
@@ -1875,16 +1891,16 @@ var WebRTCTransport = class {
|
|
|
1875
1891
|
import_log10.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
|
|
1876
1892
|
id: this._instanceId
|
|
1877
1893
|
}), {
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1894
|
+
F: __dxlog_file8,
|
|
1895
|
+
L: 39,
|
|
1896
|
+
S: this,
|
|
1897
|
+
C: (f, a) => f(...a)
|
|
1882
1898
|
});
|
|
1883
1899
|
(0, import_log10.log)("created connection", params, {
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1900
|
+
F: __dxlog_file8,
|
|
1901
|
+
L: 40,
|
|
1902
|
+
S: this,
|
|
1903
|
+
C: (f, a) => f(...a)
|
|
1888
1904
|
});
|
|
1889
1905
|
this._peer = new import_simple_peer.default({
|
|
1890
1906
|
initiator: this.params.initiator,
|
|
@@ -1893,10 +1909,10 @@ var WebRTCTransport = class {
|
|
|
1893
1909
|
});
|
|
1894
1910
|
this._peer.on("signal", async (data) => {
|
|
1895
1911
|
(0, import_log10.log)("signal", data, {
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1912
|
+
F: __dxlog_file8,
|
|
1913
|
+
L: 48,
|
|
1914
|
+
S: this,
|
|
1915
|
+
C: (f, a) => f(...a)
|
|
1900
1916
|
});
|
|
1901
1917
|
await this.params.sendSignal({
|
|
1902
1918
|
payload: {
|
|
@@ -1905,21 +1921,21 @@ var WebRTCTransport = class {
|
|
|
1905
1921
|
});
|
|
1906
1922
|
});
|
|
1907
1923
|
this._peer.on("connect", () => {
|
|
1908
|
-
(0, import_log10.log)("connected",
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1924
|
+
(0, import_log10.log)("connected", void 0, {
|
|
1925
|
+
F: __dxlog_file8,
|
|
1926
|
+
L: 53,
|
|
1927
|
+
S: this,
|
|
1928
|
+
C: (f, a) => f(...a)
|
|
1913
1929
|
});
|
|
1914
1930
|
this.params.stream.pipe(this._peer).pipe(this.params.stream);
|
|
1915
1931
|
this.connected.emit();
|
|
1916
1932
|
});
|
|
1917
1933
|
this._peer.on("close", async () => {
|
|
1918
|
-
(0, import_log10.log)("closed",
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1934
|
+
(0, import_log10.log)("closed", void 0, {
|
|
1935
|
+
F: __dxlog_file8,
|
|
1936
|
+
L: 59,
|
|
1937
|
+
S: this,
|
|
1938
|
+
C: (f, a) => f(...a)
|
|
1923
1939
|
});
|
|
1924
1940
|
await this._disconnectStreams();
|
|
1925
1941
|
this.closed.emit();
|
|
@@ -1934,10 +1950,10 @@ var WebRTCTransport = class {
|
|
|
1934
1950
|
config: this.params.webrtcConfig,
|
|
1935
1951
|
stats
|
|
1936
1952
|
}, {
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1953
|
+
F: __dxlog_file8,
|
|
1954
|
+
L: 71,
|
|
1955
|
+
S: this,
|
|
1956
|
+
C: (f, a) => f(...a)
|
|
1941
1957
|
});
|
|
1942
1958
|
});
|
|
1943
1959
|
}
|
|
@@ -1948,35 +1964,35 @@ var WebRTCTransport = class {
|
|
|
1948
1964
|
import_log10.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
|
|
1949
1965
|
id: this._instanceId
|
|
1950
1966
|
}), {
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1967
|
+
F: __dxlog_file8,
|
|
1968
|
+
L: 81,
|
|
1969
|
+
S: this,
|
|
1970
|
+
C: (f, a) => f(...a)
|
|
1955
1971
|
});
|
|
1956
1972
|
}
|
|
1957
1973
|
async destroy() {
|
|
1958
|
-
(0, import_log10.log)("closing...",
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1974
|
+
(0, import_log10.log)("closing...", void 0, {
|
|
1975
|
+
F: __dxlog_file8,
|
|
1976
|
+
L: 85,
|
|
1977
|
+
S: this,
|
|
1978
|
+
C: (f, a) => f(...a)
|
|
1963
1979
|
});
|
|
1964
1980
|
this._closed = true;
|
|
1965
1981
|
await this._disconnectStreams();
|
|
1966
1982
|
this._peer.destroy();
|
|
1967
1983
|
this.closed.emit();
|
|
1968
|
-
(0, import_log10.log)("closed",
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1984
|
+
(0, import_log10.log)("closed", void 0, {
|
|
1985
|
+
F: __dxlog_file8,
|
|
1986
|
+
L: 90,
|
|
1987
|
+
S: this,
|
|
1988
|
+
C: (f, a) => f(...a)
|
|
1973
1989
|
});
|
|
1974
1990
|
}
|
|
1975
1991
|
signal(signal) {
|
|
1976
1992
|
if (this._closed) {
|
|
1977
1993
|
return;
|
|
1978
1994
|
}
|
|
1979
|
-
(0,
|
|
1995
|
+
(0, import_tiny_invariant10.default)(signal.payload.data, "Signal message must contain signal data.");
|
|
1980
1996
|
this._peer.signal(signal.payload.data);
|
|
1981
1997
|
}
|
|
1982
1998
|
async _disconnectStreams() {
|
|
@@ -1986,13 +2002,14 @@ var WebRTCTransport = class {
|
|
|
1986
2002
|
};
|
|
1987
2003
|
|
|
1988
2004
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
1989
|
-
var import_node_assert9 = __toESM(require("node:assert"));
|
|
1990
2005
|
var import_node_stream2 = require("node:stream");
|
|
2006
|
+
var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
|
|
1991
2007
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
1992
2008
|
var import_keys10 = require("@dxos/keys");
|
|
1993
2009
|
var import_log11 = require("@dxos/log");
|
|
1994
2010
|
var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
1995
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";
|
|
1996
2013
|
var WebRTCTransportService = class {
|
|
1997
2014
|
// prettier-ignore
|
|
1998
2015
|
constructor(_webrtcConfig) {
|
|
@@ -2063,11 +2080,11 @@ var WebRTCTransportService = class {
|
|
|
2063
2080
|
return rpcStream;
|
|
2064
2081
|
}
|
|
2065
2082
|
async sendSignal({ proxyId, signal }) {
|
|
2066
|
-
(0,
|
|
2083
|
+
(0, import_tiny_invariant11.default)(this.transports.has(proxyId));
|
|
2067
2084
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2068
2085
|
}
|
|
2069
2086
|
async sendData({ proxyId, payload }) {
|
|
2070
|
-
(0,
|
|
2087
|
+
(0, import_tiny_invariant11.default)(this.transports.has(proxyId));
|
|
2071
2088
|
await this.transports.get(proxyId).stream.push(payload);
|
|
2072
2089
|
}
|
|
2073
2090
|
async close({ proxyId }) {
|
|
@@ -2075,23 +2092,25 @@ var WebRTCTransportService = class {
|
|
|
2075
2092
|
await ((_a2 = this.transports.get(proxyId)) == null ? void 0 : _a2.transport.destroy());
|
|
2076
2093
|
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
2077
2094
|
this.transports.delete(proxyId);
|
|
2078
|
-
(0, import_log11.log)("Closed.",
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2095
|
+
(0, import_log11.log)("Closed.", void 0, {
|
|
2096
|
+
F: __dxlog_file9,
|
|
2097
|
+
L: 109,
|
|
2098
|
+
S: this,
|
|
2099
|
+
C: (f, a) => f(...a)
|
|
2083
2100
|
});
|
|
2084
2101
|
}
|
|
2085
2102
|
};
|
|
2086
2103
|
|
|
2087
2104
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2088
|
-
var
|
|
2105
|
+
var import_tiny_invariant12 = __toESM(require("tiny-invariant"));
|
|
2089
2106
|
var import_async9 = require("@dxos/async");
|
|
2090
2107
|
var import_context5 = require("@dxos/context");
|
|
2091
2108
|
var import_debug6 = require("@dxos/debug");
|
|
2092
2109
|
var import_keys11 = require("@dxos/keys");
|
|
2093
2110
|
var import_log12 = require("@dxos/log");
|
|
2094
2111
|
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
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";
|
|
2095
2114
|
var WebRTCTransportProxy = class {
|
|
2096
2115
|
// prettier-ignore
|
|
2097
2116
|
constructor(_params) {
|
|
@@ -2109,10 +2128,10 @@ var WebRTCTransportProxy = class {
|
|
|
2109
2128
|
this._serviceStream.waitUntilReady().then(() => {
|
|
2110
2129
|
this._serviceStream.subscribe(async (event) => {
|
|
2111
2130
|
(0, import_log12.log)("WebRTCTransportProxy: event", event, {
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2131
|
+
F: __dxlog_file10,
|
|
2132
|
+
L: 50,
|
|
2133
|
+
S: this,
|
|
2134
|
+
C: (f, a) => f(...a)
|
|
2116
2135
|
});
|
|
2117
2136
|
if (event.connection) {
|
|
2118
2137
|
await this._handleConnection(event.connection);
|
|
@@ -2129,11 +2148,11 @@ var WebRTCTransportProxy = class {
|
|
|
2129
2148
|
payload: data
|
|
2130
2149
|
});
|
|
2131
2150
|
} catch (err) {
|
|
2132
|
-
import_log12.log.catch(err,
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2151
|
+
import_log12.log.catch(err, void 0, {
|
|
2152
|
+
F: __dxlog_file10,
|
|
2153
|
+
L: 67,
|
|
2154
|
+
S: this,
|
|
2155
|
+
C: (f, a) => f(...a)
|
|
2137
2156
|
});
|
|
2138
2157
|
}
|
|
2139
2158
|
};
|
|
@@ -2141,11 +2160,11 @@ var WebRTCTransportProxy = class {
|
|
|
2141
2160
|
this._ctx.onDispose(() => {
|
|
2142
2161
|
this._params.stream.off("data", dataListener);
|
|
2143
2162
|
});
|
|
2144
|
-
}, (error) => import_log12.log.catch(error,
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
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)
|
|
2149
2168
|
}));
|
|
2150
2169
|
}
|
|
2151
2170
|
async _handleConnection(connectionEvent) {
|
|
@@ -2164,7 +2183,7 @@ var WebRTCTransportProxy = class {
|
|
|
2164
2183
|
}
|
|
2165
2184
|
}
|
|
2166
2185
|
_handleData(dataEvent) {
|
|
2167
|
-
this._params.stream.write(
|
|
2186
|
+
this._params.stream.write((0, import_util8.arrayToBuffer)(dataEvent.payload));
|
|
2168
2187
|
}
|
|
2169
2188
|
async _handleSignal(signalEvent) {
|
|
2170
2189
|
await this._params.sendSignal(signalEvent.payload);
|
|
@@ -2187,11 +2206,11 @@ var WebRTCTransportProxy = class {
|
|
|
2187
2206
|
proxyId: this._proxyId
|
|
2188
2207
|
});
|
|
2189
2208
|
} catch (err) {
|
|
2190
|
-
import_log12.log.catch(err,
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2209
|
+
import_log12.log.catch(err, void 0, {
|
|
2210
|
+
F: __dxlog_file10,
|
|
2211
|
+
L: 124,
|
|
2212
|
+
S: this,
|
|
2213
|
+
C: (f, a) => f(...a)
|
|
2195
2214
|
});
|
|
2196
2215
|
}
|
|
2197
2216
|
this.closed.emit();
|
|
@@ -2223,7 +2242,7 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2223
2242
|
return this;
|
|
2224
2243
|
}
|
|
2225
2244
|
createTransport(options) {
|
|
2226
|
-
(0,
|
|
2245
|
+
(0, import_tiny_invariant12.default)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections");
|
|
2227
2246
|
const transport = new WebRTCTransportProxy({
|
|
2228
2247
|
...options,
|
|
2229
2248
|
bridgeService: this._bridgeService
|
|
@@ -2239,7 +2258,7 @@ var import_async10 = require("@dxos/async");
|
|
|
2239
2258
|
var import_keys12 = require("@dxos/keys");
|
|
2240
2259
|
var import_log13 = require("@dxos/log");
|
|
2241
2260
|
var import_teleport2 = require("@dxos/teleport");
|
|
2242
|
-
var
|
|
2261
|
+
var import_util9 = require("@dxos/util");
|
|
2243
2262
|
|
|
2244
2263
|
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
2245
2264
|
var import_teleport = require("@dxos/teleport");
|
|
@@ -2260,20 +2279,21 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
2260
2279
|
};
|
|
2261
2280
|
|
|
2262
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";
|
|
2263
2283
|
var TestWireProtocol = class {
|
|
2264
2284
|
constructor(peerId) {
|
|
2265
2285
|
this.peerId = peerId;
|
|
2266
|
-
this.connections = new
|
|
2286
|
+
this.connections = new import_util9.ComplexMap(import_keys12.PublicKey.hash);
|
|
2267
2287
|
this.connected = new import_async10.Event();
|
|
2268
2288
|
this.disconnected = new import_async10.Event();
|
|
2269
2289
|
this.factory = createTeleportProtocolFactory(async (teleport) => {
|
|
2270
2290
|
(0, import_log13.log)("create", {
|
|
2271
2291
|
remotePeerId: teleport.remotePeerId
|
|
2272
2292
|
}, {
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2293
|
+
F: __dxlog_file11,
|
|
2294
|
+
L: 21,
|
|
2295
|
+
S: this,
|
|
2296
|
+
C: (f, a) => f(...a)
|
|
2277
2297
|
});
|
|
2278
2298
|
const extension = new import_teleport2.TestExtension({
|
|
2279
2299
|
onClose: async () => {
|
|
@@ -2293,10 +2313,10 @@ var TestWireProtocol = class {
|
|
|
2293
2313
|
(0, import_log13.log)("waitForConnection", {
|
|
2294
2314
|
peerId
|
|
2295
2315
|
}, {
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2316
|
+
F: __dxlog_file11,
|
|
2317
|
+
L: 37,
|
|
2318
|
+
S: this,
|
|
2319
|
+
C: (f, a) => f(...a)
|
|
2300
2320
|
});
|
|
2301
2321
|
await (0, import_async10.asyncTimeout)(
|
|
2302
2322
|
this.connected.waitFor((connectedId) => connectedId.equals(peerId)),
|
|
@@ -2338,7 +2358,7 @@ var TestPeer = class {
|
|
|
2338
2358
|
constructor(testBuilder, peerId) {
|
|
2339
2359
|
this.testBuilder = testBuilder;
|
|
2340
2360
|
this.peerId = peerId;
|
|
2341
|
-
this._swarms = new
|
|
2361
|
+
this._swarms = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
|
|
2342
2362
|
this._signalManager = this.testBuilder.createSignalManager();
|
|
2343
2363
|
this._networkManager = this.createNetworkManager();
|
|
2344
2364
|
}
|