@dxos/network-manager 0.1.55 → 0.1.56-main.09ca29d
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-IBLQYMBY.mjs → chunk-FC6CWDES.mjs} +823 -294
- package/dist/lib/browser/chunk-FC6CWDES.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +5 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -2
- package/dist/lib/node/index.cjs +843 -312
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +772 -301
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/network-manager.d.ts +1 -1
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection-limiter.d.ts +28 -0
- package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -0
- package/dist/types/src/swarm/connection-limiter.test.d.ts +2 -0
- package/dist/types/src/swarm/connection-limiter.test.d.ts.map +1 -0
- package/dist/types/src/swarm/connection.d.ts +1 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.test.d.ts +2 -0
- package/dist/types/src/swarm/connection.test.d.ts.map +1 -0
- package/dist/types/src/swarm/index.d.ts +1 -0
- package/dist/types/src/swarm/index.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +3 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +3 -1
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/topology/fully-connected-topology.d.ts.map +1 -1
- package/dist/types/src/topology/star-topology.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/network-manager.ts +19 -6
- package/src/signal/swarm-messenger.ts +1 -2
- package/src/swarm/connection-limiter.test.ts +44 -0
- package/src/swarm/connection-limiter.ts +72 -0
- package/src/swarm/connection.test.ts +72 -0
- package/src/swarm/connection.ts +18 -5
- package/src/swarm/index.ts +1 -0
- package/src/swarm/peer.ts +46 -9
- package/src/swarm/swarm.test.ts +140 -90
- package/src/swarm/swarm.ts +4 -3
- package/src/topology/fully-connected-topology.ts +1 -2
- package/src/topology/mmst-topology.ts +1 -1
- package/src/topology/star-topology.ts +1 -2
- package/src/transport/memory-transport.ts +1 -1
- package/src/transport/webrtc-transport-proxy.ts +14 -12
- package/src/transport/webrtc-transport-service.ts +31 -8
- package/src/transport/webrtc-transport.ts +1 -1
- package/dist/lib/browser/chunk-IBLQYMBY.mjs.map +0 -7
|
@@ -38,35 +38,35 @@ __export(testing_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(testing_exports);
|
|
39
39
|
|
|
40
40
|
// packages/core/mesh/network-manager/src/testing/test-builder.ts
|
|
41
|
-
var
|
|
41
|
+
var import_keys14 = require("@dxos/keys");
|
|
42
42
|
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_util11 = require("@dxos/util");
|
|
47
47
|
|
|
48
48
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
49
|
+
var import_async7 = require("@dxos/async");
|
|
50
|
+
var import_invariant6 = require("@dxos/invariant");
|
|
51
|
+
var import_keys8 = require("@dxos/keys");
|
|
52
|
+
var import_log7 = require("@dxos/log");
|
|
53
53
|
var import_messaging = require("@dxos/messaging");
|
|
54
54
|
var import_protocols4 = require("@dxos/protocols");
|
|
55
55
|
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
56
|
-
var
|
|
56
|
+
var import_util6 = require("@dxos/util");
|
|
57
57
|
|
|
58
58
|
// packages/core/mesh/network-manager/src/connection-log.ts
|
|
59
|
-
var
|
|
59
|
+
var import_async6 = require("@dxos/async");
|
|
60
60
|
var import_debug3 = require("@dxos/debug");
|
|
61
|
-
var
|
|
62
|
-
var
|
|
61
|
+
var import_keys7 = require("@dxos/keys");
|
|
62
|
+
var import_util5 = require("@dxos/util");
|
|
63
63
|
|
|
64
64
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
65
|
-
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
66
65
|
var import_async = require("@dxos/async");
|
|
67
66
|
var import_context = require("@dxos/context");
|
|
68
67
|
var import_debug = require("@dxos/debug");
|
|
69
68
|
var import_errors = require("@dxos/errors");
|
|
69
|
+
var import_invariant = require("@dxos/invariant");
|
|
70
70
|
var import_keys = require("@dxos/keys");
|
|
71
71
|
var import_log = require("@dxos/log");
|
|
72
72
|
var import_protocols = require("@dxos/protocols");
|
|
@@ -80,7 +80,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
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 = "/
|
|
83
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
|
|
84
84
|
var STARTING_SIGNALLING_DELAY = 10;
|
|
85
85
|
var MAX_SIGNALLING_DELAY = 300;
|
|
86
86
|
var ConnectionState;
|
|
@@ -138,6 +138,18 @@ var Connection = class {
|
|
|
138
138
|
await this._flushSignalBuffer();
|
|
139
139
|
});
|
|
140
140
|
this._signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
141
|
+
import_log.log.trace("dxos.mesh.connection.construct", {
|
|
142
|
+
sessionId: this.sessionId,
|
|
143
|
+
topic: this.topic,
|
|
144
|
+
localPeerId: this.ownId,
|
|
145
|
+
remotePeerId: this.remoteId,
|
|
146
|
+
initiator: this.initiator
|
|
147
|
+
}, {
|
|
148
|
+
F: __dxlog_file,
|
|
149
|
+
L: 95,
|
|
150
|
+
S: this,
|
|
151
|
+
C: (f, a) => f(...a)
|
|
152
|
+
});
|
|
141
153
|
}
|
|
142
154
|
get state() {
|
|
143
155
|
return this._state;
|
|
@@ -151,14 +163,33 @@ var Connection = class {
|
|
|
151
163
|
/**
|
|
152
164
|
* Create an underlying transport and prepares it for the connection.
|
|
153
165
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
166
|
+
async openConnection() {
|
|
167
|
+
(0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
|
|
168
|
+
F: __dxlog_file,
|
|
169
|
+
L: 120,
|
|
170
|
+
S: this,
|
|
171
|
+
A: [
|
|
172
|
+
"this._state === ConnectionState.INITIAL",
|
|
173
|
+
"'Invalid state.'"
|
|
174
|
+
]
|
|
175
|
+
});
|
|
157
176
|
import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.begin({
|
|
158
177
|
id: this._instanceId
|
|
159
178
|
}), {
|
|
160
179
|
F: __dxlog_file,
|
|
161
|
-
L:
|
|
180
|
+
L: 121,
|
|
181
|
+
S: this,
|
|
182
|
+
C: (f, a) => f(...a)
|
|
183
|
+
});
|
|
184
|
+
import_log.log.trace("dxos.mesh.connection.open", {
|
|
185
|
+
sessionId: this.sessionId,
|
|
186
|
+
topic: this.topic,
|
|
187
|
+
localPeerId: this.ownId,
|
|
188
|
+
remotePeerId: this.remoteId,
|
|
189
|
+
initiator: this.initiator
|
|
190
|
+
}, {
|
|
191
|
+
F: __dxlog_file,
|
|
192
|
+
L: 122,
|
|
162
193
|
S: this,
|
|
163
194
|
C: (f, a) => f(...a)
|
|
164
195
|
});
|
|
@@ -169,13 +200,21 @@ var Connection = class {
|
|
|
169
200
|
this._protocol.stream.on("close", () => {
|
|
170
201
|
(0, import_log.log)("protocol stream closed", void 0, {
|
|
171
202
|
F: __dxlog_file,
|
|
172
|
-
L:
|
|
203
|
+
L: 139,
|
|
173
204
|
S: this,
|
|
174
205
|
C: (f, a) => f(...a)
|
|
175
206
|
});
|
|
176
207
|
this.close().catch((err) => this.errors.raise(err));
|
|
177
208
|
});
|
|
178
|
-
(0,
|
|
209
|
+
(0, import_invariant.invariant)(!this._transport, void 0, {
|
|
210
|
+
F: __dxlog_file,
|
|
211
|
+
L: 143,
|
|
212
|
+
S: this,
|
|
213
|
+
A: [
|
|
214
|
+
"!this._transport",
|
|
215
|
+
""
|
|
216
|
+
]
|
|
217
|
+
});
|
|
179
218
|
this._transport = this._transportFactory.createTransport({
|
|
180
219
|
initiator: this.initiator,
|
|
181
220
|
stream: this._protocol.stream,
|
|
@@ -201,7 +240,7 @@ var Connection = class {
|
|
|
201
240
|
id: this._instanceId
|
|
202
241
|
}), {
|
|
203
242
|
F: __dxlog_file,
|
|
204
|
-
L:
|
|
243
|
+
L: 172,
|
|
205
244
|
S: this,
|
|
206
245
|
C: (f, a) => f(...a)
|
|
207
246
|
});
|
|
@@ -217,7 +256,7 @@ var Connection = class {
|
|
|
217
256
|
peerId: this.ownId
|
|
218
257
|
}, {
|
|
219
258
|
F: __dxlog_file,
|
|
220
|
-
L:
|
|
259
|
+
L: 184,
|
|
221
260
|
S: this,
|
|
222
261
|
C: (f, a) => f(...a)
|
|
223
262
|
});
|
|
@@ -226,7 +265,7 @@ var Connection = class {
|
|
|
226
265
|
} catch (err) {
|
|
227
266
|
import_log.log.catch(err, void 0, {
|
|
228
267
|
F: __dxlog_file,
|
|
229
|
-
L:
|
|
268
|
+
L: 190,
|
|
230
269
|
S: this,
|
|
231
270
|
C: (f, a) => f(...a)
|
|
232
271
|
});
|
|
@@ -236,7 +275,7 @@ var Connection = class {
|
|
|
236
275
|
} catch (err) {
|
|
237
276
|
import_log.log.catch(err, void 0, {
|
|
238
277
|
F: __dxlog_file,
|
|
239
|
-
L:
|
|
278
|
+
L: 197,
|
|
240
279
|
S: this,
|
|
241
280
|
C: (f, a) => f(...a)
|
|
242
281
|
});
|
|
@@ -245,7 +284,7 @@ var Connection = class {
|
|
|
245
284
|
peerId: this.ownId
|
|
246
285
|
}, {
|
|
247
286
|
F: __dxlog_file,
|
|
248
|
-
L:
|
|
287
|
+
L: 200,
|
|
249
288
|
S: this,
|
|
250
289
|
C: (f, a) => f(...a)
|
|
251
290
|
});
|
|
@@ -285,7 +324,7 @@ var Connection = class {
|
|
|
285
324
|
err
|
|
286
325
|
}, {
|
|
287
326
|
F: __dxlog_file,
|
|
288
|
-
L:
|
|
327
|
+
L: 234,
|
|
289
328
|
S: this,
|
|
290
329
|
C: (f, a) => f(...a)
|
|
291
330
|
});
|
|
@@ -297,19 +336,51 @@ var Connection = class {
|
|
|
297
336
|
*/
|
|
298
337
|
async signal(msg) {
|
|
299
338
|
var _a2, _b, _c;
|
|
300
|
-
(0,
|
|
339
|
+
(0, import_invariant.invariant)(msg.sessionId, void 0, {
|
|
340
|
+
F: __dxlog_file,
|
|
341
|
+
L: 243,
|
|
342
|
+
S: this,
|
|
343
|
+
A: [
|
|
344
|
+
"msg.sessionId",
|
|
345
|
+
""
|
|
346
|
+
]
|
|
347
|
+
});
|
|
301
348
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
302
349
|
(0, import_log.log)("dropping signal for incorrect session id", void 0, {
|
|
303
350
|
F: __dxlog_file,
|
|
304
|
-
L:
|
|
351
|
+
L: 245,
|
|
305
352
|
S: this,
|
|
306
353
|
C: (f, a) => f(...a)
|
|
307
354
|
});
|
|
308
355
|
return;
|
|
309
356
|
}
|
|
310
|
-
(0,
|
|
311
|
-
|
|
312
|
-
|
|
357
|
+
(0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
358
|
+
F: __dxlog_file,
|
|
359
|
+
L: 248,
|
|
360
|
+
S: this,
|
|
361
|
+
A: [
|
|
362
|
+
"msg.data.signal || msg.data.signalBatch",
|
|
363
|
+
""
|
|
364
|
+
]
|
|
365
|
+
});
|
|
366
|
+
(0, import_invariant.invariant)((_a2 = msg.author) == null ? void 0 : _a2.equals(this.remoteId), void 0, {
|
|
367
|
+
F: __dxlog_file,
|
|
368
|
+
L: 249,
|
|
369
|
+
S: this,
|
|
370
|
+
A: [
|
|
371
|
+
"msg.author?.equals(this.remoteId)",
|
|
372
|
+
""
|
|
373
|
+
]
|
|
374
|
+
});
|
|
375
|
+
(0, import_invariant.invariant)((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId), void 0, {
|
|
376
|
+
F: __dxlog_file,
|
|
377
|
+
L: 250,
|
|
378
|
+
S: this,
|
|
379
|
+
A: [
|
|
380
|
+
"msg.recipient?.equals(this.ownId)",
|
|
381
|
+
""
|
|
382
|
+
]
|
|
383
|
+
});
|
|
313
384
|
const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
|
|
314
385
|
msg.data.signal
|
|
315
386
|
];
|
|
@@ -324,20 +395,28 @@ var Connection = class {
|
|
|
324
395
|
msg: msg.data
|
|
325
396
|
}, {
|
|
326
397
|
F: __dxlog_file,
|
|
327
|
-
L:
|
|
398
|
+
L: 259,
|
|
328
399
|
S: this,
|
|
329
400
|
C: (f, a) => f(...a)
|
|
330
401
|
});
|
|
331
402
|
this._incomingSignalBuffer.push(signal);
|
|
332
403
|
} else {
|
|
333
|
-
(0,
|
|
404
|
+
(0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
|
|
405
|
+
F: __dxlog_file,
|
|
406
|
+
L: 262,
|
|
407
|
+
S: this,
|
|
408
|
+
A: [
|
|
409
|
+
"this._transport",
|
|
410
|
+
"'Connection not ready to accept signals.'"
|
|
411
|
+
]
|
|
412
|
+
});
|
|
334
413
|
(0, import_log.log)("received signal", {
|
|
335
414
|
peerId: this.ownId,
|
|
336
415
|
remoteId: this.remoteId,
|
|
337
416
|
msg: msg.data
|
|
338
417
|
}, {
|
|
339
418
|
F: __dxlog_file,
|
|
340
|
-
L:
|
|
419
|
+
L: 263,
|
|
341
420
|
S: this,
|
|
342
421
|
C: (f, a) => f(...a)
|
|
343
422
|
});
|
|
@@ -352,11 +431,19 @@ var Connection = class {
|
|
|
352
431
|
peerId: this.ownId
|
|
353
432
|
}, {
|
|
354
433
|
F: __dxlog_file,
|
|
355
|
-
L:
|
|
434
|
+
L: 270,
|
|
356
435
|
S: this,
|
|
357
436
|
C: (f, a) => f(...a)
|
|
358
437
|
});
|
|
359
|
-
(0,
|
|
438
|
+
(0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
|
|
439
|
+
F: __dxlog_file,
|
|
440
|
+
L: 271,
|
|
441
|
+
S: this,
|
|
442
|
+
A: [
|
|
443
|
+
"state !== this._state",
|
|
444
|
+
"'Already in this state.'"
|
|
445
|
+
]
|
|
446
|
+
});
|
|
360
447
|
this._state = state;
|
|
361
448
|
this.stateChanged.emit(state);
|
|
362
449
|
}
|
|
@@ -366,23 +453,23 @@ _ts_decorate([
|
|
|
366
453
|
], Connection.prototype, "close", null);
|
|
367
454
|
|
|
368
455
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
369
|
-
var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
|
|
370
456
|
var import_async3 = require("@dxos/async");
|
|
371
457
|
var import_context4 = require("@dxos/context");
|
|
372
458
|
var import_debug2 = require("@dxos/debug");
|
|
459
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
373
460
|
var import_keys4 = require("@dxos/keys");
|
|
374
461
|
var import_log4 = require("@dxos/log");
|
|
375
462
|
var import_protocols3 = require("@dxos/protocols");
|
|
376
463
|
var import_util2 = require("@dxos/util");
|
|
377
464
|
|
|
378
465
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
379
|
-
var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
|
|
380
466
|
var import_context2 = require("@dxos/context");
|
|
467
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
381
468
|
var import_keys2 = require("@dxos/keys");
|
|
382
469
|
var import_log2 = require("@dxos/log");
|
|
383
470
|
var import_protocols2 = require("@dxos/protocols");
|
|
384
471
|
var import_util = require("@dxos/util");
|
|
385
|
-
var __dxlog_file2 = "/
|
|
472
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
386
473
|
var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
387
474
|
var SwarmMessenger = class {
|
|
388
475
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
@@ -408,7 +495,7 @@ var SwarmMessenger = class {
|
|
|
408
495
|
msg: message
|
|
409
496
|
}, {
|
|
410
497
|
F: __dxlog_file2,
|
|
411
|
-
L:
|
|
498
|
+
L: 69,
|
|
412
499
|
S: this,
|
|
413
500
|
C: (f, a) => f(...a)
|
|
414
501
|
});
|
|
@@ -437,7 +524,7 @@ var SwarmMessenger = class {
|
|
|
437
524
|
message
|
|
438
525
|
}, {
|
|
439
526
|
F: __dxlog_file2,
|
|
440
|
-
L:
|
|
527
|
+
L: 80,
|
|
441
528
|
S: this,
|
|
442
529
|
C: (f, a) => f(...a)
|
|
443
530
|
});
|
|
@@ -445,7 +532,15 @@ var SwarmMessenger = class {
|
|
|
445
532
|
}
|
|
446
533
|
async signal(message) {
|
|
447
534
|
var _a2, _b;
|
|
448
|
-
(0,
|
|
535
|
+
(0, import_invariant2.invariant)(((_a2 = message.data) == null ? void 0 : _a2.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message", {
|
|
536
|
+
F: __dxlog_file2,
|
|
537
|
+
L: 85,
|
|
538
|
+
S: this,
|
|
539
|
+
A: [
|
|
540
|
+
"message.data?.signal || message.data?.signalBatch",
|
|
541
|
+
"'Invalid message'"
|
|
542
|
+
]
|
|
543
|
+
});
|
|
449
544
|
await this._sendReliableMessage({
|
|
450
545
|
author: message.author,
|
|
451
546
|
recipient: message.recipient,
|
|
@@ -481,7 +576,7 @@ var SwarmMessenger = class {
|
|
|
481
576
|
msg: networkMessage
|
|
482
577
|
}, {
|
|
483
578
|
F: __dxlog_file2,
|
|
484
|
-
L:
|
|
579
|
+
L: 123,
|
|
485
580
|
S: this,
|
|
486
581
|
C: (f, a) => f(...a)
|
|
487
582
|
});
|
|
@@ -496,16 +591,32 @@ var SwarmMessenger = class {
|
|
|
496
591
|
}
|
|
497
592
|
async _resolveAnswers(message) {
|
|
498
593
|
var _a2, _b, _c;
|
|
499
|
-
(0,
|
|
594
|
+
(0, import_invariant2.invariant)((_b = (_a2 = message.data) == null ? void 0 : _a2.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId", {
|
|
595
|
+
F: __dxlog_file2,
|
|
596
|
+
L: 135,
|
|
597
|
+
S: this,
|
|
598
|
+
A: [
|
|
599
|
+
"message.data?.answer?.offerMessageId",
|
|
600
|
+
"'No offerMessageId'"
|
|
601
|
+
]
|
|
602
|
+
});
|
|
500
603
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
501
604
|
if (offerRecord) {
|
|
502
605
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
503
|
-
(0,
|
|
606
|
+
(0, import_invariant2.invariant)((_c = message.data) == null ? void 0 : _c.answer, "No answer", {
|
|
607
|
+
F: __dxlog_file2,
|
|
608
|
+
L: 139,
|
|
609
|
+
S: this,
|
|
610
|
+
A: [
|
|
611
|
+
"message.data?.answer",
|
|
612
|
+
"'No answer'"
|
|
613
|
+
]
|
|
614
|
+
});
|
|
504
615
|
(0, import_log2.log)("resolving", {
|
|
505
616
|
answer: message.data.answer
|
|
506
617
|
}, {
|
|
507
618
|
F: __dxlog_file2,
|
|
508
|
-
L:
|
|
619
|
+
L: 140,
|
|
509
620
|
S: this,
|
|
510
621
|
C: (f, a) => f(...a)
|
|
511
622
|
});
|
|
@@ -513,7 +624,15 @@ var SwarmMessenger = class {
|
|
|
513
624
|
}
|
|
514
625
|
}
|
|
515
626
|
async _handleOffer({ author, recipient, message }) {
|
|
516
|
-
(0,
|
|
627
|
+
(0, import_invariant2.invariant)(message.data.offer, "No offer", {
|
|
628
|
+
F: __dxlog_file2,
|
|
629
|
+
L: 154,
|
|
630
|
+
S: this,
|
|
631
|
+
A: [
|
|
632
|
+
"message.data.offer",
|
|
633
|
+
"'No offer'"
|
|
634
|
+
]
|
|
635
|
+
});
|
|
517
636
|
const offerMessage = {
|
|
518
637
|
author,
|
|
519
638
|
recipient,
|
|
@@ -541,15 +660,31 @@ var SwarmMessenger = class {
|
|
|
541
660
|
err
|
|
542
661
|
}, {
|
|
543
662
|
F: __dxlog_file2,
|
|
544
|
-
L:
|
|
663
|
+
L: 174,
|
|
545
664
|
S: this,
|
|
546
665
|
C: (f, a) => f(...a)
|
|
547
666
|
});
|
|
548
667
|
}
|
|
549
668
|
}
|
|
550
669
|
async _handleSignal({ author, recipient, message }) {
|
|
551
|
-
(0,
|
|
552
|
-
|
|
670
|
+
(0, import_invariant2.invariant)(message.messageId, void 0, {
|
|
671
|
+
F: __dxlog_file2,
|
|
672
|
+
L: 187,
|
|
673
|
+
S: this,
|
|
674
|
+
A: [
|
|
675
|
+
"message.messageId",
|
|
676
|
+
""
|
|
677
|
+
]
|
|
678
|
+
});
|
|
679
|
+
(0, import_invariant2.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
680
|
+
F: __dxlog_file2,
|
|
681
|
+
L: 188,
|
|
682
|
+
S: this,
|
|
683
|
+
A: [
|
|
684
|
+
"message.data.signal || message.data.signalBatch",
|
|
685
|
+
"'Invalid message'"
|
|
686
|
+
]
|
|
687
|
+
});
|
|
553
688
|
const signalMessage = {
|
|
554
689
|
author,
|
|
555
690
|
recipient,
|
|
@@ -564,9 +699,10 @@ var SwarmMessenger = class {
|
|
|
564
699
|
};
|
|
565
700
|
|
|
566
701
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
567
|
-
var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
|
|
568
702
|
var import_async2 = require("@dxos/async");
|
|
569
703
|
var import_context3 = require("@dxos/context");
|
|
704
|
+
var import_errors2 = require("@dxos/errors");
|
|
705
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
570
706
|
var import_keys3 = require("@dxos/keys");
|
|
571
707
|
var import_log3 = require("@dxos/log");
|
|
572
708
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
@@ -579,16 +715,17 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
579
715
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
580
716
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
581
717
|
}
|
|
582
|
-
var __dxlog_file3 = "/
|
|
718
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
583
719
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
584
720
|
var Peer = class {
|
|
585
|
-
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _callbacks) {
|
|
721
|
+
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
586
722
|
this.id = id;
|
|
587
723
|
this.topic = topic;
|
|
588
724
|
this.localPeerId = localPeerId;
|
|
589
725
|
this._signalMessaging = _signalMessaging;
|
|
590
726
|
this._protocolProvider = _protocolProvider;
|
|
591
727
|
this._transportFactory = _transportFactory;
|
|
728
|
+
this._connectionLimiter = _connectionLimiter;
|
|
592
729
|
this._callbacks = _callbacks;
|
|
593
730
|
this._availableAfter = 0;
|
|
594
731
|
this.availableToConnect = true;
|
|
@@ -600,16 +737,18 @@ var Peer = class {
|
|
|
600
737
|
* Respond to remote offer.
|
|
601
738
|
*/
|
|
602
739
|
async onOffer(message) {
|
|
740
|
+
var _a2;
|
|
603
741
|
const remoteId = message.author;
|
|
604
742
|
if (this.connection || this.initiating) {
|
|
605
743
|
if (remoteId.toHex() < this.localPeerId.toHex()) {
|
|
606
|
-
(0, import_log3.log)("
|
|
607
|
-
|
|
744
|
+
(0, import_log3.log)("close local connection", {
|
|
745
|
+
localPeerId: this.id,
|
|
608
746
|
topic: this.topic,
|
|
609
|
-
|
|
747
|
+
remotePeerId: this.localPeerId,
|
|
748
|
+
sessionId: (_a2 = this.connection) == null ? void 0 : _a2.sessionId
|
|
610
749
|
}, {
|
|
611
750
|
F: __dxlog_file3,
|
|
612
|
-
L:
|
|
751
|
+
L: 106,
|
|
613
752
|
S: this,
|
|
614
753
|
C: (f, a) => f(...a)
|
|
615
754
|
});
|
|
@@ -624,22 +763,33 @@ var Peer = class {
|
|
|
624
763
|
}
|
|
625
764
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
626
765
|
if (!this.connection) {
|
|
627
|
-
(0,
|
|
766
|
+
(0, import_invariant3.invariant)(message.sessionId, void 0, {
|
|
767
|
+
F: __dxlog_file3,
|
|
768
|
+
L: 126,
|
|
769
|
+
S: this,
|
|
770
|
+
A: [
|
|
771
|
+
"message.sessionId",
|
|
772
|
+
""
|
|
773
|
+
]
|
|
774
|
+
});
|
|
628
775
|
const connection = this._createConnection(false, message.sessionId);
|
|
629
776
|
try {
|
|
630
|
-
|
|
777
|
+
await this._connectionLimiter.connecting(message.sessionId);
|
|
778
|
+
await connection.openConnection();
|
|
631
779
|
} catch (err) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
780
|
+
if (!(err instanceof import_errors2.CancelledError)) {
|
|
781
|
+
import_log3.log.warn("connection error", {
|
|
782
|
+
topic: this.topic,
|
|
783
|
+
peerId: this.localPeerId,
|
|
784
|
+
remoteId: this.id,
|
|
785
|
+
err
|
|
786
|
+
}, {
|
|
787
|
+
F: __dxlog_file3,
|
|
788
|
+
L: 134,
|
|
789
|
+
S: this,
|
|
790
|
+
C: (f, a) => f(...a)
|
|
791
|
+
});
|
|
792
|
+
}
|
|
643
793
|
await this.closeConnection();
|
|
644
794
|
}
|
|
645
795
|
return {
|
|
@@ -655,8 +805,24 @@ var Peer = class {
|
|
|
655
805
|
* Initiate a connection to the remote peer.
|
|
656
806
|
*/
|
|
657
807
|
async initiateConnection() {
|
|
658
|
-
(0,
|
|
659
|
-
|
|
808
|
+
(0, import_invariant3.invariant)(!this.initiating, "Initiation in progress.", {
|
|
809
|
+
F: __dxlog_file3,
|
|
810
|
+
L: 151,
|
|
811
|
+
S: this,
|
|
812
|
+
A: [
|
|
813
|
+
"!this.initiating",
|
|
814
|
+
"'Initiation in progress.'"
|
|
815
|
+
]
|
|
816
|
+
});
|
|
817
|
+
(0, import_invariant3.invariant)(!this.connection, "Already connected.", {
|
|
818
|
+
F: __dxlog_file3,
|
|
819
|
+
L: 152,
|
|
820
|
+
S: this,
|
|
821
|
+
A: [
|
|
822
|
+
"!this.connection",
|
|
823
|
+
"'Already connected.'"
|
|
824
|
+
]
|
|
825
|
+
});
|
|
660
826
|
const sessionId = import_keys3.PublicKey.random();
|
|
661
827
|
(0, import_log3.log)("initiating...", {
|
|
662
828
|
id: this.id,
|
|
@@ -665,13 +831,14 @@ var Peer = class {
|
|
|
665
831
|
sessionId
|
|
666
832
|
}, {
|
|
667
833
|
F: __dxlog_file3,
|
|
668
|
-
L:
|
|
834
|
+
L: 154,
|
|
669
835
|
S: this,
|
|
670
836
|
C: (f, a) => f(...a)
|
|
671
837
|
});
|
|
672
838
|
const connection = this._createConnection(true, sessionId);
|
|
673
839
|
this.initiating = true;
|
|
674
840
|
try {
|
|
841
|
+
await this._connectionLimiter.connecting(sessionId);
|
|
675
842
|
const answer = await this._signalMessaging.offer({
|
|
676
843
|
author: this.localPeerId,
|
|
677
844
|
recipient: this.id,
|
|
@@ -688,14 +855,14 @@ var Peer = class {
|
|
|
688
855
|
remoteId: this.id
|
|
689
856
|
}, {
|
|
690
857
|
F: __dxlog_file3,
|
|
691
|
-
L:
|
|
858
|
+
L: 169,
|
|
692
859
|
S: this,
|
|
693
860
|
C: (f, a) => f(...a)
|
|
694
861
|
});
|
|
695
862
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
696
863
|
(0, import_log3.log)("ignoring response", void 0, {
|
|
697
864
|
F: __dxlog_file3,
|
|
698
|
-
L:
|
|
865
|
+
L: 171,
|
|
699
866
|
S: this,
|
|
700
867
|
C: (f, a) => f(...a)
|
|
701
868
|
});
|
|
@@ -705,7 +872,7 @@ var Peer = class {
|
|
|
705
872
|
this._callbacks.onRejected();
|
|
706
873
|
return;
|
|
707
874
|
}
|
|
708
|
-
connection.openConnection();
|
|
875
|
+
await connection.openConnection();
|
|
709
876
|
this._callbacks.onAccepted();
|
|
710
877
|
} catch (err) {
|
|
711
878
|
(0, import_log3.log)("initiation error", {
|
|
@@ -715,7 +882,7 @@ var Peer = class {
|
|
|
715
882
|
remoteId: this.id
|
|
716
883
|
}, {
|
|
717
884
|
F: __dxlog_file3,
|
|
718
|
-
L:
|
|
885
|
+
L: 182,
|
|
719
886
|
S: this,
|
|
720
887
|
C: (f, a) => f(...a)
|
|
721
888
|
});
|
|
@@ -739,11 +906,19 @@ var Peer = class {
|
|
|
739
906
|
sessionId
|
|
740
907
|
}, {
|
|
741
908
|
F: __dxlog_file3,
|
|
742
|
-
L:
|
|
909
|
+
L: 196,
|
|
743
910
|
S: this,
|
|
744
911
|
C: (f, a) => f(...a)
|
|
745
912
|
});
|
|
746
|
-
(0,
|
|
913
|
+
(0, import_invariant3.invariant)(!this.connection, "Already connected.", {
|
|
914
|
+
F: __dxlog_file3,
|
|
915
|
+
L: 203,
|
|
916
|
+
S: this,
|
|
917
|
+
A: [
|
|
918
|
+
"!this.connection",
|
|
919
|
+
"'Already connected.'"
|
|
920
|
+
]
|
|
921
|
+
});
|
|
747
922
|
const connection = new Connection(
|
|
748
923
|
this.topic,
|
|
749
924
|
this.localPeerId,
|
|
@@ -769,6 +944,19 @@ var Peer = class {
|
|
|
769
944
|
this.availableToConnect = true;
|
|
770
945
|
this._lastConnectionTime = Date.now();
|
|
771
946
|
this._callbacks.onConnected();
|
|
947
|
+
this._connectionLimiter.doneConnecting(sessionId);
|
|
948
|
+
import_log3.log.trace("dxos.mesh.connection.connected", {
|
|
949
|
+
topic: this.topic,
|
|
950
|
+
localPeerId: this.localPeerId,
|
|
951
|
+
remotePeerId: this.id,
|
|
952
|
+
sessionId,
|
|
953
|
+
initiator
|
|
954
|
+
}, {
|
|
955
|
+
F: __dxlog_file3,
|
|
956
|
+
L: 229,
|
|
957
|
+
S: this,
|
|
958
|
+
C: (f, a) => f(...a)
|
|
959
|
+
});
|
|
772
960
|
break;
|
|
773
961
|
}
|
|
774
962
|
case ConnectionState.CLOSED: {
|
|
@@ -779,11 +967,31 @@ var Peer = class {
|
|
|
779
967
|
initiator
|
|
780
968
|
}, {
|
|
781
969
|
F: __dxlog_file3,
|
|
782
|
-
L:
|
|
970
|
+
L: 240,
|
|
971
|
+
S: this,
|
|
972
|
+
C: (f, a) => f(...a)
|
|
973
|
+
});
|
|
974
|
+
(0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
|
|
975
|
+
F: __dxlog_file3,
|
|
976
|
+
L: 241,
|
|
977
|
+
S: this,
|
|
978
|
+
A: [
|
|
979
|
+
"this.connection === connection",
|
|
980
|
+
"'Connection mismatch (race condition).'"
|
|
981
|
+
]
|
|
982
|
+
});
|
|
983
|
+
import_log3.log.trace("dxos.mesh.connection.closed", {
|
|
984
|
+
topic: this.topic,
|
|
985
|
+
localPeerId: this.localPeerId,
|
|
986
|
+
remotePeerId: this.id,
|
|
987
|
+
sessionId,
|
|
988
|
+
initiator
|
|
989
|
+
}, {
|
|
990
|
+
F: __dxlog_file3,
|
|
991
|
+
L: 243,
|
|
783
992
|
S: this,
|
|
784
993
|
C: (f, a) => f(...a)
|
|
785
994
|
});
|
|
786
|
-
(0, import_tiny_invariant3.default)(this.connection === connection, "Connection mismatch (race condition).");
|
|
787
995
|
if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
|
|
788
996
|
this._availableAfter = 0;
|
|
789
997
|
} else {
|
|
@@ -792,6 +1000,7 @@ var Peer = class {
|
|
|
792
1000
|
}
|
|
793
1001
|
this.connection = void 0;
|
|
794
1002
|
this._callbacks.onDisconnected();
|
|
1003
|
+
this._connectionLimiter.doneConnecting(sessionId);
|
|
795
1004
|
(0, import_async2.scheduleTask)(this._connectionCtx, () => {
|
|
796
1005
|
this.availableToConnect = true;
|
|
797
1006
|
this._callbacks.onPeerAvailable();
|
|
@@ -809,7 +1018,20 @@ var Peer = class {
|
|
|
809
1018
|
err
|
|
810
1019
|
}, {
|
|
811
1020
|
F: __dxlog_file3,
|
|
812
|
-
L:
|
|
1021
|
+
L: 277,
|
|
1022
|
+
S: this,
|
|
1023
|
+
C: (f, a) => f(...a)
|
|
1024
|
+
});
|
|
1025
|
+
import_log3.log.trace("dxos.mesh.connection.error", {
|
|
1026
|
+
topic: this.topic,
|
|
1027
|
+
localPeerId: this.localPeerId,
|
|
1028
|
+
remotePeerId: this.id,
|
|
1029
|
+
sessionId,
|
|
1030
|
+
initiator,
|
|
1031
|
+
err
|
|
1032
|
+
}, {
|
|
1033
|
+
F: __dxlog_file3,
|
|
1034
|
+
L: 278,
|
|
813
1035
|
S: this,
|
|
814
1036
|
C: (f, a) => f(...a)
|
|
815
1037
|
});
|
|
@@ -828,7 +1050,7 @@ var Peer = class {
|
|
|
828
1050
|
sessionId: connection.sessionId
|
|
829
1051
|
}, {
|
|
830
1052
|
F: __dxlog_file3,
|
|
831
|
-
L:
|
|
1053
|
+
L: 301,
|
|
832
1054
|
S: this,
|
|
833
1055
|
C: (f, a) => f(...a)
|
|
834
1056
|
});
|
|
@@ -838,7 +1060,7 @@ var Peer = class {
|
|
|
838
1060
|
sessionId: connection.sessionId
|
|
839
1061
|
}, {
|
|
840
1062
|
F: __dxlog_file3,
|
|
841
|
-
L:
|
|
1063
|
+
L: 307,
|
|
842
1064
|
S: this,
|
|
843
1065
|
C: (f, a) => f(...a)
|
|
844
1066
|
});
|
|
@@ -849,7 +1071,7 @@ var Peer = class {
|
|
|
849
1071
|
message
|
|
850
1072
|
}, {
|
|
851
1073
|
F: __dxlog_file3,
|
|
852
|
-
L:
|
|
1074
|
+
L: 312,
|
|
853
1075
|
S: this,
|
|
854
1076
|
C: (f, a) => f(...a)
|
|
855
1077
|
});
|
|
@@ -865,7 +1087,7 @@ var Peer = class {
|
|
|
865
1087
|
topic: this.topic
|
|
866
1088
|
}, {
|
|
867
1089
|
F: __dxlog_file3,
|
|
868
|
-
L:
|
|
1090
|
+
L: 322,
|
|
869
1091
|
S: this,
|
|
870
1092
|
C: (f, a) => f(...a)
|
|
871
1093
|
});
|
|
@@ -899,13 +1121,13 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
899
1121
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
900
1122
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
901
1123
|
}
|
|
902
|
-
var __dxlog_file4 = "/
|
|
1124
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
903
1125
|
var INITIATION_DELAY = 100;
|
|
904
1126
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
905
1127
|
var Swarm = class {
|
|
906
1128
|
// TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
|
|
907
1129
|
// TODO(burdon): Split up properties.
|
|
908
|
-
constructor(_topic, _ownPeerId, _topology, _protocolProvider, _messenger, _transportFactory, _label) {
|
|
1130
|
+
constructor(_topic, _ownPeerId, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter) {
|
|
909
1131
|
this._topic = _topic;
|
|
910
1132
|
this._ownPeerId = _ownPeerId;
|
|
911
1133
|
this._topology = _topology;
|
|
@@ -913,6 +1135,7 @@ var Swarm = class {
|
|
|
913
1135
|
this._messenger = _messenger;
|
|
914
1136
|
this._transportFactory = _transportFactory;
|
|
915
1137
|
this._label = _label;
|
|
1138
|
+
this._connectionLimiter = _connectionLimiter;
|
|
916
1139
|
this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
|
|
917
1140
|
this._ctx = new import_context4.Context();
|
|
918
1141
|
this._listeningHandle = void 0;
|
|
@@ -929,7 +1152,7 @@ var Swarm = class {
|
|
|
929
1152
|
}
|
|
930
1153
|
}), {
|
|
931
1154
|
F: __dxlog_file4,
|
|
932
|
-
L:
|
|
1155
|
+
L: 87,
|
|
933
1156
|
S: this,
|
|
934
1157
|
C: (f, a) => f(...a)
|
|
935
1158
|
});
|
|
@@ -937,7 +1160,7 @@ var Swarm = class {
|
|
|
937
1160
|
peerId: _ownPeerId
|
|
938
1161
|
}, {
|
|
939
1162
|
F: __dxlog_file4,
|
|
940
|
-
L:
|
|
1163
|
+
L: 91,
|
|
941
1164
|
S: this,
|
|
942
1165
|
C: (f, a) => f(...a)
|
|
943
1166
|
});
|
|
@@ -952,7 +1175,7 @@ var Swarm = class {
|
|
|
952
1175
|
id: this._instanceId
|
|
953
1176
|
}), {
|
|
954
1177
|
F: __dxlog_file4,
|
|
955
|
-
L:
|
|
1178
|
+
L: 100,
|
|
956
1179
|
S: this,
|
|
957
1180
|
C: (f, a) => f(...a)
|
|
958
1181
|
});
|
|
@@ -973,7 +1196,15 @@ var Swarm = class {
|
|
|
973
1196
|
return this._topic;
|
|
974
1197
|
}
|
|
975
1198
|
async open() {
|
|
976
|
-
(0,
|
|
1199
|
+
(0, import_invariant4.invariant)(!this._listeningHandle, void 0, {
|
|
1200
|
+
F: __dxlog_file4,
|
|
1201
|
+
L: 127,
|
|
1202
|
+
S: this,
|
|
1203
|
+
A: [
|
|
1204
|
+
"!this._listeningHandle",
|
|
1205
|
+
""
|
|
1206
|
+
]
|
|
1207
|
+
});
|
|
977
1208
|
this._listeningHandle = await this._messenger.listen({
|
|
978
1209
|
peerId: this._ownPeerId,
|
|
979
1210
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
@@ -982,7 +1213,7 @@ var Swarm = class {
|
|
|
982
1213
|
err
|
|
983
1214
|
}, {
|
|
984
1215
|
F: __dxlog_file4,
|
|
985
|
-
L:
|
|
1216
|
+
L: 134,
|
|
986
1217
|
S: this,
|
|
987
1218
|
C: (f, a) => f(...a)
|
|
988
1219
|
}));
|
|
@@ -993,7 +1224,7 @@ var Swarm = class {
|
|
|
993
1224
|
var _a2;
|
|
994
1225
|
(0, import_log4.log)("destroying...", void 0, {
|
|
995
1226
|
F: __dxlog_file4,
|
|
996
|
-
L:
|
|
1227
|
+
L: 140,
|
|
997
1228
|
S: this,
|
|
998
1229
|
C: (f, a) => f(...a)
|
|
999
1230
|
});
|
|
@@ -1004,13 +1235,21 @@ var Swarm = class {
|
|
|
1004
1235
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
1005
1236
|
(0, import_log4.log)("destroyed", void 0, {
|
|
1006
1237
|
F: __dxlog_file4,
|
|
1007
|
-
L:
|
|
1238
|
+
L: 147,
|
|
1008
1239
|
S: this,
|
|
1009
1240
|
C: (f, a) => f(...a)
|
|
1010
1241
|
});
|
|
1011
1242
|
}
|
|
1012
1243
|
async setTopology(topology) {
|
|
1013
|
-
(0,
|
|
1244
|
+
(0, import_invariant4.invariant)(!this._ctx.disposed, "Swarm is offline", {
|
|
1245
|
+
F: __dxlog_file4,
|
|
1246
|
+
L: 151,
|
|
1247
|
+
S: this,
|
|
1248
|
+
A: [
|
|
1249
|
+
"!this._ctx.disposed",
|
|
1250
|
+
"'Swarm is offline'"
|
|
1251
|
+
]
|
|
1252
|
+
});
|
|
1014
1253
|
if (topology === this._topology) {
|
|
1015
1254
|
return;
|
|
1016
1255
|
}
|
|
@@ -1019,7 +1258,7 @@ var Swarm = class {
|
|
|
1019
1258
|
topology: getClassName(topology)
|
|
1020
1259
|
}, {
|
|
1021
1260
|
F: __dxlog_file4,
|
|
1022
|
-
L:
|
|
1261
|
+
L: 155,
|
|
1023
1262
|
S: this,
|
|
1024
1263
|
C: (f, a) => f(...a)
|
|
1025
1264
|
});
|
|
@@ -1034,14 +1273,14 @@ var Swarm = class {
|
|
|
1034
1273
|
swarmEvent
|
|
1035
1274
|
}, {
|
|
1036
1275
|
F: __dxlog_file4,
|
|
1037
|
-
L:
|
|
1276
|
+
L: 168,
|
|
1038
1277
|
S: this,
|
|
1039
1278
|
C: (f, a) => f(...a)
|
|
1040
1279
|
});
|
|
1041
1280
|
if (this._ctx.disposed) {
|
|
1042
1281
|
(0, import_log4.log)("swarm event ignored for disposed swarm", void 0, {
|
|
1043
1282
|
F: __dxlog_file4,
|
|
1044
|
-
L:
|
|
1283
|
+
L: 171,
|
|
1045
1284
|
S: this,
|
|
1046
1285
|
C: (f, a) => f(...a)
|
|
1047
1286
|
});
|
|
@@ -1053,7 +1292,7 @@ var Swarm = class {
|
|
|
1053
1292
|
peerId
|
|
1054
1293
|
}, {
|
|
1055
1294
|
F: __dxlog_file4,
|
|
1056
|
-
L:
|
|
1295
|
+
L: 177,
|
|
1057
1296
|
S: this,
|
|
1058
1297
|
C: (f, a) => f(...a)
|
|
1059
1298
|
});
|
|
@@ -1068,7 +1307,7 @@ var Swarm = class {
|
|
|
1068
1307
|
if (((_a2 = peer.connection) == null ? void 0 : _a2.state) !== ConnectionState.CONNECTED) {
|
|
1069
1308
|
void this._destroyPeer(peer.id).catch((err) => import_log4.log.catch(err, void 0, {
|
|
1070
1309
|
F: __dxlog_file4,
|
|
1071
|
-
L:
|
|
1310
|
+
L: 188,
|
|
1072
1311
|
S: this,
|
|
1073
1312
|
C: (f, a) => f(...a)
|
|
1074
1313
|
}));
|
|
@@ -1083,14 +1322,14 @@ var Swarm = class {
|
|
|
1083
1322
|
message
|
|
1084
1323
|
}, {
|
|
1085
1324
|
F: __dxlog_file4,
|
|
1086
|
-
L:
|
|
1325
|
+
L: 198,
|
|
1087
1326
|
S: this,
|
|
1088
1327
|
C: (f, a) => f(...a)
|
|
1089
1328
|
});
|
|
1090
1329
|
if (this._ctx.disposed) {
|
|
1091
1330
|
(0, import_log4.log)("ignored for disposed swarm", void 0, {
|
|
1092
1331
|
F: __dxlog_file4,
|
|
1093
|
-
L:
|
|
1332
|
+
L: 200,
|
|
1094
1333
|
S: this,
|
|
1095
1334
|
C: (f, a) => f(...a)
|
|
1096
1335
|
});
|
|
@@ -1098,13 +1337,21 @@ var Swarm = class {
|
|
|
1098
1337
|
accept: false
|
|
1099
1338
|
};
|
|
1100
1339
|
}
|
|
1101
|
-
(0,
|
|
1340
|
+
(0, import_invariant4.invariant)(message.author, void 0, {
|
|
1341
|
+
F: __dxlog_file4,
|
|
1342
|
+
L: 205,
|
|
1343
|
+
S: this,
|
|
1344
|
+
A: [
|
|
1345
|
+
"message.author",
|
|
1346
|
+
""
|
|
1347
|
+
]
|
|
1348
|
+
});
|
|
1102
1349
|
if (!((_a2 = message.recipient) == null ? void 0 : _a2.equals(this._ownPeerId))) {
|
|
1103
1350
|
(0, import_log4.log)("rejecting offer with incorrect peerId", {
|
|
1104
1351
|
message
|
|
1105
1352
|
}, {
|
|
1106
1353
|
F: __dxlog_file4,
|
|
1107
|
-
L:
|
|
1354
|
+
L: 207,
|
|
1108
1355
|
S: this,
|
|
1109
1356
|
C: (f, a) => f(...a)
|
|
1110
1357
|
});
|
|
@@ -1117,7 +1364,7 @@ var Swarm = class {
|
|
|
1117
1364
|
message
|
|
1118
1365
|
}, {
|
|
1119
1366
|
F: __dxlog_file4,
|
|
1120
|
-
L:
|
|
1367
|
+
L: 211,
|
|
1121
1368
|
S: this,
|
|
1122
1369
|
C: (f, a) => f(...a)
|
|
1123
1370
|
});
|
|
@@ -1149,9 +1396,33 @@ var Swarm = class {
|
|
|
1149
1396
|
});
|
|
1150
1397
|
return;
|
|
1151
1398
|
}
|
|
1152
|
-
(0,
|
|
1153
|
-
|
|
1154
|
-
|
|
1399
|
+
(0, import_invariant4.invariant)((_a2 = message.recipient) == null ? void 0 : _a2.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1400
|
+
F: __dxlog_file4,
|
|
1401
|
+
L: 227,
|
|
1402
|
+
S: this,
|
|
1403
|
+
A: [
|
|
1404
|
+
"message.recipient?.equals(this._ownPeerId)",
|
|
1405
|
+
"`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
|
|
1406
|
+
]
|
|
1407
|
+
});
|
|
1408
|
+
(0, import_invariant4.invariant)((_b = message.topic) == null ? void 0 : _b.equals(this._topic), void 0, {
|
|
1409
|
+
F: __dxlog_file4,
|
|
1410
|
+
L: 231,
|
|
1411
|
+
S: this,
|
|
1412
|
+
A: [
|
|
1413
|
+
"message.topic?.equals(this._topic)",
|
|
1414
|
+
""
|
|
1415
|
+
]
|
|
1416
|
+
});
|
|
1417
|
+
(0, import_invariant4.invariant)(message.author, void 0, {
|
|
1418
|
+
F: __dxlog_file4,
|
|
1419
|
+
L: 232,
|
|
1420
|
+
S: this,
|
|
1421
|
+
A: [
|
|
1422
|
+
"message.author",
|
|
1423
|
+
""
|
|
1424
|
+
]
|
|
1425
|
+
});
|
|
1155
1426
|
const peer = this._getOrCreatePeer(message.author);
|
|
1156
1427
|
await peer.onSignal(message);
|
|
1157
1428
|
}
|
|
@@ -1169,7 +1440,7 @@ var Swarm = class {
|
|
|
1169
1440
|
_getOrCreatePeer(peerId) {
|
|
1170
1441
|
let peer = this._peers.get(peerId);
|
|
1171
1442
|
if (!peer) {
|
|
1172
|
-
peer = new Peer(peerId, this._topic, this._ownPeerId, this._swarmMessenger, this._protocolProvider, this._transportFactory, {
|
|
1443
|
+
peer = new Peer(peerId, this._topic, this._ownPeerId, this._swarmMessenger, this._protocolProvider, this._transportFactory, this._connectionLimiter, {
|
|
1173
1444
|
onInitiated: (connection) => {
|
|
1174
1445
|
this.connectionAdded.emit(connection);
|
|
1175
1446
|
},
|
|
@@ -1203,7 +1474,15 @@ var Swarm = class {
|
|
|
1203
1474
|
return peer;
|
|
1204
1475
|
}
|
|
1205
1476
|
async _destroyPeer(peerId) {
|
|
1206
|
-
(0,
|
|
1477
|
+
(0, import_invariant4.invariant)(this._peers.has(peerId), void 0, {
|
|
1478
|
+
F: __dxlog_file4,
|
|
1479
|
+
L: 302,
|
|
1480
|
+
S: this,
|
|
1481
|
+
A: [
|
|
1482
|
+
"this._peers.has(peerId)",
|
|
1483
|
+
""
|
|
1484
|
+
]
|
|
1485
|
+
});
|
|
1207
1486
|
await this._peers.get(peerId).destroy();
|
|
1208
1487
|
this._peers.delete(peerId);
|
|
1209
1488
|
}
|
|
@@ -1224,7 +1503,7 @@ var Swarm = class {
|
|
|
1224
1503
|
} catch (err) {
|
|
1225
1504
|
(0, import_log4.log)("initiation error", err, {
|
|
1226
1505
|
F: __dxlog_file4,
|
|
1227
|
-
L:
|
|
1506
|
+
L: 328,
|
|
1228
1507
|
S: this,
|
|
1229
1508
|
C: (f, a) => f(...a)
|
|
1230
1509
|
});
|
|
@@ -1252,7 +1531,7 @@ var Swarm = class {
|
|
|
1252
1531
|
remoteId
|
|
1253
1532
|
}, {
|
|
1254
1533
|
F: __dxlog_file4,
|
|
1255
|
-
L:
|
|
1534
|
+
L: 355,
|
|
1256
1535
|
S: this,
|
|
1257
1536
|
C: (f, a) => f(...a)
|
|
1258
1537
|
});
|
|
@@ -1269,7 +1548,7 @@ var Swarm = class {
|
|
|
1269
1548
|
remoteId
|
|
1270
1549
|
}, {
|
|
1271
1550
|
F: __dxlog_file4,
|
|
1272
|
-
L:
|
|
1551
|
+
L: 369,
|
|
1273
1552
|
S: this,
|
|
1274
1553
|
C: (f, a) => f(...a)
|
|
1275
1554
|
});
|
|
@@ -1279,7 +1558,7 @@ var Swarm = class {
|
|
|
1279
1558
|
remoteId
|
|
1280
1559
|
}, {
|
|
1281
1560
|
F: __dxlog_file4,
|
|
1282
|
-
L:
|
|
1561
|
+
L: 372,
|
|
1283
1562
|
S: this,
|
|
1284
1563
|
C: (f, a) => f(...a)
|
|
1285
1564
|
});
|
|
@@ -1307,9 +1586,6 @@ _ts_decorate3([
|
|
|
1307
1586
|
_ts_decorate3([
|
|
1308
1587
|
import_async3.synchronized
|
|
1309
1588
|
], Swarm.prototype, "onOffer", null);
|
|
1310
|
-
_ts_decorate3([
|
|
1311
|
-
import_async3.synchronized
|
|
1312
|
-
], Swarm.prototype, "onSignal", null);
|
|
1313
1589
|
_ts_decorate3([
|
|
1314
1590
|
import_async3.synchronized
|
|
1315
1591
|
], Swarm.prototype, "goOffline", null);
|
|
@@ -1322,7 +1598,7 @@ var import_async4 = require("@dxos/async");
|
|
|
1322
1598
|
var import_keys5 = require("@dxos/keys");
|
|
1323
1599
|
var import_log5 = require("@dxos/log");
|
|
1324
1600
|
var import_util3 = require("@dxos/util");
|
|
1325
|
-
var __dxlog_file5 = "/
|
|
1601
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
1326
1602
|
var SwarmMapper = class {
|
|
1327
1603
|
get peers() {
|
|
1328
1604
|
return Array.from(this._peers.values());
|
|
@@ -1388,6 +1664,88 @@ var SwarmMapper = class {
|
|
|
1388
1664
|
}
|
|
1389
1665
|
};
|
|
1390
1666
|
|
|
1667
|
+
// packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
|
|
1668
|
+
var import_async5 = require("@dxos/async");
|
|
1669
|
+
var import_context5 = require("@dxos/context");
|
|
1670
|
+
var import_errors3 = require("@dxos/errors");
|
|
1671
|
+
var import_invariant5 = require("@dxos/invariant");
|
|
1672
|
+
var import_keys6 = require("@dxos/keys");
|
|
1673
|
+
var import_log6 = require("@dxos/log");
|
|
1674
|
+
var import_util4 = require("@dxos/util");
|
|
1675
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
1676
|
+
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 3;
|
|
1677
|
+
var ConnectionLimiter = class {
|
|
1678
|
+
constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
|
|
1679
|
+
this._ctx = new import_context5.Context();
|
|
1680
|
+
/**
|
|
1681
|
+
* Queue of promises to resolve when initiating connections amount is below the limit.
|
|
1682
|
+
*/
|
|
1683
|
+
this._waitingPromises = new import_util4.ComplexMap(import_keys6.PublicKey.hash);
|
|
1684
|
+
this.resolveWaitingPromises = new import_async5.DeferredTask(this._ctx, async () => {
|
|
1685
|
+
Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
|
|
1686
|
+
resolve();
|
|
1687
|
+
});
|
|
1688
|
+
});
|
|
1689
|
+
this._maxConcurrentInitConnections = maxConcurrentInitConnections;
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
|
|
1693
|
+
*/
|
|
1694
|
+
async connecting(sessionId) {
|
|
1695
|
+
(0, import_invariant5.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
1696
|
+
F: __dxlog_file6,
|
|
1697
|
+
L: 48,
|
|
1698
|
+
S: this,
|
|
1699
|
+
A: [
|
|
1700
|
+
"!this._waitingPromises.has(sessionId)",
|
|
1701
|
+
"'Peer is already waiting for connection'"
|
|
1702
|
+
]
|
|
1703
|
+
});
|
|
1704
|
+
(0, import_log6.log)("waiting", {
|
|
1705
|
+
sessionId
|
|
1706
|
+
}, {
|
|
1707
|
+
F: __dxlog_file6,
|
|
1708
|
+
L: 49,
|
|
1709
|
+
S: this,
|
|
1710
|
+
C: (f, a) => f(...a)
|
|
1711
|
+
});
|
|
1712
|
+
await new Promise((resolve, reject) => {
|
|
1713
|
+
this._waitingPromises.set(sessionId, {
|
|
1714
|
+
resolve,
|
|
1715
|
+
reject
|
|
1716
|
+
});
|
|
1717
|
+
this.resolveWaitingPromises.schedule();
|
|
1718
|
+
});
|
|
1719
|
+
(0, import_log6.log)("allow", {
|
|
1720
|
+
sessionId
|
|
1721
|
+
}, {
|
|
1722
|
+
F: __dxlog_file6,
|
|
1723
|
+
L: 57,
|
|
1724
|
+
S: this,
|
|
1725
|
+
C: (f, a) => f(...a)
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
/**
|
|
1729
|
+
* Rejects promise returned by `connecting` method.
|
|
1730
|
+
*/
|
|
1731
|
+
doneConnecting(sessionId) {
|
|
1732
|
+
(0, import_log6.log)("done", {
|
|
1733
|
+
sessionId
|
|
1734
|
+
}, {
|
|
1735
|
+
F: __dxlog_file6,
|
|
1736
|
+
L: 64,
|
|
1737
|
+
S: this,
|
|
1738
|
+
C: (f, a) => f(...a)
|
|
1739
|
+
});
|
|
1740
|
+
if (!this._waitingPromises.has(sessionId)) {
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
this._waitingPromises.get(sessionId).reject(new import_errors3.CancelledError());
|
|
1744
|
+
this._waitingPromises.delete(sessionId);
|
|
1745
|
+
this.resolveWaitingPromises.schedule();
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
|
|
1391
1749
|
// packages/core/mesh/network-manager/src/connection-log.ts
|
|
1392
1750
|
var EventType;
|
|
1393
1751
|
(function(EventType2) {
|
|
@@ -1402,8 +1760,8 @@ var ConnectionLog = class {
|
|
|
1402
1760
|
/**
|
|
1403
1761
|
* SwarmId => info
|
|
1404
1762
|
*/
|
|
1405
|
-
this._swarms = new
|
|
1406
|
-
this.update = new
|
|
1763
|
+
this._swarms = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
|
|
1764
|
+
this.update = new import_async6.Event();
|
|
1407
1765
|
}
|
|
1408
1766
|
getSwarmInfo(swarmId) {
|
|
1409
1767
|
var _a2;
|
|
@@ -1414,13 +1772,13 @@ var ConnectionLog = class {
|
|
|
1414
1772
|
}
|
|
1415
1773
|
joinedSwarm(swarm) {
|
|
1416
1774
|
const info = {
|
|
1417
|
-
id:
|
|
1775
|
+
id: import_keys7.PublicKey.from(swarm._instanceId),
|
|
1418
1776
|
topic: swarm.topic,
|
|
1419
1777
|
isActive: true,
|
|
1420
1778
|
label: swarm.label,
|
|
1421
1779
|
connections: []
|
|
1422
1780
|
};
|
|
1423
|
-
this._swarms.set(
|
|
1781
|
+
this._swarms.set(import_keys7.PublicKey.from(swarm._instanceId), info);
|
|
1424
1782
|
this.update.emit();
|
|
1425
1783
|
swarm.connectionAdded.on((connection) => {
|
|
1426
1784
|
var _a2, _b;
|
|
@@ -1449,21 +1807,24 @@ var ConnectionLog = class {
|
|
|
1449
1807
|
});
|
|
1450
1808
|
}
|
|
1451
1809
|
leftSwarm(swarm) {
|
|
1452
|
-
this.getSwarmInfo(
|
|
1810
|
+
this.getSwarmInfo(import_keys7.PublicKey.from(swarm._instanceId)).isActive = false;
|
|
1453
1811
|
this.update.emit();
|
|
1454
1812
|
}
|
|
1455
1813
|
};
|
|
1456
1814
|
|
|
1457
1815
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
1458
|
-
var
|
|
1816
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
1459
1817
|
var NetworkManager = class {
|
|
1460
1818
|
constructor({ transportFactory, signalManager, log: log1 }) {
|
|
1461
|
-
|
|
1462
|
-
|
|
1819
|
+
/**
|
|
1820
|
+
* @internal
|
|
1821
|
+
*/
|
|
1822
|
+
this._swarms = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
|
|
1823
|
+
this._mappers = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
|
|
1463
1824
|
this._connectionState = import_services.ConnectionState.ONLINE;
|
|
1464
|
-
this.connectionStateChanged = new
|
|
1465
|
-
this.topicsUpdated = new
|
|
1466
|
-
this._instanceId =
|
|
1825
|
+
this.connectionStateChanged = new import_async7.Event();
|
|
1826
|
+
this.topicsUpdated = new import_async7.Event();
|
|
1827
|
+
this._instanceId = import_keys8.PublicKey.random().toHex();
|
|
1467
1828
|
this._transportFactory = transportFactory;
|
|
1468
1829
|
this._signalManager = signalManager;
|
|
1469
1830
|
this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => {
|
|
@@ -1477,6 +1838,7 @@ var NetworkManager = class {
|
|
|
1477
1838
|
join: (opts) => this._signalManager.join(opts),
|
|
1478
1839
|
leave: (opts) => this._signalManager.leave(opts)
|
|
1479
1840
|
};
|
|
1841
|
+
this._connectionLimiter = new ConnectionLimiter();
|
|
1480
1842
|
if (log1) {
|
|
1481
1843
|
this._connectionLog = new ConnectionLog();
|
|
1482
1844
|
}
|
|
@@ -1499,21 +1861,21 @@ var NetworkManager = class {
|
|
|
1499
1861
|
return this._swarms.get(topic);
|
|
1500
1862
|
}
|
|
1501
1863
|
async open() {
|
|
1502
|
-
|
|
1864
|
+
import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.begin({
|
|
1503
1865
|
id: this._instanceId
|
|
1504
1866
|
}), {
|
|
1505
|
-
F:
|
|
1506
|
-
L:
|
|
1867
|
+
F: __dxlog_file7,
|
|
1868
|
+
L: 130,
|
|
1507
1869
|
S: this,
|
|
1508
1870
|
C: (f, a) => f(...a)
|
|
1509
1871
|
});
|
|
1510
1872
|
await this._messenger.open();
|
|
1511
1873
|
await this._signalManager.open();
|
|
1512
|
-
|
|
1874
|
+
import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.end({
|
|
1513
1875
|
id: this._instanceId
|
|
1514
1876
|
}), {
|
|
1515
|
-
F:
|
|
1516
|
-
L:
|
|
1877
|
+
F: __dxlog_file7,
|
|
1878
|
+
L: 133,
|
|
1517
1879
|
S: this,
|
|
1518
1880
|
C: (f, a) => f(...a)
|
|
1519
1881
|
});
|
|
@@ -1521,9 +1883,9 @@ var NetworkManager = class {
|
|
|
1521
1883
|
async close() {
|
|
1522
1884
|
for (const topic of this._swarms.keys()) {
|
|
1523
1885
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1524
|
-
(0,
|
|
1525
|
-
F:
|
|
1526
|
-
L:
|
|
1886
|
+
(0, import_log7.log)(err, void 0, {
|
|
1887
|
+
F: __dxlog_file7,
|
|
1888
|
+
L: 139,
|
|
1527
1889
|
S: this,
|
|
1528
1890
|
C: (f, a) => f(...a)
|
|
1529
1891
|
});
|
|
@@ -1537,30 +1899,62 @@ var NetworkManager = class {
|
|
|
1537
1899
|
*/
|
|
1538
1900
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1539
1901
|
var _a2;
|
|
1540
|
-
(0,
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1902
|
+
(0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(topic), void 0, {
|
|
1903
|
+
F: __dxlog_file7,
|
|
1904
|
+
L: 157,
|
|
1905
|
+
S: this,
|
|
1906
|
+
A: [
|
|
1907
|
+
"PublicKey.isPublicKey(topic)",
|
|
1908
|
+
""
|
|
1909
|
+
]
|
|
1910
|
+
});
|
|
1911
|
+
(0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(peerId), void 0, {
|
|
1912
|
+
F: __dxlog_file7,
|
|
1913
|
+
L: 158,
|
|
1914
|
+
S: this,
|
|
1915
|
+
A: [
|
|
1916
|
+
"PublicKey.isPublicKey(peerId)",
|
|
1917
|
+
""
|
|
1918
|
+
]
|
|
1919
|
+
});
|
|
1920
|
+
(0, import_invariant6.invariant)(topology, void 0, {
|
|
1921
|
+
F: __dxlog_file7,
|
|
1922
|
+
L: 159,
|
|
1923
|
+
S: this,
|
|
1924
|
+
A: [
|
|
1925
|
+
"topology",
|
|
1926
|
+
""
|
|
1927
|
+
]
|
|
1928
|
+
});
|
|
1929
|
+
(0, import_invariant6.invariant)(typeof protocol === "function", void 0, {
|
|
1930
|
+
F: __dxlog_file7,
|
|
1931
|
+
L: 160,
|
|
1932
|
+
S: this,
|
|
1933
|
+
A: [
|
|
1934
|
+
"typeof protocol === 'function'",
|
|
1935
|
+
""
|
|
1936
|
+
]
|
|
1937
|
+
});
|
|
1544
1938
|
if (this._swarms.has(topic)) {
|
|
1545
|
-
throw new Error(`Already connected to swarm: ${
|
|
1939
|
+
throw new Error(`Already connected to swarm: ${import_keys8.PublicKey.from(topic)}`);
|
|
1546
1940
|
}
|
|
1547
|
-
(0,
|
|
1548
|
-
topic:
|
|
1941
|
+
(0, import_log7.log)("joining", {
|
|
1942
|
+
topic: import_keys8.PublicKey.from(topic),
|
|
1549
1943
|
peerId,
|
|
1550
1944
|
topology: topology.toString()
|
|
1551
1945
|
}, {
|
|
1552
|
-
F:
|
|
1553
|
-
L:
|
|
1946
|
+
F: __dxlog_file7,
|
|
1947
|
+
L: 165,
|
|
1554
1948
|
S: this,
|
|
1555
1949
|
C: (f, a) => f(...a)
|
|
1556
1950
|
});
|
|
1557
|
-
const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label);
|
|
1951
|
+
const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
1558
1952
|
swarm.errors.handle((error) => {
|
|
1559
|
-
(0,
|
|
1953
|
+
(0, import_log7.log)("swarm error", {
|
|
1560
1954
|
error
|
|
1561
1955
|
}, {
|
|
1562
|
-
F:
|
|
1563
|
-
L:
|
|
1956
|
+
F: __dxlog_file7,
|
|
1957
|
+
L: 178,
|
|
1564
1958
|
S: this,
|
|
1565
1959
|
C: (f, a) => f(...a)
|
|
1566
1960
|
});
|
|
@@ -1571,20 +1965,20 @@ var NetworkManager = class {
|
|
|
1571
1965
|
this._signalConnection.join({
|
|
1572
1966
|
topic,
|
|
1573
1967
|
peerId
|
|
1574
|
-
}).catch((error) =>
|
|
1575
|
-
F:
|
|
1576
|
-
L:
|
|
1968
|
+
}).catch((error) => import_log7.log.catch(error, void 0, {
|
|
1969
|
+
F: __dxlog_file7,
|
|
1970
|
+
L: 187,
|
|
1577
1971
|
S: this,
|
|
1578
1972
|
C: (f, a) => f(...a)
|
|
1579
1973
|
}));
|
|
1580
1974
|
this.topicsUpdated.emit();
|
|
1581
1975
|
(_a2 = this._connectionLog) == null ? void 0 : _a2.joinedSwarm(swarm);
|
|
1582
|
-
(0,
|
|
1583
|
-
topic:
|
|
1976
|
+
(0, import_log7.log)("joined", {
|
|
1977
|
+
topic: import_keys8.PublicKey.from(topic),
|
|
1584
1978
|
count: this._swarms.size
|
|
1585
1979
|
}, {
|
|
1586
|
-
F:
|
|
1587
|
-
L:
|
|
1980
|
+
F: __dxlog_file7,
|
|
1981
|
+
L: 191,
|
|
1588
1982
|
S: this,
|
|
1589
1983
|
C: (f, a) => f(...a)
|
|
1590
1984
|
});
|
|
@@ -1600,11 +1994,11 @@ var NetworkManager = class {
|
|
|
1600
1994
|
if (!this._swarms.has(topic)) {
|
|
1601
1995
|
return;
|
|
1602
1996
|
}
|
|
1603
|
-
(0,
|
|
1604
|
-
topic:
|
|
1997
|
+
(0, import_log7.log)("leaving", {
|
|
1998
|
+
topic: import_keys8.PublicKey.from(topic)
|
|
1605
1999
|
}, {
|
|
1606
|
-
F:
|
|
1607
|
-
L:
|
|
2000
|
+
F: __dxlog_file7,
|
|
2001
|
+
L: 207,
|
|
1608
2002
|
S: this,
|
|
1609
2003
|
C: (f, a) => f(...a)
|
|
1610
2004
|
});
|
|
@@ -1620,12 +2014,12 @@ var NetworkManager = class {
|
|
|
1620
2014
|
await swarm.destroy();
|
|
1621
2015
|
this._swarms.delete(topic);
|
|
1622
2016
|
await this.topicsUpdated.emit();
|
|
1623
|
-
(0,
|
|
1624
|
-
topic:
|
|
2017
|
+
(0, import_log7.log)("left", {
|
|
2018
|
+
topic: import_keys8.PublicKey.from(topic),
|
|
1625
2019
|
count: this._swarms.size
|
|
1626
2020
|
}, {
|
|
1627
|
-
F:
|
|
1628
|
-
L:
|
|
2021
|
+
F: __dxlog_file7,
|
|
2022
|
+
L: 221,
|
|
1629
2023
|
S: this,
|
|
1630
2024
|
C: (f, a) => f(...a)
|
|
1631
2025
|
});
|
|
@@ -1659,17 +2053,34 @@ var NetworkManager = class {
|
|
|
1659
2053
|
};
|
|
1660
2054
|
|
|
1661
2055
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1662
|
-
var
|
|
2056
|
+
var import_invariant7 = require("@dxos/invariant");
|
|
2057
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
1663
2058
|
var FullyConnectedTopology = class {
|
|
1664
2059
|
toString() {
|
|
1665
2060
|
return "FullyConnectedTopology";
|
|
1666
2061
|
}
|
|
1667
2062
|
init(controller) {
|
|
1668
|
-
(0,
|
|
2063
|
+
(0, import_invariant7.invariant)(!this._controller, "Already initialized", {
|
|
2064
|
+
F: __dxlog_file8,
|
|
2065
|
+
L: 18,
|
|
2066
|
+
S: this,
|
|
2067
|
+
A: [
|
|
2068
|
+
"!this._controller",
|
|
2069
|
+
"'Already initialized'"
|
|
2070
|
+
]
|
|
2071
|
+
});
|
|
1669
2072
|
this._controller = controller;
|
|
1670
2073
|
}
|
|
1671
2074
|
update() {
|
|
1672
|
-
(0,
|
|
2075
|
+
(0, import_invariant7.invariant)(this._controller, "Not initialized", {
|
|
2076
|
+
F: __dxlog_file8,
|
|
2077
|
+
L: 23,
|
|
2078
|
+
S: this,
|
|
2079
|
+
A: [
|
|
2080
|
+
"this._controller",
|
|
2081
|
+
"'Not initialized'"
|
|
2082
|
+
]
|
|
2083
|
+
});
|
|
1673
2084
|
const { candidates: discovered } = this._controller.getState();
|
|
1674
2085
|
for (const peer of discovered) {
|
|
1675
2086
|
this._controller.connect(peer);
|
|
@@ -1683,22 +2094,22 @@ var FullyConnectedTopology = class {
|
|
|
1683
2094
|
};
|
|
1684
2095
|
|
|
1685
2096
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1686
|
-
var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
|
|
1687
2097
|
var import_xor_distance = __toESM(require("xor-distance"));
|
|
1688
|
-
var
|
|
2098
|
+
var import_invariant8 = require("@dxos/invariant");
|
|
2099
|
+
var import_log8 = require("@dxos/log");
|
|
1689
2100
|
|
|
1690
2101
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1691
|
-
var
|
|
1692
|
-
var
|
|
2102
|
+
var import_invariant9 = require("@dxos/invariant");
|
|
2103
|
+
var import_log9 = require("@dxos/log");
|
|
1693
2104
|
|
|
1694
2105
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1695
2106
|
var import_node_stream = require("node:stream");
|
|
1696
|
-
var
|
|
1697
|
-
var import_async7 = require("@dxos/async");
|
|
2107
|
+
var import_async8 = require("@dxos/async");
|
|
1698
2108
|
var import_debug4 = require("@dxos/debug");
|
|
1699
|
-
var
|
|
1700
|
-
var
|
|
1701
|
-
var
|
|
2109
|
+
var import_invariant10 = require("@dxos/invariant");
|
|
2110
|
+
var import_keys9 = require("@dxos/keys");
|
|
2111
|
+
var import_log10 = require("@dxos/log");
|
|
2112
|
+
var import_util7 = require("@dxos/util");
|
|
1702
2113
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
1703
2114
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1704
2115
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1709,7 +2120,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
1709
2120
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1710
2121
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1711
2122
|
}
|
|
1712
|
-
var
|
|
2123
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
1713
2124
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1714
2125
|
var createStreamDelay = (delay) => {
|
|
1715
2126
|
return new import_node_stream.Transform({
|
|
@@ -1726,26 +2137,34 @@ var _MemoryTransport = class {
|
|
|
1726
2137
|
constructor(options) {
|
|
1727
2138
|
var _a2;
|
|
1728
2139
|
this.options = options;
|
|
1729
|
-
this.closed = new
|
|
1730
|
-
this.connected = new
|
|
2140
|
+
this.closed = new import_async8.Event();
|
|
2141
|
+
this.connected = new import_async8.Event();
|
|
1731
2142
|
this.errors = new import_debug4.ErrorStream();
|
|
1732
|
-
this._instanceId =
|
|
1733
|
-
this._remote = new
|
|
2143
|
+
this._instanceId = import_keys9.PublicKey.random();
|
|
2144
|
+
this._remote = new import_async8.Trigger();
|
|
1734
2145
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1735
2146
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1736
2147
|
this._destroyed = false;
|
|
1737
|
-
(0,
|
|
1738
|
-
F:
|
|
2148
|
+
(0, import_log10.log)("creating", void 0, {
|
|
2149
|
+
F: __dxlog_file9,
|
|
1739
2150
|
L: 64,
|
|
1740
2151
|
S: this,
|
|
1741
2152
|
C: (f, a) => f(...a)
|
|
1742
2153
|
});
|
|
1743
|
-
(0,
|
|
2154
|
+
(0, import_invariant10.invariant)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2155
|
+
F: __dxlog_file9,
|
|
2156
|
+
L: 66,
|
|
2157
|
+
S: this,
|
|
2158
|
+
A: [
|
|
2159
|
+
"!MemoryTransport._connections.has(this._instanceId)",
|
|
2160
|
+
"'Duplicate memory connection'"
|
|
2161
|
+
]
|
|
2162
|
+
});
|
|
1744
2163
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1745
2164
|
if (this.options.initiator) {
|
|
1746
2165
|
setTimeout(async () => {
|
|
1747
|
-
(0,
|
|
1748
|
-
F:
|
|
2166
|
+
(0, import_log10.log)("sending signal", void 0, {
|
|
2167
|
+
F: __dxlog_file9,
|
|
1749
2168
|
L: 73,
|
|
1750
2169
|
S: this,
|
|
1751
2170
|
C: (f, a) => f(...a)
|
|
@@ -1774,11 +2193,19 @@ var _MemoryTransport = class {
|
|
|
1774
2193
|
this.closed.emit();
|
|
1775
2194
|
return;
|
|
1776
2195
|
}
|
|
1777
|
-
(0,
|
|
2196
|
+
(0, import_invariant10.invariant)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2197
|
+
F: __dxlog_file9,
|
|
2198
|
+
L: 99,
|
|
2199
|
+
S: this,
|
|
2200
|
+
A: [
|
|
2201
|
+
"!this._remoteConnection._remoteConnection",
|
|
2202
|
+
"`Remote already connected: ${this._remoteInstanceId}`"
|
|
2203
|
+
]
|
|
2204
|
+
});
|
|
1778
2205
|
this._remoteConnection._remoteConnection = this;
|
|
1779
2206
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1780
|
-
(0,
|
|
1781
|
-
F:
|
|
2207
|
+
(0, import_log10.log)("connected", void 0, {
|
|
2208
|
+
F: __dxlog_file9,
|
|
1782
2209
|
L: 103,
|
|
1783
2210
|
S: this,
|
|
1784
2211
|
C: (f, a) => f(...a)
|
|
@@ -1795,8 +2222,8 @@ var _MemoryTransport = class {
|
|
|
1795
2222
|
}
|
|
1796
2223
|
}
|
|
1797
2224
|
async destroy() {
|
|
1798
|
-
(0,
|
|
1799
|
-
F:
|
|
2225
|
+
(0, import_log10.log)("closing", void 0, {
|
|
2226
|
+
F: __dxlog_file9,
|
|
1800
2227
|
L: 124,
|
|
1801
2228
|
S: this,
|
|
1802
2229
|
C: (f, a) => f(...a)
|
|
@@ -1804,8 +2231,8 @@ var _MemoryTransport = class {
|
|
|
1804
2231
|
this._destroyed = true;
|
|
1805
2232
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
1806
2233
|
if (this._remoteConnection) {
|
|
1807
|
-
(0,
|
|
1808
|
-
F:
|
|
2234
|
+
(0, import_log10.log)("closing", void 0, {
|
|
2235
|
+
F: __dxlog_file9,
|
|
1809
2236
|
L: 129,
|
|
1810
2237
|
S: this,
|
|
1811
2238
|
C: (f, a) => f(...a)
|
|
@@ -1817,26 +2244,26 @@ var _MemoryTransport = class {
|
|
|
1817
2244
|
this._remoteConnection.closed.emit();
|
|
1818
2245
|
this._remoteConnection._remoteConnection = void 0;
|
|
1819
2246
|
this._remoteConnection = void 0;
|
|
1820
|
-
(0,
|
|
1821
|
-
F:
|
|
2247
|
+
(0, import_log10.log)("closed", void 0, {
|
|
2248
|
+
F: __dxlog_file9,
|
|
1822
2249
|
L: 147,
|
|
1823
2250
|
S: this,
|
|
1824
2251
|
C: (f, a) => f(...a)
|
|
1825
2252
|
});
|
|
1826
2253
|
}
|
|
1827
2254
|
this.closed.emit();
|
|
1828
|
-
(0,
|
|
1829
|
-
F:
|
|
2255
|
+
(0, import_log10.log)("closed", void 0, {
|
|
2256
|
+
F: __dxlog_file9,
|
|
1830
2257
|
L: 151,
|
|
1831
2258
|
S: this,
|
|
1832
2259
|
C: (f, a) => f(...a)
|
|
1833
2260
|
});
|
|
1834
2261
|
}
|
|
1835
2262
|
signal({ payload }) {
|
|
1836
|
-
(0,
|
|
2263
|
+
(0, import_log10.log)("received signal", {
|
|
1837
2264
|
payload
|
|
1838
2265
|
}, {
|
|
1839
|
-
F:
|
|
2266
|
+
F: __dxlog_file9,
|
|
1840
2267
|
L: 155,
|
|
1841
2268
|
S: this,
|
|
1842
2269
|
C: (f, a) => f(...a)
|
|
@@ -1846,28 +2273,28 @@ var _MemoryTransport = class {
|
|
|
1846
2273
|
}
|
|
1847
2274
|
const transportId = payload.transportId;
|
|
1848
2275
|
if (transportId) {
|
|
1849
|
-
const remoteId =
|
|
2276
|
+
const remoteId = import_keys9.PublicKey.fromHex(transportId);
|
|
1850
2277
|
this._remote.wake(remoteId);
|
|
1851
2278
|
}
|
|
1852
2279
|
}
|
|
1853
2280
|
};
|
|
1854
2281
|
var MemoryTransport = _MemoryTransport;
|
|
1855
2282
|
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
1856
|
-
MemoryTransport._connections = new
|
|
2283
|
+
MemoryTransport._connections = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
|
|
1857
2284
|
_ts_decorate4([
|
|
1858
|
-
|
|
2285
|
+
import_log10.logInfo
|
|
1859
2286
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
1860
2287
|
_ts_decorate4([
|
|
1861
|
-
|
|
2288
|
+
import_log10.logInfo
|
|
1862
2289
|
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
1863
2290
|
|
|
1864
2291
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1865
2292
|
var import_simple_peer = __toESM(require("simple-peer"));
|
|
1866
|
-
var
|
|
1867
|
-
var import_async8 = require("@dxos/async");
|
|
2293
|
+
var import_async9 = require("@dxos/async");
|
|
1868
2294
|
var import_debug5 = require("@dxos/debug");
|
|
1869
|
-
var
|
|
1870
|
-
var
|
|
2295
|
+
var import_invariant11 = require("@dxos/invariant");
|
|
2296
|
+
var import_keys10 = require("@dxos/keys");
|
|
2297
|
+
var import_log11 = require("@dxos/log");
|
|
1871
2298
|
var import_protocols5 = require("@dxos/protocols");
|
|
1872
2299
|
|
|
1873
2300
|
// packages/core/mesh/network-manager/src/transport/webrtc.ts
|
|
@@ -1878,26 +2305,26 @@ try {
|
|
|
1878
2305
|
}
|
|
1879
2306
|
|
|
1880
2307
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1881
|
-
var
|
|
2308
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
|
|
1882
2309
|
var WebRTCTransport = class {
|
|
1883
2310
|
constructor(params) {
|
|
1884
2311
|
var _a2;
|
|
1885
2312
|
this.params = params;
|
|
1886
2313
|
this._closed = false;
|
|
1887
|
-
this.closed = new
|
|
1888
|
-
this.connected = new
|
|
2314
|
+
this.closed = new import_async9.Event();
|
|
2315
|
+
this.connected = new import_async9.Event();
|
|
1889
2316
|
this.errors = new import_debug5.ErrorStream();
|
|
1890
|
-
this._instanceId =
|
|
1891
|
-
|
|
2317
|
+
this._instanceId = import_keys10.PublicKey.random().toHex();
|
|
2318
|
+
import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
|
|
1892
2319
|
id: this._instanceId
|
|
1893
2320
|
}), {
|
|
1894
|
-
F:
|
|
2321
|
+
F: __dxlog_file10,
|
|
1895
2322
|
L: 39,
|
|
1896
2323
|
S: this,
|
|
1897
2324
|
C: (f, a) => f(...a)
|
|
1898
2325
|
});
|
|
1899
|
-
(0,
|
|
1900
|
-
F:
|
|
2326
|
+
(0, import_log11.log)("created connection", params, {
|
|
2327
|
+
F: __dxlog_file10,
|
|
1901
2328
|
L: 40,
|
|
1902
2329
|
S: this,
|
|
1903
2330
|
C: (f, a) => f(...a)
|
|
@@ -1908,8 +2335,8 @@ var WebRTCTransport = class {
|
|
|
1908
2335
|
config: this.params.webrtcConfig
|
|
1909
2336
|
});
|
|
1910
2337
|
this._peer.on("signal", async (data) => {
|
|
1911
|
-
(0,
|
|
1912
|
-
F:
|
|
2338
|
+
(0, import_log11.log)("signal", data, {
|
|
2339
|
+
F: __dxlog_file10,
|
|
1913
2340
|
L: 48,
|
|
1914
2341
|
S: this,
|
|
1915
2342
|
C: (f, a) => f(...a)
|
|
@@ -1921,8 +2348,8 @@ var WebRTCTransport = class {
|
|
|
1921
2348
|
});
|
|
1922
2349
|
});
|
|
1923
2350
|
this._peer.on("connect", () => {
|
|
1924
|
-
(0,
|
|
1925
|
-
F:
|
|
2351
|
+
(0, import_log11.log)("connected", void 0, {
|
|
2352
|
+
F: __dxlog_file10,
|
|
1926
2353
|
L: 53,
|
|
1927
2354
|
S: this,
|
|
1928
2355
|
C: (f, a) => f(...a)
|
|
@@ -1931,8 +2358,8 @@ var WebRTCTransport = class {
|
|
|
1931
2358
|
this.connected.emit();
|
|
1932
2359
|
});
|
|
1933
2360
|
this._peer.on("close", async () => {
|
|
1934
|
-
(0,
|
|
1935
|
-
F:
|
|
2361
|
+
(0, import_log11.log)("closed", void 0, {
|
|
2362
|
+
F: __dxlog_file10,
|
|
1936
2363
|
L: 59,
|
|
1937
2364
|
S: this,
|
|
1938
2365
|
C: (f, a) => f(...a)
|
|
@@ -1946,11 +2373,11 @@ var WebRTCTransport = class {
|
|
|
1946
2373
|
try {
|
|
1947
2374
|
if (typeof ((_a3 = this._peer) == null ? void 0 : _a3._pc.getStats) === "function") {
|
|
1948
2375
|
this._peer._pc.getStats().then((stats) => {
|
|
1949
|
-
|
|
2376
|
+
import_log11.log.warn("report after webrtc error", {
|
|
1950
2377
|
config: this.params.webrtcConfig,
|
|
1951
2378
|
stats
|
|
1952
2379
|
}, {
|
|
1953
|
-
F:
|
|
2380
|
+
F: __dxlog_file10,
|
|
1954
2381
|
L: 71,
|
|
1955
2382
|
S: this,
|
|
1956
2383
|
C: (f, a) => f(...a)
|
|
@@ -1961,18 +2388,18 @@ var WebRTCTransport = class {
|
|
|
1961
2388
|
}
|
|
1962
2389
|
await this.destroy();
|
|
1963
2390
|
});
|
|
1964
|
-
|
|
2391
|
+
import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
|
|
1965
2392
|
id: this._instanceId
|
|
1966
2393
|
}), {
|
|
1967
|
-
F:
|
|
2394
|
+
F: __dxlog_file10,
|
|
1968
2395
|
L: 81,
|
|
1969
2396
|
S: this,
|
|
1970
2397
|
C: (f, a) => f(...a)
|
|
1971
2398
|
});
|
|
1972
2399
|
}
|
|
1973
2400
|
async destroy() {
|
|
1974
|
-
(0,
|
|
1975
|
-
F:
|
|
2401
|
+
(0, import_log11.log)("closing...", void 0, {
|
|
2402
|
+
F: __dxlog_file10,
|
|
1976
2403
|
L: 85,
|
|
1977
2404
|
S: this,
|
|
1978
2405
|
C: (f, a) => f(...a)
|
|
@@ -1981,8 +2408,8 @@ var WebRTCTransport = class {
|
|
|
1981
2408
|
await this._disconnectStreams();
|
|
1982
2409
|
this._peer.destroy();
|
|
1983
2410
|
this.closed.emit();
|
|
1984
|
-
(0,
|
|
1985
|
-
F:
|
|
2411
|
+
(0, import_log11.log)("closed", void 0, {
|
|
2412
|
+
F: __dxlog_file10,
|
|
1986
2413
|
L: 90,
|
|
1987
2414
|
S: this,
|
|
1988
2415
|
C: (f, a) => f(...a)
|
|
@@ -1992,7 +2419,15 @@ var WebRTCTransport = class {
|
|
|
1992
2419
|
if (this._closed) {
|
|
1993
2420
|
return;
|
|
1994
2421
|
}
|
|
1995
|
-
(0,
|
|
2422
|
+
(0, import_invariant11.invariant)(signal.payload.data, "Signal message must contain signal data.", {
|
|
2423
|
+
F: __dxlog_file10,
|
|
2424
|
+
L: 98,
|
|
2425
|
+
S: this,
|
|
2426
|
+
A: [
|
|
2427
|
+
"signal.payload.data",
|
|
2428
|
+
"'Signal message must contain signal data.'"
|
|
2429
|
+
]
|
|
2430
|
+
});
|
|
1996
2431
|
this._peer.signal(signal.payload.data);
|
|
1997
2432
|
}
|
|
1998
2433
|
async _disconnectStreams() {
|
|
@@ -2003,23 +2438,30 @@ var WebRTCTransport = class {
|
|
|
2003
2438
|
|
|
2004
2439
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
2005
2440
|
var import_node_stream2 = require("node:stream");
|
|
2006
|
-
var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
|
|
2007
2441
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
2008
|
-
var
|
|
2009
|
-
var
|
|
2442
|
+
var import_invariant12 = require("@dxos/invariant");
|
|
2443
|
+
var import_keys11 = require("@dxos/keys");
|
|
2444
|
+
var import_log12 = require("@dxos/log");
|
|
2010
2445
|
var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2011
|
-
var
|
|
2012
|
-
var
|
|
2446
|
+
var import_util8 = require("@dxos/util");
|
|
2447
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
|
|
2013
2448
|
var WebRTCTransportService = class {
|
|
2014
2449
|
// prettier-ignore
|
|
2015
2450
|
constructor(_webrtcConfig) {
|
|
2016
2451
|
this._webrtcConfig = _webrtcConfig;
|
|
2017
|
-
this.transports = new
|
|
2452
|
+
this.transports = new import_util8.ComplexMap(import_keys11.PublicKey.hash);
|
|
2018
2453
|
}
|
|
2019
2454
|
open(request) {
|
|
2020
2455
|
const rpcStream = new import_codec_protobuf.Stream(({ ready, next, close }) => {
|
|
2021
2456
|
const duplex = new import_node_stream2.Duplex({
|
|
2022
2457
|
read: () => {
|
|
2458
|
+
const callbacks = [
|
|
2459
|
+
...transportState.writeCallbacks
|
|
2460
|
+
];
|
|
2461
|
+
transportState.writeCallbacks.length = 0;
|
|
2462
|
+
for (const cb of callbacks) {
|
|
2463
|
+
cb();
|
|
2464
|
+
}
|
|
2023
2465
|
},
|
|
2024
2466
|
write: function(chunk, _, callback) {
|
|
2025
2467
|
next({
|
|
@@ -2071,30 +2513,54 @@ var WebRTCTransportService = class {
|
|
|
2071
2513
|
});
|
|
2072
2514
|
close();
|
|
2073
2515
|
});
|
|
2074
|
-
|
|
2075
|
-
this.transports.set(request.proxyId, {
|
|
2516
|
+
const transportState = {
|
|
2076
2517
|
transport,
|
|
2077
|
-
stream: duplex
|
|
2078
|
-
|
|
2518
|
+
stream: duplex,
|
|
2519
|
+
writeCallbacks: []
|
|
2520
|
+
};
|
|
2521
|
+
ready();
|
|
2522
|
+
this.transports.set(request.proxyId, transportState);
|
|
2079
2523
|
});
|
|
2080
2524
|
return rpcStream;
|
|
2081
2525
|
}
|
|
2082
2526
|
async sendSignal({ proxyId, signal }) {
|
|
2083
|
-
(0,
|
|
2527
|
+
(0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
|
|
2528
|
+
F: __dxlog_file11,
|
|
2529
|
+
L: 113,
|
|
2530
|
+
S: this,
|
|
2531
|
+
A: [
|
|
2532
|
+
"this.transports.has(proxyId)",
|
|
2533
|
+
""
|
|
2534
|
+
]
|
|
2535
|
+
});
|
|
2084
2536
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2085
2537
|
}
|
|
2086
2538
|
async sendData({ proxyId, payload }) {
|
|
2087
|
-
(0,
|
|
2088
|
-
|
|
2539
|
+
(0, import_invariant12.invariant)(this.transports.has(proxyId), void 0, {
|
|
2540
|
+
F: __dxlog_file11,
|
|
2541
|
+
L: 118,
|
|
2542
|
+
S: this,
|
|
2543
|
+
A: [
|
|
2544
|
+
"this.transports.has(proxyId)",
|
|
2545
|
+
""
|
|
2546
|
+
]
|
|
2547
|
+
});
|
|
2548
|
+
const state = this.transports.get(proxyId);
|
|
2549
|
+
const bufferHasSpace = state.stream.push(payload);
|
|
2550
|
+
if (!bufferHasSpace) {
|
|
2551
|
+
await new Promise((resolve) => {
|
|
2552
|
+
state.writeCallbacks.push(resolve);
|
|
2553
|
+
});
|
|
2554
|
+
}
|
|
2089
2555
|
}
|
|
2090
2556
|
async close({ proxyId }) {
|
|
2091
2557
|
var _a2, _b;
|
|
2092
2558
|
await ((_a2 = this.transports.get(proxyId)) == null ? void 0 : _a2.transport.destroy());
|
|
2093
2559
|
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
2094
2560
|
this.transports.delete(proxyId);
|
|
2095
|
-
(0,
|
|
2096
|
-
F:
|
|
2097
|
-
L:
|
|
2561
|
+
(0, import_log12.log)("Closed.", void 0, {
|
|
2562
|
+
F: __dxlog_file11,
|
|
2563
|
+
L: 132,
|
|
2098
2564
|
S: this,
|
|
2099
2565
|
C: (f, a) => f(...a)
|
|
2100
2566
|
});
|
|
@@ -2102,24 +2568,25 @@ var WebRTCTransportService = class {
|
|
|
2102
2568
|
};
|
|
2103
2569
|
|
|
2104
2570
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2105
|
-
var
|
|
2106
|
-
var
|
|
2107
|
-
var
|
|
2571
|
+
var import_node_stream3 = require("node:stream");
|
|
2572
|
+
var import_async10 = require("@dxos/async");
|
|
2573
|
+
var import_context6 = require("@dxos/context");
|
|
2108
2574
|
var import_debug6 = require("@dxos/debug");
|
|
2109
|
-
var
|
|
2110
|
-
var
|
|
2575
|
+
var import_invariant13 = require("@dxos/invariant");
|
|
2576
|
+
var import_keys12 = require("@dxos/keys");
|
|
2577
|
+
var import_log13 = require("@dxos/log");
|
|
2111
2578
|
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2112
|
-
var
|
|
2113
|
-
var
|
|
2579
|
+
var import_util9 = require("@dxos/util");
|
|
2580
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
|
|
2114
2581
|
var WebRTCTransportProxy = class {
|
|
2115
2582
|
// prettier-ignore
|
|
2116
2583
|
constructor(_params) {
|
|
2117
2584
|
this._params = _params;
|
|
2118
|
-
this._proxyId =
|
|
2119
|
-
this._ctx = new
|
|
2120
|
-
this.closed = new
|
|
2585
|
+
this._proxyId = import_keys12.PublicKey.random();
|
|
2586
|
+
this._ctx = new import_context6.Context();
|
|
2587
|
+
this.closed = new import_async10.Event();
|
|
2121
2588
|
this._closed = false;
|
|
2122
|
-
this.connected = new
|
|
2589
|
+
this.connected = new import_async10.Event();
|
|
2123
2590
|
this.errors = new import_debug6.ErrorStream();
|
|
2124
2591
|
this._serviceStream = this._params.bridgeService.open({
|
|
2125
2592
|
proxyId: this._proxyId,
|
|
@@ -2127,9 +2594,9 @@ var WebRTCTransportProxy = class {
|
|
|
2127
2594
|
});
|
|
2128
2595
|
this._serviceStream.waitUntilReady().then(() => {
|
|
2129
2596
|
this._serviceStream.subscribe(async (event) => {
|
|
2130
|
-
(0,
|
|
2131
|
-
F:
|
|
2132
|
-
L:
|
|
2597
|
+
(0, import_log13.log)("WebRTCTransportProxy: event", event, {
|
|
2598
|
+
F: __dxlog_file12,
|
|
2599
|
+
L: 51,
|
|
2133
2600
|
S: this,
|
|
2134
2601
|
C: (f, a) => f(...a)
|
|
2135
2602
|
});
|
|
@@ -2141,28 +2608,24 @@ var WebRTCTransportProxy = class {
|
|
|
2141
2608
|
await this._handleSignal(event.signal);
|
|
2142
2609
|
}
|
|
2143
2610
|
});
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2611
|
+
this._params.stream.pipe(new import_node_stream3.Writable({
|
|
2612
|
+
write: (chunk, _, callback) => {
|
|
2613
|
+
this._params.bridgeService.sendData({
|
|
2147
2614
|
proxyId: this._proxyId,
|
|
2148
|
-
payload:
|
|
2149
|
-
})
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2615
|
+
payload: chunk
|
|
2616
|
+
}).then(() => callback(), (err) => {
|
|
2617
|
+
import_log13.log.catch(err, void 0, {
|
|
2618
|
+
F: __dxlog_file12,
|
|
2619
|
+
L: 69,
|
|
2620
|
+
S: this,
|
|
2621
|
+
C: (f, a) => f(...a)
|
|
2622
|
+
});
|
|
2156
2623
|
});
|
|
2157
2624
|
}
|
|
2158
|
-
};
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
});
|
|
2163
|
-
}, (error) => import_log12.log.catch(error, void 0, {
|
|
2164
|
-
F: __dxlog_file10,
|
|
2165
|
-
L: 73,
|
|
2625
|
+
}));
|
|
2626
|
+
}, (error) => import_log13.log.catch(error, void 0, {
|
|
2627
|
+
F: __dxlog_file12,
|
|
2628
|
+
L: 75,
|
|
2166
2629
|
S: this,
|
|
2167
2630
|
C: (f, a) => f(...a)
|
|
2168
2631
|
}));
|
|
@@ -2183,7 +2646,7 @@ var WebRTCTransportProxy = class {
|
|
|
2183
2646
|
}
|
|
2184
2647
|
}
|
|
2185
2648
|
_handleData(dataEvent) {
|
|
2186
|
-
this._params.stream.write((0,
|
|
2649
|
+
this._params.stream.write((0, import_util9.arrayToBuffer)(dataEvent.payload));
|
|
2187
2650
|
}
|
|
2188
2651
|
async _handleSignal(signalEvent) {
|
|
2189
2652
|
await this._params.sendSignal(signalEvent.payload);
|
|
@@ -2206,9 +2669,9 @@ var WebRTCTransportProxy = class {
|
|
|
2206
2669
|
proxyId: this._proxyId
|
|
2207
2670
|
});
|
|
2208
2671
|
} catch (err) {
|
|
2209
|
-
|
|
2210
|
-
F:
|
|
2211
|
-
L:
|
|
2672
|
+
import_log13.log.catch(err, void 0, {
|
|
2673
|
+
F: __dxlog_file12,
|
|
2674
|
+
L: 126,
|
|
2212
2675
|
S: this,
|
|
2213
2676
|
C: (f, a) => f(...a)
|
|
2214
2677
|
});
|
|
@@ -2242,7 +2705,15 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2242
2705
|
return this;
|
|
2243
2706
|
}
|
|
2244
2707
|
createTransport(options) {
|
|
2245
|
-
(0,
|
|
2708
|
+
(0, import_invariant13.invariant)(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections", {
|
|
2709
|
+
F: __dxlog_file12,
|
|
2710
|
+
L: 163,
|
|
2711
|
+
S: this,
|
|
2712
|
+
A: [
|
|
2713
|
+
"this._bridgeService",
|
|
2714
|
+
"'WebRTCTransportProxyFactory is not ready to open connections'"
|
|
2715
|
+
]
|
|
2716
|
+
});
|
|
2246
2717
|
const transport = new WebRTCTransportProxy({
|
|
2247
2718
|
...options,
|
|
2248
2719
|
bridgeService: this._bridgeService
|
|
@@ -2254,11 +2725,11 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2254
2725
|
};
|
|
2255
2726
|
|
|
2256
2727
|
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
2257
|
-
var
|
|
2258
|
-
var
|
|
2259
|
-
var
|
|
2728
|
+
var import_async11 = require("@dxos/async");
|
|
2729
|
+
var import_keys13 = require("@dxos/keys");
|
|
2730
|
+
var import_log14 = require("@dxos/log");
|
|
2260
2731
|
var import_teleport2 = require("@dxos/teleport");
|
|
2261
|
-
var
|
|
2732
|
+
var import_util10 = require("@dxos/util");
|
|
2262
2733
|
|
|
2263
2734
|
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
2264
2735
|
var import_teleport = require("@dxos/teleport");
|
|
@@ -2279,19 +2750,19 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
2279
2750
|
};
|
|
2280
2751
|
|
|
2281
2752
|
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
2282
|
-
var
|
|
2753
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
|
|
2283
2754
|
var TestWireProtocol = class {
|
|
2284
2755
|
constructor(peerId) {
|
|
2285
2756
|
this.peerId = peerId;
|
|
2286
|
-
this.connections = new
|
|
2287
|
-
this.streamConnections = new
|
|
2288
|
-
this.connected = new
|
|
2289
|
-
this.disconnected = new
|
|
2757
|
+
this.connections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
|
|
2758
|
+
this.streamConnections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
|
|
2759
|
+
this.connected = new import_async11.Event();
|
|
2760
|
+
this.disconnected = new import_async11.Event();
|
|
2290
2761
|
this.factory = createTeleportProtocolFactory(async (teleport) => {
|
|
2291
|
-
(0,
|
|
2762
|
+
(0, import_log14.log)("create", {
|
|
2292
2763
|
remotePeerId: teleport.remotePeerId
|
|
2293
2764
|
}, {
|
|
2294
|
-
F:
|
|
2765
|
+
F: __dxlog_file13,
|
|
2295
2766
|
L: 23,
|
|
2296
2767
|
S: this,
|
|
2297
2768
|
C: (f, a) => f(...a)
|
|
@@ -2318,15 +2789,15 @@ var TestWireProtocol = class {
|
|
|
2318
2789
|
if (this.connections.has(peerId)) {
|
|
2319
2790
|
return this.connections.get(peerId);
|
|
2320
2791
|
}
|
|
2321
|
-
(0,
|
|
2792
|
+
(0, import_log14.log)("waitForConnection", {
|
|
2322
2793
|
peerId
|
|
2323
2794
|
}, {
|
|
2324
|
-
F:
|
|
2795
|
+
F: __dxlog_file13,
|
|
2325
2796
|
L: 47,
|
|
2326
2797
|
S: this,
|
|
2327
2798
|
C: (f, a) => f(...a)
|
|
2328
2799
|
});
|
|
2329
|
-
await (0,
|
|
2800
|
+
await (0, import_async11.asyncTimeout)(
|
|
2330
2801
|
this.connected.waitFor((connectedId) => connectedId.equals(peerId)),
|
|
2331
2802
|
// TODO(nf): Make this configurable.
|
|
2332
2803
|
1e4
|
|
@@ -2372,7 +2843,7 @@ var TestBuilder = class {
|
|
|
2372
2843
|
}
|
|
2373
2844
|
return new import_messaging2.MemorySignalManager(this._signalContext);
|
|
2374
2845
|
}
|
|
2375
|
-
createPeer(peerId =
|
|
2846
|
+
createPeer(peerId = import_keys14.PublicKey.random()) {
|
|
2376
2847
|
return new TestPeer(this, peerId);
|
|
2377
2848
|
}
|
|
2378
2849
|
};
|
|
@@ -2380,7 +2851,7 @@ var TestPeer = class {
|
|
|
2380
2851
|
constructor(testBuilder, peerId) {
|
|
2381
2852
|
this.testBuilder = testBuilder;
|
|
2382
2853
|
this.peerId = peerId;
|
|
2383
|
-
this._swarms = new
|
|
2854
|
+
this._swarms = new import_util11.ComplexMap(import_keys14.PublicKey.hash);
|
|
2384
2855
|
this._signalManager = this.testBuilder.createSignalManager();
|
|
2385
2856
|
this._networkManager = this.createNetworkManager();
|
|
2386
2857
|
}
|