@dxos/network-manager 0.1.49-next.fdd6c88 → 0.1.49
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-6HMQOZ2C.mjs → chunk-U73XV3EJ.mjs} +207 -137
- package/dist/lib/browser/chunk-U73XV3EJ.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 +203 -133
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +203 -133
- 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/signal-messenger.d.ts +3 -2
- package/dist/types/src/signal/signal-messenger.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +10 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +2 -0
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/package.json +18 -17
- package/src/network-manager.ts +5 -1
- package/src/signal/integration.test.ts +2 -0
- package/src/signal/signal-messenger.ts +2 -2
- package/src/signal/swarm-messenger.test.ts +7 -4
- package/src/signal/swarm-messenger.ts +23 -12
- package/src/swarm/connection.ts +83 -28
- package/src/swarm/swarm.test.ts +9 -7
- package/src/swarm/swarm.ts +19 -15
- package/dist/lib/browser/chunk-6HMQOZ2C.mjs.map +0 -7
|
@@ -64,7 +64,9 @@ var import_util4 = require("@dxos/util");
|
|
|
64
64
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
65
65
|
var import_node_assert = __toESM(require("node:assert"));
|
|
66
66
|
var import_async = require("@dxos/async");
|
|
67
|
+
var import_context = require("@dxos/context");
|
|
67
68
|
var import_debug = require("@dxos/debug");
|
|
69
|
+
var import_errors = require("@dxos/errors");
|
|
68
70
|
var import_keys = require("@dxos/keys");
|
|
69
71
|
var import_log = require("@dxos/log");
|
|
70
72
|
var import_protocols = require("@dxos/protocols");
|
|
@@ -78,6 +80,8 @@ var __decorate = function(decorators, target, key, desc) {
|
|
|
78
80
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
79
81
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
80
82
|
};
|
|
83
|
+
var STARTING_SIGNALLING_DELAY = 10;
|
|
84
|
+
var MAX_SIGNALLING_DELAY = 300;
|
|
81
85
|
var ConnectionState;
|
|
82
86
|
(function(ConnectionState6) {
|
|
83
87
|
ConnectionState6[
|
|
@@ -122,11 +126,17 @@ var Connection = class {
|
|
|
122
126
|
this._signalMessaging = _signalMessaging;
|
|
123
127
|
this._protocol = _protocol;
|
|
124
128
|
this._transportFactory = _transportFactory;
|
|
129
|
+
this._ctx = new import_context.Context();
|
|
125
130
|
this._state = ConnectionState.INITIAL;
|
|
126
|
-
this.
|
|
131
|
+
this._incomingSignalBuffer = [];
|
|
132
|
+
this._outgoingSignalBuffer = [];
|
|
127
133
|
this.stateChanged = new import_async.Event();
|
|
128
134
|
this.errors = new import_debug.ErrorStream();
|
|
129
135
|
this._instanceId = import_keys.PublicKey.random().toHex();
|
|
136
|
+
this._signalSendTask = new import_async.DeferredTask(this._ctx, async () => {
|
|
137
|
+
await this._flushSignalBuffer();
|
|
138
|
+
});
|
|
139
|
+
this._signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
130
140
|
}
|
|
131
141
|
get state() {
|
|
132
142
|
return this._state;
|
|
@@ -147,7 +157,7 @@ var Connection = class {
|
|
|
147
157
|
id: this._instanceId
|
|
148
158
|
}), {
|
|
149
159
|
file: "connection.ts",
|
|
150
|
-
line:
|
|
160
|
+
line: 115,
|
|
151
161
|
scope: this,
|
|
152
162
|
callSite: (f, a) => f(...a)
|
|
153
163
|
});
|
|
@@ -158,7 +168,7 @@ var Connection = class {
|
|
|
158
168
|
this._protocol.stream.on("close", () => {
|
|
159
169
|
(0, import_log.log)("protocol stream closed", {}, {
|
|
160
170
|
file: "connection.ts",
|
|
161
|
-
line:
|
|
171
|
+
line: 126,
|
|
162
172
|
scope: this,
|
|
163
173
|
callSite: (f, a) => f(...a)
|
|
164
174
|
});
|
|
@@ -168,29 +178,7 @@ var Connection = class {
|
|
|
168
178
|
this._transport = this._transportFactory.createTransport({
|
|
169
179
|
initiator: this.initiator,
|
|
170
180
|
stream: this._protocol.stream,
|
|
171
|
-
sendSignal: async (signal) =>
|
|
172
|
-
try {
|
|
173
|
-
await this._signalMessaging.signal({
|
|
174
|
-
author: this.ownId,
|
|
175
|
-
recipient: this.remoteId,
|
|
176
|
-
sessionId: this.sessionId,
|
|
177
|
-
topic: this.topic,
|
|
178
|
-
data: {
|
|
179
|
-
signal
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
} catch (err) {
|
|
183
|
-
(0, import_log.log)("Signal failed", {
|
|
184
|
-
err
|
|
185
|
-
}, {
|
|
186
|
-
file: "connection.ts",
|
|
187
|
-
line: 122,
|
|
188
|
-
scope: this,
|
|
189
|
-
callSite: (f, a) => f(...a)
|
|
190
|
-
});
|
|
191
|
-
await this.close();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
181
|
+
sendSignal: async (signal) => this._sendSignal(signal)
|
|
194
182
|
});
|
|
195
183
|
this._transport.connected.once(() => {
|
|
196
184
|
this._changeState(ConnectionState.CONNECTED);
|
|
@@ -204,15 +192,15 @@ var Connection = class {
|
|
|
204
192
|
this.errors.raise(err);
|
|
205
193
|
}
|
|
206
194
|
});
|
|
207
|
-
for (const signal of this.
|
|
195
|
+
for (const signal of this._incomingSignalBuffer) {
|
|
208
196
|
void this._transport.signal(signal);
|
|
209
197
|
}
|
|
210
|
-
this.
|
|
198
|
+
this._incomingSignalBuffer = [];
|
|
211
199
|
import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.end({
|
|
212
200
|
id: this._instanceId
|
|
213
201
|
}), {
|
|
214
202
|
file: "connection.ts",
|
|
215
|
-
line:
|
|
203
|
+
line: 159,
|
|
216
204
|
scope: this,
|
|
217
205
|
callSite: (f, a) => f(...a)
|
|
218
206
|
});
|
|
@@ -223,11 +211,12 @@ var Connection = class {
|
|
|
223
211
|
return;
|
|
224
212
|
}
|
|
225
213
|
this._changeState(ConnectionState.CLOSING);
|
|
214
|
+
await this._ctx.dispose();
|
|
226
215
|
(0, import_log.log)("closing...", {
|
|
227
216
|
peerId: this.ownId
|
|
228
217
|
}, {
|
|
229
218
|
file: "connection.ts",
|
|
230
|
-
line:
|
|
219
|
+
line: 171,
|
|
231
220
|
scope: this,
|
|
232
221
|
callSite: (f, a) => f(...a)
|
|
233
222
|
});
|
|
@@ -236,7 +225,7 @@ var Connection = class {
|
|
|
236
225
|
} catch (err) {
|
|
237
226
|
import_log.log.catch(err, {}, {
|
|
238
227
|
file: "connection.ts",
|
|
239
|
-
line:
|
|
228
|
+
line: 177,
|
|
240
229
|
scope: this,
|
|
241
230
|
callSite: (f, a) => f(...a)
|
|
242
231
|
});
|
|
@@ -246,7 +235,7 @@ var Connection = class {
|
|
|
246
235
|
} catch (err1) {
|
|
247
236
|
import_log.log.catch(err1, {}, {
|
|
248
237
|
file: "connection.ts",
|
|
249
|
-
line:
|
|
238
|
+
line: 184,
|
|
250
239
|
scope: this,
|
|
251
240
|
callSite: (f, a) => f(...a)
|
|
252
241
|
});
|
|
@@ -255,53 +244,105 @@ var Connection = class {
|
|
|
255
244
|
peerId: this.ownId
|
|
256
245
|
}, {
|
|
257
246
|
file: "connection.ts",
|
|
258
|
-
line:
|
|
247
|
+
line: 187,
|
|
259
248
|
scope: this,
|
|
260
249
|
callSite: (f, a) => f(...a)
|
|
261
250
|
});
|
|
262
251
|
this._changeState(ConnectionState.CLOSED);
|
|
263
252
|
}
|
|
253
|
+
_sendSignal(signal) {
|
|
254
|
+
this._outgoingSignalBuffer.push(signal);
|
|
255
|
+
this._signalSendTask.schedule();
|
|
256
|
+
}
|
|
257
|
+
async _flushSignalBuffer() {
|
|
258
|
+
if (this._outgoingSignalBuffer.length === 0) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
await (0, import_context.cancelWithContext)(this._ctx, (0, import_async.sleep)(this._signallingDelay));
|
|
263
|
+
this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
|
|
264
|
+
const signals = [
|
|
265
|
+
...this._outgoingSignalBuffer
|
|
266
|
+
];
|
|
267
|
+
this._outgoingSignalBuffer.length = 0;
|
|
268
|
+
await this._signalMessaging.signal({
|
|
269
|
+
author: this.ownId,
|
|
270
|
+
recipient: this.remoteId,
|
|
271
|
+
sessionId: this.sessionId,
|
|
272
|
+
topic: this.topic,
|
|
273
|
+
data: {
|
|
274
|
+
signalBatch: {
|
|
275
|
+
signals
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
} catch (err) {
|
|
280
|
+
if (err instanceof import_errors.CancelledError) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
import_log.log.warn("Signal failed", {
|
|
284
|
+
err
|
|
285
|
+
}, {
|
|
286
|
+
file: "connection.ts",
|
|
287
|
+
line: 221,
|
|
288
|
+
scope: this,
|
|
289
|
+
callSite: (f, a) => f(...a)
|
|
290
|
+
});
|
|
291
|
+
await this.close();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Receive a signal from the remote peer.
|
|
296
|
+
*/
|
|
264
297
|
async signal(msg) {
|
|
265
|
-
var _a2, _b;
|
|
298
|
+
var _a2, _b, _c;
|
|
266
299
|
(0, import_node_assert.default)(msg.sessionId);
|
|
267
300
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
268
301
|
(0, import_log.log)("dropping signal for incorrect session id", {}, {
|
|
269
302
|
file: "connection.ts",
|
|
270
|
-
line:
|
|
303
|
+
line: 232,
|
|
271
304
|
scope: this,
|
|
272
305
|
callSite: (f, a) => f(...a)
|
|
273
306
|
});
|
|
274
307
|
return;
|
|
275
308
|
}
|
|
276
|
-
(0, import_node_assert.default)(msg.data.signal);
|
|
309
|
+
(0, import_node_assert.default)(msg.data.signal || msg.data.signalBatch);
|
|
277
310
|
(0, import_node_assert.default)((_a2 = msg.author) == null ? void 0 : _a2.equals(this.remoteId));
|
|
278
311
|
(0, import_node_assert.default)((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId));
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
312
|
+
const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
|
|
313
|
+
msg.data.signal
|
|
314
|
+
];
|
|
315
|
+
for (const signal of signals) {
|
|
316
|
+
if (!signal) {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (this._state === ConnectionState.INITIAL) {
|
|
320
|
+
(0, import_log.log)("buffered signal", {
|
|
321
|
+
peerId: this.ownId,
|
|
322
|
+
remoteId: this.remoteId,
|
|
323
|
+
msg: msg.data
|
|
324
|
+
}, {
|
|
325
|
+
file: "connection.ts",
|
|
326
|
+
line: 246,
|
|
327
|
+
scope: this,
|
|
328
|
+
callSite: (f, a) => f(...a)
|
|
329
|
+
});
|
|
330
|
+
this._incomingSignalBuffer.push(signal);
|
|
331
|
+
} else {
|
|
332
|
+
(0, import_node_assert.default)(this._transport, "Connection not ready to accept signals.");
|
|
333
|
+
(0, import_log.log)("received signal", {
|
|
334
|
+
peerId: this.ownId,
|
|
335
|
+
remoteId: this.remoteId,
|
|
336
|
+
msg: msg.data
|
|
337
|
+
}, {
|
|
338
|
+
file: "connection.ts",
|
|
339
|
+
line: 250,
|
|
340
|
+
scope: this,
|
|
341
|
+
callSite: (f, a) => f(...a)
|
|
342
|
+
});
|
|
343
|
+
await this._transport.signal(signal);
|
|
344
|
+
}
|
|
292
345
|
}
|
|
293
|
-
(0, import_node_assert.default)(this._transport, "Connection not ready to accept signals.");
|
|
294
|
-
(0, import_log.log)("received signal", {
|
|
295
|
-
peerId: this.ownId,
|
|
296
|
-
remoteId: this.remoteId,
|
|
297
|
-
msg: msg.data
|
|
298
|
-
}, {
|
|
299
|
-
file: "connection.ts",
|
|
300
|
-
line: 197,
|
|
301
|
-
scope: this,
|
|
302
|
-
callSite: (f, a) => f(...a)
|
|
303
|
-
});
|
|
304
|
-
await this._transport.signal(msg.data.signal);
|
|
305
346
|
}
|
|
306
347
|
_changeState(state) {
|
|
307
348
|
(0, import_log.log)("stateChanged", {
|
|
@@ -310,7 +351,7 @@ var Connection = class {
|
|
|
310
351
|
peerId: this.ownId
|
|
311
352
|
}, {
|
|
312
353
|
file: "connection.ts",
|
|
313
|
-
line:
|
|
354
|
+
line: 257,
|
|
314
355
|
scope: this,
|
|
315
356
|
callSite: (f, a) => f(...a)
|
|
316
357
|
});
|
|
@@ -326,7 +367,7 @@ __decorate([
|
|
|
326
367
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
327
368
|
var import_node_assert4 = __toESM(require("node:assert"));
|
|
328
369
|
var import_async3 = require("@dxos/async");
|
|
329
|
-
var
|
|
370
|
+
var import_context4 = require("@dxos/context");
|
|
330
371
|
var import_debug2 = require("@dxos/debug");
|
|
331
372
|
var import_keys4 = require("@dxos/keys");
|
|
332
373
|
var import_log4 = require("@dxos/log");
|
|
@@ -335,14 +376,14 @@ var import_util2 = require("@dxos/util");
|
|
|
335
376
|
|
|
336
377
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
337
378
|
var import_node_assert2 = __toESM(require("node:assert"));
|
|
338
|
-
var
|
|
379
|
+
var import_context2 = require("@dxos/context");
|
|
339
380
|
var import_keys2 = require("@dxos/keys");
|
|
340
381
|
var import_log2 = require("@dxos/log");
|
|
341
382
|
var import_protocols2 = require("@dxos/protocols");
|
|
342
383
|
var import_util = require("@dxos/util");
|
|
343
384
|
var SwarmMessenger = class {
|
|
344
385
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
345
|
-
this._ctx = new
|
|
386
|
+
this._ctx = new import_context2.Context();
|
|
346
387
|
this._offerRecords = new import_util.ComplexMap((key) => key.toHex());
|
|
347
388
|
this._sendMessage = sendMessage;
|
|
348
389
|
this._onSignal = onSignal;
|
|
@@ -350,7 +391,7 @@ var SwarmMessenger = class {
|
|
|
350
391
|
this._topic = topic;
|
|
351
392
|
}
|
|
352
393
|
async receiveMessage({ author, recipient, payload }) {
|
|
353
|
-
var _a2, _b, _c;
|
|
394
|
+
var _a2, _b, _c, _d;
|
|
354
395
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
355
396
|
return;
|
|
356
397
|
}
|
|
@@ -382,11 +423,26 @@ var SwarmMessenger = class {
|
|
|
382
423
|
recipient,
|
|
383
424
|
message
|
|
384
425
|
});
|
|
426
|
+
} else if ((_d = message.data) == null ? void 0 : _d.signalBatch) {
|
|
427
|
+
await this._handleSignal({
|
|
428
|
+
author,
|
|
429
|
+
recipient,
|
|
430
|
+
message
|
|
431
|
+
});
|
|
432
|
+
} else {
|
|
433
|
+
import_log2.log.warn("unknown message", {
|
|
434
|
+
message
|
|
435
|
+
}, {
|
|
436
|
+
file: "swarm-messenger.ts",
|
|
437
|
+
line: 79,
|
|
438
|
+
scope: this,
|
|
439
|
+
callSite: (f, a) => f(...a)
|
|
440
|
+
});
|
|
385
441
|
}
|
|
386
442
|
}
|
|
387
443
|
async signal(message) {
|
|
388
|
-
var _a2;
|
|
389
|
-
(0, import_node_assert2.default)((_a2 = message.data) == null ? void 0 : _a2.signal);
|
|
444
|
+
var _a2, _b;
|
|
445
|
+
(0, import_node_assert2.default)(((_a2 = message.data) == null ? void 0 : _a2.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message");
|
|
390
446
|
await this._sendReliableMessage({
|
|
391
447
|
author: message.author,
|
|
392
448
|
recipient: message.recipient,
|
|
@@ -422,7 +478,7 @@ var SwarmMessenger = class {
|
|
|
422
478
|
msg: networkMessage
|
|
423
479
|
}, {
|
|
424
480
|
file: "swarm-messenger.ts",
|
|
425
|
-
line:
|
|
481
|
+
line: 122,
|
|
426
482
|
scope: this,
|
|
427
483
|
callSite: (f, a) => f(...a)
|
|
428
484
|
});
|
|
@@ -446,7 +502,7 @@ var SwarmMessenger = class {
|
|
|
446
502
|
answer: message.data.answer
|
|
447
503
|
}, {
|
|
448
504
|
file: "swarm-messenger.ts",
|
|
449
|
-
line:
|
|
505
|
+
line: 139,
|
|
450
506
|
scope: this,
|
|
451
507
|
callSite: (f, a) => f(...a)
|
|
452
508
|
});
|
|
@@ -465,27 +521,39 @@ var SwarmMessenger = class {
|
|
|
465
521
|
};
|
|
466
522
|
const answer = await this._onOffer(offerMessage);
|
|
467
523
|
answer.offerMessageId = message.messageId;
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
524
|
+
try {
|
|
525
|
+
await this._sendReliableMessage({
|
|
526
|
+
author: recipient,
|
|
527
|
+
recipient: author,
|
|
528
|
+
message: {
|
|
529
|
+
topic: message.topic,
|
|
530
|
+
sessionId: message.sessionId,
|
|
531
|
+
data: {
|
|
532
|
+
answer
|
|
533
|
+
}
|
|
476
534
|
}
|
|
477
|
-
}
|
|
478
|
-
})
|
|
535
|
+
});
|
|
536
|
+
} catch (err) {
|
|
537
|
+
import_log2.log.warn("error sending answer", {
|
|
538
|
+
err
|
|
539
|
+
}, {
|
|
540
|
+
file: "swarm-messenger.ts",
|
|
541
|
+
line: 173,
|
|
542
|
+
scope: this,
|
|
543
|
+
callSite: (f, a) => f(...a)
|
|
544
|
+
});
|
|
545
|
+
}
|
|
479
546
|
}
|
|
480
547
|
async _handleSignal({ author, recipient, message }) {
|
|
481
548
|
(0, import_node_assert2.default)(message.messageId);
|
|
482
|
-
(0, import_node_assert2.default)(message.data.signal, "
|
|
549
|
+
(0, import_node_assert2.default)(message.data.signal || message.data.signalBatch, "Invalid message");
|
|
483
550
|
const signalMessage = {
|
|
484
551
|
author,
|
|
485
552
|
recipient,
|
|
486
553
|
...message,
|
|
487
554
|
data: {
|
|
488
|
-
signal: message.data.signal
|
|
555
|
+
signal: message.data.signal,
|
|
556
|
+
signalBatch: message.data.signalBatch
|
|
489
557
|
}
|
|
490
558
|
};
|
|
491
559
|
await this._onSignal(signalMessage);
|
|
@@ -495,7 +563,7 @@ var SwarmMessenger = class {
|
|
|
495
563
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
496
564
|
var import_node_assert3 = __toESM(require("node:assert"));
|
|
497
565
|
var import_async2 = require("@dxos/async");
|
|
498
|
-
var
|
|
566
|
+
var import_context3 = require("@dxos/context");
|
|
499
567
|
var import_keys3 = require("@dxos/keys");
|
|
500
568
|
var import_log3 = require("@dxos/log");
|
|
501
569
|
var __decorate2 = function(decorators, target, key, desc) {
|
|
@@ -520,7 +588,7 @@ var Peer = class {
|
|
|
520
588
|
this._callbacks = _callbacks;
|
|
521
589
|
this._availableAfter = 0;
|
|
522
590
|
this.availableToConnect = true;
|
|
523
|
-
this._ctx = new
|
|
591
|
+
this._ctx = new import_context3.Context();
|
|
524
592
|
this.advertizing = false;
|
|
525
593
|
this.initiating = false;
|
|
526
594
|
}
|
|
@@ -841,7 +909,8 @@ var Swarm = class {
|
|
|
841
909
|
this._transportFactory = _transportFactory;
|
|
842
910
|
this._label = _label;
|
|
843
911
|
this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
|
|
844
|
-
this._ctx = new
|
|
912
|
+
this._ctx = new import_context4.Context();
|
|
913
|
+
this._listeningHandle = void 0;
|
|
845
914
|
this.connectionAdded = new import_async3.Event();
|
|
846
915
|
this.disconnected = new import_async3.Event();
|
|
847
916
|
this.connected = new import_async3.Event();
|
|
@@ -855,7 +924,7 @@ var Swarm = class {
|
|
|
855
924
|
}
|
|
856
925
|
}), {
|
|
857
926
|
file: "swarm.ts",
|
|
858
|
-
line:
|
|
927
|
+
line: 86,
|
|
859
928
|
scope: this,
|
|
860
929
|
callSite: (f, a) => f(...a)
|
|
861
930
|
});
|
|
@@ -863,7 +932,7 @@ var Swarm = class {
|
|
|
863
932
|
peerId: _ownPeerId
|
|
864
933
|
}, {
|
|
865
934
|
file: "swarm.ts",
|
|
866
|
-
line:
|
|
935
|
+
line: 90,
|
|
867
936
|
scope: this,
|
|
868
937
|
callSite: (f, a) => f(...a)
|
|
869
938
|
});
|
|
@@ -874,30 +943,11 @@ var Swarm = class {
|
|
|
874
943
|
onOffer: async (msg) => await this.onOffer(msg),
|
|
875
944
|
topic: this._topic
|
|
876
945
|
});
|
|
877
|
-
this._messenger.listen({
|
|
878
|
-
peerId: this._ownPeerId,
|
|
879
|
-
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
880
|
-
onMessage: async (message) => {
|
|
881
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) => (0, import_log4.log)("Error while receiving message", {
|
|
882
|
-
err
|
|
883
|
-
}, {
|
|
884
|
-
file: "swarm.ts",
|
|
885
|
-
line: 105,
|
|
886
|
-
scope: this,
|
|
887
|
-
callSite: (f, a) => f(...a)
|
|
888
|
-
}));
|
|
889
|
-
}
|
|
890
|
-
}).catch((error) => import_log4.log.catch(error, {}, {
|
|
891
|
-
file: "swarm.ts",
|
|
892
|
-
line: 108,
|
|
893
|
-
scope: this,
|
|
894
|
-
callSite: (f, a) => f(...a)
|
|
895
|
-
}));
|
|
896
946
|
import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.end({
|
|
897
947
|
id: this._instanceId
|
|
898
948
|
}), {
|
|
899
949
|
file: "swarm.ts",
|
|
900
|
-
line:
|
|
950
|
+
line: 99,
|
|
901
951
|
scope: this,
|
|
902
952
|
callSite: (f, a) => f(...a)
|
|
903
953
|
});
|
|
@@ -917,20 +967,39 @@ var Swarm = class {
|
|
|
917
967
|
get topic() {
|
|
918
968
|
return this._topic;
|
|
919
969
|
}
|
|
920
|
-
|
|
970
|
+
async open() {
|
|
971
|
+
(0, import_node_assert4.default)(!this._listeningHandle);
|
|
972
|
+
this._listeningHandle = await this._messenger.listen({
|
|
973
|
+
peerId: this._ownPeerId,
|
|
974
|
+
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
975
|
+
onMessage: async (message) => {
|
|
976
|
+
await this._swarmMessenger.receiveMessage(message).catch((err) => import_log4.log.warn("Error while receiving message", {
|
|
977
|
+
err
|
|
978
|
+
}, {
|
|
979
|
+
file: "swarm.ts",
|
|
980
|
+
line: 133,
|
|
981
|
+
scope: this,
|
|
982
|
+
callSite: (f, a) => f(...a)
|
|
983
|
+
}));
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
}
|
|
921
987
|
async destroy() {
|
|
988
|
+
var _a2;
|
|
922
989
|
(0, import_log4.log)("destroying...", {}, {
|
|
923
990
|
file: "swarm.ts",
|
|
924
|
-
line:
|
|
991
|
+
line: 139,
|
|
925
992
|
scope: this,
|
|
926
993
|
callSite: (f, a) => f(...a)
|
|
927
994
|
});
|
|
995
|
+
await ((_a2 = this._listeningHandle) == null ? void 0 : _a2.unsubscribe());
|
|
996
|
+
this._listeningHandle = void 0;
|
|
928
997
|
await this._ctx.dispose();
|
|
929
998
|
await this._topology.destroy();
|
|
930
999
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
931
1000
|
(0, import_log4.log)("destroyed", {}, {
|
|
932
1001
|
file: "swarm.ts",
|
|
933
|
-
line:
|
|
1002
|
+
line: 146,
|
|
934
1003
|
scope: this,
|
|
935
1004
|
callSite: (f, a) => f(...a)
|
|
936
1005
|
});
|
|
@@ -945,7 +1014,7 @@ var Swarm = class {
|
|
|
945
1014
|
topology: getClassName(topology)
|
|
946
1015
|
}, {
|
|
947
1016
|
file: "swarm.ts",
|
|
948
|
-
line:
|
|
1017
|
+
line: 154,
|
|
949
1018
|
scope: this,
|
|
950
1019
|
callSite: (f, a) => f(...a)
|
|
951
1020
|
});
|
|
@@ -960,14 +1029,14 @@ var Swarm = class {
|
|
|
960
1029
|
swarmEvent
|
|
961
1030
|
}, {
|
|
962
1031
|
file: "swarm.ts",
|
|
963
|
-
line:
|
|
1032
|
+
line: 167,
|
|
964
1033
|
scope: this,
|
|
965
1034
|
callSite: (f, a) => f(...a)
|
|
966
1035
|
});
|
|
967
1036
|
if (this._ctx.disposed) {
|
|
968
1037
|
(0, import_log4.log)("swarm event ignored for disposed swarm", {}, {
|
|
969
1038
|
file: "swarm.ts",
|
|
970
|
-
line:
|
|
1039
|
+
line: 170,
|
|
971
1040
|
scope: this,
|
|
972
1041
|
callSite: (f, a) => f(...a)
|
|
973
1042
|
});
|
|
@@ -979,7 +1048,7 @@ var Swarm = class {
|
|
|
979
1048
|
peerId
|
|
980
1049
|
}, {
|
|
981
1050
|
file: "swarm.ts",
|
|
982
|
-
line:
|
|
1051
|
+
line: 176,
|
|
983
1052
|
scope: this,
|
|
984
1053
|
callSite: (f, a) => f(...a)
|
|
985
1054
|
});
|
|
@@ -994,7 +1063,7 @@ var Swarm = class {
|
|
|
994
1063
|
if (((_a2 = peer1.connection) == null ? void 0 : _a2.state) !== ConnectionState.CONNECTED) {
|
|
995
1064
|
void this._destroyPeer(peer1.id).catch((err) => import_log4.log.catch(err, {}, {
|
|
996
1065
|
file: "swarm.ts",
|
|
997
|
-
line:
|
|
1066
|
+
line: 187,
|
|
998
1067
|
scope: this,
|
|
999
1068
|
callSite: (f, a) => f(...a)
|
|
1000
1069
|
}));
|
|
@@ -1009,14 +1078,14 @@ var Swarm = class {
|
|
|
1009
1078
|
message
|
|
1010
1079
|
}, {
|
|
1011
1080
|
file: "swarm.ts",
|
|
1012
|
-
line:
|
|
1081
|
+
line: 197,
|
|
1013
1082
|
scope: this,
|
|
1014
1083
|
callSite: (f, a) => f(...a)
|
|
1015
1084
|
});
|
|
1016
1085
|
if (this._ctx.disposed) {
|
|
1017
1086
|
(0, import_log4.log)("ignored for disposed swarm", {}, {
|
|
1018
1087
|
file: "swarm.ts",
|
|
1019
|
-
line:
|
|
1088
|
+
line: 199,
|
|
1020
1089
|
scope: this,
|
|
1021
1090
|
callSite: (f, a) => f(...a)
|
|
1022
1091
|
});
|
|
@@ -1030,7 +1099,7 @@ var Swarm = class {
|
|
|
1030
1099
|
message
|
|
1031
1100
|
}, {
|
|
1032
1101
|
file: "swarm.ts",
|
|
1033
|
-
line:
|
|
1102
|
+
line: 206,
|
|
1034
1103
|
scope: this,
|
|
1035
1104
|
callSite: (f, a) => f(...a)
|
|
1036
1105
|
});
|
|
@@ -1043,7 +1112,7 @@ var Swarm = class {
|
|
|
1043
1112
|
message
|
|
1044
1113
|
}, {
|
|
1045
1114
|
file: "swarm.ts",
|
|
1046
|
-
line:
|
|
1115
|
+
line: 210,
|
|
1047
1116
|
scope: this,
|
|
1048
1117
|
callSite: (f, a) => f(...a)
|
|
1049
1118
|
});
|
|
@@ -1062,14 +1131,14 @@ var Swarm = class {
|
|
|
1062
1131
|
message
|
|
1063
1132
|
}, {
|
|
1064
1133
|
file: "swarm.ts",
|
|
1065
|
-
line:
|
|
1134
|
+
line: 222,
|
|
1066
1135
|
scope: this,
|
|
1067
1136
|
callSite: (f, a) => f(...a)
|
|
1068
1137
|
});
|
|
1069
1138
|
if (this._ctx.disposed) {
|
|
1070
1139
|
import_log4.log.info("ignored for offline swarm", {}, {
|
|
1071
1140
|
file: "swarm.ts",
|
|
1072
|
-
line:
|
|
1141
|
+
line: 224,
|
|
1073
1142
|
scope: this,
|
|
1074
1143
|
callSite: (f, a) => f(...a)
|
|
1075
1144
|
});
|
|
@@ -1090,7 +1159,7 @@ var Swarm = class {
|
|
|
1090
1159
|
}
|
|
1091
1160
|
// For debug purposes
|
|
1092
1161
|
async goOnline() {
|
|
1093
|
-
this._ctx = new
|
|
1162
|
+
this._ctx = new import_context4.Context();
|
|
1094
1163
|
}
|
|
1095
1164
|
_getOrCreatePeer(peerId) {
|
|
1096
1165
|
let peer = this._peers.get(peerId);
|
|
@@ -1150,7 +1219,7 @@ var Swarm = class {
|
|
|
1150
1219
|
} catch (err) {
|
|
1151
1220
|
(0, import_log4.log)("initiation error", err, {
|
|
1152
1221
|
file: "swarm.ts",
|
|
1153
|
-
line:
|
|
1222
|
+
line: 327,
|
|
1154
1223
|
scope: this,
|
|
1155
1224
|
callSite: (f, a) => f(...a)
|
|
1156
1225
|
});
|
|
@@ -1178,7 +1247,7 @@ var Swarm = class {
|
|
|
1178
1247
|
remoteId
|
|
1179
1248
|
}, {
|
|
1180
1249
|
file: "swarm.ts",
|
|
1181
|
-
line:
|
|
1250
|
+
line: 354,
|
|
1182
1251
|
scope: this,
|
|
1183
1252
|
callSite: (f, a) => f(...a)
|
|
1184
1253
|
});
|
|
@@ -1195,7 +1264,7 @@ var Swarm = class {
|
|
|
1195
1264
|
remoteId
|
|
1196
1265
|
}, {
|
|
1197
1266
|
file: "swarm.ts",
|
|
1198
|
-
line:
|
|
1267
|
+
line: 368,
|
|
1199
1268
|
scope: this,
|
|
1200
1269
|
callSite: (f, a) => f(...a)
|
|
1201
1270
|
});
|
|
@@ -1205,7 +1274,7 @@ var Swarm = class {
|
|
|
1205
1274
|
remoteId
|
|
1206
1275
|
}, {
|
|
1207
1276
|
file: "swarm.ts",
|
|
1208
|
-
line:
|
|
1277
|
+
line: 371,
|
|
1209
1278
|
scope: this,
|
|
1210
1279
|
callSite: (f, a) => f(...a)
|
|
1211
1280
|
});
|
|
@@ -1485,16 +1554,17 @@ var NetworkManager = class {
|
|
|
1485
1554
|
});
|
|
1486
1555
|
});
|
|
1487
1556
|
this._swarms.set(topic, swarm);
|
|
1557
|
+
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
1558
|
+
await swarm.open();
|
|
1488
1559
|
this._signalConnection.join({
|
|
1489
1560
|
topic,
|
|
1490
1561
|
peerId
|
|
1491
1562
|
}).catch((error) => import_log6.log.catch(error, {}, {
|
|
1492
1563
|
file: "network-manager.ts",
|
|
1493
|
-
line:
|
|
1564
|
+
line: 174,
|
|
1494
1565
|
scope: this,
|
|
1495
1566
|
callSite: (f, a) => f(...a)
|
|
1496
1567
|
}));
|
|
1497
|
-
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
1498
1568
|
this.topicsUpdated.emit();
|
|
1499
1569
|
(_a2 = this._connectionLog) == null ? void 0 : _a2.joinedSwarm(swarm);
|
|
1500
1570
|
(0, import_log6.log)("joined", {
|
|
@@ -1502,7 +1572,7 @@ var NetworkManager = class {
|
|
|
1502
1572
|
count: this._swarms.size
|
|
1503
1573
|
}, {
|
|
1504
1574
|
file: "network-manager.ts",
|
|
1505
|
-
line:
|
|
1575
|
+
line: 178,
|
|
1506
1576
|
scope: this,
|
|
1507
1577
|
callSite: (f, a) => f(...a)
|
|
1508
1578
|
});
|
|
@@ -1522,7 +1592,7 @@ var NetworkManager = class {
|
|
|
1522
1592
|
topic: import_keys7.PublicKey.from(topic)
|
|
1523
1593
|
}, {
|
|
1524
1594
|
file: "network-manager.ts",
|
|
1525
|
-
line:
|
|
1595
|
+
line: 194,
|
|
1526
1596
|
scope: this,
|
|
1527
1597
|
callSite: (f, a) => f(...a)
|
|
1528
1598
|
});
|
|
@@ -1543,7 +1613,7 @@ var NetworkManager = class {
|
|
|
1543
1613
|
count: this._swarms.size
|
|
1544
1614
|
}, {
|
|
1545
1615
|
file: "network-manager.ts",
|
|
1546
|
-
line:
|
|
1616
|
+
line: 208,
|
|
1547
1617
|
scope: this,
|
|
1548
1618
|
callSite: (f, a) => f(...a)
|
|
1549
1619
|
});
|
|
@@ -2017,7 +2087,7 @@ var WebRTCTransportService = class {
|
|
|
2017
2087
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2018
2088
|
var import_node_assert10 = __toESM(require("node:assert"));
|
|
2019
2089
|
var import_async9 = require("@dxos/async");
|
|
2020
|
-
var
|
|
2090
|
+
var import_context5 = require("@dxos/context");
|
|
2021
2091
|
var import_debug6 = require("@dxos/debug");
|
|
2022
2092
|
var import_keys11 = require("@dxos/keys");
|
|
2023
2093
|
var import_log12 = require("@dxos/log");
|
|
@@ -2027,7 +2097,7 @@ var WebRTCTransportProxy = class {
|
|
|
2027
2097
|
constructor(_params) {
|
|
2028
2098
|
this._params = _params;
|
|
2029
2099
|
this._proxyId = import_keys11.PublicKey.random();
|
|
2030
|
-
this._ctx = new
|
|
2100
|
+
this._ctx = new import_context5.Context();
|
|
2031
2101
|
this.closed = new import_async9.Event();
|
|
2032
2102
|
this._closed = false;
|
|
2033
2103
|
this.connected = new import_async9.Event();
|