@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
package/dist/lib/node/index.cjs
CHANGED
|
@@ -61,7 +61,9 @@ var import_util4 = require("@dxos/util");
|
|
|
61
61
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
62
62
|
var import_node_assert = __toESM(require("node:assert"));
|
|
63
63
|
var import_async = require("@dxos/async");
|
|
64
|
+
var import_context = require("@dxos/context");
|
|
64
65
|
var import_debug = require("@dxos/debug");
|
|
66
|
+
var import_errors = require("@dxos/errors");
|
|
65
67
|
var import_keys = require("@dxos/keys");
|
|
66
68
|
var import_log = require("@dxos/log");
|
|
67
69
|
var import_protocols = require("@dxos/protocols");
|
|
@@ -75,6 +77,8 @@ var __decorate = function(decorators, target, key, desc) {
|
|
|
75
77
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
76
78
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
77
79
|
};
|
|
80
|
+
var STARTING_SIGNALLING_DELAY = 10;
|
|
81
|
+
var MAX_SIGNALLING_DELAY = 300;
|
|
78
82
|
var ConnectionState;
|
|
79
83
|
(function(ConnectionState5) {
|
|
80
84
|
ConnectionState5[
|
|
@@ -119,11 +123,17 @@ var Connection = class {
|
|
|
119
123
|
this._signalMessaging = _signalMessaging;
|
|
120
124
|
this._protocol = _protocol;
|
|
121
125
|
this._transportFactory = _transportFactory;
|
|
126
|
+
this._ctx = new import_context.Context();
|
|
122
127
|
this._state = ConnectionState.INITIAL;
|
|
123
|
-
this.
|
|
128
|
+
this._incomingSignalBuffer = [];
|
|
129
|
+
this._outgoingSignalBuffer = [];
|
|
124
130
|
this.stateChanged = new import_async.Event();
|
|
125
131
|
this.errors = new import_debug.ErrorStream();
|
|
126
132
|
this._instanceId = import_keys.PublicKey.random().toHex();
|
|
133
|
+
this._signalSendTask = new import_async.DeferredTask(this._ctx, async () => {
|
|
134
|
+
await this._flushSignalBuffer();
|
|
135
|
+
});
|
|
136
|
+
this._signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
127
137
|
}
|
|
128
138
|
get state() {
|
|
129
139
|
return this._state;
|
|
@@ -144,7 +154,7 @@ var Connection = class {
|
|
|
144
154
|
id: this._instanceId
|
|
145
155
|
}), {
|
|
146
156
|
file: "connection.ts",
|
|
147
|
-
line:
|
|
157
|
+
line: 115,
|
|
148
158
|
scope: this,
|
|
149
159
|
callSite: (f, a) => f(...a)
|
|
150
160
|
});
|
|
@@ -155,7 +165,7 @@ var Connection = class {
|
|
|
155
165
|
this._protocol.stream.on("close", () => {
|
|
156
166
|
(0, import_log.log)("protocol stream closed", {}, {
|
|
157
167
|
file: "connection.ts",
|
|
158
|
-
line:
|
|
168
|
+
line: 126,
|
|
159
169
|
scope: this,
|
|
160
170
|
callSite: (f, a) => f(...a)
|
|
161
171
|
});
|
|
@@ -165,29 +175,7 @@ var Connection = class {
|
|
|
165
175
|
this._transport = this._transportFactory.createTransport({
|
|
166
176
|
initiator: this.initiator,
|
|
167
177
|
stream: this._protocol.stream,
|
|
168
|
-
sendSignal: async (signal) =>
|
|
169
|
-
try {
|
|
170
|
-
await this._signalMessaging.signal({
|
|
171
|
-
author: this.ownId,
|
|
172
|
-
recipient: this.remoteId,
|
|
173
|
-
sessionId: this.sessionId,
|
|
174
|
-
topic: this.topic,
|
|
175
|
-
data: {
|
|
176
|
-
signal
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
} catch (err) {
|
|
180
|
-
(0, import_log.log)("Signal failed", {
|
|
181
|
-
err
|
|
182
|
-
}, {
|
|
183
|
-
file: "connection.ts",
|
|
184
|
-
line: 122,
|
|
185
|
-
scope: this,
|
|
186
|
-
callSite: (f, a) => f(...a)
|
|
187
|
-
});
|
|
188
|
-
await this.close();
|
|
189
|
-
}
|
|
190
|
-
}
|
|
178
|
+
sendSignal: async (signal) => this._sendSignal(signal)
|
|
191
179
|
});
|
|
192
180
|
this._transport.connected.once(() => {
|
|
193
181
|
this._changeState(ConnectionState.CONNECTED);
|
|
@@ -201,15 +189,15 @@ var Connection = class {
|
|
|
201
189
|
this.errors.raise(err);
|
|
202
190
|
}
|
|
203
191
|
});
|
|
204
|
-
for (const signal of this.
|
|
192
|
+
for (const signal of this._incomingSignalBuffer) {
|
|
205
193
|
void this._transport.signal(signal);
|
|
206
194
|
}
|
|
207
|
-
this.
|
|
195
|
+
this._incomingSignalBuffer = [];
|
|
208
196
|
import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.end({
|
|
209
197
|
id: this._instanceId
|
|
210
198
|
}), {
|
|
211
199
|
file: "connection.ts",
|
|
212
|
-
line:
|
|
200
|
+
line: 159,
|
|
213
201
|
scope: this,
|
|
214
202
|
callSite: (f, a) => f(...a)
|
|
215
203
|
});
|
|
@@ -220,11 +208,12 @@ var Connection = class {
|
|
|
220
208
|
return;
|
|
221
209
|
}
|
|
222
210
|
this._changeState(ConnectionState.CLOSING);
|
|
211
|
+
await this._ctx.dispose();
|
|
223
212
|
(0, import_log.log)("closing...", {
|
|
224
213
|
peerId: this.ownId
|
|
225
214
|
}, {
|
|
226
215
|
file: "connection.ts",
|
|
227
|
-
line:
|
|
216
|
+
line: 171,
|
|
228
217
|
scope: this,
|
|
229
218
|
callSite: (f, a) => f(...a)
|
|
230
219
|
});
|
|
@@ -233,7 +222,7 @@ var Connection = class {
|
|
|
233
222
|
} catch (err) {
|
|
234
223
|
import_log.log.catch(err, {}, {
|
|
235
224
|
file: "connection.ts",
|
|
236
|
-
line:
|
|
225
|
+
line: 177,
|
|
237
226
|
scope: this,
|
|
238
227
|
callSite: (f, a) => f(...a)
|
|
239
228
|
});
|
|
@@ -243,7 +232,7 @@ var Connection = class {
|
|
|
243
232
|
} catch (err1) {
|
|
244
233
|
import_log.log.catch(err1, {}, {
|
|
245
234
|
file: "connection.ts",
|
|
246
|
-
line:
|
|
235
|
+
line: 184,
|
|
247
236
|
scope: this,
|
|
248
237
|
callSite: (f, a) => f(...a)
|
|
249
238
|
});
|
|
@@ -252,53 +241,105 @@ var Connection = class {
|
|
|
252
241
|
peerId: this.ownId
|
|
253
242
|
}, {
|
|
254
243
|
file: "connection.ts",
|
|
255
|
-
line:
|
|
244
|
+
line: 187,
|
|
256
245
|
scope: this,
|
|
257
246
|
callSite: (f, a) => f(...a)
|
|
258
247
|
});
|
|
259
248
|
this._changeState(ConnectionState.CLOSED);
|
|
260
249
|
}
|
|
250
|
+
_sendSignal(signal) {
|
|
251
|
+
this._outgoingSignalBuffer.push(signal);
|
|
252
|
+
this._signalSendTask.schedule();
|
|
253
|
+
}
|
|
254
|
+
async _flushSignalBuffer() {
|
|
255
|
+
if (this._outgoingSignalBuffer.length === 0) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
await (0, import_context.cancelWithContext)(this._ctx, (0, import_async.sleep)(this._signallingDelay));
|
|
260
|
+
this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
|
|
261
|
+
const signals = [
|
|
262
|
+
...this._outgoingSignalBuffer
|
|
263
|
+
];
|
|
264
|
+
this._outgoingSignalBuffer.length = 0;
|
|
265
|
+
await this._signalMessaging.signal({
|
|
266
|
+
author: this.ownId,
|
|
267
|
+
recipient: this.remoteId,
|
|
268
|
+
sessionId: this.sessionId,
|
|
269
|
+
topic: this.topic,
|
|
270
|
+
data: {
|
|
271
|
+
signalBatch: {
|
|
272
|
+
signals
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
} catch (err) {
|
|
277
|
+
if (err instanceof import_errors.CancelledError) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
import_log.log.warn("Signal failed", {
|
|
281
|
+
err
|
|
282
|
+
}, {
|
|
283
|
+
file: "connection.ts",
|
|
284
|
+
line: 221,
|
|
285
|
+
scope: this,
|
|
286
|
+
callSite: (f, a) => f(...a)
|
|
287
|
+
});
|
|
288
|
+
await this.close();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Receive a signal from the remote peer.
|
|
293
|
+
*/
|
|
261
294
|
async signal(msg) {
|
|
262
|
-
var _a, _b;
|
|
295
|
+
var _a, _b, _c;
|
|
263
296
|
(0, import_node_assert.default)(msg.sessionId);
|
|
264
297
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
265
298
|
(0, import_log.log)("dropping signal for incorrect session id", {}, {
|
|
266
299
|
file: "connection.ts",
|
|
267
|
-
line:
|
|
300
|
+
line: 232,
|
|
268
301
|
scope: this,
|
|
269
302
|
callSite: (f, a) => f(...a)
|
|
270
303
|
});
|
|
271
304
|
return;
|
|
272
305
|
}
|
|
273
|
-
(0, import_node_assert.default)(msg.data.signal);
|
|
306
|
+
(0, import_node_assert.default)(msg.data.signal || msg.data.signalBatch);
|
|
274
307
|
(0, import_node_assert.default)((_a = msg.author) == null ? void 0 : _a.equals(this.remoteId));
|
|
275
308
|
(0, import_node_assert.default)((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId));
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
309
|
+
const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
|
|
310
|
+
msg.data.signal
|
|
311
|
+
];
|
|
312
|
+
for (const signal of signals) {
|
|
313
|
+
if (!signal) {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (this._state === ConnectionState.INITIAL) {
|
|
317
|
+
(0, import_log.log)("buffered signal", {
|
|
318
|
+
peerId: this.ownId,
|
|
319
|
+
remoteId: this.remoteId,
|
|
320
|
+
msg: msg.data
|
|
321
|
+
}, {
|
|
322
|
+
file: "connection.ts",
|
|
323
|
+
line: 246,
|
|
324
|
+
scope: this,
|
|
325
|
+
callSite: (f, a) => f(...a)
|
|
326
|
+
});
|
|
327
|
+
this._incomingSignalBuffer.push(signal);
|
|
328
|
+
} else {
|
|
329
|
+
(0, import_node_assert.default)(this._transport, "Connection not ready to accept signals.");
|
|
330
|
+
(0, import_log.log)("received signal", {
|
|
331
|
+
peerId: this.ownId,
|
|
332
|
+
remoteId: this.remoteId,
|
|
333
|
+
msg: msg.data
|
|
334
|
+
}, {
|
|
335
|
+
file: "connection.ts",
|
|
336
|
+
line: 250,
|
|
337
|
+
scope: this,
|
|
338
|
+
callSite: (f, a) => f(...a)
|
|
339
|
+
});
|
|
340
|
+
await this._transport.signal(signal);
|
|
341
|
+
}
|
|
289
342
|
}
|
|
290
|
-
(0, import_node_assert.default)(this._transport, "Connection not ready to accept signals.");
|
|
291
|
-
(0, import_log.log)("received signal", {
|
|
292
|
-
peerId: this.ownId,
|
|
293
|
-
remoteId: this.remoteId,
|
|
294
|
-
msg: msg.data
|
|
295
|
-
}, {
|
|
296
|
-
file: "connection.ts",
|
|
297
|
-
line: 197,
|
|
298
|
-
scope: this,
|
|
299
|
-
callSite: (f, a) => f(...a)
|
|
300
|
-
});
|
|
301
|
-
await this._transport.signal(msg.data.signal);
|
|
302
343
|
}
|
|
303
344
|
_changeState(state) {
|
|
304
345
|
(0, import_log.log)("stateChanged", {
|
|
@@ -307,7 +348,7 @@ var Connection = class {
|
|
|
307
348
|
peerId: this.ownId
|
|
308
349
|
}, {
|
|
309
350
|
file: "connection.ts",
|
|
310
|
-
line:
|
|
351
|
+
line: 257,
|
|
311
352
|
scope: this,
|
|
312
353
|
callSite: (f, a) => f(...a)
|
|
313
354
|
});
|
|
@@ -323,7 +364,7 @@ __decorate([
|
|
|
323
364
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
324
365
|
var import_node_assert4 = __toESM(require("node:assert"));
|
|
325
366
|
var import_async3 = require("@dxos/async");
|
|
326
|
-
var
|
|
367
|
+
var import_context4 = require("@dxos/context");
|
|
327
368
|
var import_debug2 = require("@dxos/debug");
|
|
328
369
|
var import_keys4 = require("@dxos/keys");
|
|
329
370
|
var import_log4 = require("@dxos/log");
|
|
@@ -332,14 +373,14 @@ var import_util2 = require("@dxos/util");
|
|
|
332
373
|
|
|
333
374
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
334
375
|
var import_node_assert2 = __toESM(require("node:assert"));
|
|
335
|
-
var
|
|
376
|
+
var import_context2 = require("@dxos/context");
|
|
336
377
|
var import_keys2 = require("@dxos/keys");
|
|
337
378
|
var import_log2 = require("@dxos/log");
|
|
338
379
|
var import_protocols2 = require("@dxos/protocols");
|
|
339
380
|
var import_util = require("@dxos/util");
|
|
340
381
|
var SwarmMessenger = class {
|
|
341
382
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
342
|
-
this._ctx = new
|
|
383
|
+
this._ctx = new import_context2.Context();
|
|
343
384
|
this._offerRecords = new import_util.ComplexMap((key) => key.toHex());
|
|
344
385
|
this._sendMessage = sendMessage;
|
|
345
386
|
this._onSignal = onSignal;
|
|
@@ -347,7 +388,7 @@ var SwarmMessenger = class {
|
|
|
347
388
|
this._topic = topic;
|
|
348
389
|
}
|
|
349
390
|
async receiveMessage({ author, recipient, payload }) {
|
|
350
|
-
var _a, _b, _c;
|
|
391
|
+
var _a, _b, _c, _d;
|
|
351
392
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
352
393
|
return;
|
|
353
394
|
}
|
|
@@ -379,11 +420,26 @@ var SwarmMessenger = class {
|
|
|
379
420
|
recipient,
|
|
380
421
|
message
|
|
381
422
|
});
|
|
423
|
+
} else if ((_d = message.data) == null ? void 0 : _d.signalBatch) {
|
|
424
|
+
await this._handleSignal({
|
|
425
|
+
author,
|
|
426
|
+
recipient,
|
|
427
|
+
message
|
|
428
|
+
});
|
|
429
|
+
} else {
|
|
430
|
+
import_log2.log.warn("unknown message", {
|
|
431
|
+
message
|
|
432
|
+
}, {
|
|
433
|
+
file: "swarm-messenger.ts",
|
|
434
|
+
line: 79,
|
|
435
|
+
scope: this,
|
|
436
|
+
callSite: (f, a) => f(...a)
|
|
437
|
+
});
|
|
382
438
|
}
|
|
383
439
|
}
|
|
384
440
|
async signal(message) {
|
|
385
|
-
var _a;
|
|
386
|
-
(0, import_node_assert2.default)((_a = message.data) == null ? void 0 : _a.signal);
|
|
441
|
+
var _a, _b;
|
|
442
|
+
(0, import_node_assert2.default)(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message");
|
|
387
443
|
await this._sendReliableMessage({
|
|
388
444
|
author: message.author,
|
|
389
445
|
recipient: message.recipient,
|
|
@@ -419,7 +475,7 @@ var SwarmMessenger = class {
|
|
|
419
475
|
msg: networkMessage
|
|
420
476
|
}, {
|
|
421
477
|
file: "swarm-messenger.ts",
|
|
422
|
-
line:
|
|
478
|
+
line: 122,
|
|
423
479
|
scope: this,
|
|
424
480
|
callSite: (f, a) => f(...a)
|
|
425
481
|
});
|
|
@@ -443,7 +499,7 @@ var SwarmMessenger = class {
|
|
|
443
499
|
answer: message.data.answer
|
|
444
500
|
}, {
|
|
445
501
|
file: "swarm-messenger.ts",
|
|
446
|
-
line:
|
|
502
|
+
line: 139,
|
|
447
503
|
scope: this,
|
|
448
504
|
callSite: (f, a) => f(...a)
|
|
449
505
|
});
|
|
@@ -462,27 +518,39 @@ var SwarmMessenger = class {
|
|
|
462
518
|
};
|
|
463
519
|
const answer = await this._onOffer(offerMessage);
|
|
464
520
|
answer.offerMessageId = message.messageId;
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
521
|
+
try {
|
|
522
|
+
await this._sendReliableMessage({
|
|
523
|
+
author: recipient,
|
|
524
|
+
recipient: author,
|
|
525
|
+
message: {
|
|
526
|
+
topic: message.topic,
|
|
527
|
+
sessionId: message.sessionId,
|
|
528
|
+
data: {
|
|
529
|
+
answer
|
|
530
|
+
}
|
|
473
531
|
}
|
|
474
|
-
}
|
|
475
|
-
})
|
|
532
|
+
});
|
|
533
|
+
} catch (err) {
|
|
534
|
+
import_log2.log.warn("error sending answer", {
|
|
535
|
+
err
|
|
536
|
+
}, {
|
|
537
|
+
file: "swarm-messenger.ts",
|
|
538
|
+
line: 173,
|
|
539
|
+
scope: this,
|
|
540
|
+
callSite: (f, a) => f(...a)
|
|
541
|
+
});
|
|
542
|
+
}
|
|
476
543
|
}
|
|
477
544
|
async _handleSignal({ author, recipient, message }) {
|
|
478
545
|
(0, import_node_assert2.default)(message.messageId);
|
|
479
|
-
(0, import_node_assert2.default)(message.data.signal, "
|
|
546
|
+
(0, import_node_assert2.default)(message.data.signal || message.data.signalBatch, "Invalid message");
|
|
480
547
|
const signalMessage = {
|
|
481
548
|
author,
|
|
482
549
|
recipient,
|
|
483
550
|
...message,
|
|
484
551
|
data: {
|
|
485
|
-
signal: message.data.signal
|
|
552
|
+
signal: message.data.signal,
|
|
553
|
+
signalBatch: message.data.signalBatch
|
|
486
554
|
}
|
|
487
555
|
};
|
|
488
556
|
await this._onSignal(signalMessage);
|
|
@@ -492,7 +560,7 @@ var SwarmMessenger = class {
|
|
|
492
560
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
493
561
|
var import_node_assert3 = __toESM(require("node:assert"));
|
|
494
562
|
var import_async2 = require("@dxos/async");
|
|
495
|
-
var
|
|
563
|
+
var import_context3 = require("@dxos/context");
|
|
496
564
|
var import_keys3 = require("@dxos/keys");
|
|
497
565
|
var import_log3 = require("@dxos/log");
|
|
498
566
|
var __decorate2 = function(decorators, target, key, desc) {
|
|
@@ -517,7 +585,7 @@ var Peer = class {
|
|
|
517
585
|
this._callbacks = _callbacks;
|
|
518
586
|
this._availableAfter = 0;
|
|
519
587
|
this.availableToConnect = true;
|
|
520
|
-
this._ctx = new
|
|
588
|
+
this._ctx = new import_context3.Context();
|
|
521
589
|
this.advertizing = false;
|
|
522
590
|
this.initiating = false;
|
|
523
591
|
}
|
|
@@ -838,7 +906,8 @@ var Swarm = class {
|
|
|
838
906
|
this._transportFactory = _transportFactory;
|
|
839
907
|
this._label = _label;
|
|
840
908
|
this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
|
|
841
|
-
this._ctx = new
|
|
909
|
+
this._ctx = new import_context4.Context();
|
|
910
|
+
this._listeningHandle = void 0;
|
|
842
911
|
this.connectionAdded = new import_async3.Event();
|
|
843
912
|
this.disconnected = new import_async3.Event();
|
|
844
913
|
this.connected = new import_async3.Event();
|
|
@@ -852,7 +921,7 @@ var Swarm = class {
|
|
|
852
921
|
}
|
|
853
922
|
}), {
|
|
854
923
|
file: "swarm.ts",
|
|
855
|
-
line:
|
|
924
|
+
line: 86,
|
|
856
925
|
scope: this,
|
|
857
926
|
callSite: (f, a) => f(...a)
|
|
858
927
|
});
|
|
@@ -860,7 +929,7 @@ var Swarm = class {
|
|
|
860
929
|
peerId: _ownPeerId
|
|
861
930
|
}, {
|
|
862
931
|
file: "swarm.ts",
|
|
863
|
-
line:
|
|
932
|
+
line: 90,
|
|
864
933
|
scope: this,
|
|
865
934
|
callSite: (f, a) => f(...a)
|
|
866
935
|
});
|
|
@@ -871,30 +940,11 @@ var Swarm = class {
|
|
|
871
940
|
onOffer: async (msg) => await this.onOffer(msg),
|
|
872
941
|
topic: this._topic
|
|
873
942
|
});
|
|
874
|
-
this._messenger.listen({
|
|
875
|
-
peerId: this._ownPeerId,
|
|
876
|
-
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
877
|
-
onMessage: async (message) => {
|
|
878
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) => (0, import_log4.log)("Error while receiving message", {
|
|
879
|
-
err
|
|
880
|
-
}, {
|
|
881
|
-
file: "swarm.ts",
|
|
882
|
-
line: 105,
|
|
883
|
-
scope: this,
|
|
884
|
-
callSite: (f, a) => f(...a)
|
|
885
|
-
}));
|
|
886
|
-
}
|
|
887
|
-
}).catch((error) => import_log4.log.catch(error, {}, {
|
|
888
|
-
file: "swarm.ts",
|
|
889
|
-
line: 108,
|
|
890
|
-
scope: this,
|
|
891
|
-
callSite: (f, a) => f(...a)
|
|
892
|
-
}));
|
|
893
943
|
import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.end({
|
|
894
944
|
id: this._instanceId
|
|
895
945
|
}), {
|
|
896
946
|
file: "swarm.ts",
|
|
897
|
-
line:
|
|
947
|
+
line: 99,
|
|
898
948
|
scope: this,
|
|
899
949
|
callSite: (f, a) => f(...a)
|
|
900
950
|
});
|
|
@@ -914,20 +964,39 @@ var Swarm = class {
|
|
|
914
964
|
get topic() {
|
|
915
965
|
return this._topic;
|
|
916
966
|
}
|
|
917
|
-
|
|
967
|
+
async open() {
|
|
968
|
+
(0, import_node_assert4.default)(!this._listeningHandle);
|
|
969
|
+
this._listeningHandle = await this._messenger.listen({
|
|
970
|
+
peerId: this._ownPeerId,
|
|
971
|
+
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
972
|
+
onMessage: async (message) => {
|
|
973
|
+
await this._swarmMessenger.receiveMessage(message).catch((err) => import_log4.log.warn("Error while receiving message", {
|
|
974
|
+
err
|
|
975
|
+
}, {
|
|
976
|
+
file: "swarm.ts",
|
|
977
|
+
line: 133,
|
|
978
|
+
scope: this,
|
|
979
|
+
callSite: (f, a) => f(...a)
|
|
980
|
+
}));
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
}
|
|
918
984
|
async destroy() {
|
|
985
|
+
var _a;
|
|
919
986
|
(0, import_log4.log)("destroying...", {}, {
|
|
920
987
|
file: "swarm.ts",
|
|
921
|
-
line:
|
|
988
|
+
line: 139,
|
|
922
989
|
scope: this,
|
|
923
990
|
callSite: (f, a) => f(...a)
|
|
924
991
|
});
|
|
992
|
+
await ((_a = this._listeningHandle) == null ? void 0 : _a.unsubscribe());
|
|
993
|
+
this._listeningHandle = void 0;
|
|
925
994
|
await this._ctx.dispose();
|
|
926
995
|
await this._topology.destroy();
|
|
927
996
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
928
997
|
(0, import_log4.log)("destroyed", {}, {
|
|
929
998
|
file: "swarm.ts",
|
|
930
|
-
line:
|
|
999
|
+
line: 146,
|
|
931
1000
|
scope: this,
|
|
932
1001
|
callSite: (f, a) => f(...a)
|
|
933
1002
|
});
|
|
@@ -942,7 +1011,7 @@ var Swarm = class {
|
|
|
942
1011
|
topology: getClassName(topology)
|
|
943
1012
|
}, {
|
|
944
1013
|
file: "swarm.ts",
|
|
945
|
-
line:
|
|
1014
|
+
line: 154,
|
|
946
1015
|
scope: this,
|
|
947
1016
|
callSite: (f, a) => f(...a)
|
|
948
1017
|
});
|
|
@@ -957,14 +1026,14 @@ var Swarm = class {
|
|
|
957
1026
|
swarmEvent
|
|
958
1027
|
}, {
|
|
959
1028
|
file: "swarm.ts",
|
|
960
|
-
line:
|
|
1029
|
+
line: 167,
|
|
961
1030
|
scope: this,
|
|
962
1031
|
callSite: (f, a) => f(...a)
|
|
963
1032
|
});
|
|
964
1033
|
if (this._ctx.disposed) {
|
|
965
1034
|
(0, import_log4.log)("swarm event ignored for disposed swarm", {}, {
|
|
966
1035
|
file: "swarm.ts",
|
|
967
|
-
line:
|
|
1036
|
+
line: 170,
|
|
968
1037
|
scope: this,
|
|
969
1038
|
callSite: (f, a) => f(...a)
|
|
970
1039
|
});
|
|
@@ -976,7 +1045,7 @@ var Swarm = class {
|
|
|
976
1045
|
peerId
|
|
977
1046
|
}, {
|
|
978
1047
|
file: "swarm.ts",
|
|
979
|
-
line:
|
|
1048
|
+
line: 176,
|
|
980
1049
|
scope: this,
|
|
981
1050
|
callSite: (f, a) => f(...a)
|
|
982
1051
|
});
|
|
@@ -991,7 +1060,7 @@ var Swarm = class {
|
|
|
991
1060
|
if (((_a = peer1.connection) == null ? void 0 : _a.state) !== ConnectionState.CONNECTED) {
|
|
992
1061
|
void this._destroyPeer(peer1.id).catch((err) => import_log4.log.catch(err, {}, {
|
|
993
1062
|
file: "swarm.ts",
|
|
994
|
-
line:
|
|
1063
|
+
line: 187,
|
|
995
1064
|
scope: this,
|
|
996
1065
|
callSite: (f, a) => f(...a)
|
|
997
1066
|
}));
|
|
@@ -1006,14 +1075,14 @@ var Swarm = class {
|
|
|
1006
1075
|
message
|
|
1007
1076
|
}, {
|
|
1008
1077
|
file: "swarm.ts",
|
|
1009
|
-
line:
|
|
1078
|
+
line: 197,
|
|
1010
1079
|
scope: this,
|
|
1011
1080
|
callSite: (f, a) => f(...a)
|
|
1012
1081
|
});
|
|
1013
1082
|
if (this._ctx.disposed) {
|
|
1014
1083
|
(0, import_log4.log)("ignored for disposed swarm", {}, {
|
|
1015
1084
|
file: "swarm.ts",
|
|
1016
|
-
line:
|
|
1085
|
+
line: 199,
|
|
1017
1086
|
scope: this,
|
|
1018
1087
|
callSite: (f, a) => f(...a)
|
|
1019
1088
|
});
|
|
@@ -1027,7 +1096,7 @@ var Swarm = class {
|
|
|
1027
1096
|
message
|
|
1028
1097
|
}, {
|
|
1029
1098
|
file: "swarm.ts",
|
|
1030
|
-
line:
|
|
1099
|
+
line: 206,
|
|
1031
1100
|
scope: this,
|
|
1032
1101
|
callSite: (f, a) => f(...a)
|
|
1033
1102
|
});
|
|
@@ -1040,7 +1109,7 @@ var Swarm = class {
|
|
|
1040
1109
|
message
|
|
1041
1110
|
}, {
|
|
1042
1111
|
file: "swarm.ts",
|
|
1043
|
-
line:
|
|
1112
|
+
line: 210,
|
|
1044
1113
|
scope: this,
|
|
1045
1114
|
callSite: (f, a) => f(...a)
|
|
1046
1115
|
});
|
|
@@ -1059,14 +1128,14 @@ var Swarm = class {
|
|
|
1059
1128
|
message
|
|
1060
1129
|
}, {
|
|
1061
1130
|
file: "swarm.ts",
|
|
1062
|
-
line:
|
|
1131
|
+
line: 222,
|
|
1063
1132
|
scope: this,
|
|
1064
1133
|
callSite: (f, a) => f(...a)
|
|
1065
1134
|
});
|
|
1066
1135
|
if (this._ctx.disposed) {
|
|
1067
1136
|
import_log4.log.info("ignored for offline swarm", {}, {
|
|
1068
1137
|
file: "swarm.ts",
|
|
1069
|
-
line:
|
|
1138
|
+
line: 224,
|
|
1070
1139
|
scope: this,
|
|
1071
1140
|
callSite: (f, a) => f(...a)
|
|
1072
1141
|
});
|
|
@@ -1087,7 +1156,7 @@ var Swarm = class {
|
|
|
1087
1156
|
}
|
|
1088
1157
|
// For debug purposes
|
|
1089
1158
|
async goOnline() {
|
|
1090
|
-
this._ctx = new
|
|
1159
|
+
this._ctx = new import_context4.Context();
|
|
1091
1160
|
}
|
|
1092
1161
|
_getOrCreatePeer(peerId) {
|
|
1093
1162
|
let peer = this._peers.get(peerId);
|
|
@@ -1147,7 +1216,7 @@ var Swarm = class {
|
|
|
1147
1216
|
} catch (err) {
|
|
1148
1217
|
(0, import_log4.log)("initiation error", err, {
|
|
1149
1218
|
file: "swarm.ts",
|
|
1150
|
-
line:
|
|
1219
|
+
line: 327,
|
|
1151
1220
|
scope: this,
|
|
1152
1221
|
callSite: (f, a) => f(...a)
|
|
1153
1222
|
});
|
|
@@ -1175,7 +1244,7 @@ var Swarm = class {
|
|
|
1175
1244
|
remoteId
|
|
1176
1245
|
}, {
|
|
1177
1246
|
file: "swarm.ts",
|
|
1178
|
-
line:
|
|
1247
|
+
line: 354,
|
|
1179
1248
|
scope: this,
|
|
1180
1249
|
callSite: (f, a) => f(...a)
|
|
1181
1250
|
});
|
|
@@ -1192,7 +1261,7 @@ var Swarm = class {
|
|
|
1192
1261
|
remoteId
|
|
1193
1262
|
}, {
|
|
1194
1263
|
file: "swarm.ts",
|
|
1195
|
-
line:
|
|
1264
|
+
line: 368,
|
|
1196
1265
|
scope: this,
|
|
1197
1266
|
callSite: (f, a) => f(...a)
|
|
1198
1267
|
});
|
|
@@ -1202,7 +1271,7 @@ var Swarm = class {
|
|
|
1202
1271
|
remoteId
|
|
1203
1272
|
}, {
|
|
1204
1273
|
file: "swarm.ts",
|
|
1205
|
-
line:
|
|
1274
|
+
line: 371,
|
|
1206
1275
|
scope: this,
|
|
1207
1276
|
callSite: (f, a) => f(...a)
|
|
1208
1277
|
});
|
|
@@ -1490,16 +1559,17 @@ var NetworkManager = class {
|
|
|
1490
1559
|
});
|
|
1491
1560
|
});
|
|
1492
1561
|
this._swarms.set(topic, swarm);
|
|
1562
|
+
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
1563
|
+
await swarm.open();
|
|
1493
1564
|
this._signalConnection.join({
|
|
1494
1565
|
topic,
|
|
1495
1566
|
peerId
|
|
1496
1567
|
}).catch((error) => import_log6.log.catch(error, {}, {
|
|
1497
1568
|
file: "network-manager.ts",
|
|
1498
|
-
line:
|
|
1569
|
+
line: 174,
|
|
1499
1570
|
scope: this,
|
|
1500
1571
|
callSite: (f, a) => f(...a)
|
|
1501
1572
|
}));
|
|
1502
|
-
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
1503
1573
|
this.topicsUpdated.emit();
|
|
1504
1574
|
(_a = this._connectionLog) == null ? void 0 : _a.joinedSwarm(swarm);
|
|
1505
1575
|
(0, import_log6.log)("joined", {
|
|
@@ -1507,7 +1577,7 @@ var NetworkManager = class {
|
|
|
1507
1577
|
count: this._swarms.size
|
|
1508
1578
|
}, {
|
|
1509
1579
|
file: "network-manager.ts",
|
|
1510
|
-
line:
|
|
1580
|
+
line: 178,
|
|
1511
1581
|
scope: this,
|
|
1512
1582
|
callSite: (f, a) => f(...a)
|
|
1513
1583
|
});
|
|
@@ -1527,7 +1597,7 @@ var NetworkManager = class {
|
|
|
1527
1597
|
topic: import_keys7.PublicKey.from(topic)
|
|
1528
1598
|
}, {
|
|
1529
1599
|
file: "network-manager.ts",
|
|
1530
|
-
line:
|
|
1600
|
+
line: 194,
|
|
1531
1601
|
scope: this,
|
|
1532
1602
|
callSite: (f, a) => f(...a)
|
|
1533
1603
|
});
|
|
@@ -1548,7 +1618,7 @@ var NetworkManager = class {
|
|
|
1548
1618
|
count: this._swarms.size
|
|
1549
1619
|
}, {
|
|
1550
1620
|
file: "network-manager.ts",
|
|
1551
|
-
line:
|
|
1621
|
+
line: 208,
|
|
1552
1622
|
scope: this,
|
|
1553
1623
|
callSite: (f, a) => f(...a)
|
|
1554
1624
|
});
|
|
@@ -2170,7 +2240,7 @@ var WebRTCTransportService = class {
|
|
|
2170
2240
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2171
2241
|
var import_node_assert12 = __toESM(require("node:assert"));
|
|
2172
2242
|
var import_async9 = require("@dxos/async");
|
|
2173
|
-
var
|
|
2243
|
+
var import_context5 = require("@dxos/context");
|
|
2174
2244
|
var import_debug6 = require("@dxos/debug");
|
|
2175
2245
|
var import_keys11 = require("@dxos/keys");
|
|
2176
2246
|
var import_log12 = require("@dxos/log");
|
|
@@ -2180,7 +2250,7 @@ var WebRTCTransportProxy = class {
|
|
|
2180
2250
|
constructor(_params) {
|
|
2181
2251
|
this._params = _params;
|
|
2182
2252
|
this._proxyId = import_keys11.PublicKey.random();
|
|
2183
|
-
this._ctx = new
|
|
2253
|
+
this._ctx = new import_context5.Context();
|
|
2184
2254
|
this.closed = new import_async9.Event();
|
|
2185
2255
|
this._closed = false;
|
|
2186
2256
|
this.connected = new import_async9.Event();
|