@dxos/network-manager 0.1.56-main.b25ef1c → 0.1.56-main.bf228a7
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-FYPOLWVS.mjs} +561 -187
- package/dist/lib/browser/chunk-FYPOLWVS.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 +560 -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 +486 -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 +1 -2
- package/src/swarm/peer.ts +1 -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";
|
|
@@ -98,12 +98,20 @@ var Connection = class {
|
|
|
98
98
|
* Create an underlying transport and prepares it for the connection.
|
|
99
99
|
*/
|
|
100
100
|
async openConnection() {
|
|
101
|
-
invariant(this._state === ConnectionState.INITIAL, "Invalid state."
|
|
101
|
+
invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
|
|
102
|
+
F: __dxlog_file,
|
|
103
|
+
L: 112,
|
|
104
|
+
S: this,
|
|
105
|
+
A: [
|
|
106
|
+
"this._state === ConnectionState.INITIAL",
|
|
107
|
+
"'Invalid state.'"
|
|
108
|
+
]
|
|
109
|
+
});
|
|
102
110
|
log.trace("dxos.mesh.connection.open-connection", trace.begin({
|
|
103
111
|
id: this._instanceId
|
|
104
112
|
}), {
|
|
105
113
|
F: __dxlog_file,
|
|
106
|
-
L:
|
|
114
|
+
L: 113,
|
|
107
115
|
S: this,
|
|
108
116
|
C: (f, a) => f(...a)
|
|
109
117
|
});
|
|
@@ -114,13 +122,21 @@ var Connection = class {
|
|
|
114
122
|
this._protocol.stream.on("close", () => {
|
|
115
123
|
log("protocol stream closed", void 0, {
|
|
116
124
|
F: __dxlog_file,
|
|
117
|
-
L:
|
|
125
|
+
L: 124,
|
|
118
126
|
S: this,
|
|
119
127
|
C: (f, a) => f(...a)
|
|
120
128
|
});
|
|
121
129
|
this.close().catch((err) => this.errors.raise(err));
|
|
122
130
|
});
|
|
123
|
-
invariant(!this._transport
|
|
131
|
+
invariant(!this._transport, void 0, {
|
|
132
|
+
F: __dxlog_file,
|
|
133
|
+
L: 128,
|
|
134
|
+
S: this,
|
|
135
|
+
A: [
|
|
136
|
+
"!this._transport",
|
|
137
|
+
""
|
|
138
|
+
]
|
|
139
|
+
});
|
|
124
140
|
this._transport = this._transportFactory.createTransport({
|
|
125
141
|
initiator: this.initiator,
|
|
126
142
|
stream: this._protocol.stream,
|
|
@@ -146,7 +162,7 @@ var Connection = class {
|
|
|
146
162
|
id: this._instanceId
|
|
147
163
|
}), {
|
|
148
164
|
F: __dxlog_file,
|
|
149
|
-
L:
|
|
165
|
+
L: 157,
|
|
150
166
|
S: this,
|
|
151
167
|
C: (f, a) => f(...a)
|
|
152
168
|
});
|
|
@@ -162,7 +178,7 @@ var Connection = class {
|
|
|
162
178
|
peerId: this.ownId
|
|
163
179
|
}, {
|
|
164
180
|
F: __dxlog_file,
|
|
165
|
-
L:
|
|
181
|
+
L: 169,
|
|
166
182
|
S: this,
|
|
167
183
|
C: (f, a) => f(...a)
|
|
168
184
|
});
|
|
@@ -171,7 +187,7 @@ var Connection = class {
|
|
|
171
187
|
} catch (err) {
|
|
172
188
|
log.catch(err, void 0, {
|
|
173
189
|
F: __dxlog_file,
|
|
174
|
-
L:
|
|
190
|
+
L: 175,
|
|
175
191
|
S: this,
|
|
176
192
|
C: (f, a) => f(...a)
|
|
177
193
|
});
|
|
@@ -181,7 +197,7 @@ var Connection = class {
|
|
|
181
197
|
} catch (err) {
|
|
182
198
|
log.catch(err, void 0, {
|
|
183
199
|
F: __dxlog_file,
|
|
184
|
-
L:
|
|
200
|
+
L: 182,
|
|
185
201
|
S: this,
|
|
186
202
|
C: (f, a) => f(...a)
|
|
187
203
|
});
|
|
@@ -190,7 +206,7 @@ var Connection = class {
|
|
|
190
206
|
peerId: this.ownId
|
|
191
207
|
}, {
|
|
192
208
|
F: __dxlog_file,
|
|
193
|
-
L:
|
|
209
|
+
L: 185,
|
|
194
210
|
S: this,
|
|
195
211
|
C: (f, a) => f(...a)
|
|
196
212
|
});
|
|
@@ -230,7 +246,7 @@ var Connection = class {
|
|
|
230
246
|
err
|
|
231
247
|
}, {
|
|
232
248
|
F: __dxlog_file,
|
|
233
|
-
L:
|
|
249
|
+
L: 219,
|
|
234
250
|
S: this,
|
|
235
251
|
C: (f, a) => f(...a)
|
|
236
252
|
});
|
|
@@ -242,19 +258,51 @@ var Connection = class {
|
|
|
242
258
|
*/
|
|
243
259
|
async signal(msg) {
|
|
244
260
|
var _a, _b, _c;
|
|
245
|
-
invariant(msg.sessionId
|
|
261
|
+
invariant(msg.sessionId, void 0, {
|
|
262
|
+
F: __dxlog_file,
|
|
263
|
+
L: 228,
|
|
264
|
+
S: this,
|
|
265
|
+
A: [
|
|
266
|
+
"msg.sessionId",
|
|
267
|
+
""
|
|
268
|
+
]
|
|
269
|
+
});
|
|
246
270
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
247
271
|
log("dropping signal for incorrect session id", void 0, {
|
|
248
272
|
F: __dxlog_file,
|
|
249
|
-
L:
|
|
273
|
+
L: 230,
|
|
250
274
|
S: this,
|
|
251
275
|
C: (f, a) => f(...a)
|
|
252
276
|
});
|
|
253
277
|
return;
|
|
254
278
|
}
|
|
255
|
-
invariant(msg.data.signal || msg.data.signalBatch
|
|
256
|
-
|
|
257
|
-
|
|
279
|
+
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
280
|
+
F: __dxlog_file,
|
|
281
|
+
L: 233,
|
|
282
|
+
S: this,
|
|
283
|
+
A: [
|
|
284
|
+
"msg.data.signal || msg.data.signalBatch",
|
|
285
|
+
""
|
|
286
|
+
]
|
|
287
|
+
});
|
|
288
|
+
invariant((_a = msg.author) == null ? void 0 : _a.equals(this.remoteId), void 0, {
|
|
289
|
+
F: __dxlog_file,
|
|
290
|
+
L: 234,
|
|
291
|
+
S: this,
|
|
292
|
+
A: [
|
|
293
|
+
"msg.author?.equals(this.remoteId)",
|
|
294
|
+
""
|
|
295
|
+
]
|
|
296
|
+
});
|
|
297
|
+
invariant((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId), void 0, {
|
|
298
|
+
F: __dxlog_file,
|
|
299
|
+
L: 235,
|
|
300
|
+
S: this,
|
|
301
|
+
A: [
|
|
302
|
+
"msg.recipient?.equals(this.ownId)",
|
|
303
|
+
""
|
|
304
|
+
]
|
|
305
|
+
});
|
|
258
306
|
const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
|
|
259
307
|
msg.data.signal
|
|
260
308
|
];
|
|
@@ -269,20 +317,28 @@ var Connection = class {
|
|
|
269
317
|
msg: msg.data
|
|
270
318
|
}, {
|
|
271
319
|
F: __dxlog_file,
|
|
272
|
-
L:
|
|
320
|
+
L: 244,
|
|
273
321
|
S: this,
|
|
274
322
|
C: (f, a) => f(...a)
|
|
275
323
|
});
|
|
276
324
|
this._incomingSignalBuffer.push(signal);
|
|
277
325
|
} else {
|
|
278
|
-
invariant(this._transport, "Connection not ready to accept signals."
|
|
326
|
+
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
327
|
+
F: __dxlog_file,
|
|
328
|
+
L: 247,
|
|
329
|
+
S: this,
|
|
330
|
+
A: [
|
|
331
|
+
"this._transport",
|
|
332
|
+
"'Connection not ready to accept signals.'"
|
|
333
|
+
]
|
|
334
|
+
});
|
|
279
335
|
log("received signal", {
|
|
280
336
|
peerId: this.ownId,
|
|
281
337
|
remoteId: this.remoteId,
|
|
282
338
|
msg: msg.data
|
|
283
339
|
}, {
|
|
284
340
|
F: __dxlog_file,
|
|
285
|
-
L:
|
|
341
|
+
L: 248,
|
|
286
342
|
S: this,
|
|
287
343
|
C: (f, a) => f(...a)
|
|
288
344
|
});
|
|
@@ -297,11 +353,19 @@ var Connection = class {
|
|
|
297
353
|
peerId: this.ownId
|
|
298
354
|
}, {
|
|
299
355
|
F: __dxlog_file,
|
|
300
|
-
L:
|
|
356
|
+
L: 255,
|
|
301
357
|
S: this,
|
|
302
358
|
C: (f, a) => f(...a)
|
|
303
359
|
});
|
|
304
|
-
invariant(state !== this._state, "Already in this state."
|
|
360
|
+
invariant(state !== this._state, "Already in this state.", {
|
|
361
|
+
F: __dxlog_file,
|
|
362
|
+
L: 256,
|
|
363
|
+
S: this,
|
|
364
|
+
A: [
|
|
365
|
+
"state !== this._state",
|
|
366
|
+
"'Already in this state.'"
|
|
367
|
+
]
|
|
368
|
+
});
|
|
305
369
|
this._state = state;
|
|
306
370
|
this.stateChanged.emit(state);
|
|
307
371
|
}
|
|
@@ -311,8 +375,8 @@ _ts_decorate([
|
|
|
311
375
|
], Connection.prototype, "close", null);
|
|
312
376
|
|
|
313
377
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
314
|
-
import invariant2 from "tiny-invariant";
|
|
315
378
|
import { Context as Context2 } from "@dxos/context";
|
|
379
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
316
380
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
317
381
|
import { log as log2 } from "@dxos/log";
|
|
318
382
|
import { schema } from "@dxos/protocols";
|
|
@@ -343,7 +407,7 @@ var SwarmMessenger = class {
|
|
|
343
407
|
msg: message
|
|
344
408
|
}, {
|
|
345
409
|
F: __dxlog_file2,
|
|
346
|
-
L:
|
|
410
|
+
L: 69,
|
|
347
411
|
S: this,
|
|
348
412
|
C: (f, a) => f(...a)
|
|
349
413
|
});
|
|
@@ -372,7 +436,7 @@ var SwarmMessenger = class {
|
|
|
372
436
|
message
|
|
373
437
|
}, {
|
|
374
438
|
F: __dxlog_file2,
|
|
375
|
-
L:
|
|
439
|
+
L: 80,
|
|
376
440
|
S: this,
|
|
377
441
|
C: (f, a) => f(...a)
|
|
378
442
|
});
|
|
@@ -380,7 +444,15 @@ var SwarmMessenger = class {
|
|
|
380
444
|
}
|
|
381
445
|
async signal(message) {
|
|
382
446
|
var _a, _b;
|
|
383
|
-
invariant2(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message"
|
|
447
|
+
invariant2(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message", {
|
|
448
|
+
F: __dxlog_file2,
|
|
449
|
+
L: 85,
|
|
450
|
+
S: this,
|
|
451
|
+
A: [
|
|
452
|
+
"message.data?.signal || message.data?.signalBatch",
|
|
453
|
+
"'Invalid message'"
|
|
454
|
+
]
|
|
455
|
+
});
|
|
384
456
|
await this._sendReliableMessage({
|
|
385
457
|
author: message.author,
|
|
386
458
|
recipient: message.recipient,
|
|
@@ -416,7 +488,7 @@ var SwarmMessenger = class {
|
|
|
416
488
|
msg: networkMessage
|
|
417
489
|
}, {
|
|
418
490
|
F: __dxlog_file2,
|
|
419
|
-
L:
|
|
491
|
+
L: 123,
|
|
420
492
|
S: this,
|
|
421
493
|
C: (f, a) => f(...a)
|
|
422
494
|
});
|
|
@@ -431,16 +503,32 @@ var SwarmMessenger = class {
|
|
|
431
503
|
}
|
|
432
504
|
async _resolveAnswers(message) {
|
|
433
505
|
var _a, _b, _c;
|
|
434
|
-
invariant2((_b = (_a = message.data) == null ? void 0 : _a.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId"
|
|
506
|
+
invariant2((_b = (_a = message.data) == null ? void 0 : _a.answer) == null ? void 0 : _b.offerMessageId, "No offerMessageId", {
|
|
507
|
+
F: __dxlog_file2,
|
|
508
|
+
L: 135,
|
|
509
|
+
S: this,
|
|
510
|
+
A: [
|
|
511
|
+
"message.data?.answer?.offerMessageId",
|
|
512
|
+
"'No offerMessageId'"
|
|
513
|
+
]
|
|
514
|
+
});
|
|
435
515
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
436
516
|
if (offerRecord) {
|
|
437
517
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
438
|
-
invariant2((_c = message.data) == null ? void 0 : _c.answer, "No answer"
|
|
518
|
+
invariant2((_c = message.data) == null ? void 0 : _c.answer, "No answer", {
|
|
519
|
+
F: __dxlog_file2,
|
|
520
|
+
L: 139,
|
|
521
|
+
S: this,
|
|
522
|
+
A: [
|
|
523
|
+
"message.data?.answer",
|
|
524
|
+
"'No answer'"
|
|
525
|
+
]
|
|
526
|
+
});
|
|
439
527
|
log2("resolving", {
|
|
440
528
|
answer: message.data.answer
|
|
441
529
|
}, {
|
|
442
530
|
F: __dxlog_file2,
|
|
443
|
-
L:
|
|
531
|
+
L: 140,
|
|
444
532
|
S: this,
|
|
445
533
|
C: (f, a) => f(...a)
|
|
446
534
|
});
|
|
@@ -448,7 +536,15 @@ var SwarmMessenger = class {
|
|
|
448
536
|
}
|
|
449
537
|
}
|
|
450
538
|
async _handleOffer({ author, recipient, message }) {
|
|
451
|
-
invariant2(message.data.offer, "No offer"
|
|
539
|
+
invariant2(message.data.offer, "No offer", {
|
|
540
|
+
F: __dxlog_file2,
|
|
541
|
+
L: 154,
|
|
542
|
+
S: this,
|
|
543
|
+
A: [
|
|
544
|
+
"message.data.offer",
|
|
545
|
+
"'No offer'"
|
|
546
|
+
]
|
|
547
|
+
});
|
|
452
548
|
const offerMessage = {
|
|
453
549
|
author,
|
|
454
550
|
recipient,
|
|
@@ -476,15 +572,31 @@ var SwarmMessenger = class {
|
|
|
476
572
|
err
|
|
477
573
|
}, {
|
|
478
574
|
F: __dxlog_file2,
|
|
479
|
-
L:
|
|
575
|
+
L: 174,
|
|
480
576
|
S: this,
|
|
481
577
|
C: (f, a) => f(...a)
|
|
482
578
|
});
|
|
483
579
|
}
|
|
484
580
|
}
|
|
485
581
|
async _handleSignal({ author, recipient, message }) {
|
|
486
|
-
invariant2(message.messageId
|
|
487
|
-
|
|
582
|
+
invariant2(message.messageId, void 0, {
|
|
583
|
+
F: __dxlog_file2,
|
|
584
|
+
L: 187,
|
|
585
|
+
S: this,
|
|
586
|
+
A: [
|
|
587
|
+
"message.messageId",
|
|
588
|
+
""
|
|
589
|
+
]
|
|
590
|
+
});
|
|
591
|
+
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
592
|
+
F: __dxlog_file2,
|
|
593
|
+
L: 188,
|
|
594
|
+
S: this,
|
|
595
|
+
A: [
|
|
596
|
+
"message.data.signal || message.data.signalBatch",
|
|
597
|
+
"'Invalid message'"
|
|
598
|
+
]
|
|
599
|
+
});
|
|
488
600
|
const signalMessage = {
|
|
489
601
|
author,
|
|
490
602
|
recipient,
|
|
@@ -499,20 +611,20 @@ var SwarmMessenger = class {
|
|
|
499
611
|
};
|
|
500
612
|
|
|
501
613
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
502
|
-
import invariant4 from "tiny-invariant";
|
|
503
614
|
import { Event as Event2, scheduleTask as scheduleTask2, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
|
|
504
615
|
import { Context as Context4 } from "@dxos/context";
|
|
505
616
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
617
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
506
618
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
507
619
|
import { log as log4, logInfo } from "@dxos/log";
|
|
508
620
|
import { trace as trace2 } from "@dxos/protocols";
|
|
509
621
|
import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
|
|
510
622
|
|
|
511
623
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
512
|
-
import invariant3 from "tiny-invariant";
|
|
513
624
|
import { scheduleTask, synchronized as synchronized2 } from "@dxos/async";
|
|
514
625
|
import { Context as Context3 } from "@dxos/context";
|
|
515
626
|
import { CancelledError as CancelledError2 } from "@dxos/errors";
|
|
627
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
516
628
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
517
629
|
import { log as log3 } from "@dxos/log";
|
|
518
630
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
@@ -558,7 +670,7 @@ var Peer = class {
|
|
|
558
670
|
sessionId: (_a = this.connection) == null ? void 0 : _a.sessionId
|
|
559
671
|
}, {
|
|
560
672
|
F: __dxlog_file3,
|
|
561
|
-
L:
|
|
673
|
+
L: 106,
|
|
562
674
|
S: this,
|
|
563
675
|
C: (f, a) => f(...a)
|
|
564
676
|
});
|
|
@@ -573,7 +685,15 @@ var Peer = class {
|
|
|
573
685
|
}
|
|
574
686
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
575
687
|
if (!this.connection) {
|
|
576
|
-
invariant3(message.sessionId
|
|
688
|
+
invariant3(message.sessionId, void 0, {
|
|
689
|
+
F: __dxlog_file3,
|
|
690
|
+
L: 126,
|
|
691
|
+
S: this,
|
|
692
|
+
A: [
|
|
693
|
+
"message.sessionId",
|
|
694
|
+
""
|
|
695
|
+
]
|
|
696
|
+
});
|
|
577
697
|
const connection = this._createConnection(false, message.sessionId);
|
|
578
698
|
try {
|
|
579
699
|
await this._connectionLimiter.connecting(message.sessionId);
|
|
@@ -587,7 +707,7 @@ var Peer = class {
|
|
|
587
707
|
err
|
|
588
708
|
}, {
|
|
589
709
|
F: __dxlog_file3,
|
|
590
|
-
L:
|
|
710
|
+
L: 134,
|
|
591
711
|
S: this,
|
|
592
712
|
C: (f, a) => f(...a)
|
|
593
713
|
});
|
|
@@ -607,8 +727,24 @@ var Peer = class {
|
|
|
607
727
|
* Initiate a connection to the remote peer.
|
|
608
728
|
*/
|
|
609
729
|
async initiateConnection() {
|
|
610
|
-
invariant3(!this.initiating, "Initiation in progress."
|
|
611
|
-
|
|
730
|
+
invariant3(!this.initiating, "Initiation in progress.", {
|
|
731
|
+
F: __dxlog_file3,
|
|
732
|
+
L: 151,
|
|
733
|
+
S: this,
|
|
734
|
+
A: [
|
|
735
|
+
"!this.initiating",
|
|
736
|
+
"'Initiation in progress.'"
|
|
737
|
+
]
|
|
738
|
+
});
|
|
739
|
+
invariant3(!this.connection, "Already connected.", {
|
|
740
|
+
F: __dxlog_file3,
|
|
741
|
+
L: 152,
|
|
742
|
+
S: this,
|
|
743
|
+
A: [
|
|
744
|
+
"!this.connection",
|
|
745
|
+
"'Already connected.'"
|
|
746
|
+
]
|
|
747
|
+
});
|
|
612
748
|
const sessionId = PublicKey3.random();
|
|
613
749
|
log3("initiating...", {
|
|
614
750
|
id: this.id,
|
|
@@ -617,7 +753,7 @@ var Peer = class {
|
|
|
617
753
|
sessionId
|
|
618
754
|
}, {
|
|
619
755
|
F: __dxlog_file3,
|
|
620
|
-
L:
|
|
756
|
+
L: 154,
|
|
621
757
|
S: this,
|
|
622
758
|
C: (f, a) => f(...a)
|
|
623
759
|
});
|
|
@@ -641,14 +777,14 @@ var Peer = class {
|
|
|
641
777
|
remoteId: this.id
|
|
642
778
|
}, {
|
|
643
779
|
F: __dxlog_file3,
|
|
644
|
-
L:
|
|
780
|
+
L: 169,
|
|
645
781
|
S: this,
|
|
646
782
|
C: (f, a) => f(...a)
|
|
647
783
|
});
|
|
648
784
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
649
785
|
log3("ignoring response", void 0, {
|
|
650
786
|
F: __dxlog_file3,
|
|
651
|
-
L:
|
|
787
|
+
L: 171,
|
|
652
788
|
S: this,
|
|
653
789
|
C: (f, a) => f(...a)
|
|
654
790
|
});
|
|
@@ -668,7 +804,7 @@ var Peer = class {
|
|
|
668
804
|
remoteId: this.id
|
|
669
805
|
}, {
|
|
670
806
|
F: __dxlog_file3,
|
|
671
|
-
L:
|
|
807
|
+
L: 182,
|
|
672
808
|
S: this,
|
|
673
809
|
C: (f, a) => f(...a)
|
|
674
810
|
});
|
|
@@ -692,11 +828,19 @@ var Peer = class {
|
|
|
692
828
|
sessionId
|
|
693
829
|
}, {
|
|
694
830
|
F: __dxlog_file3,
|
|
695
|
-
L:
|
|
831
|
+
L: 196,
|
|
696
832
|
S: this,
|
|
697
833
|
C: (f, a) => f(...a)
|
|
698
834
|
});
|
|
699
|
-
invariant3(!this.connection, "Already connected."
|
|
835
|
+
invariant3(!this.connection, "Already connected.", {
|
|
836
|
+
F: __dxlog_file3,
|
|
837
|
+
L: 203,
|
|
838
|
+
S: this,
|
|
839
|
+
A: [
|
|
840
|
+
"!this.connection",
|
|
841
|
+
"'Already connected.'"
|
|
842
|
+
]
|
|
843
|
+
});
|
|
700
844
|
const connection = new Connection(
|
|
701
845
|
this.topic,
|
|
702
846
|
this.localPeerId,
|
|
@@ -733,11 +877,19 @@ var Peer = class {
|
|
|
733
877
|
initiator
|
|
734
878
|
}, {
|
|
735
879
|
F: __dxlog_file3,
|
|
736
|
-
L:
|
|
880
|
+
L: 233,
|
|
737
881
|
S: this,
|
|
738
882
|
C: (f, a) => f(...a)
|
|
739
883
|
});
|
|
740
|
-
invariant3(this.connection === connection, "Connection mismatch (race condition)."
|
|
884
|
+
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
885
|
+
F: __dxlog_file3,
|
|
886
|
+
L: 234,
|
|
887
|
+
S: this,
|
|
888
|
+
A: [
|
|
889
|
+
"this.connection === connection",
|
|
890
|
+
"'Connection mismatch (race condition).'"
|
|
891
|
+
]
|
|
892
|
+
});
|
|
741
893
|
if (this._lastConnectionTime && this._lastConnectionTime + CONNECTION_COUNTS_STABLE_AFTER < Date.now()) {
|
|
742
894
|
this._availableAfter = 0;
|
|
743
895
|
} else {
|
|
@@ -764,7 +916,7 @@ var Peer = class {
|
|
|
764
916
|
err
|
|
765
917
|
}, {
|
|
766
918
|
F: __dxlog_file3,
|
|
767
|
-
L:
|
|
919
|
+
L: 262,
|
|
768
920
|
S: this,
|
|
769
921
|
C: (f, a) => f(...a)
|
|
770
922
|
});
|
|
@@ -783,7 +935,7 @@ var Peer = class {
|
|
|
783
935
|
sessionId: connection.sessionId
|
|
784
936
|
}, {
|
|
785
937
|
F: __dxlog_file3,
|
|
786
|
-
L:
|
|
938
|
+
L: 278,
|
|
787
939
|
S: this,
|
|
788
940
|
C: (f, a) => f(...a)
|
|
789
941
|
});
|
|
@@ -793,7 +945,7 @@ var Peer = class {
|
|
|
793
945
|
sessionId: connection.sessionId
|
|
794
946
|
}, {
|
|
795
947
|
F: __dxlog_file3,
|
|
796
|
-
L:
|
|
948
|
+
L: 284,
|
|
797
949
|
S: this,
|
|
798
950
|
C: (f, a) => f(...a)
|
|
799
951
|
});
|
|
@@ -804,7 +956,7 @@ var Peer = class {
|
|
|
804
956
|
message
|
|
805
957
|
}, {
|
|
806
958
|
F: __dxlog_file3,
|
|
807
|
-
L:
|
|
959
|
+
L: 289,
|
|
808
960
|
S: this,
|
|
809
961
|
C: (f, a) => f(...a)
|
|
810
962
|
});
|
|
@@ -820,7 +972,7 @@ var Peer = class {
|
|
|
820
972
|
topic: this.topic
|
|
821
973
|
}, {
|
|
822
974
|
F: __dxlog_file3,
|
|
823
|
-
L:
|
|
975
|
+
L: 299,
|
|
824
976
|
S: this,
|
|
825
977
|
C: (f, a) => f(...a)
|
|
826
978
|
});
|
|
@@ -885,7 +1037,7 @@ var Swarm = class {
|
|
|
885
1037
|
}
|
|
886
1038
|
}), {
|
|
887
1039
|
F: __dxlog_file4,
|
|
888
|
-
L:
|
|
1040
|
+
L: 87,
|
|
889
1041
|
S: this,
|
|
890
1042
|
C: (f, a) => f(...a)
|
|
891
1043
|
});
|
|
@@ -893,7 +1045,7 @@ var Swarm = class {
|
|
|
893
1045
|
peerId: _ownPeerId
|
|
894
1046
|
}, {
|
|
895
1047
|
F: __dxlog_file4,
|
|
896
|
-
L:
|
|
1048
|
+
L: 91,
|
|
897
1049
|
S: this,
|
|
898
1050
|
C: (f, a) => f(...a)
|
|
899
1051
|
});
|
|
@@ -908,7 +1060,7 @@ var Swarm = class {
|
|
|
908
1060
|
id: this._instanceId
|
|
909
1061
|
}), {
|
|
910
1062
|
F: __dxlog_file4,
|
|
911
|
-
L:
|
|
1063
|
+
L: 100,
|
|
912
1064
|
S: this,
|
|
913
1065
|
C: (f, a) => f(...a)
|
|
914
1066
|
});
|
|
@@ -929,7 +1081,15 @@ var Swarm = class {
|
|
|
929
1081
|
return this._topic;
|
|
930
1082
|
}
|
|
931
1083
|
async open() {
|
|
932
|
-
invariant4(!this._listeningHandle
|
|
1084
|
+
invariant4(!this._listeningHandle, void 0, {
|
|
1085
|
+
F: __dxlog_file4,
|
|
1086
|
+
L: 127,
|
|
1087
|
+
S: this,
|
|
1088
|
+
A: [
|
|
1089
|
+
"!this._listeningHandle",
|
|
1090
|
+
""
|
|
1091
|
+
]
|
|
1092
|
+
});
|
|
933
1093
|
this._listeningHandle = await this._messenger.listen({
|
|
934
1094
|
peerId: this._ownPeerId,
|
|
935
1095
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
@@ -938,7 +1098,7 @@ var Swarm = class {
|
|
|
938
1098
|
err
|
|
939
1099
|
}, {
|
|
940
1100
|
F: __dxlog_file4,
|
|
941
|
-
L:
|
|
1101
|
+
L: 134,
|
|
942
1102
|
S: this,
|
|
943
1103
|
C: (f, a) => f(...a)
|
|
944
1104
|
}));
|
|
@@ -949,7 +1109,7 @@ var Swarm = class {
|
|
|
949
1109
|
var _a;
|
|
950
1110
|
log4("destroying...", void 0, {
|
|
951
1111
|
F: __dxlog_file4,
|
|
952
|
-
L:
|
|
1112
|
+
L: 140,
|
|
953
1113
|
S: this,
|
|
954
1114
|
C: (f, a) => f(...a)
|
|
955
1115
|
});
|
|
@@ -960,13 +1120,21 @@ var Swarm = class {
|
|
|
960
1120
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
961
1121
|
log4("destroyed", void 0, {
|
|
962
1122
|
F: __dxlog_file4,
|
|
963
|
-
L:
|
|
1123
|
+
L: 147,
|
|
964
1124
|
S: this,
|
|
965
1125
|
C: (f, a) => f(...a)
|
|
966
1126
|
});
|
|
967
1127
|
}
|
|
968
1128
|
async setTopology(topology) {
|
|
969
|
-
invariant4(!this._ctx.disposed, "Swarm is offline"
|
|
1129
|
+
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1130
|
+
F: __dxlog_file4,
|
|
1131
|
+
L: 151,
|
|
1132
|
+
S: this,
|
|
1133
|
+
A: [
|
|
1134
|
+
"!this._ctx.disposed",
|
|
1135
|
+
"'Swarm is offline'"
|
|
1136
|
+
]
|
|
1137
|
+
});
|
|
970
1138
|
if (topology === this._topology) {
|
|
971
1139
|
return;
|
|
972
1140
|
}
|
|
@@ -975,7 +1143,7 @@ var Swarm = class {
|
|
|
975
1143
|
topology: getClassName(topology)
|
|
976
1144
|
}, {
|
|
977
1145
|
F: __dxlog_file4,
|
|
978
|
-
L:
|
|
1146
|
+
L: 155,
|
|
979
1147
|
S: this,
|
|
980
1148
|
C: (f, a) => f(...a)
|
|
981
1149
|
});
|
|
@@ -990,14 +1158,14 @@ var Swarm = class {
|
|
|
990
1158
|
swarmEvent
|
|
991
1159
|
}, {
|
|
992
1160
|
F: __dxlog_file4,
|
|
993
|
-
L:
|
|
1161
|
+
L: 168,
|
|
994
1162
|
S: this,
|
|
995
1163
|
C: (f, a) => f(...a)
|
|
996
1164
|
});
|
|
997
1165
|
if (this._ctx.disposed) {
|
|
998
1166
|
log4("swarm event ignored for disposed swarm", void 0, {
|
|
999
1167
|
F: __dxlog_file4,
|
|
1000
|
-
L:
|
|
1168
|
+
L: 171,
|
|
1001
1169
|
S: this,
|
|
1002
1170
|
C: (f, a) => f(...a)
|
|
1003
1171
|
});
|
|
@@ -1009,7 +1177,7 @@ var Swarm = class {
|
|
|
1009
1177
|
peerId
|
|
1010
1178
|
}, {
|
|
1011
1179
|
F: __dxlog_file4,
|
|
1012
|
-
L:
|
|
1180
|
+
L: 177,
|
|
1013
1181
|
S: this,
|
|
1014
1182
|
C: (f, a) => f(...a)
|
|
1015
1183
|
});
|
|
@@ -1024,7 +1192,7 @@ var Swarm = class {
|
|
|
1024
1192
|
if (((_a = peer.connection) == null ? void 0 : _a.state) !== ConnectionState.CONNECTED) {
|
|
1025
1193
|
void this._destroyPeer(peer.id).catch((err) => log4.catch(err, void 0, {
|
|
1026
1194
|
F: __dxlog_file4,
|
|
1027
|
-
L:
|
|
1195
|
+
L: 188,
|
|
1028
1196
|
S: this,
|
|
1029
1197
|
C: (f, a) => f(...a)
|
|
1030
1198
|
}));
|
|
@@ -1039,14 +1207,14 @@ var Swarm = class {
|
|
|
1039
1207
|
message
|
|
1040
1208
|
}, {
|
|
1041
1209
|
F: __dxlog_file4,
|
|
1042
|
-
L:
|
|
1210
|
+
L: 198,
|
|
1043
1211
|
S: this,
|
|
1044
1212
|
C: (f, a) => f(...a)
|
|
1045
1213
|
});
|
|
1046
1214
|
if (this._ctx.disposed) {
|
|
1047
1215
|
log4("ignored for disposed swarm", void 0, {
|
|
1048
1216
|
F: __dxlog_file4,
|
|
1049
|
-
L:
|
|
1217
|
+
L: 200,
|
|
1050
1218
|
S: this,
|
|
1051
1219
|
C: (f, a) => f(...a)
|
|
1052
1220
|
});
|
|
@@ -1054,13 +1222,21 @@ var Swarm = class {
|
|
|
1054
1222
|
accept: false
|
|
1055
1223
|
};
|
|
1056
1224
|
}
|
|
1057
|
-
invariant4(message.author
|
|
1225
|
+
invariant4(message.author, void 0, {
|
|
1226
|
+
F: __dxlog_file4,
|
|
1227
|
+
L: 205,
|
|
1228
|
+
S: this,
|
|
1229
|
+
A: [
|
|
1230
|
+
"message.author",
|
|
1231
|
+
""
|
|
1232
|
+
]
|
|
1233
|
+
});
|
|
1058
1234
|
if (!((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId))) {
|
|
1059
1235
|
log4("rejecting offer with incorrect peerId", {
|
|
1060
1236
|
message
|
|
1061
1237
|
}, {
|
|
1062
1238
|
F: __dxlog_file4,
|
|
1063
|
-
L:
|
|
1239
|
+
L: 207,
|
|
1064
1240
|
S: this,
|
|
1065
1241
|
C: (f, a) => f(...a)
|
|
1066
1242
|
});
|
|
@@ -1073,7 +1249,7 @@ var Swarm = class {
|
|
|
1073
1249
|
message
|
|
1074
1250
|
}, {
|
|
1075
1251
|
F: __dxlog_file4,
|
|
1076
|
-
L:
|
|
1252
|
+
L: 211,
|
|
1077
1253
|
S: this,
|
|
1078
1254
|
C: (f, a) => f(...a)
|
|
1079
1255
|
});
|
|
@@ -1092,22 +1268,46 @@ var Swarm = class {
|
|
|
1092
1268
|
message
|
|
1093
1269
|
}, {
|
|
1094
1270
|
F: __dxlog_file4,
|
|
1095
|
-
L:
|
|
1271
|
+
L: 222,
|
|
1096
1272
|
S: this,
|
|
1097
1273
|
C: (f, a) => f(...a)
|
|
1098
1274
|
});
|
|
1099
1275
|
if (this._ctx.disposed) {
|
|
1100
1276
|
log4.info("ignored for offline swarm", void 0, {
|
|
1101
1277
|
F: __dxlog_file4,
|
|
1102
|
-
L:
|
|
1278
|
+
L: 224,
|
|
1103
1279
|
S: this,
|
|
1104
1280
|
C: (f, a) => f(...a)
|
|
1105
1281
|
});
|
|
1106
1282
|
return;
|
|
1107
1283
|
}
|
|
1108
|
-
invariant4((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}
|
|
1109
|
-
|
|
1110
|
-
|
|
1284
|
+
invariant4((_a = message.recipient) == null ? void 0 : _a.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1285
|
+
F: __dxlog_file4,
|
|
1286
|
+
L: 227,
|
|
1287
|
+
S: this,
|
|
1288
|
+
A: [
|
|
1289
|
+
"message.recipient?.equals(this._ownPeerId)",
|
|
1290
|
+
"`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
|
|
1291
|
+
]
|
|
1292
|
+
});
|
|
1293
|
+
invariant4((_b = message.topic) == null ? void 0 : _b.equals(this._topic), void 0, {
|
|
1294
|
+
F: __dxlog_file4,
|
|
1295
|
+
L: 231,
|
|
1296
|
+
S: this,
|
|
1297
|
+
A: [
|
|
1298
|
+
"message.topic?.equals(this._topic)",
|
|
1299
|
+
""
|
|
1300
|
+
]
|
|
1301
|
+
});
|
|
1302
|
+
invariant4(message.author, void 0, {
|
|
1303
|
+
F: __dxlog_file4,
|
|
1304
|
+
L: 232,
|
|
1305
|
+
S: this,
|
|
1306
|
+
A: [
|
|
1307
|
+
"message.author",
|
|
1308
|
+
""
|
|
1309
|
+
]
|
|
1310
|
+
});
|
|
1111
1311
|
const peer = this._getOrCreatePeer(message.author);
|
|
1112
1312
|
await peer.onSignal(message);
|
|
1113
1313
|
}
|
|
@@ -1159,7 +1359,15 @@ var Swarm = class {
|
|
|
1159
1359
|
return peer;
|
|
1160
1360
|
}
|
|
1161
1361
|
async _destroyPeer(peerId) {
|
|
1162
|
-
invariant4(this._peers.has(peerId)
|
|
1362
|
+
invariant4(this._peers.has(peerId), void 0, {
|
|
1363
|
+
F: __dxlog_file4,
|
|
1364
|
+
L: 302,
|
|
1365
|
+
S: this,
|
|
1366
|
+
A: [
|
|
1367
|
+
"this._peers.has(peerId)",
|
|
1368
|
+
""
|
|
1369
|
+
]
|
|
1370
|
+
});
|
|
1163
1371
|
await this._peers.get(peerId).destroy();
|
|
1164
1372
|
this._peers.delete(peerId);
|
|
1165
1373
|
}
|
|
@@ -1180,7 +1388,7 @@ var Swarm = class {
|
|
|
1180
1388
|
} catch (err) {
|
|
1181
1389
|
log4("initiation error", err, {
|
|
1182
1390
|
F: __dxlog_file4,
|
|
1183
|
-
L:
|
|
1391
|
+
L: 328,
|
|
1184
1392
|
S: this,
|
|
1185
1393
|
C: (f, a) => f(...a)
|
|
1186
1394
|
});
|
|
@@ -1208,7 +1416,7 @@ var Swarm = class {
|
|
|
1208
1416
|
remoteId
|
|
1209
1417
|
}, {
|
|
1210
1418
|
F: __dxlog_file4,
|
|
1211
|
-
L:
|
|
1419
|
+
L: 355,
|
|
1212
1420
|
S: this,
|
|
1213
1421
|
C: (f, a) => f(...a)
|
|
1214
1422
|
});
|
|
@@ -1225,7 +1433,7 @@ var Swarm = class {
|
|
|
1225
1433
|
remoteId
|
|
1226
1434
|
}, {
|
|
1227
1435
|
F: __dxlog_file4,
|
|
1228
|
-
L:
|
|
1436
|
+
L: 369,
|
|
1229
1437
|
S: this,
|
|
1230
1438
|
C: (f, a) => f(...a)
|
|
1231
1439
|
});
|
|
@@ -1235,7 +1443,7 @@ var Swarm = class {
|
|
|
1235
1443
|
remoteId
|
|
1236
1444
|
}, {
|
|
1237
1445
|
F: __dxlog_file4,
|
|
1238
|
-
L:
|
|
1446
|
+
L: 372,
|
|
1239
1447
|
S: this,
|
|
1240
1448
|
C: (f, a) => f(...a)
|
|
1241
1449
|
});
|
|
@@ -1345,8 +1553,9 @@ var SwarmMapper = class {
|
|
|
1345
1553
|
import { DeferredTask as DeferredTask2 } from "@dxos/async";
|
|
1346
1554
|
import { Context as Context5 } from "@dxos/context";
|
|
1347
1555
|
import { CancelledError as CancelledError3 } from "@dxos/errors";
|
|
1556
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1348
1557
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
1349
|
-
import {
|
|
1558
|
+
import { log as log6 } from "@dxos/log";
|
|
1350
1559
|
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
1351
1560
|
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
1352
1561
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 3;
|
|
@@ -1370,7 +1579,7 @@ var ConnectionLimiter = class {
|
|
|
1370
1579
|
async connecting(sessionId) {
|
|
1371
1580
|
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
1372
1581
|
F: __dxlog_file6,
|
|
1373
|
-
L:
|
|
1582
|
+
L: 48,
|
|
1374
1583
|
S: this,
|
|
1375
1584
|
A: [
|
|
1376
1585
|
"!this._waitingPromises.has(sessionId)",
|
|
@@ -1381,7 +1590,7 @@ var ConnectionLimiter = class {
|
|
|
1381
1590
|
sessionId
|
|
1382
1591
|
}, {
|
|
1383
1592
|
F: __dxlog_file6,
|
|
1384
|
-
L:
|
|
1593
|
+
L: 49,
|
|
1385
1594
|
S: this,
|
|
1386
1595
|
C: (f, a) => f(...a)
|
|
1387
1596
|
});
|
|
@@ -1396,7 +1605,7 @@ var ConnectionLimiter = class {
|
|
|
1396
1605
|
sessionId
|
|
1397
1606
|
}, {
|
|
1398
1607
|
F: __dxlog_file6,
|
|
1399
|
-
L:
|
|
1608
|
+
L: 57,
|
|
1400
1609
|
S: this,
|
|
1401
1610
|
C: (f, a) => f(...a)
|
|
1402
1611
|
});
|
|
@@ -1409,7 +1618,7 @@ var ConnectionLimiter = class {
|
|
|
1409
1618
|
sessionId
|
|
1410
1619
|
}, {
|
|
1411
1620
|
F: __dxlog_file6,
|
|
1412
|
-
L:
|
|
1621
|
+
L: 64,
|
|
1413
1622
|
S: this,
|
|
1414
1623
|
C: (f, a) => f(...a)
|
|
1415
1624
|
});
|
|
@@ -1493,8 +1702,8 @@ var ConnectionLog = class {
|
|
|
1493
1702
|
};
|
|
1494
1703
|
|
|
1495
1704
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
1496
|
-
import invariant6 from "tiny-invariant";
|
|
1497
1705
|
import { Event as Event5 } from "@dxos/async";
|
|
1706
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1498
1707
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
1499
1708
|
import { log as log7 } from "@dxos/log";
|
|
1500
1709
|
import { Messenger } from "@dxos/messaging";
|
|
@@ -1553,7 +1762,7 @@ var NetworkManager = class {
|
|
|
1553
1762
|
id: this._instanceId
|
|
1554
1763
|
}), {
|
|
1555
1764
|
F: __dxlog_file7,
|
|
1556
|
-
L:
|
|
1765
|
+
L: 130,
|
|
1557
1766
|
S: this,
|
|
1558
1767
|
C: (f, a) => f(...a)
|
|
1559
1768
|
});
|
|
@@ -1563,7 +1772,7 @@ var NetworkManager = class {
|
|
|
1563
1772
|
id: this._instanceId
|
|
1564
1773
|
}), {
|
|
1565
1774
|
F: __dxlog_file7,
|
|
1566
|
-
L:
|
|
1775
|
+
L: 133,
|
|
1567
1776
|
S: this,
|
|
1568
1777
|
C: (f, a) => f(...a)
|
|
1569
1778
|
});
|
|
@@ -1573,7 +1782,7 @@ var NetworkManager = class {
|
|
|
1573
1782
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1574
1783
|
log7(err, void 0, {
|
|
1575
1784
|
F: __dxlog_file7,
|
|
1576
|
-
L:
|
|
1785
|
+
L: 139,
|
|
1577
1786
|
S: this,
|
|
1578
1787
|
C: (f, a) => f(...a)
|
|
1579
1788
|
});
|
|
@@ -1587,10 +1796,42 @@ var NetworkManager = class {
|
|
|
1587
1796
|
*/
|
|
1588
1797
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1589
1798
|
var _a;
|
|
1590
|
-
invariant6(PublicKey8.isPublicKey(topic)
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1799
|
+
invariant6(PublicKey8.isPublicKey(topic), void 0, {
|
|
1800
|
+
F: __dxlog_file7,
|
|
1801
|
+
L: 157,
|
|
1802
|
+
S: this,
|
|
1803
|
+
A: [
|
|
1804
|
+
"PublicKey.isPublicKey(topic)",
|
|
1805
|
+
""
|
|
1806
|
+
]
|
|
1807
|
+
});
|
|
1808
|
+
invariant6(PublicKey8.isPublicKey(peerId), void 0, {
|
|
1809
|
+
F: __dxlog_file7,
|
|
1810
|
+
L: 158,
|
|
1811
|
+
S: this,
|
|
1812
|
+
A: [
|
|
1813
|
+
"PublicKey.isPublicKey(peerId)",
|
|
1814
|
+
""
|
|
1815
|
+
]
|
|
1816
|
+
});
|
|
1817
|
+
invariant6(topology, void 0, {
|
|
1818
|
+
F: __dxlog_file7,
|
|
1819
|
+
L: 159,
|
|
1820
|
+
S: this,
|
|
1821
|
+
A: [
|
|
1822
|
+
"topology",
|
|
1823
|
+
""
|
|
1824
|
+
]
|
|
1825
|
+
});
|
|
1826
|
+
invariant6(typeof protocol === "function", void 0, {
|
|
1827
|
+
F: __dxlog_file7,
|
|
1828
|
+
L: 160,
|
|
1829
|
+
S: this,
|
|
1830
|
+
A: [
|
|
1831
|
+
"typeof protocol === 'function'",
|
|
1832
|
+
""
|
|
1833
|
+
]
|
|
1834
|
+
});
|
|
1594
1835
|
if (this._swarms.has(topic)) {
|
|
1595
1836
|
throw new Error(`Already connected to swarm: ${PublicKey8.from(topic)}`);
|
|
1596
1837
|
}
|
|
@@ -1600,7 +1841,7 @@ var NetworkManager = class {
|
|
|
1600
1841
|
topology: topology.toString()
|
|
1601
1842
|
}, {
|
|
1602
1843
|
F: __dxlog_file7,
|
|
1603
|
-
L:
|
|
1844
|
+
L: 165,
|
|
1604
1845
|
S: this,
|
|
1605
1846
|
C: (f, a) => f(...a)
|
|
1606
1847
|
});
|
|
@@ -1610,7 +1851,7 @@ var NetworkManager = class {
|
|
|
1610
1851
|
error
|
|
1611
1852
|
}, {
|
|
1612
1853
|
F: __dxlog_file7,
|
|
1613
|
-
L:
|
|
1854
|
+
L: 178,
|
|
1614
1855
|
S: this,
|
|
1615
1856
|
C: (f, a) => f(...a)
|
|
1616
1857
|
});
|
|
@@ -1623,7 +1864,7 @@ var NetworkManager = class {
|
|
|
1623
1864
|
peerId
|
|
1624
1865
|
}).catch((error) => log7.catch(error, void 0, {
|
|
1625
1866
|
F: __dxlog_file7,
|
|
1626
|
-
L:
|
|
1867
|
+
L: 187,
|
|
1627
1868
|
S: this,
|
|
1628
1869
|
C: (f, a) => f(...a)
|
|
1629
1870
|
}));
|
|
@@ -1634,7 +1875,7 @@ var NetworkManager = class {
|
|
|
1634
1875
|
count: this._swarms.size
|
|
1635
1876
|
}, {
|
|
1636
1877
|
F: __dxlog_file7,
|
|
1637
|
-
L:
|
|
1878
|
+
L: 191,
|
|
1638
1879
|
S: this,
|
|
1639
1880
|
C: (f, a) => f(...a)
|
|
1640
1881
|
});
|
|
@@ -1654,7 +1895,7 @@ var NetworkManager = class {
|
|
|
1654
1895
|
topic: PublicKey8.from(topic)
|
|
1655
1896
|
}, {
|
|
1656
1897
|
F: __dxlog_file7,
|
|
1657
|
-
L:
|
|
1898
|
+
L: 207,
|
|
1658
1899
|
S: this,
|
|
1659
1900
|
C: (f, a) => f(...a)
|
|
1660
1901
|
});
|
|
@@ -1675,7 +1916,7 @@ var NetworkManager = class {
|
|
|
1675
1916
|
count: this._swarms.size
|
|
1676
1917
|
}, {
|
|
1677
1918
|
F: __dxlog_file7,
|
|
1678
|
-
L:
|
|
1919
|
+
L: 221,
|
|
1679
1920
|
S: this,
|
|
1680
1921
|
C: (f, a) => f(...a)
|
|
1681
1922
|
});
|
|
@@ -1709,17 +1950,34 @@ var NetworkManager = class {
|
|
|
1709
1950
|
};
|
|
1710
1951
|
|
|
1711
1952
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1712
|
-
import invariant7 from "
|
|
1953
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
1954
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
1713
1955
|
var FullyConnectedTopology = class {
|
|
1714
1956
|
toString() {
|
|
1715
1957
|
return "FullyConnectedTopology";
|
|
1716
1958
|
}
|
|
1717
1959
|
init(controller) {
|
|
1718
|
-
invariant7(!this._controller, "Already initialized"
|
|
1960
|
+
invariant7(!this._controller, "Already initialized", {
|
|
1961
|
+
F: __dxlog_file8,
|
|
1962
|
+
L: 18,
|
|
1963
|
+
S: this,
|
|
1964
|
+
A: [
|
|
1965
|
+
"!this._controller",
|
|
1966
|
+
"'Already initialized'"
|
|
1967
|
+
]
|
|
1968
|
+
});
|
|
1719
1969
|
this._controller = controller;
|
|
1720
1970
|
}
|
|
1721
1971
|
update() {
|
|
1722
|
-
invariant7(this._controller, "Not initialized"
|
|
1972
|
+
invariant7(this._controller, "Not initialized", {
|
|
1973
|
+
F: __dxlog_file8,
|
|
1974
|
+
L: 23,
|
|
1975
|
+
S: this,
|
|
1976
|
+
A: [
|
|
1977
|
+
"this._controller",
|
|
1978
|
+
"'Not initialized'"
|
|
1979
|
+
]
|
|
1980
|
+
});
|
|
1723
1981
|
const { candidates: discovered } = this._controller.getState();
|
|
1724
1982
|
for (const peer of discovered) {
|
|
1725
1983
|
this._controller.connect(peer);
|
|
@@ -1733,10 +1991,10 @@ var FullyConnectedTopology = class {
|
|
|
1733
1991
|
};
|
|
1734
1992
|
|
|
1735
1993
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1736
|
-
import invariant8 from "tiny-invariant";
|
|
1737
1994
|
import distance from "xor-distance";
|
|
1995
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
1738
1996
|
import { log as log8 } from "@dxos/log";
|
|
1739
|
-
var
|
|
1997
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
1740
1998
|
var MMSTTopology = class {
|
|
1741
1999
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
1742
2000
|
this._sampleCollected = false;
|
|
@@ -1745,15 +2003,31 @@ var MMSTTopology = class {
|
|
|
1745
2003
|
this._sampleSize = sampleSize;
|
|
1746
2004
|
}
|
|
1747
2005
|
init(controller) {
|
|
1748
|
-
invariant8(!this._controller, "Already initialized"
|
|
2006
|
+
invariant8(!this._controller, "Already initialized", {
|
|
2007
|
+
F: __dxlog_file9,
|
|
2008
|
+
L: 46,
|
|
2009
|
+
S: this,
|
|
2010
|
+
A: [
|
|
2011
|
+
"!this._controller",
|
|
2012
|
+
"'Already initialized'"
|
|
2013
|
+
]
|
|
2014
|
+
});
|
|
1749
2015
|
this._controller = controller;
|
|
1750
2016
|
}
|
|
1751
2017
|
update() {
|
|
1752
|
-
invariant8(this._controller, "Not initialized"
|
|
2018
|
+
invariant8(this._controller, "Not initialized", {
|
|
2019
|
+
F: __dxlog_file9,
|
|
2020
|
+
L: 51,
|
|
2021
|
+
S: this,
|
|
2022
|
+
A: [
|
|
2023
|
+
"this._controller",
|
|
2024
|
+
"'Not initialized'"
|
|
2025
|
+
]
|
|
2026
|
+
});
|
|
1753
2027
|
const { connected, candidates } = this._controller.getState();
|
|
1754
2028
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
1755
2029
|
log8("Running the algorithm.", void 0, {
|
|
1756
|
-
F:
|
|
2030
|
+
F: __dxlog_file9,
|
|
1757
2031
|
L: 55,
|
|
1758
2032
|
S: this,
|
|
1759
2033
|
C: (f, a) => f(...a)
|
|
@@ -1763,11 +2037,19 @@ var MMSTTopology = class {
|
|
|
1763
2037
|
}
|
|
1764
2038
|
}
|
|
1765
2039
|
async onOffer(peer) {
|
|
1766
|
-
invariant8(this._controller, "Not initialized"
|
|
2040
|
+
invariant8(this._controller, "Not initialized", {
|
|
2041
|
+
F: __dxlog_file9,
|
|
2042
|
+
L: 62,
|
|
2043
|
+
S: this,
|
|
2044
|
+
A: [
|
|
2045
|
+
"this._controller",
|
|
2046
|
+
"'Not initialized'"
|
|
2047
|
+
]
|
|
2048
|
+
});
|
|
1767
2049
|
const { connected } = this._controller.getState();
|
|
1768
2050
|
const accept = connected.length < this._maxPeers;
|
|
1769
2051
|
log8(`Offer ${peer} accept=${accept}`, void 0, {
|
|
1770
|
-
F:
|
|
2052
|
+
F: __dxlog_file9,
|
|
1771
2053
|
L: 65,
|
|
1772
2054
|
S: this,
|
|
1773
2055
|
C: (f, a) => f(...a)
|
|
@@ -1777,13 +2059,21 @@ var MMSTTopology = class {
|
|
|
1777
2059
|
async destroy() {
|
|
1778
2060
|
}
|
|
1779
2061
|
_runAlgorithm() {
|
|
1780
|
-
invariant8(this._controller, "Not initialized"
|
|
2062
|
+
invariant8(this._controller, "Not initialized", {
|
|
2063
|
+
F: __dxlog_file9,
|
|
2064
|
+
L: 74,
|
|
2065
|
+
S: this,
|
|
2066
|
+
A: [
|
|
2067
|
+
"this._controller",
|
|
2068
|
+
"'Not initialized'"
|
|
2069
|
+
]
|
|
2070
|
+
});
|
|
1781
2071
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
1782
2072
|
if (connected.length > this._maxPeers) {
|
|
1783
2073
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
1784
2074
|
for (const peer of sorted) {
|
|
1785
2075
|
log8(`Disconnect ${peer}.`, void 0, {
|
|
1786
|
-
F:
|
|
2076
|
+
F: __dxlog_file9,
|
|
1787
2077
|
L: 83,
|
|
1788
2078
|
S: this,
|
|
1789
2079
|
C: (f, a) => f(...a)
|
|
@@ -1795,7 +2085,7 @@ var MMSTTopology = class {
|
|
|
1795
2085
|
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
1796
2086
|
for (const peer of sorted) {
|
|
1797
2087
|
log8(`Connect ${peer}.`, void 0, {
|
|
1798
|
-
F:
|
|
2088
|
+
F: __dxlog_file9,
|
|
1799
2089
|
L: 91,
|
|
1800
2090
|
S: this,
|
|
1801
2091
|
C: (f, a) => f(...a)
|
|
@@ -1811,9 +2101,9 @@ var MMSTTopology = class {
|
|
|
1811
2101
|
var sortByXorDistance = (keys, reference) => keys.sort((a, b) => distance.gt(distance(a.asBuffer(), reference.asBuffer()), distance(b.asBuffer(), reference.asBuffer())));
|
|
1812
2102
|
|
|
1813
2103
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1814
|
-
import invariant9 from "
|
|
2104
|
+
import { invariant as invariant9 } from "@dxos/invariant";
|
|
1815
2105
|
import { log as log9 } from "@dxos/log";
|
|
1816
|
-
var
|
|
2106
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
1817
2107
|
var StarTopology = class {
|
|
1818
2108
|
// prettier-ignore
|
|
1819
2109
|
constructor(_centralPeer) {
|
|
@@ -1823,16 +2113,32 @@ var StarTopology = class {
|
|
|
1823
2113
|
return `StarTopology(${this._centralPeer.truncate()})`;
|
|
1824
2114
|
}
|
|
1825
2115
|
init(controller) {
|
|
1826
|
-
invariant9(!this._controller, "Already initialized."
|
|
2116
|
+
invariant9(!this._controller, "Already initialized.", {
|
|
2117
|
+
F: __dxlog_file10,
|
|
2118
|
+
L: 24,
|
|
2119
|
+
S: this,
|
|
2120
|
+
A: [
|
|
2121
|
+
"!this._controller",
|
|
2122
|
+
"'Already initialized.'"
|
|
2123
|
+
]
|
|
2124
|
+
});
|
|
1827
2125
|
this._controller = controller;
|
|
1828
2126
|
}
|
|
1829
2127
|
update() {
|
|
1830
|
-
invariant9(this._controller, "Not initialized."
|
|
2128
|
+
invariant9(this._controller, "Not initialized.", {
|
|
2129
|
+
F: __dxlog_file10,
|
|
2130
|
+
L: 29,
|
|
2131
|
+
S: this,
|
|
2132
|
+
A: [
|
|
2133
|
+
"this._controller",
|
|
2134
|
+
"'Not initialized.'"
|
|
2135
|
+
]
|
|
2136
|
+
});
|
|
1831
2137
|
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
1832
2138
|
if (!ownPeerId.equals(this._centralPeer)) {
|
|
1833
2139
|
log9("leaf peer dropping all connections apart from central peer.", void 0, {
|
|
1834
|
-
F:
|
|
1835
|
-
L:
|
|
2140
|
+
F: __dxlog_file10,
|
|
2141
|
+
L: 32,
|
|
1836
2142
|
S: this,
|
|
1837
2143
|
C: (f, a) => f(...a)
|
|
1838
2144
|
});
|
|
@@ -1841,8 +2147,8 @@ var StarTopology = class {
|
|
|
1841
2147
|
log9("dropping connection", {
|
|
1842
2148
|
peer
|
|
1843
2149
|
}, {
|
|
1844
|
-
F:
|
|
1845
|
-
L:
|
|
2150
|
+
F: __dxlog_file10,
|
|
2151
|
+
L: 37,
|
|
1846
2152
|
S: this,
|
|
1847
2153
|
C: (f, a) => f(...a)
|
|
1848
2154
|
});
|
|
@@ -1855,8 +2161,8 @@ var StarTopology = class {
|
|
|
1855
2161
|
log9("connecting to peer", {
|
|
1856
2162
|
peer
|
|
1857
2163
|
}, {
|
|
1858
|
-
F:
|
|
1859
|
-
L:
|
|
2164
|
+
F: __dxlog_file10,
|
|
2165
|
+
L: 46,
|
|
1860
2166
|
S: this,
|
|
1861
2167
|
C: (f, a) => f(...a)
|
|
1862
2168
|
});
|
|
@@ -1865,15 +2171,23 @@ var StarTopology = class {
|
|
|
1865
2171
|
}
|
|
1866
2172
|
}
|
|
1867
2173
|
async onOffer(peer) {
|
|
1868
|
-
invariant9(this._controller, "Not initialized."
|
|
2174
|
+
invariant9(this._controller, "Not initialized.", {
|
|
2175
|
+
F: __dxlog_file10,
|
|
2176
|
+
L: 53,
|
|
2177
|
+
S: this,
|
|
2178
|
+
A: [
|
|
2179
|
+
"this._controller",
|
|
2180
|
+
"'Not initialized.'"
|
|
2181
|
+
]
|
|
2182
|
+
});
|
|
1869
2183
|
const { ownPeerId } = this._controller.getState();
|
|
1870
2184
|
log9("offer", {
|
|
1871
2185
|
peer,
|
|
1872
2186
|
isCentral: peer.equals(this._centralPeer),
|
|
1873
2187
|
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
1874
2188
|
}, {
|
|
1875
|
-
F:
|
|
1876
|
-
L:
|
|
2189
|
+
F: __dxlog_file10,
|
|
2190
|
+
L: 55,
|
|
1877
2191
|
S: this,
|
|
1878
2192
|
C: (f, a) => f(...a)
|
|
1879
2193
|
});
|
|
@@ -1885,9 +2199,9 @@ var StarTopology = class {
|
|
|
1885
2199
|
|
|
1886
2200
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1887
2201
|
import { Transform } from "@dxos/node-std/stream";
|
|
1888
|
-
import invariant10 from "tiny-invariant";
|
|
1889
2202
|
import { Event as Event6, Trigger } from "@dxos/async";
|
|
1890
2203
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
2204
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
1891
2205
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
1892
2206
|
import { log as log10, logInfo as logInfo2 } from "@dxos/log";
|
|
1893
2207
|
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
@@ -1901,7 +2215,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
1901
2215
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1902
2216
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1903
2217
|
}
|
|
1904
|
-
var
|
|
2218
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
1905
2219
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1906
2220
|
var createStreamDelay = (delay) => {
|
|
1907
2221
|
return new Transform({
|
|
@@ -1927,17 +2241,25 @@ var _MemoryTransport = class {
|
|
|
1927
2241
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1928
2242
|
this._destroyed = false;
|
|
1929
2243
|
log10("creating", void 0, {
|
|
1930
|
-
F:
|
|
2244
|
+
F: __dxlog_file11,
|
|
1931
2245
|
L: 64,
|
|
1932
2246
|
S: this,
|
|
1933
2247
|
C: (f, a) => f(...a)
|
|
1934
2248
|
});
|
|
1935
|
-
invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection"
|
|
2249
|
+
invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2250
|
+
F: __dxlog_file11,
|
|
2251
|
+
L: 66,
|
|
2252
|
+
S: this,
|
|
2253
|
+
A: [
|
|
2254
|
+
"!MemoryTransport._connections.has(this._instanceId)",
|
|
2255
|
+
"'Duplicate memory connection'"
|
|
2256
|
+
]
|
|
2257
|
+
});
|
|
1936
2258
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1937
2259
|
if (this.options.initiator) {
|
|
1938
2260
|
setTimeout(async () => {
|
|
1939
2261
|
log10("sending signal", void 0, {
|
|
1940
|
-
F:
|
|
2262
|
+
F: __dxlog_file11,
|
|
1941
2263
|
L: 73,
|
|
1942
2264
|
S: this,
|
|
1943
2265
|
C: (f, a) => f(...a)
|
|
@@ -1966,11 +2288,19 @@ var _MemoryTransport = class {
|
|
|
1966
2288
|
this.closed.emit();
|
|
1967
2289
|
return;
|
|
1968
2290
|
}
|
|
1969
|
-
invariant10(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}
|
|
2291
|
+
invariant10(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2292
|
+
F: __dxlog_file11,
|
|
2293
|
+
L: 99,
|
|
2294
|
+
S: this,
|
|
2295
|
+
A: [
|
|
2296
|
+
"!this._remoteConnection._remoteConnection",
|
|
2297
|
+
"`Remote already connected: ${this._remoteInstanceId}`"
|
|
2298
|
+
]
|
|
2299
|
+
});
|
|
1970
2300
|
this._remoteConnection._remoteConnection = this;
|
|
1971
2301
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1972
2302
|
log10("connected", void 0, {
|
|
1973
|
-
F:
|
|
2303
|
+
F: __dxlog_file11,
|
|
1974
2304
|
L: 103,
|
|
1975
2305
|
S: this,
|
|
1976
2306
|
C: (f, a) => f(...a)
|
|
@@ -1988,7 +2318,7 @@ var _MemoryTransport = class {
|
|
|
1988
2318
|
}
|
|
1989
2319
|
async destroy() {
|
|
1990
2320
|
log10("closing", void 0, {
|
|
1991
|
-
F:
|
|
2321
|
+
F: __dxlog_file11,
|
|
1992
2322
|
L: 124,
|
|
1993
2323
|
S: this,
|
|
1994
2324
|
C: (f, a) => f(...a)
|
|
@@ -1997,7 +2327,7 @@ var _MemoryTransport = class {
|
|
|
1997
2327
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
1998
2328
|
if (this._remoteConnection) {
|
|
1999
2329
|
log10("closing", void 0, {
|
|
2000
|
-
F:
|
|
2330
|
+
F: __dxlog_file11,
|
|
2001
2331
|
L: 129,
|
|
2002
2332
|
S: this,
|
|
2003
2333
|
C: (f, a) => f(...a)
|
|
@@ -2010,7 +2340,7 @@ var _MemoryTransport = class {
|
|
|
2010
2340
|
this._remoteConnection._remoteConnection = void 0;
|
|
2011
2341
|
this._remoteConnection = void 0;
|
|
2012
2342
|
log10("closed", void 0, {
|
|
2013
|
-
F:
|
|
2343
|
+
F: __dxlog_file11,
|
|
2014
2344
|
L: 147,
|
|
2015
2345
|
S: this,
|
|
2016
2346
|
C: (f, a) => f(...a)
|
|
@@ -2018,7 +2348,7 @@ var _MemoryTransport = class {
|
|
|
2018
2348
|
}
|
|
2019
2349
|
this.closed.emit();
|
|
2020
2350
|
log10("closed", void 0, {
|
|
2021
|
-
F:
|
|
2351
|
+
F: __dxlog_file11,
|
|
2022
2352
|
L: 151,
|
|
2023
2353
|
S: this,
|
|
2024
2354
|
C: (f, a) => f(...a)
|
|
@@ -2028,7 +2358,7 @@ var _MemoryTransport = class {
|
|
|
2028
2358
|
log10("received signal", {
|
|
2029
2359
|
payload
|
|
2030
2360
|
}, {
|
|
2031
|
-
F:
|
|
2361
|
+
F: __dxlog_file11,
|
|
2032
2362
|
L: 155,
|
|
2033
2363
|
S: this,
|
|
2034
2364
|
C: (f, a) => f(...a)
|
|
@@ -2055,9 +2385,9 @@ _ts_decorate4([
|
|
|
2055
2385
|
|
|
2056
2386
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
2057
2387
|
import SimplePeerConstructor from "simple-peer";
|
|
2058
|
-
import invariant11 from "tiny-invariant";
|
|
2059
2388
|
import { Event as Event7 } from "@dxos/async";
|
|
2060
2389
|
import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
|
|
2390
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
2061
2391
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
2062
2392
|
import { log as log11 } from "@dxos/log";
|
|
2063
2393
|
import { trace as trace4 } from "@dxos/protocols";
|
|
@@ -2070,7 +2400,7 @@ try {
|
|
|
2070
2400
|
}
|
|
2071
2401
|
|
|
2072
2402
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
2073
|
-
var
|
|
2403
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
|
|
2074
2404
|
var WebRTCTransport = class {
|
|
2075
2405
|
constructor(params) {
|
|
2076
2406
|
var _a;
|
|
@@ -2083,13 +2413,13 @@ var WebRTCTransport = class {
|
|
|
2083
2413
|
log11.trace("dxos.mesh.webrtc-transport.constructor", trace4.begin({
|
|
2084
2414
|
id: this._instanceId
|
|
2085
2415
|
}), {
|
|
2086
|
-
F:
|
|
2416
|
+
F: __dxlog_file12,
|
|
2087
2417
|
L: 39,
|
|
2088
2418
|
S: this,
|
|
2089
2419
|
C: (f, a) => f(...a)
|
|
2090
2420
|
});
|
|
2091
2421
|
log11("created connection", params, {
|
|
2092
|
-
F:
|
|
2422
|
+
F: __dxlog_file12,
|
|
2093
2423
|
L: 40,
|
|
2094
2424
|
S: this,
|
|
2095
2425
|
C: (f, a) => f(...a)
|
|
@@ -2101,7 +2431,7 @@ var WebRTCTransport = class {
|
|
|
2101
2431
|
});
|
|
2102
2432
|
this._peer.on("signal", async (data) => {
|
|
2103
2433
|
log11("signal", data, {
|
|
2104
|
-
F:
|
|
2434
|
+
F: __dxlog_file12,
|
|
2105
2435
|
L: 48,
|
|
2106
2436
|
S: this,
|
|
2107
2437
|
C: (f, a) => f(...a)
|
|
@@ -2114,7 +2444,7 @@ var WebRTCTransport = class {
|
|
|
2114
2444
|
});
|
|
2115
2445
|
this._peer.on("connect", () => {
|
|
2116
2446
|
log11("connected", void 0, {
|
|
2117
|
-
F:
|
|
2447
|
+
F: __dxlog_file12,
|
|
2118
2448
|
L: 53,
|
|
2119
2449
|
S: this,
|
|
2120
2450
|
C: (f, a) => f(...a)
|
|
@@ -2124,7 +2454,7 @@ var WebRTCTransport = class {
|
|
|
2124
2454
|
});
|
|
2125
2455
|
this._peer.on("close", async () => {
|
|
2126
2456
|
log11("closed", void 0, {
|
|
2127
|
-
F:
|
|
2457
|
+
F: __dxlog_file12,
|
|
2128
2458
|
L: 59,
|
|
2129
2459
|
S: this,
|
|
2130
2460
|
C: (f, a) => f(...a)
|
|
@@ -2142,7 +2472,7 @@ var WebRTCTransport = class {
|
|
|
2142
2472
|
config: this.params.webrtcConfig,
|
|
2143
2473
|
stats
|
|
2144
2474
|
}, {
|
|
2145
|
-
F:
|
|
2475
|
+
F: __dxlog_file12,
|
|
2146
2476
|
L: 71,
|
|
2147
2477
|
S: this,
|
|
2148
2478
|
C: (f, a) => f(...a)
|
|
@@ -2156,7 +2486,7 @@ var WebRTCTransport = class {
|
|
|
2156
2486
|
log11.trace("dxos.mesh.webrtc-transport.constructor", trace4.end({
|
|
2157
2487
|
id: this._instanceId
|
|
2158
2488
|
}), {
|
|
2159
|
-
F:
|
|
2489
|
+
F: __dxlog_file12,
|
|
2160
2490
|
L: 81,
|
|
2161
2491
|
S: this,
|
|
2162
2492
|
C: (f, a) => f(...a)
|
|
@@ -2164,7 +2494,7 @@ var WebRTCTransport = class {
|
|
|
2164
2494
|
}
|
|
2165
2495
|
async destroy() {
|
|
2166
2496
|
log11("closing...", void 0, {
|
|
2167
|
-
F:
|
|
2497
|
+
F: __dxlog_file12,
|
|
2168
2498
|
L: 85,
|
|
2169
2499
|
S: this,
|
|
2170
2500
|
C: (f, a) => f(...a)
|
|
@@ -2174,7 +2504,7 @@ var WebRTCTransport = class {
|
|
|
2174
2504
|
this._peer.destroy();
|
|
2175
2505
|
this.closed.emit();
|
|
2176
2506
|
log11("closed", void 0, {
|
|
2177
|
-
F:
|
|
2507
|
+
F: __dxlog_file12,
|
|
2178
2508
|
L: 90,
|
|
2179
2509
|
S: this,
|
|
2180
2510
|
C: (f, a) => f(...a)
|
|
@@ -2184,7 +2514,15 @@ var WebRTCTransport = class {
|
|
|
2184
2514
|
if (this._closed) {
|
|
2185
2515
|
return;
|
|
2186
2516
|
}
|
|
2187
|
-
invariant11(signal.payload.data, "Signal message must contain signal data."
|
|
2517
|
+
invariant11(signal.payload.data, "Signal message must contain signal data.", {
|
|
2518
|
+
F: __dxlog_file12,
|
|
2519
|
+
L: 98,
|
|
2520
|
+
S: this,
|
|
2521
|
+
A: [
|
|
2522
|
+
"signal.payload.data",
|
|
2523
|
+
"'Signal message must contain signal data.'"
|
|
2524
|
+
]
|
|
2525
|
+
});
|
|
2188
2526
|
this._peer.signal(signal.payload.data);
|
|
2189
2527
|
}
|
|
2190
2528
|
async _disconnectStreams() {
|
|
@@ -2201,13 +2539,13 @@ var createWebRTCTransportFactory = (webrtcConfig) => ({
|
|
|
2201
2539
|
|
|
2202
2540
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
2203
2541
|
import { Duplex } from "@dxos/node-std/stream";
|
|
2204
|
-
import invariant12 from "tiny-invariant";
|
|
2205
2542
|
import { Stream } from "@dxos/codec-protobuf";
|
|
2543
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
2206
2544
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
2207
2545
|
import { log as log12 } from "@dxos/log";
|
|
2208
2546
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
2209
2547
|
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
2210
|
-
var
|
|
2548
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
|
|
2211
2549
|
var WebRTCTransportService = class {
|
|
2212
2550
|
// prettier-ignore
|
|
2213
2551
|
constructor(_webrtcConfig) {
|
|
@@ -2218,6 +2556,13 @@ var WebRTCTransportService = class {
|
|
|
2218
2556
|
const rpcStream = new Stream(({ ready, next, close }) => {
|
|
2219
2557
|
const duplex = new Duplex({
|
|
2220
2558
|
read: () => {
|
|
2559
|
+
const callbacks = [
|
|
2560
|
+
...transportState.writeCallbacks
|
|
2561
|
+
];
|
|
2562
|
+
transportState.writeCallbacks.length = 0;
|
|
2563
|
+
for (const cb of callbacks) {
|
|
2564
|
+
cb();
|
|
2565
|
+
}
|
|
2221
2566
|
},
|
|
2222
2567
|
write: function(chunk, _, callback) {
|
|
2223
2568
|
next({
|
|
@@ -2269,21 +2614,45 @@ var WebRTCTransportService = class {
|
|
|
2269
2614
|
});
|
|
2270
2615
|
close();
|
|
2271
2616
|
});
|
|
2272
|
-
|
|
2273
|
-
this.transports.set(request.proxyId, {
|
|
2617
|
+
const transportState = {
|
|
2274
2618
|
transport,
|
|
2275
|
-
stream: duplex
|
|
2276
|
-
|
|
2619
|
+
stream: duplex,
|
|
2620
|
+
writeCallbacks: []
|
|
2621
|
+
};
|
|
2622
|
+
ready();
|
|
2623
|
+
this.transports.set(request.proxyId, transportState);
|
|
2277
2624
|
});
|
|
2278
2625
|
return rpcStream;
|
|
2279
2626
|
}
|
|
2280
2627
|
async sendSignal({ proxyId, signal }) {
|
|
2281
|
-
invariant12(this.transports.has(proxyId)
|
|
2628
|
+
invariant12(this.transports.has(proxyId), void 0, {
|
|
2629
|
+
F: __dxlog_file13,
|
|
2630
|
+
L: 113,
|
|
2631
|
+
S: this,
|
|
2632
|
+
A: [
|
|
2633
|
+
"this.transports.has(proxyId)",
|
|
2634
|
+
""
|
|
2635
|
+
]
|
|
2636
|
+
});
|
|
2282
2637
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2283
2638
|
}
|
|
2284
2639
|
async sendData({ proxyId, payload }) {
|
|
2285
|
-
invariant12(this.transports.has(proxyId)
|
|
2286
|
-
|
|
2640
|
+
invariant12(this.transports.has(proxyId), void 0, {
|
|
2641
|
+
F: __dxlog_file13,
|
|
2642
|
+
L: 118,
|
|
2643
|
+
S: this,
|
|
2644
|
+
A: [
|
|
2645
|
+
"this.transports.has(proxyId)",
|
|
2646
|
+
""
|
|
2647
|
+
]
|
|
2648
|
+
});
|
|
2649
|
+
const state = this.transports.get(proxyId);
|
|
2650
|
+
const bufferHasSpace = state.stream.push(payload);
|
|
2651
|
+
if (!bufferHasSpace) {
|
|
2652
|
+
await new Promise((resolve) => {
|
|
2653
|
+
state.writeCallbacks.push(resolve);
|
|
2654
|
+
});
|
|
2655
|
+
}
|
|
2287
2656
|
}
|
|
2288
2657
|
async close({ proxyId }) {
|
|
2289
2658
|
var _a, _b;
|
|
@@ -2291,8 +2660,8 @@ var WebRTCTransportService = class {
|
|
|
2291
2660
|
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
2292
2661
|
this.transports.delete(proxyId);
|
|
2293
2662
|
log12("Closed.", void 0, {
|
|
2294
|
-
F:
|
|
2295
|
-
L:
|
|
2663
|
+
F: __dxlog_file13,
|
|
2664
|
+
L: 132,
|
|
2296
2665
|
S: this,
|
|
2297
2666
|
C: (f, a) => f(...a)
|
|
2298
2667
|
});
|
|
@@ -2300,15 +2669,16 @@ var WebRTCTransportService = class {
|
|
|
2300
2669
|
};
|
|
2301
2670
|
|
|
2302
2671
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2303
|
-
import
|
|
2672
|
+
import { Writable } from "@dxos/node-std/stream";
|
|
2304
2673
|
import { Event as Event8 } from "@dxos/async";
|
|
2305
2674
|
import { Context as Context6 } from "@dxos/context";
|
|
2306
2675
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
2676
|
+
import { invariant as invariant13 } from "@dxos/invariant";
|
|
2307
2677
|
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
2308
2678
|
import { log as log13 } from "@dxos/log";
|
|
2309
2679
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
2310
2680
|
import { arrayToBuffer } from "@dxos/util";
|
|
2311
|
-
var
|
|
2681
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
|
|
2312
2682
|
var WebRTCTransportProxy = class {
|
|
2313
2683
|
// prettier-ignore
|
|
2314
2684
|
constructor(_params) {
|
|
@@ -2326,8 +2696,8 @@ var WebRTCTransportProxy = class {
|
|
|
2326
2696
|
this._serviceStream.waitUntilReady().then(() => {
|
|
2327
2697
|
this._serviceStream.subscribe(async (event) => {
|
|
2328
2698
|
log13("WebRTCTransportProxy: event", event, {
|
|
2329
|
-
F:
|
|
2330
|
-
L:
|
|
2699
|
+
F: __dxlog_file14,
|
|
2700
|
+
L: 51,
|
|
2331
2701
|
S: this,
|
|
2332
2702
|
C: (f, a) => f(...a)
|
|
2333
2703
|
});
|
|
@@ -2339,28 +2709,24 @@ var WebRTCTransportProxy = class {
|
|
|
2339
2709
|
await this._handleSignal(event.signal);
|
|
2340
2710
|
}
|
|
2341
2711
|
});
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2712
|
+
this._params.stream.pipe(new Writable({
|
|
2713
|
+
write: (chunk, _, callback) => {
|
|
2714
|
+
this._params.bridgeService.sendData({
|
|
2345
2715
|
proxyId: this._proxyId,
|
|
2346
|
-
payload:
|
|
2347
|
-
})
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2716
|
+
payload: chunk
|
|
2717
|
+
}).then(() => callback(), (err) => {
|
|
2718
|
+
log13.catch(err, void 0, {
|
|
2719
|
+
F: __dxlog_file14,
|
|
2720
|
+
L: 69,
|
|
2721
|
+
S: this,
|
|
2722
|
+
C: (f, a) => f(...a)
|
|
2723
|
+
});
|
|
2354
2724
|
});
|
|
2355
2725
|
}
|
|
2356
|
-
};
|
|
2357
|
-
this._params.stream.on("data", dataListener);
|
|
2358
|
-
this._ctx.onDispose(() => {
|
|
2359
|
-
this._params.stream.off("data", dataListener);
|
|
2360
|
-
});
|
|
2726
|
+
}));
|
|
2361
2727
|
}, (error) => log13.catch(error, void 0, {
|
|
2362
|
-
F:
|
|
2363
|
-
L:
|
|
2728
|
+
F: __dxlog_file14,
|
|
2729
|
+
L: 75,
|
|
2364
2730
|
S: this,
|
|
2365
2731
|
C: (f, a) => f(...a)
|
|
2366
2732
|
}));
|
|
@@ -2405,8 +2771,8 @@ var WebRTCTransportProxy = class {
|
|
|
2405
2771
|
});
|
|
2406
2772
|
} catch (err) {
|
|
2407
2773
|
log13.catch(err, void 0, {
|
|
2408
|
-
F:
|
|
2409
|
-
L:
|
|
2774
|
+
F: __dxlog_file14,
|
|
2775
|
+
L: 126,
|
|
2410
2776
|
S: this,
|
|
2411
2777
|
C: (f, a) => f(...a)
|
|
2412
2778
|
});
|
|
@@ -2440,7 +2806,15 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2440
2806
|
return this;
|
|
2441
2807
|
}
|
|
2442
2808
|
createTransport(options) {
|
|
2443
|
-
invariant13(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections"
|
|
2809
|
+
invariant13(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections", {
|
|
2810
|
+
F: __dxlog_file14,
|
|
2811
|
+
L: 163,
|
|
2812
|
+
S: this,
|
|
2813
|
+
A: [
|
|
2814
|
+
"this._bridgeService",
|
|
2815
|
+
"'WebRTCTransportProxyFactory is not ready to open connections'"
|
|
2816
|
+
]
|
|
2817
|
+
});
|
|
2444
2818
|
const transport = new WebRTCTransportProxy({
|
|
2445
2819
|
...options,
|
|
2446
2820
|
bridgeService: this._bridgeService
|
|
@@ -2492,4 +2866,4 @@ export {
|
|
|
2492
2866
|
WebRTCTransportProxyFactory,
|
|
2493
2867
|
createTeleportProtocolFactory
|
|
2494
2868
|
};
|
|
2495
|
-
//# sourceMappingURL=chunk-
|
|
2869
|
+
//# sourceMappingURL=chunk-FYPOLWVS.mjs.map
|