@dxos/network-manager 0.8.4-main.ae835ea → 0.8.4-main.bc674ce
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-E3P563GT.mjs → chunk-AQSYW43M.mjs} +412 -735
- package/dist/lib/browser/chunk-AQSYW43M.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +342 -4
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/browser/transport/tcp/index.mjs +2 -33
- package/dist/lib/browser/transport/tcp/index.mjs.map +4 -4
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs +36 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs.map +7 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs +160 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-PKBROUZV.mjs → chunk-SCX3PZRE.mjs} +412 -735
- package/dist/lib/node-esm/chunk-SCX3PZRE.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +342 -4
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +1 -1
- package/dist/lib/node-esm/transport/tcp/index.mjs +2 -157
- package/dist/lib/node-esm/transport/tcp/index.mjs.map +4 -4
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs +36 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs.map +7 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs +160 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs.map +7 -0
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/transport/tcp/index.d.ts +1 -1
- package/dist/types/src/transport/tcp/index.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/wire-protocol.d.ts +5 -5
- package/dist/types/src/wire-protocol.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -22
- package/src/swarm/connection.test.ts +2 -1
- package/src/swarm/connection.ts +7 -5
- package/src/swarm/peer.ts +2 -1
- package/src/swarm/swarm.test.ts +2 -1
- package/src/tests/webrtc-transport.test.ts +4 -2
- package/src/transport/tcp/index.ts +1 -1
- package/src/transport/webrtc/rtc-peer-connection.ts +1 -1
- package/src/transport/webrtc/rtc-transport-channel.ts +1 -1
- package/src/transport/webrtc/rtc-transport-proxy.test.ts +2 -1
- package/src/transport/webrtc/rtc-transport-proxy.ts +6 -4
- package/src/transport/webrtc/rtc-transport.test.ts +2 -1
- package/src/wire-protocol.ts +6 -6
- package/dist/lib/browser/chunk-E3P563GT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-PKBROUZV.mjs.map +0 -7
|
@@ -144,21 +144,25 @@ var Connection = class {
|
|
|
144
144
|
});
|
|
145
145
|
this._protocolClosed.wake();
|
|
146
146
|
this.close({
|
|
147
|
-
error: new ProtocolError(
|
|
147
|
+
error: new ProtocolError({
|
|
148
|
+
message: "protocol stream closed"
|
|
149
|
+
})
|
|
148
150
|
}).catch((err) => this.errors.raise(err));
|
|
149
151
|
});
|
|
150
152
|
scheduleTask(this.connectedTimeoutContext, async () => {
|
|
151
153
|
log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
|
|
152
154
|
F: __dxlog_file,
|
|
153
|
-
L:
|
|
155
|
+
L: 196,
|
|
154
156
|
S: this,
|
|
155
157
|
C: (f, a) => f(...a)
|
|
156
158
|
});
|
|
157
|
-
await this.abort(new TimeoutError(
|
|
159
|
+
await this.abort(new TimeoutError({
|
|
160
|
+
message: `${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`
|
|
161
|
+
})).catch((err) => this.errors.raise(err));
|
|
158
162
|
}, TRANSPORT_CONNECTION_TIMEOUT);
|
|
159
163
|
invariant(!this._transport, void 0, {
|
|
160
164
|
F: __dxlog_file,
|
|
161
|
-
L:
|
|
165
|
+
L: 204,
|
|
162
166
|
S: this,
|
|
163
167
|
A: [
|
|
164
168
|
"!this._transport",
|
|
@@ -185,7 +189,7 @@ var Connection = class {
|
|
|
185
189
|
this._transportClosed.wake();
|
|
186
190
|
log("abort triggered by transport close", void 0, {
|
|
187
191
|
F: __dxlog_file,
|
|
188
|
-
L:
|
|
192
|
+
L: 226,
|
|
189
193
|
S: this,
|
|
190
194
|
C: (f, a) => f(...a)
|
|
191
195
|
});
|
|
@@ -196,7 +200,7 @@ var Connection = class {
|
|
|
196
200
|
err
|
|
197
201
|
}, {
|
|
198
202
|
F: __dxlog_file,
|
|
199
|
-
L:
|
|
203
|
+
L: 231,
|
|
200
204
|
S: this,
|
|
201
205
|
C: (f, a) => f(...a)
|
|
202
206
|
});
|
|
@@ -206,7 +210,7 @@ var Connection = class {
|
|
|
206
210
|
if (err instanceof ConnectionResetError) {
|
|
207
211
|
log.info("aborting due to transport ConnectionResetError", void 0, {
|
|
208
212
|
F: __dxlog_file,
|
|
209
|
-
L:
|
|
213
|
+
L: 238,
|
|
210
214
|
S: this,
|
|
211
215
|
C: (f, a) => f(...a)
|
|
212
216
|
});
|
|
@@ -214,7 +218,7 @@ var Connection = class {
|
|
|
214
218
|
} else if (err instanceof ConnectivityError) {
|
|
215
219
|
log.info("aborting due to transport ConnectivityError", void 0, {
|
|
216
220
|
F: __dxlog_file,
|
|
217
|
-
L:
|
|
221
|
+
L: 241,
|
|
218
222
|
S: this,
|
|
219
223
|
C: (f, a) => f(...a)
|
|
220
224
|
});
|
|
@@ -234,7 +238,7 @@ var Connection = class {
|
|
|
234
238
|
id: this._instanceId
|
|
235
239
|
}), {
|
|
236
240
|
F: __dxlog_file,
|
|
237
|
-
L:
|
|
241
|
+
L: 260,
|
|
238
242
|
S: this,
|
|
239
243
|
C: (f, a) => f(...a)
|
|
240
244
|
});
|
|
@@ -244,14 +248,14 @@ var Connection = class {
|
|
|
244
248
|
err
|
|
245
249
|
}, {
|
|
246
250
|
F: __dxlog_file,
|
|
247
|
-
L:
|
|
251
|
+
L: 267,
|
|
248
252
|
S: this,
|
|
249
253
|
C: (f, a) => f(...a)
|
|
250
254
|
});
|
|
251
255
|
if (this._state === "CLOSED" || this._state === "ABORTED") {
|
|
252
256
|
log(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
253
257
|
F: __dxlog_file,
|
|
254
|
-
L:
|
|
258
|
+
L: 269,
|
|
255
259
|
S: this,
|
|
256
260
|
C: (f, a) => f(...a)
|
|
257
261
|
});
|
|
@@ -268,7 +272,7 @@ var Connection = class {
|
|
|
268
272
|
err
|
|
269
273
|
}, {
|
|
270
274
|
F: __dxlog_file,
|
|
271
|
-
L:
|
|
275
|
+
L: 281,
|
|
272
276
|
S: this,
|
|
273
277
|
C: (f, a) => f(...a)
|
|
274
278
|
});
|
|
@@ -279,7 +283,7 @@ var Connection = class {
|
|
|
279
283
|
} catch (err2) {
|
|
280
284
|
log.catch(err2, void 0, {
|
|
281
285
|
F: __dxlog_file,
|
|
282
|
-
L:
|
|
286
|
+
L: 287,
|
|
283
287
|
S: this,
|
|
284
288
|
C: (f, a) => f(...a)
|
|
285
289
|
});
|
|
@@ -289,7 +293,7 @@ var Connection = class {
|
|
|
289
293
|
} catch (err2) {
|
|
290
294
|
log.catch(err2, void 0, {
|
|
291
295
|
F: __dxlog_file,
|
|
292
|
-
L:
|
|
296
|
+
L: 294,
|
|
293
297
|
S: this,
|
|
294
298
|
C: (f, a) => f(...a)
|
|
295
299
|
});
|
|
@@ -299,7 +303,7 @@ var Connection = class {
|
|
|
299
303
|
} catch (err2) {
|
|
300
304
|
log.catch(err2, void 0, {
|
|
301
305
|
F: __dxlog_file,
|
|
302
|
-
L:
|
|
306
|
+
L: 300,
|
|
303
307
|
S: this,
|
|
304
308
|
C: (f, a) => f(...a)
|
|
305
309
|
});
|
|
@@ -311,7 +315,7 @@ var Connection = class {
|
|
|
311
315
|
error
|
|
312
316
|
}, {
|
|
313
317
|
F: __dxlog_file,
|
|
314
|
-
L:
|
|
318
|
+
L: 307,
|
|
315
319
|
S: this,
|
|
316
320
|
C: (f, a) => f(...a)
|
|
317
321
|
});
|
|
@@ -326,7 +330,7 @@ var Connection = class {
|
|
|
326
330
|
error
|
|
327
331
|
}, {
|
|
328
332
|
F: __dxlog_file,
|
|
329
|
-
L:
|
|
333
|
+
L: 318,
|
|
330
334
|
S: this,
|
|
331
335
|
C: (f, a) => f(...a)
|
|
332
336
|
});
|
|
@@ -340,7 +344,7 @@ var Connection = class {
|
|
|
340
344
|
if (lastState !== "CONNECTED" || error != null) {
|
|
341
345
|
log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
342
346
|
F: __dxlog_file,
|
|
343
|
-
L:
|
|
347
|
+
L: 329,
|
|
344
348
|
S: this,
|
|
345
349
|
C: (f, a) => f(...a)
|
|
346
350
|
});
|
|
@@ -352,7 +356,7 @@ var Connection = class {
|
|
|
352
356
|
error
|
|
353
357
|
}, {
|
|
354
358
|
F: __dxlog_file,
|
|
355
|
-
L:
|
|
359
|
+
L: 333,
|
|
356
360
|
S: this,
|
|
357
361
|
C: (f, a) => f(...a)
|
|
358
362
|
});
|
|
@@ -363,7 +367,7 @@ var Connection = class {
|
|
|
363
367
|
} catch (err) {
|
|
364
368
|
log.catch(err, void 0, {
|
|
365
369
|
F: __dxlog_file,
|
|
366
|
-
L:
|
|
370
|
+
L: 338,
|
|
367
371
|
S: this,
|
|
368
372
|
C: (f, a) => f(...a)
|
|
369
373
|
});
|
|
@@ -373,7 +377,7 @@ var Connection = class {
|
|
|
373
377
|
} catch (err) {
|
|
374
378
|
log.catch(err, void 0, {
|
|
375
379
|
F: __dxlog_file,
|
|
376
|
-
L:
|
|
380
|
+
L: 344,
|
|
377
381
|
S: this,
|
|
378
382
|
C: (f, a) => f(...a)
|
|
379
383
|
});
|
|
@@ -382,7 +386,7 @@ var Connection = class {
|
|
|
382
386
|
peerId: this.localInfo
|
|
383
387
|
}, {
|
|
384
388
|
F: __dxlog_file,
|
|
385
|
-
L:
|
|
389
|
+
L: 347,
|
|
386
390
|
S: this,
|
|
387
391
|
C: (f, a) => f(...a)
|
|
388
392
|
});
|
|
@@ -392,7 +396,7 @@ var Connection = class {
|
|
|
392
396
|
async _closeProtocol(options) {
|
|
393
397
|
log("closing protocol", options, {
|
|
394
398
|
F: __dxlog_file,
|
|
395
|
-
L:
|
|
399
|
+
L: 353,
|
|
396
400
|
S: this,
|
|
397
401
|
C: (f, a) => f(...a)
|
|
398
402
|
});
|
|
@@ -402,7 +406,7 @@ var Connection = class {
|
|
|
402
406
|
]);
|
|
403
407
|
log("protocol closed", options, {
|
|
404
408
|
F: __dxlog_file,
|
|
405
|
-
L:
|
|
409
|
+
L: 355,
|
|
406
410
|
S: this,
|
|
407
411
|
C: (f, a) => f(...a)
|
|
408
412
|
});
|
|
@@ -410,7 +414,7 @@ var Connection = class {
|
|
|
410
414
|
async _closeTransport() {
|
|
411
415
|
log("closing transport", void 0, {
|
|
412
416
|
F: __dxlog_file,
|
|
413
|
-
L:
|
|
417
|
+
L: 359,
|
|
414
418
|
S: this,
|
|
415
419
|
C: (f, a) => f(...a)
|
|
416
420
|
});
|
|
@@ -420,7 +424,7 @@ var Connection = class {
|
|
|
420
424
|
]);
|
|
421
425
|
log("transport closed", void 0, {
|
|
422
426
|
F: __dxlog_file,
|
|
423
|
-
L:
|
|
427
|
+
L: 361,
|
|
424
428
|
S: this,
|
|
425
429
|
C: (f, a) => f(...a)
|
|
426
430
|
});
|
|
@@ -461,12 +465,15 @@ var Connection = class {
|
|
|
461
465
|
err
|
|
462
466
|
}, {
|
|
463
467
|
F: __dxlog_file,
|
|
464
|
-
L:
|
|
468
|
+
L: 401,
|
|
465
469
|
S: this,
|
|
466
470
|
C: (f, a) => f(...a)
|
|
467
471
|
});
|
|
468
472
|
await this.close({
|
|
469
|
-
error: new ConnectivityError(
|
|
473
|
+
error: new ConnectivityError({
|
|
474
|
+
message: "signal message failed to deliver",
|
|
475
|
+
cause: err
|
|
476
|
+
})
|
|
470
477
|
});
|
|
471
478
|
}
|
|
472
479
|
}
|
|
@@ -476,7 +483,7 @@ var Connection = class {
|
|
|
476
483
|
async signal(msg) {
|
|
477
484
|
invariant(msg.sessionId, void 0, {
|
|
478
485
|
F: __dxlog_file,
|
|
479
|
-
L:
|
|
486
|
+
L: 410,
|
|
480
487
|
S: this,
|
|
481
488
|
A: [
|
|
482
489
|
"msg.sessionId",
|
|
@@ -486,7 +493,7 @@ var Connection = class {
|
|
|
486
493
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
487
494
|
log("dropping signal for incorrect session id", void 0, {
|
|
488
495
|
F: __dxlog_file,
|
|
489
|
-
L:
|
|
496
|
+
L: 412,
|
|
490
497
|
S: this,
|
|
491
498
|
C: (f, a) => f(...a)
|
|
492
499
|
});
|
|
@@ -494,7 +501,7 @@ var Connection = class {
|
|
|
494
501
|
}
|
|
495
502
|
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
496
503
|
F: __dxlog_file,
|
|
497
|
-
L:
|
|
504
|
+
L: 415,
|
|
498
505
|
S: this,
|
|
499
506
|
A: [
|
|
500
507
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -503,7 +510,7 @@ var Connection = class {
|
|
|
503
510
|
});
|
|
504
511
|
invariant(msg.author.peerKey === this.remoteInfo.peerKey, void 0, {
|
|
505
512
|
F: __dxlog_file,
|
|
506
|
-
L:
|
|
513
|
+
L: 416,
|
|
507
514
|
S: this,
|
|
508
515
|
A: [
|
|
509
516
|
"msg.author.peerKey === this.remoteInfo.peerKey",
|
|
@@ -512,7 +519,7 @@ var Connection = class {
|
|
|
512
519
|
});
|
|
513
520
|
invariant(msg.recipient.peerKey === this.localInfo.peerKey, void 0, {
|
|
514
521
|
F: __dxlog_file,
|
|
515
|
-
L:
|
|
522
|
+
L: 417,
|
|
516
523
|
S: this,
|
|
517
524
|
A: [
|
|
518
525
|
"msg.recipient.peerKey === this.localInfo.peerKey",
|
|
@@ -536,7 +543,7 @@ var Connection = class {
|
|
|
536
543
|
msg: msg.data
|
|
537
544
|
}, {
|
|
538
545
|
F: __dxlog_file,
|
|
539
|
-
L:
|
|
546
|
+
L: 426,
|
|
540
547
|
S: this,
|
|
541
548
|
C: (f, a) => f(...a)
|
|
542
549
|
});
|
|
@@ -544,7 +551,7 @@ var Connection = class {
|
|
|
544
551
|
} else {
|
|
545
552
|
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
546
553
|
F: __dxlog_file,
|
|
547
|
-
L:
|
|
554
|
+
L: 429,
|
|
548
555
|
S: this,
|
|
549
556
|
A: [
|
|
550
557
|
"this._transport",
|
|
@@ -557,7 +564,7 @@ var Connection = class {
|
|
|
557
564
|
msg: msg.data
|
|
558
565
|
}, {
|
|
559
566
|
F: __dxlog_file,
|
|
560
|
-
L:
|
|
567
|
+
L: 430,
|
|
561
568
|
S: this,
|
|
562
569
|
C: (f, a) => f(...a)
|
|
563
570
|
});
|
|
@@ -575,13 +582,13 @@ var Connection = class {
|
|
|
575
582
|
peerId: this.localInfo
|
|
576
583
|
}, {
|
|
577
584
|
F: __dxlog_file,
|
|
578
|
-
L:
|
|
585
|
+
L: 441,
|
|
579
586
|
S: this,
|
|
580
587
|
C: (f, a) => f(...a)
|
|
581
588
|
});
|
|
582
589
|
invariant(state !== this._state, "Already in this state.", {
|
|
583
590
|
F: __dxlog_file,
|
|
584
|
-
L:
|
|
591
|
+
L: 442,
|
|
585
592
|
S: this,
|
|
586
593
|
A: [
|
|
587
594
|
"state !== this._state",
|
|
@@ -608,52 +615,19 @@ _ts_decorate([
|
|
|
608
615
|
synchronized
|
|
609
616
|
], Connection.prototype, "close", null);
|
|
610
617
|
|
|
611
|
-
// src/signal/ice.ts
|
|
612
|
-
import { asyncTimeout } from "@dxos/async";
|
|
613
|
-
import { log as log2 } from "@dxos/log";
|
|
614
|
-
import { isNonNullable } from "@dxos/util";
|
|
615
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/ice.ts";
|
|
616
|
-
var createIceProvider = (iceProviders) => {
|
|
617
|
-
let cachedIceServers;
|
|
618
|
-
return {
|
|
619
|
-
getIceServers: async () => {
|
|
620
|
-
if (cachedIceServers) {
|
|
621
|
-
return cachedIceServers;
|
|
622
|
-
}
|
|
623
|
-
cachedIceServers = (await Promise.all(iceProviders.map(({ urls }) => asyncTimeout(fetch(urls, {
|
|
624
|
-
method: "GET"
|
|
625
|
-
}), 1e4).then((response) => response.json()).catch((err) => {
|
|
626
|
-
const isDev = typeof window !== "undefined" && window.location.href.includes("localhost");
|
|
627
|
-
if (!isDev) {
|
|
628
|
-
log2.error("Failed to fetch ICE servers from provider", {
|
|
629
|
-
urls,
|
|
630
|
-
err
|
|
631
|
-
}, {
|
|
632
|
-
F: __dxlog_file2,
|
|
633
|
-
L: 30,
|
|
634
|
-
S: void 0,
|
|
635
|
-
C: (f, a) => f(...a)
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
})))).filter(isNonNullable).map(({ iceServers }) => iceServers).flat();
|
|
639
|
-
return cachedIceServers;
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
};
|
|
643
|
-
|
|
644
618
|
// src/signal/swarm-messenger.ts
|
|
645
619
|
import { Context as Context2 } from "@dxos/context";
|
|
646
620
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
647
621
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
648
|
-
import { log as
|
|
622
|
+
import { log as log2 } from "@dxos/log";
|
|
649
623
|
import { TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
650
624
|
import { schema } from "@dxos/protocols/proto";
|
|
651
625
|
import { ComplexMap } from "@dxos/util";
|
|
652
|
-
var
|
|
626
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
653
627
|
var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
654
628
|
var SwarmMessenger = class {
|
|
655
629
|
_ctx = new Context2(void 0, {
|
|
656
|
-
F:
|
|
630
|
+
F: __dxlog_file2,
|
|
657
631
|
L: 35
|
|
658
632
|
});
|
|
659
633
|
_sendMessage;
|
|
@@ -675,12 +649,12 @@ var SwarmMessenger = class {
|
|
|
675
649
|
if (!this._topic.equals(message.topic)) {
|
|
676
650
|
return;
|
|
677
651
|
}
|
|
678
|
-
|
|
652
|
+
log2("received", {
|
|
679
653
|
from: author,
|
|
680
654
|
to: recipient,
|
|
681
655
|
msg: message
|
|
682
656
|
}, {
|
|
683
|
-
F:
|
|
657
|
+
F: __dxlog_file2,
|
|
684
658
|
L: 71,
|
|
685
659
|
S: this,
|
|
686
660
|
C: (f, a) => f(...a)
|
|
@@ -706,10 +680,10 @@ var SwarmMessenger = class {
|
|
|
706
680
|
message
|
|
707
681
|
});
|
|
708
682
|
} else {
|
|
709
|
-
|
|
683
|
+
log2.warn("unknown message", {
|
|
710
684
|
message
|
|
711
685
|
}, {
|
|
712
|
-
F:
|
|
686
|
+
F: __dxlog_file2,
|
|
713
687
|
L: 82,
|
|
714
688
|
S: this,
|
|
715
689
|
C: (f, a) => f(...a)
|
|
@@ -718,7 +692,7 @@ var SwarmMessenger = class {
|
|
|
718
692
|
}
|
|
719
693
|
async signal(message) {
|
|
720
694
|
invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
721
|
-
F:
|
|
695
|
+
F: __dxlog_file2,
|
|
722
696
|
L: 87,
|
|
723
697
|
S: this,
|
|
724
698
|
A: [
|
|
@@ -754,12 +728,12 @@ var SwarmMessenger = class {
|
|
|
754
728
|
// Setting unique message_id if it not specified yet.
|
|
755
729
|
messageId: message.messageId ?? PublicKey2.random()
|
|
756
730
|
};
|
|
757
|
-
|
|
731
|
+
log2("sending", {
|
|
758
732
|
from: author,
|
|
759
733
|
to: recipient,
|
|
760
734
|
msg: networkMessage
|
|
761
735
|
}, {
|
|
762
|
-
F:
|
|
736
|
+
F: __dxlog_file2,
|
|
763
737
|
L: 125,
|
|
764
738
|
S: this,
|
|
765
739
|
C: (f, a) => f(...a)
|
|
@@ -775,7 +749,7 @@ var SwarmMessenger = class {
|
|
|
775
749
|
}
|
|
776
750
|
async _resolveAnswers(message) {
|
|
777
751
|
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
778
|
-
F:
|
|
752
|
+
F: __dxlog_file2,
|
|
779
753
|
L: 137,
|
|
780
754
|
S: this,
|
|
781
755
|
A: [
|
|
@@ -787,7 +761,7 @@ var SwarmMessenger = class {
|
|
|
787
761
|
if (offerRecord) {
|
|
788
762
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
789
763
|
invariant2(message.data?.answer, "No answer", {
|
|
790
|
-
F:
|
|
764
|
+
F: __dxlog_file2,
|
|
791
765
|
L: 141,
|
|
792
766
|
S: this,
|
|
793
767
|
A: [
|
|
@@ -795,10 +769,10 @@ var SwarmMessenger = class {
|
|
|
795
769
|
"'No answer'"
|
|
796
770
|
]
|
|
797
771
|
});
|
|
798
|
-
|
|
772
|
+
log2("resolving", {
|
|
799
773
|
answer: message.data.answer
|
|
800
774
|
}, {
|
|
801
|
-
F:
|
|
775
|
+
F: __dxlog_file2,
|
|
802
776
|
L: 142,
|
|
803
777
|
S: this,
|
|
804
778
|
C: (f, a) => f(...a)
|
|
@@ -808,7 +782,7 @@ var SwarmMessenger = class {
|
|
|
808
782
|
}
|
|
809
783
|
async _handleOffer({ author, recipient, message }) {
|
|
810
784
|
invariant2(message.data.offer, "No offer", {
|
|
811
|
-
F:
|
|
785
|
+
F: __dxlog_file2,
|
|
812
786
|
L: 156,
|
|
813
787
|
S: this,
|
|
814
788
|
A: [
|
|
@@ -840,19 +814,19 @@ var SwarmMessenger = class {
|
|
|
840
814
|
});
|
|
841
815
|
} catch (err) {
|
|
842
816
|
if (err instanceof TimeoutError2) {
|
|
843
|
-
|
|
817
|
+
log2.info("timeout sending answer to offer", {
|
|
844
818
|
err
|
|
845
819
|
}, {
|
|
846
|
-
F:
|
|
820
|
+
F: __dxlog_file2,
|
|
847
821
|
L: 177,
|
|
848
822
|
S: this,
|
|
849
823
|
C: (f, a) => f(...a)
|
|
850
824
|
});
|
|
851
825
|
} else {
|
|
852
|
-
|
|
826
|
+
log2.info("error sending answer to offer", {
|
|
853
827
|
err
|
|
854
828
|
}, {
|
|
855
|
-
F:
|
|
829
|
+
F: __dxlog_file2,
|
|
856
830
|
L: 179,
|
|
857
831
|
S: this,
|
|
858
832
|
C: (f, a) => f(...a)
|
|
@@ -862,7 +836,7 @@ var SwarmMessenger = class {
|
|
|
862
836
|
}
|
|
863
837
|
async _handleSignal({ author, recipient, message }) {
|
|
864
838
|
invariant2(message.messageId, void 0, {
|
|
865
|
-
F:
|
|
839
|
+
F: __dxlog_file2,
|
|
866
840
|
L: 193,
|
|
867
841
|
S: this,
|
|
868
842
|
A: [
|
|
@@ -871,7 +845,7 @@ var SwarmMessenger = class {
|
|
|
871
845
|
]
|
|
872
846
|
});
|
|
873
847
|
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
874
|
-
F:
|
|
848
|
+
F: __dxlog_file2,
|
|
875
849
|
L: 194,
|
|
876
850
|
S: this,
|
|
877
851
|
A: [
|
|
@@ -898,17 +872,17 @@ import { Context as Context4 } from "@dxos/context";
|
|
|
898
872
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
899
873
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
900
874
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
901
|
-
import { log as
|
|
875
|
+
import { log as log4, logInfo as logInfo2 } from "@dxos/log";
|
|
902
876
|
import { PeerInfoHash } from "@dxos/messaging";
|
|
903
877
|
import { trace as trace2 } from "@dxos/protocols";
|
|
904
|
-
import { ComplexMap as ComplexMap2, isNonNullable
|
|
878
|
+
import { ComplexMap as ComplexMap2, isNonNullable } from "@dxos/util";
|
|
905
879
|
|
|
906
880
|
// src/swarm/peer.ts
|
|
907
881
|
import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
|
|
908
882
|
import { Context as Context3 } from "@dxos/context";
|
|
909
883
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
910
884
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
911
|
-
import { log as
|
|
885
|
+
import { log as log3 } from "@dxos/log";
|
|
912
886
|
import { CancelledError as CancelledError2, SystemError } from "@dxos/protocols";
|
|
913
887
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
914
888
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -916,10 +890,12 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
916
890
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
917
891
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
918
892
|
}
|
|
919
|
-
var
|
|
893
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
920
894
|
var ConnectionDisplacedError = class extends SystemError {
|
|
921
895
|
constructor() {
|
|
922
|
-
super(
|
|
896
|
+
super({
|
|
897
|
+
message: "Connection displaced by remote initiator."
|
|
898
|
+
});
|
|
923
899
|
}
|
|
924
900
|
};
|
|
925
901
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
@@ -939,7 +915,7 @@ var Peer = class {
|
|
|
939
915
|
availableToConnect = true;
|
|
940
916
|
_lastConnectionTime;
|
|
941
917
|
_ctx = new Context3(void 0, {
|
|
942
|
-
F:
|
|
918
|
+
F: __dxlog_file3,
|
|
943
919
|
L: 81
|
|
944
920
|
});
|
|
945
921
|
_connectionCtx;
|
|
@@ -970,8 +946,8 @@ var Peer = class {
|
|
|
970
946
|
ConnectionState.INITIAL,
|
|
971
947
|
ConnectionState.CONNECTING
|
|
972
948
|
].includes(this.connection.state)) {
|
|
973
|
-
|
|
974
|
-
F:
|
|
949
|
+
log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
950
|
+
F: __dxlog_file3,
|
|
975
951
|
L: 116,
|
|
976
952
|
S: this,
|
|
977
953
|
C: (f, a) => f(...a)
|
|
@@ -982,13 +958,13 @@ var Peer = class {
|
|
|
982
958
|
}
|
|
983
959
|
if (this.connection || this.initiating) {
|
|
984
960
|
if (remote.peerKey < this.localInfo.peerKey) {
|
|
985
|
-
|
|
961
|
+
log3("close local connection", {
|
|
986
962
|
localPeer: this.localInfo,
|
|
987
963
|
topic: this.topic,
|
|
988
964
|
remotePeer: this.remoteInfo,
|
|
989
965
|
sessionId: this.connection?.sessionId
|
|
990
966
|
}, {
|
|
991
|
-
F:
|
|
967
|
+
F: __dxlog_file3,
|
|
992
968
|
L: 125,
|
|
993
969
|
S: this,
|
|
994
970
|
C: (f, a) => f(...a)
|
|
@@ -1005,7 +981,7 @@ var Peer = class {
|
|
|
1005
981
|
if (await this._callbacks.onOffer(remote)) {
|
|
1006
982
|
if (!this.connection) {
|
|
1007
983
|
invariant3(message.sessionId, void 0, {
|
|
1008
|
-
F:
|
|
984
|
+
F: __dxlog_file3,
|
|
1009
985
|
L: 145,
|
|
1010
986
|
S: this,
|
|
1011
987
|
A: [
|
|
@@ -1020,13 +996,13 @@ var Peer = class {
|
|
|
1020
996
|
await connection.openConnection();
|
|
1021
997
|
} catch (err) {
|
|
1022
998
|
if (!(err instanceof CancelledError2)) {
|
|
1023
|
-
|
|
999
|
+
log3.info("connection error", {
|
|
1024
1000
|
topic: this.topic,
|
|
1025
1001
|
peerId: this.localInfo,
|
|
1026
1002
|
remoteId: this.remoteInfo,
|
|
1027
1003
|
err
|
|
1028
1004
|
}, {
|
|
1029
|
-
F:
|
|
1005
|
+
F: __dxlog_file3,
|
|
1030
1006
|
L: 155,
|
|
1031
1007
|
S: this,
|
|
1032
1008
|
C: (f, a) => f(...a)
|
|
@@ -1048,8 +1024,8 @@ var Peer = class {
|
|
|
1048
1024
|
*/
|
|
1049
1025
|
async initiateConnection() {
|
|
1050
1026
|
invariant3(!this.initiating, "Initiation in progress.", {
|
|
1051
|
-
F:
|
|
1052
|
-
L:
|
|
1027
|
+
F: __dxlog_file3,
|
|
1028
|
+
L: 173,
|
|
1053
1029
|
S: this,
|
|
1054
1030
|
A: [
|
|
1055
1031
|
"!this.initiating",
|
|
@@ -1057,8 +1033,8 @@ var Peer = class {
|
|
|
1057
1033
|
]
|
|
1058
1034
|
});
|
|
1059
1035
|
invariant3(!this.connection, "Already connected.", {
|
|
1060
|
-
F:
|
|
1061
|
-
L:
|
|
1036
|
+
F: __dxlog_file3,
|
|
1037
|
+
L: 174,
|
|
1062
1038
|
S: this,
|
|
1063
1039
|
A: [
|
|
1064
1040
|
"!this.connection",
|
|
@@ -1066,14 +1042,14 @@ var Peer = class {
|
|
|
1066
1042
|
]
|
|
1067
1043
|
});
|
|
1068
1044
|
const sessionId = PublicKey3.random();
|
|
1069
|
-
|
|
1045
|
+
log3("initiating...", {
|
|
1070
1046
|
local: this.localInfo,
|
|
1071
1047
|
topic: this.topic,
|
|
1072
1048
|
remote: this.remoteInfo,
|
|
1073
1049
|
sessionId
|
|
1074
1050
|
}, {
|
|
1075
|
-
F:
|
|
1076
|
-
L:
|
|
1051
|
+
F: __dxlog_file3,
|
|
1052
|
+
L: 176,
|
|
1077
1053
|
S: this,
|
|
1078
1054
|
C: (f, a) => f(...a)
|
|
1079
1055
|
});
|
|
@@ -1092,35 +1068,35 @@ var Peer = class {
|
|
|
1092
1068
|
offer: {}
|
|
1093
1069
|
}
|
|
1094
1070
|
});
|
|
1095
|
-
|
|
1071
|
+
log3("received", {
|
|
1096
1072
|
answer,
|
|
1097
1073
|
topic: this.topic,
|
|
1098
1074
|
local: this.localInfo,
|
|
1099
1075
|
remote: this.remoteInfo
|
|
1100
1076
|
}, {
|
|
1101
|
-
F:
|
|
1102
|
-
L:
|
|
1077
|
+
F: __dxlog_file3,
|
|
1078
|
+
L: 193,
|
|
1103
1079
|
S: this,
|
|
1104
1080
|
C: (f, a) => f(...a)
|
|
1105
1081
|
});
|
|
1106
1082
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1107
|
-
|
|
1108
|
-
F:
|
|
1109
|
-
L:
|
|
1083
|
+
log3("ignoring response", void 0, {
|
|
1084
|
+
F: __dxlog_file3,
|
|
1085
|
+
L: 195,
|
|
1110
1086
|
S: this,
|
|
1111
1087
|
C: (f, a) => f(...a)
|
|
1112
1088
|
});
|
|
1113
1089
|
return;
|
|
1114
1090
|
}
|
|
1115
1091
|
} catch (err) {
|
|
1116
|
-
|
|
1092
|
+
log3("initiation error: send offer", {
|
|
1117
1093
|
err,
|
|
1118
1094
|
topic: this.topic,
|
|
1119
1095
|
local: this.localInfo,
|
|
1120
1096
|
remote: this.remoteInfo
|
|
1121
1097
|
}, {
|
|
1122
|
-
F:
|
|
1123
|
-
L:
|
|
1098
|
+
F: __dxlog_file3,
|
|
1099
|
+
L: 199,
|
|
1124
1100
|
S: this,
|
|
1125
1101
|
C: (f, a) => f(...a)
|
|
1126
1102
|
});
|
|
@@ -1135,14 +1111,14 @@ var Peer = class {
|
|
|
1135
1111
|
return;
|
|
1136
1112
|
}
|
|
1137
1113
|
} catch (err) {
|
|
1138
|
-
|
|
1114
|
+
log3("initiation error: accept answer", {
|
|
1139
1115
|
err,
|
|
1140
1116
|
topic: this.topic,
|
|
1141
1117
|
local: this.localInfo,
|
|
1142
1118
|
remote: this.remoteInfo
|
|
1143
1119
|
}, {
|
|
1144
|
-
F:
|
|
1145
|
-
L:
|
|
1120
|
+
F: __dxlog_file3,
|
|
1121
|
+
L: 212,
|
|
1146
1122
|
S: this,
|
|
1147
1123
|
C: (f, a) => f(...a)
|
|
1148
1124
|
});
|
|
@@ -1152,31 +1128,31 @@ var Peer = class {
|
|
|
1152
1128
|
this.initiating = false;
|
|
1153
1129
|
}
|
|
1154
1130
|
try {
|
|
1155
|
-
|
|
1156
|
-
F:
|
|
1157
|
-
L:
|
|
1131
|
+
log3("opening connection as initiator", void 0, {
|
|
1132
|
+
F: __dxlog_file3,
|
|
1133
|
+
L: 225,
|
|
1158
1134
|
S: this,
|
|
1159
1135
|
C: (f, a) => f(...a)
|
|
1160
1136
|
});
|
|
1161
1137
|
await connection.openConnection();
|
|
1162
1138
|
this._callbacks.onAccepted();
|
|
1163
1139
|
} catch (err) {
|
|
1164
|
-
|
|
1140
|
+
log3("initiation error: open connection", {
|
|
1165
1141
|
err,
|
|
1166
1142
|
topic: this.topic,
|
|
1167
1143
|
local: this.localInfo,
|
|
1168
1144
|
remote: this.remoteInfo
|
|
1169
1145
|
}, {
|
|
1170
|
-
F:
|
|
1171
|
-
L:
|
|
1146
|
+
F: __dxlog_file3,
|
|
1147
|
+
L: 229,
|
|
1172
1148
|
S: this,
|
|
1173
1149
|
C: (f, a) => f(...a)
|
|
1174
1150
|
});
|
|
1175
|
-
|
|
1151
|
+
log3.warn("closing connection due to unhandled error on openConnection", {
|
|
1176
1152
|
err
|
|
1177
1153
|
}, {
|
|
1178
|
-
F:
|
|
1179
|
-
L:
|
|
1154
|
+
F: __dxlog_file3,
|
|
1155
|
+
L: 236,
|
|
1180
1156
|
S: this,
|
|
1181
1157
|
C: (f, a) => f(...a)
|
|
1182
1158
|
});
|
|
@@ -1191,21 +1167,21 @@ var Peer = class {
|
|
|
1191
1167
|
* Either we're initiating a connection or creating one in response to an offer from the other peer.
|
|
1192
1168
|
*/
|
|
1193
1169
|
_createConnection(initiator, sessionId) {
|
|
1194
|
-
|
|
1170
|
+
log3("creating connection", {
|
|
1195
1171
|
topic: this.topic,
|
|
1196
1172
|
peerId: this.localInfo,
|
|
1197
1173
|
remoteId: this.remoteInfo,
|
|
1198
1174
|
initiator,
|
|
1199
1175
|
sessionId
|
|
1200
1176
|
}, {
|
|
1201
|
-
F:
|
|
1202
|
-
L:
|
|
1177
|
+
F: __dxlog_file3,
|
|
1178
|
+
L: 250,
|
|
1203
1179
|
S: this,
|
|
1204
1180
|
C: (f, a) => f(...a)
|
|
1205
1181
|
});
|
|
1206
1182
|
invariant3(!this.connection, "Already connected.", {
|
|
1207
|
-
F:
|
|
1208
|
-
L:
|
|
1183
|
+
F: __dxlog_file3,
|
|
1184
|
+
L: 257,
|
|
1209
1185
|
S: this,
|
|
1210
1186
|
A: [
|
|
1211
1187
|
"!this.connection",
|
|
@@ -1233,15 +1209,15 @@ var Peer = class {
|
|
|
1233
1209
|
this._lastConnectionTime = Date.now();
|
|
1234
1210
|
this._callbacks.onConnected();
|
|
1235
1211
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1236
|
-
|
|
1212
|
+
log3.trace("dxos.mesh.connection.connected", {
|
|
1237
1213
|
topic: this.topic,
|
|
1238
1214
|
localPeerId: this.localInfo,
|
|
1239
1215
|
remotePeerId: this.remoteInfo,
|
|
1240
1216
|
sessionId,
|
|
1241
1217
|
initiator
|
|
1242
1218
|
}, {
|
|
1243
|
-
F:
|
|
1244
|
-
L:
|
|
1219
|
+
F: __dxlog_file3,
|
|
1220
|
+
L: 281,
|
|
1245
1221
|
S: this,
|
|
1246
1222
|
C: (f, a) => f(...a)
|
|
1247
1223
|
});
|
|
@@ -1253,31 +1229,31 @@ var Peer = class {
|
|
|
1253
1229
|
remoteId: this.remoteInfo,
|
|
1254
1230
|
initiator
|
|
1255
1231
|
};
|
|
1256
|
-
|
|
1257
|
-
F:
|
|
1258
|
-
L:
|
|
1232
|
+
log3("connection closed", logMeta, {
|
|
1233
|
+
F: __dxlog_file3,
|
|
1234
|
+
L: 291,
|
|
1259
1235
|
S: this,
|
|
1260
1236
|
C: (f, a) => f(...a)
|
|
1261
1237
|
});
|
|
1262
1238
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1263
1239
|
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1264
|
-
F:
|
|
1265
|
-
L:
|
|
1240
|
+
F: __dxlog_file3,
|
|
1241
|
+
L: 296,
|
|
1266
1242
|
S: this,
|
|
1267
1243
|
A: [
|
|
1268
1244
|
"this.connection === connection",
|
|
1269
1245
|
"'Connection mismatch (race condition).'"
|
|
1270
1246
|
]
|
|
1271
1247
|
});
|
|
1272
|
-
|
|
1248
|
+
log3.trace("dxos.mesh.connection.closed", {
|
|
1273
1249
|
topic: this.topic,
|
|
1274
1250
|
localPeerId: this.localInfo,
|
|
1275
1251
|
remotePeerId: this.remoteInfo,
|
|
1276
1252
|
sessionId,
|
|
1277
1253
|
initiator
|
|
1278
1254
|
}, {
|
|
1279
|
-
F:
|
|
1280
|
-
L:
|
|
1255
|
+
F: __dxlog_file3,
|
|
1256
|
+
L: 298,
|
|
1281
1257
|
S: this,
|
|
1282
1258
|
C: (f, a) => f(...a)
|
|
1283
1259
|
});
|
|
@@ -1292,9 +1268,9 @@ var Peer = class {
|
|
|
1292
1268
|
}
|
|
1293
1269
|
this._callbacks.onDisconnected();
|
|
1294
1270
|
scheduleTask2(this._connectionCtx, () => {
|
|
1295
|
-
|
|
1296
|
-
F:
|
|
1297
|
-
L:
|
|
1271
|
+
log3("peer became available", logMeta, {
|
|
1272
|
+
F: __dxlog_file3,
|
|
1273
|
+
L: 322,
|
|
1298
1274
|
S: this,
|
|
1299
1275
|
C: (f, a) => f(...a)
|
|
1300
1276
|
});
|
|
@@ -1310,19 +1286,19 @@ var Peer = class {
|
|
|
1310
1286
|
void this._connectionCtx?.dispose();
|
|
1311
1287
|
this._connectionCtx = this._ctx.derive();
|
|
1312
1288
|
connection.errors.handle((err) => {
|
|
1313
|
-
|
|
1289
|
+
log3.info("connection error, closing", {
|
|
1314
1290
|
topic: this.topic,
|
|
1315
1291
|
peerId: this.localInfo,
|
|
1316
1292
|
remoteId: this.remoteInfo,
|
|
1317
1293
|
initiator,
|
|
1318
1294
|
err
|
|
1319
1295
|
}, {
|
|
1320
|
-
F:
|
|
1321
|
-
L:
|
|
1296
|
+
F: __dxlog_file3,
|
|
1297
|
+
L: 340,
|
|
1322
1298
|
S: this,
|
|
1323
1299
|
C: (f, a) => f(...a)
|
|
1324
1300
|
});
|
|
1325
|
-
|
|
1301
|
+
log3.trace("dxos.mesh.connection.error", {
|
|
1326
1302
|
topic: this.topic,
|
|
1327
1303
|
localPeerId: this.localInfo,
|
|
1328
1304
|
remotePeerId: this.remoteInfo,
|
|
@@ -1330,8 +1306,8 @@ var Peer = class {
|
|
|
1330
1306
|
initiator,
|
|
1331
1307
|
err
|
|
1332
1308
|
}, {
|
|
1333
|
-
F:
|
|
1334
|
-
L:
|
|
1309
|
+
F: __dxlog_file3,
|
|
1310
|
+
L: 347,
|
|
1335
1311
|
S: this,
|
|
1336
1312
|
C: (f, a) => f(...a)
|
|
1337
1313
|
});
|
|
@@ -1345,35 +1321,35 @@ var Peer = class {
|
|
|
1345
1321
|
return;
|
|
1346
1322
|
}
|
|
1347
1323
|
const connection = this.connection;
|
|
1348
|
-
|
|
1324
|
+
log3("closing...", {
|
|
1349
1325
|
peerId: this.remoteInfo,
|
|
1350
1326
|
sessionId: connection.sessionId
|
|
1351
1327
|
}, {
|
|
1352
|
-
F:
|
|
1353
|
-
L:
|
|
1328
|
+
F: __dxlog_file3,
|
|
1329
|
+
L: 372,
|
|
1354
1330
|
S: this,
|
|
1355
1331
|
C: (f, a) => f(...a)
|
|
1356
1332
|
});
|
|
1357
1333
|
await connection.close({
|
|
1358
1334
|
error: err
|
|
1359
1335
|
});
|
|
1360
|
-
|
|
1336
|
+
log3("closed", {
|
|
1361
1337
|
peerId: this.remoteInfo,
|
|
1362
1338
|
sessionId: connection.sessionId
|
|
1363
1339
|
}, {
|
|
1364
|
-
F:
|
|
1365
|
-
L:
|
|
1340
|
+
F: __dxlog_file3,
|
|
1341
|
+
L: 378,
|
|
1366
1342
|
S: this,
|
|
1367
1343
|
C: (f, a) => f(...a)
|
|
1368
1344
|
});
|
|
1369
1345
|
}
|
|
1370
1346
|
async onSignal(message) {
|
|
1371
1347
|
if (!this.connection) {
|
|
1372
|
-
|
|
1348
|
+
log3("dropping signal message for non-existent connection", {
|
|
1373
1349
|
message
|
|
1374
1350
|
}, {
|
|
1375
|
-
F:
|
|
1376
|
-
L:
|
|
1351
|
+
F: __dxlog_file3,
|
|
1352
|
+
L: 383,
|
|
1377
1353
|
S: this,
|
|
1378
1354
|
C: (f, a) => f(...a)
|
|
1379
1355
|
});
|
|
@@ -1383,12 +1359,12 @@ var Peer = class {
|
|
|
1383
1359
|
}
|
|
1384
1360
|
async safeDestroy(reason) {
|
|
1385
1361
|
await this._ctx.dispose();
|
|
1386
|
-
|
|
1362
|
+
log3("Destroying peer", {
|
|
1387
1363
|
peerId: this.remoteInfo,
|
|
1388
1364
|
topic: this.topic
|
|
1389
1365
|
}, {
|
|
1390
|
-
F:
|
|
1391
|
-
L:
|
|
1366
|
+
F: __dxlog_file3,
|
|
1367
|
+
L: 393,
|
|
1392
1368
|
S: this,
|
|
1393
1369
|
C: (f, a) => f(...a)
|
|
1394
1370
|
});
|
|
@@ -1420,7 +1396,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
1420
1396
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1421
1397
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1422
1398
|
}
|
|
1423
|
-
var
|
|
1399
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1424
1400
|
var INITIATION_DELAY = 100;
|
|
1425
1401
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1426
1402
|
var Swarm = class {
|
|
@@ -1435,7 +1411,7 @@ var Swarm = class {
|
|
|
1435
1411
|
_initiationDelay;
|
|
1436
1412
|
_swarmMessenger;
|
|
1437
1413
|
_ctx = new Context4(void 0, {
|
|
1438
|
-
F:
|
|
1414
|
+
F: __dxlog_file4,
|
|
1439
1415
|
L: 39
|
|
1440
1416
|
});
|
|
1441
1417
|
_listeningHandle = void 0;
|
|
@@ -1476,22 +1452,22 @@ var Swarm = class {
|
|
|
1476
1452
|
this._label = _label;
|
|
1477
1453
|
this._connectionLimiter = _connectionLimiter;
|
|
1478
1454
|
this._initiationDelay = _initiationDelay;
|
|
1479
|
-
|
|
1455
|
+
log4.trace("dxos.mesh.swarm.constructor", trace2.begin({
|
|
1480
1456
|
id: this._instanceId,
|
|
1481
1457
|
data: {
|
|
1482
1458
|
topic: this._topic.toHex(),
|
|
1483
1459
|
peer: this._ownPeer
|
|
1484
1460
|
}
|
|
1485
1461
|
}), {
|
|
1486
|
-
F:
|
|
1462
|
+
F: __dxlog_file4,
|
|
1487
1463
|
L: 89,
|
|
1488
1464
|
S: this,
|
|
1489
1465
|
C: (f, a) => f(...a)
|
|
1490
1466
|
});
|
|
1491
|
-
|
|
1467
|
+
log4("creating swarm", {
|
|
1492
1468
|
peerId: _ownPeer
|
|
1493
1469
|
}, {
|
|
1494
|
-
F:
|
|
1470
|
+
F: __dxlog_file4,
|
|
1495
1471
|
L: 93,
|
|
1496
1472
|
S: this,
|
|
1497
1473
|
C: (f, a) => f(...a)
|
|
@@ -1503,17 +1479,17 @@ var Swarm = class {
|
|
|
1503
1479
|
onOffer: async (msg) => await this.onOffer(msg),
|
|
1504
1480
|
topic: this._topic
|
|
1505
1481
|
});
|
|
1506
|
-
|
|
1482
|
+
log4.trace("dxos.mesh.swarm.constructor", trace2.end({
|
|
1507
1483
|
id: this._instanceId
|
|
1508
1484
|
}), {
|
|
1509
|
-
F:
|
|
1485
|
+
F: __dxlog_file4,
|
|
1510
1486
|
L: 102,
|
|
1511
1487
|
S: this,
|
|
1512
1488
|
C: (f, a) => f(...a)
|
|
1513
1489
|
});
|
|
1514
1490
|
}
|
|
1515
1491
|
get connections() {
|
|
1516
|
-
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(
|
|
1492
|
+
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable);
|
|
1517
1493
|
}
|
|
1518
1494
|
get ownPeerId() {
|
|
1519
1495
|
return PublicKey4.from(this._ownPeer.peerKey);
|
|
@@ -1532,7 +1508,7 @@ var Swarm = class {
|
|
|
1532
1508
|
}
|
|
1533
1509
|
async open() {
|
|
1534
1510
|
invariant4(!this._listeningHandle, void 0, {
|
|
1535
|
-
F:
|
|
1511
|
+
F: __dxlog_file4,
|
|
1536
1512
|
L: 133,
|
|
1537
1513
|
S: this,
|
|
1538
1514
|
A: [
|
|
@@ -1544,10 +1520,10 @@ var Swarm = class {
|
|
|
1544
1520
|
peer: this._ownPeer,
|
|
1545
1521
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
1546
1522
|
onMessage: async (message) => {
|
|
1547
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) =>
|
|
1523
|
+
await this._swarmMessenger.receiveMessage(message).catch((err) => log4.info("Error while receiving message", {
|
|
1548
1524
|
err
|
|
1549
1525
|
}, {
|
|
1550
|
-
F:
|
|
1526
|
+
F: __dxlog_file4,
|
|
1551
1527
|
L: 141,
|
|
1552
1528
|
S: this,
|
|
1553
1529
|
C: (f, a) => f(...a)
|
|
@@ -1556,8 +1532,8 @@ var Swarm = class {
|
|
|
1556
1532
|
});
|
|
1557
1533
|
}
|
|
1558
1534
|
async destroy() {
|
|
1559
|
-
|
|
1560
|
-
F:
|
|
1535
|
+
log4("destroying...", void 0, {
|
|
1536
|
+
F: __dxlog_file4,
|
|
1561
1537
|
L: 147,
|
|
1562
1538
|
S: this,
|
|
1563
1539
|
C: (f, a) => f(...a)
|
|
@@ -1567,8 +1543,8 @@ var Swarm = class {
|
|
|
1567
1543
|
await this._ctx.dispose();
|
|
1568
1544
|
await this._topology.destroy();
|
|
1569
1545
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1570
|
-
|
|
1571
|
-
F:
|
|
1546
|
+
log4("destroyed", void 0, {
|
|
1547
|
+
F: __dxlog_file4,
|
|
1572
1548
|
L: 154,
|
|
1573
1549
|
S: this,
|
|
1574
1550
|
C: (f, a) => f(...a)
|
|
@@ -1576,7 +1552,7 @@ var Swarm = class {
|
|
|
1576
1552
|
}
|
|
1577
1553
|
async setTopology(topology) {
|
|
1578
1554
|
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1579
|
-
F:
|
|
1555
|
+
F: __dxlog_file4,
|
|
1580
1556
|
L: 158,
|
|
1581
1557
|
S: this,
|
|
1582
1558
|
A: [
|
|
@@ -1587,11 +1563,11 @@ var Swarm = class {
|
|
|
1587
1563
|
if (topology === this._topology) {
|
|
1588
1564
|
return;
|
|
1589
1565
|
}
|
|
1590
|
-
|
|
1566
|
+
log4("setting topology", {
|
|
1591
1567
|
previous: getClassName(this._topology),
|
|
1592
1568
|
topology: getClassName(topology)
|
|
1593
1569
|
}, {
|
|
1594
|
-
F:
|
|
1570
|
+
F: __dxlog_file4,
|
|
1595
1571
|
L: 162,
|
|
1596
1572
|
S: this,
|
|
1597
1573
|
C: (f, a) => f(...a)
|
|
@@ -1602,17 +1578,17 @@ var Swarm = class {
|
|
|
1602
1578
|
this._topology.update();
|
|
1603
1579
|
}
|
|
1604
1580
|
async onSwarmEvent(swarmEvent) {
|
|
1605
|
-
|
|
1581
|
+
log4("swarm event", {
|
|
1606
1582
|
swarmEvent
|
|
1607
1583
|
}, {
|
|
1608
|
-
F:
|
|
1584
|
+
F: __dxlog_file4,
|
|
1609
1585
|
L: 175,
|
|
1610
1586
|
S: this,
|
|
1611
1587
|
C: (f, a) => f(...a)
|
|
1612
1588
|
});
|
|
1613
1589
|
if (this._ctx.disposed) {
|
|
1614
|
-
|
|
1615
|
-
F:
|
|
1590
|
+
log4("swarm event ignored for disposed swarm", void 0, {
|
|
1591
|
+
F: __dxlog_file4,
|
|
1616
1592
|
L: 178,
|
|
1617
1593
|
S: this,
|
|
1618
1594
|
C: (f, a) => f(...a)
|
|
@@ -1622,10 +1598,10 @@ var Swarm = class {
|
|
|
1622
1598
|
if (swarmEvent.peerAvailable) {
|
|
1623
1599
|
const peerId = swarmEvent.peerAvailable.peer.peerKey;
|
|
1624
1600
|
if (peerId !== this._ownPeer.peerKey) {
|
|
1625
|
-
|
|
1601
|
+
log4("new peer", {
|
|
1626
1602
|
peerId
|
|
1627
1603
|
}, {
|
|
1628
|
-
F:
|
|
1604
|
+
F: __dxlog_file4,
|
|
1629
1605
|
L: 185,
|
|
1630
1606
|
S: this,
|
|
1631
1607
|
C: (f, a) => f(...a)
|
|
@@ -1638,24 +1614,24 @@ var Swarm = class {
|
|
|
1638
1614
|
if (peer) {
|
|
1639
1615
|
peer.advertizing = false;
|
|
1640
1616
|
if (this._isConnectionEstablishmentInProgress(peer)) {
|
|
1641
|
-
|
|
1642
|
-
F:
|
|
1617
|
+
log4(`destroying peer, state: ${peer.connection?.state}`, void 0, {
|
|
1618
|
+
F: __dxlog_file4,
|
|
1643
1619
|
L: 196,
|
|
1644
1620
|
S: this,
|
|
1645
1621
|
C: (f, a) => f(...a)
|
|
1646
1622
|
});
|
|
1647
|
-
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) =>
|
|
1648
|
-
F:
|
|
1623
|
+
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log4.catch(err, void 0, {
|
|
1624
|
+
F: __dxlog_file4,
|
|
1649
1625
|
L: 197,
|
|
1650
1626
|
S: this,
|
|
1651
1627
|
C: (f, a) => f(...a)
|
|
1652
1628
|
}));
|
|
1653
1629
|
}
|
|
1654
1630
|
} else {
|
|
1655
|
-
|
|
1631
|
+
log4("received peerLeft but no peer found", {
|
|
1656
1632
|
peer: swarmEvent.peerLeft.peer.peerKey
|
|
1657
1633
|
}, {
|
|
1658
|
-
F:
|
|
1634
|
+
F: __dxlog_file4,
|
|
1659
1635
|
L: 200,
|
|
1660
1636
|
S: this,
|
|
1661
1637
|
C: (f, a) => f(...a)
|
|
@@ -1665,17 +1641,17 @@ var Swarm = class {
|
|
|
1665
1641
|
this._topology.update();
|
|
1666
1642
|
}
|
|
1667
1643
|
async onOffer(message) {
|
|
1668
|
-
|
|
1644
|
+
log4("offer", {
|
|
1669
1645
|
message
|
|
1670
1646
|
}, {
|
|
1671
|
-
F:
|
|
1647
|
+
F: __dxlog_file4,
|
|
1672
1648
|
L: 209,
|
|
1673
1649
|
S: this,
|
|
1674
1650
|
C: (f, a) => f(...a)
|
|
1675
1651
|
});
|
|
1676
1652
|
if (this._ctx.disposed) {
|
|
1677
|
-
|
|
1678
|
-
F:
|
|
1653
|
+
log4("ignored for disposed swarm", void 0, {
|
|
1654
|
+
F: __dxlog_file4,
|
|
1679
1655
|
L: 211,
|
|
1680
1656
|
S: this,
|
|
1681
1657
|
C: (f, a) => f(...a)
|
|
@@ -1685,7 +1661,7 @@ var Swarm = class {
|
|
|
1685
1661
|
};
|
|
1686
1662
|
}
|
|
1687
1663
|
invariant4(message.author, void 0, {
|
|
1688
|
-
F:
|
|
1664
|
+
F: __dxlog_file4,
|
|
1689
1665
|
L: 216,
|
|
1690
1666
|
S: this,
|
|
1691
1667
|
A: [
|
|
@@ -1694,10 +1670,10 @@ var Swarm = class {
|
|
|
1694
1670
|
]
|
|
1695
1671
|
});
|
|
1696
1672
|
if (message.recipient.peerKey !== this._ownPeer.peerKey) {
|
|
1697
|
-
|
|
1673
|
+
log4("rejecting offer with incorrect peerId", {
|
|
1698
1674
|
message
|
|
1699
1675
|
}, {
|
|
1700
|
-
F:
|
|
1676
|
+
F: __dxlog_file4,
|
|
1701
1677
|
L: 218,
|
|
1702
1678
|
S: this,
|
|
1703
1679
|
C: (f, a) => f(...a)
|
|
@@ -1707,10 +1683,10 @@ var Swarm = class {
|
|
|
1707
1683
|
};
|
|
1708
1684
|
}
|
|
1709
1685
|
if (!message.topic?.equals(this._topic)) {
|
|
1710
|
-
|
|
1686
|
+
log4("rejecting offer with incorrect topic", {
|
|
1711
1687
|
message
|
|
1712
1688
|
}, {
|
|
1713
|
-
F:
|
|
1689
|
+
F: __dxlog_file4,
|
|
1714
1690
|
L: 222,
|
|
1715
1691
|
S: this,
|
|
1716
1692
|
C: (f, a) => f(...a)
|
|
@@ -1735,17 +1711,17 @@ var Swarm = class {
|
|
|
1735
1711
|
return peer;
|
|
1736
1712
|
}
|
|
1737
1713
|
async onSignal(message) {
|
|
1738
|
-
|
|
1714
|
+
log4("signal", {
|
|
1739
1715
|
message
|
|
1740
1716
|
}, {
|
|
1741
|
-
F:
|
|
1717
|
+
F: __dxlog_file4,
|
|
1742
1718
|
L: 247,
|
|
1743
1719
|
S: this,
|
|
1744
1720
|
C: (f, a) => f(...a)
|
|
1745
1721
|
});
|
|
1746
1722
|
if (this._ctx.disposed) {
|
|
1747
|
-
|
|
1748
|
-
F:
|
|
1723
|
+
log4.info("ignored for offline swarm", void 0, {
|
|
1724
|
+
F: __dxlog_file4,
|
|
1749
1725
|
L: 249,
|
|
1750
1726
|
S: this,
|
|
1751
1727
|
C: (f, a) => f(...a)
|
|
@@ -1753,7 +1729,7 @@ var Swarm = class {
|
|
|
1753
1729
|
return;
|
|
1754
1730
|
}
|
|
1755
1731
|
invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1756
|
-
F:
|
|
1732
|
+
F: __dxlog_file4,
|
|
1757
1733
|
L: 252,
|
|
1758
1734
|
S: this,
|
|
1759
1735
|
A: [
|
|
@@ -1762,7 +1738,7 @@ var Swarm = class {
|
|
|
1762
1738
|
]
|
|
1763
1739
|
});
|
|
1764
1740
|
invariant4(message.topic?.equals(this._topic), void 0, {
|
|
1765
|
-
F:
|
|
1741
|
+
F: __dxlog_file4,
|
|
1766
1742
|
L: 256,
|
|
1767
1743
|
S: this,
|
|
1768
1744
|
A: [
|
|
@@ -1771,7 +1747,7 @@ var Swarm = class {
|
|
|
1771
1747
|
]
|
|
1772
1748
|
});
|
|
1773
1749
|
invariant4(message.author, void 0, {
|
|
1774
|
-
F:
|
|
1750
|
+
F: __dxlog_file4,
|
|
1775
1751
|
L: 257,
|
|
1776
1752
|
S: this,
|
|
1777
1753
|
A: [
|
|
@@ -1792,13 +1768,13 @@ var Swarm = class {
|
|
|
1792
1768
|
// For debug purposes
|
|
1793
1769
|
async goOnline() {
|
|
1794
1770
|
this._ctx = new Context4(void 0, {
|
|
1795
|
-
F:
|
|
1771
|
+
F: __dxlog_file4,
|
|
1796
1772
|
L: 273
|
|
1797
1773
|
});
|
|
1798
1774
|
}
|
|
1799
1775
|
_getOrCreatePeer(peerInfo) {
|
|
1800
1776
|
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
|
|
1801
|
-
F:
|
|
1777
|
+
F: __dxlog_file4,
|
|
1802
1778
|
L: 277,
|
|
1803
1779
|
S: this,
|
|
1804
1780
|
A: [
|
|
@@ -1817,8 +1793,8 @@ var Swarm = class {
|
|
|
1817
1793
|
},
|
|
1818
1794
|
onDisconnected: async () => {
|
|
1819
1795
|
if (this._isUnregistered(peer)) {
|
|
1820
|
-
|
|
1821
|
-
F:
|
|
1796
|
+
log4.verbose("ignored onDisconnected for unregistered peer", void 0, {
|
|
1797
|
+
F: __dxlog_file4,
|
|
1822
1798
|
L: 297,
|
|
1823
1799
|
S: this,
|
|
1824
1800
|
C: (f, a) => f(...a)
|
|
@@ -1833,10 +1809,10 @@ var Swarm = class {
|
|
|
1833
1809
|
},
|
|
1834
1810
|
onRejected: () => {
|
|
1835
1811
|
if (!this._isUnregistered(peer)) {
|
|
1836
|
-
|
|
1812
|
+
log4("peer rejected connection", {
|
|
1837
1813
|
peerInfo
|
|
1838
1814
|
}, {
|
|
1839
|
-
F:
|
|
1815
|
+
F: __dxlog_file4,
|
|
1840
1816
|
L: 311,
|
|
1841
1817
|
S: this,
|
|
1842
1818
|
C: (f, a) => f(...a)
|
|
@@ -1859,18 +1835,18 @@ var Swarm = class {
|
|
|
1859
1835
|
return peer;
|
|
1860
1836
|
}
|
|
1861
1837
|
async _destroyPeer(peerInfo, reason) {
|
|
1862
|
-
|
|
1838
|
+
log4("destroy peer", {
|
|
1863
1839
|
peerKey: peerInfo.peerKey,
|
|
1864
1840
|
reason
|
|
1865
1841
|
}, {
|
|
1866
|
-
F:
|
|
1842
|
+
F: __dxlog_file4,
|
|
1867
1843
|
L: 333,
|
|
1868
1844
|
S: this,
|
|
1869
1845
|
C: (f, a) => f(...a)
|
|
1870
1846
|
});
|
|
1871
1847
|
const peer = this._peers.get(peerInfo);
|
|
1872
1848
|
invariant4(peer, void 0, {
|
|
1873
|
-
F:
|
|
1849
|
+
F: __dxlog_file4,
|
|
1874
1850
|
L: 335,
|
|
1875
1851
|
S: this,
|
|
1876
1852
|
A: [
|
|
@@ -1899,8 +1875,8 @@ var Swarm = class {
|
|
|
1899
1875
|
peerKey: peer.toHex()
|
|
1900
1876
|
});
|
|
1901
1877
|
} catch (err) {
|
|
1902
|
-
|
|
1903
|
-
F:
|
|
1878
|
+
log4("initiation error", err, {
|
|
1879
|
+
F: __dxlog_file4,
|
|
1904
1880
|
L: 362,
|
|
1905
1881
|
S: this,
|
|
1906
1882
|
C: (f, a) => f(...a)
|
|
@@ -1928,10 +1904,10 @@ var Swarm = class {
|
|
|
1928
1904
|
const ctx = this._ctx;
|
|
1929
1905
|
const peer = this._getOrCreatePeer(remotePeer);
|
|
1930
1906
|
if (remotePeer.peerKey < this._ownPeer.peerKey) {
|
|
1931
|
-
|
|
1907
|
+
log4("initiation delay", {
|
|
1932
1908
|
remotePeer
|
|
1933
1909
|
}, {
|
|
1934
|
-
F:
|
|
1910
|
+
F: __dxlog_file4,
|
|
1935
1911
|
L: 390,
|
|
1936
1912
|
S: this,
|
|
1937
1913
|
C: (f, a) => f(...a)
|
|
@@ -1947,20 +1923,20 @@ var Swarm = class {
|
|
|
1947
1923
|
if (peer.connection) {
|
|
1948
1924
|
return;
|
|
1949
1925
|
}
|
|
1950
|
-
|
|
1926
|
+
log4("initiating connection...", {
|
|
1951
1927
|
remotePeer
|
|
1952
1928
|
}, {
|
|
1953
|
-
F:
|
|
1929
|
+
F: __dxlog_file4,
|
|
1954
1930
|
L: 406,
|
|
1955
1931
|
S: this,
|
|
1956
1932
|
C: (f, a) => f(...a)
|
|
1957
1933
|
});
|
|
1958
1934
|
await peer.initiateConnection();
|
|
1959
1935
|
this._topology.update();
|
|
1960
|
-
|
|
1936
|
+
log4("initiated", {
|
|
1961
1937
|
remotePeer
|
|
1962
1938
|
}, {
|
|
1963
|
-
F:
|
|
1939
|
+
F: __dxlog_file4,
|
|
1964
1940
|
L: 409,
|
|
1965
1941
|
S: this,
|
|
1966
1942
|
C: (f, a) => f(...a)
|
|
@@ -2012,10 +1988,10 @@ _ts_decorate3([
|
|
|
2012
1988
|
// src/swarm/swarm-mapper.ts
|
|
2013
1989
|
import { Event as Event4, SubscriptionList } from "@dxos/async";
|
|
2014
1990
|
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
2015
|
-
import { log as
|
|
1991
|
+
import { log as log5 } from "@dxos/log";
|
|
2016
1992
|
import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
|
|
2017
1993
|
import { ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
2018
|
-
var
|
|
1994
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
2019
1995
|
var SwarmMapper = class {
|
|
2020
1996
|
_swarm;
|
|
2021
1997
|
_subscriptions = new SubscriptionList();
|
|
@@ -2041,8 +2017,8 @@ var SwarmMapper = class {
|
|
|
2041
2017
|
this._update();
|
|
2042
2018
|
}
|
|
2043
2019
|
_update() {
|
|
2044
|
-
|
|
2045
|
-
F:
|
|
2020
|
+
log5("updating swarm", void 0, {
|
|
2021
|
+
F: __dxlog_file5,
|
|
2046
2022
|
L: 71,
|
|
2047
2023
|
S: this,
|
|
2048
2024
|
C: (f, a) => f(...a)
|
|
@@ -2062,11 +2038,11 @@ var SwarmMapper = class {
|
|
|
2062
2038
|
]
|
|
2063
2039
|
});
|
|
2064
2040
|
}
|
|
2065
|
-
|
|
2041
|
+
log5("graph changed", {
|
|
2066
2042
|
directConnections: this._swarm.connections.length,
|
|
2067
2043
|
totalPeersInSwarm: this._peers.size
|
|
2068
2044
|
}, {
|
|
2069
|
-
F:
|
|
2045
|
+
F: __dxlog_file5,
|
|
2070
2046
|
L: 112,
|
|
2071
2047
|
S: this,
|
|
2072
2048
|
C: (f, a) => f(...a)
|
|
@@ -2086,14 +2062,14 @@ import { DeferredTask as DeferredTask2 } from "@dxos/async";
|
|
|
2086
2062
|
import { Context as Context5 } from "@dxos/context";
|
|
2087
2063
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
2088
2064
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
2089
|
-
import { log as
|
|
2065
|
+
import { log as log6 } from "@dxos/log";
|
|
2090
2066
|
import { CancelledError as CancelledError3 } from "@dxos/protocols";
|
|
2091
2067
|
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
2092
|
-
var
|
|
2068
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
2093
2069
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
|
|
2094
2070
|
var ConnectionLimiter = class {
|
|
2095
2071
|
_ctx = new Context5(void 0, {
|
|
2096
|
-
F:
|
|
2072
|
+
F: __dxlog_file6,
|
|
2097
2073
|
L: 23
|
|
2098
2074
|
});
|
|
2099
2075
|
_maxConcurrentInitConnections;
|
|
@@ -2114,7 +2090,7 @@ var ConnectionLimiter = class {
|
|
|
2114
2090
|
*/
|
|
2115
2091
|
async connecting(sessionId) {
|
|
2116
2092
|
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
2117
|
-
F:
|
|
2093
|
+
F: __dxlog_file6,
|
|
2118
2094
|
L: 48,
|
|
2119
2095
|
S: this,
|
|
2120
2096
|
A: [
|
|
@@ -2122,10 +2098,10 @@ var ConnectionLimiter = class {
|
|
|
2122
2098
|
"'Peer is already waiting for connection'"
|
|
2123
2099
|
]
|
|
2124
2100
|
});
|
|
2125
|
-
|
|
2101
|
+
log6("waiting", {
|
|
2126
2102
|
sessionId
|
|
2127
2103
|
}, {
|
|
2128
|
-
F:
|
|
2104
|
+
F: __dxlog_file6,
|
|
2129
2105
|
L: 49,
|
|
2130
2106
|
S: this,
|
|
2131
2107
|
C: (f, a) => f(...a)
|
|
@@ -2137,10 +2113,10 @@ var ConnectionLimiter = class {
|
|
|
2137
2113
|
});
|
|
2138
2114
|
this.resolveWaitingPromises.schedule();
|
|
2139
2115
|
});
|
|
2140
|
-
|
|
2116
|
+
log6("allow", {
|
|
2141
2117
|
sessionId
|
|
2142
2118
|
}, {
|
|
2143
|
-
F:
|
|
2119
|
+
F: __dxlog_file6,
|
|
2144
2120
|
L: 57,
|
|
2145
2121
|
S: this,
|
|
2146
2122
|
C: (f, a) => f(...a)
|
|
@@ -2150,10 +2126,10 @@ var ConnectionLimiter = class {
|
|
|
2150
2126
|
* Rejects promise returned by `connecting` method.
|
|
2151
2127
|
*/
|
|
2152
2128
|
doneConnecting(sessionId) {
|
|
2153
|
-
|
|
2129
|
+
log6("done", {
|
|
2154
2130
|
sessionId
|
|
2155
2131
|
}, {
|
|
2156
|
-
F:
|
|
2132
|
+
F: __dxlog_file6,
|
|
2157
2133
|
L: 64,
|
|
2158
2134
|
S: this,
|
|
2159
2135
|
C: (f, a) => f(...a)
|
|
@@ -2261,7 +2237,7 @@ var gcSwarm = (swarm) => {
|
|
|
2261
2237
|
import { Event as Event6, synchronized as synchronized4 } from "@dxos/async";
|
|
2262
2238
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
2263
2239
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2264
|
-
import { log as
|
|
2240
|
+
import { log as log7 } from "@dxos/log";
|
|
2265
2241
|
import { Messenger } from "@dxos/messaging";
|
|
2266
2242
|
import { trace as trace3 } from "@dxos/protocols";
|
|
2267
2243
|
import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -2272,7 +2248,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
2272
2248
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2273
2249
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2274
2250
|
}
|
|
2275
|
-
var
|
|
2251
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2276
2252
|
var SwarmNetworkManager = class {
|
|
2277
2253
|
/**
|
|
2278
2254
|
* @internal
|
|
@@ -2328,20 +2304,20 @@ var SwarmNetworkManager = class {
|
|
|
2328
2304
|
this._peerInfo = peerInfo;
|
|
2329
2305
|
}
|
|
2330
2306
|
async open() {
|
|
2331
|
-
|
|
2307
|
+
log7.trace("dxos.mesh.network-manager.open", trace3.begin({
|
|
2332
2308
|
id: this._instanceId
|
|
2333
2309
|
}), {
|
|
2334
|
-
F:
|
|
2310
|
+
F: __dxlog_file7,
|
|
2335
2311
|
L: 133,
|
|
2336
2312
|
S: this,
|
|
2337
2313
|
C: (f, a) => f(...a)
|
|
2338
2314
|
});
|
|
2339
2315
|
await this._messenger.open();
|
|
2340
2316
|
await this._signalManager.open();
|
|
2341
|
-
|
|
2317
|
+
log7.trace("dxos.mesh.network-manager.open", trace3.end({
|
|
2342
2318
|
id: this._instanceId
|
|
2343
2319
|
}), {
|
|
2344
|
-
F:
|
|
2320
|
+
F: __dxlog_file7,
|
|
2345
2321
|
L: 136,
|
|
2346
2322
|
S: this,
|
|
2347
2323
|
C: (f, a) => f(...a)
|
|
@@ -2350,8 +2326,8 @@ var SwarmNetworkManager = class {
|
|
|
2350
2326
|
async close() {
|
|
2351
2327
|
for (const topic of this._swarms.keys()) {
|
|
2352
2328
|
await this.leaveSwarm(topic).catch((err) => {
|
|
2353
|
-
|
|
2354
|
-
F:
|
|
2329
|
+
log7(err, void 0, {
|
|
2330
|
+
F: __dxlog_file7,
|
|
2355
2331
|
L: 142,
|
|
2356
2332
|
S: this,
|
|
2357
2333
|
C: (f, a) => f(...a)
|
|
@@ -2366,7 +2342,7 @@ var SwarmNetworkManager = class {
|
|
|
2366
2342
|
*/
|
|
2367
2343
|
async joinSwarm({ topic, topology, protocolProvider: protocol, label }) {
|
|
2368
2344
|
invariant6(PublicKey8.isPublicKey(topic), void 0, {
|
|
2369
|
-
F:
|
|
2345
|
+
F: __dxlog_file7,
|
|
2370
2346
|
L: 160,
|
|
2371
2347
|
S: this,
|
|
2372
2348
|
A: [
|
|
@@ -2375,7 +2351,7 @@ var SwarmNetworkManager = class {
|
|
|
2375
2351
|
]
|
|
2376
2352
|
});
|
|
2377
2353
|
invariant6(topology, void 0, {
|
|
2378
|
-
F:
|
|
2354
|
+
F: __dxlog_file7,
|
|
2379
2355
|
L: 161,
|
|
2380
2356
|
S: this,
|
|
2381
2357
|
A: [
|
|
@@ -2384,7 +2360,7 @@ var SwarmNetworkManager = class {
|
|
|
2384
2360
|
]
|
|
2385
2361
|
});
|
|
2386
2362
|
invariant6(this._peerInfo, void 0, {
|
|
2387
|
-
F:
|
|
2363
|
+
F: __dxlog_file7,
|
|
2388
2364
|
L: 162,
|
|
2389
2365
|
S: this,
|
|
2390
2366
|
A: [
|
|
@@ -2393,7 +2369,7 @@ var SwarmNetworkManager = class {
|
|
|
2393
2369
|
]
|
|
2394
2370
|
});
|
|
2395
2371
|
invariant6(typeof protocol === "function", void 0, {
|
|
2396
|
-
F:
|
|
2372
|
+
F: __dxlog_file7,
|
|
2397
2373
|
L: 163,
|
|
2398
2374
|
S: this,
|
|
2399
2375
|
A: [
|
|
@@ -2404,22 +2380,22 @@ var SwarmNetworkManager = class {
|
|
|
2404
2380
|
if (this._swarms.has(topic)) {
|
|
2405
2381
|
throw new Error(`Already connected to swarm: ${PublicKey8.from(topic)}`);
|
|
2406
2382
|
}
|
|
2407
|
-
|
|
2383
|
+
log7("joining", {
|
|
2408
2384
|
topic: PublicKey8.from(topic),
|
|
2409
2385
|
peerInfo: this._peerInfo,
|
|
2410
2386
|
topology: topology.toString()
|
|
2411
2387
|
}, {
|
|
2412
|
-
F:
|
|
2388
|
+
F: __dxlog_file7,
|
|
2413
2389
|
L: 168,
|
|
2414
2390
|
S: this,
|
|
2415
2391
|
C: (f, a) => f(...a)
|
|
2416
2392
|
});
|
|
2417
2393
|
const swarm = new Swarm(topic, this._peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
2418
2394
|
swarm.errors.handle((error) => {
|
|
2419
|
-
|
|
2395
|
+
log7("swarm error", {
|
|
2420
2396
|
error
|
|
2421
2397
|
}, {
|
|
2422
|
-
F:
|
|
2398
|
+
F: __dxlog_file7,
|
|
2423
2399
|
L: 181,
|
|
2424
2400
|
S: this,
|
|
2425
2401
|
C: (f, a) => f(...a)
|
|
@@ -2431,19 +2407,19 @@ var SwarmNetworkManager = class {
|
|
|
2431
2407
|
this._signalConnection.join({
|
|
2432
2408
|
topic,
|
|
2433
2409
|
peer: this._peerInfo
|
|
2434
|
-
}).catch((error) =>
|
|
2435
|
-
F:
|
|
2410
|
+
}).catch((error) => log7.catch(error, void 0, {
|
|
2411
|
+
F: __dxlog_file7,
|
|
2436
2412
|
L: 190,
|
|
2437
2413
|
S: this,
|
|
2438
2414
|
C: (f, a) => f(...a)
|
|
2439
2415
|
}));
|
|
2440
2416
|
this.topicsUpdated.emit();
|
|
2441
2417
|
this._connectionLog?.joinedSwarm(swarm);
|
|
2442
|
-
|
|
2418
|
+
log7("joined", {
|
|
2443
2419
|
topic: PublicKey8.from(topic),
|
|
2444
2420
|
count: this._swarms.size
|
|
2445
2421
|
}, {
|
|
2446
|
-
F:
|
|
2422
|
+
F: __dxlog_file7,
|
|
2447
2423
|
L: 194,
|
|
2448
2424
|
S: this,
|
|
2449
2425
|
C: (f, a) => f(...a)
|
|
@@ -2459,10 +2435,10 @@ var SwarmNetworkManager = class {
|
|
|
2459
2435
|
if (!this._swarms.has(topic)) {
|
|
2460
2436
|
return;
|
|
2461
2437
|
}
|
|
2462
|
-
|
|
2438
|
+
log7("leaving", {
|
|
2463
2439
|
topic: PublicKey8.from(topic)
|
|
2464
2440
|
}, {
|
|
2465
|
-
F:
|
|
2441
|
+
F: __dxlog_file7,
|
|
2466
2442
|
L: 211,
|
|
2467
2443
|
S: this,
|
|
2468
2444
|
C: (f, a) => f(...a)
|
|
@@ -2479,11 +2455,11 @@ var SwarmNetworkManager = class {
|
|
|
2479
2455
|
await swarm.destroy();
|
|
2480
2456
|
this._swarms.delete(topic);
|
|
2481
2457
|
this.topicsUpdated.emit();
|
|
2482
|
-
|
|
2458
|
+
log7("left", {
|
|
2483
2459
|
topic: PublicKey8.from(topic),
|
|
2484
2460
|
count: this._swarms.size
|
|
2485
2461
|
}, {
|
|
2486
|
-
F:
|
|
2462
|
+
F: __dxlog_file7,
|
|
2487
2463
|
L: 225,
|
|
2488
2464
|
S: this,
|
|
2489
2465
|
C: (f, a) => f(...a)
|
|
@@ -2525,7 +2501,7 @@ _ts_decorate4([
|
|
|
2525
2501
|
|
|
2526
2502
|
// src/topology/fully-connected-topology.ts
|
|
2527
2503
|
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2528
|
-
var
|
|
2504
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
2529
2505
|
var FullyConnectedTopology = class {
|
|
2530
2506
|
_controller;
|
|
2531
2507
|
toString() {
|
|
@@ -2533,7 +2509,7 @@ var FullyConnectedTopology = class {
|
|
|
2533
2509
|
}
|
|
2534
2510
|
init(controller) {
|
|
2535
2511
|
invariant7(!this._controller, "Already initialized", {
|
|
2536
|
-
F:
|
|
2512
|
+
F: __dxlog_file8,
|
|
2537
2513
|
L: 18,
|
|
2538
2514
|
S: this,
|
|
2539
2515
|
A: [
|
|
@@ -2545,7 +2521,7 @@ var FullyConnectedTopology = class {
|
|
|
2545
2521
|
}
|
|
2546
2522
|
update() {
|
|
2547
2523
|
invariant7(this._controller, "Not initialized", {
|
|
2548
|
-
F:
|
|
2524
|
+
F: __dxlog_file8,
|
|
2549
2525
|
L: 23,
|
|
2550
2526
|
S: this,
|
|
2551
2527
|
A: [
|
|
@@ -2565,321 +2541,13 @@ var FullyConnectedTopology = class {
|
|
|
2565
2541
|
}
|
|
2566
2542
|
};
|
|
2567
2543
|
|
|
2568
|
-
// src/topology/mmst-topology.ts
|
|
2569
|
-
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2570
|
-
import { log as log9 } from "@dxos/log";
|
|
2571
|
-
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2572
|
-
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2573
|
-
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2574
|
-
var MMSTTopology = class {
|
|
2575
|
-
_originateConnections;
|
|
2576
|
-
_maxPeers;
|
|
2577
|
-
_sampleSize;
|
|
2578
|
-
_controller;
|
|
2579
|
-
_sampleCollected = false;
|
|
2580
|
-
_lastAction = /* @__PURE__ */ new Date(0);
|
|
2581
|
-
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2582
|
-
this._originateConnections = originateConnections;
|
|
2583
|
-
this._maxPeers = maxPeers;
|
|
2584
|
-
this._sampleSize = sampleSize;
|
|
2585
|
-
}
|
|
2586
|
-
init(controller) {
|
|
2587
|
-
invariant8(!this._controller, "Already initialized", {
|
|
2588
|
-
F: __dxlog_file10,
|
|
2589
|
-
L: 49,
|
|
2590
|
-
S: this,
|
|
2591
|
-
A: [
|
|
2592
|
-
"!this._controller",
|
|
2593
|
-
"'Already initialized'"
|
|
2594
|
-
]
|
|
2595
|
-
});
|
|
2596
|
-
this._controller = controller;
|
|
2597
|
-
}
|
|
2598
|
-
update() {
|
|
2599
|
-
invariant8(this._controller, "Not initialized", {
|
|
2600
|
-
F: __dxlog_file10,
|
|
2601
|
-
L: 54,
|
|
2602
|
-
S: this,
|
|
2603
|
-
A: [
|
|
2604
|
-
"this._controller",
|
|
2605
|
-
"'Not initialized'"
|
|
2606
|
-
]
|
|
2607
|
-
});
|
|
2608
|
-
const { connected, candidates } = this._controller.getState();
|
|
2609
|
-
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2610
|
-
log9("Running the algorithm.", void 0, {
|
|
2611
|
-
F: __dxlog_file10,
|
|
2612
|
-
L: 58,
|
|
2613
|
-
S: this,
|
|
2614
|
-
C: (f, a) => f(...a)
|
|
2615
|
-
});
|
|
2616
|
-
this._sampleCollected = true;
|
|
2617
|
-
this._runAlgorithm();
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
forceUpdate() {
|
|
2621
|
-
this._lastAction = /* @__PURE__ */ new Date(0);
|
|
2622
|
-
this.update();
|
|
2623
|
-
}
|
|
2624
|
-
async onOffer(peer) {
|
|
2625
|
-
invariant8(this._controller, "Not initialized", {
|
|
2626
|
-
F: __dxlog_file10,
|
|
2627
|
-
L: 70,
|
|
2628
|
-
S: this,
|
|
2629
|
-
A: [
|
|
2630
|
-
"this._controller",
|
|
2631
|
-
"'Not initialized'"
|
|
2632
|
-
]
|
|
2633
|
-
});
|
|
2634
|
-
const { connected } = this._controller.getState();
|
|
2635
|
-
const accept = connected.length < this._maxPeers;
|
|
2636
|
-
log9(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2637
|
-
F: __dxlog_file10,
|
|
2638
|
-
L: 73,
|
|
2639
|
-
S: this,
|
|
2640
|
-
C: (f, a) => f(...a)
|
|
2641
|
-
});
|
|
2642
|
-
return accept;
|
|
2643
|
-
}
|
|
2644
|
-
async destroy() {
|
|
2645
|
-
}
|
|
2646
|
-
_runAlgorithm() {
|
|
2647
|
-
invariant8(this._controller, "Not initialized", {
|
|
2648
|
-
F: __dxlog_file10,
|
|
2649
|
-
L: 82,
|
|
2650
|
-
S: this,
|
|
2651
|
-
A: [
|
|
2652
|
-
"this._controller",
|
|
2653
|
-
"'Not initialized'"
|
|
2654
|
-
]
|
|
2655
|
-
});
|
|
2656
|
-
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2657
|
-
if (connected.length > this._maxPeers) {
|
|
2658
|
-
log9(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2659
|
-
F: __dxlog_file10,
|
|
2660
|
-
L: 88,
|
|
2661
|
-
S: this,
|
|
2662
|
-
C: (f, a) => f(...a)
|
|
2663
|
-
});
|
|
2664
|
-
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2665
|
-
invariant8(sorted.length === 0, void 0, {
|
|
2666
|
-
F: __dxlog_file10,
|
|
2667
|
-
L: 92,
|
|
2668
|
-
S: this,
|
|
2669
|
-
A: [
|
|
2670
|
-
"sorted.length === 0",
|
|
2671
|
-
""
|
|
2672
|
-
]
|
|
2673
|
-
});
|
|
2674
|
-
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2675
|
-
log9(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2676
|
-
F: __dxlog_file10,
|
|
2677
|
-
L: 95,
|
|
2678
|
-
S: this,
|
|
2679
|
-
C: (f, a) => f(...a)
|
|
2680
|
-
});
|
|
2681
|
-
}
|
|
2682
|
-
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2683
|
-
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2684
|
-
log9(`Disconnect ${peer}.`, void 0, {
|
|
2685
|
-
F: __dxlog_file10,
|
|
2686
|
-
L: 100,
|
|
2687
|
-
S: this,
|
|
2688
|
-
C: (f, a) => f(...a)
|
|
2689
|
-
});
|
|
2690
|
-
this._controller.disconnect(peer);
|
|
2691
|
-
}
|
|
2692
|
-
this._lastAction = /* @__PURE__ */ new Date();
|
|
2693
|
-
} else {
|
|
2694
|
-
log9("rate limited disconnect", void 0, {
|
|
2695
|
-
F: __dxlog_file10,
|
|
2696
|
-
L: 105,
|
|
2697
|
-
S: this,
|
|
2698
|
-
C: (f, a) => f(...a)
|
|
2699
|
-
});
|
|
2700
|
-
}
|
|
2701
|
-
} else if (connected.length < this._originateConnections) {
|
|
2702
|
-
log9(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2703
|
-
F: __dxlog_file10,
|
|
2704
|
-
L: 109,
|
|
2705
|
-
S: this,
|
|
2706
|
-
C: (f, a) => f(...a)
|
|
2707
|
-
});
|
|
2708
|
-
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2709
|
-
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2710
|
-
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2711
|
-
log9(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2712
|
-
F: __dxlog_file10,
|
|
2713
|
-
L: 114,
|
|
2714
|
-
S: this,
|
|
2715
|
-
C: (f, a) => f(...a)
|
|
2716
|
-
});
|
|
2717
|
-
}
|
|
2718
|
-
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2719
|
-
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2720
|
-
log9(`Connect ${peer}.`, void 0, {
|
|
2721
|
-
F: __dxlog_file10,
|
|
2722
|
-
L: 118,
|
|
2723
|
-
S: this,
|
|
2724
|
-
C: (f, a) => f(...a)
|
|
2725
|
-
});
|
|
2726
|
-
this._controller.connect(peer);
|
|
2727
|
-
}
|
|
2728
|
-
this._lastAction = /* @__PURE__ */ new Date();
|
|
2729
|
-
} else {
|
|
2730
|
-
log9("rate limited connect", void 0, {
|
|
2731
|
-
F: __dxlog_file10,
|
|
2732
|
-
L: 123,
|
|
2733
|
-
S: this,
|
|
2734
|
-
C: (f, a) => f(...a)
|
|
2735
|
-
});
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
}
|
|
2739
|
-
toString() {
|
|
2740
|
-
return "MMSTTopology";
|
|
2741
|
-
}
|
|
2742
|
-
};
|
|
2743
|
-
var sortByXorDistance = (keys, reference) => {
|
|
2744
|
-
const sorted = keys.sort((a, b) => {
|
|
2745
|
-
return compareXor(distXor(a.asBuffer(), reference.asBuffer()), distXor(b.asBuffer(), reference.asBuffer()));
|
|
2746
|
-
});
|
|
2747
|
-
log9("Sorted keys", {
|
|
2748
|
-
keys,
|
|
2749
|
-
reference,
|
|
2750
|
-
sorted
|
|
2751
|
-
}, {
|
|
2752
|
-
F: __dxlog_file10,
|
|
2753
|
-
L: 137,
|
|
2754
|
-
S: void 0,
|
|
2755
|
-
C: (f, a) => f(...a)
|
|
2756
|
-
});
|
|
2757
|
-
return sorted;
|
|
2758
|
-
};
|
|
2759
|
-
var distXor = (a, b) => {
|
|
2760
|
-
const maxLength = Math.max(a.length, b.length);
|
|
2761
|
-
const result = Buffer.allocUnsafe(maxLength);
|
|
2762
|
-
for (let i = 0; i < maxLength; i++) {
|
|
2763
|
-
result[i] = (a[i] || 0) ^ (b[i] || 0);
|
|
2764
|
-
}
|
|
2765
|
-
return result;
|
|
2766
|
-
};
|
|
2767
|
-
var compareXor = (a, b) => {
|
|
2768
|
-
const maxLength = Math.max(a.length, b.length);
|
|
2769
|
-
for (let i = 0; i < maxLength; i++) {
|
|
2770
|
-
if ((a[i] || 0) === (b[i] || 0)) {
|
|
2771
|
-
continue;
|
|
2772
|
-
}
|
|
2773
|
-
return (a[i] || 0) < (b[i] || 0) ? -1 : 1;
|
|
2774
|
-
}
|
|
2775
|
-
return 0;
|
|
2776
|
-
};
|
|
2777
|
-
|
|
2778
|
-
// src/topology/star-topology.ts
|
|
2779
|
-
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2780
|
-
import { log as log10 } from "@dxos/log";
|
|
2781
|
-
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
2782
|
-
var StarTopology = class {
|
|
2783
|
-
_centralPeer;
|
|
2784
|
-
_controller;
|
|
2785
|
-
constructor(_centralPeer) {
|
|
2786
|
-
this._centralPeer = _centralPeer;
|
|
2787
|
-
}
|
|
2788
|
-
toString() {
|
|
2789
|
-
return `StarTopology(${this._centralPeer.truncate()})`;
|
|
2790
|
-
}
|
|
2791
|
-
init(controller) {
|
|
2792
|
-
invariant9(!this._controller, "Already initialized.", {
|
|
2793
|
-
F: __dxlog_file11,
|
|
2794
|
-
L: 21,
|
|
2795
|
-
S: this,
|
|
2796
|
-
A: [
|
|
2797
|
-
"!this._controller",
|
|
2798
|
-
"'Already initialized.'"
|
|
2799
|
-
]
|
|
2800
|
-
});
|
|
2801
|
-
this._controller = controller;
|
|
2802
|
-
}
|
|
2803
|
-
update() {
|
|
2804
|
-
invariant9(this._controller, "Not initialized.", {
|
|
2805
|
-
F: __dxlog_file11,
|
|
2806
|
-
L: 26,
|
|
2807
|
-
S: this,
|
|
2808
|
-
A: [
|
|
2809
|
-
"this._controller",
|
|
2810
|
-
"'Not initialized.'"
|
|
2811
|
-
]
|
|
2812
|
-
});
|
|
2813
|
-
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
2814
|
-
if (!ownPeerId.equals(this._centralPeer)) {
|
|
2815
|
-
log10("leaf peer dropping all connections apart from central peer.", void 0, {
|
|
2816
|
-
F: __dxlog_file11,
|
|
2817
|
-
L: 29,
|
|
2818
|
-
S: this,
|
|
2819
|
-
C: (f, a) => f(...a)
|
|
2820
|
-
});
|
|
2821
|
-
for (const peer of connected) {
|
|
2822
|
-
if (!peer.equals(this._centralPeer)) {
|
|
2823
|
-
log10("dropping connection", {
|
|
2824
|
-
peer
|
|
2825
|
-
}, {
|
|
2826
|
-
F: __dxlog_file11,
|
|
2827
|
-
L: 34,
|
|
2828
|
-
S: this,
|
|
2829
|
-
C: (f, a) => f(...a)
|
|
2830
|
-
});
|
|
2831
|
-
this._controller.disconnect(peer);
|
|
2832
|
-
}
|
|
2833
|
-
}
|
|
2834
|
-
}
|
|
2835
|
-
for (const peer of candidates) {
|
|
2836
|
-
if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
|
|
2837
|
-
log10("connecting to peer", {
|
|
2838
|
-
peer
|
|
2839
|
-
}, {
|
|
2840
|
-
F: __dxlog_file11,
|
|
2841
|
-
L: 43,
|
|
2842
|
-
S: this,
|
|
2843
|
-
C: (f, a) => f(...a)
|
|
2844
|
-
});
|
|
2845
|
-
this._controller.connect(peer);
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
|
-
}
|
|
2849
|
-
async onOffer(peer) {
|
|
2850
|
-
invariant9(this._controller, "Not initialized.", {
|
|
2851
|
-
F: __dxlog_file11,
|
|
2852
|
-
L: 50,
|
|
2853
|
-
S: this,
|
|
2854
|
-
A: [
|
|
2855
|
-
"this._controller",
|
|
2856
|
-
"'Not initialized.'"
|
|
2857
|
-
]
|
|
2858
|
-
});
|
|
2859
|
-
const { ownPeerId } = this._controller.getState();
|
|
2860
|
-
log10("offer", {
|
|
2861
|
-
peer,
|
|
2862
|
-
isCentral: peer.equals(this._centralPeer),
|
|
2863
|
-
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
2864
|
-
}, {
|
|
2865
|
-
F: __dxlog_file11,
|
|
2866
|
-
L: 52,
|
|
2867
|
-
S: this,
|
|
2868
|
-
C: (f, a) => f(...a)
|
|
2869
|
-
});
|
|
2870
|
-
return ownPeerId.equals(this._centralPeer) || peer.equals(this._centralPeer);
|
|
2871
|
-
}
|
|
2872
|
-
async destroy() {
|
|
2873
|
-
}
|
|
2874
|
-
};
|
|
2875
|
-
|
|
2876
2544
|
// src/transport/memory-transport.ts
|
|
2877
2545
|
import { Transform } from "@dxos/node-std/stream";
|
|
2878
2546
|
import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
|
|
2879
2547
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
2880
|
-
import { invariant as
|
|
2548
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2881
2549
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
2882
|
-
import { log as
|
|
2550
|
+
import { log as log8, logInfo as logInfo3 } from "@dxos/log";
|
|
2883
2551
|
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
2884
2552
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
2885
2553
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2887,7 +2555,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
2887
2555
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2888
2556
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2889
2557
|
}
|
|
2890
|
-
var
|
|
2558
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
2891
2559
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
2892
2560
|
var createStreamDelay = (delay) => {
|
|
2893
2561
|
return new Transform({
|
|
@@ -2916,8 +2584,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2916
2584
|
errors = new ErrorStream3();
|
|
2917
2585
|
constructor(_options) {
|
|
2918
2586
|
this._options = _options;
|
|
2919
|
-
|
|
2920
|
-
F:
|
|
2587
|
+
invariant8(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2588
|
+
F: __dxlog_file9,
|
|
2921
2589
|
L: 64,
|
|
2922
2590
|
S: this,
|
|
2923
2591
|
A: [
|
|
@@ -2931,15 +2599,15 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2931
2599
|
return !this._closed;
|
|
2932
2600
|
}
|
|
2933
2601
|
async open() {
|
|
2934
|
-
|
|
2935
|
-
F:
|
|
2602
|
+
log8("opening...", void 0, {
|
|
2603
|
+
F: __dxlog_file9,
|
|
2936
2604
|
L: 74,
|
|
2937
2605
|
S: this,
|
|
2938
2606
|
C: (f, a) => f(...a)
|
|
2939
2607
|
});
|
|
2940
2608
|
if (this._options.initiator) {
|
|
2941
|
-
|
|
2942
|
-
F:
|
|
2609
|
+
log8("sending signal", void 0, {
|
|
2610
|
+
F: __dxlog_file9,
|
|
2943
2611
|
L: 78,
|
|
2944
2612
|
S: this,
|
|
2945
2613
|
C: (f, a) => f(...a)
|
|
@@ -2969,8 +2637,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2969
2637
|
this.closed.emit();
|
|
2970
2638
|
return;
|
|
2971
2639
|
}
|
|
2972
|
-
|
|
2973
|
-
F:
|
|
2640
|
+
invariant8(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2641
|
+
F: __dxlog_file9,
|
|
2974
2642
|
L: 104,
|
|
2975
2643
|
S: this,
|
|
2976
2644
|
A: [
|
|
@@ -2980,8 +2648,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2980
2648
|
});
|
|
2981
2649
|
this._remoteConnection._remoteConnection = this;
|
|
2982
2650
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
2983
|
-
|
|
2984
|
-
F:
|
|
2651
|
+
log8("connected", void 0, {
|
|
2652
|
+
F: __dxlog_file9,
|
|
2985
2653
|
L: 108,
|
|
2986
2654
|
S: this,
|
|
2987
2655
|
C: (f, a) => f(...a)
|
|
@@ -2999,8 +2667,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2999
2667
|
return this;
|
|
3000
2668
|
}
|
|
3001
2669
|
async close() {
|
|
3002
|
-
|
|
3003
|
-
F:
|
|
2670
|
+
log8("closing...", void 0, {
|
|
2671
|
+
F: __dxlog_file9,
|
|
3004
2672
|
L: 130,
|
|
3005
2673
|
S: this,
|
|
3006
2674
|
C: (f, a) => f(...a)
|
|
@@ -3020,8 +2688,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3020
2688
|
this._remoteConnection = void 0;
|
|
3021
2689
|
}
|
|
3022
2690
|
this.closed.emit();
|
|
3023
|
-
|
|
3024
|
-
F:
|
|
2691
|
+
log8("closed", void 0, {
|
|
2692
|
+
F: __dxlog_file9,
|
|
3025
2693
|
L: 158,
|
|
3026
2694
|
S: this,
|
|
3027
2695
|
C: (f, a) => f(...a)
|
|
@@ -3029,10 +2697,10 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3029
2697
|
return this;
|
|
3030
2698
|
}
|
|
3031
2699
|
async onSignal({ payload }) {
|
|
3032
|
-
|
|
2700
|
+
log8("received signal", {
|
|
3033
2701
|
payload
|
|
3034
2702
|
}, {
|
|
3035
|
-
F:
|
|
2703
|
+
F: __dxlog_file9,
|
|
3036
2704
|
L: 163,
|
|
3037
2705
|
S: this,
|
|
3038
2706
|
C: (f, a) => f(...a)
|
|
@@ -3122,8 +2790,8 @@ var getRtcConnectionFactory = () => {
|
|
|
3122
2790
|
|
|
3123
2791
|
// src/transport/webrtc/rtc-peer-connection.ts
|
|
3124
2792
|
import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } from "@dxos/async";
|
|
3125
|
-
import { invariant as
|
|
3126
|
-
import { log as
|
|
2793
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2794
|
+
import { log as log10, logInfo as logInfo4 } from "@dxos/log";
|
|
3127
2795
|
import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
|
|
3128
2796
|
import { trace as trace4 } from "@dxos/tracing";
|
|
3129
2797
|
|
|
@@ -3132,8 +2800,8 @@ import { Duplex } from "@dxos/node-std/stream";
|
|
|
3132
2800
|
import { Event as AsyncEvent } from "@dxos/async";
|
|
3133
2801
|
import { Resource } from "@dxos/context";
|
|
3134
2802
|
import { ErrorStream as ErrorStream4 } from "@dxos/debug";
|
|
3135
|
-
import { invariant as
|
|
3136
|
-
import { log as
|
|
2803
|
+
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2804
|
+
import { log as log9 } from "@dxos/log";
|
|
3137
2805
|
import { ConnectivityError as ConnectivityError2 } from "@dxos/protocols";
|
|
3138
2806
|
|
|
3139
2807
|
// src/transport/webrtc/rtc-transport-stats.ts
|
|
@@ -3184,7 +2852,7 @@ var getRtcConnectionStats = async (connection, channelTopic) => {
|
|
|
3184
2852
|
};
|
|
3185
2853
|
|
|
3186
2854
|
// src/transport/webrtc/rtc-transport-channel.ts
|
|
3187
|
-
var
|
|
2855
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
|
|
3188
2856
|
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
3189
2857
|
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3190
2858
|
var RtcTransportChannel = class extends Resource {
|
|
@@ -3209,8 +2877,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3209
2877
|
}
|
|
3210
2878
|
}
|
|
3211
2879
|
async _open() {
|
|
3212
|
-
|
|
3213
|
-
F:
|
|
2880
|
+
invariant9(!this._isChannelCreationInProgress, void 0, {
|
|
2881
|
+
F: __dxlog_file10,
|
|
3214
2882
|
L: 57,
|
|
3215
2883
|
S: this,
|
|
3216
2884
|
A: [
|
|
@@ -3228,13 +2896,15 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3228
2896
|
}
|
|
3229
2897
|
}).catch((err) => {
|
|
3230
2898
|
if (this.isOpen) {
|
|
3231
|
-
const error = err instanceof Error ? err : new ConnectivityError2(
|
|
2899
|
+
const error = err instanceof Error ? err : new ConnectivityError2({
|
|
2900
|
+
message: `Failed to create a channel: ${JSON.stringify(err?.message)}`
|
|
2901
|
+
});
|
|
3232
2902
|
this.errors.raise(error);
|
|
3233
2903
|
} else {
|
|
3234
|
-
|
|
2904
|
+
log9.verbose("connection establishment failed after transport was closed", {
|
|
3235
2905
|
err
|
|
3236
2906
|
}, {
|
|
3237
|
-
F:
|
|
2907
|
+
F: __dxlog_file10,
|
|
3238
2908
|
L: 77,
|
|
3239
2909
|
S: this,
|
|
3240
2910
|
C: (f, a) => f(...a)
|
|
@@ -3251,8 +2921,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3251
2921
|
this._stream = void 0;
|
|
3252
2922
|
}
|
|
3253
2923
|
this.closed.emit();
|
|
3254
|
-
|
|
3255
|
-
F:
|
|
2924
|
+
log9("closed", void 0, {
|
|
2925
|
+
F: __dxlog_file10,
|
|
3256
2926
|
L: 93,
|
|
3257
2927
|
S: this,
|
|
3258
2928
|
C: (f, a) => f(...a)
|
|
@@ -3262,10 +2932,10 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3262
2932
|
Object.assign(channel, {
|
|
3263
2933
|
onopen: () => {
|
|
3264
2934
|
if (!this.isOpen) {
|
|
3265
|
-
|
|
2935
|
+
log9.warn("channel opened in a closed transport", {
|
|
3266
2936
|
topic: this._options.topic
|
|
3267
2937
|
}, {
|
|
3268
|
-
F:
|
|
2938
|
+
F: __dxlog_file10,
|
|
3269
2939
|
L: 100,
|
|
3270
2940
|
S: this,
|
|
3271
2941
|
C: (f, a) => f(...a)
|
|
@@ -3273,8 +2943,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3273
2943
|
this._safeCloseChannel(channel);
|
|
3274
2944
|
return;
|
|
3275
2945
|
}
|
|
3276
|
-
|
|
3277
|
-
F:
|
|
2946
|
+
log9("onopen", void 0, {
|
|
2947
|
+
F: __dxlog_file10,
|
|
3278
2948
|
L: 105,
|
|
3279
2949
|
S: this,
|
|
3280
2950
|
C: (f, a) => f(...a)
|
|
@@ -3291,8 +2961,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3291
2961
|
this.connected.emit();
|
|
3292
2962
|
},
|
|
3293
2963
|
onclose: async () => {
|
|
3294
|
-
|
|
3295
|
-
F:
|
|
2964
|
+
log9("onclose", void 0, {
|
|
2965
|
+
F: __dxlog_file10,
|
|
3296
2966
|
L: 118,
|
|
3297
2967
|
S: this,
|
|
3298
2968
|
C: (f, a) => f(...a)
|
|
@@ -3301,8 +2971,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3301
2971
|
},
|
|
3302
2972
|
onmessage: async (event) => {
|
|
3303
2973
|
if (!this._stream) {
|
|
3304
|
-
|
|
3305
|
-
F:
|
|
2974
|
+
log9.warn("ignoring message on a closed channel", void 0, {
|
|
2975
|
+
F: __dxlog_file10,
|
|
3306
2976
|
L: 124,
|
|
3307
2977
|
S: this,
|
|
3308
2978
|
C: (f, a) => f(...a)
|
|
@@ -3332,8 +3002,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3332
3002
|
}
|
|
3333
3003
|
async _handleChannelWrite(chunk, callback) {
|
|
3334
3004
|
if (!this._channel) {
|
|
3335
|
-
|
|
3336
|
-
F:
|
|
3005
|
+
log9.warn("writing to a channel after a connection was closed", void 0, {
|
|
3006
|
+
F: __dxlog_file10,
|
|
3337
3007
|
L: 154,
|
|
3338
3008
|
S: this,
|
|
3339
3009
|
C: (f, a) => f(...a)
|
|
@@ -3355,8 +3025,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3355
3025
|
}
|
|
3356
3026
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3357
3027
|
if (this._streamDataFlushedCallback !== null) {
|
|
3358
|
-
|
|
3359
|
-
F:
|
|
3028
|
+
log9.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3029
|
+
F: __dxlog_file10,
|
|
3360
3030
|
L: 175,
|
|
3361
3031
|
S: this,
|
|
3362
3032
|
C: (f, a) => f(...a)
|
|
@@ -3371,8 +3041,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3371
3041
|
try {
|
|
3372
3042
|
channel.close();
|
|
3373
3043
|
} catch (error) {
|
|
3374
|
-
|
|
3375
|
-
F:
|
|
3044
|
+
log9.catch(error, void 0, {
|
|
3045
|
+
F: __dxlog_file10,
|
|
3376
3046
|
L: 187,
|
|
3377
3047
|
S: this,
|
|
3378
3048
|
C: (f, a) => f(...a)
|
|
@@ -3423,7 +3093,7 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
3423
3093
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3424
3094
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3425
3095
|
}
|
|
3426
|
-
var
|
|
3096
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
|
|
3427
3097
|
var RtcPeerConnection = class {
|
|
3428
3098
|
_factory;
|
|
3429
3099
|
_options;
|
|
@@ -3471,8 +3141,8 @@ var RtcPeerConnection = class {
|
|
|
3471
3141
|
if (existingChannel) {
|
|
3472
3142
|
return existingChannel;
|
|
3473
3143
|
}
|
|
3474
|
-
|
|
3475
|
-
F:
|
|
3144
|
+
log10("waiting for initiator-peer to open a data channel", void 0, {
|
|
3145
|
+
F: __dxlog_file11,
|
|
3476
3146
|
L: 96,
|
|
3477
3147
|
S: this,
|
|
3478
3148
|
C: (f, a) => f(...a)
|
|
@@ -3500,10 +3170,10 @@ var RtcPeerConnection = class {
|
|
|
3500
3170
|
if (this._connection) {
|
|
3501
3171
|
return this._connection;
|
|
3502
3172
|
}
|
|
3503
|
-
|
|
3173
|
+
log10("initializing connection...", () => ({
|
|
3504
3174
|
remotePeer: this._options.remotePeerKey
|
|
3505
3175
|
}), {
|
|
3506
|
-
F:
|
|
3176
|
+
F: __dxlog_file11,
|
|
3507
3177
|
L: 121,
|
|
3508
3178
|
S: this,
|
|
3509
3179
|
C: (f, a) => f(...a)
|
|
@@ -3513,8 +3183,8 @@ var RtcPeerConnection = class {
|
|
|
3513
3183
|
const iceCandidateErrors = [];
|
|
3514
3184
|
Object.assign(connection, {
|
|
3515
3185
|
onnegotiationneeded: async () => {
|
|
3516
|
-
|
|
3517
|
-
F:
|
|
3186
|
+
invariant10(this._initiator, void 0, {
|
|
3187
|
+
F: __dxlog_file11,
|
|
3518
3188
|
L: 136,
|
|
3519
3189
|
S: this,
|
|
3520
3190
|
A: [
|
|
@@ -3526,8 +3196,8 @@ var RtcPeerConnection = class {
|
|
|
3526
3196
|
this._onConnectionCallbackAfterClose("onnegotiationneeded", connection);
|
|
3527
3197
|
return;
|
|
3528
3198
|
}
|
|
3529
|
-
|
|
3530
|
-
F:
|
|
3199
|
+
log10("onnegotiationneeded", void 0, {
|
|
3200
|
+
F: __dxlog_file11,
|
|
3531
3201
|
L: 143,
|
|
3532
3202
|
S: this,
|
|
3533
3203
|
C: (f, a) => f(...a)
|
|
@@ -3548,18 +3218,18 @@ var RtcPeerConnection = class {
|
|
|
3548
3218
|
return;
|
|
3549
3219
|
}
|
|
3550
3220
|
if (event.candidate) {
|
|
3551
|
-
|
|
3221
|
+
log10("onicecandidate", {
|
|
3552
3222
|
candidate: event.candidate.candidate
|
|
3553
3223
|
}, {
|
|
3554
|
-
F:
|
|
3224
|
+
F: __dxlog_file11,
|
|
3555
3225
|
L: 162,
|
|
3556
3226
|
S: this,
|
|
3557
3227
|
C: (f, a) => f(...a)
|
|
3558
3228
|
});
|
|
3559
3229
|
await this._sendIceCandidate(event.candidate);
|
|
3560
3230
|
} else {
|
|
3561
|
-
|
|
3562
|
-
F:
|
|
3231
|
+
log10("onicecandidate gathering complete", void 0, {
|
|
3232
|
+
F: __dxlog_file11,
|
|
3563
3233
|
L: 165,
|
|
3564
3234
|
S: this,
|
|
3565
3235
|
C: (f, a) => f(...a)
|
|
@@ -3584,10 +3254,10 @@ var RtcPeerConnection = class {
|
|
|
3584
3254
|
this._onConnectionCallbackAfterClose("oniceconnectionstatechange", connection);
|
|
3585
3255
|
return;
|
|
3586
3256
|
}
|
|
3587
|
-
|
|
3257
|
+
log10("oniceconnectionstatechange", {
|
|
3588
3258
|
state: connection.iceConnectionState
|
|
3589
3259
|
}, {
|
|
3590
|
-
F:
|
|
3260
|
+
F: __dxlog_file11,
|
|
3591
3261
|
L: 185,
|
|
3592
3262
|
S: this,
|
|
3593
3263
|
C: (f, a) => f(...a)
|
|
@@ -3606,10 +3276,10 @@ var RtcPeerConnection = class {
|
|
|
3606
3276
|
}
|
|
3607
3277
|
return;
|
|
3608
3278
|
}
|
|
3609
|
-
|
|
3279
|
+
log10("onconnectionstatechange", {
|
|
3610
3280
|
state: connection.connectionState
|
|
3611
3281
|
}, {
|
|
3612
|
-
F:
|
|
3282
|
+
F: __dxlog_file11,
|
|
3613
3283
|
L: 202,
|
|
3614
3284
|
S: this,
|
|
3615
3285
|
C: (f, a) => f(...a)
|
|
@@ -3619,10 +3289,10 @@ var RtcPeerConnection = class {
|
|
|
3619
3289
|
}
|
|
3620
3290
|
},
|
|
3621
3291
|
onsignalingstatechange: () => {
|
|
3622
|
-
|
|
3292
|
+
log10("onsignalingstatechange", {
|
|
3623
3293
|
state: connection.signalingState
|
|
3624
3294
|
}, {
|
|
3625
|
-
F:
|
|
3295
|
+
F: __dxlog_file11,
|
|
3626
3296
|
L: 209,
|
|
3627
3297
|
S: this,
|
|
3628
3298
|
C: (f, a) => f(...a)
|
|
@@ -3631,8 +3301,8 @@ var RtcPeerConnection = class {
|
|
|
3631
3301
|
// When channel is added to connection.
|
|
3632
3302
|
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event
|
|
3633
3303
|
ondatachannel: (event) => {
|
|
3634
|
-
|
|
3635
|
-
F:
|
|
3304
|
+
invariant10(!this._initiator, "Initiator is expected to create data channels.", {
|
|
3305
|
+
F: __dxlog_file11,
|
|
3636
3306
|
L: 215,
|
|
3637
3307
|
S: this,
|
|
3638
3308
|
A: [
|
|
@@ -3644,10 +3314,10 @@ var RtcPeerConnection = class {
|
|
|
3644
3314
|
this._onConnectionCallbackAfterClose("ondatachannel", connection);
|
|
3645
3315
|
return;
|
|
3646
3316
|
}
|
|
3647
|
-
|
|
3317
|
+
log10("ondatachannel", {
|
|
3648
3318
|
label: event.channel.label
|
|
3649
3319
|
}, {
|
|
3650
|
-
F:
|
|
3320
|
+
F: __dxlog_file11,
|
|
3651
3321
|
L: 222,
|
|
3652
3322
|
S: this,
|
|
3653
3323
|
C: (f, a) => f(...a)
|
|
@@ -3672,10 +3342,10 @@ var RtcPeerConnection = class {
|
|
|
3672
3342
|
}
|
|
3673
3343
|
_abortConnection(connection, error) {
|
|
3674
3344
|
if (connection !== this._connection) {
|
|
3675
|
-
|
|
3345
|
+
log10.error("attempted to abort an inactive connection", {
|
|
3676
3346
|
error
|
|
3677
3347
|
}, {
|
|
3678
|
-
F:
|
|
3348
|
+
F: __dxlog_file11,
|
|
3679
3349
|
L: 247,
|
|
3680
3350
|
S: this,
|
|
3681
3351
|
C: (f, a) => f(...a)
|
|
@@ -3693,18 +3363,18 @@ var RtcPeerConnection = class {
|
|
|
3693
3363
|
}
|
|
3694
3364
|
this._transportChannels.clear();
|
|
3695
3365
|
this._safeCloseConnection();
|
|
3696
|
-
|
|
3366
|
+
log10("connection aborted", {
|
|
3697
3367
|
reason: error.message
|
|
3698
3368
|
}, {
|
|
3699
|
-
F:
|
|
3369
|
+
F: __dxlog_file11,
|
|
3700
3370
|
L: 261,
|
|
3701
3371
|
S: this,
|
|
3702
3372
|
C: (f, a) => f(...a)
|
|
3703
3373
|
});
|
|
3704
3374
|
}
|
|
3705
3375
|
async _lockAndCloseConnection() {
|
|
3706
|
-
|
|
3707
|
-
F:
|
|
3376
|
+
invariant10(this._transportChannels.size === 0, void 0, {
|
|
3377
|
+
F: __dxlog_file11,
|
|
3708
3378
|
L: 266,
|
|
3709
3379
|
S: this,
|
|
3710
3380
|
A: [
|
|
@@ -3714,8 +3384,8 @@ var RtcPeerConnection = class {
|
|
|
3714
3384
|
});
|
|
3715
3385
|
if (this._connection) {
|
|
3716
3386
|
this._safeCloseConnection();
|
|
3717
|
-
|
|
3718
|
-
F:
|
|
3387
|
+
log10("connection closed", void 0, {
|
|
3388
|
+
F: __dxlog_file11,
|
|
3719
3389
|
L: 269,
|
|
3720
3390
|
S: this,
|
|
3721
3391
|
C: (f, a) => f(...a)
|
|
@@ -3725,10 +3395,10 @@ var RtcPeerConnection = class {
|
|
|
3725
3395
|
async onSignal(signal) {
|
|
3726
3396
|
const connection = this._connection;
|
|
3727
3397
|
if (!connection) {
|
|
3728
|
-
|
|
3398
|
+
log10.warn("a signal ignored because the connection was closed", {
|
|
3729
3399
|
type: signal.payload.data.type
|
|
3730
3400
|
}, {
|
|
3731
|
-
F:
|
|
3401
|
+
F: __dxlog_file11,
|
|
3732
3402
|
L: 277,
|
|
3733
3403
|
S: this,
|
|
3734
3404
|
C: (f, a) => f(...a)
|
|
@@ -3792,10 +3462,10 @@ var RtcPeerConnection = class {
|
|
|
3792
3462
|
this._abortConnection(connection, new Error(`Unknown signal type ${data.type}.`));
|
|
3793
3463
|
break;
|
|
3794
3464
|
}
|
|
3795
|
-
|
|
3465
|
+
log10("signal processed", {
|
|
3796
3466
|
type: data.type
|
|
3797
3467
|
}, {
|
|
3798
|
-
F:
|
|
3468
|
+
F: __dxlog_file11,
|
|
3799
3469
|
L: 336,
|
|
3800
3470
|
S: this,
|
|
3801
3471
|
C: (f, a) => f(...a)
|
|
@@ -3805,10 +3475,10 @@ var RtcPeerConnection = class {
|
|
|
3805
3475
|
try {
|
|
3806
3476
|
await this._readyForCandidates.wait();
|
|
3807
3477
|
if (connection === this._connection) {
|
|
3808
|
-
|
|
3478
|
+
log10("adding ice candidate", {
|
|
3809
3479
|
candidate
|
|
3810
3480
|
}, {
|
|
3811
|
-
F:
|
|
3481
|
+
F: __dxlog_file11,
|
|
3812
3482
|
L: 344,
|
|
3813
3483
|
S: this,
|
|
3814
3484
|
C: (f, a) => f(...a)
|
|
@@ -3816,8 +3486,8 @@ var RtcPeerConnection = class {
|
|
|
3816
3486
|
await connection.addIceCandidate(candidate);
|
|
3817
3487
|
}
|
|
3818
3488
|
} catch (err) {
|
|
3819
|
-
|
|
3820
|
-
F:
|
|
3489
|
+
log10.catch(err, void 0, {
|
|
3490
|
+
F: __dxlog_file11,
|
|
3821
3491
|
L: 348,
|
|
3822
3492
|
S: this,
|
|
3823
3493
|
C: (f, a) => f(...a)
|
|
@@ -3826,16 +3496,16 @@ var RtcPeerConnection = class {
|
|
|
3826
3496
|
}
|
|
3827
3497
|
_onSessionNegotiated(connection) {
|
|
3828
3498
|
if (connection === this._connection) {
|
|
3829
|
-
|
|
3830
|
-
F:
|
|
3499
|
+
log10("ready to process ice candidates", void 0, {
|
|
3500
|
+
F: __dxlog_file11,
|
|
3831
3501
|
L: 354,
|
|
3832
3502
|
S: this,
|
|
3833
3503
|
C: (f, a) => f(...a)
|
|
3834
3504
|
});
|
|
3835
3505
|
this._readyForCandidates.wake();
|
|
3836
3506
|
} else {
|
|
3837
|
-
|
|
3838
|
-
F:
|
|
3507
|
+
log10.warn("session was negotiated after connection became inactive", void 0, {
|
|
3508
|
+
F: __dxlog_file11,
|
|
3839
3509
|
L: 357,
|
|
3840
3510
|
S: this,
|
|
3841
3511
|
C: (f, a) => f(...a)
|
|
@@ -3843,11 +3513,11 @@ var RtcPeerConnection = class {
|
|
|
3843
3513
|
}
|
|
3844
3514
|
}
|
|
3845
3515
|
_onConnectionCallbackAfterClose(callback, connection) {
|
|
3846
|
-
|
|
3516
|
+
log10.warn("callback invoked after a connection was destroyed, this is probably a bug", {
|
|
3847
3517
|
callback,
|
|
3848
3518
|
state: connection.connectionState
|
|
3849
3519
|
}, {
|
|
3850
|
-
F:
|
|
3520
|
+
F: __dxlog_file11,
|
|
3851
3521
|
L: 362,
|
|
3852
3522
|
S: this,
|
|
3853
3523
|
C: (f, a) => f(...a)
|
|
@@ -3859,8 +3529,8 @@ var RtcPeerConnection = class {
|
|
|
3859
3529
|
try {
|
|
3860
3530
|
connection?.close();
|
|
3861
3531
|
} catch (err) {
|
|
3862
|
-
|
|
3863
|
-
F:
|
|
3532
|
+
log10.catch(err, void 0, {
|
|
3533
|
+
F: __dxlog_file11,
|
|
3864
3534
|
L: 374,
|
|
3865
3535
|
S: this,
|
|
3866
3536
|
C: (f, a) => f(...a)
|
|
@@ -3870,8 +3540,8 @@ var RtcPeerConnection = class {
|
|
|
3870
3540
|
this._connection = void 0;
|
|
3871
3541
|
this._dataChannels.clear();
|
|
3872
3542
|
this._readyForCandidates.wake();
|
|
3873
|
-
void this._factory.onConnectionDestroyed().catch((err) =>
|
|
3874
|
-
F:
|
|
3543
|
+
void this._factory.onConnectionDestroyed().catch((err) => log10.catch(err, void 0, {
|
|
3544
|
+
F: __dxlog_file11,
|
|
3875
3545
|
L: 380,
|
|
3876
3546
|
S: this,
|
|
3877
3547
|
C: (f, a) => f(...a)
|
|
@@ -3895,8 +3565,8 @@ var RtcPeerConnection = class {
|
|
|
3895
3565
|
];
|
|
3896
3566
|
}
|
|
3897
3567
|
} catch (error) {
|
|
3898
|
-
|
|
3899
|
-
F:
|
|
3568
|
+
log10.catch(error, void 0, {
|
|
3569
|
+
F: __dxlog_file11,
|
|
3900
3570
|
L: 396,
|
|
3901
3571
|
S: this,
|
|
3902
3572
|
C: (f, a) => f(...a)
|
|
@@ -3920,10 +3590,10 @@ var RtcPeerConnection = class {
|
|
|
3920
3590
|
}
|
|
3921
3591
|
});
|
|
3922
3592
|
} catch (err) {
|
|
3923
|
-
|
|
3593
|
+
log10.warn("signaling error", {
|
|
3924
3594
|
err
|
|
3925
3595
|
}, {
|
|
3926
|
-
F:
|
|
3596
|
+
F: __dxlog_file11,
|
|
3927
3597
|
L: 417,
|
|
3928
3598
|
S: this,
|
|
3929
3599
|
C: (f, a) => f(...a)
|
|
@@ -4001,8 +3671,10 @@ var isRemoteDescriptionSet = (connection, data) => {
|
|
|
4001
3671
|
};
|
|
4002
3672
|
var createIceFailureError = (details) => {
|
|
4003
3673
|
const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
|
|
4004
|
-
return new ConnectivityError3(
|
|
4005
|
-
|
|
3674
|
+
return new ConnectivityError3({
|
|
3675
|
+
message: `ICE failed:
|
|
3676
|
+
${candidateErrors.join("\n")}`
|
|
3677
|
+
});
|
|
4006
3678
|
};
|
|
4007
3679
|
|
|
4008
3680
|
// src/transport/webrtc/rtc-transport-factory.ts
|
|
@@ -4028,13 +3700,13 @@ import { Writable } from "@dxos/node-std/stream";
|
|
|
4028
3700
|
import { Event as Event8, scheduleTask as scheduleTask4 } from "@dxos/async";
|
|
4029
3701
|
import { Resource as Resource2 } from "@dxos/context";
|
|
4030
3702
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
4031
|
-
import { invariant as
|
|
3703
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
4032
3704
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
4033
|
-
import { log as
|
|
3705
|
+
import { log as log11 } from "@dxos/log";
|
|
4034
3706
|
import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError4, TimeoutError as TimeoutError3 } from "@dxos/protocols";
|
|
4035
3707
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
4036
3708
|
import { arrayToBuffer } from "@dxos/util";
|
|
4037
|
-
var
|
|
3709
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
|
|
4038
3710
|
var RPC_TIMEOUT = 1e4;
|
|
4039
3711
|
var CLOSE_RPC_TIMEOUT = 3e3;
|
|
4040
3712
|
var RESP_MIN_THRESHOLD = 500;
|
|
@@ -4067,8 +3739,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4067
3739
|
this._serviceStream = stream;
|
|
4068
3740
|
stream.waitUntilReady().then(() => {
|
|
4069
3741
|
stream.subscribe(async (event) => {
|
|
4070
|
-
|
|
4071
|
-
F:
|
|
3742
|
+
log11("rtc transport proxy event", event, {
|
|
3743
|
+
F: __dxlog_file12,
|
|
4072
3744
|
L: 66,
|
|
4073
3745
|
S: this,
|
|
4074
3746
|
C: (f, a) => f(...a)
|
|
@@ -4081,10 +3753,10 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4081
3753
|
await this._handleSignal(event.signal);
|
|
4082
3754
|
}
|
|
4083
3755
|
}, (err) => {
|
|
4084
|
-
|
|
3756
|
+
log11("rtc bridge stream closed", {
|
|
4085
3757
|
err
|
|
4086
3758
|
}, {
|
|
4087
|
-
F:
|
|
3759
|
+
F: __dxlog_file12,
|
|
4088
3760
|
L: 76,
|
|
4089
3761
|
S: this,
|
|
4090
3762
|
C: (f, a) => f(...a)
|
|
@@ -4105,8 +3777,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4105
3777
|
timeout: RPC_TIMEOUT
|
|
4106
3778
|
}).then(() => {
|
|
4107
3779
|
if (Date.now() - sendStartMs > RESP_MIN_THRESHOLD) {
|
|
4108
|
-
|
|
4109
|
-
F:
|
|
3780
|
+
log11("slow response, delaying callback", void 0, {
|
|
3781
|
+
F: __dxlog_file12,
|
|
4110
3782
|
L: 93,
|
|
4111
3783
|
S: this,
|
|
4112
3784
|
C: (f, a) => f(...a)
|
|
@@ -4138,8 +3810,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4138
3810
|
await this._serviceStream?.close();
|
|
4139
3811
|
this._serviceStream = void 0;
|
|
4140
3812
|
} catch (err) {
|
|
4141
|
-
|
|
4142
|
-
F:
|
|
3813
|
+
log11.catch(err, void 0, {
|
|
3814
|
+
F: __dxlog_file12,
|
|
4143
3815
|
L: 128,
|
|
4144
3816
|
S: this,
|
|
4145
3817
|
C: (f, a) => f(...a)
|
|
@@ -4152,8 +3824,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4152
3824
|
timeout: CLOSE_RPC_TIMEOUT
|
|
4153
3825
|
});
|
|
4154
3826
|
} catch (err) {
|
|
4155
|
-
|
|
4156
|
-
F:
|
|
3827
|
+
log11.catch(err, void 0, {
|
|
3828
|
+
F: __dxlog_file12,
|
|
4157
3829
|
L: 134,
|
|
4158
3830
|
S: this,
|
|
4159
3831
|
C: (f, a) => f(...a)
|
|
@@ -4198,7 +3870,9 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4198
3870
|
} catch (error) {
|
|
4199
3871
|
const type = signalEvent.payload.payload.data?.type;
|
|
4200
3872
|
if (type === "offer" || type === "answer") {
|
|
4201
|
-
this._raiseIfOpen(new ConnectivityError4(
|
|
3873
|
+
this._raiseIfOpen(new ConnectivityError4({
|
|
3874
|
+
message: `Session establishment failed: ${type} couldn't be sent.`
|
|
3875
|
+
}));
|
|
4202
3876
|
}
|
|
4203
3877
|
}
|
|
4204
3878
|
}
|
|
@@ -4236,11 +3910,11 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4236
3910
|
if (this.isOpen) {
|
|
4237
3911
|
this.errors.raise(error);
|
|
4238
3912
|
} else {
|
|
4239
|
-
|
|
3913
|
+
log11.info("error swallowed because transport was closed", {
|
|
4240
3914
|
message: error.message
|
|
4241
3915
|
}, {
|
|
4242
|
-
F:
|
|
4243
|
-
L:
|
|
3916
|
+
F: __dxlog_file12,
|
|
3917
|
+
L: 217,
|
|
4244
3918
|
S: this,
|
|
4245
3919
|
C: (f, a) => f(...a)
|
|
4246
3920
|
});
|
|
@@ -4269,9 +3943,9 @@ var RtcTransportProxyFactory = class {
|
|
|
4269
3943
|
return this;
|
|
4270
3944
|
}
|
|
4271
3945
|
createTransport(options) {
|
|
4272
|
-
|
|
4273
|
-
F:
|
|
4274
|
-
L:
|
|
3946
|
+
invariant11(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
|
|
3947
|
+
F: __dxlog_file12,
|
|
3948
|
+
L: 247,
|
|
4275
3949
|
S: this,
|
|
4276
3950
|
A: [
|
|
4277
3951
|
"this._bridgeService",
|
|
@@ -4292,11 +3966,17 @@ var RtcTransportProxyFactory = class {
|
|
|
4292
3966
|
var decodeError = (err) => {
|
|
4293
3967
|
const message = typeof err === "string" ? err : err.message;
|
|
4294
3968
|
if (message.includes("CONNECTION_RESET")) {
|
|
4295
|
-
return new ConnectionResetError2(
|
|
3969
|
+
return new ConnectionResetError2({
|
|
3970
|
+
message
|
|
3971
|
+
});
|
|
4296
3972
|
} else if (message.includes("TIMEOUT")) {
|
|
4297
|
-
return new TimeoutError3(
|
|
3973
|
+
return new TimeoutError3({
|
|
3974
|
+
message
|
|
3975
|
+
});
|
|
4298
3976
|
} else if (message.includes("CONNECTIVITY_ERROR")) {
|
|
4299
|
-
return new ConnectivityError4(
|
|
3977
|
+
return new ConnectivityError4({
|
|
3978
|
+
message
|
|
3979
|
+
});
|
|
4300
3980
|
} else {
|
|
4301
3981
|
return typeof err === "string" ? new Error(err) : err;
|
|
4302
3982
|
}
|
|
@@ -4305,12 +3985,12 @@ var decodeError = (err) => {
|
|
|
4305
3985
|
// src/transport/webrtc/rtc-transport-service.ts
|
|
4306
3986
|
import { Duplex as Duplex2 } from "@dxos/node-std/stream";
|
|
4307
3987
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
4308
|
-
import { invariant as
|
|
3988
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
4309
3989
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
4310
|
-
import { log as
|
|
3990
|
+
import { log as log12 } from "@dxos/log";
|
|
4311
3991
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
4312
3992
|
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
4313
|
-
var
|
|
3993
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
|
|
4314
3994
|
var RtcTransportService = class {
|
|
4315
3995
|
_transportFactory;
|
|
4316
3996
|
_openTransports = new ComplexMap8(PublicKey11.hash);
|
|
@@ -4323,8 +4003,8 @@ var RtcTransportService = class {
|
|
|
4323
4003
|
open(request) {
|
|
4324
4004
|
const existingTransport = this._openTransports.get(request.proxyId);
|
|
4325
4005
|
if (existingTransport) {
|
|
4326
|
-
|
|
4327
|
-
F:
|
|
4006
|
+
log12.error("requesting a new transport bridge for an existing proxy", void 0, {
|
|
4007
|
+
F: __dxlog_file13,
|
|
4328
4008
|
L: 54,
|
|
4329
4009
|
S: this,
|
|
4330
4010
|
C: (f, a) => f(...a)
|
|
@@ -4389,8 +4069,8 @@ var RtcTransportService = class {
|
|
|
4389
4069
|
close(err);
|
|
4390
4070
|
});
|
|
4391
4071
|
ready();
|
|
4392
|
-
|
|
4393
|
-
F:
|
|
4072
|
+
log12("stream ready", void 0, {
|
|
4073
|
+
F: __dxlog_file13,
|
|
4394
4074
|
L: 116,
|
|
4395
4075
|
S: this,
|
|
4396
4076
|
C: (f, a) => f(...a)
|
|
@@ -4400,8 +4080,8 @@ var RtcTransportService = class {
|
|
|
4400
4080
|
}
|
|
4401
4081
|
async sendSignal({ proxyId, signal }) {
|
|
4402
4082
|
const transport = this._openTransports.get(proxyId);
|
|
4403
|
-
|
|
4404
|
-
F:
|
|
4083
|
+
invariant12(transport, void 0, {
|
|
4084
|
+
F: __dxlog_file13,
|
|
4405
4085
|
L: 124,
|
|
4406
4086
|
S: this,
|
|
4407
4087
|
A: [
|
|
@@ -4413,8 +4093,8 @@ var RtcTransportService = class {
|
|
|
4413
4093
|
}
|
|
4414
4094
|
async getDetails({ proxyId }) {
|
|
4415
4095
|
const transport = this._openTransports.get(proxyId);
|
|
4416
|
-
|
|
4417
|
-
F:
|
|
4096
|
+
invariant12(transport, void 0, {
|
|
4097
|
+
F: __dxlog_file13,
|
|
4418
4098
|
L: 131,
|
|
4419
4099
|
S: this,
|
|
4420
4100
|
A: [
|
|
@@ -4428,8 +4108,8 @@ var RtcTransportService = class {
|
|
|
4428
4108
|
}
|
|
4429
4109
|
async getStats({ proxyId }) {
|
|
4430
4110
|
const transport = this._openTransports.get(proxyId);
|
|
4431
|
-
|
|
4432
|
-
F:
|
|
4111
|
+
invariant12(transport, void 0, {
|
|
4112
|
+
F: __dxlog_file13,
|
|
4433
4113
|
L: 138,
|
|
4434
4114
|
S: this,
|
|
4435
4115
|
A: [
|
|
@@ -4443,8 +4123,8 @@ var RtcTransportService = class {
|
|
|
4443
4123
|
}
|
|
4444
4124
|
async sendData({ proxyId, payload }) {
|
|
4445
4125
|
const transport = this._openTransports.get(proxyId);
|
|
4446
|
-
|
|
4447
|
-
F:
|
|
4126
|
+
invariant12(transport, void 0, {
|
|
4127
|
+
F: __dxlog_file13,
|
|
4448
4128
|
L: 145,
|
|
4449
4129
|
S: this,
|
|
4450
4130
|
A: [
|
|
@@ -4475,10 +4155,10 @@ var RtcTransportService = class {
|
|
|
4475
4155
|
try {
|
|
4476
4156
|
await transport.transport.close();
|
|
4477
4157
|
} catch (error) {
|
|
4478
|
-
|
|
4158
|
+
log12.warn("transport close error", {
|
|
4479
4159
|
message: error?.message
|
|
4480
4160
|
}, {
|
|
4481
|
-
F:
|
|
4161
|
+
F: __dxlog_file13,
|
|
4482
4162
|
L: 175,
|
|
4483
4163
|
S: this,
|
|
4484
4164
|
C: (f, a) => f(...a)
|
|
@@ -4487,17 +4167,17 @@ var RtcTransportService = class {
|
|
|
4487
4167
|
try {
|
|
4488
4168
|
transport.connectorStream.end();
|
|
4489
4169
|
} catch (error) {
|
|
4490
|
-
|
|
4170
|
+
log12.warn("connectorStream close error", {
|
|
4491
4171
|
message: error?.message
|
|
4492
4172
|
}, {
|
|
4493
|
-
F:
|
|
4173
|
+
F: __dxlog_file13,
|
|
4494
4174
|
L: 180,
|
|
4495
4175
|
S: this,
|
|
4496
4176
|
C: (f, a) => f(...a)
|
|
4497
4177
|
});
|
|
4498
4178
|
}
|
|
4499
|
-
|
|
4500
|
-
F:
|
|
4179
|
+
log12("closed", void 0, {
|
|
4180
|
+
F: __dxlog_file13,
|
|
4501
4181
|
L: 182,
|
|
4502
4182
|
S: this,
|
|
4503
4183
|
C: (f, a) => f(...a)
|
|
@@ -4519,10 +4199,10 @@ var createStateUpdater = (next) => {
|
|
|
4519
4199
|
|
|
4520
4200
|
// src/wire-protocol.ts
|
|
4521
4201
|
import { Teleport } from "@dxos/teleport";
|
|
4522
|
-
var createTeleportProtocolFactory = (onConnection,
|
|
4202
|
+
var createTeleportProtocolFactory = (onConnection, defaultProps) => {
|
|
4523
4203
|
return (params) => {
|
|
4524
4204
|
const teleport = new Teleport({
|
|
4525
|
-
...
|
|
4205
|
+
...defaultProps,
|
|
4526
4206
|
...params
|
|
4527
4207
|
});
|
|
4528
4208
|
return {
|
|
@@ -4544,7 +4224,6 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
|
|
|
4544
4224
|
export {
|
|
4545
4225
|
ConnectionState,
|
|
4546
4226
|
Connection,
|
|
4547
|
-
createIceProvider,
|
|
4548
4227
|
SwarmMessenger,
|
|
4549
4228
|
Swarm,
|
|
4550
4229
|
SwarmMapper,
|
|
@@ -4554,8 +4233,6 @@ export {
|
|
|
4554
4233
|
ConnectionLog,
|
|
4555
4234
|
SwarmNetworkManager,
|
|
4556
4235
|
FullyConnectedTopology,
|
|
4557
|
-
MMSTTopology,
|
|
4558
|
-
StarTopology,
|
|
4559
4236
|
MemoryTransportFactory,
|
|
4560
4237
|
MemoryTransport,
|
|
4561
4238
|
TransportKind,
|
|
@@ -4565,4 +4242,4 @@ export {
|
|
|
4565
4242
|
RtcTransportService,
|
|
4566
4243
|
createTeleportProtocolFactory
|
|
4567
4244
|
};
|
|
4568
|
-
//# sourceMappingURL=chunk-
|
|
4245
|
+
//# sourceMappingURL=chunk-AQSYW43M.mjs.map
|