@dxos/network-manager 0.1.48 → 0.1.49-next.7ec9d52
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
|
@@ -9,8 +9,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
9
|
|
|
10
10
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
11
11
|
import assert from "@dxos/node-std/assert";
|
|
12
|
-
import { Event, synchronized } from "@dxos/async";
|
|
12
|
+
import { DeferredTask, Event, sleep, synchronized } from "@dxos/async";
|
|
13
|
+
import { Context, cancelWithContext } from "@dxos/context";
|
|
13
14
|
import { ErrorStream } from "@dxos/debug";
|
|
15
|
+
import { CancelledError } from "@dxos/errors";
|
|
14
16
|
import { PublicKey } from "@dxos/keys";
|
|
15
17
|
import { log } from "@dxos/log";
|
|
16
18
|
import { trace } from "@dxos/protocols";
|
|
@@ -24,6 +26,8 @@ var __decorate = function(decorators, target, key, desc) {
|
|
|
24
26
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
25
27
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
26
28
|
};
|
|
29
|
+
var STARTING_SIGNALLING_DELAY = 10;
|
|
30
|
+
var MAX_SIGNALLING_DELAY = 300;
|
|
27
31
|
var ConnectionState;
|
|
28
32
|
(function(ConnectionState5) {
|
|
29
33
|
ConnectionState5[
|
|
@@ -68,11 +72,17 @@ var Connection = class {
|
|
|
68
72
|
this._signalMessaging = _signalMessaging;
|
|
69
73
|
this._protocol = _protocol;
|
|
70
74
|
this._transportFactory = _transportFactory;
|
|
75
|
+
this._ctx = new Context();
|
|
71
76
|
this._state = ConnectionState.INITIAL;
|
|
72
|
-
this.
|
|
77
|
+
this._incomingSignalBuffer = [];
|
|
78
|
+
this._outgoingSignalBuffer = [];
|
|
73
79
|
this.stateChanged = new Event();
|
|
74
80
|
this.errors = new ErrorStream();
|
|
75
81
|
this._instanceId = PublicKey.random().toHex();
|
|
82
|
+
this._signalSendTask = new DeferredTask(this._ctx, async () => {
|
|
83
|
+
await this._flushSignalBuffer();
|
|
84
|
+
});
|
|
85
|
+
this._signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
76
86
|
}
|
|
77
87
|
get state() {
|
|
78
88
|
return this._state;
|
|
@@ -93,7 +103,7 @@ var Connection = class {
|
|
|
93
103
|
id: this._instanceId
|
|
94
104
|
}), {
|
|
95
105
|
file: "connection.ts",
|
|
96
|
-
line:
|
|
106
|
+
line: 115,
|
|
97
107
|
scope: this,
|
|
98
108
|
callSite: (f, a) => f(...a)
|
|
99
109
|
});
|
|
@@ -104,7 +114,7 @@ var Connection = class {
|
|
|
104
114
|
this._protocol.stream.on("close", () => {
|
|
105
115
|
log("protocol stream closed", {}, {
|
|
106
116
|
file: "connection.ts",
|
|
107
|
-
line:
|
|
117
|
+
line: 126,
|
|
108
118
|
scope: this,
|
|
109
119
|
callSite: (f, a) => f(...a)
|
|
110
120
|
});
|
|
@@ -114,29 +124,7 @@ var Connection = class {
|
|
|
114
124
|
this._transport = this._transportFactory.createTransport({
|
|
115
125
|
initiator: this.initiator,
|
|
116
126
|
stream: this._protocol.stream,
|
|
117
|
-
sendSignal: async (signal) =>
|
|
118
|
-
try {
|
|
119
|
-
await this._signalMessaging.signal({
|
|
120
|
-
author: this.ownId,
|
|
121
|
-
recipient: this.remoteId,
|
|
122
|
-
sessionId: this.sessionId,
|
|
123
|
-
topic: this.topic,
|
|
124
|
-
data: {
|
|
125
|
-
signal
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
} catch (err) {
|
|
129
|
-
log("Signal failed", {
|
|
130
|
-
err
|
|
131
|
-
}, {
|
|
132
|
-
file: "connection.ts",
|
|
133
|
-
line: 122,
|
|
134
|
-
scope: this,
|
|
135
|
-
callSite: (f, a) => f(...a)
|
|
136
|
-
});
|
|
137
|
-
await this.close();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
127
|
+
sendSignal: async (signal) => this._sendSignal(signal)
|
|
140
128
|
});
|
|
141
129
|
this._transport.connected.once(() => {
|
|
142
130
|
this._changeState(ConnectionState.CONNECTED);
|
|
@@ -150,15 +138,15 @@ var Connection = class {
|
|
|
150
138
|
this.errors.raise(err);
|
|
151
139
|
}
|
|
152
140
|
});
|
|
153
|
-
for (const signal of this.
|
|
141
|
+
for (const signal of this._incomingSignalBuffer) {
|
|
154
142
|
void this._transport.signal(signal);
|
|
155
143
|
}
|
|
156
|
-
this.
|
|
144
|
+
this._incomingSignalBuffer = [];
|
|
157
145
|
log.trace("dxos.mesh.connection.open-connection", trace.end({
|
|
158
146
|
id: this._instanceId
|
|
159
147
|
}), {
|
|
160
148
|
file: "connection.ts",
|
|
161
|
-
line:
|
|
149
|
+
line: 159,
|
|
162
150
|
scope: this,
|
|
163
151
|
callSite: (f, a) => f(...a)
|
|
164
152
|
});
|
|
@@ -169,11 +157,12 @@ var Connection = class {
|
|
|
169
157
|
return;
|
|
170
158
|
}
|
|
171
159
|
this._changeState(ConnectionState.CLOSING);
|
|
160
|
+
await this._ctx.dispose();
|
|
172
161
|
log("closing...", {
|
|
173
162
|
peerId: this.ownId
|
|
174
163
|
}, {
|
|
175
164
|
file: "connection.ts",
|
|
176
|
-
line:
|
|
165
|
+
line: 171,
|
|
177
166
|
scope: this,
|
|
178
167
|
callSite: (f, a) => f(...a)
|
|
179
168
|
});
|
|
@@ -182,7 +171,7 @@ var Connection = class {
|
|
|
182
171
|
} catch (err) {
|
|
183
172
|
log.catch(err, {}, {
|
|
184
173
|
file: "connection.ts",
|
|
185
|
-
line:
|
|
174
|
+
line: 177,
|
|
186
175
|
scope: this,
|
|
187
176
|
callSite: (f, a) => f(...a)
|
|
188
177
|
});
|
|
@@ -192,7 +181,7 @@ var Connection = class {
|
|
|
192
181
|
} catch (err1) {
|
|
193
182
|
log.catch(err1, {}, {
|
|
194
183
|
file: "connection.ts",
|
|
195
|
-
line:
|
|
184
|
+
line: 184,
|
|
196
185
|
scope: this,
|
|
197
186
|
callSite: (f, a) => f(...a)
|
|
198
187
|
});
|
|
@@ -201,53 +190,105 @@ var Connection = class {
|
|
|
201
190
|
peerId: this.ownId
|
|
202
191
|
}, {
|
|
203
192
|
file: "connection.ts",
|
|
204
|
-
line:
|
|
193
|
+
line: 187,
|
|
205
194
|
scope: this,
|
|
206
195
|
callSite: (f, a) => f(...a)
|
|
207
196
|
});
|
|
208
197
|
this._changeState(ConnectionState.CLOSED);
|
|
209
198
|
}
|
|
199
|
+
_sendSignal(signal) {
|
|
200
|
+
this._outgoingSignalBuffer.push(signal);
|
|
201
|
+
this._signalSendTask.schedule();
|
|
202
|
+
}
|
|
203
|
+
async _flushSignalBuffer() {
|
|
204
|
+
if (this._outgoingSignalBuffer.length === 0) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
await cancelWithContext(this._ctx, sleep(this._signallingDelay));
|
|
209
|
+
this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
|
|
210
|
+
const signals = [
|
|
211
|
+
...this._outgoingSignalBuffer
|
|
212
|
+
];
|
|
213
|
+
this._outgoingSignalBuffer.length = 0;
|
|
214
|
+
await this._signalMessaging.signal({
|
|
215
|
+
author: this.ownId,
|
|
216
|
+
recipient: this.remoteId,
|
|
217
|
+
sessionId: this.sessionId,
|
|
218
|
+
topic: this.topic,
|
|
219
|
+
data: {
|
|
220
|
+
signalBatch: {
|
|
221
|
+
signals
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
} catch (err) {
|
|
226
|
+
if (err instanceof CancelledError) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
log.warn("Signal failed", {
|
|
230
|
+
err
|
|
231
|
+
}, {
|
|
232
|
+
file: "connection.ts",
|
|
233
|
+
line: 221,
|
|
234
|
+
scope: this,
|
|
235
|
+
callSite: (f, a) => f(...a)
|
|
236
|
+
});
|
|
237
|
+
await this.close();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Receive a signal from the remote peer.
|
|
242
|
+
*/
|
|
210
243
|
async signal(msg) {
|
|
211
|
-
var _a, _b;
|
|
244
|
+
var _a, _b, _c;
|
|
212
245
|
assert(msg.sessionId);
|
|
213
246
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
214
247
|
log("dropping signal for incorrect session id", {}, {
|
|
215
248
|
file: "connection.ts",
|
|
216
|
-
line:
|
|
249
|
+
line: 232,
|
|
217
250
|
scope: this,
|
|
218
251
|
callSite: (f, a) => f(...a)
|
|
219
252
|
});
|
|
220
253
|
return;
|
|
221
254
|
}
|
|
222
|
-
assert(msg.data.signal);
|
|
255
|
+
assert(msg.data.signal || msg.data.signalBatch);
|
|
223
256
|
assert((_a = msg.author) == null ? void 0 : _a.equals(this.remoteId));
|
|
224
257
|
assert((_b = msg.recipient) == null ? void 0 : _b.equals(this.ownId));
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
258
|
+
const signals = msg.data.signalBatch ? (_c = msg.data.signalBatch.signals) != null ? _c : [] : [
|
|
259
|
+
msg.data.signal
|
|
260
|
+
];
|
|
261
|
+
for (const signal of signals) {
|
|
262
|
+
if (!signal) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (this._state === ConnectionState.INITIAL) {
|
|
266
|
+
log("buffered signal", {
|
|
267
|
+
peerId: this.ownId,
|
|
268
|
+
remoteId: this.remoteId,
|
|
269
|
+
msg: msg.data
|
|
270
|
+
}, {
|
|
271
|
+
file: "connection.ts",
|
|
272
|
+
line: 246,
|
|
273
|
+
scope: this,
|
|
274
|
+
callSite: (f, a) => f(...a)
|
|
275
|
+
});
|
|
276
|
+
this._incomingSignalBuffer.push(signal);
|
|
277
|
+
} else {
|
|
278
|
+
assert(this._transport, "Connection not ready to accept signals.");
|
|
279
|
+
log("received signal", {
|
|
280
|
+
peerId: this.ownId,
|
|
281
|
+
remoteId: this.remoteId,
|
|
282
|
+
msg: msg.data
|
|
283
|
+
}, {
|
|
284
|
+
file: "connection.ts",
|
|
285
|
+
line: 250,
|
|
286
|
+
scope: this,
|
|
287
|
+
callSite: (f, a) => f(...a)
|
|
288
|
+
});
|
|
289
|
+
await this._transport.signal(signal);
|
|
290
|
+
}
|
|
238
291
|
}
|
|
239
|
-
assert(this._transport, "Connection not ready to accept signals.");
|
|
240
|
-
log("received signal", {
|
|
241
|
-
peerId: this.ownId,
|
|
242
|
-
remoteId: this.remoteId,
|
|
243
|
-
msg: msg.data
|
|
244
|
-
}, {
|
|
245
|
-
file: "connection.ts",
|
|
246
|
-
line: 197,
|
|
247
|
-
scope: this,
|
|
248
|
-
callSite: (f, a) => f(...a)
|
|
249
|
-
});
|
|
250
|
-
await this._transport.signal(msg.data.signal);
|
|
251
292
|
}
|
|
252
293
|
_changeState(state) {
|
|
253
294
|
log("stateChanged", {
|
|
@@ -256,7 +297,7 @@ var Connection = class {
|
|
|
256
297
|
peerId: this.ownId
|
|
257
298
|
}, {
|
|
258
299
|
file: "connection.ts",
|
|
259
|
-
line:
|
|
300
|
+
line: 257,
|
|
260
301
|
scope: this,
|
|
261
302
|
callSite: (f, a) => f(...a)
|
|
262
303
|
});
|
|
@@ -271,14 +312,14 @@ __decorate([
|
|
|
271
312
|
|
|
272
313
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
273
314
|
import assert2 from "@dxos/node-std/assert";
|
|
274
|
-
import { Context } from "@dxos/context";
|
|
315
|
+
import { Context as Context2 } from "@dxos/context";
|
|
275
316
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
276
317
|
import { log as log2 } from "@dxos/log";
|
|
277
318
|
import { schema } from "@dxos/protocols";
|
|
278
319
|
import { ComplexMap } from "@dxos/util";
|
|
279
320
|
var SwarmMessenger = class {
|
|
280
321
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
281
|
-
this._ctx = new
|
|
322
|
+
this._ctx = new Context2();
|
|
282
323
|
this._offerRecords = new ComplexMap((key) => key.toHex());
|
|
283
324
|
this._sendMessage = sendMessage;
|
|
284
325
|
this._onSignal = onSignal;
|
|
@@ -286,7 +327,7 @@ var SwarmMessenger = class {
|
|
|
286
327
|
this._topic = topic;
|
|
287
328
|
}
|
|
288
329
|
async receiveMessage({ author, recipient, payload }) {
|
|
289
|
-
var _a, _b, _c;
|
|
330
|
+
var _a, _b, _c, _d;
|
|
290
331
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
291
332
|
return;
|
|
292
333
|
}
|
|
@@ -318,11 +359,26 @@ var SwarmMessenger = class {
|
|
|
318
359
|
recipient,
|
|
319
360
|
message
|
|
320
361
|
});
|
|
362
|
+
} else if ((_d = message.data) == null ? void 0 : _d.signalBatch) {
|
|
363
|
+
await this._handleSignal({
|
|
364
|
+
author,
|
|
365
|
+
recipient,
|
|
366
|
+
message
|
|
367
|
+
});
|
|
368
|
+
} else {
|
|
369
|
+
log2.warn("unknown message", {
|
|
370
|
+
message
|
|
371
|
+
}, {
|
|
372
|
+
file: "swarm-messenger.ts",
|
|
373
|
+
line: 79,
|
|
374
|
+
scope: this,
|
|
375
|
+
callSite: (f, a) => f(...a)
|
|
376
|
+
});
|
|
321
377
|
}
|
|
322
378
|
}
|
|
323
379
|
async signal(message) {
|
|
324
|
-
var _a;
|
|
325
|
-
assert2((_a = message.data) == null ? void 0 : _a.signal);
|
|
380
|
+
var _a, _b;
|
|
381
|
+
assert2(((_a = message.data) == null ? void 0 : _a.signal) || ((_b = message.data) == null ? void 0 : _b.signalBatch), "Invalid message");
|
|
326
382
|
await this._sendReliableMessage({
|
|
327
383
|
author: message.author,
|
|
328
384
|
recipient: message.recipient,
|
|
@@ -358,7 +414,7 @@ var SwarmMessenger = class {
|
|
|
358
414
|
msg: networkMessage
|
|
359
415
|
}, {
|
|
360
416
|
file: "swarm-messenger.ts",
|
|
361
|
-
line:
|
|
417
|
+
line: 122,
|
|
362
418
|
scope: this,
|
|
363
419
|
callSite: (f, a) => f(...a)
|
|
364
420
|
});
|
|
@@ -382,7 +438,7 @@ var SwarmMessenger = class {
|
|
|
382
438
|
answer: message.data.answer
|
|
383
439
|
}, {
|
|
384
440
|
file: "swarm-messenger.ts",
|
|
385
|
-
line:
|
|
441
|
+
line: 139,
|
|
386
442
|
scope: this,
|
|
387
443
|
callSite: (f, a) => f(...a)
|
|
388
444
|
});
|
|
@@ -401,27 +457,39 @@ var SwarmMessenger = class {
|
|
|
401
457
|
};
|
|
402
458
|
const answer = await this._onOffer(offerMessage);
|
|
403
459
|
answer.offerMessageId = message.messageId;
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
460
|
+
try {
|
|
461
|
+
await this._sendReliableMessage({
|
|
462
|
+
author: recipient,
|
|
463
|
+
recipient: author,
|
|
464
|
+
message: {
|
|
465
|
+
topic: message.topic,
|
|
466
|
+
sessionId: message.sessionId,
|
|
467
|
+
data: {
|
|
468
|
+
answer
|
|
469
|
+
}
|
|
412
470
|
}
|
|
413
|
-
}
|
|
414
|
-
})
|
|
471
|
+
});
|
|
472
|
+
} catch (err) {
|
|
473
|
+
log2.warn("error sending answer", {
|
|
474
|
+
err
|
|
475
|
+
}, {
|
|
476
|
+
file: "swarm-messenger.ts",
|
|
477
|
+
line: 173,
|
|
478
|
+
scope: this,
|
|
479
|
+
callSite: (f, a) => f(...a)
|
|
480
|
+
});
|
|
481
|
+
}
|
|
415
482
|
}
|
|
416
483
|
async _handleSignal({ author, recipient, message }) {
|
|
417
484
|
assert2(message.messageId);
|
|
418
|
-
assert2(message.data.signal, "
|
|
485
|
+
assert2(message.data.signal || message.data.signalBatch, "Invalid message");
|
|
419
486
|
const signalMessage = {
|
|
420
487
|
author,
|
|
421
488
|
recipient,
|
|
422
489
|
...message,
|
|
423
490
|
data: {
|
|
424
|
-
signal: message.data.signal
|
|
491
|
+
signal: message.data.signal,
|
|
492
|
+
signalBatch: message.data.signalBatch
|
|
425
493
|
}
|
|
426
494
|
};
|
|
427
495
|
await this._onSignal(signalMessage);
|
|
@@ -430,8 +498,8 @@ var SwarmMessenger = class {
|
|
|
430
498
|
|
|
431
499
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
432
500
|
import assert4 from "@dxos/node-std/assert";
|
|
433
|
-
import { Event as Event2, scheduleTask as scheduleTask2, sleep, synchronized as synchronized3 } from "@dxos/async";
|
|
434
|
-
import { Context as
|
|
501
|
+
import { Event as Event2, scheduleTask as scheduleTask2, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
|
|
502
|
+
import { Context as Context4 } from "@dxos/context";
|
|
435
503
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
436
504
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
437
505
|
import { log as log4, logInfo } from "@dxos/log";
|
|
@@ -441,7 +509,7 @@ import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
|
|
|
441
509
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
442
510
|
import assert3 from "@dxos/node-std/assert";
|
|
443
511
|
import { scheduleTask, synchronized as synchronized2 } from "@dxos/async";
|
|
444
|
-
import { Context as
|
|
512
|
+
import { Context as Context3 } from "@dxos/context";
|
|
445
513
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
446
514
|
import { log as log3 } from "@dxos/log";
|
|
447
515
|
var __decorate2 = function(decorators, target, key, desc) {
|
|
@@ -466,7 +534,7 @@ var Peer = class {
|
|
|
466
534
|
this._callbacks = _callbacks;
|
|
467
535
|
this._availableAfter = 0;
|
|
468
536
|
this.availableToConnect = true;
|
|
469
|
-
this._ctx = new
|
|
537
|
+
this._ctx = new Context3();
|
|
470
538
|
this.advertizing = false;
|
|
471
539
|
this.initiating = false;
|
|
472
540
|
}
|
|
@@ -787,7 +855,8 @@ var Swarm = class {
|
|
|
787
855
|
this._transportFactory = _transportFactory;
|
|
788
856
|
this._label = _label;
|
|
789
857
|
this._peers = new ComplexMap2(PublicKey4.hash);
|
|
790
|
-
this._ctx = new
|
|
858
|
+
this._ctx = new Context4();
|
|
859
|
+
this._listeningHandle = void 0;
|
|
791
860
|
this.connectionAdded = new Event2();
|
|
792
861
|
this.disconnected = new Event2();
|
|
793
862
|
this.connected = new Event2();
|
|
@@ -801,7 +870,7 @@ var Swarm = class {
|
|
|
801
870
|
}
|
|
802
871
|
}), {
|
|
803
872
|
file: "swarm.ts",
|
|
804
|
-
line:
|
|
873
|
+
line: 86,
|
|
805
874
|
scope: this,
|
|
806
875
|
callSite: (f, a) => f(...a)
|
|
807
876
|
});
|
|
@@ -809,7 +878,7 @@ var Swarm = class {
|
|
|
809
878
|
peerId: _ownPeerId
|
|
810
879
|
}, {
|
|
811
880
|
file: "swarm.ts",
|
|
812
|
-
line:
|
|
881
|
+
line: 90,
|
|
813
882
|
scope: this,
|
|
814
883
|
callSite: (f, a) => f(...a)
|
|
815
884
|
});
|
|
@@ -820,30 +889,11 @@ var Swarm = class {
|
|
|
820
889
|
onOffer: async (msg) => await this.onOffer(msg),
|
|
821
890
|
topic: this._topic
|
|
822
891
|
});
|
|
823
|
-
this._messenger.listen({
|
|
824
|
-
peerId: this._ownPeerId,
|
|
825
|
-
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
826
|
-
onMessage: async (message) => {
|
|
827
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) => log4("Error while receiving message", {
|
|
828
|
-
err
|
|
829
|
-
}, {
|
|
830
|
-
file: "swarm.ts",
|
|
831
|
-
line: 105,
|
|
832
|
-
scope: this,
|
|
833
|
-
callSite: (f, a) => f(...a)
|
|
834
|
-
}));
|
|
835
|
-
}
|
|
836
|
-
}).catch((error) => log4.catch(error, {}, {
|
|
837
|
-
file: "swarm.ts",
|
|
838
|
-
line: 108,
|
|
839
|
-
scope: this,
|
|
840
|
-
callSite: (f, a) => f(...a)
|
|
841
|
-
}));
|
|
842
892
|
log4.trace("dxos.mesh.swarm.constructor", trace2.end({
|
|
843
893
|
id: this._instanceId
|
|
844
894
|
}), {
|
|
845
895
|
file: "swarm.ts",
|
|
846
|
-
line:
|
|
896
|
+
line: 99,
|
|
847
897
|
scope: this,
|
|
848
898
|
callSite: (f, a) => f(...a)
|
|
849
899
|
});
|
|
@@ -863,20 +913,39 @@ var Swarm = class {
|
|
|
863
913
|
get topic() {
|
|
864
914
|
return this._topic;
|
|
865
915
|
}
|
|
866
|
-
|
|
916
|
+
async open() {
|
|
917
|
+
assert4(!this._listeningHandle);
|
|
918
|
+
this._listeningHandle = await this._messenger.listen({
|
|
919
|
+
peerId: this._ownPeerId,
|
|
920
|
+
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
921
|
+
onMessage: async (message) => {
|
|
922
|
+
await this._swarmMessenger.receiveMessage(message).catch((err) => log4.warn("Error while receiving message", {
|
|
923
|
+
err
|
|
924
|
+
}, {
|
|
925
|
+
file: "swarm.ts",
|
|
926
|
+
line: 133,
|
|
927
|
+
scope: this,
|
|
928
|
+
callSite: (f, a) => f(...a)
|
|
929
|
+
}));
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
}
|
|
867
933
|
async destroy() {
|
|
934
|
+
var _a;
|
|
868
935
|
log4("destroying...", {}, {
|
|
869
936
|
file: "swarm.ts",
|
|
870
|
-
line:
|
|
937
|
+
line: 139,
|
|
871
938
|
scope: this,
|
|
872
939
|
callSite: (f, a) => f(...a)
|
|
873
940
|
});
|
|
941
|
+
await ((_a = this._listeningHandle) == null ? void 0 : _a.unsubscribe());
|
|
942
|
+
this._listeningHandle = void 0;
|
|
874
943
|
await this._ctx.dispose();
|
|
875
944
|
await this._topology.destroy();
|
|
876
945
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
877
946
|
log4("destroyed", {}, {
|
|
878
947
|
file: "swarm.ts",
|
|
879
|
-
line:
|
|
948
|
+
line: 146,
|
|
880
949
|
scope: this,
|
|
881
950
|
callSite: (f, a) => f(...a)
|
|
882
951
|
});
|
|
@@ -891,7 +960,7 @@ var Swarm = class {
|
|
|
891
960
|
topology: getClassName(topology)
|
|
892
961
|
}, {
|
|
893
962
|
file: "swarm.ts",
|
|
894
|
-
line:
|
|
963
|
+
line: 154,
|
|
895
964
|
scope: this,
|
|
896
965
|
callSite: (f, a) => f(...a)
|
|
897
966
|
});
|
|
@@ -906,14 +975,14 @@ var Swarm = class {
|
|
|
906
975
|
swarmEvent
|
|
907
976
|
}, {
|
|
908
977
|
file: "swarm.ts",
|
|
909
|
-
line:
|
|
978
|
+
line: 167,
|
|
910
979
|
scope: this,
|
|
911
980
|
callSite: (f, a) => f(...a)
|
|
912
981
|
});
|
|
913
982
|
if (this._ctx.disposed) {
|
|
914
983
|
log4("swarm event ignored for disposed swarm", {}, {
|
|
915
984
|
file: "swarm.ts",
|
|
916
|
-
line:
|
|
985
|
+
line: 170,
|
|
917
986
|
scope: this,
|
|
918
987
|
callSite: (f, a) => f(...a)
|
|
919
988
|
});
|
|
@@ -925,7 +994,7 @@ var Swarm = class {
|
|
|
925
994
|
peerId
|
|
926
995
|
}, {
|
|
927
996
|
file: "swarm.ts",
|
|
928
|
-
line:
|
|
997
|
+
line: 176,
|
|
929
998
|
scope: this,
|
|
930
999
|
callSite: (f, a) => f(...a)
|
|
931
1000
|
});
|
|
@@ -940,7 +1009,7 @@ var Swarm = class {
|
|
|
940
1009
|
if (((_a = peer1.connection) == null ? void 0 : _a.state) !== ConnectionState.CONNECTED) {
|
|
941
1010
|
void this._destroyPeer(peer1.id).catch((err) => log4.catch(err, {}, {
|
|
942
1011
|
file: "swarm.ts",
|
|
943
|
-
line:
|
|
1012
|
+
line: 187,
|
|
944
1013
|
scope: this,
|
|
945
1014
|
callSite: (f, a) => f(...a)
|
|
946
1015
|
}));
|
|
@@ -955,14 +1024,14 @@ var Swarm = class {
|
|
|
955
1024
|
message
|
|
956
1025
|
}, {
|
|
957
1026
|
file: "swarm.ts",
|
|
958
|
-
line:
|
|
1027
|
+
line: 197,
|
|
959
1028
|
scope: this,
|
|
960
1029
|
callSite: (f, a) => f(...a)
|
|
961
1030
|
});
|
|
962
1031
|
if (this._ctx.disposed) {
|
|
963
1032
|
log4("ignored for disposed swarm", {}, {
|
|
964
1033
|
file: "swarm.ts",
|
|
965
|
-
line:
|
|
1034
|
+
line: 199,
|
|
966
1035
|
scope: this,
|
|
967
1036
|
callSite: (f, a) => f(...a)
|
|
968
1037
|
});
|
|
@@ -976,7 +1045,7 @@ var Swarm = class {
|
|
|
976
1045
|
message
|
|
977
1046
|
}, {
|
|
978
1047
|
file: "swarm.ts",
|
|
979
|
-
line:
|
|
1048
|
+
line: 206,
|
|
980
1049
|
scope: this,
|
|
981
1050
|
callSite: (f, a) => f(...a)
|
|
982
1051
|
});
|
|
@@ -989,7 +1058,7 @@ var Swarm = class {
|
|
|
989
1058
|
message
|
|
990
1059
|
}, {
|
|
991
1060
|
file: "swarm.ts",
|
|
992
|
-
line:
|
|
1061
|
+
line: 210,
|
|
993
1062
|
scope: this,
|
|
994
1063
|
callSite: (f, a) => f(...a)
|
|
995
1064
|
});
|
|
@@ -1008,14 +1077,14 @@ var Swarm = class {
|
|
|
1008
1077
|
message
|
|
1009
1078
|
}, {
|
|
1010
1079
|
file: "swarm.ts",
|
|
1011
|
-
line:
|
|
1080
|
+
line: 222,
|
|
1012
1081
|
scope: this,
|
|
1013
1082
|
callSite: (f, a) => f(...a)
|
|
1014
1083
|
});
|
|
1015
1084
|
if (this._ctx.disposed) {
|
|
1016
1085
|
log4.info("ignored for offline swarm", {}, {
|
|
1017
1086
|
file: "swarm.ts",
|
|
1018
|
-
line:
|
|
1087
|
+
line: 224,
|
|
1019
1088
|
scope: this,
|
|
1020
1089
|
callSite: (f, a) => f(...a)
|
|
1021
1090
|
});
|
|
@@ -1036,7 +1105,7 @@ var Swarm = class {
|
|
|
1036
1105
|
}
|
|
1037
1106
|
// For debug purposes
|
|
1038
1107
|
async goOnline() {
|
|
1039
|
-
this._ctx = new
|
|
1108
|
+
this._ctx = new Context4();
|
|
1040
1109
|
}
|
|
1041
1110
|
_getOrCreatePeer(peerId) {
|
|
1042
1111
|
let peer = this._peers.get(peerId);
|
|
@@ -1096,7 +1165,7 @@ var Swarm = class {
|
|
|
1096
1165
|
} catch (err) {
|
|
1097
1166
|
log4("initiation error", err, {
|
|
1098
1167
|
file: "swarm.ts",
|
|
1099
|
-
line:
|
|
1168
|
+
line: 327,
|
|
1100
1169
|
scope: this,
|
|
1101
1170
|
callSite: (f, a) => f(...a)
|
|
1102
1171
|
});
|
|
@@ -1124,11 +1193,11 @@ var Swarm = class {
|
|
|
1124
1193
|
remoteId
|
|
1125
1194
|
}, {
|
|
1126
1195
|
file: "swarm.ts",
|
|
1127
|
-
line:
|
|
1196
|
+
line: 354,
|
|
1128
1197
|
scope: this,
|
|
1129
1198
|
callSite: (f, a) => f(...a)
|
|
1130
1199
|
});
|
|
1131
|
-
await
|
|
1200
|
+
await sleep2(INITIATION_DELAY);
|
|
1132
1201
|
}
|
|
1133
1202
|
if (ctx.disposed) {
|
|
1134
1203
|
return;
|
|
@@ -1141,7 +1210,7 @@ var Swarm = class {
|
|
|
1141
1210
|
remoteId
|
|
1142
1211
|
}, {
|
|
1143
1212
|
file: "swarm.ts",
|
|
1144
|
-
line:
|
|
1213
|
+
line: 368,
|
|
1145
1214
|
scope: this,
|
|
1146
1215
|
callSite: (f, a) => f(...a)
|
|
1147
1216
|
});
|
|
@@ -1151,7 +1220,7 @@ var Swarm = class {
|
|
|
1151
1220
|
remoteId
|
|
1152
1221
|
}, {
|
|
1153
1222
|
file: "swarm.ts",
|
|
1154
|
-
line:
|
|
1223
|
+
line: 371,
|
|
1155
1224
|
scope: this,
|
|
1156
1225
|
callSite: (f, a) => f(...a)
|
|
1157
1226
|
});
|
|
@@ -1443,16 +1512,17 @@ var NetworkManager = class {
|
|
|
1443
1512
|
});
|
|
1444
1513
|
});
|
|
1445
1514
|
this._swarms.set(topic, swarm);
|
|
1515
|
+
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
1516
|
+
await swarm.open();
|
|
1446
1517
|
this._signalConnection.join({
|
|
1447
1518
|
topic,
|
|
1448
1519
|
peerId
|
|
1449
1520
|
}).catch((error) => log6.catch(error, {}, {
|
|
1450
1521
|
file: "network-manager.ts",
|
|
1451
|
-
line:
|
|
1522
|
+
line: 174,
|
|
1452
1523
|
scope: this,
|
|
1453
1524
|
callSite: (f, a) => f(...a)
|
|
1454
1525
|
}));
|
|
1455
|
-
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
1456
1526
|
this.topicsUpdated.emit();
|
|
1457
1527
|
(_a = this._connectionLog) == null ? void 0 : _a.joinedSwarm(swarm);
|
|
1458
1528
|
log6("joined", {
|
|
@@ -1460,7 +1530,7 @@ var NetworkManager = class {
|
|
|
1460
1530
|
count: this._swarms.size
|
|
1461
1531
|
}, {
|
|
1462
1532
|
file: "network-manager.ts",
|
|
1463
|
-
line:
|
|
1533
|
+
line: 178,
|
|
1464
1534
|
scope: this,
|
|
1465
1535
|
callSite: (f, a) => f(...a)
|
|
1466
1536
|
});
|
|
@@ -1480,7 +1550,7 @@ var NetworkManager = class {
|
|
|
1480
1550
|
topic: PublicKey7.from(topic)
|
|
1481
1551
|
}, {
|
|
1482
1552
|
file: "network-manager.ts",
|
|
1483
|
-
line:
|
|
1553
|
+
line: 194,
|
|
1484
1554
|
scope: this,
|
|
1485
1555
|
callSite: (f, a) => f(...a)
|
|
1486
1556
|
});
|
|
@@ -1501,7 +1571,7 @@ var NetworkManager = class {
|
|
|
1501
1571
|
count: this._swarms.size
|
|
1502
1572
|
}, {
|
|
1503
1573
|
file: "network-manager.ts",
|
|
1504
|
-
line:
|
|
1574
|
+
line: 208,
|
|
1505
1575
|
scope: this,
|
|
1506
1576
|
callSite: (f, a) => f(...a)
|
|
1507
1577
|
});
|
|
@@ -2123,7 +2193,7 @@ var WebRTCTransportService = class {
|
|
|
2123
2193
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
2124
2194
|
import assert12 from "@dxos/node-std/assert";
|
|
2125
2195
|
import { Event as Event8 } from "@dxos/async";
|
|
2126
|
-
import { Context as
|
|
2196
|
+
import { Context as Context5 } from "@dxos/context";
|
|
2127
2197
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
2128
2198
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
2129
2199
|
import { log as log12 } from "@dxos/log";
|
|
@@ -2133,7 +2203,7 @@ var WebRTCTransportProxy = class {
|
|
|
2133
2203
|
constructor(_params) {
|
|
2134
2204
|
this._params = _params;
|
|
2135
2205
|
this._proxyId = PublicKey11.random();
|
|
2136
|
-
this._ctx = new
|
|
2206
|
+
this._ctx = new Context5();
|
|
2137
2207
|
this.closed = new Event8();
|
|
2138
2208
|
this._closed = false;
|
|
2139
2209
|
this.connected = new Event8();
|
|
@@ -2309,4 +2379,4 @@ export {
|
|
|
2309
2379
|
WebRTCTransportProxyFactory,
|
|
2310
2380
|
createTeleportProtocolFactory
|
|
2311
2381
|
};
|
|
2312
|
-
//# sourceMappingURL=chunk-
|
|
2382
|
+
//# sourceMappingURL=chunk-U73XV3EJ.mjs.map
|