@dxos/network-manager 0.8.4-main.9be5663bfe → 0.8.4-main.abd8ff62ef
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-Y2FDDNGM.mjs → chunk-LRGOUKHO.mjs} +252 -1397
- package/dist/lib/browser/chunk-LRGOUKHO.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +25 -169
- package/dist/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +9 -43
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs.map +2 -2
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs +7 -42
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs.map +2 -2
- package/dist/lib/node-esm/{chunk-OU3FYVBA.mjs → chunk-E6G6B72R.mjs} +252 -1397
- package/dist/lib/node-esm/chunk-E6G6B72R.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +25 -169
- package/dist/lib/node-esm/index.mjs.map +2 -2
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +9 -43
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs.map +2 -2
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs +7 -42
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs.map +2 -2
- package/dist/types/src/connection-log.d.ts.map +1 -1
- package/dist/types/src/network-manager.d.ts +1 -2
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/signal/ice.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-limiter.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +0 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +0 -3
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +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/tests/utils.d.ts.map +1 -1
- package/dist/types/src/topology/fully-connected-topology.d.ts.map +1 -1
- package/dist/types/src/topology/mmst-topology.d.ts.map +1 -1
- package/dist/types/src/topology/star-topology.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/tcp/tcp-transport.browser.d.ts.map +1 -1
- package/dist/types/src/transport/tcp/tcp-transport.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts +4 -4
- 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.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.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-stats.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/test-utils.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/utils.d.ts.map +1 -1
- package/dist/types/src/wire-protocol.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -28
- package/src/network-manager.ts +2 -4
- package/src/swarm/connection.ts +3 -12
- package/src/swarm/swarm.ts +1 -7
- package/dist/lib/browser/chunk-Y2FDDNGM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OU3FYVBA.mjs.map +0 -7
|
@@ -5,16 +5,15 @@ import { DeferredTask, Event, Trigger, scheduleTask, scheduleTaskInterval, sleep
|
|
|
5
5
|
import { Context, ContextDisposedError, cancelWithContext } from "@dxos/context";
|
|
6
6
|
import { ErrorStream } from "@dxos/debug";
|
|
7
7
|
import { invariant } from "@dxos/invariant";
|
|
8
|
-
import { PublicKey } from "@dxos/keys";
|
|
9
8
|
import { log, logInfo } from "@dxos/log";
|
|
10
|
-
import { CancelledError, ConnectionResetError, ConnectivityError, ProtocolError, TimeoutError
|
|
9
|
+
import { CancelledError, ConnectionResetError, ConnectivityError, ProtocolError, TimeoutError } from "@dxos/protocols";
|
|
10
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
|
|
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);
|
|
14
14
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
15
15
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
16
16
|
}
|
|
17
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
|
|
18
17
|
var STARTING_SIGNALLING_DELAY = 10;
|
|
19
18
|
var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
|
|
20
19
|
var TRANSPORT_STATS_INTERVAL = 5e3;
|
|
@@ -40,14 +39,8 @@ var Connection = class {
|
|
|
40
39
|
_protocol;
|
|
41
40
|
_transportFactory;
|
|
42
41
|
_callbacks;
|
|
43
|
-
_ctx = new Context(void 0, {
|
|
44
|
-
|
|
45
|
-
L: 100
|
|
46
|
-
});
|
|
47
|
-
connectedTimeoutContext = new Context(void 0, {
|
|
48
|
-
F: __dxlog_file,
|
|
49
|
-
L: 101
|
|
50
|
-
});
|
|
42
|
+
_ctx = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 66 });
|
|
43
|
+
connectedTimeoutContext = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 67 });
|
|
51
44
|
_protocolClosed = new Trigger();
|
|
52
45
|
_transportClosed = new Trigger();
|
|
53
46
|
_state = "CREATED";
|
|
@@ -57,7 +50,6 @@ var Connection = class {
|
|
|
57
50
|
_outgoingSignalBuffer = [];
|
|
58
51
|
stateChanged = new Event();
|
|
59
52
|
errors = new ErrorStream();
|
|
60
|
-
_instanceId = PublicKey.random().toHex();
|
|
61
53
|
transportStats = new Event();
|
|
62
54
|
_signalSendTask = new DeferredTask(this._ctx, async () => {
|
|
63
55
|
await this._flushSignalBuffer(this._ctx);
|
|
@@ -79,12 +71,7 @@ var Connection = class {
|
|
|
79
71
|
localPeer: this.localInfo,
|
|
80
72
|
remotePeer: this.remoteInfo,
|
|
81
73
|
initiator: this.initiator
|
|
82
|
-
}, {
|
|
83
|
-
F: __dxlog_file,
|
|
84
|
-
L: 137,
|
|
85
|
-
S: this,
|
|
86
|
-
C: (f, a) => f(...a)
|
|
87
|
-
});
|
|
74
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 92, S: this });
|
|
88
75
|
}
|
|
89
76
|
get sessionIdString() {
|
|
90
77
|
return this.sessionId.truncate();
|
|
@@ -102,46 +89,21 @@ var Connection = class {
|
|
|
102
89
|
* Create an underlying transport and prepares it for the connection.
|
|
103
90
|
*/
|
|
104
91
|
async openConnection() {
|
|
105
|
-
invariant(this._state === "INITIAL", "Invalid state.", {
|
|
106
|
-
|
|
107
|
-
L: 167,
|
|
108
|
-
S: this,
|
|
109
|
-
A: [
|
|
110
|
-
"this._state === ConnectionState.INITIAL",
|
|
111
|
-
"'Invalid state.'"
|
|
112
|
-
]
|
|
113
|
-
});
|
|
114
|
-
log.trace("dxos.mesh.connection.open-connection", trace.begin({
|
|
115
|
-
id: this._instanceId
|
|
116
|
-
}), {
|
|
117
|
-
F: __dxlog_file,
|
|
118
|
-
L: 168,
|
|
119
|
-
S: this,
|
|
120
|
-
C: (f, a) => f(...a)
|
|
121
|
-
});
|
|
92
|
+
invariant(this._state === "INITIAL", "Invalid state.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 115, S: this, A: ['this._state === "INITIAL"', "'Invalid state.'"] });
|
|
93
|
+
log("opening connection", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 116, S: this });
|
|
122
94
|
log.trace("dxos.mesh.connection.open", {
|
|
123
95
|
sessionId: this.sessionId,
|
|
124
96
|
topic: this.topic,
|
|
125
97
|
localPeerId: this.localInfo,
|
|
126
98
|
remotePeerId: this.remoteInfo,
|
|
127
99
|
initiator: this.initiator
|
|
128
|
-
}, {
|
|
129
|
-
F: __dxlog_file,
|
|
130
|
-
L: 169,
|
|
131
|
-
S: this,
|
|
132
|
-
C: (f, a) => f(...a)
|
|
133
|
-
});
|
|
100
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 117, S: this });
|
|
134
101
|
this._changeState("CONNECTING");
|
|
135
102
|
this._protocol.open(this.sessionId).catch((err) => {
|
|
136
103
|
this.errors.raise(err);
|
|
137
104
|
});
|
|
138
105
|
this._protocol.stream.on("close", () => {
|
|
139
|
-
log("protocol stream closed", void 0, {
|
|
140
|
-
F: __dxlog_file,
|
|
141
|
-
L: 186,
|
|
142
|
-
S: this,
|
|
143
|
-
C: (f, a) => f(...a)
|
|
144
|
-
});
|
|
106
|
+
log("protocol stream closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 131, S: this });
|
|
145
107
|
this._protocolClosed.wake();
|
|
146
108
|
this.close({
|
|
147
109
|
error: new ProtocolError({
|
|
@@ -150,25 +112,12 @@ var Connection = class {
|
|
|
150
112
|
}).catch((err) => this.errors.raise(err));
|
|
151
113
|
});
|
|
152
114
|
scheduleTask(this.connectedTimeoutContext, async () => {
|
|
153
|
-
log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
|
|
154
|
-
F: __dxlog_file,
|
|
155
|
-
L: 196,
|
|
156
|
-
S: this,
|
|
157
|
-
C: (f, a) => f(...a)
|
|
158
|
-
});
|
|
115
|
+
log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 140, S: this });
|
|
159
116
|
await this.abort(new TimeoutError({
|
|
160
117
|
message: `${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`
|
|
161
118
|
})).catch((err) => this.errors.raise(err));
|
|
162
119
|
}, TRANSPORT_CONNECTION_TIMEOUT);
|
|
163
|
-
invariant(!this._transport, void 0, {
|
|
164
|
-
F: __dxlog_file,
|
|
165
|
-
L: 204,
|
|
166
|
-
S: this,
|
|
167
|
-
A: [
|
|
168
|
-
"!this._transport",
|
|
169
|
-
""
|
|
170
|
-
]
|
|
171
|
-
});
|
|
120
|
+
invariant(!this._transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 145, S: this, A: ["!this._transport", ""] });
|
|
172
121
|
this._transport = this._transportFactory.createTransport({
|
|
173
122
|
ownPeerKey: this.localInfo.peerKey,
|
|
174
123
|
remotePeerKey: this.remoteInfo.peerKey,
|
|
@@ -187,41 +136,21 @@ var Connection = class {
|
|
|
187
136
|
this._transport.closed.once(() => {
|
|
188
137
|
this._transport = void 0;
|
|
189
138
|
this._transportClosed.wake();
|
|
190
|
-
log("abort triggered by transport close", void 0, {
|
|
191
|
-
F: __dxlog_file,
|
|
192
|
-
L: 226,
|
|
193
|
-
S: this,
|
|
194
|
-
C: (f, a) => f(...a)
|
|
195
|
-
});
|
|
139
|
+
log("abort triggered by transport close", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 164, S: this });
|
|
196
140
|
this.abort().catch((err) => this.errors.raise(err));
|
|
197
141
|
});
|
|
198
142
|
this._transport.errors.handle(async (err) => {
|
|
199
143
|
log("transport error:", {
|
|
200
144
|
err
|
|
201
|
-
}, {
|
|
202
|
-
F: __dxlog_file,
|
|
203
|
-
L: 231,
|
|
204
|
-
S: this,
|
|
205
|
-
C: (f, a) => f(...a)
|
|
206
|
-
});
|
|
145
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 168, S: this });
|
|
207
146
|
if (!this.closeReason) {
|
|
208
147
|
this.closeReason = err?.message;
|
|
209
148
|
}
|
|
210
149
|
if (err instanceof ConnectionResetError) {
|
|
211
|
-
log.info("aborting due to transport ConnectionResetError", void 0, {
|
|
212
|
-
F: __dxlog_file,
|
|
213
|
-
L: 238,
|
|
214
|
-
S: this,
|
|
215
|
-
C: (f, a) => f(...a)
|
|
216
|
-
});
|
|
150
|
+
log.info("aborting due to transport ConnectionResetError", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 176, S: this });
|
|
217
151
|
this.abort(err).catch((err2) => this.errors.raise(err2));
|
|
218
152
|
} else if (err instanceof ConnectivityError) {
|
|
219
|
-
log.info("aborting due to transport ConnectivityError", void 0, {
|
|
220
|
-
F: __dxlog_file,
|
|
221
|
-
L: 241,
|
|
222
|
-
S: this,
|
|
223
|
-
C: (f, a) => f(...a)
|
|
224
|
-
});
|
|
153
|
+
log.info("aborting due to transport ConnectivityError", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 179, S: this });
|
|
225
154
|
this.abort(err).catch((err2) => this.errors.raise(err2));
|
|
226
155
|
}
|
|
227
156
|
if (this._state !== "CLOSED" && this._state !== "CLOSING") {
|
|
@@ -234,31 +163,14 @@ var Connection = class {
|
|
|
234
163
|
void this._transport.onSignal(signal);
|
|
235
164
|
}
|
|
236
165
|
this._incomingSignalBuffer = [];
|
|
237
|
-
log
|
|
238
|
-
id: this._instanceId
|
|
239
|
-
}), {
|
|
240
|
-
F: __dxlog_file,
|
|
241
|
-
L: 260,
|
|
242
|
-
S: this,
|
|
243
|
-
C: (f, a) => f(...a)
|
|
244
|
-
});
|
|
166
|
+
log("opened connection", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 193, S: this });
|
|
245
167
|
}
|
|
246
168
|
async abort(err) {
|
|
247
169
|
log("abort", {
|
|
248
170
|
err
|
|
249
|
-
}, {
|
|
250
|
-
F: __dxlog_file,
|
|
251
|
-
L: 267,
|
|
252
|
-
S: this,
|
|
253
|
-
C: (f, a) => f(...a)
|
|
254
|
-
});
|
|
171
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 196, S: this });
|
|
255
172
|
if (this._state === "CLOSED" || this._state === "ABORTED") {
|
|
256
|
-
log(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
257
|
-
F: __dxlog_file,
|
|
258
|
-
L: 269,
|
|
259
|
-
S: this,
|
|
260
|
-
C: (f, a) => f(...a)
|
|
261
|
-
});
|
|
173
|
+
log(`abort ignored: already ${this._state}`, this.closeReason, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 200, S: this });
|
|
262
174
|
return;
|
|
263
175
|
}
|
|
264
176
|
await this.connectedTimeoutContext.dispose();
|
|
@@ -270,55 +182,30 @@ var Connection = class {
|
|
|
270
182
|
log("aborting...", {
|
|
271
183
|
peerId: this.localInfo,
|
|
272
184
|
err
|
|
273
|
-
}, {
|
|
274
|
-
F: __dxlog_file,
|
|
275
|
-
L: 281,
|
|
276
|
-
S: this,
|
|
277
|
-
C: (f, a) => f(...a)
|
|
278
|
-
});
|
|
185
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 209, S: this });
|
|
279
186
|
try {
|
|
280
187
|
await this._closeProtocol({
|
|
281
188
|
abort: true
|
|
282
189
|
});
|
|
283
190
|
} catch (err2) {
|
|
284
|
-
log.catch(err2, void 0, {
|
|
285
|
-
F: __dxlog_file,
|
|
286
|
-
L: 287,
|
|
287
|
-
S: this,
|
|
288
|
-
C: (f, a) => f(...a)
|
|
289
|
-
});
|
|
191
|
+
log.catch(err2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 219, S: this });
|
|
290
192
|
}
|
|
291
193
|
try {
|
|
292
194
|
await this._closeTransport();
|
|
293
195
|
} catch (err2) {
|
|
294
|
-
log.catch(err2, void 0, {
|
|
295
|
-
F: __dxlog_file,
|
|
296
|
-
L: 294,
|
|
297
|
-
S: this,
|
|
298
|
-
C: (f, a) => f(...a)
|
|
299
|
-
});
|
|
196
|
+
log.catch(err2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 225, S: this });
|
|
300
197
|
}
|
|
301
198
|
try {
|
|
302
199
|
this._callbacks?.onClosed?.(err);
|
|
303
200
|
} catch (err2) {
|
|
304
|
-
log.catch(err2, void 0, {
|
|
305
|
-
F: __dxlog_file,
|
|
306
|
-
L: 300,
|
|
307
|
-
S: this,
|
|
308
|
-
C: (f, a) => f(...a)
|
|
309
|
-
});
|
|
201
|
+
log.catch(err2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 230, S: this });
|
|
310
202
|
}
|
|
311
203
|
this._changeState("ABORTED");
|
|
312
204
|
}
|
|
313
205
|
async close({ error, reason } = {}) {
|
|
314
206
|
log("close", {
|
|
315
207
|
error
|
|
316
|
-
}, {
|
|
317
|
-
F: __dxlog_file,
|
|
318
|
-
L: 307,
|
|
319
|
-
S: this,
|
|
320
|
-
C: (f, a) => f(...a)
|
|
321
|
-
});
|
|
208
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 235, S: this });
|
|
322
209
|
if (!this.closeReason) {
|
|
323
210
|
this.closeReason = reason ?? error?.message;
|
|
324
211
|
} else {
|
|
@@ -328,12 +215,7 @@ var Connection = class {
|
|
|
328
215
|
log("close ignored: already in progress", {
|
|
329
216
|
state: this._state,
|
|
330
217
|
error
|
|
331
|
-
}, {
|
|
332
|
-
F: __dxlog_file,
|
|
333
|
-
L: 318,
|
|
334
|
-
S: this,
|
|
335
|
-
C: (f, a) => f(...a)
|
|
336
|
-
});
|
|
218
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 244, S: this });
|
|
337
219
|
return;
|
|
338
220
|
}
|
|
339
221
|
const lastState = this._state;
|
|
@@ -342,92 +224,47 @@ var Connection = class {
|
|
|
342
224
|
await this._ctx.dispose();
|
|
343
225
|
let abortProtocol = false;
|
|
344
226
|
if (lastState !== "CONNECTED" || error != null) {
|
|
345
|
-
log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
346
|
-
F: __dxlog_file,
|
|
347
|
-
L: 329,
|
|
348
|
-
S: this,
|
|
349
|
-
C: (f, a) => f(...a)
|
|
350
|
-
});
|
|
227
|
+
log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 256, S: this });
|
|
351
228
|
abortProtocol = true;
|
|
352
229
|
}
|
|
353
230
|
log("closing...", {
|
|
354
231
|
peerId: this.localInfo,
|
|
355
232
|
abortProtocol,
|
|
356
233
|
error
|
|
357
|
-
}, {
|
|
358
|
-
F: __dxlog_file,
|
|
359
|
-
L: 333,
|
|
360
|
-
S: this,
|
|
361
|
-
C: (f, a) => f(...a)
|
|
362
|
-
});
|
|
234
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 259, S: this });
|
|
363
235
|
try {
|
|
364
236
|
await this._closeProtocol({
|
|
365
237
|
abort: abortProtocol
|
|
366
238
|
});
|
|
367
239
|
} catch (err) {
|
|
368
|
-
log.catch(err, void 0, {
|
|
369
|
-
F: __dxlog_file,
|
|
370
|
-
L: 338,
|
|
371
|
-
S: this,
|
|
372
|
-
C: (f, a) => f(...a)
|
|
373
|
-
});
|
|
240
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 269, S: this });
|
|
374
241
|
}
|
|
375
242
|
try {
|
|
376
243
|
await this._closeTransport();
|
|
377
244
|
} catch (err) {
|
|
378
|
-
log.catch(err, void 0, {
|
|
379
|
-
F: __dxlog_file,
|
|
380
|
-
L: 344,
|
|
381
|
-
S: this,
|
|
382
|
-
C: (f, a) => f(...a)
|
|
383
|
-
});
|
|
245
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 275, S: this });
|
|
384
246
|
}
|
|
385
247
|
log("closed", {
|
|
386
248
|
peerId: this.localInfo
|
|
387
|
-
}, {
|
|
388
|
-
F: __dxlog_file,
|
|
389
|
-
L: 347,
|
|
390
|
-
S: this,
|
|
391
|
-
C: (f, a) => f(...a)
|
|
392
|
-
});
|
|
249
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 277, S: this });
|
|
393
250
|
this._changeState("CLOSED");
|
|
394
251
|
this._callbacks?.onClosed?.(error);
|
|
395
252
|
}
|
|
396
253
|
async _closeProtocol(options) {
|
|
397
|
-
log("closing protocol", options, {
|
|
398
|
-
F: __dxlog_file,
|
|
399
|
-
L: 353,
|
|
400
|
-
S: this,
|
|
401
|
-
C: (f, a) => f(...a)
|
|
402
|
-
});
|
|
254
|
+
log("closing protocol", options, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 284, S: this });
|
|
403
255
|
await Promise.race([
|
|
404
256
|
options?.abort ? this._protocol.abort() : this._protocol.close(),
|
|
405
257
|
this._protocolClosed.wait()
|
|
406
258
|
]);
|
|
407
|
-
log("protocol closed", options, {
|
|
408
|
-
F: __dxlog_file,
|
|
409
|
-
L: 355,
|
|
410
|
-
S: this,
|
|
411
|
-
C: (f, a) => f(...a)
|
|
412
|
-
});
|
|
259
|
+
log("protocol closed", options, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 289, S: this });
|
|
413
260
|
}
|
|
414
261
|
async _closeTransport() {
|
|
415
|
-
log("closing transport", void 0, {
|
|
416
|
-
F: __dxlog_file,
|
|
417
|
-
L: 359,
|
|
418
|
-
S: this,
|
|
419
|
-
C: (f, a) => f(...a)
|
|
420
|
-
});
|
|
262
|
+
log("closing transport", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 292, S: this });
|
|
421
263
|
await Promise.race([
|
|
422
264
|
this._transport?.close(),
|
|
423
265
|
this._transportClosed.wait()
|
|
424
266
|
]);
|
|
425
|
-
log("transport closed", void 0, {
|
|
426
|
-
F: __dxlog_file,
|
|
427
|
-
L: 361,
|
|
428
|
-
S: this,
|
|
429
|
-
C: (f, a) => f(...a)
|
|
430
|
-
});
|
|
267
|
+
log("transport closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 297, S: this });
|
|
431
268
|
}
|
|
432
269
|
_sendSignal(signal) {
|
|
433
270
|
this._outgoingSignalBuffer.push(signal);
|
|
@@ -463,12 +300,7 @@ var Connection = class {
|
|
|
463
300
|
}
|
|
464
301
|
log.info("signal message failed to deliver", {
|
|
465
302
|
err
|
|
466
|
-
}, {
|
|
467
|
-
F: __dxlog_file,
|
|
468
|
-
L: 401,
|
|
469
|
-
S: this,
|
|
470
|
-
C: (f, a) => f(...a)
|
|
471
|
-
});
|
|
303
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 333, S: this });
|
|
472
304
|
await this.close({
|
|
473
305
|
error: new ConnectivityError({
|
|
474
306
|
message: "signal message failed to deliver",
|
|
@@ -481,51 +313,14 @@ var Connection = class {
|
|
|
481
313
|
* Receive a signal from the remote peer.
|
|
482
314
|
*/
|
|
483
315
|
async signal(_ctx, msg) {
|
|
484
|
-
invariant(msg.sessionId, void 0, {
|
|
485
|
-
F: __dxlog_file,
|
|
486
|
-
L: 410,
|
|
487
|
-
S: this,
|
|
488
|
-
A: [
|
|
489
|
-
"msg.sessionId",
|
|
490
|
-
""
|
|
491
|
-
]
|
|
492
|
-
});
|
|
316
|
+
invariant(msg.sessionId, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 347, S: this, A: ["msg.sessionId", ""] });
|
|
493
317
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
494
|
-
log("dropping signal for incorrect session id", void 0, {
|
|
495
|
-
F: __dxlog_file,
|
|
496
|
-
L: 412,
|
|
497
|
-
S: this,
|
|
498
|
-
C: (f, a) => f(...a)
|
|
499
|
-
});
|
|
318
|
+
log("dropping signal for incorrect session id", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 349, S: this });
|
|
500
319
|
return;
|
|
501
320
|
}
|
|
502
|
-
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
S: this,
|
|
506
|
-
A: [
|
|
507
|
-
"msg.data.signal || msg.data.signalBatch",
|
|
508
|
-
""
|
|
509
|
-
]
|
|
510
|
-
});
|
|
511
|
-
invariant(msg.author.peerKey === this.remoteInfo.peerKey, void 0, {
|
|
512
|
-
F: __dxlog_file,
|
|
513
|
-
L: 416,
|
|
514
|
-
S: this,
|
|
515
|
-
A: [
|
|
516
|
-
"msg.author.peerKey === this.remoteInfo.peerKey",
|
|
517
|
-
""
|
|
518
|
-
]
|
|
519
|
-
});
|
|
520
|
-
invariant(msg.recipient.peerKey === this.localInfo.peerKey, void 0, {
|
|
521
|
-
F: __dxlog_file,
|
|
522
|
-
L: 417,
|
|
523
|
-
S: this,
|
|
524
|
-
A: [
|
|
525
|
-
"msg.recipient.peerKey === this.localInfo.peerKey",
|
|
526
|
-
""
|
|
527
|
-
]
|
|
528
|
-
});
|
|
321
|
+
invariant(msg.data.signal || msg.data.signalBatch, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 352, S: this, A: ["msg.data.signal || msg.data.signalBatch", ""] });
|
|
322
|
+
invariant(msg.author.peerKey === this.remoteInfo.peerKey, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 353, S: this, A: ["msg.author.peerKey === this.remoteInfo.peerKey", ""] });
|
|
323
|
+
invariant(msg.recipient.peerKey === this.localInfo.peerKey, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 354, S: this, A: ["msg.recipient.peerKey === this.localInfo.peerKey", ""] });
|
|
529
324
|
const signals = msg.data.signalBatch ? msg.data.signalBatch.signals ?? [] : [
|
|
530
325
|
msg.data.signal
|
|
531
326
|
];
|
|
@@ -541,33 +336,15 @@ var Connection = class {
|
|
|
541
336
|
peerId: this.localInfo,
|
|
542
337
|
remoteId: this.remoteInfo,
|
|
543
338
|
msg: msg.data
|
|
544
|
-
}, {
|
|
545
|
-
F: __dxlog_file,
|
|
546
|
-
L: 426,
|
|
547
|
-
S: this,
|
|
548
|
-
C: (f, a) => f(...a)
|
|
549
|
-
});
|
|
339
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 366, S: this });
|
|
550
340
|
this._incomingSignalBuffer.push(signal);
|
|
551
341
|
} else {
|
|
552
|
-
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
553
|
-
F: __dxlog_file,
|
|
554
|
-
L: 429,
|
|
555
|
-
S: this,
|
|
556
|
-
A: [
|
|
557
|
-
"this._transport",
|
|
558
|
-
"'Connection not ready to accept signals.'"
|
|
559
|
-
]
|
|
560
|
-
});
|
|
342
|
+
invariant(this._transport, "Connection not ready to accept signals.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 373, S: this, A: ["this._transport", "'Connection not ready to accept signals.'"] });
|
|
561
343
|
log("received signal", {
|
|
562
344
|
peerId: this.localInfo,
|
|
563
345
|
remoteId: this.remoteInfo,
|
|
564
346
|
msg: msg.data
|
|
565
|
-
}, {
|
|
566
|
-
F: __dxlog_file,
|
|
567
|
-
L: 430,
|
|
568
|
-
S: this,
|
|
569
|
-
C: (f, a) => f(...a)
|
|
570
|
-
});
|
|
347
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 374, S: this });
|
|
571
348
|
await this._transport.onSignal(signal);
|
|
572
349
|
}
|
|
573
350
|
}
|
|
@@ -580,21 +357,8 @@ var Connection = class {
|
|
|
580
357
|
from: this._state,
|
|
581
358
|
to: state,
|
|
582
359
|
peerId: this.localInfo
|
|
583
|
-
}, {
|
|
584
|
-
|
|
585
|
-
L: 441,
|
|
586
|
-
S: this,
|
|
587
|
-
C: (f, a) => f(...a)
|
|
588
|
-
});
|
|
589
|
-
invariant(state !== this._state, "Already in this state.", {
|
|
590
|
-
F: __dxlog_file,
|
|
591
|
-
L: 442,
|
|
592
|
-
S: this,
|
|
593
|
-
A: [
|
|
594
|
-
"state !== this._state",
|
|
595
|
-
"'Already in this state.'"
|
|
596
|
-
]
|
|
597
|
-
});
|
|
360
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 387, S: this });
|
|
361
|
+
invariant(state !== this._state, "Already in this state.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 392, S: this, A: ["state !== this._state", "'Already in this state.'"] });
|
|
598
362
|
this._state = state;
|
|
599
363
|
this.stateChanged.emit(state);
|
|
600
364
|
}
|
|
@@ -617,7 +381,7 @@ _ts_decorate([
|
|
|
617
381
|
|
|
618
382
|
// src/signal/swarm-messenger.ts
|
|
619
383
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
620
|
-
import { PublicKey
|
|
384
|
+
import { PublicKey } from "@dxos/keys";
|
|
621
385
|
import { log as log2 } from "@dxos/log";
|
|
622
386
|
import { TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
623
387
|
import { schema } from "@dxos/protocols/proto";
|
|
@@ -648,12 +412,7 @@ var SwarmMessenger = class {
|
|
|
648
412
|
from: author,
|
|
649
413
|
to: recipient,
|
|
650
414
|
msg: message
|
|
651
|
-
}, {
|
|
652
|
-
F: __dxlog_file2,
|
|
653
|
-
L: 72,
|
|
654
|
-
S: this,
|
|
655
|
-
C: (f, a) => f(...a)
|
|
656
|
-
});
|
|
415
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 35, S: this });
|
|
657
416
|
if (message.data?.offer) {
|
|
658
417
|
await this._handleOffer(ctx, {
|
|
659
418
|
author,
|
|
@@ -677,24 +436,11 @@ var SwarmMessenger = class {
|
|
|
677
436
|
} else {
|
|
678
437
|
log2.warn("unknown message", {
|
|
679
438
|
message
|
|
680
|
-
}, {
|
|
681
|
-
F: __dxlog_file2,
|
|
682
|
-
L: 83,
|
|
683
|
-
S: this,
|
|
684
|
-
C: (f, a) => f(...a)
|
|
685
|
-
});
|
|
439
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 61, S: this });
|
|
686
440
|
}
|
|
687
441
|
}
|
|
688
442
|
async signal(ctx, message) {
|
|
689
|
-
invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
690
|
-
F: __dxlog_file2,
|
|
691
|
-
L: 88,
|
|
692
|
-
S: this,
|
|
693
|
-
A: [
|
|
694
|
-
"message.data?.signal || message.data?.signalBatch",
|
|
695
|
-
"'Invalid message'"
|
|
696
|
-
]
|
|
697
|
-
});
|
|
443
|
+
invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 67, S: this, A: ["message.data?.signal || message.data?.signalBatch", "'Invalid message'"] });
|
|
698
444
|
await this._sendReliableMessage(ctx, {
|
|
699
445
|
author: message.author,
|
|
700
446
|
recipient: message.recipient,
|
|
@@ -704,7 +450,7 @@ var SwarmMessenger = class {
|
|
|
704
450
|
async offer(ctx, message) {
|
|
705
451
|
const networkMessage = {
|
|
706
452
|
...message,
|
|
707
|
-
messageId:
|
|
453
|
+
messageId: PublicKey.random()
|
|
708
454
|
};
|
|
709
455
|
return new Promise((resolve, reject) => {
|
|
710
456
|
this._offerRecords.set(networkMessage.messageId, {
|
|
@@ -721,18 +467,13 @@ var SwarmMessenger = class {
|
|
|
721
467
|
const networkMessage = {
|
|
722
468
|
...message,
|
|
723
469
|
// Setting unique message_id if it not specified yet.
|
|
724
|
-
messageId: message.messageId ??
|
|
470
|
+
messageId: message.messageId ?? PublicKey.random()
|
|
725
471
|
};
|
|
726
472
|
log2("sending", {
|
|
727
473
|
from: author,
|
|
728
474
|
to: recipient,
|
|
729
475
|
msg: networkMessage
|
|
730
|
-
}, {
|
|
731
|
-
F: __dxlog_file2,
|
|
732
|
-
L: 129,
|
|
733
|
-
S: this,
|
|
734
|
-
C: (f, a) => f(...a)
|
|
735
|
-
});
|
|
476
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 96, S: this });
|
|
736
477
|
await this._sendMessage(ctx, {
|
|
737
478
|
author,
|
|
738
479
|
recipient,
|
|
@@ -743,48 +484,19 @@ var SwarmMessenger = class {
|
|
|
743
484
|
});
|
|
744
485
|
}
|
|
745
486
|
async _resolveAnswers(message) {
|
|
746
|
-
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
747
|
-
F: __dxlog_file2,
|
|
748
|
-
L: 141,
|
|
749
|
-
S: this,
|
|
750
|
-
A: [
|
|
751
|
-
"message.data?.answer?.offerMessageId",
|
|
752
|
-
"'No offerMessageId'"
|
|
753
|
-
]
|
|
754
|
-
});
|
|
487
|
+
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 111, S: this, A: ["message.data?.answer?.offerMessageId", "'No offerMessageId'"] });
|
|
755
488
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
756
489
|
if (offerRecord) {
|
|
757
490
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
758
|
-
invariant2(message.data?.answer, "No answer", {
|
|
759
|
-
F: __dxlog_file2,
|
|
760
|
-
L: 145,
|
|
761
|
-
S: this,
|
|
762
|
-
A: [
|
|
763
|
-
"message.data?.answer",
|
|
764
|
-
"'No answer'"
|
|
765
|
-
]
|
|
766
|
-
});
|
|
491
|
+
invariant2(message.data?.answer, "No answer", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 115, S: this, A: ["message.data?.answer", "'No answer'"] });
|
|
767
492
|
log2("resolving", {
|
|
768
493
|
answer: message.data.answer
|
|
769
|
-
}, {
|
|
770
|
-
F: __dxlog_file2,
|
|
771
|
-
L: 146,
|
|
772
|
-
S: this,
|
|
773
|
-
C: (f, a) => f(...a)
|
|
774
|
-
});
|
|
494
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 116, S: this });
|
|
775
495
|
offerRecord.resolve(message.data.answer);
|
|
776
496
|
}
|
|
777
497
|
}
|
|
778
498
|
async _handleOffer(ctx, { author, recipient, message }) {
|
|
779
|
-
invariant2(message.data.offer, "No offer", {
|
|
780
|
-
F: __dxlog_file2,
|
|
781
|
-
L: 163,
|
|
782
|
-
S: this,
|
|
783
|
-
A: [
|
|
784
|
-
"message.data.offer",
|
|
785
|
-
"'No offer'"
|
|
786
|
-
]
|
|
787
|
-
});
|
|
499
|
+
invariant2(message.data.offer, "No offer", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 123, S: this, A: ["message.data.offer", "'No offer'"] });
|
|
788
500
|
const offerMessage = {
|
|
789
501
|
author,
|
|
790
502
|
recipient,
|
|
@@ -811,43 +523,17 @@ var SwarmMessenger = class {
|
|
|
811
523
|
if (err instanceof TimeoutError2) {
|
|
812
524
|
log2.info("timeout sending answer to offer", {
|
|
813
525
|
err
|
|
814
|
-
}, {
|
|
815
|
-
F: __dxlog_file2,
|
|
816
|
-
L: 184,
|
|
817
|
-
S: this,
|
|
818
|
-
C: (f, a) => f(...a)
|
|
819
|
-
});
|
|
526
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 148, S: this });
|
|
820
527
|
} else {
|
|
821
528
|
log2.info("error sending answer to offer", {
|
|
822
529
|
err
|
|
823
|
-
}, {
|
|
824
|
-
F: __dxlog_file2,
|
|
825
|
-
L: 186,
|
|
826
|
-
S: this,
|
|
827
|
-
C: (f, a) => f(...a)
|
|
828
|
-
});
|
|
530
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 152, S: this });
|
|
829
531
|
}
|
|
830
532
|
}
|
|
831
533
|
}
|
|
832
534
|
async _handleSignal(ctx, { author, recipient, message }) {
|
|
833
|
-
invariant2(message.messageId, void 0, {
|
|
834
|
-
|
|
835
|
-
L: 203,
|
|
836
|
-
S: this,
|
|
837
|
-
A: [
|
|
838
|
-
"message.messageId",
|
|
839
|
-
""
|
|
840
|
-
]
|
|
841
|
-
});
|
|
842
|
-
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
843
|
-
F: __dxlog_file2,
|
|
844
|
-
L: 204,
|
|
845
|
-
S: this,
|
|
846
|
-
A: [
|
|
847
|
-
"message.data.signal || message.data.signalBatch",
|
|
848
|
-
"'Invalid message'"
|
|
849
|
-
]
|
|
850
|
-
});
|
|
535
|
+
invariant2(message.messageId, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 159, S: this, A: ["message.messageId", ""] });
|
|
536
|
+
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 160, S: this, A: ["message.data.signal || message.data.signalBatch", "'Invalid message'"] });
|
|
851
537
|
const signalMessage = {
|
|
852
538
|
author,
|
|
853
539
|
recipient,
|
|
@@ -866,26 +552,25 @@ import { Event as Event3, scheduleTask as scheduleTask3, sleep as sleep2, synchr
|
|
|
866
552
|
import { Context as Context3 } from "@dxos/context";
|
|
867
553
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
868
554
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
869
|
-
import { PublicKey as
|
|
555
|
+
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
870
556
|
import { log as log4, logInfo as logInfo2 } from "@dxos/log";
|
|
871
557
|
import { PeerInfoHash } from "@dxos/messaging";
|
|
872
|
-
import { trace as trace2 } from "@dxos/protocols";
|
|
873
558
|
import { ComplexMap as ComplexMap2, isNonNullable } from "@dxos/util";
|
|
874
559
|
|
|
875
560
|
// src/swarm/peer.ts
|
|
876
561
|
import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
|
|
877
562
|
import { Context as Context2 } from "@dxos/context";
|
|
878
563
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
879
|
-
import { PublicKey as
|
|
564
|
+
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
880
565
|
import { log as log3 } from "@dxos/log";
|
|
881
566
|
import { CancelledError as CancelledError2, SystemError } from "@dxos/protocols";
|
|
567
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
882
568
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
883
569
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
884
570
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
885
571
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
886
572
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
887
573
|
}
|
|
888
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
889
574
|
var ConnectionDisplacedError = class extends SystemError {
|
|
890
575
|
constructor() {
|
|
891
576
|
super({
|
|
@@ -909,10 +594,7 @@ var Peer = class {
|
|
|
909
594
|
_availableAfter = 0;
|
|
910
595
|
availableToConnect = true;
|
|
911
596
|
_lastConnectionTime;
|
|
912
|
-
_ctx = new Context2(void 0, {
|
|
913
|
-
F: __dxlog_file3,
|
|
914
|
-
L: 80
|
|
915
|
-
});
|
|
597
|
+
_ctx = new Context2(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 44 });
|
|
916
598
|
_connectionCtx;
|
|
917
599
|
connection;
|
|
918
600
|
/**
|
|
@@ -941,12 +623,7 @@ var Peer = class {
|
|
|
941
623
|
ConnectionState.INITIAL,
|
|
942
624
|
ConnectionState.CONNECTING
|
|
943
625
|
].includes(this.connection.state)) {
|
|
944
|
-
log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
945
|
-
F: __dxlog_file3,
|
|
946
|
-
L: 115,
|
|
947
|
-
S: this,
|
|
948
|
-
C: (f, a) => f(...a)
|
|
949
|
-
});
|
|
626
|
+
log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 71, S: this });
|
|
950
627
|
return {
|
|
951
628
|
accept: false
|
|
952
629
|
};
|
|
@@ -958,12 +635,7 @@ var Peer = class {
|
|
|
958
635
|
topic: this.topic,
|
|
959
636
|
remotePeer: this.remoteInfo,
|
|
960
637
|
sessionId: this.connection?.sessionId
|
|
961
|
-
}, {
|
|
962
|
-
F: __dxlog_file3,
|
|
963
|
-
L: 124,
|
|
964
|
-
S: this,
|
|
965
|
-
C: (f, a) => f(...a)
|
|
966
|
-
});
|
|
638
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 82, S: this });
|
|
967
639
|
if (this.connection) {
|
|
968
640
|
await this.closeConnection(new ConnectionDisplacedError());
|
|
969
641
|
}
|
|
@@ -975,15 +647,7 @@ var Peer = class {
|
|
|
975
647
|
}
|
|
976
648
|
if (await this._callbacks.onOffer(remote)) {
|
|
977
649
|
if (!this.connection) {
|
|
978
|
-
invariant3(message.sessionId, void 0, {
|
|
979
|
-
F: __dxlog_file3,
|
|
980
|
-
L: 144,
|
|
981
|
-
S: this,
|
|
982
|
-
A: [
|
|
983
|
-
"message.sessionId",
|
|
984
|
-
""
|
|
985
|
-
]
|
|
986
|
-
});
|
|
650
|
+
invariant3(message.sessionId, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 102, S: this, A: ["message.sessionId", ""] });
|
|
987
651
|
const connection = this._createConnection(false, message.sessionId);
|
|
988
652
|
try {
|
|
989
653
|
await this._connectionLimiter.connecting(message.sessionId);
|
|
@@ -996,12 +660,7 @@ var Peer = class {
|
|
|
996
660
|
peerId: this.localInfo,
|
|
997
661
|
remoteId: this.remoteInfo,
|
|
998
662
|
err
|
|
999
|
-
}, {
|
|
1000
|
-
F: __dxlog_file3,
|
|
1001
|
-
L: 154,
|
|
1002
|
-
S: this,
|
|
1003
|
-
C: (f, a) => f(...a)
|
|
1004
|
-
});
|
|
663
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 110, S: this });
|
|
1005
664
|
}
|
|
1006
665
|
await this.closeConnection(err);
|
|
1007
666
|
}
|
|
@@ -1018,36 +677,15 @@ var Peer = class {
|
|
|
1018
677
|
* Initiate a connection to the remote peer.
|
|
1019
678
|
*/
|
|
1020
679
|
async initiateConnection(ctx) {
|
|
1021
|
-
invariant3(!this.initiating, "Initiation in progress.", {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
S: this,
|
|
1025
|
-
A: [
|
|
1026
|
-
"!this.initiating",
|
|
1027
|
-
"'Initiation in progress.'"
|
|
1028
|
-
]
|
|
1029
|
-
});
|
|
1030
|
-
invariant3(!this.connection, "Already connected.", {
|
|
1031
|
-
F: __dxlog_file3,
|
|
1032
|
-
L: 173,
|
|
1033
|
-
S: this,
|
|
1034
|
-
A: [
|
|
1035
|
-
"!this.connection",
|
|
1036
|
-
"'Already connected.'"
|
|
1037
|
-
]
|
|
1038
|
-
});
|
|
1039
|
-
const sessionId = PublicKey3.random();
|
|
680
|
+
invariant3(!this.initiating, "Initiation in progress.", { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 132, S: this, A: ["!this.initiating", "'Initiation in progress.'"] });
|
|
681
|
+
invariant3(!this.connection, "Already connected.", { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 133, S: this, A: ["!this.connection", "'Already connected.'"] });
|
|
682
|
+
const sessionId = PublicKey2.random();
|
|
1040
683
|
log3("initiating...", {
|
|
1041
684
|
local: this.localInfo,
|
|
1042
685
|
topic: this.topic,
|
|
1043
686
|
remote: this.remoteInfo,
|
|
1044
687
|
sessionId
|
|
1045
|
-
}, {
|
|
1046
|
-
F: __dxlog_file3,
|
|
1047
|
-
L: 175,
|
|
1048
|
-
S: this,
|
|
1049
|
-
C: (f, a) => f(...a)
|
|
1050
|
-
});
|
|
688
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 135, S: this });
|
|
1051
689
|
const connection = this._createConnection(true, sessionId);
|
|
1052
690
|
this.initiating = true;
|
|
1053
691
|
let answer;
|
|
@@ -1068,19 +706,9 @@ var Peer = class {
|
|
|
1068
706
|
topic: this.topic,
|
|
1069
707
|
local: this.localInfo,
|
|
1070
708
|
remote: this.remoteInfo
|
|
1071
|
-
}, {
|
|
1072
|
-
F: __dxlog_file3,
|
|
1073
|
-
L: 192,
|
|
1074
|
-
S: this,
|
|
1075
|
-
C: (f, a) => f(...a)
|
|
1076
|
-
});
|
|
709
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 156, S: this });
|
|
1077
710
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1078
|
-
log3("ignoring response", void 0, {
|
|
1079
|
-
F: __dxlog_file3,
|
|
1080
|
-
L: 194,
|
|
1081
|
-
S: this,
|
|
1082
|
-
C: (f, a) => f(...a)
|
|
1083
|
-
});
|
|
711
|
+
log3("ignoring response", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 163, S: this });
|
|
1084
712
|
return;
|
|
1085
713
|
}
|
|
1086
714
|
} catch (err) {
|
|
@@ -1089,12 +717,7 @@ var Peer = class {
|
|
|
1089
717
|
topic: this.topic,
|
|
1090
718
|
local: this.localInfo,
|
|
1091
719
|
remote: this.remoteInfo
|
|
1092
|
-
}, {
|
|
1093
|
-
F: __dxlog_file3,
|
|
1094
|
-
L: 198,
|
|
1095
|
-
S: this,
|
|
1096
|
-
C: (f, a) => f(...a)
|
|
1097
|
-
});
|
|
720
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 167, S: this });
|
|
1098
721
|
await connection.abort(err);
|
|
1099
722
|
throw err;
|
|
1100
723
|
} finally {
|
|
@@ -1111,24 +734,14 @@ var Peer = class {
|
|
|
1111
734
|
topic: this.topic,
|
|
1112
735
|
local: this.localInfo,
|
|
1113
736
|
remote: this.remoteInfo
|
|
1114
|
-
}, {
|
|
1115
|
-
F: __dxlog_file3,
|
|
1116
|
-
L: 211,
|
|
1117
|
-
S: this,
|
|
1118
|
-
C: (f, a) => f(...a)
|
|
1119
|
-
});
|
|
737
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 184, S: this });
|
|
1120
738
|
await connection.abort(err);
|
|
1121
739
|
throw err;
|
|
1122
740
|
} finally {
|
|
1123
741
|
this.initiating = false;
|
|
1124
742
|
}
|
|
1125
743
|
try {
|
|
1126
|
-
log3("opening connection as initiator", void 0, {
|
|
1127
|
-
F: __dxlog_file3,
|
|
1128
|
-
L: 224,
|
|
1129
|
-
S: this,
|
|
1130
|
-
C: (f, a) => f(...a)
|
|
1131
|
-
});
|
|
744
|
+
log3("opening connection as initiator", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 196, S: this });
|
|
1132
745
|
await connection.openConnection();
|
|
1133
746
|
this._callbacks.onAccepted();
|
|
1134
747
|
} catch (err) {
|
|
@@ -1137,20 +750,10 @@ var Peer = class {
|
|
|
1137
750
|
topic: this.topic,
|
|
1138
751
|
local: this.localInfo,
|
|
1139
752
|
remote: this.remoteInfo
|
|
1140
|
-
}, {
|
|
1141
|
-
F: __dxlog_file3,
|
|
1142
|
-
L: 228,
|
|
1143
|
-
S: this,
|
|
1144
|
-
C: (f, a) => f(...a)
|
|
1145
|
-
});
|
|
753
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 200, S: this });
|
|
1146
754
|
log3.warn("closing connection due to unhandled error on openConnection", {
|
|
1147
755
|
err
|
|
1148
|
-
}, {
|
|
1149
|
-
F: __dxlog_file3,
|
|
1150
|
-
L: 235,
|
|
1151
|
-
S: this,
|
|
1152
|
-
C: (f, a) => f(...a)
|
|
1153
|
-
});
|
|
756
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 207, S: this });
|
|
1154
757
|
await this.closeConnection(err);
|
|
1155
758
|
throw err;
|
|
1156
759
|
} finally {
|
|
@@ -1168,21 +771,8 @@ var Peer = class {
|
|
|
1168
771
|
remoteId: this.remoteInfo,
|
|
1169
772
|
initiator,
|
|
1170
773
|
sessionId
|
|
1171
|
-
}, {
|
|
1172
|
-
|
|
1173
|
-
L: 249,
|
|
1174
|
-
S: this,
|
|
1175
|
-
C: (f, a) => f(...a)
|
|
1176
|
-
});
|
|
1177
|
-
invariant3(!this.connection, "Already connected.", {
|
|
1178
|
-
F: __dxlog_file3,
|
|
1179
|
-
L: 256,
|
|
1180
|
-
S: this,
|
|
1181
|
-
A: [
|
|
1182
|
-
"!this.connection",
|
|
1183
|
-
"'Already connected.'"
|
|
1184
|
-
]
|
|
1185
|
-
});
|
|
774
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 221, S: this });
|
|
775
|
+
invariant3(!this.connection, "Already connected.", { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 228, S: this, A: ["!this.connection", "'Already connected.'"] });
|
|
1186
776
|
const connection = new Connection(
|
|
1187
777
|
this.topic,
|
|
1188
778
|
this.localInfo,
|
|
@@ -1193,8 +783,8 @@ var Peer = class {
|
|
|
1193
783
|
// TODO(dmaretskyi): Init only when connection is established.
|
|
1194
784
|
this._protocolProvider({
|
|
1195
785
|
initiator,
|
|
1196
|
-
localPeerId:
|
|
1197
|
-
remotePeerId:
|
|
786
|
+
localPeerId: PublicKey2.from(this.localInfo.peerKey),
|
|
787
|
+
remotePeerId: PublicKey2.from(this.remoteInfo.peerKey),
|
|
1198
788
|
topic: this.topic
|
|
1199
789
|
}),
|
|
1200
790
|
this._transportFactory,
|
|
@@ -1210,12 +800,7 @@ var Peer = class {
|
|
|
1210
800
|
remotePeerId: this.remoteInfo,
|
|
1211
801
|
sessionId,
|
|
1212
802
|
initiator
|
|
1213
|
-
}, {
|
|
1214
|
-
F: __dxlog_file3,
|
|
1215
|
-
L: 280,
|
|
1216
|
-
S: this,
|
|
1217
|
-
C: (f, a) => f(...a)
|
|
1218
|
-
});
|
|
803
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 241, S: this });
|
|
1219
804
|
},
|
|
1220
805
|
onClosed: (err) => {
|
|
1221
806
|
const logMeta = {
|
|
@@ -1224,34 +809,16 @@ var Peer = class {
|
|
|
1224
809
|
remoteId: this.remoteInfo,
|
|
1225
810
|
initiator
|
|
1226
811
|
};
|
|
1227
|
-
log3("connection closed", logMeta, {
|
|
1228
|
-
F: __dxlog_file3,
|
|
1229
|
-
L: 290,
|
|
1230
|
-
S: this,
|
|
1231
|
-
C: (f, a) => f(...a)
|
|
1232
|
-
});
|
|
812
|
+
log3("connection closed", logMeta, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 256, S: this });
|
|
1233
813
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1234
|
-
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1235
|
-
F: __dxlog_file3,
|
|
1236
|
-
L: 295,
|
|
1237
|
-
S: this,
|
|
1238
|
-
A: [
|
|
1239
|
-
"this.connection === connection",
|
|
1240
|
-
"'Connection mismatch (race condition).'"
|
|
1241
|
-
]
|
|
1242
|
-
});
|
|
814
|
+
invariant3(this.connection === connection, "Connection mismatch (race condition).", { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 259, S: this, A: ["this.connection === connection", "'Connection mismatch (race condition).'"] });
|
|
1243
815
|
log3.trace("dxos.mesh.connection.closed", {
|
|
1244
816
|
topic: this.topic,
|
|
1245
817
|
localPeerId: this.localInfo,
|
|
1246
818
|
remotePeerId: this.remoteInfo,
|
|
1247
819
|
sessionId,
|
|
1248
820
|
initiator
|
|
1249
|
-
}, {
|
|
1250
|
-
F: __dxlog_file3,
|
|
1251
|
-
L: 297,
|
|
1252
|
-
S: this,
|
|
1253
|
-
C: (f, a) => f(...a)
|
|
1254
|
-
});
|
|
821
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 260, S: this });
|
|
1255
822
|
if (err instanceof ConnectionDisplacedError) {
|
|
1256
823
|
this.connectionDisplaced.emit(this.connection);
|
|
1257
824
|
} else {
|
|
@@ -1263,12 +830,7 @@ var Peer = class {
|
|
|
1263
830
|
}
|
|
1264
831
|
this._callbacks.onDisconnected();
|
|
1265
832
|
scheduleTask2(this._connectionCtx, () => {
|
|
1266
|
-
log3("peer became available", logMeta, {
|
|
1267
|
-
F: __dxlog_file3,
|
|
1268
|
-
L: 321,
|
|
1269
|
-
S: this,
|
|
1270
|
-
C: (f, a) => f(...a)
|
|
1271
|
-
});
|
|
833
|
+
log3("peer became available", logMeta, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 279, S: this });
|
|
1272
834
|
this.availableToConnect = true;
|
|
1273
835
|
this._callbacks.onPeerAvailable();
|
|
1274
836
|
}, this._availableAfter);
|
|
@@ -1287,12 +849,7 @@ var Peer = class {
|
|
|
1287
849
|
remoteId: this.remoteInfo,
|
|
1288
850
|
initiator,
|
|
1289
851
|
err
|
|
1290
|
-
}, {
|
|
1291
|
-
F: __dxlog_file3,
|
|
1292
|
-
L: 339,
|
|
1293
|
-
S: this,
|
|
1294
|
-
C: (f, a) => f(...a)
|
|
1295
|
-
});
|
|
852
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 291, S: this });
|
|
1296
853
|
log3.trace("dxos.mesh.connection.error", {
|
|
1297
854
|
topic: this.topic,
|
|
1298
855
|
localPeerId: this.localInfo,
|
|
@@ -1300,12 +857,7 @@ var Peer = class {
|
|
|
1300
857
|
sessionId,
|
|
1301
858
|
initiator,
|
|
1302
859
|
err
|
|
1303
|
-
}, {
|
|
1304
|
-
F: __dxlog_file3,
|
|
1305
|
-
L: 346,
|
|
1306
|
-
S: this,
|
|
1307
|
-
C: (f, a) => f(...a)
|
|
1308
|
-
});
|
|
860
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 298, S: this });
|
|
1309
861
|
void this.closeConnection(err);
|
|
1310
862
|
});
|
|
1311
863
|
this.connection = connection;
|
|
@@ -1319,35 +871,20 @@ var Peer = class {
|
|
|
1319
871
|
log3("closing...", {
|
|
1320
872
|
peerId: this.remoteInfo,
|
|
1321
873
|
sessionId: connection.sessionId
|
|
1322
|
-
}, {
|
|
1323
|
-
F: __dxlog_file3,
|
|
1324
|
-
L: 371,
|
|
1325
|
-
S: this,
|
|
1326
|
-
C: (f, a) => f(...a)
|
|
1327
|
-
});
|
|
874
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 317, S: this });
|
|
1328
875
|
await connection.close({
|
|
1329
876
|
error: err
|
|
1330
877
|
});
|
|
1331
878
|
log3("closed", {
|
|
1332
879
|
peerId: this.remoteInfo,
|
|
1333
880
|
sessionId: connection.sessionId
|
|
1334
|
-
}, {
|
|
1335
|
-
F: __dxlog_file3,
|
|
1336
|
-
L: 377,
|
|
1337
|
-
S: this,
|
|
1338
|
-
C: (f, a) => f(...a)
|
|
1339
|
-
});
|
|
881
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 326, S: this });
|
|
1340
882
|
}
|
|
1341
883
|
async onSignal(ctx, message) {
|
|
1342
884
|
if (!this.connection) {
|
|
1343
885
|
log3("dropping signal message for non-existent connection", {
|
|
1344
886
|
message
|
|
1345
|
-
}, {
|
|
1346
|
-
F: __dxlog_file3,
|
|
1347
|
-
L: 382,
|
|
1348
|
-
S: this,
|
|
1349
|
-
C: (f, a) => f(...a)
|
|
1350
|
-
});
|
|
887
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 333, S: this });
|
|
1351
888
|
return;
|
|
1352
889
|
}
|
|
1353
890
|
await this.connection.signal(ctx, message);
|
|
@@ -1357,12 +894,7 @@ var Peer = class {
|
|
|
1357
894
|
log3("Destroying peer", {
|
|
1358
895
|
peerId: this.remoteInfo,
|
|
1359
896
|
topic: this.topic
|
|
1360
|
-
}, {
|
|
1361
|
-
F: __dxlog_file3,
|
|
1362
|
-
L: 392,
|
|
1363
|
-
S: this,
|
|
1364
|
-
C: (f, a) => f(...a)
|
|
1365
|
-
});
|
|
897
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 342, S: this });
|
|
1366
898
|
await this?.connection?.close({
|
|
1367
899
|
reason
|
|
1368
900
|
});
|
|
@@ -1385,13 +917,13 @@ var increaseInterval = (interval) => {
|
|
|
1385
917
|
};
|
|
1386
918
|
|
|
1387
919
|
// src/swarm/swarm.ts
|
|
920
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1388
921
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
1389
922
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1390
923
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1391
924
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1392
925
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1393
926
|
}
|
|
1394
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1395
927
|
var INITIATION_DELAY = 100;
|
|
1396
928
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1397
929
|
var Swarm = class {
|
|
@@ -1405,10 +937,7 @@ var Swarm = class {
|
|
|
1405
937
|
_connectionLimiter;
|
|
1406
938
|
_initiationDelay;
|
|
1407
939
|
_swarmMessenger;
|
|
1408
|
-
_ctx = new Context3(void 0, {
|
|
1409
|
-
F: __dxlog_file4,
|
|
1410
|
-
L: 38
|
|
1411
|
-
});
|
|
940
|
+
_ctx = new Context3(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 39 });
|
|
1412
941
|
_listeningHandle = void 0;
|
|
1413
942
|
/**
|
|
1414
943
|
* PeerInfo -> Peer.
|
|
@@ -1418,7 +947,7 @@ var Swarm = class {
|
|
|
1418
947
|
/**
|
|
1419
948
|
* Unique id of the swarm, local to the current peer, generated when swarm is joined.
|
|
1420
949
|
*/
|
|
1421
|
-
_instanceId =
|
|
950
|
+
_instanceId = PublicKey3.random().toHex();
|
|
1422
951
|
/**
|
|
1423
952
|
* New connection to a peer is started.
|
|
1424
953
|
* @internal
|
|
@@ -1447,26 +976,10 @@ var Swarm = class {
|
|
|
1447
976
|
this._label = _label;
|
|
1448
977
|
this._connectionLimiter = _connectionLimiter;
|
|
1449
978
|
this._initiationDelay = _initiationDelay;
|
|
1450
|
-
log4.trace("dxos.mesh.swarm.constructor", trace2.begin({
|
|
1451
|
-
id: this._instanceId,
|
|
1452
|
-
data: {
|
|
1453
|
-
topic: this._topic.toHex(),
|
|
1454
|
-
peer: this._ownPeer
|
|
1455
|
-
}
|
|
1456
|
-
}), {
|
|
1457
|
-
F: __dxlog_file4,
|
|
1458
|
-
L: 88,
|
|
1459
|
-
S: this,
|
|
1460
|
-
C: (f, a) => f(...a)
|
|
1461
|
-
});
|
|
1462
979
|
log4("creating swarm", {
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
L: 92,
|
|
1467
|
-
S: this,
|
|
1468
|
-
C: (f, a) => f(...a)
|
|
1469
|
-
});
|
|
980
|
+
topic: this._topic.toHex(),
|
|
981
|
+
peer: this._ownPeer
|
|
982
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 73, S: this });
|
|
1470
983
|
_topology.init(this._getSwarmController());
|
|
1471
984
|
this._swarmMessenger = new SwarmMessenger({
|
|
1472
985
|
sendMessage: async (ctx, msg) => await this._messenger.sendMessage(ctx, msg),
|
|
@@ -1474,20 +987,12 @@ var Swarm = class {
|
|
|
1474
987
|
onOffer: async (ctx, msg) => await this.onOffer(ctx, msg),
|
|
1475
988
|
topic: this._topic
|
|
1476
989
|
});
|
|
1477
|
-
log4.trace("dxos.mesh.swarm.constructor", trace2.end({
|
|
1478
|
-
id: this._instanceId
|
|
1479
|
-
}), {
|
|
1480
|
-
F: __dxlog_file4,
|
|
1481
|
-
L: 101,
|
|
1482
|
-
S: this,
|
|
1483
|
-
C: (f, a) => f(...a)
|
|
1484
|
-
});
|
|
1485
990
|
}
|
|
1486
991
|
get connections() {
|
|
1487
992
|
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable);
|
|
1488
993
|
}
|
|
1489
994
|
get ownPeerId() {
|
|
1490
|
-
return
|
|
995
|
+
return PublicKey3.from(this._ownPeer.peerKey);
|
|
1491
996
|
}
|
|
1492
997
|
get ownPeer() {
|
|
1493
998
|
return this._ownPeer;
|
|
@@ -1502,71 +1007,35 @@ var Swarm = class {
|
|
|
1502
1007
|
return this._topic;
|
|
1503
1008
|
}
|
|
1504
1009
|
async open() {
|
|
1505
|
-
invariant4(!this._listeningHandle, void 0, {
|
|
1506
|
-
F: __dxlog_file4,
|
|
1507
|
-
L: 132,
|
|
1508
|
-
S: this,
|
|
1509
|
-
A: [
|
|
1510
|
-
"!this._listeningHandle",
|
|
1511
|
-
""
|
|
1512
|
-
]
|
|
1513
|
-
});
|
|
1010
|
+
invariant4(!this._listeningHandle, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 103, S: this, A: ["!this._listeningHandle", ""] });
|
|
1514
1011
|
this._listeningHandle = await this._messenger.listen({
|
|
1515
1012
|
peer: this._ownPeer,
|
|
1516
1013
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
1517
1014
|
onMessage: async (message) => {
|
|
1518
1015
|
await this._swarmMessenger.receiveMessage(this._ctx, message).catch((err) => log4.info("Error while receiving message", {
|
|
1519
1016
|
err
|
|
1520
|
-
}, {
|
|
1521
|
-
F: __dxlog_file4,
|
|
1522
|
-
L: 140,
|
|
1523
|
-
S: this,
|
|
1524
|
-
C: (f, a) => f(...a)
|
|
1525
|
-
}));
|
|
1017
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 109, S: this }));
|
|
1526
1018
|
}
|
|
1527
1019
|
});
|
|
1528
1020
|
}
|
|
1529
1021
|
async destroy() {
|
|
1530
|
-
log4("destroying...", void 0, {
|
|
1531
|
-
F: __dxlog_file4,
|
|
1532
|
-
L: 146,
|
|
1533
|
-
S: this,
|
|
1534
|
-
C: (f, a) => f(...a)
|
|
1535
|
-
});
|
|
1022
|
+
log4("destroying...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 116, S: this });
|
|
1536
1023
|
await this._listeningHandle?.unsubscribe();
|
|
1537
1024
|
this._listeningHandle = void 0;
|
|
1538
1025
|
await this._ctx.dispose();
|
|
1539
1026
|
await this._topology.destroy();
|
|
1540
1027
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1541
|
-
log4("destroyed", void 0, {
|
|
1542
|
-
F: __dxlog_file4,
|
|
1543
|
-
L: 153,
|
|
1544
|
-
S: this,
|
|
1545
|
-
C: (f, a) => f(...a)
|
|
1546
|
-
});
|
|
1028
|
+
log4("destroyed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 122, S: this });
|
|
1547
1029
|
}
|
|
1548
1030
|
async setTopology(topology) {
|
|
1549
|
-
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1550
|
-
F: __dxlog_file4,
|
|
1551
|
-
L: 157,
|
|
1552
|
-
S: this,
|
|
1553
|
-
A: [
|
|
1554
|
-
"!this._ctx.disposed",
|
|
1555
|
-
"'Swarm is offline'"
|
|
1556
|
-
]
|
|
1557
|
-
});
|
|
1031
|
+
invariant4(!this._ctx.disposed, "Swarm is offline", { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 125, S: this, A: ["!this._ctx.disposed", "'Swarm is offline'"] });
|
|
1558
1032
|
if (topology === this._topology) {
|
|
1559
1033
|
return;
|
|
1560
1034
|
}
|
|
1561
1035
|
log4("setting topology", {
|
|
1562
1036
|
previous: getClassName(this._topology),
|
|
1563
1037
|
topology: getClassName(topology)
|
|
1564
|
-
}, {
|
|
1565
|
-
F: __dxlog_file4,
|
|
1566
|
-
L: 161,
|
|
1567
|
-
S: this,
|
|
1568
|
-
C: (f, a) => f(...a)
|
|
1569
|
-
});
|
|
1038
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 129, S: this });
|
|
1570
1039
|
await this._topology.destroy();
|
|
1571
1040
|
this._topology = topology;
|
|
1572
1041
|
this._topology.init(this._getSwarmController());
|
|
@@ -1575,19 +1044,9 @@ var Swarm = class {
|
|
|
1575
1044
|
async onSwarmEvent(swarmEvent) {
|
|
1576
1045
|
log4("swarm event", {
|
|
1577
1046
|
swarmEvent
|
|
1578
|
-
}, {
|
|
1579
|
-
F: __dxlog_file4,
|
|
1580
|
-
L: 174,
|
|
1581
|
-
S: this,
|
|
1582
|
-
C: (f, a) => f(...a)
|
|
1583
|
-
});
|
|
1047
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 139, S: this });
|
|
1584
1048
|
if (this._ctx.disposed) {
|
|
1585
|
-
log4("swarm event ignored for disposed swarm", void 0, {
|
|
1586
|
-
F: __dxlog_file4,
|
|
1587
|
-
L: 177,
|
|
1588
|
-
S: this,
|
|
1589
|
-
C: (f, a) => f(...a)
|
|
1590
|
-
});
|
|
1049
|
+
log4("swarm event ignored for disposed swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 143, S: this });
|
|
1591
1050
|
return;
|
|
1592
1051
|
}
|
|
1593
1052
|
if (swarmEvent.peerAvailable) {
|
|
@@ -1595,12 +1054,7 @@ var Swarm = class {
|
|
|
1595
1054
|
if (peerId !== this._ownPeer.peerKey) {
|
|
1596
1055
|
log4("new peer", {
|
|
1597
1056
|
peerId
|
|
1598
|
-
}, {
|
|
1599
|
-
F: __dxlog_file4,
|
|
1600
|
-
L: 184,
|
|
1601
|
-
S: this,
|
|
1602
|
-
C: (f, a) => f(...a)
|
|
1603
|
-
});
|
|
1057
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 149, S: this });
|
|
1604
1058
|
const peer = this._getOrCreatePeer(swarmEvent.peerAvailable.peer);
|
|
1605
1059
|
peer.advertizing = true;
|
|
1606
1060
|
}
|
|
@@ -1609,28 +1063,13 @@ var Swarm = class {
|
|
|
1609
1063
|
if (peer) {
|
|
1610
1064
|
peer.advertizing = false;
|
|
1611
1065
|
if (this._isConnectionEstablishmentInProgress(peer)) {
|
|
1612
|
-
log4(`destroying peer, state: ${peer.connection?.state}`, void 0, {
|
|
1613
|
-
|
|
1614
|
-
L: 195,
|
|
1615
|
-
S: this,
|
|
1616
|
-
C: (f, a) => f(...a)
|
|
1617
|
-
});
|
|
1618
|
-
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log4.catch(err, void 0, {
|
|
1619
|
-
F: __dxlog_file4,
|
|
1620
|
-
L: 196,
|
|
1621
|
-
S: this,
|
|
1622
|
-
C: (f, a) => f(...a)
|
|
1623
|
-
}));
|
|
1066
|
+
log4(`destroying peer, state: ${peer.connection?.state}`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 162, S: this });
|
|
1067
|
+
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log4.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 163, S: this }));
|
|
1624
1068
|
}
|
|
1625
1069
|
} else {
|
|
1626
1070
|
log4("received peerLeft but no peer found", {
|
|
1627
1071
|
peer: swarmEvent.peerLeft.peer.peerKey
|
|
1628
|
-
}, {
|
|
1629
|
-
F: __dxlog_file4,
|
|
1630
|
-
L: 199,
|
|
1631
|
-
S: this,
|
|
1632
|
-
C: (f, a) => f(...a)
|
|
1633
|
-
});
|
|
1072
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 166, S: this });
|
|
1634
1073
|
}
|
|
1635
1074
|
}
|
|
1636
1075
|
this._topology.update();
|
|
@@ -1638,41 +1077,18 @@ var Swarm = class {
|
|
|
1638
1077
|
async onOffer(ctx, message) {
|
|
1639
1078
|
log4("offer", {
|
|
1640
1079
|
message
|
|
1641
|
-
}, {
|
|
1642
|
-
F: __dxlog_file4,
|
|
1643
|
-
L: 208,
|
|
1644
|
-
S: this,
|
|
1645
|
-
C: (f, a) => f(...a)
|
|
1646
|
-
});
|
|
1080
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 174, S: this });
|
|
1647
1081
|
if (this._ctx.disposed) {
|
|
1648
|
-
log4("ignored for disposed swarm", void 0, {
|
|
1649
|
-
F: __dxlog_file4,
|
|
1650
|
-
L: 210,
|
|
1651
|
-
S: this,
|
|
1652
|
-
C: (f, a) => f(...a)
|
|
1653
|
-
});
|
|
1082
|
+
log4("ignored for disposed swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 178, S: this });
|
|
1654
1083
|
return {
|
|
1655
1084
|
accept: false
|
|
1656
1085
|
};
|
|
1657
1086
|
}
|
|
1658
|
-
invariant4(message.author, void 0, {
|
|
1659
|
-
F: __dxlog_file4,
|
|
1660
|
-
L: 215,
|
|
1661
|
-
S: this,
|
|
1662
|
-
A: [
|
|
1663
|
-
"message.author",
|
|
1664
|
-
""
|
|
1665
|
-
]
|
|
1666
|
-
});
|
|
1087
|
+
invariant4(message.author, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 184, S: this, A: ["message.author", ""] });
|
|
1667
1088
|
if (message.recipient.peerKey !== this._ownPeer.peerKey) {
|
|
1668
1089
|
log4("rejecting offer with incorrect peerId", {
|
|
1669
1090
|
message
|
|
1670
|
-
}, {
|
|
1671
|
-
F: __dxlog_file4,
|
|
1672
|
-
L: 217,
|
|
1673
|
-
S: this,
|
|
1674
|
-
C: (f, a) => f(...a)
|
|
1675
|
-
});
|
|
1091
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 186, S: this });
|
|
1676
1092
|
return {
|
|
1677
1093
|
accept: false
|
|
1678
1094
|
};
|
|
@@ -1680,12 +1096,7 @@ var Swarm = class {
|
|
|
1680
1096
|
if (!message.topic?.equals(this._topic)) {
|
|
1681
1097
|
log4("rejecting offer with incorrect topic", {
|
|
1682
1098
|
message
|
|
1683
|
-
}, {
|
|
1684
|
-
F: __dxlog_file4,
|
|
1685
|
-
L: 221,
|
|
1686
|
-
S: this,
|
|
1687
|
-
C: (f, a) => f(...a)
|
|
1688
|
-
});
|
|
1099
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 194, S: this });
|
|
1689
1100
|
return {
|
|
1690
1101
|
accept: false
|
|
1691
1102
|
};
|
|
@@ -1708,48 +1119,14 @@ var Swarm = class {
|
|
|
1708
1119
|
async onSignal(ctx, message) {
|
|
1709
1120
|
log4("signal", {
|
|
1710
1121
|
message
|
|
1711
|
-
}, {
|
|
1712
|
-
F: __dxlog_file4,
|
|
1713
|
-
L: 246,
|
|
1714
|
-
S: this,
|
|
1715
|
-
C: (f, a) => f(...a)
|
|
1716
|
-
});
|
|
1122
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 218, S: this });
|
|
1717
1123
|
if (this._ctx.disposed) {
|
|
1718
|
-
log4.info("ignored for offline swarm", void 0, {
|
|
1719
|
-
F: __dxlog_file4,
|
|
1720
|
-
L: 248,
|
|
1721
|
-
S: this,
|
|
1722
|
-
C: (f, a) => f(...a)
|
|
1723
|
-
});
|
|
1124
|
+
log4.info("ignored for offline swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 222, S: this });
|
|
1724
1125
|
return;
|
|
1725
1126
|
}
|
|
1726
|
-
invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
S: this,
|
|
1730
|
-
A: [
|
|
1731
|
-
"message.recipient.peerKey === this._ownPeer.peerKey",
|
|
1732
|
-
"`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
|
|
1733
|
-
]
|
|
1734
|
-
});
|
|
1735
|
-
invariant4(message.topic?.equals(this._topic), void 0, {
|
|
1736
|
-
F: __dxlog_file4,
|
|
1737
|
-
L: 255,
|
|
1738
|
-
S: this,
|
|
1739
|
-
A: [
|
|
1740
|
-
"message.topic?.equals(this._topic)",
|
|
1741
|
-
""
|
|
1742
|
-
]
|
|
1743
|
-
});
|
|
1744
|
-
invariant4(message.author, void 0, {
|
|
1745
|
-
F: __dxlog_file4,
|
|
1746
|
-
L: 256,
|
|
1747
|
-
S: this,
|
|
1748
|
-
A: [
|
|
1749
|
-
"message.author",
|
|
1750
|
-
""
|
|
1751
|
-
]
|
|
1752
|
-
});
|
|
1127
|
+
invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 225, S: this, A: ["message.recipient.peerKey === this._ownPeer.peerKey", "`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"] });
|
|
1128
|
+
invariant4(message.topic?.equals(this._topic), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 226, S: this, A: ["message.topic?.equals(this._topic)", ""] });
|
|
1129
|
+
invariant4(message.author, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 227, S: this, A: ["message.author", ""] });
|
|
1753
1130
|
const peer = this._getOrCreatePeer(message.author);
|
|
1754
1131
|
await peer.onSignal(ctx, message);
|
|
1755
1132
|
}
|
|
@@ -1762,21 +1139,10 @@ var Swarm = class {
|
|
|
1762
1139
|
}
|
|
1763
1140
|
// For debug purposes
|
|
1764
1141
|
async goOnline() {
|
|
1765
|
-
this._ctx = new Context3(void 0, {
|
|
1766
|
-
F: __dxlog_file4,
|
|
1767
|
-
L: 272
|
|
1768
|
-
});
|
|
1142
|
+
this._ctx = new Context3(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 240 });
|
|
1769
1143
|
}
|
|
1770
1144
|
_getOrCreatePeer(peerInfo) {
|
|
1771
|
-
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
|
|
1772
|
-
F: __dxlog_file4,
|
|
1773
|
-
L: 276,
|
|
1774
|
-
S: this,
|
|
1775
|
-
A: [
|
|
1776
|
-
"peerInfo.peerKey",
|
|
1777
|
-
"'PeerInfo.peerKey is required'"
|
|
1778
|
-
]
|
|
1779
|
-
});
|
|
1145
|
+
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 243, S: this, A: ["peerInfo.peerKey", "'PeerInfo.peerKey is required'"] });
|
|
1780
1146
|
let peer = this._peers.get(peerInfo);
|
|
1781
1147
|
if (!peer) {
|
|
1782
1148
|
peer = new Peer(peerInfo, this._topic, this._ownPeer, this._swarmMessenger, this._protocolProvider, this._transportFactory, this._connectionLimiter, {
|
|
@@ -1788,12 +1154,7 @@ var Swarm = class {
|
|
|
1788
1154
|
},
|
|
1789
1155
|
onDisconnected: async () => {
|
|
1790
1156
|
if (this._isUnregistered(peer)) {
|
|
1791
|
-
log4.verbose("ignored onDisconnected for unregistered peer", void 0, {
|
|
1792
|
-
F: __dxlog_file4,
|
|
1793
|
-
L: 296,
|
|
1794
|
-
S: this,
|
|
1795
|
-
C: (f, a) => f(...a)
|
|
1796
|
-
});
|
|
1157
|
+
log4.verbose("ignored onDisconnected for unregistered peer", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 255, S: this });
|
|
1797
1158
|
return;
|
|
1798
1159
|
}
|
|
1799
1160
|
if (!peer.advertizing) {
|
|
@@ -1806,12 +1167,7 @@ var Swarm = class {
|
|
|
1806
1167
|
if (!this._isUnregistered(peer)) {
|
|
1807
1168
|
log4("peer rejected connection", {
|
|
1808
1169
|
peerInfo
|
|
1809
|
-
}, {
|
|
1810
|
-
F: __dxlog_file4,
|
|
1811
|
-
L: 310,
|
|
1812
|
-
S: this,
|
|
1813
|
-
C: (f, a) => f(...a)
|
|
1814
|
-
});
|
|
1170
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 268, S: this });
|
|
1815
1171
|
void this._destroyPeer(peerInfo, "peer rejected connection");
|
|
1816
1172
|
}
|
|
1817
1173
|
},
|
|
@@ -1819,7 +1175,7 @@ var Swarm = class {
|
|
|
1819
1175
|
this._topology.update();
|
|
1820
1176
|
},
|
|
1821
1177
|
onOffer: (remoteId) => {
|
|
1822
|
-
return this._topology.onOffer(
|
|
1178
|
+
return this._topology.onOffer(PublicKey3.from(remoteId.peerKey));
|
|
1823
1179
|
},
|
|
1824
1180
|
onPeerAvailable: () => {
|
|
1825
1181
|
this._topology.update();
|
|
@@ -1833,32 +1189,19 @@ var Swarm = class {
|
|
|
1833
1189
|
log4("destroy peer", {
|
|
1834
1190
|
peerKey: peerInfo.peerKey,
|
|
1835
1191
|
reason
|
|
1836
|
-
}, {
|
|
1837
|
-
F: __dxlog_file4,
|
|
1838
|
-
L: 332,
|
|
1839
|
-
S: this,
|
|
1840
|
-
C: (f, a) => f(...a)
|
|
1841
|
-
});
|
|
1192
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 289, S: this });
|
|
1842
1193
|
const peer = this._peers.get(peerInfo);
|
|
1843
|
-
invariant4(peer, void 0, {
|
|
1844
|
-
F: __dxlog_file4,
|
|
1845
|
-
L: 334,
|
|
1846
|
-
S: this,
|
|
1847
|
-
A: [
|
|
1848
|
-
"peer",
|
|
1849
|
-
""
|
|
1850
|
-
]
|
|
1851
|
-
});
|
|
1194
|
+
invariant4(peer, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 294, S: this, A: ["peer", ""] });
|
|
1852
1195
|
this._peers.delete(peerInfo);
|
|
1853
1196
|
await peer.safeDestroy(reason);
|
|
1854
1197
|
}
|
|
1855
1198
|
_getSwarmController() {
|
|
1856
1199
|
return {
|
|
1857
1200
|
getState: () => ({
|
|
1858
|
-
ownPeerId:
|
|
1859
|
-
connected: Array.from(this._peers.entries()).filter(([_, peer]) => peer.connection).map(([info]) =>
|
|
1860
|
-
candidates: Array.from(this._peers.entries()).filter(([_, peer]) => !peer.connection && peer.advertizing && peer.availableToConnect).map(([info]) =>
|
|
1861
|
-
allPeers: Array.from(this._peers.keys()).map((info) =>
|
|
1201
|
+
ownPeerId: PublicKey3.from(this._ownPeer.peerKey),
|
|
1202
|
+
connected: Array.from(this._peers.entries()).filter(([_, peer]) => peer.connection).map(([info]) => PublicKey3.from(info.peerKey)),
|
|
1203
|
+
candidates: Array.from(this._peers.entries()).filter(([_, peer]) => !peer.connection && peer.advertizing && peer.availableToConnect).map(([info]) => PublicKey3.from(info.peerKey)),
|
|
1204
|
+
allPeers: Array.from(this._peers.keys()).map((info) => PublicKey3.from(info.peerKey))
|
|
1862
1205
|
}),
|
|
1863
1206
|
connect: (peer) => {
|
|
1864
1207
|
if (this._ctx.disposed) {
|
|
@@ -1870,12 +1213,7 @@ var Swarm = class {
|
|
|
1870
1213
|
peerKey: peer.toHex()
|
|
1871
1214
|
});
|
|
1872
1215
|
} catch (err) {
|
|
1873
|
-
log4("initiation error", err, {
|
|
1874
|
-
F: __dxlog_file4,
|
|
1875
|
-
L: 361,
|
|
1876
|
-
S: this,
|
|
1877
|
-
C: (f, a) => f(...a)
|
|
1878
|
-
});
|
|
1216
|
+
log4("initiation error", err, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 317, S: this });
|
|
1879
1217
|
}
|
|
1880
1218
|
});
|
|
1881
1219
|
},
|
|
@@ -1901,12 +1239,7 @@ var Swarm = class {
|
|
|
1901
1239
|
if (remotePeer.peerKey < this._ownPeer.peerKey) {
|
|
1902
1240
|
log4("initiation delay", {
|
|
1903
1241
|
remotePeer
|
|
1904
|
-
}, {
|
|
1905
|
-
F: __dxlog_file4,
|
|
1906
|
-
L: 389,
|
|
1907
|
-
S: this,
|
|
1908
|
-
C: (f, a) => f(...a)
|
|
1909
|
-
});
|
|
1242
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 343, S: this });
|
|
1910
1243
|
await sleep2(this._initiationDelay);
|
|
1911
1244
|
}
|
|
1912
1245
|
if (ctx.disposed) {
|
|
@@ -1920,22 +1253,12 @@ var Swarm = class {
|
|
|
1920
1253
|
}
|
|
1921
1254
|
log4("initiating connection...", {
|
|
1922
1255
|
remotePeer
|
|
1923
|
-
}, {
|
|
1924
|
-
F: __dxlog_file4,
|
|
1925
|
-
L: 405,
|
|
1926
|
-
S: this,
|
|
1927
|
-
C: (f, a) => f(...a)
|
|
1928
|
-
});
|
|
1256
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 358, S: this });
|
|
1929
1257
|
await peer.initiateConnection(ctx);
|
|
1930
1258
|
this._topology.update();
|
|
1931
1259
|
log4("initiated", {
|
|
1932
1260
|
remotePeer
|
|
1933
|
-
}, {
|
|
1934
|
-
F: __dxlog_file4,
|
|
1935
|
-
L: 408,
|
|
1936
|
-
S: this,
|
|
1937
|
-
C: (f, a) => f(...a)
|
|
1938
|
-
});
|
|
1261
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 363, S: this });
|
|
1939
1262
|
}
|
|
1940
1263
|
async _closeConnection(peerInfo) {
|
|
1941
1264
|
const peer = this._peers.get(peerInfo);
|
|
@@ -1982,7 +1305,7 @@ _ts_decorate3([
|
|
|
1982
1305
|
|
|
1983
1306
|
// src/swarm/swarm-mapper.ts
|
|
1984
1307
|
import { Event as Event4, SubscriptionList } from "@dxos/async";
|
|
1985
|
-
import { PublicKey as
|
|
1308
|
+
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
1986
1309
|
import { log as log5 } from "@dxos/log";
|
|
1987
1310
|
import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
|
|
1988
1311
|
import { ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
@@ -2012,12 +1335,7 @@ var SwarmMapper = class {
|
|
|
2012
1335
|
this._update();
|
|
2013
1336
|
}
|
|
2014
1337
|
_update() {
|
|
2015
|
-
log5("updating swarm", void 0, {
|
|
2016
|
-
F: __dxlog_file5,
|
|
2017
|
-
L: 71,
|
|
2018
|
-
S: this,
|
|
2019
|
-
C: (f, a) => f(...a)
|
|
2020
|
-
});
|
|
1338
|
+
log5("updating swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 40, S: this });
|
|
2021
1339
|
this._peers.clear();
|
|
2022
1340
|
this._peers.set(this._swarm.ownPeer, {
|
|
2023
1341
|
id: this._swarm.ownPeerId,
|
|
@@ -2026,7 +1344,7 @@ var SwarmMapper = class {
|
|
|
2026
1344
|
});
|
|
2027
1345
|
for (const connection of this._swarm.connections) {
|
|
2028
1346
|
this._peers.set(connection.remoteInfo, {
|
|
2029
|
-
id:
|
|
1347
|
+
id: PublicKey4.from(connection.remoteInfo.peerKey),
|
|
2030
1348
|
state: connection.state,
|
|
2031
1349
|
connections: [
|
|
2032
1350
|
this._swarm.ownPeerId
|
|
@@ -2036,12 +1354,7 @@ var SwarmMapper = class {
|
|
|
2036
1354
|
log5("graph changed", {
|
|
2037
1355
|
directConnections: this._swarm.connections.length,
|
|
2038
1356
|
totalPeersInSwarm: this._peers.size
|
|
2039
|
-
}, {
|
|
2040
|
-
F: __dxlog_file5,
|
|
2041
|
-
L: 112,
|
|
2042
|
-
S: this,
|
|
2043
|
-
C: (f, a) => f(...a)
|
|
2044
|
-
});
|
|
1357
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 77, S: this });
|
|
2045
1358
|
this.mapUpdated.emit(Array.from(this._peers.values()));
|
|
2046
1359
|
}
|
|
2047
1360
|
// TODO(burdon): Async open/close.
|
|
@@ -2056,22 +1369,19 @@ var SwarmMapper = class {
|
|
|
2056
1369
|
import { DeferredTask as DeferredTask2 } from "@dxos/async";
|
|
2057
1370
|
import { Context as Context4 } from "@dxos/context";
|
|
2058
1371
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
2059
|
-
import { PublicKey as
|
|
1372
|
+
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
2060
1373
|
import { log as log6 } from "@dxos/log";
|
|
2061
1374
|
import { CancelledError as CancelledError3 } from "@dxos/protocols";
|
|
2062
1375
|
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
2063
1376
|
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
2064
1377
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
|
|
2065
1378
|
var ConnectionLimiter = class {
|
|
2066
|
-
_ctx = new Context4(void 0, {
|
|
2067
|
-
F: __dxlog_file6,
|
|
2068
|
-
L: 23
|
|
2069
|
-
});
|
|
1379
|
+
_ctx = new Context4(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 15 });
|
|
2070
1380
|
_maxConcurrentInitConnections;
|
|
2071
1381
|
/**
|
|
2072
1382
|
* Queue of promises to resolve when initiating connections amount is below the limit.
|
|
2073
1383
|
*/
|
|
2074
|
-
_waitingPromises = new ComplexMap4(
|
|
1384
|
+
_waitingPromises = new ComplexMap4(PublicKey5.hash);
|
|
2075
1385
|
resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
|
|
2076
1386
|
Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
|
|
2077
1387
|
resolve();
|
|
@@ -2084,23 +1394,10 @@ var ConnectionLimiter = class {
|
|
|
2084
1394
|
* @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
|
|
2085
1395
|
*/
|
|
2086
1396
|
async connecting(sessionId) {
|
|
2087
|
-
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
2088
|
-
F: __dxlog_file6,
|
|
2089
|
-
L: 48,
|
|
2090
|
-
S: this,
|
|
2091
|
-
A: [
|
|
2092
|
-
"!this._waitingPromises.has(sessionId)",
|
|
2093
|
-
"'Peer is already waiting for connection'"
|
|
2094
|
-
]
|
|
2095
|
-
});
|
|
1397
|
+
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 31, S: this, A: ["!this._waitingPromises.has(sessionId)", "'Peer is already waiting for connection'"] });
|
|
2096
1398
|
log6("waiting", {
|
|
2097
1399
|
sessionId
|
|
2098
|
-
}, {
|
|
2099
|
-
F: __dxlog_file6,
|
|
2100
|
-
L: 49,
|
|
2101
|
-
S: this,
|
|
2102
|
-
C: (f, a) => f(...a)
|
|
2103
|
-
});
|
|
1400
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 32, S: this });
|
|
2104
1401
|
await new Promise((resolve, reject) => {
|
|
2105
1402
|
this._waitingPromises.set(sessionId, {
|
|
2106
1403
|
resolve,
|
|
@@ -2110,12 +1407,7 @@ var ConnectionLimiter = class {
|
|
|
2110
1407
|
});
|
|
2111
1408
|
log6("allow", {
|
|
2112
1409
|
sessionId
|
|
2113
|
-
}, {
|
|
2114
|
-
F: __dxlog_file6,
|
|
2115
|
-
L: 57,
|
|
2116
|
-
S: this,
|
|
2117
|
-
C: (f, a) => f(...a)
|
|
2118
|
-
});
|
|
1410
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 42, S: this });
|
|
2119
1411
|
}
|
|
2120
1412
|
/**
|
|
2121
1413
|
* Rejects promise returned by `connecting` method.
|
|
@@ -2123,12 +1415,7 @@ var ConnectionLimiter = class {
|
|
|
2123
1415
|
doneConnecting(sessionId) {
|
|
2124
1416
|
log6("done", {
|
|
2125
1417
|
sessionId
|
|
2126
|
-
}, {
|
|
2127
|
-
F: __dxlog_file6,
|
|
2128
|
-
L: 64,
|
|
2129
|
-
S: this,
|
|
2130
|
-
C: (f, a) => f(...a)
|
|
2131
|
-
});
|
|
1418
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 49, S: this });
|
|
2132
1419
|
if (!this._waitingPromises.has(sessionId)) {
|
|
2133
1420
|
return;
|
|
2134
1421
|
}
|
|
@@ -2141,7 +1428,7 @@ var ConnectionLimiter = class {
|
|
|
2141
1428
|
// src/connection-log.ts
|
|
2142
1429
|
import { Event as Event5 } from "@dxos/async";
|
|
2143
1430
|
import { raise } from "@dxos/debug";
|
|
2144
|
-
import { PublicKey as
|
|
1431
|
+
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
2145
1432
|
import { ComplexMap as ComplexMap5 } from "@dxos/util";
|
|
2146
1433
|
var CONNECTION_GC_THRESHOLD = 1e3 * 60 * 15;
|
|
2147
1434
|
var EventType = /* @__PURE__ */ (function(EventType2) {
|
|
@@ -2156,7 +1443,7 @@ var ConnectionLog = class {
|
|
|
2156
1443
|
/**
|
|
2157
1444
|
* SwarmId => info
|
|
2158
1445
|
*/
|
|
2159
|
-
_swarms = new ComplexMap5(
|
|
1446
|
+
_swarms = new ComplexMap5(PublicKey6.hash);
|
|
2160
1447
|
update = new Event5();
|
|
2161
1448
|
getSwarmInfo(swarmId) {
|
|
2162
1449
|
return this._swarms.get(swarmId) ?? raise(new Error(`Swarm not found: ${swarmId}`));
|
|
@@ -2166,19 +1453,19 @@ var ConnectionLog = class {
|
|
|
2166
1453
|
}
|
|
2167
1454
|
joinedSwarm(swarm) {
|
|
2168
1455
|
const info = {
|
|
2169
|
-
id:
|
|
1456
|
+
id: PublicKey6.from(swarm._instanceId),
|
|
2170
1457
|
topic: swarm.topic,
|
|
2171
1458
|
isActive: true,
|
|
2172
1459
|
label: swarm.label,
|
|
2173
1460
|
connections: []
|
|
2174
1461
|
};
|
|
2175
|
-
this._swarms.set(
|
|
1462
|
+
this._swarms.set(PublicKey6.from(swarm._instanceId), info);
|
|
2176
1463
|
this.update.emit();
|
|
2177
1464
|
swarm.connectionAdded.on((connection) => {
|
|
2178
1465
|
const connectionInfo = {
|
|
2179
1466
|
state: ConnectionState.CREATED,
|
|
2180
1467
|
closeReason: connection.closeReason,
|
|
2181
|
-
remotePeerId:
|
|
1468
|
+
remotePeerId: PublicKey6.from(connection.remoteInfo.peerKey),
|
|
2182
1469
|
sessionId: connection.sessionId,
|
|
2183
1470
|
transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
|
|
2184
1471
|
protocolExtensions: [],
|
|
@@ -2218,7 +1505,7 @@ var ConnectionLog = class {
|
|
|
2218
1505
|
});
|
|
2219
1506
|
}
|
|
2220
1507
|
leftSwarm(swarm) {
|
|
2221
|
-
this.getSwarmInfo(
|
|
1508
|
+
this.getSwarmInfo(PublicKey6.from(swarm._instanceId)).isActive = false;
|
|
2222
1509
|
this.update.emit();
|
|
2223
1510
|
}
|
|
2224
1511
|
};
|
|
@@ -2231,32 +1518,30 @@ var gcSwarm = (swarm) => {
|
|
|
2231
1518
|
// src/network-manager.ts
|
|
2232
1519
|
import { Event as Event6, synchronized as synchronized4 } from "@dxos/async";
|
|
2233
1520
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
2234
|
-
import { PublicKey as
|
|
1521
|
+
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
2235
1522
|
import { log as log7 } from "@dxos/log";
|
|
2236
1523
|
import { Messenger } from "@dxos/messaging";
|
|
2237
|
-
import { trace as trace3 } from "@dxos/protocols";
|
|
2238
1524
|
import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2239
1525
|
import { ComplexMap as ComplexMap6 } from "@dxos/util";
|
|
1526
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2240
1527
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
2241
1528
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2242
1529
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2243
1530
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2244
1531
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2245
1532
|
}
|
|
2246
|
-
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2247
1533
|
var SwarmNetworkManager = class {
|
|
2248
1534
|
/**
|
|
2249
1535
|
* @internal
|
|
2250
1536
|
*/
|
|
2251
|
-
_swarms = new ComplexMap6(
|
|
2252
|
-
_mappers = new ComplexMap6(
|
|
1537
|
+
_swarms = new ComplexMap6(PublicKey7.hash);
|
|
1538
|
+
_mappers = new ComplexMap6(PublicKey7.hash);
|
|
2253
1539
|
_transportFactory;
|
|
2254
1540
|
_signalManager;
|
|
2255
1541
|
_messenger;
|
|
2256
1542
|
_signalConnection;
|
|
2257
1543
|
_connectionLimiter;
|
|
2258
1544
|
_connectionLog;
|
|
2259
|
-
_instanceId = PublicKey8.random().toHex();
|
|
2260
1545
|
_peerInfo = void 0;
|
|
2261
1546
|
_connectionState = ConnectionState2.ONLINE;
|
|
2262
1547
|
connectionStateChanged = new Event6();
|
|
@@ -2299,34 +1584,15 @@ var SwarmNetworkManager = class {
|
|
|
2299
1584
|
this._peerInfo = peerInfo;
|
|
2300
1585
|
}
|
|
2301
1586
|
async open() {
|
|
2302
|
-
log7
|
|
2303
|
-
id: this._instanceId
|
|
2304
|
-
}), {
|
|
2305
|
-
F: __dxlog_file7,
|
|
2306
|
-
L: 134,
|
|
2307
|
-
S: this,
|
|
2308
|
-
C: (f, a) => f(...a)
|
|
2309
|
-
});
|
|
1587
|
+
log7("opening network manager", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 76, S: this });
|
|
2310
1588
|
await this._messenger.open();
|
|
2311
1589
|
await this._signalManager.open();
|
|
2312
|
-
log7
|
|
2313
|
-
id: this._instanceId
|
|
2314
|
-
}), {
|
|
2315
|
-
F: __dxlog_file7,
|
|
2316
|
-
L: 137,
|
|
2317
|
-
S: this,
|
|
2318
|
-
C: (f, a) => f(...a)
|
|
2319
|
-
});
|
|
1590
|
+
log7("opened network manager", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 79, S: this });
|
|
2320
1591
|
}
|
|
2321
1592
|
async close(ctx) {
|
|
2322
1593
|
for (const topic of this._swarms.keys()) {
|
|
2323
1594
|
await this.leaveSwarm(ctx, topic).catch((err) => {
|
|
2324
|
-
log7(err, void 0, {
|
|
2325
|
-
F: __dxlog_file7,
|
|
2326
|
-
L: 143,
|
|
2327
|
-
S: this,
|
|
2328
|
-
C: (f, a) => f(...a)
|
|
2329
|
-
});
|
|
1595
|
+
log7(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 84, S: this });
|
|
2330
1596
|
});
|
|
2331
1597
|
}
|
|
2332
1598
|
await this._messenger.close();
|
|
@@ -2336,65 +1602,23 @@ var SwarmNetworkManager = class {
|
|
|
2336
1602
|
* Join the swarm.
|
|
2337
1603
|
*/
|
|
2338
1604
|
async joinSwarm(ctx, { topic, topology, protocolProvider: protocol, label }) {
|
|
2339
|
-
invariant6(
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
A: [
|
|
2344
|
-
"PublicKey.isPublicKey(topic)",
|
|
2345
|
-
""
|
|
2346
|
-
]
|
|
2347
|
-
});
|
|
2348
|
-
invariant6(topology, void 0, {
|
|
2349
|
-
F: __dxlog_file7,
|
|
2350
|
-
L: 165,
|
|
2351
|
-
S: this,
|
|
2352
|
-
A: [
|
|
2353
|
-
"topology",
|
|
2354
|
-
""
|
|
2355
|
-
]
|
|
2356
|
-
});
|
|
2357
|
-
invariant6(this._peerInfo, void 0, {
|
|
2358
|
-
F: __dxlog_file7,
|
|
2359
|
-
L: 166,
|
|
2360
|
-
S: this,
|
|
2361
|
-
A: [
|
|
2362
|
-
"this._peerInfo",
|
|
2363
|
-
""
|
|
2364
|
-
]
|
|
2365
|
-
});
|
|
2366
|
-
invariant6(typeof protocol === "function", void 0, {
|
|
2367
|
-
F: __dxlog_file7,
|
|
2368
|
-
L: 167,
|
|
2369
|
-
S: this,
|
|
2370
|
-
A: [
|
|
2371
|
-
"typeof protocol === 'function'",
|
|
2372
|
-
""
|
|
2373
|
-
]
|
|
2374
|
-
});
|
|
1605
|
+
invariant6(PublicKey7.isPublicKey(topic), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 93, S: this, A: ["PublicKey.isPublicKey(topic)", ""] });
|
|
1606
|
+
invariant6(topology, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 94, S: this, A: ["topology", ""] });
|
|
1607
|
+
invariant6(this._peerInfo, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 95, S: this, A: ["this._peerInfo", ""] });
|
|
1608
|
+
invariant6(typeof protocol === "function", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 96, S: this, A: ["typeof protocol === 'function'", ""] });
|
|
2375
1609
|
if (this._swarms.has(topic)) {
|
|
2376
|
-
throw new Error(`Already connected to swarm: ${
|
|
1610
|
+
throw new Error(`Already connected to swarm: ${PublicKey7.from(topic)}`);
|
|
2377
1611
|
}
|
|
2378
1612
|
log7("joining", {
|
|
2379
|
-
topic:
|
|
1613
|
+
topic: PublicKey7.from(topic),
|
|
2380
1614
|
peerInfo: this._peerInfo,
|
|
2381
1615
|
topology: topology.toString()
|
|
2382
|
-
}, {
|
|
2383
|
-
F: __dxlog_file7,
|
|
2384
|
-
L: 172,
|
|
2385
|
-
S: this,
|
|
2386
|
-
C: (f, a) => f(...a)
|
|
2387
|
-
});
|
|
1616
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 100, S: this });
|
|
2388
1617
|
const swarm = new Swarm(topic, this._peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
2389
1618
|
swarm.errors.handle((error) => {
|
|
2390
1619
|
log7("swarm error", {
|
|
2391
1620
|
error
|
|
2392
|
-
}, {
|
|
2393
|
-
F: __dxlog_file7,
|
|
2394
|
-
L: 185,
|
|
2395
|
-
S: this,
|
|
2396
|
-
C: (f, a) => f(...a)
|
|
2397
|
-
});
|
|
1621
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 107, S: this });
|
|
2398
1622
|
});
|
|
2399
1623
|
this._swarms.set(topic, swarm);
|
|
2400
1624
|
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
@@ -2402,23 +1626,13 @@ var SwarmNetworkManager = class {
|
|
|
2402
1626
|
this._signalConnection.join(ctx, {
|
|
2403
1627
|
topic,
|
|
2404
1628
|
peer: this._peerInfo
|
|
2405
|
-
}).catch((error) => log7.catch(error, void 0, {
|
|
2406
|
-
F: __dxlog_file7,
|
|
2407
|
-
L: 194,
|
|
2408
|
-
S: this,
|
|
2409
|
-
C: (f, a) => f(...a)
|
|
2410
|
-
}));
|
|
1629
|
+
}).catch((error) => log7.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 118, S: this }));
|
|
2411
1630
|
this.topicsUpdated.emit();
|
|
2412
1631
|
this._connectionLog?.joinedSwarm(swarm);
|
|
2413
1632
|
log7("joined", {
|
|
2414
|
-
topic:
|
|
1633
|
+
topic: PublicKey7.from(topic),
|
|
2415
1634
|
count: this._swarms.size
|
|
2416
|
-
}, {
|
|
2417
|
-
F: __dxlog_file7,
|
|
2418
|
-
L: 198,
|
|
2419
|
-
S: this,
|
|
2420
|
-
C: (f, a) => f(...a)
|
|
2421
|
-
});
|
|
1635
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 121, S: this });
|
|
2422
1636
|
return {
|
|
2423
1637
|
close: (ctx2) => this.leaveSwarm(ctx2, topic)
|
|
2424
1638
|
};
|
|
@@ -2431,13 +1645,8 @@ var SwarmNetworkManager = class {
|
|
|
2431
1645
|
return;
|
|
2432
1646
|
}
|
|
2433
1647
|
log7("leaving", {
|
|
2434
|
-
topic:
|
|
2435
|
-
}, {
|
|
2436
|
-
F: __dxlog_file7,
|
|
2437
|
-
L: 215,
|
|
2438
|
-
S: this,
|
|
2439
|
-
C: (f, a) => f(...a)
|
|
2440
|
-
});
|
|
1648
|
+
topic: PublicKey7.from(topic)
|
|
1649
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 136, S: this });
|
|
2441
1650
|
const swarm = this._swarms.get(topic);
|
|
2442
1651
|
await this._signalConnection.leave(ctx, {
|
|
2443
1652
|
topic,
|
|
@@ -2451,14 +1660,9 @@ var SwarmNetworkManager = class {
|
|
|
2451
1660
|
this._swarms.delete(topic);
|
|
2452
1661
|
this.topicsUpdated.emit();
|
|
2453
1662
|
log7("left", {
|
|
2454
|
-
topic:
|
|
1663
|
+
topic: PublicKey7.from(topic),
|
|
2455
1664
|
count: this._swarms.size
|
|
2456
|
-
}, {
|
|
2457
|
-
F: __dxlog_file7,
|
|
2458
|
-
L: 229,
|
|
2459
|
-
S: this,
|
|
2460
|
-
C: (f, a) => f(...a)
|
|
2461
|
-
});
|
|
1665
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 151, S: this });
|
|
2462
1666
|
}
|
|
2463
1667
|
async setConnectionState(state) {
|
|
2464
1668
|
if (state === this._connectionState) {
|
|
@@ -2503,27 +1707,11 @@ var FullyConnectedTopology = class {
|
|
|
2503
1707
|
return "FullyConnectedTopology";
|
|
2504
1708
|
}
|
|
2505
1709
|
init(controller) {
|
|
2506
|
-
invariant7(!this._controller, "Already initialized", {
|
|
2507
|
-
F: __dxlog_file8,
|
|
2508
|
-
L: 18,
|
|
2509
|
-
S: this,
|
|
2510
|
-
A: [
|
|
2511
|
-
"!this._controller",
|
|
2512
|
-
"'Already initialized'"
|
|
2513
|
-
]
|
|
2514
|
-
});
|
|
1710
|
+
invariant7(!this._controller, "Already initialized", { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 11, S: this, A: ["!this._controller", "'Already initialized'"] });
|
|
2515
1711
|
this._controller = controller;
|
|
2516
1712
|
}
|
|
2517
1713
|
update() {
|
|
2518
|
-
invariant7(this._controller, "Not initialized", {
|
|
2519
|
-
F: __dxlog_file8,
|
|
2520
|
-
L: 23,
|
|
2521
|
-
S: this,
|
|
2522
|
-
A: [
|
|
2523
|
-
"this._controller",
|
|
2524
|
-
"'Not initialized'"
|
|
2525
|
-
]
|
|
2526
|
-
});
|
|
1714
|
+
invariant7(this._controller, "Not initialized", { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 15, S: this, A: ["this._controller", "'Not initialized'"] });
|
|
2527
1715
|
const { candidates: discovered } = this._controller.getState();
|
|
2528
1716
|
for (const peer of discovered) {
|
|
2529
1717
|
this._controller.connect(peer);
|
|
@@ -2541,16 +1729,16 @@ import { Transform } from "node:stream";
|
|
|
2541
1729
|
import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
|
|
2542
1730
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
2543
1731
|
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2544
|
-
import { PublicKey as
|
|
1732
|
+
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2545
1733
|
import { log as log8, logInfo as logInfo3 } from "@dxos/log";
|
|
2546
1734
|
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
1735
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
2547
1736
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
2548
1737
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2549
1738
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2550
1739
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2551
1740
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2552
1741
|
}
|
|
2553
|
-
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
2554
1742
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
2555
1743
|
var createStreamDelay = (delay) => {
|
|
2556
1744
|
return new Transform({
|
|
@@ -2566,8 +1754,8 @@ var MemoryTransportFactory = {
|
|
|
2566
1754
|
var MemoryTransport = class _MemoryTransport {
|
|
2567
1755
|
_options;
|
|
2568
1756
|
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
2569
|
-
static _connections = new ComplexMap7(
|
|
2570
|
-
_instanceId =
|
|
1757
|
+
static _connections = new ComplexMap7(PublicKey8.hash);
|
|
1758
|
+
_instanceId = PublicKey8.random();
|
|
2571
1759
|
_remote = new Trigger2();
|
|
2572
1760
|
_outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2573
1761
|
_incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
@@ -2579,34 +1767,16 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2579
1767
|
errors = new ErrorStream3();
|
|
2580
1768
|
constructor(_options) {
|
|
2581
1769
|
this._options = _options;
|
|
2582
|
-
invariant8(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2583
|
-
F: __dxlog_file9,
|
|
2584
|
-
L: 64,
|
|
2585
|
-
S: this,
|
|
2586
|
-
A: [
|
|
2587
|
-
"!MemoryTransport._connections.has(this._instanceId)",
|
|
2588
|
-
"'Duplicate memory connection'"
|
|
2589
|
-
]
|
|
2590
|
-
});
|
|
1770
|
+
invariant8(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 51, S: this, A: ["!MemoryTransport._connections.has(this._instanceId)", "'Duplicate memory connection'"] });
|
|
2591
1771
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
2592
1772
|
}
|
|
2593
1773
|
get isOpen() {
|
|
2594
1774
|
return !this._closed;
|
|
2595
1775
|
}
|
|
2596
1776
|
async open() {
|
|
2597
|
-
log8("opening...", void 0, {
|
|
2598
|
-
F: __dxlog_file9,
|
|
2599
|
-
L: 74,
|
|
2600
|
-
S: this,
|
|
2601
|
-
C: (f, a) => f(...a)
|
|
2602
|
-
});
|
|
1777
|
+
log8("opening...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 59, S: this });
|
|
2603
1778
|
if (this._options.initiator) {
|
|
2604
|
-
log8("sending signal", void 0, {
|
|
2605
|
-
F: __dxlog_file9,
|
|
2606
|
-
L: 78,
|
|
2607
|
-
S: this,
|
|
2608
|
-
C: (f, a) => f(...a)
|
|
2609
|
-
});
|
|
1779
|
+
log8("sending signal", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 62, S: this });
|
|
2610
1780
|
try {
|
|
2611
1781
|
await this._options.sendSignal({
|
|
2612
1782
|
payload: {
|
|
@@ -2632,23 +1802,10 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2632
1802
|
this.closed.emit();
|
|
2633
1803
|
return;
|
|
2634
1804
|
}
|
|
2635
|
-
invariant8(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2636
|
-
F: __dxlog_file9,
|
|
2637
|
-
L: 104,
|
|
2638
|
-
S: this,
|
|
2639
|
-
A: [
|
|
2640
|
-
"!this._remoteConnection._remoteConnection",
|
|
2641
|
-
"`Remote already connected: ${this._remoteInstanceId}`"
|
|
2642
|
-
]
|
|
2643
|
-
});
|
|
1805
|
+
invariant8(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 90, S: this, A: ["!this._remoteConnection._remoteConnection", "`Remote already connected: ${this._remoteInstanceId}`"] });
|
|
2644
1806
|
this._remoteConnection._remoteConnection = this;
|
|
2645
1807
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
2646
|
-
log8("connected", void 0, {
|
|
2647
|
-
F: __dxlog_file9,
|
|
2648
|
-
L: 108,
|
|
2649
|
-
S: this,
|
|
2650
|
-
C: (f, a) => f(...a)
|
|
2651
|
-
});
|
|
1808
|
+
log8("connected", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 93, S: this });
|
|
2652
1809
|
this._options.stream.pipe(this._outgoingDelay).pipe(this._remoteConnection._options.stream).pipe(this._incomingDelay).pipe(this._options.stream);
|
|
2653
1810
|
this.connected.emit();
|
|
2654
1811
|
this._remoteConnection.connected.emit();
|
|
@@ -2662,12 +1819,7 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2662
1819
|
return this;
|
|
2663
1820
|
}
|
|
2664
1821
|
async close() {
|
|
2665
|
-
log8("closing...", void 0, {
|
|
2666
|
-
F: __dxlog_file9,
|
|
2667
|
-
L: 130,
|
|
2668
|
-
S: this,
|
|
2669
|
-
C: (f, a) => f(...a)
|
|
2670
|
-
});
|
|
1822
|
+
log8("closing...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 107, S: this });
|
|
2671
1823
|
this._closed = true;
|
|
2672
1824
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
2673
1825
|
if (this._remoteConnection) {
|
|
@@ -2683,29 +1835,19 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2683
1835
|
this._remoteConnection = void 0;
|
|
2684
1836
|
}
|
|
2685
1837
|
this.closed.emit();
|
|
2686
|
-
log8("closed", void 0, {
|
|
2687
|
-
F: __dxlog_file9,
|
|
2688
|
-
L: 158,
|
|
2689
|
-
S: this,
|
|
2690
|
-
C: (f, a) => f(...a)
|
|
2691
|
-
});
|
|
1838
|
+
log8("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 130, S: this });
|
|
2692
1839
|
return this;
|
|
2693
1840
|
}
|
|
2694
1841
|
async onSignal({ payload }) {
|
|
2695
1842
|
log8("received signal", {
|
|
2696
1843
|
payload
|
|
2697
|
-
}, {
|
|
2698
|
-
F: __dxlog_file9,
|
|
2699
|
-
L: 163,
|
|
2700
|
-
S: this,
|
|
2701
|
-
C: (f, a) => f(...a)
|
|
2702
|
-
});
|
|
1844
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 134, S: this });
|
|
2703
1845
|
if (!payload?.transportId) {
|
|
2704
1846
|
return;
|
|
2705
1847
|
}
|
|
2706
1848
|
const transportId = payload.transportId;
|
|
2707
1849
|
if (transportId) {
|
|
2708
|
-
const remoteId =
|
|
1850
|
+
const remoteId = PublicKey8.fromHex(transportId);
|
|
2709
1851
|
this._remote.wake(remoteId);
|
|
2710
1852
|
}
|
|
2711
1853
|
}
|
|
@@ -2788,7 +1930,7 @@ import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } f
|
|
|
2788
1930
|
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2789
1931
|
import { log as log10, logInfo as logInfo4 } from "@dxos/log";
|
|
2790
1932
|
import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
|
|
2791
|
-
import { trace
|
|
1933
|
+
import { trace } from "@dxos/tracing";
|
|
2792
1934
|
|
|
2793
1935
|
// src/transport/webrtc/rtc-transport-channel.ts
|
|
2794
1936
|
import { Duplex } from "node:stream";
|
|
@@ -2872,15 +2014,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2872
2014
|
}
|
|
2873
2015
|
}
|
|
2874
2016
|
async _open() {
|
|
2875
|
-
invariant9(!this._isChannelCreationInProgress, void 0, {
|
|
2876
|
-
F: __dxlog_file10,
|
|
2877
|
-
L: 56,
|
|
2878
|
-
S: this,
|
|
2879
|
-
A: [
|
|
2880
|
-
"!this._isChannelCreationInProgress",
|
|
2881
|
-
""
|
|
2882
|
-
]
|
|
2883
|
-
});
|
|
2017
|
+
invariant9(!this._isChannelCreationInProgress, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 41, S: this, A: ["!this._isChannelCreationInProgress", ""] });
|
|
2884
2018
|
this._isChannelCreationInProgress = true;
|
|
2885
2019
|
this._connection.createDataChannel(this._options.topic).then((channel) => {
|
|
2886
2020
|
if (this.isOpen) {
|
|
@@ -2898,12 +2032,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2898
2032
|
} else {
|
|
2899
2033
|
log9.verbose("connection establishment failed after transport was closed", {
|
|
2900
2034
|
err
|
|
2901
|
-
}, {
|
|
2902
|
-
F: __dxlog_file10,
|
|
2903
|
-
L: 76,
|
|
2904
|
-
S: this,
|
|
2905
|
-
C: (f, a) => f(...a)
|
|
2906
|
-
});
|
|
2035
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 57, S: this });
|
|
2907
2036
|
}
|
|
2908
2037
|
}).finally(() => {
|
|
2909
2038
|
this._isChannelCreationInProgress = false;
|
|
@@ -2916,12 +2045,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2916
2045
|
this._stream = void 0;
|
|
2917
2046
|
}
|
|
2918
2047
|
this.closed.emit();
|
|
2919
|
-
log9("closed", void 0, {
|
|
2920
|
-
F: __dxlog_file10,
|
|
2921
|
-
L: 92,
|
|
2922
|
-
S: this,
|
|
2923
|
-
C: (f, a) => f(...a)
|
|
2924
|
-
});
|
|
2048
|
+
log9("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 72, S: this });
|
|
2925
2049
|
}
|
|
2926
2050
|
_initChannel(channel) {
|
|
2927
2051
|
Object.assign(channel, {
|
|
@@ -2929,21 +2053,11 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2929
2053
|
if (!this.isOpen) {
|
|
2930
2054
|
log9.warn("channel opened in a closed transport", {
|
|
2931
2055
|
topic: this._options.topic
|
|
2932
|
-
}, {
|
|
2933
|
-
F: __dxlog_file10,
|
|
2934
|
-
L: 99,
|
|
2935
|
-
S: this,
|
|
2936
|
-
C: (f, a) => f(...a)
|
|
2937
|
-
});
|
|
2056
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 78, S: this });
|
|
2938
2057
|
this._safeCloseChannel(channel);
|
|
2939
2058
|
return;
|
|
2940
2059
|
}
|
|
2941
|
-
log9("onopen", void 0, {
|
|
2942
|
-
F: __dxlog_file10,
|
|
2943
|
-
L: 104,
|
|
2944
|
-
S: this,
|
|
2945
|
-
C: (f, a) => f(...a)
|
|
2946
|
-
});
|
|
2060
|
+
log9("onopen", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 84, S: this });
|
|
2947
2061
|
const duplex = new Duplex({
|
|
2948
2062
|
read: () => {
|
|
2949
2063
|
},
|
|
@@ -2956,22 +2070,12 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2956
2070
|
this.connected.emit();
|
|
2957
2071
|
},
|
|
2958
2072
|
onclose: async () => {
|
|
2959
|
-
log9("onclose", void 0, {
|
|
2960
|
-
F: __dxlog_file10,
|
|
2961
|
-
L: 117,
|
|
2962
|
-
S: this,
|
|
2963
|
-
C: (f, a) => f(...a)
|
|
2964
|
-
});
|
|
2073
|
+
log9("onclose", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 96, S: this });
|
|
2965
2074
|
await this.close();
|
|
2966
2075
|
},
|
|
2967
2076
|
onmessage: async (event) => {
|
|
2968
2077
|
if (!this._stream) {
|
|
2969
|
-
log9.warn("ignoring message on a closed channel", void 0, {
|
|
2970
|
-
F: __dxlog_file10,
|
|
2971
|
-
L: 123,
|
|
2972
|
-
S: this,
|
|
2973
|
-
C: (f, a) => f(...a)
|
|
2974
|
-
});
|
|
2078
|
+
log9.warn("ignoring message on a closed channel", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 101, S: this });
|
|
2975
2079
|
return;
|
|
2976
2080
|
}
|
|
2977
2081
|
let data = event.data;
|
|
@@ -2997,12 +2101,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2997
2101
|
}
|
|
2998
2102
|
async _handleChannelWrite(chunk, callback) {
|
|
2999
2103
|
if (!this._channel) {
|
|
3000
|
-
log9.warn("writing to a channel after a connection was closed", void 0, {
|
|
3001
|
-
F: __dxlog_file10,
|
|
3002
|
-
L: 153,
|
|
3003
|
-
S: this,
|
|
3004
|
-
C: (f, a) => f(...a)
|
|
3005
|
-
});
|
|
2104
|
+
log9.warn("writing to a channel after a connection was closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 127, S: this });
|
|
3006
2105
|
return;
|
|
3007
2106
|
}
|
|
3008
2107
|
if (chunk.length > MAX_MESSAGE_SIZE) {
|
|
@@ -3020,12 +2119,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3020
2119
|
}
|
|
3021
2120
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3022
2121
|
if (this._streamDataFlushedCallback !== null) {
|
|
3023
|
-
log9.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3024
|
-
F: __dxlog_file10,
|
|
3025
|
-
L: 174,
|
|
3026
|
-
S: this,
|
|
3027
|
-
C: (f, a) => f(...a)
|
|
3028
|
-
});
|
|
2122
|
+
log9.error("consumer trying to write before we are ready for more data", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 145, S: this });
|
|
3029
2123
|
}
|
|
3030
2124
|
this._streamDataFlushedCallback = callback;
|
|
3031
2125
|
} else {
|
|
@@ -3036,12 +2130,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3036
2130
|
try {
|
|
3037
2131
|
channel.close();
|
|
3038
2132
|
} catch (error) {
|
|
3039
|
-
log9.catch(error, void 0, {
|
|
3040
|
-
F: __dxlog_file10,
|
|
3041
|
-
L: 186,
|
|
3042
|
-
S: this,
|
|
3043
|
-
C: (f, a) => f(...a)
|
|
3044
|
-
});
|
|
2133
|
+
log9.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 156, S: this });
|
|
3045
2134
|
}
|
|
3046
2135
|
}
|
|
3047
2136
|
onSignal(signal) {
|
|
@@ -3082,13 +2171,13 @@ var deduplicatedSdpLines = (sdp) => {
|
|
|
3082
2171
|
};
|
|
3083
2172
|
|
|
3084
2173
|
// src/transport/webrtc/rtc-peer-connection.ts
|
|
2174
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
|
|
3085
2175
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
3086
2176
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3087
2177
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3088
2178
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3089
2179
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3090
2180
|
}
|
|
3091
|
-
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
|
|
3092
2181
|
var RtcPeerConnection = class {
|
|
3093
2182
|
_factory;
|
|
3094
2183
|
_options;
|
|
@@ -3136,12 +2225,7 @@ var RtcPeerConnection = class {
|
|
|
3136
2225
|
if (existingChannel) {
|
|
3137
2226
|
return existingChannel;
|
|
3138
2227
|
}
|
|
3139
|
-
log10("waiting for initiator-peer to open a data channel", void 0, {
|
|
3140
|
-
F: __dxlog_file11,
|
|
3141
|
-
L: 95,
|
|
3142
|
-
S: this,
|
|
3143
|
-
C: (f, a) => f(...a)
|
|
3144
|
-
});
|
|
2228
|
+
log10("waiting for initiator-peer to open a data channel", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 63, S: this });
|
|
3145
2229
|
return new Promise((resolve, reject) => {
|
|
3146
2230
|
this._channelCreatedCallbacks.set(topic, {
|
|
3147
2231
|
resolve,
|
|
@@ -3167,36 +2251,18 @@ var RtcPeerConnection = class {
|
|
|
3167
2251
|
}
|
|
3168
2252
|
log10("initializing connection...", () => ({
|
|
3169
2253
|
remotePeer: this._options.remotePeerKey
|
|
3170
|
-
}), {
|
|
3171
|
-
F: __dxlog_file11,
|
|
3172
|
-
L: 120,
|
|
3173
|
-
S: this,
|
|
3174
|
-
C: (f, a) => f(...a)
|
|
3175
|
-
});
|
|
2254
|
+
}), { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 87, S: this });
|
|
3176
2255
|
const config = await this._loadConnectionConfig();
|
|
3177
2256
|
const connection = await this._factory.createConnection(config);
|
|
3178
2257
|
const iceCandidateErrors = [];
|
|
3179
2258
|
Object.assign(connection, {
|
|
3180
2259
|
onnegotiationneeded: async () => {
|
|
3181
|
-
invariant10(this._initiator, void 0, {
|
|
3182
|
-
F: __dxlog_file11,
|
|
3183
|
-
L: 135,
|
|
3184
|
-
S: this,
|
|
3185
|
-
A: [
|
|
3186
|
-
"this._initiator",
|
|
3187
|
-
""
|
|
3188
|
-
]
|
|
3189
|
-
});
|
|
2260
|
+
invariant10(this._initiator, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 100, S: this, A: ["this._initiator", ""] });
|
|
3190
2261
|
if (connection !== this._connection) {
|
|
3191
2262
|
this._onConnectionCallbackAfterClose("onnegotiationneeded", connection);
|
|
3192
2263
|
return;
|
|
3193
2264
|
}
|
|
3194
|
-
log10("onnegotiationneeded", void 0, {
|
|
3195
|
-
F: __dxlog_file11,
|
|
3196
|
-
L: 142,
|
|
3197
|
-
S: this,
|
|
3198
|
-
C: (f, a) => f(...a)
|
|
3199
|
-
});
|
|
2265
|
+
log10("onnegotiationneeded", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 105, S: this });
|
|
3200
2266
|
try {
|
|
3201
2267
|
const offer = await connection.createOffer();
|
|
3202
2268
|
await connection.setLocalDescription(offer);
|
|
@@ -3215,20 +2281,10 @@ var RtcPeerConnection = class {
|
|
|
3215
2281
|
if (event.candidate) {
|
|
3216
2282
|
log10("onicecandidate", {
|
|
3217
2283
|
candidate: event.candidate.candidate
|
|
3218
|
-
}, {
|
|
3219
|
-
F: __dxlog_file11,
|
|
3220
|
-
L: 161,
|
|
3221
|
-
S: this,
|
|
3222
|
-
C: (f, a) => f(...a)
|
|
3223
|
-
});
|
|
2284
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 122, S: this });
|
|
3224
2285
|
await this._sendIceCandidate(event.candidate);
|
|
3225
2286
|
} else {
|
|
3226
|
-
log10("onicecandidate gathering complete", void 0, {
|
|
3227
|
-
F: __dxlog_file11,
|
|
3228
|
-
L: 164,
|
|
3229
|
-
S: this,
|
|
3230
|
-
C: (f, a) => f(...a)
|
|
3231
|
-
});
|
|
2287
|
+
log10("onicecandidate gathering complete", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 127, S: this });
|
|
3232
2288
|
}
|
|
3233
2289
|
},
|
|
3234
2290
|
// When error occurs while performing ICE negotiations through a STUN or TURN server.
|
|
@@ -3251,12 +2307,7 @@ var RtcPeerConnection = class {
|
|
|
3251
2307
|
}
|
|
3252
2308
|
log10("oniceconnectionstatechange", {
|
|
3253
2309
|
state: connection.iceConnectionState
|
|
3254
|
-
}, {
|
|
3255
|
-
F: __dxlog_file11,
|
|
3256
|
-
L: 184,
|
|
3257
|
-
S: this,
|
|
3258
|
-
C: (f, a) => f(...a)
|
|
3259
|
-
});
|
|
2310
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 148, S: this });
|
|
3260
2311
|
if (connection.iceConnectionState === "failed") {
|
|
3261
2312
|
void this._lockAndAbort(connection, createIceFailureError(iceCandidateErrors));
|
|
3262
2313
|
}
|
|
@@ -3273,12 +2324,7 @@ var RtcPeerConnection = class {
|
|
|
3273
2324
|
}
|
|
3274
2325
|
log10("onconnectionstatechange", {
|
|
3275
2326
|
state: connection.connectionState
|
|
3276
|
-
}, {
|
|
3277
|
-
F: __dxlog_file11,
|
|
3278
|
-
L: 201,
|
|
3279
|
-
S: this,
|
|
3280
|
-
C: (f, a) => f(...a)
|
|
3281
|
-
});
|
|
2327
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 165, S: this });
|
|
3282
2328
|
if (connection.connectionState === "failed") {
|
|
3283
2329
|
void this._lockAndAbort(connection, new Error("Connection failed."));
|
|
3284
2330
|
}
|
|
@@ -3286,37 +2332,19 @@ var RtcPeerConnection = class {
|
|
|
3286
2332
|
onsignalingstatechange: () => {
|
|
3287
2333
|
log10("onsignalingstatechange", {
|
|
3288
2334
|
state: connection.signalingState
|
|
3289
|
-
}, {
|
|
3290
|
-
F: __dxlog_file11,
|
|
3291
|
-
L: 208,
|
|
3292
|
-
S: this,
|
|
3293
|
-
C: (f, a) => f(...a)
|
|
3294
|
-
});
|
|
2335
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 173, S: this });
|
|
3295
2336
|
},
|
|
3296
2337
|
// When channel is added to connection.
|
|
3297
2338
|
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event
|
|
3298
2339
|
ondatachannel: (event) => {
|
|
3299
|
-
invariant10(!this._initiator, "Initiator is expected to create data channels.", {
|
|
3300
|
-
F: __dxlog_file11,
|
|
3301
|
-
L: 214,
|
|
3302
|
-
S: this,
|
|
3303
|
-
A: [
|
|
3304
|
-
"!this._initiator",
|
|
3305
|
-
"'Initiator is expected to create data channels.'"
|
|
3306
|
-
]
|
|
3307
|
-
});
|
|
2340
|
+
invariant10(!this._initiator, "Initiator is expected to create data channels.", { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 180, S: this, A: ["!this._initiator", "'Initiator is expected to create data channels.'"] });
|
|
3308
2341
|
if (connection !== this._connection) {
|
|
3309
2342
|
this._onConnectionCallbackAfterClose("ondatachannel", connection);
|
|
3310
2343
|
return;
|
|
3311
2344
|
}
|
|
3312
2345
|
log10("ondatachannel", {
|
|
3313
2346
|
label: event.channel.label
|
|
3314
|
-
}, {
|
|
3315
|
-
F: __dxlog_file11,
|
|
3316
|
-
L: 221,
|
|
3317
|
-
S: this,
|
|
3318
|
-
C: (f, a) => f(...a)
|
|
3319
|
-
});
|
|
2347
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 185, S: this });
|
|
3320
2348
|
this._dataChannels.set(event.channel.label, event.channel);
|
|
3321
2349
|
const pendingCallback = this._channelCreatedCallbacks.get(event.channel.label);
|
|
3322
2350
|
if (pendingCallback) {
|
|
@@ -3339,12 +2367,7 @@ var RtcPeerConnection = class {
|
|
|
3339
2367
|
if (connection !== this._connection) {
|
|
3340
2368
|
log10.error("attempted to abort an inactive connection", {
|
|
3341
2369
|
error
|
|
3342
|
-
}, {
|
|
3343
|
-
F: __dxlog_file11,
|
|
3344
|
-
L: 246,
|
|
3345
|
-
S: this,
|
|
3346
|
-
C: (f, a) => f(...a)
|
|
3347
|
-
});
|
|
2370
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 208, S: this });
|
|
3348
2371
|
this._safeCloseConnection(connection);
|
|
3349
2372
|
return;
|
|
3350
2373
|
}
|
|
@@ -3360,31 +2383,13 @@ var RtcPeerConnection = class {
|
|
|
3360
2383
|
this._safeCloseConnection();
|
|
3361
2384
|
log10("connection aborted", {
|
|
3362
2385
|
reason: error.message
|
|
3363
|
-
}, {
|
|
3364
|
-
F: __dxlog_file11,
|
|
3365
|
-
L: 260,
|
|
3366
|
-
S: this,
|
|
3367
|
-
C: (f, a) => f(...a)
|
|
3368
|
-
});
|
|
2386
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 224, S: this });
|
|
3369
2387
|
}
|
|
3370
2388
|
async _lockAndCloseConnection() {
|
|
3371
|
-
invariant10(this._transportChannels.size === 0, void 0, {
|
|
3372
|
-
F: __dxlog_file11,
|
|
3373
|
-
L: 265,
|
|
3374
|
-
S: this,
|
|
3375
|
-
A: [
|
|
3376
|
-
"this._transportChannels.size === 0",
|
|
3377
|
-
""
|
|
3378
|
-
]
|
|
3379
|
-
});
|
|
2389
|
+
invariant10(this._transportChannels.size === 0, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 229, S: this, A: ["this._transportChannels.size === 0", ""] });
|
|
3380
2390
|
if (this._connection) {
|
|
3381
2391
|
this._safeCloseConnection();
|
|
3382
|
-
log10("connection closed", void 0, {
|
|
3383
|
-
F: __dxlog_file11,
|
|
3384
|
-
L: 268,
|
|
3385
|
-
S: this,
|
|
3386
|
-
C: (f, a) => f(...a)
|
|
3387
|
-
});
|
|
2392
|
+
log10("connection closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 232, S: this });
|
|
3388
2393
|
}
|
|
3389
2394
|
}
|
|
3390
2395
|
async onSignal(signal) {
|
|
@@ -3392,12 +2397,7 @@ var RtcPeerConnection = class {
|
|
|
3392
2397
|
if (!connection) {
|
|
3393
2398
|
log10.warn("a signal ignored because the connection was closed", {
|
|
3394
2399
|
type: signal.payload.data.type
|
|
3395
|
-
}, {
|
|
3396
|
-
F: __dxlog_file11,
|
|
3397
|
-
L: 276,
|
|
3398
|
-
S: this,
|
|
3399
|
-
C: (f, a) => f(...a)
|
|
3400
|
-
});
|
|
2400
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 238, S: this });
|
|
3401
2401
|
return;
|
|
3402
2402
|
}
|
|
3403
2403
|
const data = signal.payload.data;
|
|
@@ -3459,12 +2459,7 @@ var RtcPeerConnection = class {
|
|
|
3459
2459
|
}
|
|
3460
2460
|
log10("signal processed", {
|
|
3461
2461
|
type: data.type
|
|
3462
|
-
}, {
|
|
3463
|
-
F: __dxlog_file11,
|
|
3464
|
-
L: 335,
|
|
3465
|
-
S: this,
|
|
3466
|
-
C: (f, a) => f(...a)
|
|
3467
|
-
});
|
|
2462
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 301, S: this });
|
|
3468
2463
|
}
|
|
3469
2464
|
async _processIceCandidate(connection, candidate) {
|
|
3470
2465
|
try {
|
|
@@ -3472,51 +2467,26 @@ var RtcPeerConnection = class {
|
|
|
3472
2467
|
if (connection === this._connection) {
|
|
3473
2468
|
log10("adding ice candidate", {
|
|
3474
2469
|
candidate
|
|
3475
|
-
}, {
|
|
3476
|
-
F: __dxlog_file11,
|
|
3477
|
-
L: 343,
|
|
3478
|
-
S: this,
|
|
3479
|
-
C: (f, a) => f(...a)
|
|
3480
|
-
});
|
|
2470
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 310, S: this });
|
|
3481
2471
|
await connection.addIceCandidate(candidate);
|
|
3482
2472
|
}
|
|
3483
2473
|
} catch (err) {
|
|
3484
|
-
log10.catch(err, void 0, {
|
|
3485
|
-
F: __dxlog_file11,
|
|
3486
|
-
L: 347,
|
|
3487
|
-
S: this,
|
|
3488
|
-
C: (f, a) => f(...a)
|
|
3489
|
-
});
|
|
2474
|
+
log10.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 316, S: this });
|
|
3490
2475
|
}
|
|
3491
2476
|
}
|
|
3492
2477
|
_onSessionNegotiated(connection) {
|
|
3493
2478
|
if (connection === this._connection) {
|
|
3494
|
-
log10("ready to process ice candidates", void 0, {
|
|
3495
|
-
F: __dxlog_file11,
|
|
3496
|
-
L: 353,
|
|
3497
|
-
S: this,
|
|
3498
|
-
C: (f, a) => f(...a)
|
|
3499
|
-
});
|
|
2479
|
+
log10("ready to process ice candidates", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 321, S: this });
|
|
3500
2480
|
this._readyForCandidates.wake();
|
|
3501
2481
|
} else {
|
|
3502
|
-
log10.warn("session was negotiated after connection became inactive", void 0, {
|
|
3503
|
-
F: __dxlog_file11,
|
|
3504
|
-
L: 356,
|
|
3505
|
-
S: this,
|
|
3506
|
-
C: (f, a) => f(...a)
|
|
3507
|
-
});
|
|
2482
|
+
log10.warn("session was negotiated after connection became inactive", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 324, S: this });
|
|
3508
2483
|
}
|
|
3509
2484
|
}
|
|
3510
2485
|
_onConnectionCallbackAfterClose(callback, connection) {
|
|
3511
2486
|
log10.warn("callback invoked after a connection was destroyed, this is probably a bug", {
|
|
3512
2487
|
callback,
|
|
3513
2488
|
state: connection.connectionState
|
|
3514
|
-
}, {
|
|
3515
|
-
F: __dxlog_file11,
|
|
3516
|
-
L: 361,
|
|
3517
|
-
S: this,
|
|
3518
|
-
C: (f, a) => f(...a)
|
|
3519
|
-
});
|
|
2489
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 328, S: this });
|
|
3520
2490
|
this._safeCloseConnection(connection);
|
|
3521
2491
|
}
|
|
3522
2492
|
_safeCloseConnection(connection = this._connection) {
|
|
@@ -3524,23 +2494,13 @@ var RtcPeerConnection = class {
|
|
|
3524
2494
|
try {
|
|
3525
2495
|
connection?.close();
|
|
3526
2496
|
} catch (err) {
|
|
3527
|
-
log10.catch(err, void 0, {
|
|
3528
|
-
F: __dxlog_file11,
|
|
3529
|
-
L: 373,
|
|
3530
|
-
S: this,
|
|
3531
|
-
C: (f, a) => f(...a)
|
|
3532
|
-
});
|
|
2497
|
+
log10.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 339, S: this });
|
|
3533
2498
|
}
|
|
3534
2499
|
if (resetFields) {
|
|
3535
2500
|
this._connection = void 0;
|
|
3536
2501
|
this._dataChannels.clear();
|
|
3537
2502
|
this._readyForCandidates.wake();
|
|
3538
|
-
void this._factory.onConnectionDestroyed().catch((err) => log10.catch(err, void 0, {
|
|
3539
|
-
F: __dxlog_file11,
|
|
3540
|
-
L: 379,
|
|
3541
|
-
S: this,
|
|
3542
|
-
C: (f, a) => f(...a)
|
|
3543
|
-
}));
|
|
2503
|
+
void this._factory.onConnectionDestroyed().catch((err) => log10.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 345, S: this }));
|
|
3544
2504
|
for (const [_, pendingCallback] of this._channelCreatedCallbacks.entries()) {
|
|
3545
2505
|
pendingCallback.reject("Connection closed.");
|
|
3546
2506
|
}
|
|
@@ -3560,12 +2520,7 @@ var RtcPeerConnection = class {
|
|
|
3560
2520
|
];
|
|
3561
2521
|
}
|
|
3562
2522
|
} catch (error) {
|
|
3563
|
-
log10.catch(error, void 0, {
|
|
3564
|
-
F: __dxlog_file11,
|
|
3565
|
-
L: 395,
|
|
3566
|
-
S: this,
|
|
3567
|
-
C: (f, a) => f(...a)
|
|
3568
|
-
});
|
|
2523
|
+
log10.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 365, S: this });
|
|
3569
2524
|
}
|
|
3570
2525
|
return config;
|
|
3571
2526
|
}
|
|
@@ -3587,12 +2542,7 @@ var RtcPeerConnection = class {
|
|
|
3587
2542
|
} catch (err) {
|
|
3588
2543
|
log10.warn("signaling error", {
|
|
3589
2544
|
err
|
|
3590
|
-
}, {
|
|
3591
|
-
F: __dxlog_file11,
|
|
3592
|
-
L: 416,
|
|
3593
|
-
S: this,
|
|
3594
|
-
C: (f, a) => f(...a)
|
|
3595
|
-
});
|
|
2545
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 385, S: this });
|
|
3596
2546
|
}
|
|
3597
2547
|
}
|
|
3598
2548
|
async _sendDescription(connection, description) {
|
|
@@ -3650,13 +2600,13 @@ _ts_decorate6([
|
|
|
3650
2600
|
synchronized5
|
|
3651
2601
|
], RtcPeerConnection.prototype, "onSignal", null);
|
|
3652
2602
|
_ts_decorate6([
|
|
3653
|
-
|
|
2603
|
+
trace.info()
|
|
3654
2604
|
], RtcPeerConnection.prototype, "_connectionInfo", null);
|
|
3655
2605
|
_ts_decorate6([
|
|
3656
2606
|
logInfo4
|
|
3657
2607
|
], RtcPeerConnection.prototype, "_loggerContext", null);
|
|
3658
2608
|
RtcPeerConnection = _ts_decorate6([
|
|
3659
|
-
|
|
2609
|
+
trace.resource()
|
|
3660
2610
|
], RtcPeerConnection);
|
|
3661
2611
|
var isRemoteDescriptionSet = (connection, data) => {
|
|
3662
2612
|
if (!connection.remoteDescription?.type || connection.remoteDescription?.type !== data.type) {
|
|
@@ -3696,7 +2646,7 @@ import { Event as Event8, scheduleTask as scheduleTask4 } from "@dxos/async";
|
|
|
3696
2646
|
import { Resource as Resource2 } from "@dxos/context";
|
|
3697
2647
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
3698
2648
|
import { invariant as invariant11 } from "@dxos/invariant";
|
|
3699
|
-
import { PublicKey as
|
|
2649
|
+
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
3700
2650
|
import { log as log11 } from "@dxos/log";
|
|
3701
2651
|
import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError4, TimeoutError as TimeoutError3 } from "@dxos/protocols";
|
|
3702
2652
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
@@ -3707,7 +2657,7 @@ var CLOSE_RPC_TIMEOUT = 3e3;
|
|
|
3707
2657
|
var RESP_MIN_THRESHOLD = 500;
|
|
3708
2658
|
var RtcTransportProxy = class extends Resource2 {
|
|
3709
2659
|
_options;
|
|
3710
|
-
_proxyId =
|
|
2660
|
+
_proxyId = PublicKey9.random();
|
|
3711
2661
|
closed = new Event8();
|
|
3712
2662
|
connected = new Event8();
|
|
3713
2663
|
errors = new ErrorStream5();
|
|
@@ -3734,12 +2684,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3734
2684
|
this._serviceStream = stream;
|
|
3735
2685
|
stream.waitUntilReady().then(() => {
|
|
3736
2686
|
stream.subscribe(async (event) => {
|
|
3737
|
-
log11("rtc transport proxy event", event, {
|
|
3738
|
-
F: __dxlog_file12,
|
|
3739
|
-
L: 66,
|
|
3740
|
-
S: this,
|
|
3741
|
-
C: (f, a) => f(...a)
|
|
3742
|
-
});
|
|
2687
|
+
log11("rtc transport proxy event", event, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 46, S: this });
|
|
3743
2688
|
if (event.connection) {
|
|
3744
2689
|
await this._handleConnection(event.connection);
|
|
3745
2690
|
} else if (event.data) {
|
|
@@ -3750,12 +2695,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3750
2695
|
}, (err) => {
|
|
3751
2696
|
log11("rtc bridge stream closed", {
|
|
3752
2697
|
err
|
|
3753
|
-
}, {
|
|
3754
|
-
F: __dxlog_file12,
|
|
3755
|
-
L: 76,
|
|
3756
|
-
S: this,
|
|
3757
|
-
C: (f, a) => f(...a)
|
|
3758
|
-
});
|
|
2698
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 55, S: this });
|
|
3759
2699
|
if (err) {
|
|
3760
2700
|
this._raiseIfOpen(err);
|
|
3761
2701
|
} else {
|
|
@@ -3772,12 +2712,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3772
2712
|
timeout: RPC_TIMEOUT
|
|
3773
2713
|
}).then(() => {
|
|
3774
2714
|
if (Date.now() - sendStartMs > RESP_MIN_THRESHOLD) {
|
|
3775
|
-
log11("slow response, delaying callback", void 0, {
|
|
3776
|
-
F: __dxlog_file12,
|
|
3777
|
-
L: 93,
|
|
3778
|
-
S: this,
|
|
3779
|
-
C: (f, a) => f(...a)
|
|
3780
|
-
});
|
|
2715
|
+
log11("slow response, delaying callback", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 74, S: this });
|
|
3781
2716
|
scheduleTask4(this._ctx, () => callback(), RESP_MIN_THRESHOLD);
|
|
3782
2717
|
} else {
|
|
3783
2718
|
callback();
|
|
@@ -3805,12 +2740,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3805
2740
|
await this._serviceStream?.close();
|
|
3806
2741
|
this._serviceStream = void 0;
|
|
3807
2742
|
} catch (err) {
|
|
3808
|
-
log11.catch(err, void 0, {
|
|
3809
|
-
F: __dxlog_file12,
|
|
3810
|
-
L: 128,
|
|
3811
|
-
S: this,
|
|
3812
|
-
C: (f, a) => f(...a)
|
|
3813
|
-
});
|
|
2743
|
+
log11.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 102, S: this });
|
|
3814
2744
|
}
|
|
3815
2745
|
try {
|
|
3816
2746
|
await this._options.bridgeService.close({
|
|
@@ -3819,12 +2749,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3819
2749
|
timeout: CLOSE_RPC_TIMEOUT
|
|
3820
2750
|
});
|
|
3821
2751
|
} catch (err) {
|
|
3822
|
-
log11.catch(err, void 0, {
|
|
3823
|
-
F: __dxlog_file12,
|
|
3824
|
-
L: 134,
|
|
3825
|
-
S: this,
|
|
3826
|
-
C: (f, a) => f(...a)
|
|
3827
|
-
});
|
|
2752
|
+
log11.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 111, S: this });
|
|
3828
2753
|
}
|
|
3829
2754
|
this.closed.emit();
|
|
3830
2755
|
}
|
|
@@ -3907,12 +2832,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3907
2832
|
} else {
|
|
3908
2833
|
log11.info("error swallowed because transport was closed", {
|
|
3909
2834
|
message: error.message
|
|
3910
|
-
}, {
|
|
3911
|
-
F: __dxlog_file12,
|
|
3912
|
-
L: 217,
|
|
3913
|
-
S: this,
|
|
3914
|
-
C: (f, a) => f(...a)
|
|
3915
|
-
});
|
|
2835
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 195, S: this });
|
|
3916
2836
|
}
|
|
3917
2837
|
}
|
|
3918
2838
|
/**
|
|
@@ -3938,15 +2858,7 @@ var RtcTransportProxyFactory = class {
|
|
|
3938
2858
|
return this;
|
|
3939
2859
|
}
|
|
3940
2860
|
createTransport(options) {
|
|
3941
|
-
invariant11(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
|
|
3942
|
-
F: __dxlog_file12,
|
|
3943
|
-
L: 247,
|
|
3944
|
-
S: this,
|
|
3945
|
-
A: [
|
|
3946
|
-
"this._bridgeService",
|
|
3947
|
-
"'RtcTransportProxyFactory is not ready to open connections'"
|
|
3948
|
-
]
|
|
3949
|
-
});
|
|
2861
|
+
invariant11(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 221, S: this, A: ["this._bridgeService", "'RtcTransportProxyFactory is not ready to open connections'"] });
|
|
3950
2862
|
const transport = new RtcTransportProxy({
|
|
3951
2863
|
...options,
|
|
3952
2864
|
bridgeService: this._bridgeService
|
|
@@ -3981,14 +2893,14 @@ var decodeError = (err) => {
|
|
|
3981
2893
|
import { Duplex as Duplex2 } from "node:stream";
|
|
3982
2894
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
3983
2895
|
import { invariant as invariant12 } from "@dxos/invariant";
|
|
3984
|
-
import { PublicKey as
|
|
2896
|
+
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
3985
2897
|
import { log as log12 } from "@dxos/log";
|
|
3986
2898
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
3987
2899
|
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
3988
2900
|
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
|
|
3989
2901
|
var RtcTransportService = class {
|
|
3990
2902
|
_transportFactory;
|
|
3991
|
-
_openTransports = new ComplexMap8(
|
|
2903
|
+
_openTransports = new ComplexMap8(PublicKey10.hash);
|
|
3992
2904
|
constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
|
|
3993
2905
|
this._transportFactory = _transportFactory;
|
|
3994
2906
|
}
|
|
@@ -3998,12 +2910,7 @@ var RtcTransportService = class {
|
|
|
3998
2910
|
open(request) {
|
|
3999
2911
|
const existingTransport = this._openTransports.get(request.proxyId);
|
|
4000
2912
|
if (existingTransport) {
|
|
4001
|
-
log12.error("requesting a new transport bridge for an existing proxy", void 0, {
|
|
4002
|
-
F: __dxlog_file13,
|
|
4003
|
-
L: 53,
|
|
4004
|
-
S: this,
|
|
4005
|
-
C: (f, a) => f(...a)
|
|
4006
|
-
});
|
|
2913
|
+
log12.error("requesting a new transport bridge for an existing proxy", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 24, S: this });
|
|
4007
2914
|
void this._safeCloseTransport(existingTransport);
|
|
4008
2915
|
this._openTransports.delete(request.proxyId);
|
|
4009
2916
|
}
|
|
@@ -4064,69 +2971,32 @@ var RtcTransportService = class {
|
|
|
4064
2971
|
close(err);
|
|
4065
2972
|
});
|
|
4066
2973
|
ready();
|
|
4067
|
-
log12("stream ready", void 0, {
|
|
4068
|
-
F: __dxlog_file13,
|
|
4069
|
-
L: 115,
|
|
4070
|
-
S: this,
|
|
4071
|
-
C: (f, a) => f(...a)
|
|
4072
|
-
});
|
|
2974
|
+
log12("stream ready", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 85, S: this });
|
|
4073
2975
|
pushNewState(ConnectionState4.CONNECTING);
|
|
4074
2976
|
});
|
|
4075
2977
|
}
|
|
4076
2978
|
async sendSignal({ proxyId, signal }) {
|
|
4077
2979
|
const transport = this._openTransports.get(proxyId);
|
|
4078
|
-
invariant12(transport, void 0, {
|
|
4079
|
-
F: __dxlog_file13,
|
|
4080
|
-
L: 123,
|
|
4081
|
-
S: this,
|
|
4082
|
-
A: [
|
|
4083
|
-
"transport",
|
|
4084
|
-
""
|
|
4085
|
-
]
|
|
4086
|
-
});
|
|
2980
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 91, S: this, A: ["transport", ""] });
|
|
4087
2981
|
await transport.transport.onSignal(signal);
|
|
4088
2982
|
}
|
|
4089
2983
|
async getDetails({ proxyId }) {
|
|
4090
2984
|
const transport = this._openTransports.get(proxyId);
|
|
4091
|
-
invariant12(transport, void 0, {
|
|
4092
|
-
F: __dxlog_file13,
|
|
4093
|
-
L: 130,
|
|
4094
|
-
S: this,
|
|
4095
|
-
A: [
|
|
4096
|
-
"transport",
|
|
4097
|
-
""
|
|
4098
|
-
]
|
|
4099
|
-
});
|
|
2985
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 96, S: this, A: ["transport", ""] });
|
|
4100
2986
|
return {
|
|
4101
2987
|
details: await transport.transport.getDetails()
|
|
4102
2988
|
};
|
|
4103
2989
|
}
|
|
4104
2990
|
async getStats({ proxyId }) {
|
|
4105
2991
|
const transport = this._openTransports.get(proxyId);
|
|
4106
|
-
invariant12(transport, void 0, {
|
|
4107
|
-
F: __dxlog_file13,
|
|
4108
|
-
L: 137,
|
|
4109
|
-
S: this,
|
|
4110
|
-
A: [
|
|
4111
|
-
"transport",
|
|
4112
|
-
""
|
|
4113
|
-
]
|
|
4114
|
-
});
|
|
2992
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 103, S: this, A: ["transport", ""] });
|
|
4115
2993
|
return {
|
|
4116
2994
|
stats: await transport.transport.getStats()
|
|
4117
2995
|
};
|
|
4118
2996
|
}
|
|
4119
2997
|
async sendData({ proxyId, payload }) {
|
|
4120
2998
|
const transport = this._openTransports.get(proxyId);
|
|
4121
|
-
invariant12(transport, void 0, {
|
|
4122
|
-
F: __dxlog_file13,
|
|
4123
|
-
L: 144,
|
|
4124
|
-
S: this,
|
|
4125
|
-
A: [
|
|
4126
|
-
"transport",
|
|
4127
|
-
""
|
|
4128
|
-
]
|
|
4129
|
-
});
|
|
2999
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 110, S: this, A: ["transport", ""] });
|
|
4130
3000
|
const bufferHasSpace = transport.connectorStream.push(payload);
|
|
4131
3001
|
if (!bufferHasSpace) {
|
|
4132
3002
|
await new Promise((resolve) => {
|
|
@@ -4152,31 +3022,16 @@ var RtcTransportService = class {
|
|
|
4152
3022
|
} catch (error) {
|
|
4153
3023
|
log12.warn("transport close error", {
|
|
4154
3024
|
message: error?.message
|
|
4155
|
-
}, {
|
|
4156
|
-
F: __dxlog_file13,
|
|
4157
|
-
L: 174,
|
|
4158
|
-
S: this,
|
|
4159
|
-
C: (f, a) => f(...a)
|
|
4160
|
-
});
|
|
3025
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 134, S: this });
|
|
4161
3026
|
}
|
|
4162
3027
|
try {
|
|
4163
3028
|
transport.connectorStream.end();
|
|
4164
3029
|
} catch (error) {
|
|
4165
3030
|
log12.warn("connectorStream close error", {
|
|
4166
3031
|
message: error?.message
|
|
4167
|
-
}, {
|
|
4168
|
-
F: __dxlog_file13,
|
|
4169
|
-
L: 179,
|
|
4170
|
-
S: this,
|
|
4171
|
-
C: (f, a) => f(...a)
|
|
4172
|
-
});
|
|
3032
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 141, S: this });
|
|
4173
3033
|
}
|
|
4174
|
-
log12("closed", void 0, {
|
|
4175
|
-
F: __dxlog_file13,
|
|
4176
|
-
L: 181,
|
|
4177
|
-
S: this,
|
|
4178
|
-
C: (f, a) => f(...a)
|
|
4179
|
-
});
|
|
3034
|
+
log12("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 145, S: this });
|
|
4180
3035
|
}
|
|
4181
3036
|
};
|
|
4182
3037
|
var createStateUpdater = (next) => {
|
|
@@ -4237,4 +3092,4 @@ export {
|
|
|
4237
3092
|
RtcTransportService,
|
|
4238
3093
|
createTeleportProtocolFactory
|
|
4239
3094
|
};
|
|
4240
|
-
//# sourceMappingURL=chunk-
|
|
3095
|
+
//# sourceMappingURL=chunk-E6G6B72R.mjs.map
|