@dxos/network-manager 0.8.4-main.2e9d522 → 0.8.4-main.3c1ae3b
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-2XXESTV3.mjs → chunk-5ISEIDVN.mjs} +397 -277
- package/dist/lib/browser/chunk-5ISEIDVN.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 +65 -46
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/transport/tcp/index.mjs +3 -5
- package/dist/lib/browser/transport/tcp/index.mjs.map +1 -1
- package/dist/lib/node-esm/{chunk-RPB6YS7U.mjs → chunk-S7AVXKL7.mjs} +397 -277
- package/dist/lib/node-esm/chunk-S7AVXKL7.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +65 -46
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/transport/tcp/index.mjs +8 -7
- package/dist/lib/node-esm/transport/tcp/index.mjs.map +2 -2
- package/dist/types/src/connection-log.d.ts.map +1 -1
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +2 -2
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +3 -3
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-wire-protocol.d.ts +1 -1
- package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
- package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts +2 -2
- package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -29
- package/src/connection-log.ts +1 -1
- package/src/network-manager.ts +1 -1
- package/src/signal/ice.test.ts +1 -1
- package/src/signal/integration.node.test.ts +2 -2
- package/src/signal/swarm-messenger.node.test.ts +1 -1
- package/src/signal/swarm-messenger.ts +1 -1
- package/src/swarm/connection.test.ts +4 -2
- package/src/swarm/connection.ts +10 -8
- package/src/swarm/peer.ts +4 -3
- package/src/swarm/swarm-mapper.ts +1 -1
- package/src/swarm/swarm.test.ts +7 -5
- package/src/swarm/swarm.ts +5 -4
- package/src/testing/test-builder.ts +11 -4
- package/src/testing/test-wire-protocol.ts +2 -2
- package/src/tests/basic-test-suite.ts +3 -2
- package/src/tests/memory-transport.test.ts +4 -2
- package/src/tests/tcp-transport.node.test.ts +4 -2
- package/src/tests/webrtc-transport.test.ts +6 -3
- package/src/transport/tcp/tcp-transport.ts +1 -1
- package/src/transport/webrtc/rtc-peer-connection.ts +5 -4
- package/src/transport/webrtc/rtc-transport-channel.test.ts +3 -1
- package/src/transport/webrtc/rtc-transport-channel.ts +3 -2
- package/src/transport/webrtc/rtc-transport-factory.ts +3 -2
- package/src/transport/webrtc/rtc-transport-proxy.test.ts +7 -4
- package/src/transport/webrtc/rtc-transport-proxy.ts +6 -4
- package/src/transport/webrtc/rtc-transport-service.ts +6 -5
- package/src/transport/webrtc/rtc-transport.test.ts +6 -4
- package/dist/lib/browser/chunk-2XXESTV3.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RPB6YS7U.mjs.map +0 -7
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
|
|
3
3
|
// src/swarm/connection.ts
|
|
4
|
-
import { DeferredTask, Event,
|
|
5
|
-
import { Context,
|
|
4
|
+
import { DeferredTask, Event, Trigger, scheduleTask, scheduleTaskInterval, sleep, synchronized } from "@dxos/async";
|
|
5
|
+
import { Context, ContextDisposedError, cancelWithContext } from "@dxos/context";
|
|
6
6
|
import { ErrorStream } from "@dxos/debug";
|
|
7
7
|
import { invariant } from "@dxos/invariant";
|
|
8
8
|
import { PublicKey } from "@dxos/keys";
|
|
9
9
|
import { log, logInfo } from "@dxos/log";
|
|
10
|
-
import { CancelledError,
|
|
10
|
+
import { CancelledError, ConnectionResetError, ConnectivityError, ProtocolError, TimeoutError, trace } from "@dxos/protocols";
|
|
11
11
|
function _ts_decorate(decorators, target, key, desc) {
|
|
12
12
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13
13
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -19,7 +19,7 @@ var STARTING_SIGNALLING_DELAY = 10;
|
|
|
19
19
|
var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
|
|
20
20
|
var TRANSPORT_STATS_INTERVAL = 5e3;
|
|
21
21
|
var MAX_SIGNALLING_DELAY = 300;
|
|
22
|
-
var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
|
|
22
|
+
var ConnectionState = /* @__PURE__ */ (function(ConnectionState5) {
|
|
23
23
|
ConnectionState5["CREATED"] = "CREATED";
|
|
24
24
|
ConnectionState5["INITIAL"] = "INITIAL";
|
|
25
25
|
ConnectionState5["CONNECTING"] = "CONNECTING";
|
|
@@ -29,8 +29,40 @@ var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
|
|
|
29
29
|
ConnectionState5["ABORTING"] = "ABORTING";
|
|
30
30
|
ConnectionState5["ABORTED"] = "ABORTED";
|
|
31
31
|
return ConnectionState5;
|
|
32
|
-
}({});
|
|
32
|
+
})({});
|
|
33
33
|
var Connection = class {
|
|
34
|
+
topic;
|
|
35
|
+
localInfo;
|
|
36
|
+
remoteInfo;
|
|
37
|
+
sessionId;
|
|
38
|
+
initiator;
|
|
39
|
+
_signalMessaging;
|
|
40
|
+
_protocol;
|
|
41
|
+
_transportFactory;
|
|
42
|
+
_callbacks;
|
|
43
|
+
_ctx = new Context(void 0, {
|
|
44
|
+
F: __dxlog_file,
|
|
45
|
+
L: 100
|
|
46
|
+
});
|
|
47
|
+
connectedTimeoutContext = new Context(void 0, {
|
|
48
|
+
F: __dxlog_file,
|
|
49
|
+
L: 101
|
|
50
|
+
});
|
|
51
|
+
_protocolClosed = new Trigger();
|
|
52
|
+
_transportClosed = new Trigger();
|
|
53
|
+
_state = "CREATED";
|
|
54
|
+
_transport;
|
|
55
|
+
closeReason;
|
|
56
|
+
_incomingSignalBuffer = [];
|
|
57
|
+
_outgoingSignalBuffer = [];
|
|
58
|
+
stateChanged = new Event();
|
|
59
|
+
errors = new ErrorStream();
|
|
60
|
+
_instanceId = PublicKey.random().toHex();
|
|
61
|
+
transportStats = new Event();
|
|
62
|
+
_signalSendTask = new DeferredTask(this._ctx, async () => {
|
|
63
|
+
await this._flushSignalBuffer();
|
|
64
|
+
});
|
|
65
|
+
_signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
34
66
|
constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
|
|
35
67
|
this.topic = topic;
|
|
36
68
|
this.localInfo = localInfo;
|
|
@@ -41,27 +73,6 @@ var Connection = class {
|
|
|
41
73
|
this._protocol = _protocol;
|
|
42
74
|
this._transportFactory = _transportFactory;
|
|
43
75
|
this._callbacks = _callbacks;
|
|
44
|
-
this._ctx = new Context(void 0, {
|
|
45
|
-
F: __dxlog_file,
|
|
46
|
-
L: 100
|
|
47
|
-
});
|
|
48
|
-
this.connectedTimeoutContext = new Context(void 0, {
|
|
49
|
-
F: __dxlog_file,
|
|
50
|
-
L: 101
|
|
51
|
-
});
|
|
52
|
-
this._protocolClosed = new Trigger();
|
|
53
|
-
this._transportClosed = new Trigger();
|
|
54
|
-
this._state = "CREATED";
|
|
55
|
-
this._incomingSignalBuffer = [];
|
|
56
|
-
this._outgoingSignalBuffer = [];
|
|
57
|
-
this.stateChanged = new Event();
|
|
58
|
-
this.errors = new ErrorStream();
|
|
59
|
-
this._instanceId = PublicKey.random().toHex();
|
|
60
|
-
this.transportStats = new Event();
|
|
61
|
-
this._signalSendTask = new DeferredTask(this._ctx, async () => {
|
|
62
|
-
await this._flushSignalBuffer();
|
|
63
|
-
});
|
|
64
|
-
this._signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
65
76
|
log.trace("dxos.mesh.connection.construct", {
|
|
66
77
|
sessionId: this.sessionId,
|
|
67
78
|
topic: this.topic,
|
|
@@ -133,21 +144,25 @@ var Connection = class {
|
|
|
133
144
|
});
|
|
134
145
|
this._protocolClosed.wake();
|
|
135
146
|
this.close({
|
|
136
|
-
error: new ProtocolError(
|
|
147
|
+
error: new ProtocolError({
|
|
148
|
+
message: "protocol stream closed"
|
|
149
|
+
})
|
|
137
150
|
}).catch((err) => this.errors.raise(err));
|
|
138
151
|
});
|
|
139
152
|
scheduleTask(this.connectedTimeoutContext, async () => {
|
|
140
153
|
log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
|
|
141
154
|
F: __dxlog_file,
|
|
142
|
-
L:
|
|
155
|
+
L: 196,
|
|
143
156
|
S: this,
|
|
144
157
|
C: (f, a) => f(...a)
|
|
145
158
|
});
|
|
146
|
-
await this.abort(new TimeoutError(
|
|
159
|
+
await this.abort(new TimeoutError({
|
|
160
|
+
message: `${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`
|
|
161
|
+
})).catch((err) => this.errors.raise(err));
|
|
147
162
|
}, TRANSPORT_CONNECTION_TIMEOUT);
|
|
148
163
|
invariant(!this._transport, void 0, {
|
|
149
164
|
F: __dxlog_file,
|
|
150
|
-
L:
|
|
165
|
+
L: 204,
|
|
151
166
|
S: this,
|
|
152
167
|
A: [
|
|
153
168
|
"!this._transport",
|
|
@@ -174,7 +189,7 @@ var Connection = class {
|
|
|
174
189
|
this._transportClosed.wake();
|
|
175
190
|
log("abort triggered by transport close", void 0, {
|
|
176
191
|
F: __dxlog_file,
|
|
177
|
-
L:
|
|
192
|
+
L: 226,
|
|
178
193
|
S: this,
|
|
179
194
|
C: (f, a) => f(...a)
|
|
180
195
|
});
|
|
@@ -185,7 +200,7 @@ var Connection = class {
|
|
|
185
200
|
err
|
|
186
201
|
}, {
|
|
187
202
|
F: __dxlog_file,
|
|
188
|
-
L:
|
|
203
|
+
L: 231,
|
|
189
204
|
S: this,
|
|
190
205
|
C: (f, a) => f(...a)
|
|
191
206
|
});
|
|
@@ -195,7 +210,7 @@ var Connection = class {
|
|
|
195
210
|
if (err instanceof ConnectionResetError) {
|
|
196
211
|
log.info("aborting due to transport ConnectionResetError", void 0, {
|
|
197
212
|
F: __dxlog_file,
|
|
198
|
-
L:
|
|
213
|
+
L: 238,
|
|
199
214
|
S: this,
|
|
200
215
|
C: (f, a) => f(...a)
|
|
201
216
|
});
|
|
@@ -203,7 +218,7 @@ var Connection = class {
|
|
|
203
218
|
} else if (err instanceof ConnectivityError) {
|
|
204
219
|
log.info("aborting due to transport ConnectivityError", void 0, {
|
|
205
220
|
F: __dxlog_file,
|
|
206
|
-
L:
|
|
221
|
+
L: 241,
|
|
207
222
|
S: this,
|
|
208
223
|
C: (f, a) => f(...a)
|
|
209
224
|
});
|
|
@@ -223,7 +238,7 @@ var Connection = class {
|
|
|
223
238
|
id: this._instanceId
|
|
224
239
|
}), {
|
|
225
240
|
F: __dxlog_file,
|
|
226
|
-
L:
|
|
241
|
+
L: 260,
|
|
227
242
|
S: this,
|
|
228
243
|
C: (f, a) => f(...a)
|
|
229
244
|
});
|
|
@@ -233,14 +248,14 @@ var Connection = class {
|
|
|
233
248
|
err
|
|
234
249
|
}, {
|
|
235
250
|
F: __dxlog_file,
|
|
236
|
-
L:
|
|
251
|
+
L: 267,
|
|
237
252
|
S: this,
|
|
238
253
|
C: (f, a) => f(...a)
|
|
239
254
|
});
|
|
240
255
|
if (this._state === "CLOSED" || this._state === "ABORTED") {
|
|
241
256
|
log(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
242
257
|
F: __dxlog_file,
|
|
243
|
-
L:
|
|
258
|
+
L: 269,
|
|
244
259
|
S: this,
|
|
245
260
|
C: (f, a) => f(...a)
|
|
246
261
|
});
|
|
@@ -257,7 +272,7 @@ var Connection = class {
|
|
|
257
272
|
err
|
|
258
273
|
}, {
|
|
259
274
|
F: __dxlog_file,
|
|
260
|
-
L:
|
|
275
|
+
L: 281,
|
|
261
276
|
S: this,
|
|
262
277
|
C: (f, a) => f(...a)
|
|
263
278
|
});
|
|
@@ -268,7 +283,7 @@ var Connection = class {
|
|
|
268
283
|
} catch (err2) {
|
|
269
284
|
log.catch(err2, void 0, {
|
|
270
285
|
F: __dxlog_file,
|
|
271
|
-
L:
|
|
286
|
+
L: 287,
|
|
272
287
|
S: this,
|
|
273
288
|
C: (f, a) => f(...a)
|
|
274
289
|
});
|
|
@@ -278,7 +293,7 @@ var Connection = class {
|
|
|
278
293
|
} catch (err2) {
|
|
279
294
|
log.catch(err2, void 0, {
|
|
280
295
|
F: __dxlog_file,
|
|
281
|
-
L:
|
|
296
|
+
L: 294,
|
|
282
297
|
S: this,
|
|
283
298
|
C: (f, a) => f(...a)
|
|
284
299
|
});
|
|
@@ -288,7 +303,7 @@ var Connection = class {
|
|
|
288
303
|
} catch (err2) {
|
|
289
304
|
log.catch(err2, void 0, {
|
|
290
305
|
F: __dxlog_file,
|
|
291
|
-
L:
|
|
306
|
+
L: 300,
|
|
292
307
|
S: this,
|
|
293
308
|
C: (f, a) => f(...a)
|
|
294
309
|
});
|
|
@@ -300,7 +315,7 @@ var Connection = class {
|
|
|
300
315
|
error
|
|
301
316
|
}, {
|
|
302
317
|
F: __dxlog_file,
|
|
303
|
-
L:
|
|
318
|
+
L: 307,
|
|
304
319
|
S: this,
|
|
305
320
|
C: (f, a) => f(...a)
|
|
306
321
|
});
|
|
@@ -315,7 +330,7 @@ var Connection = class {
|
|
|
315
330
|
error
|
|
316
331
|
}, {
|
|
317
332
|
F: __dxlog_file,
|
|
318
|
-
L:
|
|
333
|
+
L: 318,
|
|
319
334
|
S: this,
|
|
320
335
|
C: (f, a) => f(...a)
|
|
321
336
|
});
|
|
@@ -329,7 +344,7 @@ var Connection = class {
|
|
|
329
344
|
if (lastState !== "CONNECTED" || error != null) {
|
|
330
345
|
log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
331
346
|
F: __dxlog_file,
|
|
332
|
-
L:
|
|
347
|
+
L: 329,
|
|
333
348
|
S: this,
|
|
334
349
|
C: (f, a) => f(...a)
|
|
335
350
|
});
|
|
@@ -341,7 +356,7 @@ var Connection = class {
|
|
|
341
356
|
error
|
|
342
357
|
}, {
|
|
343
358
|
F: __dxlog_file,
|
|
344
|
-
L:
|
|
359
|
+
L: 333,
|
|
345
360
|
S: this,
|
|
346
361
|
C: (f, a) => f(...a)
|
|
347
362
|
});
|
|
@@ -352,7 +367,7 @@ var Connection = class {
|
|
|
352
367
|
} catch (err) {
|
|
353
368
|
log.catch(err, void 0, {
|
|
354
369
|
F: __dxlog_file,
|
|
355
|
-
L:
|
|
370
|
+
L: 338,
|
|
356
371
|
S: this,
|
|
357
372
|
C: (f, a) => f(...a)
|
|
358
373
|
});
|
|
@@ -362,7 +377,7 @@ var Connection = class {
|
|
|
362
377
|
} catch (err) {
|
|
363
378
|
log.catch(err, void 0, {
|
|
364
379
|
F: __dxlog_file,
|
|
365
|
-
L:
|
|
380
|
+
L: 344,
|
|
366
381
|
S: this,
|
|
367
382
|
C: (f, a) => f(...a)
|
|
368
383
|
});
|
|
@@ -371,7 +386,7 @@ var Connection = class {
|
|
|
371
386
|
peerId: this.localInfo
|
|
372
387
|
}, {
|
|
373
388
|
F: __dxlog_file,
|
|
374
|
-
L:
|
|
389
|
+
L: 347,
|
|
375
390
|
S: this,
|
|
376
391
|
C: (f, a) => f(...a)
|
|
377
392
|
});
|
|
@@ -381,7 +396,7 @@ var Connection = class {
|
|
|
381
396
|
async _closeProtocol(options) {
|
|
382
397
|
log("closing protocol", options, {
|
|
383
398
|
F: __dxlog_file,
|
|
384
|
-
L:
|
|
399
|
+
L: 353,
|
|
385
400
|
S: this,
|
|
386
401
|
C: (f, a) => f(...a)
|
|
387
402
|
});
|
|
@@ -391,7 +406,7 @@ var Connection = class {
|
|
|
391
406
|
]);
|
|
392
407
|
log("protocol closed", options, {
|
|
393
408
|
F: __dxlog_file,
|
|
394
|
-
L:
|
|
409
|
+
L: 355,
|
|
395
410
|
S: this,
|
|
396
411
|
C: (f, a) => f(...a)
|
|
397
412
|
});
|
|
@@ -399,7 +414,7 @@ var Connection = class {
|
|
|
399
414
|
async _closeTransport() {
|
|
400
415
|
log("closing transport", void 0, {
|
|
401
416
|
F: __dxlog_file,
|
|
402
|
-
L:
|
|
417
|
+
L: 359,
|
|
403
418
|
S: this,
|
|
404
419
|
C: (f, a) => f(...a)
|
|
405
420
|
});
|
|
@@ -409,7 +424,7 @@ var Connection = class {
|
|
|
409
424
|
]);
|
|
410
425
|
log("transport closed", void 0, {
|
|
411
426
|
F: __dxlog_file,
|
|
412
|
-
L:
|
|
427
|
+
L: 361,
|
|
413
428
|
S: this,
|
|
414
429
|
C: (f, a) => f(...a)
|
|
415
430
|
});
|
|
@@ -450,12 +465,15 @@ var Connection = class {
|
|
|
450
465
|
err
|
|
451
466
|
}, {
|
|
452
467
|
F: __dxlog_file,
|
|
453
|
-
L:
|
|
468
|
+
L: 401,
|
|
454
469
|
S: this,
|
|
455
470
|
C: (f, a) => f(...a)
|
|
456
471
|
});
|
|
457
472
|
await this.close({
|
|
458
|
-
error: new ConnectivityError(
|
|
473
|
+
error: new ConnectivityError({
|
|
474
|
+
message: "signal message failed to deliver",
|
|
475
|
+
cause: err
|
|
476
|
+
})
|
|
459
477
|
});
|
|
460
478
|
}
|
|
461
479
|
}
|
|
@@ -465,7 +483,7 @@ var Connection = class {
|
|
|
465
483
|
async signal(msg) {
|
|
466
484
|
invariant(msg.sessionId, void 0, {
|
|
467
485
|
F: __dxlog_file,
|
|
468
|
-
L:
|
|
486
|
+
L: 410,
|
|
469
487
|
S: this,
|
|
470
488
|
A: [
|
|
471
489
|
"msg.sessionId",
|
|
@@ -475,7 +493,7 @@ var Connection = class {
|
|
|
475
493
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
476
494
|
log("dropping signal for incorrect session id", void 0, {
|
|
477
495
|
F: __dxlog_file,
|
|
478
|
-
L:
|
|
496
|
+
L: 412,
|
|
479
497
|
S: this,
|
|
480
498
|
C: (f, a) => f(...a)
|
|
481
499
|
});
|
|
@@ -483,7 +501,7 @@ var Connection = class {
|
|
|
483
501
|
}
|
|
484
502
|
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
485
503
|
F: __dxlog_file,
|
|
486
|
-
L:
|
|
504
|
+
L: 415,
|
|
487
505
|
S: this,
|
|
488
506
|
A: [
|
|
489
507
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -492,7 +510,7 @@ var Connection = class {
|
|
|
492
510
|
});
|
|
493
511
|
invariant(msg.author.peerKey === this.remoteInfo.peerKey, void 0, {
|
|
494
512
|
F: __dxlog_file,
|
|
495
|
-
L:
|
|
513
|
+
L: 416,
|
|
496
514
|
S: this,
|
|
497
515
|
A: [
|
|
498
516
|
"msg.author.peerKey === this.remoteInfo.peerKey",
|
|
@@ -501,7 +519,7 @@ var Connection = class {
|
|
|
501
519
|
});
|
|
502
520
|
invariant(msg.recipient.peerKey === this.localInfo.peerKey, void 0, {
|
|
503
521
|
F: __dxlog_file,
|
|
504
|
-
L:
|
|
522
|
+
L: 417,
|
|
505
523
|
S: this,
|
|
506
524
|
A: [
|
|
507
525
|
"msg.recipient.peerKey === this.localInfo.peerKey",
|
|
@@ -525,7 +543,7 @@ var Connection = class {
|
|
|
525
543
|
msg: msg.data
|
|
526
544
|
}, {
|
|
527
545
|
F: __dxlog_file,
|
|
528
|
-
L:
|
|
546
|
+
L: 426,
|
|
529
547
|
S: this,
|
|
530
548
|
C: (f, a) => f(...a)
|
|
531
549
|
});
|
|
@@ -533,7 +551,7 @@ var Connection = class {
|
|
|
533
551
|
} else {
|
|
534
552
|
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
535
553
|
F: __dxlog_file,
|
|
536
|
-
L:
|
|
554
|
+
L: 429,
|
|
537
555
|
S: this,
|
|
538
556
|
A: [
|
|
539
557
|
"this._transport",
|
|
@@ -546,7 +564,7 @@ var Connection = class {
|
|
|
546
564
|
msg: msg.data
|
|
547
565
|
}, {
|
|
548
566
|
F: __dxlog_file,
|
|
549
|
-
L:
|
|
567
|
+
L: 430,
|
|
550
568
|
S: this,
|
|
551
569
|
C: (f, a) => f(...a)
|
|
552
570
|
});
|
|
@@ -564,13 +582,13 @@ var Connection = class {
|
|
|
564
582
|
peerId: this.localInfo
|
|
565
583
|
}, {
|
|
566
584
|
F: __dxlog_file,
|
|
567
|
-
L:
|
|
585
|
+
L: 441,
|
|
568
586
|
S: this,
|
|
569
587
|
C: (f, a) => f(...a)
|
|
570
588
|
});
|
|
571
589
|
invariant(state !== this._state, "Already in this state.", {
|
|
572
590
|
F: __dxlog_file,
|
|
573
|
-
L:
|
|
591
|
+
L: 442,
|
|
574
592
|
S: this,
|
|
575
593
|
A: [
|
|
576
594
|
"state !== this._state",
|
|
@@ -641,12 +659,16 @@ import { ComplexMap } from "@dxos/util";
|
|
|
641
659
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
642
660
|
var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
643
661
|
var SwarmMessenger = class {
|
|
662
|
+
_ctx = new Context2(void 0, {
|
|
663
|
+
F: __dxlog_file3,
|
|
664
|
+
L: 35
|
|
665
|
+
});
|
|
666
|
+
_sendMessage;
|
|
667
|
+
_onSignal;
|
|
668
|
+
_onOffer;
|
|
669
|
+
_topic;
|
|
670
|
+
_offerRecords = new ComplexMap((key) => key.toHex());
|
|
644
671
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
645
|
-
this._ctx = new Context2(void 0, {
|
|
646
|
-
F: __dxlog_file3,
|
|
647
|
-
L: 35
|
|
648
|
-
});
|
|
649
|
-
this._offerRecords = new ComplexMap((key) => key.toHex());
|
|
650
672
|
this._sendMessage = sendMessage;
|
|
651
673
|
this._onSignal = onSignal;
|
|
652
674
|
this._onOffer = onOffer;
|
|
@@ -904,11 +926,39 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
904
926
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
905
927
|
var ConnectionDisplacedError = class extends SystemError {
|
|
906
928
|
constructor() {
|
|
907
|
-
super(
|
|
929
|
+
super({
|
|
930
|
+
message: "Connection displaced by remote initiator."
|
|
931
|
+
});
|
|
908
932
|
}
|
|
909
933
|
};
|
|
910
934
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
911
935
|
var Peer = class {
|
|
936
|
+
remoteInfo;
|
|
937
|
+
topic;
|
|
938
|
+
localInfo;
|
|
939
|
+
_signalMessaging;
|
|
940
|
+
_protocolProvider;
|
|
941
|
+
_transportFactory;
|
|
942
|
+
_connectionLimiter;
|
|
943
|
+
_callbacks;
|
|
944
|
+
/**
|
|
945
|
+
* Will be available to connect after this time.
|
|
946
|
+
*/
|
|
947
|
+
_availableAfter = 0;
|
|
948
|
+
availableToConnect = true;
|
|
949
|
+
_lastConnectionTime;
|
|
950
|
+
_ctx = new Context3(void 0, {
|
|
951
|
+
F: __dxlog_file4,
|
|
952
|
+
L: 81
|
|
953
|
+
});
|
|
954
|
+
_connectionCtx;
|
|
955
|
+
connection;
|
|
956
|
+
/**
|
|
957
|
+
* Whether the peer is currently advertizing itself on the signal-network.
|
|
958
|
+
*/
|
|
959
|
+
advertizing = false;
|
|
960
|
+
initiating = false;
|
|
961
|
+
connectionDisplaced = new Event2();
|
|
912
962
|
constructor(remoteInfo, topic, localInfo, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
913
963
|
this.remoteInfo = remoteInfo;
|
|
914
964
|
this.topic = topic;
|
|
@@ -918,15 +968,6 @@ var Peer = class {
|
|
|
918
968
|
this._transportFactory = _transportFactory;
|
|
919
969
|
this._connectionLimiter = _connectionLimiter;
|
|
920
970
|
this._callbacks = _callbacks;
|
|
921
|
-
this._availableAfter = 0;
|
|
922
|
-
this.availableToConnect = true;
|
|
923
|
-
this._ctx = new Context3(void 0, {
|
|
924
|
-
F: __dxlog_file4,
|
|
925
|
-
L: 80
|
|
926
|
-
});
|
|
927
|
-
this.advertizing = false;
|
|
928
|
-
this.initiating = false;
|
|
929
|
-
this.connectionDisplaced = new Event2();
|
|
930
971
|
}
|
|
931
972
|
/**
|
|
932
973
|
* Respond to remote offer.
|
|
@@ -940,7 +981,7 @@ var Peer = class {
|
|
|
940
981
|
].includes(this.connection.state)) {
|
|
941
982
|
log4.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
942
983
|
F: __dxlog_file4,
|
|
943
|
-
L:
|
|
984
|
+
L: 116,
|
|
944
985
|
S: this,
|
|
945
986
|
C: (f, a) => f(...a)
|
|
946
987
|
});
|
|
@@ -957,7 +998,7 @@ var Peer = class {
|
|
|
957
998
|
sessionId: this.connection?.sessionId
|
|
958
999
|
}, {
|
|
959
1000
|
F: __dxlog_file4,
|
|
960
|
-
L:
|
|
1001
|
+
L: 125,
|
|
961
1002
|
S: this,
|
|
962
1003
|
C: (f, a) => f(...a)
|
|
963
1004
|
});
|
|
@@ -974,7 +1015,7 @@ var Peer = class {
|
|
|
974
1015
|
if (!this.connection) {
|
|
975
1016
|
invariant3(message.sessionId, void 0, {
|
|
976
1017
|
F: __dxlog_file4,
|
|
977
|
-
L:
|
|
1018
|
+
L: 145,
|
|
978
1019
|
S: this,
|
|
979
1020
|
A: [
|
|
980
1021
|
"message.sessionId",
|
|
@@ -995,7 +1036,7 @@ var Peer = class {
|
|
|
995
1036
|
err
|
|
996
1037
|
}, {
|
|
997
1038
|
F: __dxlog_file4,
|
|
998
|
-
L:
|
|
1039
|
+
L: 155,
|
|
999
1040
|
S: this,
|
|
1000
1041
|
C: (f, a) => f(...a)
|
|
1001
1042
|
});
|
|
@@ -1017,7 +1058,7 @@ var Peer = class {
|
|
|
1017
1058
|
async initiateConnection() {
|
|
1018
1059
|
invariant3(!this.initiating, "Initiation in progress.", {
|
|
1019
1060
|
F: __dxlog_file4,
|
|
1020
|
-
L:
|
|
1061
|
+
L: 172,
|
|
1021
1062
|
S: this,
|
|
1022
1063
|
A: [
|
|
1023
1064
|
"!this.initiating",
|
|
@@ -1026,7 +1067,7 @@ var Peer = class {
|
|
|
1026
1067
|
});
|
|
1027
1068
|
invariant3(!this.connection, "Already connected.", {
|
|
1028
1069
|
F: __dxlog_file4,
|
|
1029
|
-
L:
|
|
1070
|
+
L: 173,
|
|
1030
1071
|
S: this,
|
|
1031
1072
|
A: [
|
|
1032
1073
|
"!this.connection",
|
|
@@ -1041,7 +1082,7 @@ var Peer = class {
|
|
|
1041
1082
|
sessionId
|
|
1042
1083
|
}, {
|
|
1043
1084
|
F: __dxlog_file4,
|
|
1044
|
-
L:
|
|
1085
|
+
L: 175,
|
|
1045
1086
|
S: this,
|
|
1046
1087
|
C: (f, a) => f(...a)
|
|
1047
1088
|
});
|
|
@@ -1067,14 +1108,14 @@ var Peer = class {
|
|
|
1067
1108
|
remote: this.remoteInfo
|
|
1068
1109
|
}, {
|
|
1069
1110
|
F: __dxlog_file4,
|
|
1070
|
-
L:
|
|
1111
|
+
L: 192,
|
|
1071
1112
|
S: this,
|
|
1072
1113
|
C: (f, a) => f(...a)
|
|
1073
1114
|
});
|
|
1074
1115
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1075
1116
|
log4("ignoring response", void 0, {
|
|
1076
1117
|
F: __dxlog_file4,
|
|
1077
|
-
L:
|
|
1118
|
+
L: 194,
|
|
1078
1119
|
S: this,
|
|
1079
1120
|
C: (f, a) => f(...a)
|
|
1080
1121
|
});
|
|
@@ -1088,7 +1129,7 @@ var Peer = class {
|
|
|
1088
1129
|
remote: this.remoteInfo
|
|
1089
1130
|
}, {
|
|
1090
1131
|
F: __dxlog_file4,
|
|
1091
|
-
L:
|
|
1132
|
+
L: 198,
|
|
1092
1133
|
S: this,
|
|
1093
1134
|
C: (f, a) => f(...a)
|
|
1094
1135
|
});
|
|
@@ -1110,7 +1151,7 @@ var Peer = class {
|
|
|
1110
1151
|
remote: this.remoteInfo
|
|
1111
1152
|
}, {
|
|
1112
1153
|
F: __dxlog_file4,
|
|
1113
|
-
L:
|
|
1154
|
+
L: 211,
|
|
1114
1155
|
S: this,
|
|
1115
1156
|
C: (f, a) => f(...a)
|
|
1116
1157
|
});
|
|
@@ -1122,7 +1163,7 @@ var Peer = class {
|
|
|
1122
1163
|
try {
|
|
1123
1164
|
log4("opening connection as initiator", void 0, {
|
|
1124
1165
|
F: __dxlog_file4,
|
|
1125
|
-
L:
|
|
1166
|
+
L: 224,
|
|
1126
1167
|
S: this,
|
|
1127
1168
|
C: (f, a) => f(...a)
|
|
1128
1169
|
});
|
|
@@ -1136,7 +1177,7 @@ var Peer = class {
|
|
|
1136
1177
|
remote: this.remoteInfo
|
|
1137
1178
|
}, {
|
|
1138
1179
|
F: __dxlog_file4,
|
|
1139
|
-
L:
|
|
1180
|
+
L: 228,
|
|
1140
1181
|
S: this,
|
|
1141
1182
|
C: (f, a) => f(...a)
|
|
1142
1183
|
});
|
|
@@ -1144,7 +1185,7 @@ var Peer = class {
|
|
|
1144
1185
|
err
|
|
1145
1186
|
}, {
|
|
1146
1187
|
F: __dxlog_file4,
|
|
1147
|
-
L:
|
|
1188
|
+
L: 235,
|
|
1148
1189
|
S: this,
|
|
1149
1190
|
C: (f, a) => f(...a)
|
|
1150
1191
|
});
|
|
@@ -1167,13 +1208,13 @@ var Peer = class {
|
|
|
1167
1208
|
sessionId
|
|
1168
1209
|
}, {
|
|
1169
1210
|
F: __dxlog_file4,
|
|
1170
|
-
L:
|
|
1211
|
+
L: 249,
|
|
1171
1212
|
S: this,
|
|
1172
1213
|
C: (f, a) => f(...a)
|
|
1173
1214
|
});
|
|
1174
1215
|
invariant3(!this.connection, "Already connected.", {
|
|
1175
1216
|
F: __dxlog_file4,
|
|
1176
|
-
L:
|
|
1217
|
+
L: 256,
|
|
1177
1218
|
S: this,
|
|
1178
1219
|
A: [
|
|
1179
1220
|
"!this.connection",
|
|
@@ -1209,7 +1250,7 @@ var Peer = class {
|
|
|
1209
1250
|
initiator
|
|
1210
1251
|
}, {
|
|
1211
1252
|
F: __dxlog_file4,
|
|
1212
|
-
L:
|
|
1253
|
+
L: 280,
|
|
1213
1254
|
S: this,
|
|
1214
1255
|
C: (f, a) => f(...a)
|
|
1215
1256
|
});
|
|
@@ -1223,14 +1264,14 @@ var Peer = class {
|
|
|
1223
1264
|
};
|
|
1224
1265
|
log4("connection closed", logMeta, {
|
|
1225
1266
|
F: __dxlog_file4,
|
|
1226
|
-
L:
|
|
1267
|
+
L: 290,
|
|
1227
1268
|
S: this,
|
|
1228
1269
|
C: (f, a) => f(...a)
|
|
1229
1270
|
});
|
|
1230
1271
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1231
1272
|
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1232
1273
|
F: __dxlog_file4,
|
|
1233
|
-
L:
|
|
1274
|
+
L: 295,
|
|
1234
1275
|
S: this,
|
|
1235
1276
|
A: [
|
|
1236
1277
|
"this.connection === connection",
|
|
@@ -1245,7 +1286,7 @@ var Peer = class {
|
|
|
1245
1286
|
initiator
|
|
1246
1287
|
}, {
|
|
1247
1288
|
F: __dxlog_file4,
|
|
1248
|
-
L:
|
|
1289
|
+
L: 297,
|
|
1249
1290
|
S: this,
|
|
1250
1291
|
C: (f, a) => f(...a)
|
|
1251
1292
|
});
|
|
@@ -1262,7 +1303,7 @@ var Peer = class {
|
|
|
1262
1303
|
scheduleTask2(this._connectionCtx, () => {
|
|
1263
1304
|
log4("peer became available", logMeta, {
|
|
1264
1305
|
F: __dxlog_file4,
|
|
1265
|
-
L:
|
|
1306
|
+
L: 321,
|
|
1266
1307
|
S: this,
|
|
1267
1308
|
C: (f, a) => f(...a)
|
|
1268
1309
|
});
|
|
@@ -1286,7 +1327,7 @@ var Peer = class {
|
|
|
1286
1327
|
err
|
|
1287
1328
|
}, {
|
|
1288
1329
|
F: __dxlog_file4,
|
|
1289
|
-
L:
|
|
1330
|
+
L: 339,
|
|
1290
1331
|
S: this,
|
|
1291
1332
|
C: (f, a) => f(...a)
|
|
1292
1333
|
});
|
|
@@ -1299,7 +1340,7 @@ var Peer = class {
|
|
|
1299
1340
|
err
|
|
1300
1341
|
}, {
|
|
1301
1342
|
F: __dxlog_file4,
|
|
1302
|
-
L:
|
|
1343
|
+
L: 346,
|
|
1303
1344
|
S: this,
|
|
1304
1345
|
C: (f, a) => f(...a)
|
|
1305
1346
|
});
|
|
@@ -1318,7 +1359,7 @@ var Peer = class {
|
|
|
1318
1359
|
sessionId: connection.sessionId
|
|
1319
1360
|
}, {
|
|
1320
1361
|
F: __dxlog_file4,
|
|
1321
|
-
L:
|
|
1362
|
+
L: 371,
|
|
1322
1363
|
S: this,
|
|
1323
1364
|
C: (f, a) => f(...a)
|
|
1324
1365
|
});
|
|
@@ -1330,7 +1371,7 @@ var Peer = class {
|
|
|
1330
1371
|
sessionId: connection.sessionId
|
|
1331
1372
|
}, {
|
|
1332
1373
|
F: __dxlog_file4,
|
|
1333
|
-
L:
|
|
1374
|
+
L: 377,
|
|
1334
1375
|
S: this,
|
|
1335
1376
|
C: (f, a) => f(...a)
|
|
1336
1377
|
});
|
|
@@ -1341,7 +1382,7 @@ var Peer = class {
|
|
|
1341
1382
|
message
|
|
1342
1383
|
}, {
|
|
1343
1384
|
F: __dxlog_file4,
|
|
1344
|
-
L:
|
|
1385
|
+
L: 382,
|
|
1345
1386
|
S: this,
|
|
1346
1387
|
C: (f, a) => f(...a)
|
|
1347
1388
|
});
|
|
@@ -1356,7 +1397,7 @@ var Peer = class {
|
|
|
1356
1397
|
topic: this.topic
|
|
1357
1398
|
}, {
|
|
1358
1399
|
F: __dxlog_file4,
|
|
1359
|
-
L:
|
|
1400
|
+
L: 392,
|
|
1360
1401
|
S: this,
|
|
1361
1402
|
C: (f, a) => f(...a)
|
|
1362
1403
|
});
|
|
@@ -1392,6 +1433,46 @@ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm
|
|
|
1392
1433
|
var INITIATION_DELAY = 100;
|
|
1393
1434
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1394
1435
|
var Swarm = class {
|
|
1436
|
+
_topic;
|
|
1437
|
+
_ownPeer;
|
|
1438
|
+
_topology;
|
|
1439
|
+
_protocolProvider;
|
|
1440
|
+
_messenger;
|
|
1441
|
+
_transportFactory;
|
|
1442
|
+
_label;
|
|
1443
|
+
_connectionLimiter;
|
|
1444
|
+
_initiationDelay;
|
|
1445
|
+
_swarmMessenger;
|
|
1446
|
+
_ctx = new Context4(void 0, {
|
|
1447
|
+
F: __dxlog_file5,
|
|
1448
|
+
L: 39
|
|
1449
|
+
});
|
|
1450
|
+
_listeningHandle = void 0;
|
|
1451
|
+
/**
|
|
1452
|
+
* PeerInfo -> Peer.
|
|
1453
|
+
* @internal
|
|
1454
|
+
*/
|
|
1455
|
+
_peers = new ComplexMap2(PeerInfoHash);
|
|
1456
|
+
/**
|
|
1457
|
+
* Unique id of the swarm, local to the current peer, generated when swarm is joined.
|
|
1458
|
+
*/
|
|
1459
|
+
_instanceId = PublicKey4.random().toHex();
|
|
1460
|
+
/**
|
|
1461
|
+
* New connection to a peer is started.
|
|
1462
|
+
* @internal
|
|
1463
|
+
*/
|
|
1464
|
+
connectionAdded = new Event3();
|
|
1465
|
+
/**
|
|
1466
|
+
* Connection to a peer is dropped.
|
|
1467
|
+
* @internal
|
|
1468
|
+
*/
|
|
1469
|
+
disconnected = new Event3();
|
|
1470
|
+
/**
|
|
1471
|
+
* Connection is established to a new peer.
|
|
1472
|
+
* @internal
|
|
1473
|
+
*/
|
|
1474
|
+
connected = new Event3();
|
|
1475
|
+
errors = new ErrorStream2();
|
|
1395
1476
|
// TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
|
|
1396
1477
|
// TODO(burdon): Pass in object.
|
|
1397
1478
|
constructor(_topic, _ownPeer, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
|
|
@@ -1404,17 +1485,6 @@ var Swarm = class {
|
|
|
1404
1485
|
this._label = _label;
|
|
1405
1486
|
this._connectionLimiter = _connectionLimiter;
|
|
1406
1487
|
this._initiationDelay = _initiationDelay;
|
|
1407
|
-
this._ctx = new Context4(void 0, {
|
|
1408
|
-
F: __dxlog_file5,
|
|
1409
|
-
L: 38
|
|
1410
|
-
});
|
|
1411
|
-
this._listeningHandle = void 0;
|
|
1412
|
-
this._peers = new ComplexMap2(PeerInfoHash);
|
|
1413
|
-
this._instanceId = PublicKey4.random().toHex();
|
|
1414
|
-
this.connectionAdded = new Event3();
|
|
1415
|
-
this.disconnected = new Event3();
|
|
1416
|
-
this.connected = new Event3();
|
|
1417
|
-
this.errors = new ErrorStream2();
|
|
1418
1488
|
log5.trace("dxos.mesh.swarm.constructor", trace2.begin({
|
|
1419
1489
|
id: this._instanceId,
|
|
1420
1490
|
data: {
|
|
@@ -1423,7 +1493,7 @@ var Swarm = class {
|
|
|
1423
1493
|
}
|
|
1424
1494
|
}), {
|
|
1425
1495
|
F: __dxlog_file5,
|
|
1426
|
-
L:
|
|
1496
|
+
L: 89,
|
|
1427
1497
|
S: this,
|
|
1428
1498
|
C: (f, a) => f(...a)
|
|
1429
1499
|
});
|
|
@@ -1431,7 +1501,7 @@ var Swarm = class {
|
|
|
1431
1501
|
peerId: _ownPeer
|
|
1432
1502
|
}, {
|
|
1433
1503
|
F: __dxlog_file5,
|
|
1434
|
-
L:
|
|
1504
|
+
L: 93,
|
|
1435
1505
|
S: this,
|
|
1436
1506
|
C: (f, a) => f(...a)
|
|
1437
1507
|
});
|
|
@@ -1446,7 +1516,7 @@ var Swarm = class {
|
|
|
1446
1516
|
id: this._instanceId
|
|
1447
1517
|
}), {
|
|
1448
1518
|
F: __dxlog_file5,
|
|
1449
|
-
L:
|
|
1519
|
+
L: 102,
|
|
1450
1520
|
S: this,
|
|
1451
1521
|
C: (f, a) => f(...a)
|
|
1452
1522
|
});
|
|
@@ -1472,7 +1542,7 @@ var Swarm = class {
|
|
|
1472
1542
|
async open() {
|
|
1473
1543
|
invariant4(!this._listeningHandle, void 0, {
|
|
1474
1544
|
F: __dxlog_file5,
|
|
1475
|
-
L:
|
|
1545
|
+
L: 133,
|
|
1476
1546
|
S: this,
|
|
1477
1547
|
A: [
|
|
1478
1548
|
"!this._listeningHandle",
|
|
@@ -1487,7 +1557,7 @@ var Swarm = class {
|
|
|
1487
1557
|
err
|
|
1488
1558
|
}, {
|
|
1489
1559
|
F: __dxlog_file5,
|
|
1490
|
-
L:
|
|
1560
|
+
L: 141,
|
|
1491
1561
|
S: this,
|
|
1492
1562
|
C: (f, a) => f(...a)
|
|
1493
1563
|
}));
|
|
@@ -1497,7 +1567,7 @@ var Swarm = class {
|
|
|
1497
1567
|
async destroy() {
|
|
1498
1568
|
log5("destroying...", void 0, {
|
|
1499
1569
|
F: __dxlog_file5,
|
|
1500
|
-
L:
|
|
1570
|
+
L: 147,
|
|
1501
1571
|
S: this,
|
|
1502
1572
|
C: (f, a) => f(...a)
|
|
1503
1573
|
});
|
|
@@ -1508,7 +1578,7 @@ var Swarm = class {
|
|
|
1508
1578
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1509
1579
|
log5("destroyed", void 0, {
|
|
1510
1580
|
F: __dxlog_file5,
|
|
1511
|
-
L:
|
|
1581
|
+
L: 154,
|
|
1512
1582
|
S: this,
|
|
1513
1583
|
C: (f, a) => f(...a)
|
|
1514
1584
|
});
|
|
@@ -1516,7 +1586,7 @@ var Swarm = class {
|
|
|
1516
1586
|
async setTopology(topology) {
|
|
1517
1587
|
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1518
1588
|
F: __dxlog_file5,
|
|
1519
|
-
L:
|
|
1589
|
+
L: 158,
|
|
1520
1590
|
S: this,
|
|
1521
1591
|
A: [
|
|
1522
1592
|
"!this._ctx.disposed",
|
|
@@ -1531,7 +1601,7 @@ var Swarm = class {
|
|
|
1531
1601
|
topology: getClassName(topology)
|
|
1532
1602
|
}, {
|
|
1533
1603
|
F: __dxlog_file5,
|
|
1534
|
-
L:
|
|
1604
|
+
L: 162,
|
|
1535
1605
|
S: this,
|
|
1536
1606
|
C: (f, a) => f(...a)
|
|
1537
1607
|
});
|
|
@@ -1545,14 +1615,14 @@ var Swarm = class {
|
|
|
1545
1615
|
swarmEvent
|
|
1546
1616
|
}, {
|
|
1547
1617
|
F: __dxlog_file5,
|
|
1548
|
-
L:
|
|
1618
|
+
L: 175,
|
|
1549
1619
|
S: this,
|
|
1550
1620
|
C: (f, a) => f(...a)
|
|
1551
1621
|
});
|
|
1552
1622
|
if (this._ctx.disposed) {
|
|
1553
1623
|
log5("swarm event ignored for disposed swarm", void 0, {
|
|
1554
1624
|
F: __dxlog_file5,
|
|
1555
|
-
L:
|
|
1625
|
+
L: 178,
|
|
1556
1626
|
S: this,
|
|
1557
1627
|
C: (f, a) => f(...a)
|
|
1558
1628
|
});
|
|
@@ -1565,7 +1635,7 @@ var Swarm = class {
|
|
|
1565
1635
|
peerId
|
|
1566
1636
|
}, {
|
|
1567
1637
|
F: __dxlog_file5,
|
|
1568
|
-
L:
|
|
1638
|
+
L: 185,
|
|
1569
1639
|
S: this,
|
|
1570
1640
|
C: (f, a) => f(...a)
|
|
1571
1641
|
});
|
|
@@ -1579,13 +1649,13 @@ var Swarm = class {
|
|
|
1579
1649
|
if (this._isConnectionEstablishmentInProgress(peer)) {
|
|
1580
1650
|
log5(`destroying peer, state: ${peer.connection?.state}`, void 0, {
|
|
1581
1651
|
F: __dxlog_file5,
|
|
1582
|
-
L:
|
|
1652
|
+
L: 196,
|
|
1583
1653
|
S: this,
|
|
1584
1654
|
C: (f, a) => f(...a)
|
|
1585
1655
|
});
|
|
1586
1656
|
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log5.catch(err, void 0, {
|
|
1587
1657
|
F: __dxlog_file5,
|
|
1588
|
-
L:
|
|
1658
|
+
L: 197,
|
|
1589
1659
|
S: this,
|
|
1590
1660
|
C: (f, a) => f(...a)
|
|
1591
1661
|
}));
|
|
@@ -1595,7 +1665,7 @@ var Swarm = class {
|
|
|
1595
1665
|
peer: swarmEvent.peerLeft.peer.peerKey
|
|
1596
1666
|
}, {
|
|
1597
1667
|
F: __dxlog_file5,
|
|
1598
|
-
L:
|
|
1668
|
+
L: 200,
|
|
1599
1669
|
S: this,
|
|
1600
1670
|
C: (f, a) => f(...a)
|
|
1601
1671
|
});
|
|
@@ -1608,14 +1678,14 @@ var Swarm = class {
|
|
|
1608
1678
|
message
|
|
1609
1679
|
}, {
|
|
1610
1680
|
F: __dxlog_file5,
|
|
1611
|
-
L:
|
|
1681
|
+
L: 209,
|
|
1612
1682
|
S: this,
|
|
1613
1683
|
C: (f, a) => f(...a)
|
|
1614
1684
|
});
|
|
1615
1685
|
if (this._ctx.disposed) {
|
|
1616
1686
|
log5("ignored for disposed swarm", void 0, {
|
|
1617
1687
|
F: __dxlog_file5,
|
|
1618
|
-
L:
|
|
1688
|
+
L: 211,
|
|
1619
1689
|
S: this,
|
|
1620
1690
|
C: (f, a) => f(...a)
|
|
1621
1691
|
});
|
|
@@ -1625,7 +1695,7 @@ var Swarm = class {
|
|
|
1625
1695
|
}
|
|
1626
1696
|
invariant4(message.author, void 0, {
|
|
1627
1697
|
F: __dxlog_file5,
|
|
1628
|
-
L:
|
|
1698
|
+
L: 216,
|
|
1629
1699
|
S: this,
|
|
1630
1700
|
A: [
|
|
1631
1701
|
"message.author",
|
|
@@ -1637,7 +1707,7 @@ var Swarm = class {
|
|
|
1637
1707
|
message
|
|
1638
1708
|
}, {
|
|
1639
1709
|
F: __dxlog_file5,
|
|
1640
|
-
L:
|
|
1710
|
+
L: 218,
|
|
1641
1711
|
S: this,
|
|
1642
1712
|
C: (f, a) => f(...a)
|
|
1643
1713
|
});
|
|
@@ -1650,7 +1720,7 @@ var Swarm = class {
|
|
|
1650
1720
|
message
|
|
1651
1721
|
}, {
|
|
1652
1722
|
F: __dxlog_file5,
|
|
1653
|
-
L:
|
|
1723
|
+
L: 222,
|
|
1654
1724
|
S: this,
|
|
1655
1725
|
C: (f, a) => f(...a)
|
|
1656
1726
|
});
|
|
@@ -1678,14 +1748,14 @@ var Swarm = class {
|
|
|
1678
1748
|
message
|
|
1679
1749
|
}, {
|
|
1680
1750
|
F: __dxlog_file5,
|
|
1681
|
-
L:
|
|
1751
|
+
L: 247,
|
|
1682
1752
|
S: this,
|
|
1683
1753
|
C: (f, a) => f(...a)
|
|
1684
1754
|
});
|
|
1685
1755
|
if (this._ctx.disposed) {
|
|
1686
1756
|
log5.info("ignored for offline swarm", void 0, {
|
|
1687
1757
|
F: __dxlog_file5,
|
|
1688
|
-
L:
|
|
1758
|
+
L: 249,
|
|
1689
1759
|
S: this,
|
|
1690
1760
|
C: (f, a) => f(...a)
|
|
1691
1761
|
});
|
|
@@ -1693,7 +1763,7 @@ var Swarm = class {
|
|
|
1693
1763
|
}
|
|
1694
1764
|
invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1695
1765
|
F: __dxlog_file5,
|
|
1696
|
-
L:
|
|
1766
|
+
L: 252,
|
|
1697
1767
|
S: this,
|
|
1698
1768
|
A: [
|
|
1699
1769
|
"message.recipient.peerKey === this._ownPeer.peerKey",
|
|
@@ -1702,7 +1772,7 @@ var Swarm = class {
|
|
|
1702
1772
|
});
|
|
1703
1773
|
invariant4(message.topic?.equals(this._topic), void 0, {
|
|
1704
1774
|
F: __dxlog_file5,
|
|
1705
|
-
L:
|
|
1775
|
+
L: 256,
|
|
1706
1776
|
S: this,
|
|
1707
1777
|
A: [
|
|
1708
1778
|
"message.topic?.equals(this._topic)",
|
|
@@ -1711,7 +1781,7 @@ var Swarm = class {
|
|
|
1711
1781
|
});
|
|
1712
1782
|
invariant4(message.author, void 0, {
|
|
1713
1783
|
F: __dxlog_file5,
|
|
1714
|
-
L:
|
|
1784
|
+
L: 257,
|
|
1715
1785
|
S: this,
|
|
1716
1786
|
A: [
|
|
1717
1787
|
"message.author",
|
|
@@ -1732,13 +1802,13 @@ var Swarm = class {
|
|
|
1732
1802
|
async goOnline() {
|
|
1733
1803
|
this._ctx = new Context4(void 0, {
|
|
1734
1804
|
F: __dxlog_file5,
|
|
1735
|
-
L:
|
|
1805
|
+
L: 273
|
|
1736
1806
|
});
|
|
1737
1807
|
}
|
|
1738
1808
|
_getOrCreatePeer(peerInfo) {
|
|
1739
1809
|
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
|
|
1740
1810
|
F: __dxlog_file5,
|
|
1741
|
-
L:
|
|
1811
|
+
L: 277,
|
|
1742
1812
|
S: this,
|
|
1743
1813
|
A: [
|
|
1744
1814
|
"peerInfo.peerKey",
|
|
@@ -1758,7 +1828,7 @@ var Swarm = class {
|
|
|
1758
1828
|
if (this._isUnregistered(peer)) {
|
|
1759
1829
|
log5.verbose("ignored onDisconnected for unregistered peer", void 0, {
|
|
1760
1830
|
F: __dxlog_file5,
|
|
1761
|
-
L:
|
|
1831
|
+
L: 297,
|
|
1762
1832
|
S: this,
|
|
1763
1833
|
C: (f, a) => f(...a)
|
|
1764
1834
|
});
|
|
@@ -1776,7 +1846,7 @@ var Swarm = class {
|
|
|
1776
1846
|
peerInfo
|
|
1777
1847
|
}, {
|
|
1778
1848
|
F: __dxlog_file5,
|
|
1779
|
-
L:
|
|
1849
|
+
L: 311,
|
|
1780
1850
|
S: this,
|
|
1781
1851
|
C: (f, a) => f(...a)
|
|
1782
1852
|
});
|
|
@@ -1803,14 +1873,14 @@ var Swarm = class {
|
|
|
1803
1873
|
reason
|
|
1804
1874
|
}, {
|
|
1805
1875
|
F: __dxlog_file5,
|
|
1806
|
-
L:
|
|
1876
|
+
L: 333,
|
|
1807
1877
|
S: this,
|
|
1808
1878
|
C: (f, a) => f(...a)
|
|
1809
1879
|
});
|
|
1810
1880
|
const peer = this._peers.get(peerInfo);
|
|
1811
1881
|
invariant4(peer, void 0, {
|
|
1812
1882
|
F: __dxlog_file5,
|
|
1813
|
-
L:
|
|
1883
|
+
L: 335,
|
|
1814
1884
|
S: this,
|
|
1815
1885
|
A: [
|
|
1816
1886
|
"peer",
|
|
@@ -1840,7 +1910,7 @@ var Swarm = class {
|
|
|
1840
1910
|
} catch (err) {
|
|
1841
1911
|
log5("initiation error", err, {
|
|
1842
1912
|
F: __dxlog_file5,
|
|
1843
|
-
L:
|
|
1913
|
+
L: 362,
|
|
1844
1914
|
S: this,
|
|
1845
1915
|
C: (f, a) => f(...a)
|
|
1846
1916
|
});
|
|
@@ -1871,7 +1941,7 @@ var Swarm = class {
|
|
|
1871
1941
|
remotePeer
|
|
1872
1942
|
}, {
|
|
1873
1943
|
F: __dxlog_file5,
|
|
1874
|
-
L:
|
|
1944
|
+
L: 390,
|
|
1875
1945
|
S: this,
|
|
1876
1946
|
C: (f, a) => f(...a)
|
|
1877
1947
|
});
|
|
@@ -1890,7 +1960,7 @@ var Swarm = class {
|
|
|
1890
1960
|
remotePeer
|
|
1891
1961
|
}, {
|
|
1892
1962
|
F: __dxlog_file5,
|
|
1893
|
-
L:
|
|
1963
|
+
L: 406,
|
|
1894
1964
|
S: this,
|
|
1895
1965
|
C: (f, a) => f(...a)
|
|
1896
1966
|
});
|
|
@@ -1900,7 +1970,7 @@ var Swarm = class {
|
|
|
1900
1970
|
remotePeer
|
|
1901
1971
|
}, {
|
|
1902
1972
|
F: __dxlog_file5,
|
|
1903
|
-
L:
|
|
1973
|
+
L: 409,
|
|
1904
1974
|
S: this,
|
|
1905
1975
|
C: (f, a) => f(...a)
|
|
1906
1976
|
});
|
|
@@ -1956,15 +2026,16 @@ import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
|
|
|
1956
2026
|
import { ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
1957
2027
|
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
1958
2028
|
var SwarmMapper = class {
|
|
2029
|
+
_swarm;
|
|
2030
|
+
_subscriptions = new SubscriptionList();
|
|
2031
|
+
_connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
|
|
2032
|
+
_peers = new ComplexMap3(PeerInfoHash2);
|
|
2033
|
+
mapUpdated = new Event4();
|
|
1959
2034
|
get peers() {
|
|
1960
2035
|
return Array.from(this._peers.values());
|
|
1961
2036
|
}
|
|
1962
2037
|
constructor(_swarm) {
|
|
1963
2038
|
this._swarm = _swarm;
|
|
1964
|
-
this._subscriptions = new SubscriptionList();
|
|
1965
|
-
this._connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
|
|
1966
|
-
this._peers = new ComplexMap3(PeerInfoHash2);
|
|
1967
|
-
this.mapUpdated = new Event4();
|
|
1968
2039
|
this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
|
|
1969
2040
|
this._update();
|
|
1970
2041
|
this._connectionSubscriptions.set(connection.remoteInfo, connection.stateChanged.on(() => {
|
|
@@ -2030,20 +2101,21 @@ import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
|
2030
2101
|
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
2031
2102
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
|
|
2032
2103
|
var ConnectionLimiter = class {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
});
|
|
2104
|
+
_ctx = new Context5(void 0, {
|
|
2105
|
+
F: __dxlog_file7,
|
|
2106
|
+
L: 23
|
|
2107
|
+
});
|
|
2108
|
+
_maxConcurrentInitConnections;
|
|
2109
|
+
/**
|
|
2110
|
+
* Queue of promises to resolve when initiating connections amount is below the limit.
|
|
2111
|
+
*/
|
|
2112
|
+
_waitingPromises = new ComplexMap4(PublicKey6.hash);
|
|
2113
|
+
resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
|
|
2114
|
+
Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
|
|
2115
|
+
resolve();
|
|
2046
2116
|
});
|
|
2117
|
+
});
|
|
2118
|
+
constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
|
|
2047
2119
|
this._maxConcurrentInitConnections = maxConcurrentInitConnections;
|
|
2048
2120
|
}
|
|
2049
2121
|
/**
|
|
@@ -2110,22 +2182,20 @@ import { raise } from "@dxos/debug";
|
|
|
2110
2182
|
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
2111
2183
|
import { ComplexMap as ComplexMap5 } from "@dxos/util";
|
|
2112
2184
|
var CONNECTION_GC_THRESHOLD = 1e3 * 60 * 15;
|
|
2113
|
-
var EventType = /* @__PURE__ */ function(EventType2) {
|
|
2185
|
+
var EventType = /* @__PURE__ */ (function(EventType2) {
|
|
2114
2186
|
EventType2["CONNECTION_STATE_CHANGED"] = "CONNECTION_STATE_CHANGED";
|
|
2115
2187
|
EventType2["PROTOCOL_ERROR"] = "PROTOCOL_ERROR";
|
|
2116
2188
|
EventType2["PROTOCOL_EXTENSIONS_INITIALIZED"] = "PROTOCOL_EXTENSIONS_INITIALIZED";
|
|
2117
2189
|
EventType2["PROTOCOL_EXTENSIONS_HANDSHAKE"] = "PROTOCOL_EXTENSIONS_HANDSHAKE";
|
|
2118
2190
|
EventType2["PROTOCOL_HANDSHAKE"] = "PROTOCOL_HANDSHAKE";
|
|
2119
2191
|
return EventType2;
|
|
2120
|
-
}({});
|
|
2192
|
+
})({});
|
|
2121
2193
|
var ConnectionLog = class {
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
this.update = new Event5();
|
|
2128
|
-
}
|
|
2194
|
+
/**
|
|
2195
|
+
* SwarmId => info
|
|
2196
|
+
*/
|
|
2197
|
+
_swarms = new ComplexMap5(PublicKey7.hash);
|
|
2198
|
+
update = new Event5();
|
|
2129
2199
|
getSwarmInfo(swarmId) {
|
|
2130
2200
|
return this._swarms.get(swarmId) ?? raise(new Error(`Swarm not found: ${swarmId}`));
|
|
2131
2201
|
}
|
|
@@ -2213,17 +2283,23 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
2213
2283
|
}
|
|
2214
2284
|
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2215
2285
|
var SwarmNetworkManager = class {
|
|
2286
|
+
/**
|
|
2287
|
+
* @internal
|
|
2288
|
+
*/
|
|
2289
|
+
_swarms = new ComplexMap6(PublicKey8.hash);
|
|
2290
|
+
_mappers = new ComplexMap6(PublicKey8.hash);
|
|
2291
|
+
_transportFactory;
|
|
2292
|
+
_signalManager;
|
|
2293
|
+
_messenger;
|
|
2294
|
+
_signalConnection;
|
|
2295
|
+
_connectionLimiter;
|
|
2296
|
+
_connectionLog;
|
|
2297
|
+
_instanceId = PublicKey8.random().toHex();
|
|
2298
|
+
_peerInfo = void 0;
|
|
2299
|
+
_connectionState = ConnectionState2.ONLINE;
|
|
2300
|
+
connectionStateChanged = new Event6();
|
|
2301
|
+
topicsUpdated = new Event6();
|
|
2216
2302
|
constructor({ transportFactory, signalManager, enableDevtoolsLogging, peerInfo }) {
|
|
2217
|
-
/**
|
|
2218
|
-
* @internal
|
|
2219
|
-
*/
|
|
2220
|
-
this._swarms = new ComplexMap6(PublicKey8.hash);
|
|
2221
|
-
this._mappers = new ComplexMap6(PublicKey8.hash);
|
|
2222
|
-
this._instanceId = PublicKey8.random().toHex();
|
|
2223
|
-
this._peerInfo = void 0;
|
|
2224
|
-
this._connectionState = ConnectionState2.ONLINE;
|
|
2225
|
-
this.connectionStateChanged = new Event6();
|
|
2226
|
-
this.topicsUpdated = new Event6();
|
|
2227
2303
|
this._transportFactory = transportFactory;
|
|
2228
2304
|
this._signalManager = signalManager;
|
|
2229
2305
|
this._signalManager.swarmEvent.on((event) => this._swarms.get(event.topic)?.onSwarmEvent(event));
|
|
@@ -2460,6 +2536,7 @@ _ts_decorate4([
|
|
|
2460
2536
|
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2461
2537
|
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
2462
2538
|
var FullyConnectedTopology = class {
|
|
2539
|
+
_controller;
|
|
2463
2540
|
toString() {
|
|
2464
2541
|
return "FullyConnectedTopology";
|
|
2465
2542
|
}
|
|
@@ -2504,9 +2581,13 @@ var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topo
|
|
|
2504
2581
|
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2505
2582
|
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2506
2583
|
var MMSTTopology = class {
|
|
2584
|
+
_originateConnections;
|
|
2585
|
+
_maxPeers;
|
|
2586
|
+
_sampleSize;
|
|
2587
|
+
_controller;
|
|
2588
|
+
_sampleCollected = false;
|
|
2589
|
+
_lastAction = /* @__PURE__ */ new Date(0);
|
|
2507
2590
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2508
|
-
this._sampleCollected = false;
|
|
2509
|
-
this._lastAction = /* @__PURE__ */ new Date(0);
|
|
2510
2591
|
this._originateConnections = originateConnections;
|
|
2511
2592
|
this._maxPeers = maxPeers;
|
|
2512
2593
|
this._sampleSize = sampleSize;
|
|
@@ -2708,6 +2789,8 @@ import { invariant as invariant9 } from "@dxos/invariant";
|
|
|
2708
2789
|
import { log as log10 } from "@dxos/log";
|
|
2709
2790
|
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
2710
2791
|
var StarTopology = class {
|
|
2792
|
+
_centralPeer;
|
|
2793
|
+
_controller;
|
|
2711
2794
|
constructor(_centralPeer) {
|
|
2712
2795
|
this._centralPeer = _centralPeer;
|
|
2713
2796
|
}
|
|
@@ -2827,20 +2910,21 @@ var MemoryTransportFactory = {
|
|
|
2827
2910
|
createTransport: (options) => new MemoryTransport(options)
|
|
2828
2911
|
};
|
|
2829
2912
|
var MemoryTransport = class _MemoryTransport {
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2913
|
+
_options;
|
|
2914
|
+
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
2915
|
+
static _connections = new ComplexMap7(PublicKey9.hash);
|
|
2916
|
+
_instanceId = PublicKey9.random();
|
|
2917
|
+
_remote = new Trigger2();
|
|
2918
|
+
_outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2919
|
+
_incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2920
|
+
_closed = false;
|
|
2921
|
+
_remoteInstanceId;
|
|
2922
|
+
_remoteConnection;
|
|
2923
|
+
closed = new Event7();
|
|
2924
|
+
connected = new Event7();
|
|
2925
|
+
errors = new ErrorStream3();
|
|
2834
2926
|
constructor(_options) {
|
|
2835
2927
|
this._options = _options;
|
|
2836
|
-
this._instanceId = PublicKey9.random();
|
|
2837
|
-
this._remote = new Trigger2();
|
|
2838
|
-
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2839
|
-
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2840
|
-
this._closed = false;
|
|
2841
|
-
this.closed = new Event7();
|
|
2842
|
-
this.connected = new Event7();
|
|
2843
|
-
this.errors = new ErrorStream3();
|
|
2844
2928
|
invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2845
2929
|
F: __dxlog_file12,
|
|
2846
2930
|
L: 64,
|
|
@@ -2992,13 +3076,13 @@ _ts_decorate5([
|
|
|
2992
3076
|
var toError = (err) => err instanceof Error ? err : new Error(String(err));
|
|
2993
3077
|
|
|
2994
3078
|
// src/transport/transport.ts
|
|
2995
|
-
var TransportKind = /* @__PURE__ */ function(TransportKind2) {
|
|
3079
|
+
var TransportKind = /* @__PURE__ */ (function(TransportKind2) {
|
|
2996
3080
|
TransportKind2["WEB_RTC"] = "WEB-RTC";
|
|
2997
3081
|
TransportKind2["WEB_RTC_PROXY"] = "WEB-RTC_PROXY";
|
|
2998
3082
|
TransportKind2["MEMORY"] = "MEMORY";
|
|
2999
3083
|
TransportKind2["TCP"] = "TCP";
|
|
3000
3084
|
return TransportKind2;
|
|
3001
|
-
}({});
|
|
3085
|
+
})({});
|
|
3002
3086
|
|
|
3003
3087
|
// src/transport/webrtc/rtc-connection-factory.ts
|
|
3004
3088
|
import { Mutex } from "@dxos/async";
|
|
@@ -3014,12 +3098,8 @@ var BrowserRtcConnectionFactory = class {
|
|
|
3014
3098
|
}
|
|
3015
3099
|
};
|
|
3016
3100
|
var NodeRtcConnectionFactory = class _NodeRtcConnectionFactory {
|
|
3017
|
-
static
|
|
3018
|
-
|
|
3019
|
-
}
|
|
3020
|
-
static {
|
|
3021
|
-
this._cleanupMutex = new Mutex();
|
|
3022
|
-
}
|
|
3101
|
+
static _createdConnections = 0;
|
|
3102
|
+
static _cleanupMutex = new Mutex();
|
|
3023
3103
|
// This should be inside the function to avoid triggering `eval` in the global scope.
|
|
3024
3104
|
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
3025
3105
|
// TODO(burdon): Do imports here?
|
|
@@ -3050,7 +3130,7 @@ var getRtcConnectionFactory = () => {
|
|
|
3050
3130
|
};
|
|
3051
3131
|
|
|
3052
3132
|
// src/transport/webrtc/rtc-peer-connection.ts
|
|
3053
|
-
import {
|
|
3133
|
+
import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } from "@dxos/async";
|
|
3054
3134
|
import { invariant as invariant12 } from "@dxos/invariant";
|
|
3055
3135
|
import { log as log13, logInfo as logInfo4 } from "@dxos/log";
|
|
3056
3136
|
import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
|
|
@@ -3117,8 +3197,17 @@ var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/tran
|
|
|
3117
3197
|
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
3118
3198
|
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3119
3199
|
var RtcTransportChannel = class extends Resource {
|
|
3200
|
+
_connection;
|
|
3201
|
+
_options;
|
|
3202
|
+
closed = new AsyncEvent();
|
|
3203
|
+
connected = new AsyncEvent();
|
|
3204
|
+
errors = new ErrorStream4();
|
|
3205
|
+
_channel;
|
|
3206
|
+
_stream;
|
|
3207
|
+
_streamDataFlushedCallback = null;
|
|
3208
|
+
_isChannelCreationInProgress = false;
|
|
3120
3209
|
constructor(_connection, _options) {
|
|
3121
|
-
super(), this._connection = _connection, this._options = _options
|
|
3210
|
+
super(), this._connection = _connection, this._options = _options;
|
|
3122
3211
|
}
|
|
3123
3212
|
get isRtcChannelCreationInProgress() {
|
|
3124
3213
|
return this._isChannelCreationInProgress;
|
|
@@ -3131,7 +3220,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3131
3220
|
async _open() {
|
|
3132
3221
|
invariant11(!this._isChannelCreationInProgress, void 0, {
|
|
3133
3222
|
F: __dxlog_file13,
|
|
3134
|
-
L:
|
|
3223
|
+
L: 57,
|
|
3135
3224
|
S: this,
|
|
3136
3225
|
A: [
|
|
3137
3226
|
"!this._isChannelCreationInProgress",
|
|
@@ -3148,14 +3237,16 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3148
3237
|
}
|
|
3149
3238
|
}).catch((err) => {
|
|
3150
3239
|
if (this.isOpen) {
|
|
3151
|
-
const error = err instanceof Error ? err : new ConnectivityError2(
|
|
3240
|
+
const error = err instanceof Error ? err : new ConnectivityError2({
|
|
3241
|
+
message: `Failed to create a channel: ${JSON.stringify(err?.message)}`
|
|
3242
|
+
});
|
|
3152
3243
|
this.errors.raise(error);
|
|
3153
3244
|
} else {
|
|
3154
3245
|
log12.verbose("connection establishment failed after transport was closed", {
|
|
3155
3246
|
err
|
|
3156
3247
|
}, {
|
|
3157
3248
|
F: __dxlog_file13,
|
|
3158
|
-
L:
|
|
3249
|
+
L: 77,
|
|
3159
3250
|
S: this,
|
|
3160
3251
|
C: (f, a) => f(...a)
|
|
3161
3252
|
});
|
|
@@ -3173,7 +3264,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3173
3264
|
this.closed.emit();
|
|
3174
3265
|
log12("closed", void 0, {
|
|
3175
3266
|
F: __dxlog_file13,
|
|
3176
|
-
L:
|
|
3267
|
+
L: 93,
|
|
3177
3268
|
S: this,
|
|
3178
3269
|
C: (f, a) => f(...a)
|
|
3179
3270
|
});
|
|
@@ -3186,7 +3277,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3186
3277
|
topic: this._options.topic
|
|
3187
3278
|
}, {
|
|
3188
3279
|
F: __dxlog_file13,
|
|
3189
|
-
L:
|
|
3280
|
+
L: 100,
|
|
3190
3281
|
S: this,
|
|
3191
3282
|
C: (f, a) => f(...a)
|
|
3192
3283
|
});
|
|
@@ -3195,7 +3286,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3195
3286
|
}
|
|
3196
3287
|
log12("onopen", void 0, {
|
|
3197
3288
|
F: __dxlog_file13,
|
|
3198
|
-
L:
|
|
3289
|
+
L: 105,
|
|
3199
3290
|
S: this,
|
|
3200
3291
|
C: (f, a) => f(...a)
|
|
3201
3292
|
});
|
|
@@ -3213,7 +3304,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3213
3304
|
onclose: async () => {
|
|
3214
3305
|
log12("onclose", void 0, {
|
|
3215
3306
|
F: __dxlog_file13,
|
|
3216
|
-
L:
|
|
3307
|
+
L: 118,
|
|
3217
3308
|
S: this,
|
|
3218
3309
|
C: (f, a) => f(...a)
|
|
3219
3310
|
});
|
|
@@ -3223,7 +3314,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3223
3314
|
if (!this._stream) {
|
|
3224
3315
|
log12.warn("ignoring message on a closed channel", void 0, {
|
|
3225
3316
|
F: __dxlog_file13,
|
|
3226
|
-
L:
|
|
3317
|
+
L: 124,
|
|
3227
3318
|
S: this,
|
|
3228
3319
|
C: (f, a) => f(...a)
|
|
3229
3320
|
});
|
|
@@ -3254,7 +3345,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3254
3345
|
if (!this._channel) {
|
|
3255
3346
|
log12.warn("writing to a channel after a connection was closed", void 0, {
|
|
3256
3347
|
F: __dxlog_file13,
|
|
3257
|
-
L:
|
|
3348
|
+
L: 154,
|
|
3258
3349
|
S: this,
|
|
3259
3350
|
C: (f, a) => f(...a)
|
|
3260
3351
|
});
|
|
@@ -3277,7 +3368,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3277
3368
|
if (this._streamDataFlushedCallback !== null) {
|
|
3278
3369
|
log12.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3279
3370
|
F: __dxlog_file13,
|
|
3280
|
-
L:
|
|
3371
|
+
L: 175,
|
|
3281
3372
|
S: this,
|
|
3282
3373
|
C: (f, a) => f(...a)
|
|
3283
3374
|
});
|
|
@@ -3293,7 +3384,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3293
3384
|
} catch (error) {
|
|
3294
3385
|
log12.catch(error, void 0, {
|
|
3295
3386
|
F: __dxlog_file13,
|
|
3296
|
-
L:
|
|
3387
|
+
L: 187,
|
|
3297
3388
|
S: this,
|
|
3298
3389
|
C: (f, a) => f(...a)
|
|
3299
3390
|
});
|
|
@@ -3345,14 +3436,27 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
3345
3436
|
}
|
|
3346
3437
|
var __dxlog_file14 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
|
|
3347
3438
|
var RtcPeerConnection = class {
|
|
3439
|
+
_factory;
|
|
3440
|
+
_options;
|
|
3441
|
+
// A peer who is not the initiator waits for another party to open a channel.
|
|
3442
|
+
_channelCreatedCallbacks = /* @__PURE__ */ new Map();
|
|
3443
|
+
// Channels indexed by topic.
|
|
3444
|
+
_transportChannels = /* @__PURE__ */ new Map();
|
|
3445
|
+
_dataChannels = /* @__PURE__ */ new Map();
|
|
3446
|
+
// A peer is ready to receive ICE candidates when local and remote description were set.
|
|
3447
|
+
_readyForCandidates = new Trigger3();
|
|
3448
|
+
_offerProcessingMutex = new Mutex2();
|
|
3449
|
+
/**
|
|
3450
|
+
* Can't use peer.connection.initiator, because if two connections to the same peer are created in
|
|
3451
|
+
* different swarms, we might be the initiator of the first one, but not of the other one.
|
|
3452
|
+
* Use a stable peer keypair property (key ordering) to decide who's acting as the initiator of
|
|
3453
|
+
* transport connection establishment and data channel creation.
|
|
3454
|
+
*/
|
|
3455
|
+
_initiator;
|
|
3456
|
+
_connection;
|
|
3348
3457
|
constructor(_factory, _options) {
|
|
3349
3458
|
this._factory = _factory;
|
|
3350
3459
|
this._options = _options;
|
|
3351
|
-
this._channelCreatedCallbacks = /* @__PURE__ */ new Map();
|
|
3352
|
-
this._transportChannels = /* @__PURE__ */ new Map();
|
|
3353
|
-
this._dataChannels = /* @__PURE__ */ new Map();
|
|
3354
|
-
this._readyForCandidates = new Trigger3();
|
|
3355
|
-
this._offerProcessingMutex = new Mutex2();
|
|
3356
3460
|
this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
|
|
3357
3461
|
}
|
|
3358
3462
|
get transportChannelCount() {
|
|
@@ -3380,7 +3484,7 @@ var RtcPeerConnection = class {
|
|
|
3380
3484
|
}
|
|
3381
3485
|
log13("waiting for initiator-peer to open a data channel", void 0, {
|
|
3382
3486
|
F: __dxlog_file14,
|
|
3383
|
-
L:
|
|
3487
|
+
L: 96,
|
|
3384
3488
|
S: this,
|
|
3385
3489
|
C: (f, a) => f(...a)
|
|
3386
3490
|
});
|
|
@@ -3411,7 +3515,7 @@ var RtcPeerConnection = class {
|
|
|
3411
3515
|
remotePeer: this._options.remotePeerKey
|
|
3412
3516
|
}), {
|
|
3413
3517
|
F: __dxlog_file14,
|
|
3414
|
-
L:
|
|
3518
|
+
L: 121,
|
|
3415
3519
|
S: this,
|
|
3416
3520
|
C: (f, a) => f(...a)
|
|
3417
3521
|
});
|
|
@@ -3422,7 +3526,7 @@ var RtcPeerConnection = class {
|
|
|
3422
3526
|
onnegotiationneeded: async () => {
|
|
3423
3527
|
invariant12(this._initiator, void 0, {
|
|
3424
3528
|
F: __dxlog_file14,
|
|
3425
|
-
L:
|
|
3529
|
+
L: 136,
|
|
3426
3530
|
S: this,
|
|
3427
3531
|
A: [
|
|
3428
3532
|
"this._initiator",
|
|
@@ -3435,7 +3539,7 @@ var RtcPeerConnection = class {
|
|
|
3435
3539
|
}
|
|
3436
3540
|
log13("onnegotiationneeded", void 0, {
|
|
3437
3541
|
F: __dxlog_file14,
|
|
3438
|
-
L:
|
|
3542
|
+
L: 143,
|
|
3439
3543
|
S: this,
|
|
3440
3544
|
C: (f, a) => f(...a)
|
|
3441
3545
|
});
|
|
@@ -3459,7 +3563,7 @@ var RtcPeerConnection = class {
|
|
|
3459
3563
|
candidate: event.candidate.candidate
|
|
3460
3564
|
}, {
|
|
3461
3565
|
F: __dxlog_file14,
|
|
3462
|
-
L:
|
|
3566
|
+
L: 162,
|
|
3463
3567
|
S: this,
|
|
3464
3568
|
C: (f, a) => f(...a)
|
|
3465
3569
|
});
|
|
@@ -3467,7 +3571,7 @@ var RtcPeerConnection = class {
|
|
|
3467
3571
|
} else {
|
|
3468
3572
|
log13("onicecandidate gathering complete", void 0, {
|
|
3469
3573
|
F: __dxlog_file14,
|
|
3470
|
-
L:
|
|
3574
|
+
L: 165,
|
|
3471
3575
|
S: this,
|
|
3472
3576
|
C: (f, a) => f(...a)
|
|
3473
3577
|
});
|
|
@@ -3495,7 +3599,7 @@ var RtcPeerConnection = class {
|
|
|
3495
3599
|
state: connection.iceConnectionState
|
|
3496
3600
|
}, {
|
|
3497
3601
|
F: __dxlog_file14,
|
|
3498
|
-
L:
|
|
3602
|
+
L: 185,
|
|
3499
3603
|
S: this,
|
|
3500
3604
|
C: (f, a) => f(...a)
|
|
3501
3605
|
});
|
|
@@ -3517,7 +3621,7 @@ var RtcPeerConnection = class {
|
|
|
3517
3621
|
state: connection.connectionState
|
|
3518
3622
|
}, {
|
|
3519
3623
|
F: __dxlog_file14,
|
|
3520
|
-
L:
|
|
3624
|
+
L: 202,
|
|
3521
3625
|
S: this,
|
|
3522
3626
|
C: (f, a) => f(...a)
|
|
3523
3627
|
});
|
|
@@ -3530,7 +3634,7 @@ var RtcPeerConnection = class {
|
|
|
3530
3634
|
state: connection.signalingState
|
|
3531
3635
|
}, {
|
|
3532
3636
|
F: __dxlog_file14,
|
|
3533
|
-
L:
|
|
3637
|
+
L: 209,
|
|
3534
3638
|
S: this,
|
|
3535
3639
|
C: (f, a) => f(...a)
|
|
3536
3640
|
});
|
|
@@ -3540,7 +3644,7 @@ var RtcPeerConnection = class {
|
|
|
3540
3644
|
ondatachannel: (event) => {
|
|
3541
3645
|
invariant12(!this._initiator, "Initiator is expected to create data channels.", {
|
|
3542
3646
|
F: __dxlog_file14,
|
|
3543
|
-
L:
|
|
3647
|
+
L: 215,
|
|
3544
3648
|
S: this,
|
|
3545
3649
|
A: [
|
|
3546
3650
|
"!this._initiator",
|
|
@@ -3555,7 +3659,7 @@ var RtcPeerConnection = class {
|
|
|
3555
3659
|
label: event.channel.label
|
|
3556
3660
|
}, {
|
|
3557
3661
|
F: __dxlog_file14,
|
|
3558
|
-
L:
|
|
3662
|
+
L: 222,
|
|
3559
3663
|
S: this,
|
|
3560
3664
|
C: (f, a) => f(...a)
|
|
3561
3665
|
});
|
|
@@ -3583,7 +3687,7 @@ var RtcPeerConnection = class {
|
|
|
3583
3687
|
error
|
|
3584
3688
|
}, {
|
|
3585
3689
|
F: __dxlog_file14,
|
|
3586
|
-
L:
|
|
3690
|
+
L: 247,
|
|
3587
3691
|
S: this,
|
|
3588
3692
|
C: (f, a) => f(...a)
|
|
3589
3693
|
});
|
|
@@ -3604,7 +3708,7 @@ var RtcPeerConnection = class {
|
|
|
3604
3708
|
reason: error.message
|
|
3605
3709
|
}, {
|
|
3606
3710
|
F: __dxlog_file14,
|
|
3607
|
-
L:
|
|
3711
|
+
L: 261,
|
|
3608
3712
|
S: this,
|
|
3609
3713
|
C: (f, a) => f(...a)
|
|
3610
3714
|
});
|
|
@@ -3612,7 +3716,7 @@ var RtcPeerConnection = class {
|
|
|
3612
3716
|
async _lockAndCloseConnection() {
|
|
3613
3717
|
invariant12(this._transportChannels.size === 0, void 0, {
|
|
3614
3718
|
F: __dxlog_file14,
|
|
3615
|
-
L:
|
|
3719
|
+
L: 266,
|
|
3616
3720
|
S: this,
|
|
3617
3721
|
A: [
|
|
3618
3722
|
"this._transportChannels.size === 0",
|
|
@@ -3623,7 +3727,7 @@ var RtcPeerConnection = class {
|
|
|
3623
3727
|
this._safeCloseConnection();
|
|
3624
3728
|
log13("connection closed", void 0, {
|
|
3625
3729
|
F: __dxlog_file14,
|
|
3626
|
-
L:
|
|
3730
|
+
L: 269,
|
|
3627
3731
|
S: this,
|
|
3628
3732
|
C: (f, a) => f(...a)
|
|
3629
3733
|
});
|
|
@@ -3636,7 +3740,7 @@ var RtcPeerConnection = class {
|
|
|
3636
3740
|
type: signal.payload.data.type
|
|
3637
3741
|
}, {
|
|
3638
3742
|
F: __dxlog_file14,
|
|
3639
|
-
L:
|
|
3743
|
+
L: 277,
|
|
3640
3744
|
S: this,
|
|
3641
3745
|
C: (f, a) => f(...a)
|
|
3642
3746
|
});
|
|
@@ -3703,7 +3807,7 @@ var RtcPeerConnection = class {
|
|
|
3703
3807
|
type: data.type
|
|
3704
3808
|
}, {
|
|
3705
3809
|
F: __dxlog_file14,
|
|
3706
|
-
L:
|
|
3810
|
+
L: 336,
|
|
3707
3811
|
S: this,
|
|
3708
3812
|
C: (f, a) => f(...a)
|
|
3709
3813
|
});
|
|
@@ -3716,7 +3820,7 @@ var RtcPeerConnection = class {
|
|
|
3716
3820
|
candidate
|
|
3717
3821
|
}, {
|
|
3718
3822
|
F: __dxlog_file14,
|
|
3719
|
-
L:
|
|
3823
|
+
L: 344,
|
|
3720
3824
|
S: this,
|
|
3721
3825
|
C: (f, a) => f(...a)
|
|
3722
3826
|
});
|
|
@@ -3725,7 +3829,7 @@ var RtcPeerConnection = class {
|
|
|
3725
3829
|
} catch (err) {
|
|
3726
3830
|
log13.catch(err, void 0, {
|
|
3727
3831
|
F: __dxlog_file14,
|
|
3728
|
-
L:
|
|
3832
|
+
L: 348,
|
|
3729
3833
|
S: this,
|
|
3730
3834
|
C: (f, a) => f(...a)
|
|
3731
3835
|
});
|
|
@@ -3735,7 +3839,7 @@ var RtcPeerConnection = class {
|
|
|
3735
3839
|
if (connection === this._connection) {
|
|
3736
3840
|
log13("ready to process ice candidates", void 0, {
|
|
3737
3841
|
F: __dxlog_file14,
|
|
3738
|
-
L:
|
|
3842
|
+
L: 354,
|
|
3739
3843
|
S: this,
|
|
3740
3844
|
C: (f, a) => f(...a)
|
|
3741
3845
|
});
|
|
@@ -3743,7 +3847,7 @@ var RtcPeerConnection = class {
|
|
|
3743
3847
|
} else {
|
|
3744
3848
|
log13.warn("session was negotiated after connection became inactive", void 0, {
|
|
3745
3849
|
F: __dxlog_file14,
|
|
3746
|
-
L:
|
|
3850
|
+
L: 357,
|
|
3747
3851
|
S: this,
|
|
3748
3852
|
C: (f, a) => f(...a)
|
|
3749
3853
|
});
|
|
@@ -3755,7 +3859,7 @@ var RtcPeerConnection = class {
|
|
|
3755
3859
|
state: connection.connectionState
|
|
3756
3860
|
}, {
|
|
3757
3861
|
F: __dxlog_file14,
|
|
3758
|
-
L:
|
|
3862
|
+
L: 362,
|
|
3759
3863
|
S: this,
|
|
3760
3864
|
C: (f, a) => f(...a)
|
|
3761
3865
|
});
|
|
@@ -3768,7 +3872,7 @@ var RtcPeerConnection = class {
|
|
|
3768
3872
|
} catch (err) {
|
|
3769
3873
|
log13.catch(err, void 0, {
|
|
3770
3874
|
F: __dxlog_file14,
|
|
3771
|
-
L:
|
|
3875
|
+
L: 374,
|
|
3772
3876
|
S: this,
|
|
3773
3877
|
C: (f, a) => f(...a)
|
|
3774
3878
|
});
|
|
@@ -3779,7 +3883,7 @@ var RtcPeerConnection = class {
|
|
|
3779
3883
|
this._readyForCandidates.wake();
|
|
3780
3884
|
void this._factory.onConnectionDestroyed().catch((err) => log13.catch(err, void 0, {
|
|
3781
3885
|
F: __dxlog_file14,
|
|
3782
|
-
L:
|
|
3886
|
+
L: 380,
|
|
3783
3887
|
S: this,
|
|
3784
3888
|
C: (f, a) => f(...a)
|
|
3785
3889
|
}));
|
|
@@ -3804,7 +3908,7 @@ var RtcPeerConnection = class {
|
|
|
3804
3908
|
} catch (error) {
|
|
3805
3909
|
log13.catch(error, void 0, {
|
|
3806
3910
|
F: __dxlog_file14,
|
|
3807
|
-
L:
|
|
3911
|
+
L: 396,
|
|
3808
3912
|
S: this,
|
|
3809
3913
|
C: (f, a) => f(...a)
|
|
3810
3914
|
});
|
|
@@ -3831,7 +3935,7 @@ var RtcPeerConnection = class {
|
|
|
3831
3935
|
err
|
|
3832
3936
|
}, {
|
|
3833
3937
|
F: __dxlog_file14,
|
|
3834
|
-
L:
|
|
3938
|
+
L: 417,
|
|
3835
3939
|
S: this,
|
|
3836
3940
|
C: (f, a) => f(...a)
|
|
3837
3941
|
});
|
|
@@ -3908,8 +4012,10 @@ var isRemoteDescriptionSet = (connection, data) => {
|
|
|
3908
4012
|
};
|
|
3909
4013
|
var createIceFailureError = (details) => {
|
|
3910
4014
|
const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
|
|
3911
|
-
return new ConnectivityError3(
|
|
3912
|
-
|
|
4015
|
+
return new ConnectivityError3({
|
|
4016
|
+
message: `ICE failed:
|
|
4017
|
+
${candidateErrors.join("\n")}`
|
|
4018
|
+
});
|
|
3913
4019
|
};
|
|
3914
4020
|
|
|
3915
4021
|
// src/transport/webrtc/rtc-transport-factory.ts
|
|
@@ -3946,8 +4052,14 @@ var RPC_TIMEOUT = 1e4;
|
|
|
3946
4052
|
var CLOSE_RPC_TIMEOUT = 3e3;
|
|
3947
4053
|
var RESP_MIN_THRESHOLD = 500;
|
|
3948
4054
|
var RtcTransportProxy = class extends Resource2 {
|
|
4055
|
+
_options;
|
|
4056
|
+
_proxyId = PublicKey10.random();
|
|
4057
|
+
closed = new Event8();
|
|
4058
|
+
connected = new Event8();
|
|
4059
|
+
errors = new ErrorStream5();
|
|
4060
|
+
_serviceStream;
|
|
3949
4061
|
constructor(_options) {
|
|
3950
|
-
super(), this._options = _options
|
|
4062
|
+
super(), this._options = _options;
|
|
3951
4063
|
}
|
|
3952
4064
|
async _open() {
|
|
3953
4065
|
let stream;
|
|
@@ -4099,7 +4211,9 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4099
4211
|
} catch (error) {
|
|
4100
4212
|
const type = signalEvent.payload.payload.data?.type;
|
|
4101
4213
|
if (type === "offer" || type === "answer") {
|
|
4102
|
-
this._raiseIfOpen(new ConnectivityError4(
|
|
4214
|
+
this._raiseIfOpen(new ConnectivityError4({
|
|
4215
|
+
message: `Session establishment failed: ${type} couldn't be sent.`
|
|
4216
|
+
}));
|
|
4103
4217
|
}
|
|
4104
4218
|
}
|
|
4105
4219
|
}
|
|
@@ -4141,7 +4255,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4141
4255
|
message: error.message
|
|
4142
4256
|
}, {
|
|
4143
4257
|
F: __dxlog_file15,
|
|
4144
|
-
L:
|
|
4258
|
+
L: 217,
|
|
4145
4259
|
S: this,
|
|
4146
4260
|
C: (f, a) => f(...a)
|
|
4147
4261
|
});
|
|
@@ -4156,9 +4270,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4156
4270
|
}
|
|
4157
4271
|
};
|
|
4158
4272
|
var RtcTransportProxyFactory = class {
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
}
|
|
4273
|
+
_bridgeService;
|
|
4274
|
+
_connections = /* @__PURE__ */ new Set();
|
|
4162
4275
|
/**
|
|
4163
4276
|
* Sets the current BridgeService to be used to open connections.
|
|
4164
4277
|
* Calling this method will close any existing connections.
|
|
@@ -4173,7 +4286,7 @@ var RtcTransportProxyFactory = class {
|
|
|
4173
4286
|
createTransport(options) {
|
|
4174
4287
|
invariant13(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
|
|
4175
4288
|
F: __dxlog_file15,
|
|
4176
|
-
L:
|
|
4289
|
+
L: 247,
|
|
4177
4290
|
S: this,
|
|
4178
4291
|
A: [
|
|
4179
4292
|
"this._bridgeService",
|
|
@@ -4194,11 +4307,17 @@ var RtcTransportProxyFactory = class {
|
|
|
4194
4307
|
var decodeError = (err) => {
|
|
4195
4308
|
const message = typeof err === "string" ? err : err.message;
|
|
4196
4309
|
if (message.includes("CONNECTION_RESET")) {
|
|
4197
|
-
return new ConnectionResetError2(
|
|
4310
|
+
return new ConnectionResetError2({
|
|
4311
|
+
message
|
|
4312
|
+
});
|
|
4198
4313
|
} else if (message.includes("TIMEOUT")) {
|
|
4199
|
-
return new TimeoutError3(
|
|
4314
|
+
return new TimeoutError3({
|
|
4315
|
+
message
|
|
4316
|
+
});
|
|
4200
4317
|
} else if (message.includes("CONNECTIVITY_ERROR")) {
|
|
4201
|
-
return new ConnectivityError4(
|
|
4318
|
+
return new ConnectivityError4({
|
|
4319
|
+
message
|
|
4320
|
+
});
|
|
4202
4321
|
} else {
|
|
4203
4322
|
return typeof err === "string" ? new Error(err) : err;
|
|
4204
4323
|
}
|
|
@@ -4214,9 +4333,10 @@ import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/
|
|
|
4214
4333
|
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
4215
4334
|
var __dxlog_file16 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
|
|
4216
4335
|
var RtcTransportService = class {
|
|
4336
|
+
_transportFactory;
|
|
4337
|
+
_openTransports = new ComplexMap8(PublicKey11.hash);
|
|
4217
4338
|
constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
|
|
4218
4339
|
this._transportFactory = _transportFactory;
|
|
4219
|
-
this._openTransports = new ComplexMap8(PublicKey11.hash);
|
|
4220
4340
|
}
|
|
4221
4341
|
hasOpenTransports() {
|
|
4222
4342
|
return this._openTransports.size > 0;
|
|
@@ -4226,7 +4346,7 @@ var RtcTransportService = class {
|
|
|
4226
4346
|
if (existingTransport) {
|
|
4227
4347
|
log15.error("requesting a new transport bridge for an existing proxy", void 0, {
|
|
4228
4348
|
F: __dxlog_file16,
|
|
4229
|
-
L:
|
|
4349
|
+
L: 54,
|
|
4230
4350
|
S: this,
|
|
4231
4351
|
C: (f, a) => f(...a)
|
|
4232
4352
|
});
|
|
@@ -4292,7 +4412,7 @@ var RtcTransportService = class {
|
|
|
4292
4412
|
ready();
|
|
4293
4413
|
log15("stream ready", void 0, {
|
|
4294
4414
|
F: __dxlog_file16,
|
|
4295
|
-
L:
|
|
4415
|
+
L: 116,
|
|
4296
4416
|
S: this,
|
|
4297
4417
|
C: (f, a) => f(...a)
|
|
4298
4418
|
});
|
|
@@ -4303,7 +4423,7 @@ var RtcTransportService = class {
|
|
|
4303
4423
|
const transport = this._openTransports.get(proxyId);
|
|
4304
4424
|
invariant14(transport, void 0, {
|
|
4305
4425
|
F: __dxlog_file16,
|
|
4306
|
-
L:
|
|
4426
|
+
L: 124,
|
|
4307
4427
|
S: this,
|
|
4308
4428
|
A: [
|
|
4309
4429
|
"transport",
|
|
@@ -4316,7 +4436,7 @@ var RtcTransportService = class {
|
|
|
4316
4436
|
const transport = this._openTransports.get(proxyId);
|
|
4317
4437
|
invariant14(transport, void 0, {
|
|
4318
4438
|
F: __dxlog_file16,
|
|
4319
|
-
L:
|
|
4439
|
+
L: 131,
|
|
4320
4440
|
S: this,
|
|
4321
4441
|
A: [
|
|
4322
4442
|
"transport",
|
|
@@ -4331,7 +4451,7 @@ var RtcTransportService = class {
|
|
|
4331
4451
|
const transport = this._openTransports.get(proxyId);
|
|
4332
4452
|
invariant14(transport, void 0, {
|
|
4333
4453
|
F: __dxlog_file16,
|
|
4334
|
-
L:
|
|
4454
|
+
L: 138,
|
|
4335
4455
|
S: this,
|
|
4336
4456
|
A: [
|
|
4337
4457
|
"transport",
|
|
@@ -4346,7 +4466,7 @@ var RtcTransportService = class {
|
|
|
4346
4466
|
const transport = this._openTransports.get(proxyId);
|
|
4347
4467
|
invariant14(transport, void 0, {
|
|
4348
4468
|
F: __dxlog_file16,
|
|
4349
|
-
L:
|
|
4469
|
+
L: 145,
|
|
4350
4470
|
S: this,
|
|
4351
4471
|
A: [
|
|
4352
4472
|
"transport",
|
|
@@ -4380,7 +4500,7 @@ var RtcTransportService = class {
|
|
|
4380
4500
|
message: error?.message
|
|
4381
4501
|
}, {
|
|
4382
4502
|
F: __dxlog_file16,
|
|
4383
|
-
L:
|
|
4503
|
+
L: 175,
|
|
4384
4504
|
S: this,
|
|
4385
4505
|
C: (f, a) => f(...a)
|
|
4386
4506
|
});
|
|
@@ -4392,14 +4512,14 @@ var RtcTransportService = class {
|
|
|
4392
4512
|
message: error?.message
|
|
4393
4513
|
}, {
|
|
4394
4514
|
F: __dxlog_file16,
|
|
4395
|
-
L:
|
|
4515
|
+
L: 180,
|
|
4396
4516
|
S: this,
|
|
4397
4517
|
C: (f, a) => f(...a)
|
|
4398
4518
|
});
|
|
4399
4519
|
}
|
|
4400
4520
|
log15("closed", void 0, {
|
|
4401
4521
|
F: __dxlog_file16,
|
|
4402
|
-
L:
|
|
4522
|
+
L: 182,
|
|
4403
4523
|
S: this,
|
|
4404
4524
|
C: (f, a) => f(...a)
|
|
4405
4525
|
});
|
|
@@ -4466,4 +4586,4 @@ export {
|
|
|
4466
4586
|
RtcTransportService,
|
|
4467
4587
|
createTeleportProtocolFactory
|
|
4468
4588
|
};
|
|
4469
|
-
//# sourceMappingURL=chunk-
|
|
4589
|
+
//# sourceMappingURL=chunk-5ISEIDVN.mjs.map
|