@dxos/network-manager 0.1.56-main.83e9b8a → 0.1.56-main.a25bb93
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-5R7TDXUU.mjs → chunk-FC6CWDES.mjs} +622 -187
- package/dist/lib/browser/chunk-FC6CWDES.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/index.cjs +621 -186
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +547 -168
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
- 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/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/topology/fully-connected-topology.d.ts.map +1 -1
- package/dist/types/src/topology/star-topology.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/network-manager.ts +1 -2
- package/src/signal/swarm-messenger.ts +1 -2
- package/src/swarm/connection-limiter.ts +2 -1
- package/src/swarm/connection.ts +17 -3
- package/src/swarm/peer.ts +24 -2
- package/src/swarm/swarm.ts +1 -2
- package/src/topology/fully-connected-topology.ts +1 -2
- package/src/topology/mmst-topology.ts +1 -1
- package/src/topology/star-topology.ts +1 -2
- package/src/transport/memory-transport.ts +1 -1
- package/src/transport/webrtc-transport-proxy.ts +14 -12
- package/src/transport/webrtc-transport-service.ts +31 -8
- package/src/transport/webrtc-transport.ts +1 -1
- package/dist/lib/browser/chunk-5R7TDXUU.mjs.map +0 -7
|
@@ -8,11 +8,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
11
|
-
import invariant from "tiny-invariant";
|
|
12
11
|
import { DeferredTask, Event, sleep, synchronized } from "@dxos/async";
|
|
13
12
|
import { Context, cancelWithContext } from "@dxos/context";
|
|
14
13
|
import { ErrorStream } from "@dxos/debug";
|
|
15
14
|
import { CancelledError } from "@dxos/errors";
|
|
15
|
+
import { invariant } from "@dxos/invariant";
|
|
16
16
|
import { PublicKey } from "@dxos/keys";
|
|
17
17
|
import { log } from "@dxos/log";
|
|
18
18
|
import { trace } from "@dxos/protocols";
|
|
@@ -84,6 +84,18 @@ var Connection = class {
|
|
|
84
84
|
await this._flushSignalBuffer();
|
|
85
85
|
});
|
|
86
86
|
this._signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
87
|
+
log.trace("dxos.mesh.connection.construct", {
|
|
88
|
+
sessionId: this.sessionId,
|
|
89
|
+
topic: this.topic,
|
|
90
|
+
localPeerId: this.ownId,
|
|
91
|
+
remotePeerId: this.remoteId,
|
|
92
|
+
initiator: this.initiator
|
|
93
|
+
}, {
|
|
94
|
+
F: __dxlog_file,
|
|
95
|
+
L: 95,
|
|
96
|
+
S: this,
|
|
97
|
+
C: (f, a) => f(...a)
|
|
98
|
+
});
|
|
87
99
|
}
|
|
88
100
|
get state() {
|
|
89
101
|
return this._state;
|
|
@@ -98,12 +110,32 @@ var Connection = class {
|
|
|
98
110
|
* Create an underlying transport and prepares it for the connection.
|
|
99
111
|
*/
|
|
100
112
|
async openConnection() {
|
|
101
|
-
invariant(this._state === ConnectionState.INITIAL, "Invalid state."
|
|
113
|
+
invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
|
|
114
|
+
F: __dxlog_file,
|
|
115
|
+
L: 120,
|
|
116
|
+
S: this,
|
|
117
|
+
A: [
|
|
118
|
+
"this._state === ConnectionState.INITIAL",
|
|
119
|
+
"'Invalid state.'"
|
|
120
|
+
]
|
|
121
|
+
});
|
|
102
122
|
log.trace("dxos.mesh.connection.open-connection", trace.begin({
|
|
103
123
|
id: this._instanceId
|
|
104
124
|
}), {
|
|
105
125
|
F: __dxlog_file,
|
|
106
|
-
L:
|
|
126
|
+
L: 121,
|
|
127
|
+
S: this,
|
|
128
|
+
C: (f, a) => f(...a)
|
|
129
|
+
});
|
|
130
|
+
log.trace("dxos.mesh.connection.open", {
|
|
131
|
+
sessionId: this.sessionId,
|
|
132
|
+
topic: this.topic,
|
|
133
|
+
localPeerId: this.ownId,
|
|
134
|
+
remotePeerId: this.remoteId,
|
|
135
|
+
initiator: this.initiator
|
|
136
|
+
}, {
|
|
137
|
+
F: __dxlog_file,
|
|
138
|
+
L: 122,
|
|
107
139
|
S: this,
|
|
108
140
|
C: (f, a) => f(...a)
|
|
109
141
|
});
|
|
@@ -114,13 +146,21 @@ var Connection = class {
|
|
|
114
146
|
this._protocol.stream.on("close", () => {
|
|
115
147
|
log("protocol stream closed", void 0, {
|
|
116
148
|
F: __dxlog_file,
|
|
117
|
-
L:
|
|
149
|
+
L: 139,
|
|
118
150
|
S: this,
|
|
119
151
|
C: (f, a) => f(...a)
|
|
120
152
|
});
|
|
121
153
|
this.close().catch((err) => this.errors.raise(err));
|
|
122
154
|
});
|
|
123
|
-
invariant(!this._transport
|
|
155
|
+
invariant(!this._transport, void 0, {
|
|
156
|
+
F: __dxlog_file,
|
|
157
|
+
L: 143,
|
|
158
|
+
S: this,
|
|
159
|
+
A: [
|
|
160
|
+
"!this._transport",
|
|
161
|
+
""
|
|
162
|
+
]
|
|
163
|
+
});
|
|
124
164
|
this._transport = this._transportFactory.createTransport({
|
|
125
165
|
initiator: this.initiator,
|
|
126
166
|
stream: this._protocol.stream,
|
|
@@ -146,7 +186,7 @@ var Connection = class {
|
|
|
146
186
|
id: this._instanceId
|
|
147
187
|
}), {
|
|
148
188
|
F: __dxlog_file,
|
|
149
|
-
L:
|
|
189
|
+
L: 172,
|
|
150
190
|
S: this,
|
|
151
191
|
C: (f, a) => f(...a)
|
|
152
192
|
});
|
|
@@ -162,7 +202,7 @@ var Connection = class {
|
|
|
162
202
|
peerId: this.ownId
|
|
163
203
|
}, {
|
|
164
204
|
F: __dxlog_file,
|
|
165
|
-
L:
|
|
205
|
+
L: 184,
|
|
166
206
|
S: this,
|
|
167
207
|
C: (f, a) => f(...a)
|
|
168
208
|
});
|
|
@@ -171,7 +211,7 @@ var Connection = class {
|
|
|
171
211
|
} catch (err) {
|
|
172
212
|
log.catch(err, void 0, {
|
|
173
213
|
F: __dxlog_file,
|
|
174
|
-
L:
|
|
214
|
+
L: 190,
|
|
175
215
|
S: this,
|
|
176
216
|
C: (f, a) => f(...a)
|
|
177
217
|
});
|
|
@@ -181,7 +221,7 @@ var Connection = class {
|
|
|
181
221
|
} catch (err) {
|
|
182
222
|
log.catch(err, void 0, {
|
|
183
223
|
F: __dxlog_file,
|
|
184
|
-
L:
|
|
224
|
+
L: 197,
|
|
185
225
|
S: this,
|
|
186
226
|
C: (f, a) => f(...a)
|
|
187
227
|
});
|
|
@@ -190,7 +230,7 @@ var Connection = class {
|
|
|
190
230
|
peerId: this.ownId
|
|
191
231
|
}, {
|
|
192
232
|
F: __dxlog_file,
|
|
193
|
-
L:
|
|
233
|
+
L: 200,
|
|
194
234
|
S: this,
|
|
195
235
|
C: (f, a) => f(...a)
|
|
196
236
|
});
|
|
@@ -230,7 +270,7 @@ var Connection = class {
|
|
|
230
270
|
err
|
|
231
271
|
}, {
|
|
232
272
|
F: __dxlog_file,
|
|
233
|
-
L:
|
|
273
|
+
L: 234,
|
|
234
274
|
S: this,
|
|
235
275
|
C: (f, a) => f(...a)
|
|
236
276
|
});
|
|
@@ -242,19 +282,51 @@ var Connection = class {
|
|
|
242
282
|
*/
|
|
243
283
|
async signal(msg) {
|
|
244
284
|
var _a, _b, _c;
|
|
245
|
-
invariant(msg.sessionId
|
|
285
|
+
invariant(msg.sessionId, void 0, {
|
|
286
|
+
F: __dxlog_file,
|
|
287
|
+
L: 243,
|
|
288
|
+
S: this,
|
|
289
|
+
A: [
|
|
290
|
+
"msg.sessionId",
|
|
291
|
+
""
|
|
292
|
+
]
|
|
293
|
+
});
|
|
246
294
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
247
295
|
log("dropping signal for incorrect session id", void 0, {
|
|
248
296
|
F: __dxlog_file,
|
|
249
|
-
L:
|
|
297
|
+
L: 245,
|
|
250
298
|
S: this,
|
|
251
299
|
C: (f, a) => f(...a)
|
|
252
300
|
});
|
|
253
301
|
return;
|
|
254
302
|
}
|
|
255
|
-
invariant(msg.data.signal || msg.data.signalBatch
|
|
256
|
-
|
|
257
|
-
|
|
303
|
+
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
304
|
+
F: __dxlog_file,
|
|
305
|
+
L: 248,
|
|
306
|
+
S: this,
|
|
307
|
+
A: [
|
|
308
|
+
"msg.data.signal || msg.data.signalBatch",
|
|
309
|
+
""
|
|
310
|
+
]
|
|
311
|
+
});
|
|
312
|
+
invariant((_a = msg.author) == null ? void 0 : _a.equals(this.remoteId), void 0, {
|
|
313
|
+
F: __dxlog_file,
|
|
314
|
+
L: 249,
|
|
315
|
+
S: this,
|
|
316
|
+
A: [
|
|
317
|
+
"msg.author?.equals(this.remoteId)",
|
|
318
|
+
""
|
|
319
|
+
]
|
|
320
|
+
});
|
|
321
|
+
invariant((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId), void 0, {
|
|
322
|
+
F: __dxlog_file,
|
|
323
|
+
L: 250,
|
|
324
|
+
S: this,
|
|
325
|
+
A: [
|
|
326
|
+
"msg.recipient?.equals(this.ownId)",
|
|
327
|
+
""
|
|
328
|
+
]
|
|
329
|
+
});
|
|
258
330
|
const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
|
|
259
331
|
msg.data.signal
|
|
260
332
|
];
|
|
@@ -269,20 +341,28 @@ var Connection = class {
|
|
|
269
341
|
msg: msg.data
|
|
270
342
|
}, {
|
|
271
343
|
F: __dxlog_file,
|
|
272
|
-
L:
|
|
344
|
+
L: 259,
|
|
273
345
|
S: this,
|
|
274
346
|
C: (f, a) => f(...a)
|
|
275
347
|
});
|
|
276
348
|
this._incomingSignalBuffer.push(signal);
|
|
277
349
|
} else {
|
|
278
|
-
invariant(this._transport, "Connection not ready to accept signals."
|
|
350
|
+
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
351
|
+
F: __dxlog_file,
|
|
352
|
+
L: 262,
|
|
353
|
+
S: this,
|
|
354
|
+
A: [
|
|
355
|
+
"this._transport",
|
|
356
|
+
"'Connection not ready to accept signals.'"
|
|
357
|
+
]
|
|
358
|
+
});
|
|
279
359
|
log("received signal", {
|
|
280
360
|
peerId: this.ownId,
|
|
281
361
|
remoteId: this.remoteId,
|
|
282
362
|
msg: msg.data
|
|
283
363
|
}, {
|
|
284
364
|
F: __dxlog_file,
|
|
285
|
-
L:
|
|
365
|
+
L: 263,
|
|
286
366
|
S: this,
|
|
287
367
|
C: (f, a) => f(...a)
|
|
288
368
|
});
|
|
@@ -297,11 +377,19 @@ var Connection = class {
|
|
|
297
377
|
peerId: this.ownId
|
|
298
378
|
}, {
|
|
299
379
|
F: __dxlog_file,
|
|
300
|
-
L:
|
|
380
|
+
L: 270,
|
|
301
381
|
S: this,
|
|
302
382
|
C: (f, a) => f(...a)
|
|
303
383
|
});
|
|
304
|
-
invariant(state !== this._state, "Already in this state."
|
|
384
|
+
invariant(state !== this._state, "Already in this state.", {
|
|
385
|
+
F: __dxlog_file,
|
|
386
|
+
L: 271,
|
|
387
|
+
S: this,
|
|
388
|
+
A: [
|
|
389
|
+
"state !== this._state",
|
|
390
|
+
"'Already in this state.'"
|
|
391
|
+
]
|
|
392
|
+
});
|
|
305
393
|
this._state = state;
|
|
306
394
|
this.stateChanged.emit(state);
|
|
307
395
|
}
|
|
@@ -311,8 +399,8 @@ _ts_decorate([
|
|
|
311
399
|
], Connection.prototype, "close", null);
|
|
312
400
|
|
|
313
401
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
314
|
-
import invariant2 from "tiny-invariant";
|
|
315
402
|
import { Context as Context2 } from "@dxos/context";
|
|
403
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
316
404
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
317
405
|
import { log as log2 } from "@dxos/log";
|
|
318
406
|
import { schema } from "@dxos/protocols";
|
|
@@ -343,7 +431,7 @@ var SwarmMessenger = class {
|
|
|
343
431
|
msg: message
|
|
344
432
|
}, {
|
|
345
433
|
F: __dxlog_file2,
|
|
346
|
-
L:
|
|
434
|
+
L: 69,
|
|
347
435
|
S: this,
|
|
348
436
|
C: (f, a) => f(...a)
|
|
349
437
|
});
|
|
@@ -372,7 +460,7 @@ var SwarmMessenger = class {
|
|
|
372
460
|
message
|
|
373
461
|
}, {
|
|
374
462
|
F: __dxlog_file2,
|
|
375
|
-
L:
|
|
463
|
+
L: 80,
|
|
376
464
|
S: this,
|
|
377
465
|
C: (f, a) => f(...a)
|
|
378
466
|
});
|
|
@@ -380,7 +468,15 @@ var SwarmMessenger = class {
|
|
|
380
468
|
}
|
|
381
469
|
async signal(message) {
|
|
382
470
|
var _a, _b;
|
|
383
|
-
invariant2(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message"
|
|
471
|
+
invariant2(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message", {
|
|
472
|
+
F: __dxlog_file2,
|
|
473
|
+
L: 85,
|
|
474
|
+
S: this,
|
|
475
|
+
A: [
|
|
476
|
+
"message.data?.signal || message.data?.signalBatch",
|
|
477
|
+
"'Invalid message'"
|
|
478
|
+
]
|
|
479
|
+
});
|
|
384
480
|
await this._sendReliableMessage({
|
|
385
481
|
author: message.author,
|
|
386
482
|
recipient: message.recipient,
|
|
@@ -416,7 +512,7 @@ var SwarmMessenger = class {
|
|
|
416
512
|
msg: networkMessage
|
|
417
513
|
}, {
|
|
418
514
|
F: __dxlog_file2,
|
|
419
|
-
L:
|
|
515
|
+
L: 123,
|
|
420
516
|
S: this,
|
|
421
517
|
C: (f, a) => f(...a)
|
|
422
518
|
});
|
|
@@ -431,16 +527,32 @@ var SwarmMessenger = class {
|
|
|
431
527
|
}
|
|
432
528
|
async _resolveAnswers(message) {
|
|
433
529
|
var _a, _b, _c;
|
|
434
|
-
invariant2((_b = (_a = message.data) == null ? void 0 : _a.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId"
|
|
530
|
+
invariant2((_b = (_a = message.data) == null ? void 0 : _a.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId", {
|
|
531
|
+
F: __dxlog_file2,
|
|
532
|
+
L: 135,
|
|
533
|
+
S: this,
|
|
534
|
+
A: [
|
|
535
|
+
"message.data?.answer?.offerMessageId",
|
|
536
|
+
"'No offerMessageId'"
|
|
537
|
+
]
|
|
538
|
+
});
|
|
435
539
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
436
540
|
if (offerRecord) {
|
|
437
541
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
438
|
-
invariant2((_c = message.data) == null ? void 0 : _c.answer, "No answer"
|
|
542
|
+
invariant2((_c = message.data) == null ? void 0 : _c.answer, "No answer", {
|
|
543
|
+
F: __dxlog_file2,
|
|
544
|
+
L: 139,
|
|
545
|
+
S: this,
|
|
546
|
+
A: [
|
|
547
|
+
"message.data?.answer",
|
|
548
|
+
"'No answer'"
|
|
549
|
+
]
|
|
550
|
+
});
|
|
439
551
|
log2("resolving", {
|
|
440
552
|
answer: message.data.answer
|
|
441
553
|
}, {
|
|
442
554
|
F: __dxlog_file2,
|
|
443
|
-
L:
|
|
555
|
+
L: 140,
|
|
444
556
|
S: this,
|
|
445
557
|
C: (f, a) => f(...a)
|
|
446
558
|
});
|
|
@@ -448,7 +560,15 @@ var SwarmMessenger = class {
|
|
|
448
560
|
}
|
|
449
561
|
}
|
|
450
562
|
async _handleOffer({ author, recipient, message }) {
|
|
451
|
-
invariant2(message.data.offer, "No offer"
|
|
563
|
+
invariant2(message.data.offer, "No offer", {
|
|
564
|
+
F: __dxlog_file2,
|
|
565
|
+
L: 154,
|
|
566
|
+
S: this,
|
|
567
|
+
A: [
|
|
568
|
+
"message.data.offer",
|
|
569
|
+
"'No offer'"
|
|
570
|
+
]
|
|
571
|
+
});
|
|
452
572
|
const offerMessage = {
|
|
453
573
|
author,
|
|
454
574
|
recipient,
|
|
@@ -476,15 +596,31 @@ var SwarmMessenger = class {
|
|
|
476
596
|
err
|
|
477
597
|
}, {
|
|
478
598
|
F: __dxlog_file2,
|
|
479
|
-
L:
|
|
599
|
+
L: 174,
|
|
480
600
|
S: this,
|
|
481
601
|
C: (f, a) => f(...a)
|
|
482
602
|
});
|
|
483
603
|
}
|
|
484
604
|
}
|
|
485
605
|
async _handleSignal({ author, recipient, message }) {
|
|
486
|
-
invariant2(message.messageId
|
|
487
|
-
|
|
606
|
+
invariant2(message.messageId, void 0, {
|
|
607
|
+
F: __dxlog_file2,
|
|
608
|
+
L: 187,
|
|
609
|
+
S: this,
|
|
610
|
+
A: [
|
|
611
|
+
"message.messageId",
|
|
612
|
+
""
|
|
613
|
+
]
|
|
614
|
+
});
|
|
615
|
+
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
616
|
+
F: __dxlog_file2,
|
|
617
|
+
L: 188,
|
|
618
|
+
S: this,
|
|
619
|
+
A: [
|
|
620
|
+
"message.data.signal || message.data.signalBatch",
|
|
621
|
+
"'Invalid message'"
|
|
622
|
+
]
|
|
623
|
+
});
|
|
488
624
|
const signalMessage = {
|
|
489
625
|
author,
|
|
490
626
|
recipient,
|
|
@@ -499,20 +635,20 @@ var SwarmMessenger = class {
|
|
|
499
635
|
};
|
|
500
636
|
|
|
501
637
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
502
|
-
import invariant4 from "tiny-invariant";
|
|
503
638
|
import { Event as Event2, scheduleTask as scheduleTask2, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
|
|
504
639
|
import { Context as Context4 } from "@dxos/context";
|
|
505
640
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
641
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
506
642
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
507
643
|
import { log as log4, logInfo } from "@dxos/log";
|
|
508
644
|
import { trace as trace2 } from "@dxos/protocols";
|
|
509
645
|
import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
|
|
510
646
|
|
|
511
647
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
512
|
-
import invariant3 from "tiny-invariant";
|
|
513
648
|
import { scheduleTask, synchronized as synchronized2 } from "@dxos/async";
|
|
514
649
|
import { Context as Context3 } from "@dxos/context";
|
|
515
650
|
import { CancelledError as CancelledError2 } from "@dxos/errors";
|
|
651
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
516
652
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
517
653
|
import { log as log3 } from "@dxos/log";
|
|
518
654
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
@@ -558,7 +694,7 @@ var Peer = class {
|
|
|
558
694
|
sessionId: (_a = this.connection) == null ? void 0 : _a.sessionId
|
|
559
695
|
}, {
|
|
560
696
|
F: __dxlog_file3,
|
|
561
|
-
L:
|
|
697
|
+
L: 106,
|
|
562
698
|
S: this,
|
|
563
699
|
C: (f, a) => f(...a)
|
|
564
700
|
});
|
|
@@ -573,7 +709,15 @@ var Peer = class {
|
|
|
573
709
|
}
|
|
574
710
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
575
711
|
if (!this.connection) {
|
|
576
|
-
invariant3(message.sessionId
|
|
712
|
+
invariant3(message.sessionId, void 0, {
|
|
713
|
+
F: __dxlog_file3,
|
|
714
|
+
L: 126,
|
|
715
|
+
S: this,
|
|
716
|
+
A: [
|
|
717
|
+
"message.sessionId",
|
|
718
|
+
""
|
|
719
|
+
]
|
|
720
|
+
});
|
|
577
721
|
const connection = this._createConnection(false, message.sessionId);
|
|
578
722
|
try {
|
|
579
723
|
await this._connectionLimiter.connecting(message.sessionId);
|
|
@@ -587,7 +731,7 @@ var Peer = class {
|
|
|
587
731
|
err
|
|
588
732
|
}, {
|
|
589
733
|
F: __dxlog_file3,
|
|
590
|
-
L:
|
|
734
|
+
L: 134,
|
|
591
735
|
S: this,
|
|
592
736
|
C: (f, a) => f(...a)
|
|
593
737
|
});
|
|
@@ -607,8 +751,24 @@ var Peer = class {
|
|
|
607
751
|
* Initiate a connection to the remote peer.
|
|
608
752
|
*/
|
|
609
753
|
async initiateConnection() {
|
|
610
|
-
invariant3(!this.initiating, "Initiation in progress."
|
|
611
|
-
|
|
754
|
+
invariant3(!this.initiating, "Initiation in progress.", {
|
|
755
|
+
F: __dxlog_file3,
|
|
756
|
+
L: 151,
|
|
757
|
+
S: this,
|
|
758
|
+
A: [
|
|
759
|
+
"!this.initiating",
|
|
760
|
+
"'Initiation in progress.'"
|
|
761
|
+
]
|
|
762
|
+
});
|
|
763
|
+
invariant3(!this.connection, "Already connected.", {
|
|
764
|
+
F: __dxlog_file3,
|
|
765
|
+
L: 152,
|
|
766
|
+
S: this,
|
|
767
|
+
A: [
|
|
768
|
+
"!this.connection",
|
|
769
|
+
"'Already connected.'"
|
|
770
|
+
]
|
|
771
|
+
});
|
|
612
772
|
const sessionId = PublicKey3.random();
|
|
613
773
|
log3("initiating...", {
|
|
614
774
|
id: this.id,
|
|
@@ -617,7 +777,7 @@ var Peer = class {
|
|
|
617
777
|
sessionId
|
|
618
778
|
}, {
|
|
619
779
|
F: __dxlog_file3,
|
|
620
|
-
L:
|
|
780
|
+
L: 154,
|
|
621
781
|
S: this,
|
|
622
782
|
C: (f, a) => f(...a)
|
|
623
783
|
});
|
|
@@ -641,14 +801,14 @@ var Peer = class {
|
|
|
641
801
|
remoteId: this.id
|
|
642
802
|
}, {
|
|
643
803
|
F: __dxlog_file3,
|
|
644
|
-
L:
|
|
804
|
+
L: 169,
|
|
645
805
|
S: this,
|
|
646
806
|
C: (f, a) => f(...a)
|
|
647
807
|
});
|
|
648
808
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
649
809
|
log3("ignoring response", void 0, {
|
|
650
810
|
F: __dxlog_file3,
|
|
651
|
-
L:
|
|
811
|
+
L: 171,
|
|
652
812
|
S: this,
|
|
653
813
|
C: (f, a) => f(...a)
|
|
654
814
|
});
|
|
@@ -668,7 +828,7 @@ var Peer = class {
|
|
|
668
828
|
remoteId: this.id
|
|
669
829
|
}, {
|
|
670
830
|
F: __dxlog_file3,
|
|
671
|
-
L:
|
|
831
|
+
L: 182,
|
|
672
832
|
S: this,
|
|
673
833
|
C: (f, a) => f(...a)
|
|
674
834
|
});
|
|
@@ -692,11 +852,19 @@ var Peer = class {
|
|
|
692
852
|
sessionId
|
|
693
853
|
}, {
|
|
694
854
|
F: __dxlog_file3,
|
|
695
|
-
L:
|
|
855
|
+
L: 196,
|
|
696
856
|
S: this,
|
|
697
857
|
C: (f, a) => f(...a)
|
|
698
858
|
});
|
|
699
|
-
invariant3(!this.connection, "Already connected."
|
|
859
|
+
invariant3(!this.connection, "Already connected.", {
|
|
860
|
+
F: __dxlog_file3,
|
|
861
|
+
L: 203,
|
|
862
|
+
S: this,
|
|
863
|
+
A: [
|
|
864
|
+
"!this.connection",
|
|
865
|
+
"'Already connected.'"
|
|
866
|
+
]
|
|
867
|
+
});
|
|
700
868
|
const connection = new Connection(
|
|
701
869
|
this.topic,
|
|
702
870
|
this.localPeerId,
|
|
@@ -723,6 +891,18 @@ var Peer = class {
|
|
|
723
891
|
this._lastConnectionTime = Date.now();
|
|
724
892
|
this._callbacks.onConnected();
|
|
725
893
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
894
|
+
log3.trace("dxos.mesh.connection.connected", {
|
|
895
|
+
topic: this.topic,
|
|
896
|
+
localPeerId: this.localPeerId,
|
|
897
|
+
remotePeerId: this.id,
|
|
898
|
+
sessionId,
|
|
899
|
+
initiator
|
|
900
|
+
}, {
|
|
901
|
+
F: __dxlog_file3,
|
|
902
|
+
L: 229,
|
|
903
|
+
S: this,
|
|
904
|
+
C: (f, a) => f(...a)
|
|
905
|
+
});
|
|
726
906
|
break;
|
|
727
907
|
}
|
|
728
908
|
case ConnectionState.CLOSED: {
|
|
@@ -733,11 +913,31 @@ var Peer = class {
|
|
|
733
913
|
initiator
|
|
734
914
|
}, {
|
|
735
915
|
F: __dxlog_file3,
|
|
736
|
-
L:
|
|
916
|
+
L: 240,
|
|
917
|
+
S: this,
|
|
918
|
+
C: (f, a) => f(...a)
|
|
919
|
+
});
|
|
920
|
+
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
921
|
+
F: __dxlog_file3,
|
|
922
|
+
L: 241,
|
|
923
|
+
S: this,
|
|
924
|
+
A: [
|
|
925
|
+
"this.connection === connection",
|
|
926
|
+
"'Connection mismatch (race condition).'"
|
|
927
|
+
]
|
|
928
|
+
});
|
|
929
|
+
log3.trace("dxos.mesh.connection.closed", {
|
|
930
|
+
topic: this.topic,
|
|
931
|
+
localPeerId: this.localPeerId,
|
|
932
|
+
remotePeerId: this.id,
|
|
933
|
+
sessionId,
|
|
934
|
+
initiator
|
|
935
|
+
}, {
|
|
936
|
+
F: __dxlog_file3,
|
|
937
|
+
L: 243,
|
|
737
938
|
S: this,
|
|
738
939
|
C: (f, a) => f(...a)
|
|
739
940
|
});
|
|
740
|
-
invariant3(this.connection === connection, "Connection mismatch (race condition).");
|
|
741
941
|
if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
|
|
742
942
|
this._availableAfter = 0;
|
|
743
943
|
} else {
|
|
@@ -764,7 +964,20 @@ var Peer = class {
|
|
|
764
964
|
err
|
|
765
965
|
}, {
|
|
766
966
|
F: __dxlog_file3,
|
|
767
|
-
L:
|
|
967
|
+
L: 277,
|
|
968
|
+
S: this,
|
|
969
|
+
C: (f, a) => f(...a)
|
|
970
|
+
});
|
|
971
|
+
log3.trace("dxos.mesh.connection.error", {
|
|
972
|
+
topic: this.topic,
|
|
973
|
+
localPeerId: this.localPeerId,
|
|
974
|
+
remotePeerId: this.id,
|
|
975
|
+
sessionId,
|
|
976
|
+
initiator,
|
|
977
|
+
err
|
|
978
|
+
}, {
|
|
979
|
+
F: __dxlog_file3,
|
|
980
|
+
L: 278,
|
|
768
981
|
S: this,
|
|
769
982
|
C: (f, a) => f(...a)
|
|
770
983
|
});
|
|
@@ -783,7 +996,7 @@ var Peer = class {
|
|
|
783
996
|
sessionId: connection.sessionId
|
|
784
997
|
}, {
|
|
785
998
|
F: __dxlog_file3,
|
|
786
|
-
L:
|
|
999
|
+
L: 301,
|
|
787
1000
|
S: this,
|
|
788
1001
|
C: (f, a) => f(...a)
|
|
789
1002
|
});
|
|
@@ -793,7 +1006,7 @@ var Peer = class {
|
|
|
793
1006
|
sessionId: connection.sessionId
|
|
794
1007
|
}, {
|
|
795
1008
|
F: __dxlog_file3,
|
|
796
|
-
L:
|
|
1009
|
+
L: 307,
|
|
797
1010
|
S: this,
|
|
798
1011
|
C: (f, a) => f(...a)
|
|
799
1012
|
});
|
|
@@ -804,7 +1017,7 @@ var Peer = class {
|
|
|
804
1017
|
message
|
|
805
1018
|
}, {
|
|
806
1019
|
F: __dxlog_file3,
|
|
807
|
-
L:
|
|
1020
|
+
L: 312,
|
|
808
1021
|
S: this,
|
|
809
1022
|
C: (f, a) => f(...a)
|
|
810
1023
|
});
|
|
@@ -820,7 +1033,7 @@ var Peer = class {
|
|
|
820
1033
|
topic: this.topic
|
|
821
1034
|
}, {
|
|
822
1035
|
F: __dxlog_file3,
|
|
823
|
-
L:
|
|
1036
|
+
L: 322,
|
|
824
1037
|
S: this,
|
|
825
1038
|
C: (f, a) => f(...a)
|
|
826
1039
|
});
|
|
@@ -885,7 +1098,7 @@ var Swarm = class {
|
|
|
885
1098
|
}
|
|
886
1099
|
}), {
|
|
887
1100
|
F: __dxlog_file4,
|
|
888
|
-
L:
|
|
1101
|
+
L: 87,
|
|
889
1102
|
S: this,
|
|
890
1103
|
C: (f, a) => f(...a)
|
|
891
1104
|
});
|
|
@@ -893,7 +1106,7 @@ var Swarm = class {
|
|
|
893
1106
|
peerId: _ownPeerId
|
|
894
1107
|
}, {
|
|
895
1108
|
F: __dxlog_file4,
|
|
896
|
-
L:
|
|
1109
|
+
L: 91,
|
|
897
1110
|
S: this,
|
|
898
1111
|
C: (f, a) => f(...a)
|
|
899
1112
|
});
|
|
@@ -908,7 +1121,7 @@ var Swarm = class {
|
|
|
908
1121
|
id: this._instanceId
|
|
909
1122
|
}), {
|
|
910
1123
|
F: __dxlog_file4,
|
|
911
|
-
L:
|
|
1124
|
+
L: 100,
|
|
912
1125
|
S: this,
|
|
913
1126
|
C: (f, a) => f(...a)
|
|
914
1127
|
});
|
|
@@ -929,7 +1142,15 @@ var Swarm = class {
|
|
|
929
1142
|
return this._topic;
|
|
930
1143
|
}
|
|
931
1144
|
async open() {
|
|
932
|
-
invariant4(!this._listeningHandle
|
|
1145
|
+
invariant4(!this._listeningHandle, void 0, {
|
|
1146
|
+
F: __dxlog_file4,
|
|
1147
|
+
L: 127,
|
|
1148
|
+
S: this,
|
|
1149
|
+
A: [
|
|
1150
|
+
"!this._listeningHandle",
|
|
1151
|
+
""
|
|
1152
|
+
]
|
|
1153
|
+
});
|
|
933
1154
|
this._listeningHandle = await this._messenger.listen({
|
|
934
1155
|
peerId: this._ownPeerId,
|
|
935
1156
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
@@ -938,7 +1159,7 @@ var Swarm = class {
|
|
|
938
1159
|
err
|
|
939
1160
|
}, {
|
|
940
1161
|
F: __dxlog_file4,
|
|
941
|
-
L:
|
|
1162
|
+
L: 134,
|
|
942
1163
|
S: this,
|
|
943
1164
|
C: (f, a) => f(...a)
|
|
944
1165
|
}));
|
|
@@ -949,7 +1170,7 @@ var Swarm = class {
|
|
|
949
1170
|
var _a;
|
|
950
1171
|
log4("destroying...", void 0, {
|
|
951
1172
|
F: __dxlog_file4,
|
|
952
|
-
L:
|
|
1173
|
+
L: 140,
|
|
953
1174
|
S: this,
|
|
954
1175
|
C: (f, a) => f(...a)
|
|
955
1176
|
});
|
|
@@ -960,13 +1181,21 @@ var Swarm = class {
|
|
|
960
1181
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
961
1182
|
log4("destroyed", void 0, {
|
|
962
1183
|
F: __dxlog_file4,
|
|
963
|
-
L:
|
|
1184
|
+
L: 147,
|
|
964
1185
|
S: this,
|
|
965
1186
|
C: (f, a) => f(...a)
|
|
966
1187
|
});
|
|
967
1188
|
}
|
|
968
1189
|
async setTopology(topology) {
|
|
969
|
-
invariant4(!this._ctx.disposed, "Swarm is offline"
|
|
1190
|
+
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1191
|
+
F: __dxlog_file4,
|
|
1192
|
+
L: 151,
|
|
1193
|
+
S: this,
|
|
1194
|
+
A: [
|
|
1195
|
+
"!this._ctx.disposed",
|
|
1196
|
+
"'Swarm is offline'"
|
|
1197
|
+
]
|
|
1198
|
+
});
|
|
970
1199
|
if (topology === this._topology) {
|
|
971
1200
|
return;
|
|
972
1201
|
}
|
|
@@ -975,7 +1204,7 @@ var Swarm = class {
|
|
|
975
1204
|
topology: getClassName(topology)
|
|
976
1205
|
}, {
|
|
977
1206
|
F: __dxlog_file4,
|
|
978
|
-
L:
|
|
1207
|
+
L: 155,
|
|
979
1208
|
S: this,
|
|
980
1209
|
C: (f, a) => f(...a)
|
|
981
1210
|
});
|
|
@@ -990,14 +1219,14 @@ var Swarm = class {
|
|
|
990
1219
|
swarmEvent
|
|
991
1220
|
}, {
|
|
992
1221
|
F: __dxlog_file4,
|
|
993
|
-
L:
|
|
1222
|
+
L: 168,
|
|
994
1223
|
S: this,
|
|
995
1224
|
C: (f, a) => f(...a)
|
|
996
1225
|
});
|
|
997
1226
|
if (this._ctx.disposed) {
|
|
998
1227
|
log4("swarm event ignored for disposed swarm", void 0, {
|
|
999
1228
|
F: __dxlog_file4,
|
|
1000
|
-
L:
|
|
1229
|
+
L: 171,
|
|
1001
1230
|
S: this,
|
|
1002
1231
|
C: (f, a) => f(...a)
|
|
1003
1232
|
});
|
|
@@ -1009,7 +1238,7 @@ var Swarm = class {
|
|
|
1009
1238
|
peerId
|
|
1010
1239
|
}, {
|
|
1011
1240
|
F: __dxlog_file4,
|
|
1012
|
-
L:
|
|
1241
|
+
L: 177,
|
|
1013
1242
|
S: this,
|
|
1014
1243
|
C: (f, a) => f(...a)
|
|
1015
1244
|
});
|
|
@@ -1024,7 +1253,7 @@ var Swarm = class {
|
|
|
1024
1253
|
if (((_a = peer.connection) == null ? void 0 : _a.state) !== ConnectionState.CONNECTED) {
|
|
1025
1254
|
void this._destroyPeer(peer.id).catch((err) => log4.catch(err, void 0, {
|
|
1026
1255
|
F: __dxlog_file4,
|
|
1027
|
-
L:
|
|
1256
|
+
L: 188,
|
|
1028
1257
|
S: this,
|
|
1029
1258
|
C: (f, a) => f(...a)
|
|
1030
1259
|
}));
|
|
@@ -1039,14 +1268,14 @@ var Swarm = class {
|
|
|
1039
1268
|
message
|
|
1040
1269
|
}, {
|
|
1041
1270
|
F: __dxlog_file4,
|
|
1042
|
-
L:
|
|
1271
|
+
L: 198,
|
|
1043
1272
|
S: this,
|
|
1044
1273
|
C: (f, a) => f(...a)
|
|
1045
1274
|
});
|
|
1046
1275
|
if (this._ctx.disposed) {
|
|
1047
1276
|
log4("ignored for disposed swarm", void 0, {
|
|
1048
1277
|
F: __dxlog_file4,
|
|
1049
|
-
L:
|
|
1278
|
+
L: 200,
|
|
1050
1279
|
S: this,
|
|
1051
1280
|
C: (f, a) => f(...a)
|
|
1052
1281
|
});
|
|
@@ -1054,13 +1283,21 @@ var Swarm = class {
|
|
|
1054
1283
|
accept: false
|
|
1055
1284
|
};
|
|
1056
1285
|
}
|
|
1057
|
-
invariant4(message.author
|
|
1286
|
+
invariant4(message.author, void 0, {
|
|
1287
|
+
F: __dxlog_file4,
|
|
1288
|
+
L: 205,
|
|
1289
|
+
S: this,
|
|
1290
|
+
A: [
|
|
1291
|
+
"message.author",
|
|
1292
|
+
""
|
|
1293
|
+
]
|
|
1294
|
+
});
|
|
1058
1295
|
if (!((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId))) {
|
|
1059
1296
|
log4("rejecting offer with incorrect peerId", {
|
|
1060
1297
|
message
|
|
1061
1298
|
}, {
|
|
1062
1299
|
F: __dxlog_file4,
|
|
1063
|
-
L:
|
|
1300
|
+
L: 207,
|
|
1064
1301
|
S: this,
|
|
1065
1302
|
C: (f, a) => f(...a)
|
|
1066
1303
|
});
|
|
@@ -1073,7 +1310,7 @@ var Swarm = class {
|
|
|
1073
1310
|
message
|
|
1074
1311
|
}, {
|
|
1075
1312
|
F: __dxlog_file4,
|
|
1076
|
-
L:
|
|
1313
|
+
L: 211,
|
|
1077
1314
|
S: this,
|
|
1078
1315
|
C: (f, a) => f(...a)
|
|
1079
1316
|
});
|
|
@@ -1092,22 +1329,46 @@ var Swarm = class {
|
|
|
1092
1329
|
message
|
|
1093
1330
|
}, {
|
|
1094
1331
|
F: __dxlog_file4,
|
|
1095
|
-
L:
|
|
1332
|
+
L: 222,
|
|
1096
1333
|
S: this,
|
|
1097
1334
|
C: (f, a) => f(...a)
|
|
1098
1335
|
});
|
|
1099
1336
|
if (this._ctx.disposed) {
|
|
1100
1337
|
log4.info("ignored for offline swarm", void 0, {
|
|
1101
1338
|
F: __dxlog_file4,
|
|
1102
|
-
L:
|
|
1339
|
+
L: 224,
|
|
1103
1340
|
S: this,
|
|
1104
1341
|
C: (f, a) => f(...a)
|
|
1105
1342
|
});
|
|
1106
1343
|
return;
|
|
1107
1344
|
}
|
|
1108
|
-
invariant4((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}
|
|
1109
|
-
|
|
1110
|
-
|
|
1345
|
+
invariant4((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1346
|
+
F: __dxlog_file4,
|
|
1347
|
+
L: 227,
|
|
1348
|
+
S: this,
|
|
1349
|
+
A: [
|
|
1350
|
+
"message.recipient?.equals(this._ownPeerId)",
|
|
1351
|
+
"`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
|
|
1352
|
+
]
|
|
1353
|
+
});
|
|
1354
|
+
invariant4((_b = message.topic) == null ? void 0 : _b.equals(this._topic), void 0, {
|
|
1355
|
+
F: __dxlog_file4,
|
|
1356
|
+
L: 231,
|
|
1357
|
+
S: this,
|
|
1358
|
+
A: [
|
|
1359
|
+
"message.topic?.equals(this._topic)",
|
|
1360
|
+
""
|
|
1361
|
+
]
|
|
1362
|
+
});
|
|
1363
|
+
invariant4(message.author, void 0, {
|
|
1364
|
+
F: __dxlog_file4,
|
|
1365
|
+
L: 232,
|
|
1366
|
+
S: this,
|
|
1367
|
+
A: [
|
|
1368
|
+
"message.author",
|
|
1369
|
+
""
|
|
1370
|
+
]
|
|
1371
|
+
});
|
|
1111
1372
|
const peer = this._getOrCreatePeer(message.author);
|
|
1112
1373
|
await peer.onSignal(message);
|
|
1113
1374
|
}
|
|
@@ -1159,7 +1420,15 @@ var Swarm = class {
|
|
|
1159
1420
|
return peer;
|
|
1160
1421
|
}
|
|
1161
1422
|
async _destroyPeer(peerId) {
|
|
1162
|
-
invariant4(this._peers.has(peerId)
|
|
1423
|
+
invariant4(this._peers.has(peerId), void 0, {
|
|
1424
|
+
F: __dxlog_file4,
|
|
1425
|
+
L: 302,
|
|
1426
|
+
S: this,
|
|
1427
|
+
A: [
|
|
1428
|
+
"this._peers.has(peerId)",
|
|
1429
|
+
""
|
|
1430
|
+
]
|
|
1431
|
+
});
|
|
1163
1432
|
await this._peers.get(peerId).destroy();
|
|
1164
1433
|
this._peers.delete(peerId);
|
|
1165
1434
|
}
|
|
@@ -1180,7 +1449,7 @@ var Swarm = class {
|
|
|
1180
1449
|
} catch (err) {
|
|
1181
1450
|
log4("initiation error", err, {
|
|
1182
1451
|
F: __dxlog_file4,
|
|
1183
|
-
L:
|
|
1452
|
+
L: 328,
|
|
1184
1453
|
S: this,
|
|
1185
1454
|
C: (f, a) => f(...a)
|
|
1186
1455
|
});
|
|
@@ -1208,7 +1477,7 @@ var Swarm = class {
|
|
|
1208
1477
|
remoteId
|
|
1209
1478
|
}, {
|
|
1210
1479
|
F: __dxlog_file4,
|
|
1211
|
-
L:
|
|
1480
|
+
L: 355,
|
|
1212
1481
|
S: this,
|
|
1213
1482
|
C: (f, a) => f(...a)
|
|
1214
1483
|
});
|
|
@@ -1225,7 +1494,7 @@ var Swarm = class {
|
|
|
1225
1494
|
remoteId
|
|
1226
1495
|
}, {
|
|
1227
1496
|
F: __dxlog_file4,
|
|
1228
|
-
L:
|
|
1497
|
+
L: 369,
|
|
1229
1498
|
S: this,
|
|
1230
1499
|
C: (f, a) => f(...a)
|
|
1231
1500
|
});
|
|
@@ -1235,7 +1504,7 @@ var Swarm = class {
|
|
|
1235
1504
|
remoteId
|
|
1236
1505
|
}, {
|
|
1237
1506
|
F: __dxlog_file4,
|
|
1238
|
-
L:
|
|
1507
|
+
L: 372,
|
|
1239
1508
|
S: this,
|
|
1240
1509
|
C: (f, a) => f(...a)
|
|
1241
1510
|
});
|
|
@@ -1345,8 +1614,9 @@ var SwarmMapper = class {
|
|
|
1345
1614
|
import { DeferredTask as DeferredTask2 } from "@dxos/async";
|
|
1346
1615
|
import { Context as Context5 } from "@dxos/context";
|
|
1347
1616
|
import { CancelledError as CancelledError3 } from "@dxos/errors";
|
|
1617
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1348
1618
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
1349
|
-
import {
|
|
1619
|
+
import { log as log6 } from "@dxos/log";
|
|
1350
1620
|
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
1351
1621
|
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
1352
1622
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 3;
|
|
@@ -1370,7 +1640,7 @@ var ConnectionLimiter = class {
|
|
|
1370
1640
|
async connecting(sessionId) {
|
|
1371
1641
|
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
1372
1642
|
F: __dxlog_file6,
|
|
1373
|
-
L:
|
|
1643
|
+
L: 48,
|
|
1374
1644
|
S: this,
|
|
1375
1645
|
A: [
|
|
1376
1646
|
"!this._waitingPromises.has(sessionId)",
|
|
@@ -1381,7 +1651,7 @@ var ConnectionLimiter = class {
|
|
|
1381
1651
|
sessionId
|
|
1382
1652
|
}, {
|
|
1383
1653
|
F: __dxlog_file6,
|
|
1384
|
-
L:
|
|
1654
|
+
L: 49,
|
|
1385
1655
|
S: this,
|
|
1386
1656
|
C: (f, a) => f(...a)
|
|
1387
1657
|
});
|
|
@@ -1396,7 +1666,7 @@ var ConnectionLimiter = class {
|
|
|
1396
1666
|
sessionId
|
|
1397
1667
|
}, {
|
|
1398
1668
|
F: __dxlog_file6,
|
|
1399
|
-
L:
|
|
1669
|
+
L: 57,
|
|
1400
1670
|
S: this,
|
|
1401
1671
|
C: (f, a) => f(...a)
|
|
1402
1672
|
});
|
|
@@ -1409,7 +1679,7 @@ var ConnectionLimiter = class {
|
|
|
1409
1679
|
sessionId
|
|
1410
1680
|
}, {
|
|
1411
1681
|
F: __dxlog_file6,
|
|
1412
|
-
L:
|
|
1682
|
+
L: 64,
|
|
1413
1683
|
S: this,
|
|
1414
1684
|
C: (f, a) => f(...a)
|
|
1415
1685
|
});
|
|
@@ -1493,8 +1763,8 @@ var ConnectionLog = class {
|
|
|
1493
1763
|
};
|
|
1494
1764
|
|
|
1495
1765
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
1496
|
-
import invariant6 from "tiny-invariant";
|
|
1497
1766
|
import { Event as Event5 } from "@dxos/async";
|
|
1767
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1498
1768
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
1499
1769
|
import { log as log7 } from "@dxos/log";
|
|
1500
1770
|
import { Messenger } from "@dxos/messaging";
|
|
@@ -1553,7 +1823,7 @@ var NetworkManager = class {
|
|
|
1553
1823
|
id: this._instanceId
|
|
1554
1824
|
}), {
|
|
1555
1825
|
F: __dxlog_file7,
|
|
1556
|
-
L:
|
|
1826
|
+
L: 130,
|
|
1557
1827
|
S: this,
|
|
1558
1828
|
C: (f, a) => f(...a)
|
|
1559
1829
|
});
|
|
@@ -1563,7 +1833,7 @@ var NetworkManager = class {
|
|
|
1563
1833
|
id: this._instanceId
|
|
1564
1834
|
}), {
|
|
1565
1835
|
F: __dxlog_file7,
|
|
1566
|
-
L:
|
|
1836
|
+
L: 133,
|
|
1567
1837
|
S: this,
|
|
1568
1838
|
C: (f, a) => f(...a)
|
|
1569
1839
|
});
|
|
@@ -1573,7 +1843,7 @@ var NetworkManager = class {
|
|
|
1573
1843
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1574
1844
|
log7(err, void 0, {
|
|
1575
1845
|
F: __dxlog_file7,
|
|
1576
|
-
L:
|
|
1846
|
+
L: 139,
|
|
1577
1847
|
S: this,
|
|
1578
1848
|
C: (f, a) => f(...a)
|
|
1579
1849
|
});
|
|
@@ -1587,10 +1857,42 @@ var NetworkManager = class {
|
|
|
1587
1857
|
*/
|
|
1588
1858
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1589
1859
|
var _a;
|
|
1590
|
-
invariant6(PublicKey8.isPublicKey(topic)
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1860
|
+
invariant6(PublicKey8.isPublicKey(topic), void 0, {
|
|
1861
|
+
F: __dxlog_file7,
|
|
1862
|
+
L: 157,
|
|
1863
|
+
S: this,
|
|
1864
|
+
A: [
|
|
1865
|
+
"PublicKey.isPublicKey(topic)",
|
|
1866
|
+
""
|
|
1867
|
+
]
|
|
1868
|
+
});
|
|
1869
|
+
invariant6(PublicKey8.isPublicKey(peerId), void 0, {
|
|
1870
|
+
F: __dxlog_file7,
|
|
1871
|
+
L: 158,
|
|
1872
|
+
S: this,
|
|
1873
|
+
A: [
|
|
1874
|
+
"PublicKey.isPublicKey(peerId)",
|
|
1875
|
+
""
|
|
1876
|
+
]
|
|
1877
|
+
});
|
|
1878
|
+
invariant6(topology, void 0, {
|
|
1879
|
+
F: __dxlog_file7,
|
|
1880
|
+
L: 159,
|
|
1881
|
+
S: this,
|
|
1882
|
+
A: [
|
|
1883
|
+
"topology",
|
|
1884
|
+
""
|
|
1885
|
+
]
|
|
1886
|
+
});
|
|
1887
|
+
invariant6(typeof protocol === "function", void 0, {
|
|
1888
|
+
F: __dxlog_file7,
|
|
1889
|
+
L: 160,
|
|
1890
|
+
S: this,
|
|
1891
|
+
A: [
|
|
1892
|
+
"typeof protocol === 'function'",
|
|
1893
|
+
""
|
|
1894
|
+
]
|
|
1895
|
+
});
|
|
1594
1896
|
if (this._swarms.has(topic)) {
|
|
1595
1897
|
throw new Error(`Already connected to swarm: ${PublicKey8.from(topic)}`);
|
|
1596
1898
|
}
|
|
@@ -1600,7 +1902,7 @@ var NetworkManager = class {
|
|
|
1600
1902
|
topology: topology.toString()
|
|
1601
1903
|
}, {
|
|
1602
1904
|
F: __dxlog_file7,
|
|
1603
|
-
L:
|
|
1905
|
+
L: 165,
|
|
1604
1906
|
S: this,
|
|
1605
1907
|
C: (f, a) => f(...a)
|
|
1606
1908
|
});
|
|
@@ -1610,7 +1912,7 @@ var NetworkManager = class {
|
|
|
1610
1912
|
error
|
|
1611
1913
|
}, {
|
|
1612
1914
|
F: __dxlog_file7,
|
|
1613
|
-
L:
|
|
1915
|
+
L: 178,
|
|
1614
1916
|
S: this,
|
|
1615
1917
|
C: (f, a) => f(...a)
|
|
1616
1918
|
});
|
|
@@ -1623,7 +1925,7 @@ var NetworkManager = class {
|
|
|
1623
1925
|
peerId
|
|
1624
1926
|
}).catch((error) => log7.catch(error, void 0, {
|
|
1625
1927
|
F: __dxlog_file7,
|
|
1626
|
-
L:
|
|
1928
|
+
L: 187,
|
|
1627
1929
|
S: this,
|
|
1628
1930
|
C: (f, a) => f(...a)
|
|
1629
1931
|
}));
|
|
@@ -1634,7 +1936,7 @@ var NetworkManager = class {
|
|
|
1634
1936
|
count: this._swarms.size
|
|
1635
1937
|
}, {
|
|
1636
1938
|
F: __dxlog_file7,
|
|
1637
|
-
L:
|
|
1939
|
+
L: 191,
|
|
1638
1940
|
S: this,
|
|
1639
1941
|
C: (f, a) => f(...a)
|
|
1640
1942
|
});
|
|
@@ -1654,7 +1956,7 @@ var NetworkManager = class {
|
|
|
1654
1956
|
topic: PublicKey8.from(topic)
|
|
1655
1957
|
}, {
|
|
1656
1958
|
F: __dxlog_file7,
|
|
1657
|
-
L:
|
|
1959
|
+
L: 207,
|
|
1658
1960
|
S: this,
|
|
1659
1961
|
C: (f, a) => f(...a)
|
|
1660
1962
|
});
|
|
@@ -1675,7 +1977,7 @@ var NetworkManager = class {
|
|
|
1675
1977
|
count: this._swarms.size
|
|
1676
1978
|
}, {
|
|
1677
1979
|
F: __dxlog_file7,
|
|
1678
|
-
L:
|
|
1980
|
+
L: 221,
|
|
1679
1981
|
S: this,
|
|
1680
1982
|
C: (f, a) => f(...a)
|
|
1681
1983
|
});
|
|
@@ -1709,17 +2011,34 @@ var NetworkManager = class {
|
|
|
1709
2011
|
};
|
|
1710
2012
|
|
|
1711
2013
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1712
|
-
import invariant7 from "
|
|
2014
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2015
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
1713
2016
|
var FullyConnectedTopology = class {
|
|
1714
2017
|
toString() {
|
|
1715
2018
|
return "FullyConnectedTopology";
|
|
1716
2019
|
}
|
|
1717
2020
|
init(controller) {
|
|
1718
|
-
invariant7(!this._controller, "Already initialized"
|
|
2021
|
+
invariant7(!this._controller, "Already initialized", {
|
|
2022
|
+
F: __dxlog_file8,
|
|
2023
|
+
L: 18,
|
|
2024
|
+
S: this,
|
|
2025
|
+
A: [
|
|
2026
|
+
"!this._controller",
|
|
2027
|
+
"'Already initialized'"
|
|
2028
|
+
]
|
|
2029
|
+
});
|
|
1719
2030
|
this._controller = controller;
|
|
1720
2031
|
}
|
|
1721
2032
|
update() {
|
|
1722
|
-
invariant7(this._controller, "Not initialized"
|
|
2033
|
+
invariant7(this._controller, "Not initialized", {
|
|
2034
|
+
F: __dxlog_file8,
|
|
2035
|
+
L: 23,
|
|
2036
|
+
S: this,
|
|
2037
|
+
A: [
|
|
2038
|
+
"this._controller",
|
|
2039
|
+
"'Not initialized'"
|
|
2040
|
+
]
|
|
2041
|
+
});
|
|
1723
2042
|
const { candidates: discovered } = this._controller.getState();
|
|
1724
2043
|
for (const peer of discovered) {
|
|
1725
2044
|
this._controller.connect(peer);
|
|
@@ -1733,10 +2052,10 @@ var FullyConnectedTopology = class {
|
|
|
1733
2052
|
};
|
|
1734
2053
|
|
|
1735
2054
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1736
|
-
import invariant8 from "tiny-invariant";
|
|
1737
2055
|
import distance from "xor-distance";
|
|
2056
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
1738
2057
|
import { log as log8 } from "@dxos/log";
|
|
1739
|
-
var
|
|
2058
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
1740
2059
|
var MMSTTopology = class {
|
|
1741
2060
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
1742
2061
|
this._sampleCollected = false;
|
|
@@ -1745,15 +2064,31 @@ var MMSTTopology = class {
|
|
|
1745
2064
|
this._sampleSize = sampleSize;
|
|
1746
2065
|
}
|
|
1747
2066
|
init(controller) {
|
|
1748
|
-
invariant8(!this._controller, "Already initialized"
|
|
2067
|
+
invariant8(!this._controller, "Already initialized", {
|
|
2068
|
+
F: __dxlog_file9,
|
|
2069
|
+
L: 46,
|
|
2070
|
+
S: this,
|
|
2071
|
+
A: [
|
|
2072
|
+
"!this._controller",
|
|
2073
|
+
"'Already initialized'"
|
|
2074
|
+
]
|
|
2075
|
+
});
|
|
1749
2076
|
this._controller = controller;
|
|
1750
2077
|
}
|
|
1751
2078
|
update() {
|
|
1752
|
-
invariant8(this._controller, "Not initialized"
|
|
2079
|
+
invariant8(this._controller, "Not initialized", {
|
|
2080
|
+
F: __dxlog_file9,
|
|
2081
|
+
L: 51,
|
|
2082
|
+
S: this,
|
|
2083
|
+
A: [
|
|
2084
|
+
"this._controller",
|
|
2085
|
+
"'Not initialized'"
|
|
2086
|
+
]
|
|
2087
|
+
});
|
|
1753
2088
|
const { connected, candidates } = this._controller.getState();
|
|
1754
2089
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
1755
2090
|
log8("Running the algorithm.", void 0, {
|
|
1756
|
-
F:
|
|
2091
|
+
F: __dxlog_file9,
|
|
1757
2092
|
L: 55,
|
|
1758
2093
|
S: this,
|
|
1759
2094
|
C: (f, a) => f(...a)
|
|
@@ -1763,11 +2098,19 @@ var MMSTTopology = class {
|
|
|
1763
2098
|
}
|
|
1764
2099
|
}
|
|
1765
2100
|
async onOffer(peer) {
|
|
1766
|
-
invariant8(this._controller, "Not initialized"
|
|
2101
|
+
invariant8(this._controller, "Not initialized", {
|
|
2102
|
+
F: __dxlog_file9,
|
|
2103
|
+
L: 62,
|
|
2104
|
+
S: this,
|
|
2105
|
+
A: [
|
|
2106
|
+
"this._controller",
|
|
2107
|
+
"'Not initialized'"
|
|
2108
|
+
]
|
|
2109
|
+
});
|
|
1767
2110
|
const { connected } = this._controller.getState();
|
|
1768
2111
|
const accept = connected.length < this._maxPeers;
|
|
1769
2112
|
log8(`Offer ${peer} accept=${accept}`, void 0, {
|
|
1770
|
-
F:
|
|
2113
|
+
F: __dxlog_file9,
|
|
1771
2114
|
L: 65,
|
|
1772
2115
|
S: this,
|
|
1773
2116
|
C: (f, a) => f(...a)
|
|
@@ -1777,13 +2120,21 @@ var MMSTTopology = class {
|
|
|
1777
2120
|
async destroy() {
|
|
1778
2121
|
}
|
|
1779
2122
|
_runAlgorithm() {
|
|
1780
|
-
invariant8(this._controller, "Not initialized"
|
|
2123
|
+
invariant8(this._controller, "Not initialized", {
|
|
2124
|
+
F: __dxlog_file9,
|
|
2125
|
+
L: 74,
|
|
2126
|
+
S: this,
|
|
2127
|
+
A: [
|
|
2128
|
+
"this._controller",
|
|
2129
|
+
"'Not initialized'"
|
|
2130
|
+
]
|
|
2131
|
+
});
|
|
1781
2132
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
1782
2133
|
if (connected.length > this._maxPeers) {
|
|
1783
2134
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
1784
2135
|
for (const peer of sorted) {
|
|
1785
2136
|
log8(`Disconnect ${peer}.`, void 0, {
|
|
1786
|
-
F:
|
|
2137
|
+
F: __dxlog_file9,
|
|
1787
2138
|
L: 83,
|
|
1788
2139
|
S: this,
|
|
1789
2140
|
C: (f, a) => f(...a)
|
|
@@ -1795,7 +2146,7 @@ var MMSTTopology = class {
|
|
|
1795
2146
|
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
1796
2147
|
for (const peer of sorted) {
|
|
1797
2148
|
log8(`Connect ${peer}.`, void 0, {
|
|
1798
|
-
F:
|
|
2149
|
+
F: __dxlog_file9,
|
|
1799
2150
|
L: 91,
|
|
1800
2151
|
S: this,
|
|
1801
2152
|
C: (f, a) => f(...a)
|
|
@@ -1811,9 +2162,9 @@ var MMSTTopology = class {
|
|
|
1811
2162
|
var sortByXorDistance = (keys, reference) => keys.sort((a, b) => distance.gt(distance(a.asBuffer(), reference.asBuffer()), distance(b.asBuffer(), reference.asBuffer())));
|
|
1812
2163
|
|
|
1813
2164
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1814
|
-
import invariant9 from "
|
|
2165
|
+
import { invariant as invariant9 } from "@dxos/invariant";
|
|
1815
2166
|
import { log as log9 } from "@dxos/log";
|
|
1816
|
-
var
|
|
2167
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
1817
2168
|
var StarTopology = class {
|
|
1818
2169
|
// prettier-ignore
|
|
1819
2170
|
constructor(_centralPeer) {
|
|
@@ -1823,16 +2174,32 @@ var StarTopology = class {
|
|
|
1823
2174
|
return `StarTopology(${this._centralPeer.truncate()})`;
|
|
1824
2175
|
}
|
|
1825
2176
|
init(controller) {
|
|
1826
|
-
invariant9(!this._controller, "Already initialized."
|
|
2177
|
+
invariant9(!this._controller, "Already initialized.", {
|
|
2178
|
+
F: __dxlog_file10,
|
|
2179
|
+
L: 24,
|
|
2180
|
+
S: this,
|
|
2181
|
+
A: [
|
|
2182
|
+
"!this._controller",
|
|
2183
|
+
"'Already initialized.'"
|
|
2184
|
+
]
|
|
2185
|
+
});
|
|
1827
2186
|
this._controller = controller;
|
|
1828
2187
|
}
|
|
1829
2188
|
update() {
|
|
1830
|
-
invariant9(this._controller, "Not initialized."
|
|
2189
|
+
invariant9(this._controller, "Not initialized.", {
|
|
2190
|
+
F: __dxlog_file10,
|
|
2191
|
+
L: 29,
|
|
2192
|
+
S: this,
|
|
2193
|
+
A: [
|
|
2194
|
+
"this._controller",
|
|
2195
|
+
"'Not initialized.'"
|
|
2196
|
+
]
|
|
2197
|
+
});
|
|
1831
2198
|
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
1832
2199
|
if (!ownPeerId.equals(this._centralPeer)) {
|
|
1833
2200
|
log9("leaf peer dropping all connections apart from central peer.", void 0, {
|
|
1834
|
-
F:
|
|
1835
|
-
L:
|
|
2201
|
+
F: __dxlog_file10,
|
|
2202
|
+
L: 32,
|
|
1836
2203
|
S: this,
|
|
1837
2204
|
C: (f, a) => f(...a)
|
|
1838
2205
|
});
|
|
@@ -1841,8 +2208,8 @@ var StarTopology = class {
|
|
|
1841
2208
|
log9("dropping connection", {
|
|
1842
2209
|
peer
|
|
1843
2210
|
}, {
|
|
1844
|
-
F:
|
|
1845
|
-
L:
|
|
2211
|
+
F: __dxlog_file10,
|
|
2212
|
+
L: 37,
|
|
1846
2213
|
S: this,
|
|
1847
2214
|
C: (f, a) => f(...a)
|
|
1848
2215
|
});
|
|
@@ -1855,8 +2222,8 @@ var StarTopology = class {
|
|
|
1855
2222
|
log9("connecting to peer", {
|
|
1856
2223
|
peer
|
|
1857
2224
|
}, {
|
|
1858
|
-
F:
|
|
1859
|
-
L:
|
|
2225
|
+
F: __dxlog_file10,
|
|
2226
|
+
L: 46,
|
|
1860
2227
|
S: this,
|
|
1861
2228
|
C: (f, a) => f(...a)
|
|
1862
2229
|
});
|
|
@@ -1865,15 +2232,23 @@ var StarTopology = class {
|
|
|
1865
2232
|
}
|
|
1866
2233
|
}
|
|
1867
2234
|
async onOffer(peer) {
|
|
1868
|
-
invariant9(this._controller, "Not initialized."
|
|
2235
|
+
invariant9(this._controller, "Not initialized.", {
|
|
2236
|
+
F: __dxlog_file10,
|
|
2237
|
+
L: 53,
|
|
2238
|
+
S: this,
|
|
2239
|
+
A: [
|
|
2240
|
+
"this._controller",
|
|
2241
|
+
"'Not initialized.'"
|
|
2242
|
+
]
|
|
2243
|
+
});
|
|
1869
2244
|
const { ownPeerId } = this._controller.getState();
|
|
1870
2245
|
log9("offer", {
|
|
1871
2246
|
peer,
|
|
1872
2247
|
isCentral: peer.equals(this._centralPeer),
|
|
1873
2248
|
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
1874
2249
|
}, {
|
|
1875
|
-
F:
|
|
1876
|
-
L:
|
|
2250
|
+
F: __dxlog_file10,
|
|
2251
|
+
L: 55,
|
|
1877
2252
|
S: this,
|
|
1878
2253
|
C: (f, a) => f(...a)
|
|
1879
2254
|
});
|
|
@@ -1885,9 +2260,9 @@ var StarTopology = class {
|
|
|
1885
2260
|
|
|
1886
2261
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1887
2262
|
import { Transform } from "@dxos/node-std/stream";
|
|
1888
|
-
import invariant10 from "tiny-invariant";
|
|
1889
2263
|
import { Event as Event6, Trigger } from "@dxos/async";
|
|
1890
2264
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
2265
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
1891
2266
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
1892
2267
|
import { log as log10, logInfo as logInfo2 } from "@dxos/log";
|
|
1893
2268
|
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
@@ -1901,7 +2276,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
1901
2276
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1902
2277
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1903
2278
|
}
|
|
1904
|
-
var
|
|
2279
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
1905
2280
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1906
2281
|
var createStreamDelay = (delay) => {
|
|
1907
2282
|
return new Transform({
|
|
@@ -1927,17 +2302,25 @@ var _MemoryTransport = class {
|
|
|
1927
2302
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1928
2303
|
this._destroyed = false;
|
|
1929
2304
|
log10("creating", void 0, {
|
|
1930
|
-
F:
|
|
2305
|
+
F: __dxlog_file11,
|
|
1931
2306
|
L: 64,
|
|
1932
2307
|
S: this,
|
|
1933
2308
|
C: (f, a) => f(...a)
|
|
1934
2309
|
});
|
|
1935
|
-
invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection"
|
|
2310
|
+
invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2311
|
+
F: __dxlog_file11,
|
|
2312
|
+
L: 66,
|
|
2313
|
+
S: this,
|
|
2314
|
+
A: [
|
|
2315
|
+
"!MemoryTransport._connections.has(this._instanceId)",
|
|
2316
|
+
"'Duplicate memory connection'"
|
|
2317
|
+
]
|
|
2318
|
+
});
|
|
1936
2319
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1937
2320
|
if (this.options.initiator) {
|
|
1938
2321
|
setTimeout(async () => {
|
|
1939
2322
|
log10("sending signal", void 0, {
|
|
1940
|
-
F:
|
|
2323
|
+
F: __dxlog_file11,
|
|
1941
2324
|
L: 73,
|
|
1942
2325
|
S: this,
|
|
1943
2326
|
C: (f, a) => f(...a)
|
|
@@ -1966,11 +2349,19 @@ var _MemoryTransport = class {
|
|
|
1966
2349
|
this.closed.emit();
|
|
1967
2350
|
return;
|
|
1968
2351
|
}
|
|
1969
|
-
invariant10(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}
|
|
2352
|
+
invariant10(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2353
|
+
F: __dxlog_file11,
|
|
2354
|
+
L: 99,
|
|
2355
|
+
S: this,
|
|
2356
|
+
A: [
|
|
2357
|
+
"!this._remoteConnection._remoteConnection",
|
|
2358
|
+
"`Remote already connected: ${this._remoteInstanceId}`"
|
|
2359
|
+
]
|
|
2360
|
+
});
|
|
1970
2361
|
this._remoteConnection._remoteConnection = this;
|
|
1971
2362
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1972
2363
|
log10("connected", void 0, {
|
|
1973
|
-
F:
|
|
2364
|
+
F: __dxlog_file11,
|
|
1974
2365
|
L: 103,
|
|
1975
2366
|
S: this,
|
|
1976
2367
|
C: (f, a) => f(...a)
|
|
@@ -1988,7 +2379,7 @@ var _MemoryTransport = class {
|
|
|
1988
2379
|
}
|
|
1989
2380
|
async destroy() {
|
|
1990
2381
|
log10("closing", void 0, {
|
|
1991
|
-
F:
|
|
2382
|
+
F: __dxlog_file11,
|
|
1992
2383
|
L: 124,
|
|
1993
2384
|
S: this,
|
|
1994
2385
|
C: (f, a) => f(...a)
|
|
@@ -1997,7 +2388,7 @@ var _MemoryTransport = class {
|
|
|
1997
2388
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
1998
2389
|
if (this._remoteConnection) {
|
|
1999
2390
|
log10("closing", void 0, {
|
|
2000
|
-
F:
|
|
2391
|
+
F: __dxlog_file11,
|
|
2001
2392
|
L: 129,
|
|
2002
2393
|
S: this,
|
|
2003
2394
|
C: (f, a) => f(...a)
|
|
@@ -2010,7 +2401,7 @@ var _MemoryTransport = class {
|
|
|
2010
2401
|
this._remoteConnection._remoteConnection = void 0;
|
|
2011
2402
|
this._remoteConnection = void 0;
|
|
2012
2403
|
log10("closed", void 0, {
|
|
2013
|
-
F:
|
|
2404
|
+
F: __dxlog_file11,
|
|
2014
2405
|
L: 147,
|
|
2015
2406
|
S: this,
|
|
2016
2407
|
C: (f, a) => f(...a)
|
|
@@ -2018,7 +2409,7 @@ var _MemoryTransport = class {
|
|
|
2018
2409
|
}
|
|
2019
2410
|
this.closed.emit();
|
|
2020
2411
|
log10("closed", void 0, {
|
|
2021
|
-
F:
|
|
2412
|
+
F: __dxlog_file11,
|
|
2022
2413
|
L: 151,
|
|
2023
2414
|
S: this,
|
|
2024
2415
|
C: (f, a) => f(...a)
|
|
@@ -2028,7 +2419,7 @@ var _MemoryTransport = class {
|
|
|
2028
2419
|
log10("received signal", {
|
|
2029
2420
|
payload
|
|
2030
2421
|
}, {
|
|
2031
|
-
F:
|
|
2422
|
+
F: __dxlog_file11,
|
|
2032
2423
|
L: 155,
|
|
2033
2424
|
S: this,
|
|
2034
2425
|
C: (f, a) => f(...a)
|
|
@@ -2055,9 +2446,9 @@ _ts_decorate4([
|
|
|
2055
2446
|
|
|
2056
2447
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
2057
2448
|
import SimplePeerConstructor from "simple-peer";
|
|
2058
|
-
import invariant11 from "tiny-invariant";
|
|
2059
2449
|
import { Event as Event7 } from "@dxos/async";
|
|
2060
2450
|
import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
|
|
2451
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
2061
2452
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
2062
2453
|
import { log as log11 } from "@dxos/log";
|
|
2063
2454
|
import { trace as trace4 } from "@dxos/protocols";
|
|
@@ -2070,7 +2461,7 @@ try {
|
|
|
2070
2461
|
}
|
|
2071
2462
|
|
|
2072
2463
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
2073
|
-
var
|
|
2464
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
|
|
2074
2465
|
var WebRTCTransport = class {
|
|
2075
2466
|
constructor(params) {
|
|
2076
2467
|
var _a;
|
|
@@ -2083,13 +2474,13 @@ var WebRTCTransport = class {
|
|
|
2083
2474
|
log11.trace("dxos.mesh.webrtc-transport.constructor", trace4.begin({
|
|
2084
2475
|
id: this._instanceId
|
|
2085
2476
|
}), {
|
|
2086
|
-
F:
|
|
2477
|
+
F: __dxlog_file12,
|
|
2087
2478
|
L: 39,
|
|
2088
2479
|
S: this,
|
|
2089
2480
|
C: (f, a) => f(...a)
|
|
2090
2481
|
});
|
|
2091
2482
|
log11("created connection", params, {
|
|
2092
|
-
F:
|
|
2483
|
+
F: __dxlog_file12,
|
|
2093
2484
|
L: 40,
|
|
2094
2485
|
S: this,
|
|
2095
2486
|
C: (f, a) => f(...a)
|
|
@@ -2101,7 +2492,7 @@ var WebRTCTransport = class {
|
|
|
2101
2492
|
});
|
|
2102
2493
|
this._peer.on("signal", async (data) => {
|
|
2103
2494
|
log11("signal", data, {
|
|
2104
|
-
F:
|
|
2495
|
+
F: __dxlog_file12,
|
|
2105
2496
|
L: 48,
|
|
2106
2497
|
S: this,
|
|
2107
2498
|
C: (f, a) => f(...a)
|
|
@@ -2114,7 +2505,7 @@ var WebRTCTransport = class {
|
|
|
2114
2505
|
});
|
|
2115
2506
|
this._peer.on("connect", () => {
|
|
2116
2507
|
log11("connected", void 0, {
|
|
2117
|
-
F:
|
|
2508
|
+
F: __dxlog_file12,
|
|
2118
2509
|
L: 53,
|
|
2119
2510
|
S: this,
|
|
2120
2511
|
C: (f, a) => f(...a)
|
|
@@ -2124,7 +2515,7 @@ var WebRTCTransport = class {
|
|
|
2124
2515
|
});
|
|
2125
2516
|
this._peer.on("close", async () => {
|
|
2126
2517
|
log11("closed", void 0, {
|
|
2127
|
-
F:
|
|
2518
|
+
F: __dxlog_file12,
|
|
2128
2519
|
L: 59,
|
|
2129
2520
|
S: this,
|
|
2130
2521
|
C: (f, a) => f(...a)
|
|
@@ -2142,7 +2533,7 @@ var WebRTCTransport = class {
|
|
|
2142
2533
|
config: this.params.webrtcConfig,
|
|
2143
2534
|
stats
|
|
2144
2535
|
}, {
|
|
2145
|
-
F:
|
|
2536
|
+
F: __dxlog_file12,
|
|
2146
2537
|
L: 71,
|
|
2147
2538
|
S: this,
|
|
2148
2539
|
C: (f, a) => f(...a)
|
|
@@ -2156,7 +2547,7 @@ var WebRTCTransport = class {
|
|
|
2156
2547
|
log11.trace("dxos.mesh.webrtc-transport.constructor", trace4.end({
|
|
2157
2548
|
id: this._instanceId
|
|
2158
2549
|
}), {
|
|
2159
|
-
F:
|
|
2550
|
+
F: __dxlog_file12,
|
|
2160
2551
|
L: 81,
|
|
2161
2552
|
S: this,
|
|
2162
2553
|
C: (f, a) => f(...a)
|
|
@@ -2164,7 +2555,7 @@ var WebRTCTransport = class {
|
|
|
2164
2555
|
}
|
|
2165
2556
|
async destroy() {
|
|
2166
2557
|
log11("closing...", void 0, {
|
|
2167
|
-
F:
|
|
2558
|
+
F: __dxlog_file12,
|
|
2168
2559
|
L: 85,
|
|
2169
2560
|
S: this,
|
|
2170
2561
|
C: (f, a) => f(...a)
|
|
@@ -2174,7 +2565,7 @@ var WebRTCTransport = class {
|
|
|
2174
2565
|
this._peer.destroy();
|
|
2175
2566
|
this.closed.emit();
|
|
2176
2567
|
log11("closed", void 0, {
|
|
2177
|
-
F:
|
|
2568
|
+
F: __dxlog_file12,
|
|
2178
2569
|
L: 90,
|
|
2179
2570
|
S: this,
|
|
2180
2571
|
C: (f, a) => f(...a)
|
|
@@ -2184,7 +2575,15 @@ var WebRTCTransport = class {
|
|
|
2184
2575
|
if (this._closed) {
|
|
2185
2576
|
return;
|
|
2186
2577
|
}
|
|
2187
|
-
invariant11(signal.payload.data, "Signal message must contain signal data."
|
|
2578
|
+
invariant11(signal.payload.data, "Signal message must contain signal data.", {
|
|
2579
|
+
F: __dxlog_file12,
|
|
2580
|
+
L: 98,
|
|
2581
|
+
S: this,
|
|
2582
|
+
A: [
|
|
2583
|
+
"signal.payload.data",
|
|
2584
|
+
"'Signal message must contain signal data.'"
|
|
2585
|
+
]
|
|
2586
|
+
});
|
|
2188
2587
|
this._peer.signal(signal.payload.data);
|
|
2189
2588
|
}
|
|
2190
2589
|
async _disconnectStreams() {
|
|
@@ -2201,13 +2600,13 @@ var createWebRTCTransportFactory = (webrtcConfig) => ({
|
|
|
2201
2600
|
|
|
2202
2601
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
2203
2602
|
import { Duplex } from "@dxos/node-std/stream";
|
|
2204
|
-
import invariant12 from "tiny-invariant";
|
|
2205
2603
|
import { Stream } from "@dxos/codec-protobuf";
|
|
2604
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
2206
2605
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
2207
2606
|
import { log as log12 } from "@dxos/log";
|
|
2208
2607
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
2209
2608
|
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
2210
|
-
var
|
|
2609
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
|
|
2211
2610
|
var WebRTCTransportService = class {
|
|
2212
2611
|
// prettier-ignore
|
|
2213
2612
|
constructor(_webrtcConfig) {
|
|
@@ -2218,6 +2617,13 @@ var WebRTCTransportService = class {
|
|
|
2218
2617
|
const rpcStream = new Stream(({ ready, next, close }) => {
|
|
2219
2618
|
const duplex = new Duplex({
|
|
2220
2619
|
read: () => {
|
|
2620
|
+
const callbacks = [
|
|
2621
|
+
...transportState.writeCallbacks
|
|
2622
|
+
];
|
|
2623
|
+
transportState.writeCallbacks.length = 0;
|
|
2624
|
+
for (const cb of callbacks) {
|
|
2625
|
+
cb();
|
|
2626
|
+
}
|
|
2221
2627
|
},
|
|
2222
2628
|
write: function(chunk, _, callback) {
|
|
2223
2629
|
next({
|
|
@@ -2269,21 +2675,45 @@ var WebRTCTransportService = class {
|
|
|
2269
2675
|
});
|
|
2270
2676
|
close();
|
|
2271
2677
|
});
|
|
2272
|
-
|
|
2273
|
-
this.transports.set(request.proxyId, {
|
|
2678
|
+
const transportState = {
|
|
2274
2679
|
transport,
|
|
2275
|
-
stream: duplex
|
|
2276
|
-
|
|
2680
|
+
stream: duplex,
|
|
2681
|
+
writeCallbacks: []
|
|
2682
|
+
};
|
|
2683
|
+
ready();
|
|
2684
|
+
this.transports.set(request.proxyId, transportState);
|
|
2277
2685
|
});
|
|
2278
2686
|
return rpcStream;
|
|
2279
2687
|
}
|
|
2280
2688
|
async sendSignal({ proxyId, signal }) {
|
|
2281
|
-
invariant12(this.transports.has(proxyId)
|
|
2689
|
+
invariant12(this.transports.has(proxyId), void 0, {
|
|
2690
|
+
F: __dxlog_file13,
|
|
2691
|
+
L: 113,
|
|
2692
|
+
S: this,
|
|
2693
|
+
A: [
|
|
2694
|
+
"this.transports.has(proxyId)",
|
|
2695
|
+
""
|
|
2696
|
+
]
|
|
2697
|
+
});
|
|
2282
2698
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2283
2699
|
}
|
|
2284
2700
|
async sendData({ proxyId, payload }) {
|
|
2285
|
-
invariant12(this.transports.has(proxyId)
|
|
2286
|
-
|
|
2701
|
+
invariant12(this.transports.has(proxyId), void 0, {
|
|
2702
|
+
F: __dxlog_file13,
|
|
2703
|
+
L: 118,
|
|
2704
|
+
S: this,
|
|
2705
|
+
A: [
|
|
2706
|
+
"this.transports.has(proxyId)",
|
|
2707
|
+
""
|
|
2708
|
+
]
|
|
2709
|
+
});
|
|
2710
|
+
const state = this.transports.get(proxyId);
|
|
2711
|
+
const bufferHasSpace = state.stream.push(payload);
|
|
2712
|
+
if (!bufferHasSpace) {
|
|
2713
|
+
await new Promise((resolve) => {
|
|
2714
|
+
state.writeCallbacks.push(resolve);
|
|
2715
|
+
});
|
|
2716
|
+
}
|
|
2287
2717
|
}
|
|
2288
2718
|
async close({ proxyId }) {
|
|
2289
2719
|
var _a, _b;
|
|
@@ -2291,8 +2721,8 @@ var WebRTCTransportService = class {
|
|
|
2291
2721
|
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
2292
2722
|
this.transports.delete(proxyId);
|
|
2293
2723
|
log12("Closed.", void 0, {
|
|
2294
|
-
F:
|
|
2295
|
-
L:
|
|
2724
|
+
F: __dxlog_file13,
|
|
2725
|
+
L: 132,
|
|
2296
2726
|
S: this,
|
|
2297
2727
|
C: (f, a) => f(...a)
|
|
2298
2728
|
});
|
|
@@ -2300,15 +2730,16 @@ var WebRTCTransportService = class {
|
|
|
2300
2730
|
};
|
|
2301
2731
|
|
|
2302
2732
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2303
|
-
import
|
|
2733
|
+
import { Writable } from "@dxos/node-std/stream";
|
|
2304
2734
|
import { Event as Event8 } from "@dxos/async";
|
|
2305
2735
|
import { Context as Context6 } from "@dxos/context";
|
|
2306
2736
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
2737
|
+
import { invariant as invariant13 } from "@dxos/invariant";
|
|
2307
2738
|
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
2308
2739
|
import { log as log13 } from "@dxos/log";
|
|
2309
2740
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
2310
2741
|
import { arrayToBuffer } from "@dxos/util";
|
|
2311
|
-
var
|
|
2742
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
|
|
2312
2743
|
var WebRTCTransportProxy = class {
|
|
2313
2744
|
// prettier-ignore
|
|
2314
2745
|
constructor(_params) {
|
|
@@ -2326,8 +2757,8 @@ var WebRTCTransportProxy = class {
|
|
|
2326
2757
|
this._serviceStream.waitUntilReady().then(() => {
|
|
2327
2758
|
this._serviceStream.subscribe(async (event) => {
|
|
2328
2759
|
log13("WebRTCTransportProxy: event", event, {
|
|
2329
|
-
F:
|
|
2330
|
-
L:
|
|
2760
|
+
F: __dxlog_file14,
|
|
2761
|
+
L: 51,
|
|
2331
2762
|
S: this,
|
|
2332
2763
|
C: (f, a) => f(...a)
|
|
2333
2764
|
});
|
|
@@ -2339,28 +2770,24 @@ var WebRTCTransportProxy = class {
|
|
|
2339
2770
|
await this._handleSignal(event.signal);
|
|
2340
2771
|
}
|
|
2341
2772
|
});
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2773
|
+
this._params.stream.pipe(new Writable({
|
|
2774
|
+
write: (chunk, _, callback) => {
|
|
2775
|
+
this._params.bridgeService.sendData({
|
|
2345
2776
|
proxyId: this._proxyId,
|
|
2346
|
-
payload:
|
|
2347
|
-
})
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2777
|
+
payload: chunk
|
|
2778
|
+
}).then(() => callback(), (err) => {
|
|
2779
|
+
log13.catch(err, void 0, {
|
|
2780
|
+
F: __dxlog_file14,
|
|
2781
|
+
L: 69,
|
|
2782
|
+
S: this,
|
|
2783
|
+
C: (f, a) => f(...a)
|
|
2784
|
+
});
|
|
2354
2785
|
});
|
|
2355
2786
|
}
|
|
2356
|
-
};
|
|
2357
|
-
this._params.stream.on("data", dataListener);
|
|
2358
|
-
this._ctx.onDispose(() => {
|
|
2359
|
-
this._params.stream.off("data", dataListener);
|
|
2360
|
-
});
|
|
2787
|
+
}));
|
|
2361
2788
|
}, (error) => log13.catch(error, void 0, {
|
|
2362
|
-
F:
|
|
2363
|
-
L:
|
|
2789
|
+
F: __dxlog_file14,
|
|
2790
|
+
L: 75,
|
|
2364
2791
|
S: this,
|
|
2365
2792
|
C: (f, a) => f(...a)
|
|
2366
2793
|
}));
|
|
@@ -2405,8 +2832,8 @@ var WebRTCTransportProxy = class {
|
|
|
2405
2832
|
});
|
|
2406
2833
|
} catch (err) {
|
|
2407
2834
|
log13.catch(err, void 0, {
|
|
2408
|
-
F:
|
|
2409
|
-
L:
|
|
2835
|
+
F: __dxlog_file14,
|
|
2836
|
+
L: 126,
|
|
2410
2837
|
S: this,
|
|
2411
2838
|
C: (f, a) => f(...a)
|
|
2412
2839
|
});
|
|
@@ -2440,7 +2867,15 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2440
2867
|
return this;
|
|
2441
2868
|
}
|
|
2442
2869
|
createTransport(options) {
|
|
2443
|
-
invariant13(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections"
|
|
2870
|
+
invariant13(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections", {
|
|
2871
|
+
F: __dxlog_file14,
|
|
2872
|
+
L: 163,
|
|
2873
|
+
S: this,
|
|
2874
|
+
A: [
|
|
2875
|
+
"this._bridgeService",
|
|
2876
|
+
"'WebRTCTransportProxyFactory is not ready to open connections'"
|
|
2877
|
+
]
|
|
2878
|
+
});
|
|
2444
2879
|
const transport = new WebRTCTransportProxy({
|
|
2445
2880
|
...options,
|
|
2446
2881
|
bridgeService: this._bridgeService
|
|
@@ -2492,4 +2927,4 @@ export {
|
|
|
2492
2927
|
WebRTCTransportProxyFactory,
|
|
2493
2928
|
createTeleportProtocolFactory
|
|
2494
2929
|
};
|
|
2495
|
-
//# sourceMappingURL=chunk-
|
|
2930
|
+
//# sourceMappingURL=chunk-FC6CWDES.mjs.map
|