@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
package/dist/lib/node/index.cjs
CHANGED
|
@@ -59,7 +59,7 @@ var import_keys6 = require("@dxos/keys");
|
|
|
59
59
|
var import_util4 = require("@dxos/util");
|
|
60
60
|
|
|
61
61
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
62
|
-
var
|
|
62
|
+
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
63
63
|
var import_async = require("@dxos/async");
|
|
64
64
|
var import_context = require("@dxos/context");
|
|
65
65
|
var import_debug = require("@dxos/debug");
|
|
@@ -67,7 +67,7 @@ var import_errors = require("@dxos/errors");
|
|
|
67
67
|
var import_keys = require("@dxos/keys");
|
|
68
68
|
var import_log = require("@dxos/log");
|
|
69
69
|
var import_protocols = require("@dxos/protocols");
|
|
70
|
-
|
|
70
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
71
71
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
72
72
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
73
73
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -76,7 +76,8 @@ var __decorate = function(decorators, target, key, desc) {
|
|
|
76
76
|
if (d = decorators[i])
|
|
77
77
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
78
78
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
79
|
-
}
|
|
79
|
+
}
|
|
80
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
|
|
80
81
|
var STARTING_SIGNALLING_DELAY = 10;
|
|
81
82
|
var MAX_SIGNALLING_DELAY = 300;
|
|
82
83
|
var ConnectionState;
|
|
@@ -149,29 +150,29 @@ var Connection = class {
|
|
|
149
150
|
*/
|
|
150
151
|
// TODO(burdon): Make async?
|
|
151
152
|
openConnection() {
|
|
152
|
-
(0,
|
|
153
|
+
(0, import_tiny_invariant.default)(this._state === ConnectionState.INITIAL, "Invalid state.");
|
|
153
154
|
import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.begin({
|
|
154
155
|
id: this._instanceId
|
|
155
156
|
}), {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
F: __dxlog_file,
|
|
158
|
+
L: 115,
|
|
159
|
+
S: this,
|
|
160
|
+
C: (f, a) => f(...a)
|
|
160
161
|
});
|
|
161
162
|
this._changeState(ConnectionState.CONNECTING);
|
|
162
163
|
this._protocol.initialize().catch((err) => {
|
|
163
164
|
this.errors.raise(err);
|
|
164
165
|
});
|
|
165
166
|
this._protocol.stream.on("close", () => {
|
|
166
|
-
(0, import_log.log)("protocol stream closed",
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
(0, import_log.log)("protocol stream closed", void 0, {
|
|
168
|
+
F: __dxlog_file,
|
|
169
|
+
L: 126,
|
|
170
|
+
S: this,
|
|
171
|
+
C: (f, a) => f(...a)
|
|
171
172
|
});
|
|
172
173
|
this.close().catch((err) => this.errors.raise(err));
|
|
173
174
|
});
|
|
174
|
-
(0,
|
|
175
|
+
(0, import_tiny_invariant.default)(!this._transport);
|
|
175
176
|
this._transport = this._transportFactory.createTransport({
|
|
176
177
|
initiator: this.initiator,
|
|
177
178
|
stream: this._protocol.stream,
|
|
@@ -196,10 +197,10 @@ var Connection = class {
|
|
|
196
197
|
import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.end({
|
|
197
198
|
id: this._instanceId
|
|
198
199
|
}), {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
F: __dxlog_file,
|
|
201
|
+
L: 159,
|
|
202
|
+
S: this,
|
|
203
|
+
C: (f, a) => f(...a)
|
|
203
204
|
});
|
|
204
205
|
}
|
|
205
206
|
async close() {
|
|
@@ -212,38 +213,38 @@ var Connection = class {
|
|
|
212
213
|
(0, import_log.log)("closing...", {
|
|
213
214
|
peerId: this.ownId
|
|
214
215
|
}, {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
F: __dxlog_file,
|
|
217
|
+
L: 171,
|
|
218
|
+
S: this,
|
|
219
|
+
C: (f, a) => f(...a)
|
|
219
220
|
});
|
|
220
221
|
try {
|
|
221
222
|
await this._protocol.destroy();
|
|
222
223
|
} catch (err) {
|
|
223
|
-
import_log.log.catch(err,
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
import_log.log.catch(err, void 0, {
|
|
225
|
+
F: __dxlog_file,
|
|
226
|
+
L: 177,
|
|
227
|
+
S: this,
|
|
228
|
+
C: (f, a) => f(...a)
|
|
228
229
|
});
|
|
229
230
|
}
|
|
230
231
|
try {
|
|
231
232
|
await ((_a = this._transport) == null ? void 0 : _a.destroy());
|
|
232
|
-
} catch (
|
|
233
|
-
import_log.log.catch(
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
233
|
+
} catch (err) {
|
|
234
|
+
import_log.log.catch(err, void 0, {
|
|
235
|
+
F: __dxlog_file,
|
|
236
|
+
L: 184,
|
|
237
|
+
S: this,
|
|
238
|
+
C: (f, a) => f(...a)
|
|
238
239
|
});
|
|
239
240
|
}
|
|
240
241
|
(0, import_log.log)("closed", {
|
|
241
242
|
peerId: this.ownId
|
|
242
243
|
}, {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
F: __dxlog_file,
|
|
245
|
+
L: 187,
|
|
246
|
+
S: this,
|
|
247
|
+
C: (f, a) => f(...a)
|
|
247
248
|
});
|
|
248
249
|
this._changeState(ConnectionState.CLOSED);
|
|
249
250
|
}
|
|
@@ -280,10 +281,10 @@ var Connection = class {
|
|
|
280
281
|
import_log.log.warn("Signal failed", {
|
|
281
282
|
err
|
|
282
283
|
}, {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
284
|
+
F: __dxlog_file,
|
|
285
|
+
L: 221,
|
|
286
|
+
S: this,
|
|
287
|
+
C: (f, a) => f(...a)
|
|
287
288
|
});
|
|
288
289
|
await this.close();
|
|
289
290
|
}
|
|
@@ -293,19 +294,19 @@ var Connection = class {
|
|
|
293
294
|
*/
|
|
294
295
|
async signal(msg) {
|
|
295
296
|
var _a, _b, _c;
|
|
296
|
-
(0,
|
|
297
|
+
(0, import_tiny_invariant.default)(msg.sessionId);
|
|
297
298
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
298
|
-
(0, import_log.log)("dropping signal for incorrect session id",
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
299
|
+
(0, import_log.log)("dropping signal for incorrect session id", void 0, {
|
|
300
|
+
F: __dxlog_file,
|
|
301
|
+
L: 232,
|
|
302
|
+
S: this,
|
|
303
|
+
C: (f, a) => f(...a)
|
|
303
304
|
});
|
|
304
305
|
return;
|
|
305
306
|
}
|
|
306
|
-
(0,
|
|
307
|
-
(0,
|
|
308
|
-
(0,
|
|
307
|
+
(0, import_tiny_invariant.default)(msg.data.signal || msg.data.signalBatch);
|
|
308
|
+
(0, import_tiny_invariant.default)((_a = msg.author) == null ? void 0 : _a.equals(this.remoteId));
|
|
309
|
+
(0, import_tiny_invariant.default)((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId));
|
|
309
310
|
const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
|
|
310
311
|
msg.data.signal
|
|
311
312
|
];
|
|
@@ -319,23 +320,23 @@ var Connection = class {
|
|
|
319
320
|
remoteId: this.remoteId,
|
|
320
321
|
msg: msg.data
|
|
321
322
|
}, {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
323
|
+
F: __dxlog_file,
|
|
324
|
+
L: 246,
|
|
325
|
+
S: this,
|
|
326
|
+
C: (f, a) => f(...a)
|
|
326
327
|
});
|
|
327
328
|
this._incomingSignalBuffer.push(signal);
|
|
328
329
|
} else {
|
|
329
|
-
(0,
|
|
330
|
+
(0, import_tiny_invariant.default)(this._transport, "Connection not ready to accept signals.");
|
|
330
331
|
(0, import_log.log)("received signal", {
|
|
331
332
|
peerId: this.ownId,
|
|
332
333
|
remoteId: this.remoteId,
|
|
333
334
|
msg: msg.data
|
|
334
335
|
}, {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
336
|
+
F: __dxlog_file,
|
|
337
|
+
L: 250,
|
|
338
|
+
S: this,
|
|
339
|
+
C: (f, a) => f(...a)
|
|
339
340
|
});
|
|
340
341
|
await this._transport.signal(signal);
|
|
341
342
|
}
|
|
@@ -347,22 +348,22 @@ var Connection = class {
|
|
|
347
348
|
too: state,
|
|
348
349
|
peerId: this.ownId
|
|
349
350
|
}, {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
351
|
+
F: __dxlog_file,
|
|
352
|
+
L: 257,
|
|
353
|
+
S: this,
|
|
354
|
+
C: (f, a) => f(...a)
|
|
354
355
|
});
|
|
355
|
-
(0,
|
|
356
|
+
(0, import_tiny_invariant.default)(state !== this._state, "Already in this state.");
|
|
356
357
|
this._state = state;
|
|
357
358
|
this.stateChanged.emit(state);
|
|
358
359
|
}
|
|
359
360
|
};
|
|
360
|
-
|
|
361
|
+
_ts_decorate([
|
|
361
362
|
import_async.synchronized
|
|
362
363
|
], Connection.prototype, "close", null);
|
|
363
364
|
|
|
364
365
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
365
|
-
var
|
|
366
|
+
var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
|
|
366
367
|
var import_async3 = require("@dxos/async");
|
|
367
368
|
var import_context4 = require("@dxos/context");
|
|
368
369
|
var import_debug2 = require("@dxos/debug");
|
|
@@ -372,12 +373,14 @@ var import_protocols3 = require("@dxos/protocols");
|
|
|
372
373
|
var import_util2 = require("@dxos/util");
|
|
373
374
|
|
|
374
375
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
375
|
-
var
|
|
376
|
+
var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
|
|
376
377
|
var import_context2 = require("@dxos/context");
|
|
377
378
|
var import_keys2 = require("@dxos/keys");
|
|
378
379
|
var import_log2 = require("@dxos/log");
|
|
379
380
|
var import_protocols2 = require("@dxos/protocols");
|
|
380
381
|
var import_util = require("@dxos/util");
|
|
382
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
383
|
+
var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
381
384
|
var SwarmMessenger = class {
|
|
382
385
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
383
386
|
this._ctx = new import_context2.Context();
|
|
@@ -392,7 +395,7 @@ var SwarmMessenger = class {
|
|
|
392
395
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
393
396
|
return;
|
|
394
397
|
}
|
|
395
|
-
const message =
|
|
398
|
+
const message = SwarmMessage.decode(payload.value);
|
|
396
399
|
if (!this._topic.equals(message.topic)) {
|
|
397
400
|
return;
|
|
398
401
|
}
|
|
@@ -401,10 +404,10 @@ var SwarmMessenger = class {
|
|
|
401
404
|
to: recipient,
|
|
402
405
|
msg: message
|
|
403
406
|
}, {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
407
|
+
F: __dxlog_file2,
|
|
408
|
+
L: 70,
|
|
409
|
+
S: this,
|
|
410
|
+
C: (f, a) => f(...a)
|
|
408
411
|
});
|
|
409
412
|
if ((_a = message.data) == null ? void 0 : _a.offer) {
|
|
410
413
|
await this._handleOffer({
|
|
@@ -430,16 +433,16 @@ var SwarmMessenger = class {
|
|
|
430
433
|
import_log2.log.warn("unknown message", {
|
|
431
434
|
message
|
|
432
435
|
}, {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
436
|
+
F: __dxlog_file2,
|
|
437
|
+
L: 81,
|
|
438
|
+
S: this,
|
|
439
|
+
C: (f, a) => f(...a)
|
|
437
440
|
});
|
|
438
441
|
}
|
|
439
442
|
}
|
|
440
443
|
async signal(message) {
|
|
441
444
|
var _a, _b;
|
|
442
|
-
(0,
|
|
445
|
+
(0, import_tiny_invariant2.default)(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message");
|
|
443
446
|
await this._sendReliableMessage({
|
|
444
447
|
author: message.author,
|
|
445
448
|
recipient: message.recipient,
|
|
@@ -474,40 +477,40 @@ var SwarmMessenger = class {
|
|
|
474
477
|
to: recipient,
|
|
475
478
|
msg: networkMessage
|
|
476
479
|
}, {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
480
|
+
F: __dxlog_file2,
|
|
481
|
+
L: 124,
|
|
482
|
+
S: this,
|
|
483
|
+
C: (f, a) => f(...a)
|
|
481
484
|
});
|
|
482
485
|
await this._sendMessage({
|
|
483
486
|
author,
|
|
484
487
|
recipient,
|
|
485
488
|
payload: {
|
|
486
489
|
type_url: "dxos.mesh.swarm.SwarmMessage",
|
|
487
|
-
value:
|
|
490
|
+
value: SwarmMessage.encode(networkMessage)
|
|
488
491
|
}
|
|
489
492
|
});
|
|
490
493
|
}
|
|
491
494
|
async _resolveAnswers(message) {
|
|
492
495
|
var _a, _b, _c;
|
|
493
|
-
(0,
|
|
496
|
+
(0, import_tiny_invariant2.default)((_b = (_a = message.data) == null ? void 0 : _a.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId");
|
|
494
497
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
495
498
|
if (offerRecord) {
|
|
496
499
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
497
|
-
(0,
|
|
500
|
+
(0, import_tiny_invariant2.default)((_c = message.data) == null ? void 0 : _c.answer, "No answer");
|
|
498
501
|
(0, import_log2.log)("resolving", {
|
|
499
502
|
answer: message.data.answer
|
|
500
503
|
}, {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
504
|
+
F: __dxlog_file2,
|
|
505
|
+
L: 141,
|
|
506
|
+
S: this,
|
|
507
|
+
C: (f, a) => f(...a)
|
|
505
508
|
});
|
|
506
509
|
offerRecord.resolve(message.data.answer);
|
|
507
510
|
}
|
|
508
511
|
}
|
|
509
512
|
async _handleOffer({ author, recipient, message }) {
|
|
510
|
-
(0,
|
|
513
|
+
(0, import_tiny_invariant2.default)(message.data.offer, "No offer");
|
|
511
514
|
const offerMessage = {
|
|
512
515
|
author,
|
|
513
516
|
recipient,
|
|
@@ -534,16 +537,16 @@ var SwarmMessenger = class {
|
|
|
534
537
|
import_log2.log.warn("error sending answer", {
|
|
535
538
|
err
|
|
536
539
|
}, {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
540
|
+
F: __dxlog_file2,
|
|
541
|
+
L: 175,
|
|
542
|
+
S: this,
|
|
543
|
+
C: (f, a) => f(...a)
|
|
541
544
|
});
|
|
542
545
|
}
|
|
543
546
|
}
|
|
544
547
|
async _handleSignal({ author, recipient, message }) {
|
|
545
|
-
(0,
|
|
546
|
-
(0,
|
|
548
|
+
(0, import_tiny_invariant2.default)(message.messageId);
|
|
549
|
+
(0, import_tiny_invariant2.default)(message.data.signal || message.data.signalBatch, "Invalid message");
|
|
547
550
|
const signalMessage = {
|
|
548
551
|
author,
|
|
549
552
|
recipient,
|
|
@@ -558,12 +561,12 @@ var SwarmMessenger = class {
|
|
|
558
561
|
};
|
|
559
562
|
|
|
560
563
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
561
|
-
var
|
|
564
|
+
var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
|
|
562
565
|
var import_async2 = require("@dxos/async");
|
|
563
566
|
var import_context3 = require("@dxos/context");
|
|
564
567
|
var import_keys3 = require("@dxos/keys");
|
|
565
568
|
var import_log3 = require("@dxos/log");
|
|
566
|
-
|
|
569
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
567
570
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
568
571
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
569
572
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -572,7 +575,8 @@ var __decorate2 = function(decorators, target, key, desc) {
|
|
|
572
575
|
if (d = decorators[i])
|
|
573
576
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
574
577
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
575
|
-
}
|
|
578
|
+
}
|
|
579
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
576
580
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
577
581
|
var Peer = class {
|
|
578
582
|
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _callbacks) {
|
|
@@ -601,10 +605,10 @@ var Peer = class {
|
|
|
601
605
|
topic: this.topic,
|
|
602
606
|
peerId: this.localPeerId
|
|
603
607
|
}, {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
+
F: __dxlog_file3,
|
|
609
|
+
L: 105,
|
|
610
|
+
S: this,
|
|
611
|
+
C: (f, a) => f(...a)
|
|
608
612
|
});
|
|
609
613
|
if (this.connection) {
|
|
610
614
|
await this.closeConnection();
|
|
@@ -617,7 +621,7 @@ var Peer = class {
|
|
|
617
621
|
}
|
|
618
622
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
619
623
|
if (!this.connection) {
|
|
620
|
-
(0,
|
|
624
|
+
(0, import_tiny_invariant3.default)(message.sessionId);
|
|
621
625
|
const connection = this._createConnection(false, message.sessionId);
|
|
622
626
|
try {
|
|
623
627
|
connection.openConnection();
|
|
@@ -628,10 +632,10 @@ var Peer = class {
|
|
|
628
632
|
remoteId: this.id,
|
|
629
633
|
err
|
|
630
634
|
}, {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
+
F: __dxlog_file3,
|
|
636
|
+
L: 129,
|
|
637
|
+
S: this,
|
|
638
|
+
C: (f, a) => f(...a)
|
|
635
639
|
});
|
|
636
640
|
await this.closeConnection();
|
|
637
641
|
}
|
|
@@ -648,8 +652,8 @@ var Peer = class {
|
|
|
648
652
|
* Initiate a connection to the remote peer.
|
|
649
653
|
*/
|
|
650
654
|
async initiateConnection() {
|
|
651
|
-
(0,
|
|
652
|
-
(0,
|
|
655
|
+
(0, import_tiny_invariant3.default)(!this.initiating, "Initiation in progress.");
|
|
656
|
+
(0, import_tiny_invariant3.default)(!this.connection, "Already connected.");
|
|
653
657
|
const sessionId = import_keys3.PublicKey.random();
|
|
654
658
|
(0, import_log3.log)("initiating...", {
|
|
655
659
|
id: this.id,
|
|
@@ -657,10 +661,10 @@ var Peer = class {
|
|
|
657
661
|
peerId: this.id,
|
|
658
662
|
sessionId
|
|
659
663
|
}, {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
+
F: __dxlog_file3,
|
|
665
|
+
L: 147,
|
|
666
|
+
S: this,
|
|
667
|
+
C: (f, a) => f(...a)
|
|
664
668
|
});
|
|
665
669
|
const connection = this._createConnection(true, sessionId);
|
|
666
670
|
this.initiating = true;
|
|
@@ -680,17 +684,17 @@ var Peer = class {
|
|
|
680
684
|
ownId: this.localPeerId,
|
|
681
685
|
remoteId: this.id
|
|
682
686
|
}, {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
+
F: __dxlog_file3,
|
|
688
|
+
L: 159,
|
|
689
|
+
S: this,
|
|
690
|
+
C: (f, a) => f(...a)
|
|
687
691
|
});
|
|
688
692
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
689
|
-
(0, import_log3.log)("ignoring response",
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
693
|
+
(0, import_log3.log)("ignoring response", void 0, {
|
|
694
|
+
F: __dxlog_file3,
|
|
695
|
+
L: 161,
|
|
696
|
+
S: this,
|
|
697
|
+
C: (f, a) => f(...a)
|
|
694
698
|
});
|
|
695
699
|
return;
|
|
696
700
|
}
|
|
@@ -707,10 +711,10 @@ var Peer = class {
|
|
|
707
711
|
peerId: this.localPeerId,
|
|
708
712
|
remoteId: this.id
|
|
709
713
|
}, {
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
+
F: __dxlog_file3,
|
|
715
|
+
L: 172,
|
|
716
|
+
S: this,
|
|
717
|
+
C: (f, a) => f(...a)
|
|
714
718
|
});
|
|
715
719
|
await this.closeConnection();
|
|
716
720
|
throw err;
|
|
@@ -731,12 +735,12 @@ var Peer = class {
|
|
|
731
735
|
initiator,
|
|
732
736
|
sessionId
|
|
733
737
|
}, {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
+
F: __dxlog_file3,
|
|
739
|
+
L: 186,
|
|
740
|
+
S: this,
|
|
741
|
+
C: (f, a) => f(...a)
|
|
738
742
|
});
|
|
739
|
-
(0,
|
|
743
|
+
(0, import_tiny_invariant3.default)(!this.connection, "Already connected.");
|
|
740
744
|
const connection = new Connection(
|
|
741
745
|
this.topic,
|
|
742
746
|
this.localPeerId,
|
|
@@ -771,12 +775,12 @@ var Peer = class {
|
|
|
771
775
|
remoteId: this.id,
|
|
772
776
|
initiator
|
|
773
777
|
}, {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
+
F: __dxlog_file3,
|
|
779
|
+
L: 221,
|
|
780
|
+
S: this,
|
|
781
|
+
C: (f, a) => f(...a)
|
|
778
782
|
});
|
|
779
|
-
(0,
|
|
783
|
+
(0, import_tiny_invariant3.default)(this.connection === connection, "Connection mismatch (race condition).");
|
|
780
784
|
if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
|
|
781
785
|
this._availableAfter = 0;
|
|
782
786
|
} else {
|
|
@@ -801,10 +805,10 @@ var Peer = class {
|
|
|
801
805
|
initiator,
|
|
802
806
|
err
|
|
803
807
|
}, {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
+
F: __dxlog_file3,
|
|
809
|
+
L: 249,
|
|
810
|
+
S: this,
|
|
811
|
+
C: (f, a) => f(...a)
|
|
808
812
|
});
|
|
809
813
|
void this.closeConnection();
|
|
810
814
|
});
|
|
@@ -820,20 +824,20 @@ var Peer = class {
|
|
|
820
824
|
peerId: this.id,
|
|
821
825
|
sessionId: connection.sessionId
|
|
822
826
|
}, {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
+
F: __dxlog_file3,
|
|
828
|
+
L: 265,
|
|
829
|
+
S: this,
|
|
830
|
+
C: (f, a) => f(...a)
|
|
827
831
|
});
|
|
828
832
|
await connection.close();
|
|
829
833
|
(0, import_log3.log)("closed", {
|
|
830
834
|
peerId: this.id,
|
|
831
835
|
sessionId: connection.sessionId
|
|
832
836
|
}, {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
+
F: __dxlog_file3,
|
|
838
|
+
L: 271,
|
|
839
|
+
S: this,
|
|
840
|
+
C: (f, a) => f(...a)
|
|
837
841
|
});
|
|
838
842
|
}
|
|
839
843
|
async onSignal(message) {
|
|
@@ -841,10 +845,10 @@ var Peer = class {
|
|
|
841
845
|
(0, import_log3.log)("dropping signal message for non-existent connection", {
|
|
842
846
|
message
|
|
843
847
|
}, {
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
+
F: __dxlog_file3,
|
|
849
|
+
L: 276,
|
|
850
|
+
S: this,
|
|
851
|
+
C: (f, a) => f(...a)
|
|
848
852
|
});
|
|
849
853
|
return;
|
|
850
854
|
}
|
|
@@ -857,15 +861,15 @@ var Peer = class {
|
|
|
857
861
|
peerId: this.id,
|
|
858
862
|
topic: this.topic
|
|
859
863
|
}, {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
+
F: __dxlog_file3,
|
|
865
|
+
L: 285,
|
|
866
|
+
S: this,
|
|
867
|
+
C: (f, a) => f(...a)
|
|
864
868
|
});
|
|
865
869
|
await ((_a = this == null ? void 0 : this.connection) == null ? void 0 : _a.close());
|
|
866
870
|
}
|
|
867
871
|
};
|
|
868
|
-
|
|
872
|
+
_ts_decorate2([
|
|
869
873
|
import_async2.synchronized
|
|
870
874
|
], Peer.prototype, "destroy", null);
|
|
871
875
|
var increaseInterval = (interval) => {
|
|
@@ -882,7 +886,7 @@ var increaseInterval = (interval) => {
|
|
|
882
886
|
};
|
|
883
887
|
|
|
884
888
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
885
|
-
|
|
889
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
886
890
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
887
891
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
888
892
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -891,7 +895,8 @@ var __decorate3 = function(decorators, target, key, desc) {
|
|
|
891
895
|
if (d = decorators[i])
|
|
892
896
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
893
897
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
894
|
-
}
|
|
898
|
+
}
|
|
899
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
895
900
|
var INITIATION_DELAY = 100;
|
|
896
901
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
897
902
|
var Swarm = class {
|
|
@@ -908,11 +913,11 @@ var Swarm = class {
|
|
|
908
913
|
this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
|
|
909
914
|
this._ctx = new import_context4.Context();
|
|
910
915
|
this._listeningHandle = void 0;
|
|
916
|
+
this._instanceId = import_keys4.PublicKey.random().toHex();
|
|
911
917
|
this.connectionAdded = new import_async3.Event();
|
|
912
918
|
this.disconnected = new import_async3.Event();
|
|
913
919
|
this.connected = new import_async3.Event();
|
|
914
920
|
this.errors = new import_debug2.ErrorStream();
|
|
915
|
-
this._instanceId = import_keys4.PublicKey.random().toHex();
|
|
916
921
|
import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.begin({
|
|
917
922
|
id: this._instanceId,
|
|
918
923
|
data: {
|
|
@@ -920,18 +925,18 @@ var Swarm = class {
|
|
|
920
925
|
peerId: this._ownPeerId.toHex()
|
|
921
926
|
}
|
|
922
927
|
}), {
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
928
|
+
F: __dxlog_file4,
|
|
929
|
+
L: 86,
|
|
930
|
+
S: this,
|
|
931
|
+
C: (f, a) => f(...a)
|
|
927
932
|
});
|
|
928
933
|
(0, import_log4.log)("creating swarm", {
|
|
929
934
|
peerId: _ownPeerId
|
|
930
935
|
}, {
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
936
|
+
F: __dxlog_file4,
|
|
937
|
+
L: 90,
|
|
938
|
+
S: this,
|
|
939
|
+
C: (f, a) => f(...a)
|
|
935
940
|
});
|
|
936
941
|
_topology.init(this._getSwarmController());
|
|
937
942
|
this._swarmMessenger = new SwarmMessenger({
|
|
@@ -943,10 +948,10 @@ var Swarm = class {
|
|
|
943
948
|
import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.end({
|
|
944
949
|
id: this._instanceId
|
|
945
950
|
}), {
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
951
|
+
F: __dxlog_file4,
|
|
952
|
+
L: 99,
|
|
953
|
+
S: this,
|
|
954
|
+
C: (f, a) => f(...a)
|
|
950
955
|
});
|
|
951
956
|
}
|
|
952
957
|
get connections() {
|
|
@@ -965,7 +970,7 @@ var Swarm = class {
|
|
|
965
970
|
return this._topic;
|
|
966
971
|
}
|
|
967
972
|
async open() {
|
|
968
|
-
(0,
|
|
973
|
+
(0, import_tiny_invariant4.default)(!this._listeningHandle);
|
|
969
974
|
this._listeningHandle = await this._messenger.listen({
|
|
970
975
|
peerId: this._ownPeerId,
|
|
971
976
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
@@ -973,36 +978,36 @@ var Swarm = class {
|
|
|
973
978
|
await this._swarmMessenger.receiveMessage(message).catch((err) => import_log4.log.warn("Error while receiving message", {
|
|
974
979
|
err
|
|
975
980
|
}, {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
981
|
+
F: __dxlog_file4,
|
|
982
|
+
L: 133,
|
|
983
|
+
S: this,
|
|
984
|
+
C: (f, a) => f(...a)
|
|
980
985
|
}));
|
|
981
986
|
}
|
|
982
987
|
});
|
|
983
988
|
}
|
|
984
989
|
async destroy() {
|
|
985
990
|
var _a;
|
|
986
|
-
(0, import_log4.log)("destroying...",
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
+
(0, import_log4.log)("destroying...", void 0, {
|
|
992
|
+
F: __dxlog_file4,
|
|
993
|
+
L: 139,
|
|
994
|
+
S: this,
|
|
995
|
+
C: (f, a) => f(...a)
|
|
991
996
|
});
|
|
992
997
|
await ((_a = this._listeningHandle) == null ? void 0 : _a.unsubscribe());
|
|
993
998
|
this._listeningHandle = void 0;
|
|
994
999
|
await this._ctx.dispose();
|
|
995
1000
|
await this._topology.destroy();
|
|
996
1001
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
997
|
-
(0, import_log4.log)("destroyed",
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
+
(0, import_log4.log)("destroyed", void 0, {
|
|
1003
|
+
F: __dxlog_file4,
|
|
1004
|
+
L: 146,
|
|
1005
|
+
S: this,
|
|
1006
|
+
C: (f, a) => f(...a)
|
|
1002
1007
|
});
|
|
1003
1008
|
}
|
|
1004
1009
|
async setTopology(topology) {
|
|
1005
|
-
(0,
|
|
1010
|
+
(0, import_tiny_invariant4.default)(!this._ctx.disposed, "Swarm is offline");
|
|
1006
1011
|
if (topology === this._topology) {
|
|
1007
1012
|
return;
|
|
1008
1013
|
}
|
|
@@ -1010,10 +1015,10 @@ var Swarm = class {
|
|
|
1010
1015
|
previous: getClassName(this._topology),
|
|
1011
1016
|
topology: getClassName(topology)
|
|
1012
1017
|
}, {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1018
|
+
F: __dxlog_file4,
|
|
1019
|
+
L: 154,
|
|
1020
|
+
S: this,
|
|
1021
|
+
C: (f, a) => f(...a)
|
|
1017
1022
|
});
|
|
1018
1023
|
await this._topology.destroy();
|
|
1019
1024
|
this._topology = topology;
|
|
@@ -1025,17 +1030,17 @@ var Swarm = class {
|
|
|
1025
1030
|
(0, import_log4.log)("swarm event", {
|
|
1026
1031
|
swarmEvent
|
|
1027
1032
|
}, {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1033
|
+
F: __dxlog_file4,
|
|
1034
|
+
L: 167,
|
|
1035
|
+
S: this,
|
|
1036
|
+
C: (f, a) => f(...a)
|
|
1032
1037
|
});
|
|
1033
1038
|
if (this._ctx.disposed) {
|
|
1034
|
-
(0, import_log4.log)("swarm event ignored for disposed swarm",
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
+
(0, import_log4.log)("swarm event ignored for disposed swarm", void 0, {
|
|
1040
|
+
F: __dxlog_file4,
|
|
1041
|
+
L: 170,
|
|
1042
|
+
S: this,
|
|
1043
|
+
C: (f, a) => f(...a)
|
|
1039
1044
|
});
|
|
1040
1045
|
return;
|
|
1041
1046
|
}
|
|
@@ -1044,25 +1049,25 @@ var Swarm = class {
|
|
|
1044
1049
|
(0, import_log4.log)("new peer", {
|
|
1045
1050
|
peerId
|
|
1046
1051
|
}, {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1052
|
+
F: __dxlog_file4,
|
|
1053
|
+
L: 176,
|
|
1054
|
+
S: this,
|
|
1055
|
+
C: (f, a) => f(...a)
|
|
1051
1056
|
});
|
|
1052
1057
|
if (!peerId.equals(this._ownPeerId)) {
|
|
1053
1058
|
const peer = this._getOrCreatePeer(peerId);
|
|
1054
1059
|
peer.advertizing = true;
|
|
1055
1060
|
}
|
|
1056
1061
|
} else if (swarmEvent.peerLeft) {
|
|
1057
|
-
const
|
|
1058
|
-
if (
|
|
1059
|
-
|
|
1060
|
-
if (((_a =
|
|
1061
|
-
void this._destroyPeer(
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1062
|
+
const peer = this._peers.get(import_keys4.PublicKey.from(swarmEvent.peerLeft.peer));
|
|
1063
|
+
if (peer) {
|
|
1064
|
+
peer.advertizing = false;
|
|
1065
|
+
if (((_a = peer.connection) == null ? void 0 : _a.state) !== ConnectionState.CONNECTED) {
|
|
1066
|
+
void this._destroyPeer(peer.id).catch((err) => import_log4.log.catch(err, void 0, {
|
|
1067
|
+
F: __dxlog_file4,
|
|
1068
|
+
L: 187,
|
|
1069
|
+
S: this,
|
|
1070
|
+
C: (f, a) => f(...a)
|
|
1066
1071
|
}));
|
|
1067
1072
|
}
|
|
1068
1073
|
}
|
|
@@ -1074,31 +1079,31 @@ var Swarm = class {
|
|
|
1074
1079
|
(0, import_log4.log)("offer", {
|
|
1075
1080
|
message
|
|
1076
1081
|
}, {
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1082
|
+
F: __dxlog_file4,
|
|
1083
|
+
L: 197,
|
|
1084
|
+
S: this,
|
|
1085
|
+
C: (f, a) => f(...a)
|
|
1081
1086
|
});
|
|
1082
1087
|
if (this._ctx.disposed) {
|
|
1083
|
-
(0, import_log4.log)("ignored for disposed swarm",
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
+
(0, import_log4.log)("ignored for disposed swarm", void 0, {
|
|
1089
|
+
F: __dxlog_file4,
|
|
1090
|
+
L: 199,
|
|
1091
|
+
S: this,
|
|
1092
|
+
C: (f, a) => f(...a)
|
|
1088
1093
|
});
|
|
1089
1094
|
return {
|
|
1090
1095
|
accept: false
|
|
1091
1096
|
};
|
|
1092
1097
|
}
|
|
1093
|
-
(0,
|
|
1098
|
+
(0, import_tiny_invariant4.default)(message.author);
|
|
1094
1099
|
if (!((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId))) {
|
|
1095
1100
|
(0, import_log4.log)("rejecting offer with incorrect peerId", {
|
|
1096
1101
|
message
|
|
1097
1102
|
}, {
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1103
|
+
F: __dxlog_file4,
|
|
1104
|
+
L: 206,
|
|
1105
|
+
S: this,
|
|
1106
|
+
C: (f, a) => f(...a)
|
|
1102
1107
|
});
|
|
1103
1108
|
return {
|
|
1104
1109
|
accept: false
|
|
@@ -1108,10 +1113,10 @@ var Swarm = class {
|
|
|
1108
1113
|
(0, import_log4.log)("rejecting offer with incorrect topic", {
|
|
1109
1114
|
message
|
|
1110
1115
|
}, {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1116
|
+
F: __dxlog_file4,
|
|
1117
|
+
L: 210,
|
|
1118
|
+
S: this,
|
|
1119
|
+
C: (f, a) => f(...a)
|
|
1115
1120
|
});
|
|
1116
1121
|
return {
|
|
1117
1122
|
accept: false
|
|
@@ -1127,23 +1132,23 @@ var Swarm = class {
|
|
|
1127
1132
|
(0, import_log4.log)("signal", {
|
|
1128
1133
|
message
|
|
1129
1134
|
}, {
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1135
|
+
F: __dxlog_file4,
|
|
1136
|
+
L: 222,
|
|
1137
|
+
S: this,
|
|
1138
|
+
C: (f, a) => f(...a)
|
|
1134
1139
|
});
|
|
1135
1140
|
if (this._ctx.disposed) {
|
|
1136
|
-
import_log4.log.info("ignored for offline swarm",
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
+
import_log4.log.info("ignored for offline swarm", void 0, {
|
|
1142
|
+
F: __dxlog_file4,
|
|
1143
|
+
L: 224,
|
|
1144
|
+
S: this,
|
|
1145
|
+
C: (f, a) => f(...a)
|
|
1141
1146
|
});
|
|
1142
1147
|
return;
|
|
1143
1148
|
}
|
|
1144
|
-
(0,
|
|
1145
|
-
(0,
|
|
1146
|
-
(0,
|
|
1149
|
+
(0, import_tiny_invariant4.default)((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`);
|
|
1150
|
+
(0, import_tiny_invariant4.default)((_b = message.topic) == null ? void 0 : _b.equals(this._topic));
|
|
1151
|
+
(0, import_tiny_invariant4.default)(message.author);
|
|
1147
1152
|
const peer = this._getOrCreatePeer(message.author);
|
|
1148
1153
|
await peer.onSignal(message);
|
|
1149
1154
|
}
|
|
@@ -1195,7 +1200,7 @@ var Swarm = class {
|
|
|
1195
1200
|
return peer;
|
|
1196
1201
|
}
|
|
1197
1202
|
async _destroyPeer(peerId) {
|
|
1198
|
-
(0,
|
|
1203
|
+
(0, import_tiny_invariant4.default)(this._peers.has(peerId));
|
|
1199
1204
|
await this._peers.get(peerId).destroy();
|
|
1200
1205
|
this._peers.delete(peerId);
|
|
1201
1206
|
}
|
|
@@ -1215,10 +1220,10 @@ var Swarm = class {
|
|
|
1215
1220
|
await this._initiateConnection(peer);
|
|
1216
1221
|
} catch (err) {
|
|
1217
1222
|
(0, import_log4.log)("initiation error", err, {
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1223
|
+
F: __dxlog_file4,
|
|
1224
|
+
L: 327,
|
|
1225
|
+
S: this,
|
|
1226
|
+
C: (f, a) => f(...a)
|
|
1222
1227
|
});
|
|
1223
1228
|
}
|
|
1224
1229
|
});
|
|
@@ -1243,10 +1248,10 @@ var Swarm = class {
|
|
|
1243
1248
|
(0, import_log4.log)("initiation delay", {
|
|
1244
1249
|
remoteId
|
|
1245
1250
|
}, {
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1251
|
+
F: __dxlog_file4,
|
|
1252
|
+
L: 354,
|
|
1253
|
+
S: this,
|
|
1254
|
+
C: (f, a) => f(...a)
|
|
1250
1255
|
});
|
|
1251
1256
|
await (0, import_async3.sleep)(INITIATION_DELAY);
|
|
1252
1257
|
}
|
|
@@ -1260,20 +1265,20 @@ var Swarm = class {
|
|
|
1260
1265
|
(0, import_log4.log)("initiating connection...", {
|
|
1261
1266
|
remoteId
|
|
1262
1267
|
}, {
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1268
|
+
F: __dxlog_file4,
|
|
1269
|
+
L: 368,
|
|
1270
|
+
S: this,
|
|
1271
|
+
C: (f, a) => f(...a)
|
|
1267
1272
|
});
|
|
1268
1273
|
await peer.initiateConnection();
|
|
1269
1274
|
this._topology.update();
|
|
1270
1275
|
(0, import_log4.log)("initiated", {
|
|
1271
1276
|
remoteId
|
|
1272
1277
|
}, {
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1278
|
+
F: __dxlog_file4,
|
|
1279
|
+
L: 371,
|
|
1280
|
+
S: this,
|
|
1281
|
+
C: (f, a) => f(...a)
|
|
1277
1282
|
});
|
|
1278
1283
|
}
|
|
1279
1284
|
async _closeConnection(peerId) {
|
|
@@ -1284,28 +1289,28 @@ var Swarm = class {
|
|
|
1284
1289
|
await peer.closeConnection();
|
|
1285
1290
|
}
|
|
1286
1291
|
};
|
|
1287
|
-
|
|
1292
|
+
_ts_decorate3([
|
|
1288
1293
|
import_log4.logInfo
|
|
1289
1294
|
], Swarm.prototype, "_instanceId", void 0);
|
|
1290
|
-
|
|
1295
|
+
_ts_decorate3([
|
|
1291
1296
|
import_log4.logInfo
|
|
1292
1297
|
], Swarm.prototype, "ownPeerId", null);
|
|
1293
|
-
|
|
1298
|
+
_ts_decorate3([
|
|
1294
1299
|
import_log4.logInfo
|
|
1295
1300
|
], Swarm.prototype, "topic", null);
|
|
1296
|
-
|
|
1301
|
+
_ts_decorate3([
|
|
1297
1302
|
import_async3.synchronized
|
|
1298
1303
|
], Swarm.prototype, "onSwarmEvent", null);
|
|
1299
|
-
|
|
1304
|
+
_ts_decorate3([
|
|
1300
1305
|
import_async3.synchronized
|
|
1301
1306
|
], Swarm.prototype, "onOffer", null);
|
|
1302
|
-
|
|
1307
|
+
_ts_decorate3([
|
|
1303
1308
|
import_async3.synchronized
|
|
1304
1309
|
], Swarm.prototype, "onSignal", null);
|
|
1305
|
-
|
|
1310
|
+
_ts_decorate3([
|
|
1306
1311
|
import_async3.synchronized
|
|
1307
1312
|
], Swarm.prototype, "goOffline", null);
|
|
1308
|
-
|
|
1313
|
+
_ts_decorate3([
|
|
1309
1314
|
import_async3.synchronized
|
|
1310
1315
|
], Swarm.prototype, "goOnline", null);
|
|
1311
1316
|
|
|
@@ -1314,6 +1319,7 @@ var import_async4 = require("@dxos/async");
|
|
|
1314
1319
|
var import_keys5 = require("@dxos/keys");
|
|
1315
1320
|
var import_log5 = require("@dxos/log");
|
|
1316
1321
|
var import_util3 = require("@dxos/util");
|
|
1322
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
1317
1323
|
var SwarmMapper = class {
|
|
1318
1324
|
get peers() {
|
|
1319
1325
|
return Array.from(this._peers.values());
|
|
@@ -1340,11 +1346,11 @@ var SwarmMapper = class {
|
|
|
1340
1346
|
this._update();
|
|
1341
1347
|
}
|
|
1342
1348
|
_update() {
|
|
1343
|
-
(0, import_log5.log)("updating swarm",
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1349
|
+
(0, import_log5.log)("updating swarm", void 0, {
|
|
1350
|
+
F: __dxlog_file5,
|
|
1351
|
+
L: 75,
|
|
1352
|
+
S: this,
|
|
1353
|
+
C: (f, a) => f(...a)
|
|
1348
1354
|
});
|
|
1349
1355
|
this._peers.clear();
|
|
1350
1356
|
this._peers.set(this._swarm.ownPeerId, {
|
|
@@ -1365,10 +1371,10 @@ var SwarmMapper = class {
|
|
|
1365
1371
|
directConnections: this._swarm.connections.length,
|
|
1366
1372
|
totalPeersInSwarm: this._peers.size
|
|
1367
1373
|
}, {
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1374
|
+
F: __dxlog_file5,
|
|
1375
|
+
L: 116,
|
|
1376
|
+
S: this,
|
|
1377
|
+
C: (f, a) => f(...a)
|
|
1372
1378
|
});
|
|
1373
1379
|
this.mapUpdated.emit(Array.from(this._peers.values()));
|
|
1374
1380
|
}
|
|
@@ -1414,6 +1420,7 @@ var ConnectionLog = class {
|
|
|
1414
1420
|
this._swarms.set(import_keys6.PublicKey.from(swarm._instanceId), info);
|
|
1415
1421
|
this.update.emit();
|
|
1416
1422
|
swarm.connectionAdded.on((connection) => {
|
|
1423
|
+
var _a, _b;
|
|
1417
1424
|
const connectionInfo = {
|
|
1418
1425
|
state: ConnectionState.INITIAL,
|
|
1419
1426
|
remotePeerId: connection.remoteId,
|
|
@@ -1432,6 +1439,10 @@ var ConnectionLog = class {
|
|
|
1432
1439
|
});
|
|
1433
1440
|
this.update.emit();
|
|
1434
1441
|
});
|
|
1442
|
+
(_b = (_a = connection.protocol) == null ? void 0 : _a.stats) == null ? void 0 : _b.on((stats) => {
|
|
1443
|
+
connectionInfo.streams = stats;
|
|
1444
|
+
this.update.emit();
|
|
1445
|
+
});
|
|
1435
1446
|
});
|
|
1436
1447
|
}
|
|
1437
1448
|
leftSwarm(swarm) {
|
|
@@ -1441,7 +1452,7 @@ var ConnectionLog = class {
|
|
|
1441
1452
|
};
|
|
1442
1453
|
|
|
1443
1454
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
1444
|
-
var
|
|
1455
|
+
var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
|
|
1445
1456
|
var import_async6 = require("@dxos/async");
|
|
1446
1457
|
var import_keys7 = require("@dxos/keys");
|
|
1447
1458
|
var import_log6 = require("@dxos/log");
|
|
@@ -1449,8 +1460,9 @@ var import_messaging = require("@dxos/messaging");
|
|
|
1449
1460
|
var import_protocols4 = require("@dxos/protocols");
|
|
1450
1461
|
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
1451
1462
|
var import_util5 = require("@dxos/util");
|
|
1463
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
1452
1464
|
var NetworkManager = class {
|
|
1453
|
-
constructor({ transportFactory, signalManager, log:
|
|
1465
|
+
constructor({ transportFactory, signalManager, log: log1 }) {
|
|
1454
1466
|
this._swarms = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
|
|
1455
1467
|
this._mappers = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
|
|
1456
1468
|
this._connectionState = import_services.ConnectionState.ONLINE;
|
|
@@ -1470,7 +1482,7 @@ var NetworkManager = class {
|
|
|
1470
1482
|
join: (opts) => this._signalManager.join(opts),
|
|
1471
1483
|
leave: (opts) => this._signalManager.leave(opts)
|
|
1472
1484
|
};
|
|
1473
|
-
if (
|
|
1485
|
+
if (log1) {
|
|
1474
1486
|
this._connectionLog = new ConnectionLog();
|
|
1475
1487
|
}
|
|
1476
1488
|
}
|
|
@@ -1495,30 +1507,30 @@ var NetworkManager = class {
|
|
|
1495
1507
|
import_log6.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.begin({
|
|
1496
1508
|
id: this._instanceId
|
|
1497
1509
|
}), {
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1510
|
+
F: __dxlog_file6,
|
|
1511
|
+
L: 127,
|
|
1512
|
+
S: this,
|
|
1513
|
+
C: (f, a) => f(...a)
|
|
1502
1514
|
});
|
|
1503
1515
|
await this._messenger.open();
|
|
1504
1516
|
await this._signalManager.open();
|
|
1505
1517
|
import_log6.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.end({
|
|
1506
1518
|
id: this._instanceId
|
|
1507
1519
|
}), {
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1520
|
+
F: __dxlog_file6,
|
|
1521
|
+
L: 130,
|
|
1522
|
+
S: this,
|
|
1523
|
+
C: (f, a) => f(...a)
|
|
1512
1524
|
});
|
|
1513
1525
|
}
|
|
1514
1526
|
async close() {
|
|
1515
1527
|
for (const topic of this._swarms.keys()) {
|
|
1516
1528
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1517
|
-
(0, import_log6.log)(err,
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1529
|
+
(0, import_log6.log)(err, void 0, {
|
|
1530
|
+
F: __dxlog_file6,
|
|
1531
|
+
L: 136,
|
|
1532
|
+
S: this,
|
|
1533
|
+
C: (f, a) => f(...a)
|
|
1522
1534
|
});
|
|
1523
1535
|
});
|
|
1524
1536
|
}
|
|
@@ -1530,10 +1542,10 @@ var NetworkManager = class {
|
|
|
1530
1542
|
*/
|
|
1531
1543
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1532
1544
|
var _a;
|
|
1533
|
-
(0,
|
|
1534
|
-
(0,
|
|
1535
|
-
(0,
|
|
1536
|
-
(0,
|
|
1545
|
+
(0, import_tiny_invariant5.default)(import_keys7.PublicKey.isPublicKey(topic));
|
|
1546
|
+
(0, import_tiny_invariant5.default)(import_keys7.PublicKey.isPublicKey(peerId));
|
|
1547
|
+
(0, import_tiny_invariant5.default)(topology);
|
|
1548
|
+
(0, import_tiny_invariant5.default)(typeof protocol === "function");
|
|
1537
1549
|
if (this._swarms.has(topic)) {
|
|
1538
1550
|
throw new Error(`Already connected to swarm: ${import_keys7.PublicKey.from(topic)}`);
|
|
1539
1551
|
}
|
|
@@ -1542,20 +1554,20 @@ var NetworkManager = class {
|
|
|
1542
1554
|
peerId,
|
|
1543
1555
|
topology: topology.toString()
|
|
1544
1556
|
}, {
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1557
|
+
F: __dxlog_file6,
|
|
1558
|
+
L: 162,
|
|
1559
|
+
S: this,
|
|
1560
|
+
C: (f, a) => f(...a)
|
|
1549
1561
|
});
|
|
1550
1562
|
const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label);
|
|
1551
1563
|
swarm.errors.handle((error) => {
|
|
1552
1564
|
(0, import_log6.log)("swarm error", {
|
|
1553
1565
|
error
|
|
1554
1566
|
}, {
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1567
|
+
F: __dxlog_file6,
|
|
1568
|
+
L: 165,
|
|
1569
|
+
S: this,
|
|
1570
|
+
C: (f, a) => f(...a)
|
|
1559
1571
|
});
|
|
1560
1572
|
});
|
|
1561
1573
|
this._swarms.set(topic, swarm);
|
|
@@ -1564,11 +1576,11 @@ var NetworkManager = class {
|
|
|
1564
1576
|
this._signalConnection.join({
|
|
1565
1577
|
topic,
|
|
1566
1578
|
peerId
|
|
1567
|
-
}).catch((error) => import_log6.log.catch(error,
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1579
|
+
}).catch((error) => import_log6.log.catch(error, void 0, {
|
|
1580
|
+
F: __dxlog_file6,
|
|
1581
|
+
L: 174,
|
|
1582
|
+
S: this,
|
|
1583
|
+
C: (f, a) => f(...a)
|
|
1572
1584
|
}));
|
|
1573
1585
|
this.topicsUpdated.emit();
|
|
1574
1586
|
(_a = this._connectionLog) == null ? void 0 : _a.joinedSwarm(swarm);
|
|
@@ -1576,10 +1588,10 @@ var NetworkManager = class {
|
|
|
1576
1588
|
topic: import_keys7.PublicKey.from(topic),
|
|
1577
1589
|
count: this._swarms.size
|
|
1578
1590
|
}, {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1591
|
+
F: __dxlog_file6,
|
|
1592
|
+
L: 178,
|
|
1593
|
+
S: this,
|
|
1594
|
+
C: (f, a) => f(...a)
|
|
1583
1595
|
});
|
|
1584
1596
|
return {
|
|
1585
1597
|
close: () => this.leaveSwarm(topic)
|
|
@@ -1596,10 +1608,10 @@ var NetworkManager = class {
|
|
|
1596
1608
|
(0, import_log6.log)("leaving", {
|
|
1597
1609
|
topic: import_keys7.PublicKey.from(topic)
|
|
1598
1610
|
}, {
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1611
|
+
F: __dxlog_file6,
|
|
1612
|
+
L: 194,
|
|
1613
|
+
S: this,
|
|
1614
|
+
C: (f, a) => f(...a)
|
|
1603
1615
|
});
|
|
1604
1616
|
const swarm = this._swarms.get(topic);
|
|
1605
1617
|
await this._signalConnection.leave({
|
|
@@ -1617,10 +1629,10 @@ var NetworkManager = class {
|
|
|
1617
1629
|
topic: import_keys7.PublicKey.from(topic),
|
|
1618
1630
|
count: this._swarms.size
|
|
1619
1631
|
}, {
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1632
|
+
F: __dxlog_file6,
|
|
1633
|
+
L: 208,
|
|
1634
|
+
S: this,
|
|
1635
|
+
C: (f, a) => f(...a)
|
|
1624
1636
|
});
|
|
1625
1637
|
}
|
|
1626
1638
|
async setConnectionState(state) {
|
|
@@ -1652,17 +1664,17 @@ var NetworkManager = class {
|
|
|
1652
1664
|
};
|
|
1653
1665
|
|
|
1654
1666
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1655
|
-
var
|
|
1667
|
+
var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
|
|
1656
1668
|
var FullyConnectedTopology = class {
|
|
1657
1669
|
toString() {
|
|
1658
1670
|
return "FullyConnectedTopology";
|
|
1659
1671
|
}
|
|
1660
1672
|
init(controller) {
|
|
1661
|
-
(0,
|
|
1673
|
+
(0, import_tiny_invariant6.default)(!this._controller, "Already initialized");
|
|
1662
1674
|
this._controller = controller;
|
|
1663
1675
|
}
|
|
1664
1676
|
update() {
|
|
1665
|
-
(0,
|
|
1677
|
+
(0, import_tiny_invariant6.default)(this._controller, "Not initialized");
|
|
1666
1678
|
const { candidates: discovered } = this._controller.getState();
|
|
1667
1679
|
for (const peer of discovered) {
|
|
1668
1680
|
this._controller.connect(peer);
|
|
@@ -1676,9 +1688,10 @@ var FullyConnectedTopology = class {
|
|
|
1676
1688
|
};
|
|
1677
1689
|
|
|
1678
1690
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1679
|
-
var
|
|
1691
|
+
var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
|
|
1680
1692
|
var import_xor_distance = __toESM(require("xor-distance"));
|
|
1681
1693
|
var import_log7 = require("@dxos/log");
|
|
1694
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
1682
1695
|
var MMSTTopology = class {
|
|
1683
1696
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
1684
1697
|
this._sampleCollected = false;
|
|
@@ -1687,62 +1700,62 @@ var MMSTTopology = class {
|
|
|
1687
1700
|
this._sampleSize = sampleSize;
|
|
1688
1701
|
}
|
|
1689
1702
|
init(controller) {
|
|
1690
|
-
(0,
|
|
1703
|
+
(0, import_tiny_invariant7.default)(!this._controller, "Already initialized");
|
|
1691
1704
|
this._controller = controller;
|
|
1692
1705
|
}
|
|
1693
1706
|
update() {
|
|
1694
|
-
(0,
|
|
1707
|
+
(0, import_tiny_invariant7.default)(this._controller, "Not initialized");
|
|
1695
1708
|
const { connected, candidates } = this._controller.getState();
|
|
1696
1709
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
1697
|
-
(0, import_log7.log)("Running the algorithm.",
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1710
|
+
(0, import_log7.log)("Running the algorithm.", void 0, {
|
|
1711
|
+
F: __dxlog_file7,
|
|
1712
|
+
L: 55,
|
|
1713
|
+
S: this,
|
|
1714
|
+
C: (f, a) => f(...a)
|
|
1702
1715
|
});
|
|
1703
1716
|
this._sampleCollected = true;
|
|
1704
1717
|
this._runAlgorithm();
|
|
1705
1718
|
}
|
|
1706
1719
|
}
|
|
1707
1720
|
async onOffer(peer) {
|
|
1708
|
-
(0,
|
|
1721
|
+
(0, import_tiny_invariant7.default)(this._controller, "Not initialized");
|
|
1709
1722
|
const { connected } = this._controller.getState();
|
|
1710
1723
|
const accept = connected.length < this._maxPeers;
|
|
1711
|
-
(0, import_log7.log)(`Offer ${peer} accept=${accept}`,
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1724
|
+
(0, import_log7.log)(`Offer ${peer} accept=${accept}`, void 0, {
|
|
1725
|
+
F: __dxlog_file7,
|
|
1726
|
+
L: 65,
|
|
1727
|
+
S: this,
|
|
1728
|
+
C: (f, a) => f(...a)
|
|
1716
1729
|
});
|
|
1717
1730
|
return accept;
|
|
1718
1731
|
}
|
|
1719
1732
|
async destroy() {
|
|
1720
1733
|
}
|
|
1721
1734
|
_runAlgorithm() {
|
|
1722
|
-
(0,
|
|
1735
|
+
(0, import_tiny_invariant7.default)(this._controller, "Not initialized");
|
|
1723
1736
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
1724
1737
|
if (connected.length > this._maxPeers) {
|
|
1725
1738
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
1726
1739
|
for (const peer of sorted) {
|
|
1727
|
-
(0, import_log7.log)(`Disconnect ${peer}.`,
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1740
|
+
(0, import_log7.log)(`Disconnect ${peer}.`, void 0, {
|
|
1741
|
+
F: __dxlog_file7,
|
|
1742
|
+
L: 83,
|
|
1743
|
+
S: this,
|
|
1744
|
+
C: (f, a) => f(...a)
|
|
1732
1745
|
});
|
|
1733
1746
|
this._controller.disconnect(peer);
|
|
1734
1747
|
}
|
|
1735
1748
|
} else if (connected.length < this._originateConnections) {
|
|
1736
1749
|
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
1737
|
-
const
|
|
1738
|
-
for (const
|
|
1739
|
-
(0, import_log7.log)(`Connect ${
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1750
|
+
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
1751
|
+
for (const peer of sorted) {
|
|
1752
|
+
(0, import_log7.log)(`Connect ${peer}.`, void 0, {
|
|
1753
|
+
F: __dxlog_file7,
|
|
1754
|
+
L: 91,
|
|
1755
|
+
S: this,
|
|
1756
|
+
C: (f, a) => f(...a)
|
|
1744
1757
|
});
|
|
1745
|
-
this._controller.connect(
|
|
1758
|
+
this._controller.connect(peer);
|
|
1746
1759
|
}
|
|
1747
1760
|
}
|
|
1748
1761
|
}
|
|
@@ -1753,8 +1766,9 @@ var MMSTTopology = class {
|
|
|
1753
1766
|
var sortByXorDistance = (keys, reference) => keys.sort((a, b) => import_xor_distance.default.gt((0, import_xor_distance.default)(a.asBuffer(), reference.asBuffer()), (0, import_xor_distance.default)(b.asBuffer(), reference.asBuffer())));
|
|
1754
1767
|
|
|
1755
1768
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1756
|
-
var
|
|
1769
|
+
var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
|
|
1757
1770
|
var import_log8 = require("@dxos/log");
|
|
1771
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
1758
1772
|
var StarTopology = class {
|
|
1759
1773
|
// prettier-ignore
|
|
1760
1774
|
constructor(_centralPeer) {
|
|
@@ -1764,59 +1778,59 @@ var StarTopology = class {
|
|
|
1764
1778
|
return `StarTopology(${this._centralPeer.truncate()})`;
|
|
1765
1779
|
}
|
|
1766
1780
|
init(controller) {
|
|
1767
|
-
(0,
|
|
1781
|
+
(0, import_tiny_invariant8.default)(!this._controller, "Already initialized.");
|
|
1768
1782
|
this._controller = controller;
|
|
1769
1783
|
}
|
|
1770
1784
|
update() {
|
|
1771
|
-
(0,
|
|
1785
|
+
(0, import_tiny_invariant8.default)(this._controller, "Not initialized.");
|
|
1772
1786
|
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
1773
1787
|
if (!ownPeerId.equals(this._centralPeer)) {
|
|
1774
|
-
(0, import_log8.log)("leaf peer dropping all connections apart from central peer.",
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1788
|
+
(0, import_log8.log)("leaf peer dropping all connections apart from central peer.", void 0, {
|
|
1789
|
+
F: __dxlog_file8,
|
|
1790
|
+
L: 33,
|
|
1791
|
+
S: this,
|
|
1792
|
+
C: (f, a) => f(...a)
|
|
1779
1793
|
});
|
|
1780
1794
|
for (const peer of connected) {
|
|
1781
1795
|
if (!peer.equals(this._centralPeer)) {
|
|
1782
1796
|
(0, import_log8.log)("dropping connection", {
|
|
1783
1797
|
peer
|
|
1784
1798
|
}, {
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1799
|
+
F: __dxlog_file8,
|
|
1800
|
+
L: 38,
|
|
1801
|
+
S: this,
|
|
1802
|
+
C: (f, a) => f(...a)
|
|
1789
1803
|
});
|
|
1790
1804
|
this._controller.disconnect(peer);
|
|
1791
1805
|
}
|
|
1792
1806
|
}
|
|
1793
1807
|
}
|
|
1794
|
-
for (const
|
|
1795
|
-
if (
|
|
1808
|
+
for (const peer of candidates) {
|
|
1809
|
+
if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
|
|
1796
1810
|
(0, import_log8.log)("connecting to peer", {
|
|
1797
|
-
peer
|
|
1811
|
+
peer
|
|
1798
1812
|
}, {
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1813
|
+
F: __dxlog_file8,
|
|
1814
|
+
L: 47,
|
|
1815
|
+
S: this,
|
|
1816
|
+
C: (f, a) => f(...a)
|
|
1803
1817
|
});
|
|
1804
|
-
this._controller.connect(
|
|
1818
|
+
this._controller.connect(peer);
|
|
1805
1819
|
}
|
|
1806
1820
|
}
|
|
1807
1821
|
}
|
|
1808
1822
|
async onOffer(peer) {
|
|
1809
|
-
(0,
|
|
1823
|
+
(0, import_tiny_invariant8.default)(this._controller, "Not initialized.");
|
|
1810
1824
|
const { ownPeerId } = this._controller.getState();
|
|
1811
1825
|
(0, import_log8.log)("offer", {
|
|
1812
1826
|
peer,
|
|
1813
1827
|
isCentral: peer.equals(this._centralPeer),
|
|
1814
1828
|
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
1815
1829
|
}, {
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1830
|
+
F: __dxlog_file8,
|
|
1831
|
+
L: 56,
|
|
1832
|
+
S: this,
|
|
1833
|
+
C: (f, a) => f(...a)
|
|
1820
1834
|
});
|
|
1821
1835
|
return ownPeerId.equals(this._centralPeer) || peer.equals(this._centralPeer);
|
|
1822
1836
|
}
|
|
@@ -1825,14 +1839,14 @@ var StarTopology = class {
|
|
|
1825
1839
|
};
|
|
1826
1840
|
|
|
1827
1841
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1828
|
-
var import_node_assert9 = __toESM(require("node:assert"));
|
|
1829
1842
|
var import_node_stream = require("node:stream");
|
|
1843
|
+
var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
|
|
1830
1844
|
var import_async7 = require("@dxos/async");
|
|
1831
1845
|
var import_debug4 = require("@dxos/debug");
|
|
1832
1846
|
var import_keys8 = require("@dxos/keys");
|
|
1833
1847
|
var import_log9 = require("@dxos/log");
|
|
1834
1848
|
var import_util6 = require("@dxos/util");
|
|
1835
|
-
|
|
1849
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
1836
1850
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1837
1851
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1838
1852
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1841,7 +1855,8 @@ var __decorate4 = function(decorators, target, key, desc) {
|
|
|
1841
1855
|
if (d = decorators[i])
|
|
1842
1856
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1843
1857
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1844
|
-
}
|
|
1858
|
+
}
|
|
1859
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
1845
1860
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1846
1861
|
var createStreamDelay = (delay) => {
|
|
1847
1862
|
return new import_node_stream.Transform({
|
|
@@ -1861,26 +1876,26 @@ var _MemoryTransport = class {
|
|
|
1861
1876
|
this.closed = new import_async7.Event();
|
|
1862
1877
|
this.connected = new import_async7.Event();
|
|
1863
1878
|
this.errors = new import_debug4.ErrorStream();
|
|
1879
|
+
this._instanceId = import_keys8.PublicKey.random();
|
|
1864
1880
|
this._remote = new import_async7.Trigger();
|
|
1865
1881
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1866
1882
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1867
1883
|
this._destroyed = false;
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
callSite: (f, a) => f(...a)
|
|
1884
|
+
(0, import_log9.log)("creating", void 0, {
|
|
1885
|
+
F: __dxlog_file9,
|
|
1886
|
+
L: 64,
|
|
1887
|
+
S: this,
|
|
1888
|
+
C: (f, a) => f(...a)
|
|
1874
1889
|
});
|
|
1875
|
-
(0,
|
|
1890
|
+
(0, import_tiny_invariant9.default)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
|
|
1876
1891
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1877
1892
|
if (this.options.initiator) {
|
|
1878
1893
|
setTimeout(async () => {
|
|
1879
|
-
(0, import_log9.log)("sending signal",
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1894
|
+
(0, import_log9.log)("sending signal", void 0, {
|
|
1895
|
+
F: __dxlog_file9,
|
|
1896
|
+
L: 73,
|
|
1897
|
+
S: this,
|
|
1898
|
+
C: (f, a) => f(...a)
|
|
1884
1899
|
});
|
|
1885
1900
|
void this.options.sendSignal({
|
|
1886
1901
|
payload: {
|
|
@@ -1906,14 +1921,14 @@ var _MemoryTransport = class {
|
|
|
1906
1921
|
this.closed.emit();
|
|
1907
1922
|
return;
|
|
1908
1923
|
}
|
|
1909
|
-
(0,
|
|
1924
|
+
(0, import_tiny_invariant9.default)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`);
|
|
1910
1925
|
this._remoteConnection._remoteConnection = this;
|
|
1911
1926
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1912
|
-
(0, import_log9.log)("connected",
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1927
|
+
(0, import_log9.log)("connected", void 0, {
|
|
1928
|
+
F: __dxlog_file9,
|
|
1929
|
+
L: 103,
|
|
1930
|
+
S: this,
|
|
1931
|
+
C: (f, a) => f(...a)
|
|
1917
1932
|
});
|
|
1918
1933
|
this.options.stream.pipe(this._outgoingDelay).pipe(this._remoteConnection.options.stream).pipe(this._incomingDelay).pipe(this.options.stream);
|
|
1919
1934
|
this.connected.emit();
|
|
@@ -1927,20 +1942,20 @@ var _MemoryTransport = class {
|
|
|
1927
1942
|
}
|
|
1928
1943
|
}
|
|
1929
1944
|
async destroy() {
|
|
1930
|
-
(0, import_log9.log)("closing",
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1945
|
+
(0, import_log9.log)("closing", void 0, {
|
|
1946
|
+
F: __dxlog_file9,
|
|
1947
|
+
L: 124,
|
|
1948
|
+
S: this,
|
|
1949
|
+
C: (f, a) => f(...a)
|
|
1935
1950
|
});
|
|
1936
1951
|
this._destroyed = true;
|
|
1937
1952
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
1938
1953
|
if (this._remoteConnection) {
|
|
1939
|
-
(0, import_log9.log)("closing",
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1954
|
+
(0, import_log9.log)("closing", void 0, {
|
|
1955
|
+
F: __dxlog_file9,
|
|
1956
|
+
L: 129,
|
|
1957
|
+
S: this,
|
|
1958
|
+
C: (f, a) => f(...a)
|
|
1944
1959
|
});
|
|
1945
1960
|
this._remoteConnection._destroyed = true;
|
|
1946
1961
|
_MemoryTransport._connections.delete(this._remoteInstanceId);
|
|
@@ -1949,29 +1964,29 @@ var _MemoryTransport = class {
|
|
|
1949
1964
|
this._remoteConnection.closed.emit();
|
|
1950
1965
|
this._remoteConnection._remoteConnection = void 0;
|
|
1951
1966
|
this._remoteConnection = void 0;
|
|
1952
|
-
(0, import_log9.log)("closed",
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1967
|
+
(0, import_log9.log)("closed", void 0, {
|
|
1968
|
+
F: __dxlog_file9,
|
|
1969
|
+
L: 147,
|
|
1970
|
+
S: this,
|
|
1971
|
+
C: (f, a) => f(...a)
|
|
1957
1972
|
});
|
|
1958
1973
|
}
|
|
1959
1974
|
this.closed.emit();
|
|
1960
|
-
(0, import_log9.log)("closed",
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1975
|
+
(0, import_log9.log)("closed", void 0, {
|
|
1976
|
+
F: __dxlog_file9,
|
|
1977
|
+
L: 151,
|
|
1978
|
+
S: this,
|
|
1979
|
+
C: (f, a) => f(...a)
|
|
1965
1980
|
});
|
|
1966
1981
|
}
|
|
1967
1982
|
signal({ payload }) {
|
|
1968
1983
|
(0, import_log9.log)("received signal", {
|
|
1969
1984
|
payload
|
|
1970
1985
|
}, {
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1986
|
+
F: __dxlog_file9,
|
|
1987
|
+
L: 155,
|
|
1988
|
+
S: this,
|
|
1989
|
+
C: (f, a) => f(...a)
|
|
1975
1990
|
});
|
|
1976
1991
|
if (!(payload == null ? void 0 : payload.transportId)) {
|
|
1977
1992
|
return;
|
|
@@ -1986,16 +2001,16 @@ var _MemoryTransport = class {
|
|
|
1986
2001
|
var MemoryTransport = _MemoryTransport;
|
|
1987
2002
|
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
1988
2003
|
MemoryTransport._connections = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
|
|
1989
|
-
|
|
2004
|
+
_ts_decorate4([
|
|
1990
2005
|
import_log9.logInfo
|
|
1991
2006
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
1992
|
-
|
|
2007
|
+
_ts_decorate4([
|
|
1993
2008
|
import_log9.logInfo
|
|
1994
2009
|
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
1995
2010
|
|
|
1996
2011
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1997
|
-
var import_node_assert10 = __toESM(require("node:assert"));
|
|
1998
2012
|
var import_simple_peer = __toESM(require("simple-peer"));
|
|
2013
|
+
var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
|
|
1999
2014
|
var import_async8 = require("@dxos/async");
|
|
2000
2015
|
var import_debug5 = require("@dxos/debug");
|
|
2001
2016
|
var import_keys9 = require("@dxos/keys");
|
|
@@ -2010,6 +2025,7 @@ try {
|
|
|
2010
2025
|
}
|
|
2011
2026
|
|
|
2012
2027
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
2028
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
|
|
2013
2029
|
var WebRTCTransport = class {
|
|
2014
2030
|
constructor(params) {
|
|
2015
2031
|
var _a;
|
|
@@ -2022,16 +2038,16 @@ var WebRTCTransport = class {
|
|
|
2022
2038
|
import_log10.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
|
|
2023
2039
|
id: this._instanceId
|
|
2024
2040
|
}), {
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2041
|
+
F: __dxlog_file10,
|
|
2042
|
+
L: 39,
|
|
2043
|
+
S: this,
|
|
2044
|
+
C: (f, a) => f(...a)
|
|
2029
2045
|
});
|
|
2030
2046
|
(0, import_log10.log)("created connection", params, {
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2047
|
+
F: __dxlog_file10,
|
|
2048
|
+
L: 40,
|
|
2049
|
+
S: this,
|
|
2050
|
+
C: (f, a) => f(...a)
|
|
2035
2051
|
});
|
|
2036
2052
|
this._peer = new import_simple_peer.default({
|
|
2037
2053
|
initiator: this.params.initiator,
|
|
@@ -2040,10 +2056,10 @@ var WebRTCTransport = class {
|
|
|
2040
2056
|
});
|
|
2041
2057
|
this._peer.on("signal", async (data) => {
|
|
2042
2058
|
(0, import_log10.log)("signal", data, {
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2059
|
+
F: __dxlog_file10,
|
|
2060
|
+
L: 48,
|
|
2061
|
+
S: this,
|
|
2062
|
+
C: (f, a) => f(...a)
|
|
2047
2063
|
});
|
|
2048
2064
|
await this.params.sendSignal({
|
|
2049
2065
|
payload: {
|
|
@@ -2052,21 +2068,21 @@ var WebRTCTransport = class {
|
|
|
2052
2068
|
});
|
|
2053
2069
|
});
|
|
2054
2070
|
this._peer.on("connect", () => {
|
|
2055
|
-
(0, import_log10.log)("connected",
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2071
|
+
(0, import_log10.log)("connected", void 0, {
|
|
2072
|
+
F: __dxlog_file10,
|
|
2073
|
+
L: 53,
|
|
2074
|
+
S: this,
|
|
2075
|
+
C: (f, a) => f(...a)
|
|
2060
2076
|
});
|
|
2061
2077
|
this.params.stream.pipe(this._peer).pipe(this.params.stream);
|
|
2062
2078
|
this.connected.emit();
|
|
2063
2079
|
});
|
|
2064
2080
|
this._peer.on("close", async () => {
|
|
2065
|
-
(0, import_log10.log)("closed",
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2081
|
+
(0, import_log10.log)("closed", void 0, {
|
|
2082
|
+
F: __dxlog_file10,
|
|
2083
|
+
L: 59,
|
|
2084
|
+
S: this,
|
|
2085
|
+
C: (f, a) => f(...a)
|
|
2070
2086
|
});
|
|
2071
2087
|
await this._disconnectStreams();
|
|
2072
2088
|
this.closed.emit();
|
|
@@ -2081,10 +2097,10 @@ var WebRTCTransport = class {
|
|
|
2081
2097
|
config: this.params.webrtcConfig,
|
|
2082
2098
|
stats
|
|
2083
2099
|
}, {
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2100
|
+
F: __dxlog_file10,
|
|
2101
|
+
L: 71,
|
|
2102
|
+
S: this,
|
|
2103
|
+
C: (f, a) => f(...a)
|
|
2088
2104
|
});
|
|
2089
2105
|
});
|
|
2090
2106
|
}
|
|
@@ -2095,35 +2111,35 @@ var WebRTCTransport = class {
|
|
|
2095
2111
|
import_log10.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
|
|
2096
2112
|
id: this._instanceId
|
|
2097
2113
|
}), {
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2114
|
+
F: __dxlog_file10,
|
|
2115
|
+
L: 81,
|
|
2116
|
+
S: this,
|
|
2117
|
+
C: (f, a) => f(...a)
|
|
2102
2118
|
});
|
|
2103
2119
|
}
|
|
2104
2120
|
async destroy() {
|
|
2105
|
-
(0, import_log10.log)("closing...",
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2121
|
+
(0, import_log10.log)("closing...", void 0, {
|
|
2122
|
+
F: __dxlog_file10,
|
|
2123
|
+
L: 85,
|
|
2124
|
+
S: this,
|
|
2125
|
+
C: (f, a) => f(...a)
|
|
2110
2126
|
});
|
|
2111
2127
|
this._closed = true;
|
|
2112
2128
|
await this._disconnectStreams();
|
|
2113
2129
|
this._peer.destroy();
|
|
2114
2130
|
this.closed.emit();
|
|
2115
|
-
(0, import_log10.log)("closed",
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2131
|
+
(0, import_log10.log)("closed", void 0, {
|
|
2132
|
+
F: __dxlog_file10,
|
|
2133
|
+
L: 90,
|
|
2134
|
+
S: this,
|
|
2135
|
+
C: (f, a) => f(...a)
|
|
2120
2136
|
});
|
|
2121
2137
|
}
|
|
2122
2138
|
signal(signal) {
|
|
2123
2139
|
if (this._closed) {
|
|
2124
2140
|
return;
|
|
2125
2141
|
}
|
|
2126
|
-
(0,
|
|
2142
|
+
(0, import_tiny_invariant10.default)(signal.payload.data, "Signal message must contain signal data.");
|
|
2127
2143
|
this._peer.signal(signal.payload.data);
|
|
2128
2144
|
}
|
|
2129
2145
|
async _disconnectStreams() {
|
|
@@ -2139,13 +2155,14 @@ var createWebRTCTransportFactory = (webrtcConfig) => ({
|
|
|
2139
2155
|
});
|
|
2140
2156
|
|
|
2141
2157
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
2142
|
-
var import_node_assert11 = __toESM(require("node:assert"));
|
|
2143
2158
|
var import_node_stream2 = require("node:stream");
|
|
2159
|
+
var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
|
|
2144
2160
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
2145
2161
|
var import_keys10 = require("@dxos/keys");
|
|
2146
2162
|
var import_log11 = require("@dxos/log");
|
|
2147
2163
|
var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2148
2164
|
var import_util7 = require("@dxos/util");
|
|
2165
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
|
|
2149
2166
|
var WebRTCTransportService = class {
|
|
2150
2167
|
// prettier-ignore
|
|
2151
2168
|
constructor(_webrtcConfig) {
|
|
@@ -2216,11 +2233,11 @@ var WebRTCTransportService = class {
|
|
|
2216
2233
|
return rpcStream;
|
|
2217
2234
|
}
|
|
2218
2235
|
async sendSignal({ proxyId, signal }) {
|
|
2219
|
-
(0,
|
|
2236
|
+
(0, import_tiny_invariant11.default)(this.transports.has(proxyId));
|
|
2220
2237
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2221
2238
|
}
|
|
2222
2239
|
async sendData({ proxyId, payload }) {
|
|
2223
|
-
(0,
|
|
2240
|
+
(0, import_tiny_invariant11.default)(this.transports.has(proxyId));
|
|
2224
2241
|
await this.transports.get(proxyId).stream.push(payload);
|
|
2225
2242
|
}
|
|
2226
2243
|
async close({ proxyId }) {
|
|
@@ -2228,23 +2245,25 @@ var WebRTCTransportService = class {
|
|
|
2228
2245
|
await ((_a = this.transports.get(proxyId)) == null ? void 0 : _a.transport.destroy());
|
|
2229
2246
|
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
2230
2247
|
this.transports.delete(proxyId);
|
|
2231
|
-
(0, import_log11.log)("Closed.",
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2248
|
+
(0, import_log11.log)("Closed.", void 0, {
|
|
2249
|
+
F: __dxlog_file11,
|
|
2250
|
+
L: 109,
|
|
2251
|
+
S: this,
|
|
2252
|
+
C: (f, a) => f(...a)
|
|
2236
2253
|
});
|
|
2237
2254
|
}
|
|
2238
2255
|
};
|
|
2239
2256
|
|
|
2240
2257
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2241
|
-
var
|
|
2258
|
+
var import_tiny_invariant12 = __toESM(require("tiny-invariant"));
|
|
2242
2259
|
var import_async9 = require("@dxos/async");
|
|
2243
2260
|
var import_context5 = require("@dxos/context");
|
|
2244
2261
|
var import_debug6 = require("@dxos/debug");
|
|
2245
2262
|
var import_keys11 = require("@dxos/keys");
|
|
2246
2263
|
var import_log12 = require("@dxos/log");
|
|
2247
2264
|
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2265
|
+
var import_util8 = require("@dxos/util");
|
|
2266
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
|
|
2248
2267
|
var WebRTCTransportProxy = class {
|
|
2249
2268
|
// prettier-ignore
|
|
2250
2269
|
constructor(_params) {
|
|
@@ -2262,10 +2281,10 @@ var WebRTCTransportProxy = class {
|
|
|
2262
2281
|
this._serviceStream.waitUntilReady().then(() => {
|
|
2263
2282
|
this._serviceStream.subscribe(async (event) => {
|
|
2264
2283
|
(0, import_log12.log)("WebRTCTransportProxy: event", event, {
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2284
|
+
F: __dxlog_file12,
|
|
2285
|
+
L: 50,
|
|
2286
|
+
S: this,
|
|
2287
|
+
C: (f, a) => f(...a)
|
|
2269
2288
|
});
|
|
2270
2289
|
if (event.connection) {
|
|
2271
2290
|
await this._handleConnection(event.connection);
|
|
@@ -2282,11 +2301,11 @@ var WebRTCTransportProxy = class {
|
|
|
2282
2301
|
payload: data
|
|
2283
2302
|
});
|
|
2284
2303
|
} catch (err) {
|
|
2285
|
-
import_log12.log.catch(err,
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2304
|
+
import_log12.log.catch(err, void 0, {
|
|
2305
|
+
F: __dxlog_file12,
|
|
2306
|
+
L: 67,
|
|
2307
|
+
S: this,
|
|
2308
|
+
C: (f, a) => f(...a)
|
|
2290
2309
|
});
|
|
2291
2310
|
}
|
|
2292
2311
|
};
|
|
@@ -2294,11 +2313,11 @@ var WebRTCTransportProxy = class {
|
|
|
2294
2313
|
this._ctx.onDispose(() => {
|
|
2295
2314
|
this._params.stream.off("data", dataListener);
|
|
2296
2315
|
});
|
|
2297
|
-
}, (error) => import_log12.log.catch(error,
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2316
|
+
}, (error) => import_log12.log.catch(error, void 0, {
|
|
2317
|
+
F: __dxlog_file12,
|
|
2318
|
+
L: 73,
|
|
2319
|
+
S: this,
|
|
2320
|
+
C: (f, a) => f(...a)
|
|
2302
2321
|
}));
|
|
2303
2322
|
}
|
|
2304
2323
|
async _handleConnection(connectionEvent) {
|
|
@@ -2317,7 +2336,7 @@ var WebRTCTransportProxy = class {
|
|
|
2317
2336
|
}
|
|
2318
2337
|
}
|
|
2319
2338
|
_handleData(dataEvent) {
|
|
2320
|
-
this._params.stream.write(
|
|
2339
|
+
this._params.stream.write((0, import_util8.arrayToBuffer)(dataEvent.payload));
|
|
2321
2340
|
}
|
|
2322
2341
|
async _handleSignal(signalEvent) {
|
|
2323
2342
|
await this._params.sendSignal(signalEvent.payload);
|
|
@@ -2340,11 +2359,11 @@ var WebRTCTransportProxy = class {
|
|
|
2340
2359
|
proxyId: this._proxyId
|
|
2341
2360
|
});
|
|
2342
2361
|
} catch (err) {
|
|
2343
|
-
import_log12.log.catch(err,
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2362
|
+
import_log12.log.catch(err, void 0, {
|
|
2363
|
+
F: __dxlog_file12,
|
|
2364
|
+
L: 124,
|
|
2365
|
+
S: this,
|
|
2366
|
+
C: (f, a) => f(...a)
|
|
2348
2367
|
});
|
|
2349
2368
|
}
|
|
2350
2369
|
this.closed.emit();
|
|
@@ -2376,7 +2395,7 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2376
2395
|
return this;
|
|
2377
2396
|
}
|
|
2378
2397
|
createTransport(options) {
|
|
2379
|
-
(0,
|
|
2398
|
+
(0, import_tiny_invariant12.default)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections");
|
|
2380
2399
|
const transport = new WebRTCTransportProxy({
|
|
2381
2400
|
...options,
|
|
2382
2401
|
bridgeService: this._bridgeService
|