@dxos/network-manager 0.8.4-main.ef1bc66f44 → 0.8.4-main.f466a3d56e
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/{chunk-AQSYW43M.mjs → chunk-UFYPMUBI.mjs} +298 -1448
- package/dist/lib/browser/chunk-UFYPMUBI.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 +10 -34
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- 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-SCX3PZRE.mjs → chunk-3KIKKHMP.mjs} +298 -1448
- package/dist/lib/node-esm/chunk-3KIKKHMP.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 +10 -34
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- 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 +6 -6
- 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/signal-connection.d.ts +3 -2
- package/dist/types/src/signal/signal-connection.d.ts.map +1 -1
- package/dist/types/src/signal/signal-messenger.d.ts +3 -2
- package/dist/types/src/signal/signal-messenger.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts +7 -7
- 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 +2 -2
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +4 -3
- 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 +3 -5
- 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/property-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 +19 -29
- package/src/network-manager.ts +21 -19
- package/src/signal/integration.node.test.ts +11 -10
- package/src/signal/signal-connection.ts +3 -2
- package/src/signal/signal-messenger.ts +3 -2
- package/src/signal/swarm-messenger.node.test.ts +25 -24
- package/src/signal/swarm-messenger.ts +65 -55
- package/src/swarm/connection.test.ts +6 -7
- package/src/swarm/connection.ts +8 -17
- package/src/swarm/peer.ts +5 -6
- package/src/swarm/swarm.test.ts +2 -3
- package/src/swarm/swarm.ts +10 -17
- package/src/testing/test-builder.ts +4 -4
- package/src/tests/basic-test-suite.ts +0 -1
- package/src/tests/memory-transport.test.ts +0 -2
- package/src/tests/property-test-suite.ts +4 -3
- package/src/tests/tcp-transport.node.test.ts +0 -2
- package/src/tests/webrtc-transport.test.ts +0 -1
- package/src/transport/webrtc/rtc-peer-connection.ts +0 -1
- package/src/transport/webrtc/rtc-transport-channel.test.ts +0 -2
- package/src/transport/webrtc/rtc-transport-channel.ts +0 -1
- package/src/transport/webrtc/rtc-transport-factory.ts +0 -1
- package/src/transport/webrtc/rtc-transport-proxy.test.ts +0 -2
- package/src/transport/webrtc/rtc-transport-service.ts +0 -1
- package/src/transport/webrtc/rtc-transport.test.ts +0 -1
- package/dist/lib/browser/chunk-AQSYW43M.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SCX3PZRE.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,10 +50,9 @@ 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
|
-
await this._flushSignalBuffer();
|
|
55
|
+
await this._flushSignalBuffer(this._ctx);
|
|
64
56
|
});
|
|
65
57
|
_signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
66
58
|
constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
|
|
@@ -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,111 +224,66 @@ 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);
|
|
434
271
|
this._signalSendTask.schedule();
|
|
435
272
|
}
|
|
436
|
-
async _flushSignalBuffer() {
|
|
273
|
+
async _flushSignalBuffer(ctx) {
|
|
437
274
|
if (this._outgoingSignalBuffer.length === 0) {
|
|
438
275
|
return;
|
|
439
276
|
}
|
|
440
277
|
try {
|
|
441
278
|
if (true) {
|
|
442
|
-
await cancelWithContext(
|
|
279
|
+
await cancelWithContext(ctx, sleep(this._signallingDelay));
|
|
443
280
|
this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
|
|
444
281
|
}
|
|
445
282
|
const signals = [
|
|
446
283
|
...this._outgoingSignalBuffer
|
|
447
284
|
];
|
|
448
285
|
this._outgoingSignalBuffer.length = 0;
|
|
449
|
-
await this._signalMessaging.signal({
|
|
286
|
+
await this._signalMessaging.signal(ctx, {
|
|
450
287
|
author: this.localInfo,
|
|
451
288
|
recipient: this.remoteInfo,
|
|
452
289
|
sessionId: this.sessionId,
|
|
@@ -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",
|
|
@@ -480,52 +312,15 @@ var Connection = class {
|
|
|
480
312
|
/**
|
|
481
313
|
* Receive a signal from the remote peer.
|
|
482
314
|
*/
|
|
483
|
-
async signal(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
|
-
});
|
|
315
|
+
async signal(_ctx, msg) {
|
|
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
|
}
|
|
@@ -616,9 +380,8 @@ _ts_decorate([
|
|
|
616
380
|
], Connection.prototype, "close", null);
|
|
617
381
|
|
|
618
382
|
// src/signal/swarm-messenger.ts
|
|
619
|
-
import { Context as Context2 } from "@dxos/context";
|
|
620
383
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
621
|
-
import { PublicKey
|
|
384
|
+
import { PublicKey } from "@dxos/keys";
|
|
622
385
|
import { log as log2 } from "@dxos/log";
|
|
623
386
|
import { TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
624
387
|
import { schema } from "@dxos/protocols/proto";
|
|
@@ -626,10 +389,6 @@ import { ComplexMap } from "@dxos/util";
|
|
|
626
389
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
627
390
|
var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
628
391
|
var SwarmMessenger = class {
|
|
629
|
-
_ctx = new Context2(void 0, {
|
|
630
|
-
F: __dxlog_file2,
|
|
631
|
-
L: 35
|
|
632
|
-
});
|
|
633
392
|
_sendMessage;
|
|
634
393
|
_onSignal;
|
|
635
394
|
_onOffer;
|
|
@@ -641,7 +400,7 @@ var SwarmMessenger = class {
|
|
|
641
400
|
this._onOffer = onOffer;
|
|
642
401
|
this._topic = topic;
|
|
643
402
|
}
|
|
644
|
-
async receiveMessage({ author, recipient, payload }) {
|
|
403
|
+
async receiveMessage(ctx, { author, recipient, payload }) {
|
|
645
404
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
646
405
|
return;
|
|
647
406
|
}
|
|
@@ -653,14 +412,9 @@ var SwarmMessenger = class {
|
|
|
653
412
|
from: author,
|
|
654
413
|
to: recipient,
|
|
655
414
|
msg: message
|
|
656
|
-
}, {
|
|
657
|
-
F: __dxlog_file2,
|
|
658
|
-
L: 71,
|
|
659
|
-
S: this,
|
|
660
|
-
C: (f, a) => f(...a)
|
|
661
|
-
});
|
|
415
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 35, S: this });
|
|
662
416
|
if (message.data?.offer) {
|
|
663
|
-
await this._handleOffer({
|
|
417
|
+
await this._handleOffer(ctx, {
|
|
664
418
|
author,
|
|
665
419
|
recipient,
|
|
666
420
|
message
|
|
@@ -668,13 +422,13 @@ var SwarmMessenger = class {
|
|
|
668
422
|
} else if (message.data?.answer) {
|
|
669
423
|
await this._resolveAnswers(message);
|
|
670
424
|
} else if (message.data?.signal) {
|
|
671
|
-
await this._handleSignal({
|
|
425
|
+
await this._handleSignal(ctx, {
|
|
672
426
|
author,
|
|
673
427
|
recipient,
|
|
674
428
|
message
|
|
675
429
|
});
|
|
676
430
|
} else if (message.data?.signalBatch) {
|
|
677
|
-
await this._handleSignal({
|
|
431
|
+
await this._handleSignal(ctx, {
|
|
678
432
|
author,
|
|
679
433
|
recipient,
|
|
680
434
|
message
|
|
@@ -682,63 +436,45 @@ var SwarmMessenger = class {
|
|
|
682
436
|
} else {
|
|
683
437
|
log2.warn("unknown message", {
|
|
684
438
|
message
|
|
685
|
-
}, {
|
|
686
|
-
F: __dxlog_file2,
|
|
687
|
-
L: 82,
|
|
688
|
-
S: this,
|
|
689
|
-
C: (f, a) => f(...a)
|
|
690
|
-
});
|
|
439
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 61, S: this });
|
|
691
440
|
}
|
|
692
441
|
}
|
|
693
|
-
async signal(message) {
|
|
694
|
-
invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
695
|
-
|
|
696
|
-
L: 87,
|
|
697
|
-
S: this,
|
|
698
|
-
A: [
|
|
699
|
-
"message.data?.signal || message.data?.signalBatch",
|
|
700
|
-
"'Invalid message'"
|
|
701
|
-
]
|
|
702
|
-
});
|
|
703
|
-
await this._sendReliableMessage({
|
|
442
|
+
async signal(ctx, message) {
|
|
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'"] });
|
|
444
|
+
await this._sendReliableMessage(ctx, {
|
|
704
445
|
author: message.author,
|
|
705
446
|
recipient: message.recipient,
|
|
706
447
|
message
|
|
707
448
|
});
|
|
708
449
|
}
|
|
709
|
-
async offer(message) {
|
|
450
|
+
async offer(ctx, message) {
|
|
710
451
|
const networkMessage = {
|
|
711
452
|
...message,
|
|
712
|
-
messageId:
|
|
453
|
+
messageId: PublicKey.random()
|
|
713
454
|
};
|
|
714
455
|
return new Promise((resolve, reject) => {
|
|
715
456
|
this._offerRecords.set(networkMessage.messageId, {
|
|
716
457
|
resolve
|
|
717
458
|
});
|
|
718
|
-
this._sendReliableMessage({
|
|
459
|
+
this._sendReliableMessage(ctx, {
|
|
719
460
|
author: message.author,
|
|
720
461
|
recipient: message.recipient,
|
|
721
462
|
message: networkMessage
|
|
722
463
|
}).catch((err) => reject(err));
|
|
723
464
|
});
|
|
724
465
|
}
|
|
725
|
-
async _sendReliableMessage({ author, recipient, message }) {
|
|
466
|
+
async _sendReliableMessage(ctx, { author, recipient, message }) {
|
|
726
467
|
const networkMessage = {
|
|
727
468
|
...message,
|
|
728
469
|
// Setting unique message_id if it not specified yet.
|
|
729
|
-
messageId: message.messageId ??
|
|
470
|
+
messageId: message.messageId ?? PublicKey.random()
|
|
730
471
|
};
|
|
731
472
|
log2("sending", {
|
|
732
473
|
from: author,
|
|
733
474
|
to: recipient,
|
|
734
475
|
msg: networkMessage
|
|
735
|
-
}, {
|
|
736
|
-
|
|
737
|
-
L: 125,
|
|
738
|
-
S: this,
|
|
739
|
-
C: (f, a) => f(...a)
|
|
740
|
-
});
|
|
741
|
-
await this._sendMessage({
|
|
476
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 96, S: this });
|
|
477
|
+
await this._sendMessage(ctx, {
|
|
742
478
|
author,
|
|
743
479
|
recipient,
|
|
744
480
|
payload: {
|
|
@@ -748,48 +484,19 @@ var SwarmMessenger = class {
|
|
|
748
484
|
});
|
|
749
485
|
}
|
|
750
486
|
async _resolveAnswers(message) {
|
|
751
|
-
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
752
|
-
F: __dxlog_file2,
|
|
753
|
-
L: 137,
|
|
754
|
-
S: this,
|
|
755
|
-
A: [
|
|
756
|
-
"message.data?.answer?.offerMessageId",
|
|
757
|
-
"'No offerMessageId'"
|
|
758
|
-
]
|
|
759
|
-
});
|
|
487
|
+
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 111, S: this, A: ["message.data?.answer?.offerMessageId", "'No offerMessageId'"] });
|
|
760
488
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
761
489
|
if (offerRecord) {
|
|
762
490
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
763
|
-
invariant2(message.data?.answer, "No answer", {
|
|
764
|
-
F: __dxlog_file2,
|
|
765
|
-
L: 141,
|
|
766
|
-
S: this,
|
|
767
|
-
A: [
|
|
768
|
-
"message.data?.answer",
|
|
769
|
-
"'No answer'"
|
|
770
|
-
]
|
|
771
|
-
});
|
|
491
|
+
invariant2(message.data?.answer, "No answer", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 115, S: this, A: ["message.data?.answer", "'No answer'"] });
|
|
772
492
|
log2("resolving", {
|
|
773
493
|
answer: message.data.answer
|
|
774
|
-
}, {
|
|
775
|
-
F: __dxlog_file2,
|
|
776
|
-
L: 142,
|
|
777
|
-
S: this,
|
|
778
|
-
C: (f, a) => f(...a)
|
|
779
|
-
});
|
|
494
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 116, S: this });
|
|
780
495
|
offerRecord.resolve(message.data.answer);
|
|
781
496
|
}
|
|
782
497
|
}
|
|
783
|
-
async _handleOffer({ author, recipient, message }) {
|
|
784
|
-
invariant2(message.data.offer, "No offer", {
|
|
785
|
-
F: __dxlog_file2,
|
|
786
|
-
L: 156,
|
|
787
|
-
S: this,
|
|
788
|
-
A: [
|
|
789
|
-
"message.data.offer",
|
|
790
|
-
"'No offer'"
|
|
791
|
-
]
|
|
792
|
-
});
|
|
498
|
+
async _handleOffer(ctx, { author, recipient, message }) {
|
|
499
|
+
invariant2(message.data.offer, "No offer", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 123, S: this, A: ["message.data.offer", "'No offer'"] });
|
|
793
500
|
const offerMessage = {
|
|
794
501
|
author,
|
|
795
502
|
recipient,
|
|
@@ -798,10 +505,10 @@ var SwarmMessenger = class {
|
|
|
798
505
|
offer: message.data.offer
|
|
799
506
|
}
|
|
800
507
|
};
|
|
801
|
-
const answer = await this._onOffer(offerMessage);
|
|
508
|
+
const answer = await this._onOffer(ctx, offerMessage);
|
|
802
509
|
answer.offerMessageId = message.messageId;
|
|
803
510
|
try {
|
|
804
|
-
await this._sendReliableMessage({
|
|
511
|
+
await this._sendReliableMessage(ctx, {
|
|
805
512
|
author: recipient,
|
|
806
513
|
recipient: author,
|
|
807
514
|
message: {
|
|
@@ -816,43 +523,17 @@ var SwarmMessenger = class {
|
|
|
816
523
|
if (err instanceof TimeoutError2) {
|
|
817
524
|
log2.info("timeout sending answer to offer", {
|
|
818
525
|
err
|
|
819
|
-
}, {
|
|
820
|
-
F: __dxlog_file2,
|
|
821
|
-
L: 177,
|
|
822
|
-
S: this,
|
|
823
|
-
C: (f, a) => f(...a)
|
|
824
|
-
});
|
|
526
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 148, S: this });
|
|
825
527
|
} else {
|
|
826
528
|
log2.info("error sending answer to offer", {
|
|
827
529
|
err
|
|
828
|
-
}, {
|
|
829
|
-
F: __dxlog_file2,
|
|
830
|
-
L: 179,
|
|
831
|
-
S: this,
|
|
832
|
-
C: (f, a) => f(...a)
|
|
833
|
-
});
|
|
530
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 152, S: this });
|
|
834
531
|
}
|
|
835
532
|
}
|
|
836
533
|
}
|
|
837
|
-
async _handleSignal({ author, recipient, message }) {
|
|
838
|
-
invariant2(message.messageId, void 0, {
|
|
839
|
-
|
|
840
|
-
L: 193,
|
|
841
|
-
S: this,
|
|
842
|
-
A: [
|
|
843
|
-
"message.messageId",
|
|
844
|
-
""
|
|
845
|
-
]
|
|
846
|
-
});
|
|
847
|
-
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
848
|
-
F: __dxlog_file2,
|
|
849
|
-
L: 194,
|
|
850
|
-
S: this,
|
|
851
|
-
A: [
|
|
852
|
-
"message.data.signal || message.data.signalBatch",
|
|
853
|
-
"'Invalid message'"
|
|
854
|
-
]
|
|
855
|
-
});
|
|
534
|
+
async _handleSignal(ctx, { author, recipient, message }) {
|
|
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'"] });
|
|
856
537
|
const signalMessage = {
|
|
857
538
|
author,
|
|
858
539
|
recipient,
|
|
@@ -862,35 +543,34 @@ var SwarmMessenger = class {
|
|
|
862
543
|
signalBatch: message.data.signalBatch
|
|
863
544
|
}
|
|
864
545
|
};
|
|
865
|
-
await this._onSignal(signalMessage);
|
|
546
|
+
await this._onSignal(ctx, signalMessage);
|
|
866
547
|
}
|
|
867
548
|
};
|
|
868
549
|
|
|
869
550
|
// src/swarm/swarm.ts
|
|
870
551
|
import { Event as Event3, scheduleTask as scheduleTask3, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
|
|
871
|
-
import { Context as
|
|
552
|
+
import { Context as Context3 } from "@dxos/context";
|
|
872
553
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
873
554
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
874
|
-
import { PublicKey as
|
|
555
|
+
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
875
556
|
import { log as log4, logInfo as logInfo2 } from "@dxos/log";
|
|
876
557
|
import { PeerInfoHash } from "@dxos/messaging";
|
|
877
|
-
import { trace as trace2 } from "@dxos/protocols";
|
|
878
558
|
import { ComplexMap as ComplexMap2, isNonNullable } from "@dxos/util";
|
|
879
559
|
|
|
880
560
|
// src/swarm/peer.ts
|
|
881
561
|
import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
|
|
882
|
-
import { Context as
|
|
562
|
+
import { Context as Context2 } from "@dxos/context";
|
|
883
563
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
884
|
-
import { PublicKey as
|
|
564
|
+
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
885
565
|
import { log as log3 } from "@dxos/log";
|
|
886
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";
|
|
887
568
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
888
569
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
889
570
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
890
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;
|
|
891
572
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
892
573
|
}
|
|
893
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
894
574
|
var ConnectionDisplacedError = class extends SystemError {
|
|
895
575
|
constructor() {
|
|
896
576
|
super({
|
|
@@ -914,10 +594,7 @@ var Peer = class {
|
|
|
914
594
|
_availableAfter = 0;
|
|
915
595
|
availableToConnect = true;
|
|
916
596
|
_lastConnectionTime;
|
|
917
|
-
_ctx = new
|
|
918
|
-
F: __dxlog_file3,
|
|
919
|
-
L: 81
|
|
920
|
-
});
|
|
597
|
+
_ctx = new Context2(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 44 });
|
|
921
598
|
_connectionCtx;
|
|
922
599
|
connection;
|
|
923
600
|
/**
|
|
@@ -939,19 +616,14 @@ var Peer = class {
|
|
|
939
616
|
/**
|
|
940
617
|
* Respond to remote offer.
|
|
941
618
|
*/
|
|
942
|
-
async onOffer(message) {
|
|
619
|
+
async onOffer(_ctx, message) {
|
|
943
620
|
const remote = message.author;
|
|
944
621
|
if (this.connection && ![
|
|
945
622
|
ConnectionState.CREATED,
|
|
946
623
|
ConnectionState.INITIAL,
|
|
947
624
|
ConnectionState.CONNECTING
|
|
948
625
|
].includes(this.connection.state)) {
|
|
949
|
-
log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
950
|
-
F: __dxlog_file3,
|
|
951
|
-
L: 116,
|
|
952
|
-
S: this,
|
|
953
|
-
C: (f, a) => f(...a)
|
|
954
|
-
});
|
|
626
|
+
log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 71, S: this });
|
|
955
627
|
return {
|
|
956
628
|
accept: false
|
|
957
629
|
};
|
|
@@ -963,12 +635,7 @@ var Peer = class {
|
|
|
963
635
|
topic: this.topic,
|
|
964
636
|
remotePeer: this.remoteInfo,
|
|
965
637
|
sessionId: this.connection?.sessionId
|
|
966
|
-
}, {
|
|
967
|
-
F: __dxlog_file3,
|
|
968
|
-
L: 125,
|
|
969
|
-
S: this,
|
|
970
|
-
C: (f, a) => f(...a)
|
|
971
|
-
});
|
|
638
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 82, S: this });
|
|
972
639
|
if (this.connection) {
|
|
973
640
|
await this.closeConnection(new ConnectionDisplacedError());
|
|
974
641
|
}
|
|
@@ -980,15 +647,7 @@ var Peer = class {
|
|
|
980
647
|
}
|
|
981
648
|
if (await this._callbacks.onOffer(remote)) {
|
|
982
649
|
if (!this.connection) {
|
|
983
|
-
invariant3(message.sessionId, void 0, {
|
|
984
|
-
F: __dxlog_file3,
|
|
985
|
-
L: 145,
|
|
986
|
-
S: this,
|
|
987
|
-
A: [
|
|
988
|
-
"message.sessionId",
|
|
989
|
-
""
|
|
990
|
-
]
|
|
991
|
-
});
|
|
650
|
+
invariant3(message.sessionId, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 102, S: this, A: ["message.sessionId", ""] });
|
|
992
651
|
const connection = this._createConnection(false, message.sessionId);
|
|
993
652
|
try {
|
|
994
653
|
await this._connectionLimiter.connecting(message.sessionId);
|
|
@@ -1001,12 +660,7 @@ var Peer = class {
|
|
|
1001
660
|
peerId: this.localInfo,
|
|
1002
661
|
remoteId: this.remoteInfo,
|
|
1003
662
|
err
|
|
1004
|
-
}, {
|
|
1005
|
-
F: __dxlog_file3,
|
|
1006
|
-
L: 155,
|
|
1007
|
-
S: this,
|
|
1008
|
-
C: (f, a) => f(...a)
|
|
1009
|
-
});
|
|
663
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 110, S: this });
|
|
1010
664
|
}
|
|
1011
665
|
await this.closeConnection(err);
|
|
1012
666
|
}
|
|
@@ -1022,44 +676,23 @@ var Peer = class {
|
|
|
1022
676
|
/**
|
|
1023
677
|
* Initiate a connection to the remote peer.
|
|
1024
678
|
*/
|
|
1025
|
-
async initiateConnection() {
|
|
1026
|
-
invariant3(!this.initiating, "Initiation in progress.", {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
S: this,
|
|
1030
|
-
A: [
|
|
1031
|
-
"!this.initiating",
|
|
1032
|
-
"'Initiation in progress.'"
|
|
1033
|
-
]
|
|
1034
|
-
});
|
|
1035
|
-
invariant3(!this.connection, "Already connected.", {
|
|
1036
|
-
F: __dxlog_file3,
|
|
1037
|
-
L: 174,
|
|
1038
|
-
S: this,
|
|
1039
|
-
A: [
|
|
1040
|
-
"!this.connection",
|
|
1041
|
-
"'Already connected.'"
|
|
1042
|
-
]
|
|
1043
|
-
});
|
|
1044
|
-
const sessionId = PublicKey3.random();
|
|
679
|
+
async initiateConnection(ctx) {
|
|
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();
|
|
1045
683
|
log3("initiating...", {
|
|
1046
684
|
local: this.localInfo,
|
|
1047
685
|
topic: this.topic,
|
|
1048
686
|
remote: this.remoteInfo,
|
|
1049
687
|
sessionId
|
|
1050
|
-
}, {
|
|
1051
|
-
F: __dxlog_file3,
|
|
1052
|
-
L: 176,
|
|
1053
|
-
S: this,
|
|
1054
|
-
C: (f, a) => f(...a)
|
|
1055
|
-
});
|
|
688
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 135, S: this });
|
|
1056
689
|
const connection = this._createConnection(true, sessionId);
|
|
1057
690
|
this.initiating = true;
|
|
1058
691
|
let answer;
|
|
1059
692
|
try {
|
|
1060
693
|
await this._connectionLimiter.connecting(sessionId);
|
|
1061
694
|
connection.initiate();
|
|
1062
|
-
answer = await this._signalMessaging.offer({
|
|
695
|
+
answer = await this._signalMessaging.offer(ctx, {
|
|
1063
696
|
author: this.localInfo,
|
|
1064
697
|
recipient: this.remoteInfo,
|
|
1065
698
|
sessionId,
|
|
@@ -1073,19 +706,9 @@ var Peer = class {
|
|
|
1073
706
|
topic: this.topic,
|
|
1074
707
|
local: this.localInfo,
|
|
1075
708
|
remote: this.remoteInfo
|
|
1076
|
-
}, {
|
|
1077
|
-
F: __dxlog_file3,
|
|
1078
|
-
L: 193,
|
|
1079
|
-
S: this,
|
|
1080
|
-
C: (f, a) => f(...a)
|
|
1081
|
-
});
|
|
709
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 156, S: this });
|
|
1082
710
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1083
|
-
log3("ignoring response", void 0, {
|
|
1084
|
-
F: __dxlog_file3,
|
|
1085
|
-
L: 195,
|
|
1086
|
-
S: this,
|
|
1087
|
-
C: (f, a) => f(...a)
|
|
1088
|
-
});
|
|
711
|
+
log3("ignoring response", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 163, S: this });
|
|
1089
712
|
return;
|
|
1090
713
|
}
|
|
1091
714
|
} catch (err) {
|
|
@@ -1094,12 +717,7 @@ var Peer = class {
|
|
|
1094
717
|
topic: this.topic,
|
|
1095
718
|
local: this.localInfo,
|
|
1096
719
|
remote: this.remoteInfo
|
|
1097
|
-
}, {
|
|
1098
|
-
F: __dxlog_file3,
|
|
1099
|
-
L: 199,
|
|
1100
|
-
S: this,
|
|
1101
|
-
C: (f, a) => f(...a)
|
|
1102
|
-
});
|
|
720
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 167, S: this });
|
|
1103
721
|
await connection.abort(err);
|
|
1104
722
|
throw err;
|
|
1105
723
|
} finally {
|
|
@@ -1116,24 +734,14 @@ var Peer = class {
|
|
|
1116
734
|
topic: this.topic,
|
|
1117
735
|
local: this.localInfo,
|
|
1118
736
|
remote: this.remoteInfo
|
|
1119
|
-
}, {
|
|
1120
|
-
F: __dxlog_file3,
|
|
1121
|
-
L: 212,
|
|
1122
|
-
S: this,
|
|
1123
|
-
C: (f, a) => f(...a)
|
|
1124
|
-
});
|
|
737
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 184, S: this });
|
|
1125
738
|
await connection.abort(err);
|
|
1126
739
|
throw err;
|
|
1127
740
|
} finally {
|
|
1128
741
|
this.initiating = false;
|
|
1129
742
|
}
|
|
1130
743
|
try {
|
|
1131
|
-
log3("opening connection as initiator", void 0, {
|
|
1132
|
-
F: __dxlog_file3,
|
|
1133
|
-
L: 225,
|
|
1134
|
-
S: this,
|
|
1135
|
-
C: (f, a) => f(...a)
|
|
1136
|
-
});
|
|
744
|
+
log3("opening connection as initiator", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 196, S: this });
|
|
1137
745
|
await connection.openConnection();
|
|
1138
746
|
this._callbacks.onAccepted();
|
|
1139
747
|
} catch (err) {
|
|
@@ -1142,20 +750,10 @@ var Peer = class {
|
|
|
1142
750
|
topic: this.topic,
|
|
1143
751
|
local: this.localInfo,
|
|
1144
752
|
remote: this.remoteInfo
|
|
1145
|
-
}, {
|
|
1146
|
-
F: __dxlog_file3,
|
|
1147
|
-
L: 229,
|
|
1148
|
-
S: this,
|
|
1149
|
-
C: (f, a) => f(...a)
|
|
1150
|
-
});
|
|
753
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 200, S: this });
|
|
1151
754
|
log3.warn("closing connection due to unhandled error on openConnection", {
|
|
1152
755
|
err
|
|
1153
|
-
}, {
|
|
1154
|
-
F: __dxlog_file3,
|
|
1155
|
-
L: 236,
|
|
1156
|
-
S: this,
|
|
1157
|
-
C: (f, a) => f(...a)
|
|
1158
|
-
});
|
|
756
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 207, S: this });
|
|
1159
757
|
await this.closeConnection(err);
|
|
1160
758
|
throw err;
|
|
1161
759
|
} finally {
|
|
@@ -1173,21 +771,8 @@ var Peer = class {
|
|
|
1173
771
|
remoteId: this.remoteInfo,
|
|
1174
772
|
initiator,
|
|
1175
773
|
sessionId
|
|
1176
|
-
}, {
|
|
1177
|
-
|
|
1178
|
-
L: 250,
|
|
1179
|
-
S: this,
|
|
1180
|
-
C: (f, a) => f(...a)
|
|
1181
|
-
});
|
|
1182
|
-
invariant3(!this.connection, "Already connected.", {
|
|
1183
|
-
F: __dxlog_file3,
|
|
1184
|
-
L: 257,
|
|
1185
|
-
S: this,
|
|
1186
|
-
A: [
|
|
1187
|
-
"!this.connection",
|
|
1188
|
-
"'Already connected.'"
|
|
1189
|
-
]
|
|
1190
|
-
});
|
|
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.'"] });
|
|
1191
776
|
const connection = new Connection(
|
|
1192
777
|
this.topic,
|
|
1193
778
|
this.localInfo,
|
|
@@ -1198,8 +783,8 @@ var Peer = class {
|
|
|
1198
783
|
// TODO(dmaretskyi): Init only when connection is established.
|
|
1199
784
|
this._protocolProvider({
|
|
1200
785
|
initiator,
|
|
1201
|
-
localPeerId:
|
|
1202
|
-
remotePeerId:
|
|
786
|
+
localPeerId: PublicKey2.from(this.localInfo.peerKey),
|
|
787
|
+
remotePeerId: PublicKey2.from(this.remoteInfo.peerKey),
|
|
1203
788
|
topic: this.topic
|
|
1204
789
|
}),
|
|
1205
790
|
this._transportFactory,
|
|
@@ -1215,12 +800,7 @@ var Peer = class {
|
|
|
1215
800
|
remotePeerId: this.remoteInfo,
|
|
1216
801
|
sessionId,
|
|
1217
802
|
initiator
|
|
1218
|
-
}, {
|
|
1219
|
-
F: __dxlog_file3,
|
|
1220
|
-
L: 281,
|
|
1221
|
-
S: this,
|
|
1222
|
-
C: (f, a) => f(...a)
|
|
1223
|
-
});
|
|
803
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 241, S: this });
|
|
1224
804
|
},
|
|
1225
805
|
onClosed: (err) => {
|
|
1226
806
|
const logMeta = {
|
|
@@ -1229,34 +809,16 @@ var Peer = class {
|
|
|
1229
809
|
remoteId: this.remoteInfo,
|
|
1230
810
|
initiator
|
|
1231
811
|
};
|
|
1232
|
-
log3("connection closed", logMeta, {
|
|
1233
|
-
F: __dxlog_file3,
|
|
1234
|
-
L: 291,
|
|
1235
|
-
S: this,
|
|
1236
|
-
C: (f, a) => f(...a)
|
|
1237
|
-
});
|
|
812
|
+
log3("connection closed", logMeta, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 256, S: this });
|
|
1238
813
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1239
|
-
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1240
|
-
F: __dxlog_file3,
|
|
1241
|
-
L: 296,
|
|
1242
|
-
S: this,
|
|
1243
|
-
A: [
|
|
1244
|
-
"this.connection === connection",
|
|
1245
|
-
"'Connection mismatch (race condition).'"
|
|
1246
|
-
]
|
|
1247
|
-
});
|
|
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).'"] });
|
|
1248
815
|
log3.trace("dxos.mesh.connection.closed", {
|
|
1249
816
|
topic: this.topic,
|
|
1250
817
|
localPeerId: this.localInfo,
|
|
1251
818
|
remotePeerId: this.remoteInfo,
|
|
1252
819
|
sessionId,
|
|
1253
820
|
initiator
|
|
1254
|
-
}, {
|
|
1255
|
-
F: __dxlog_file3,
|
|
1256
|
-
L: 298,
|
|
1257
|
-
S: this,
|
|
1258
|
-
C: (f, a) => f(...a)
|
|
1259
|
-
});
|
|
821
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 260, S: this });
|
|
1260
822
|
if (err instanceof ConnectionDisplacedError) {
|
|
1261
823
|
this.connectionDisplaced.emit(this.connection);
|
|
1262
824
|
} else {
|
|
@@ -1268,12 +830,7 @@ var Peer = class {
|
|
|
1268
830
|
}
|
|
1269
831
|
this._callbacks.onDisconnected();
|
|
1270
832
|
scheduleTask2(this._connectionCtx, () => {
|
|
1271
|
-
log3("peer became available", logMeta, {
|
|
1272
|
-
F: __dxlog_file3,
|
|
1273
|
-
L: 322,
|
|
1274
|
-
S: this,
|
|
1275
|
-
C: (f, a) => f(...a)
|
|
1276
|
-
});
|
|
833
|
+
log3("peer became available", logMeta, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 279, S: this });
|
|
1277
834
|
this.availableToConnect = true;
|
|
1278
835
|
this._callbacks.onPeerAvailable();
|
|
1279
836
|
}, this._availableAfter);
|
|
@@ -1292,12 +849,7 @@ var Peer = class {
|
|
|
1292
849
|
remoteId: this.remoteInfo,
|
|
1293
850
|
initiator,
|
|
1294
851
|
err
|
|
1295
|
-
}, {
|
|
1296
|
-
F: __dxlog_file3,
|
|
1297
|
-
L: 340,
|
|
1298
|
-
S: this,
|
|
1299
|
-
C: (f, a) => f(...a)
|
|
1300
|
-
});
|
|
852
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 291, S: this });
|
|
1301
853
|
log3.trace("dxos.mesh.connection.error", {
|
|
1302
854
|
topic: this.topic,
|
|
1303
855
|
localPeerId: this.localInfo,
|
|
@@ -1305,12 +857,7 @@ var Peer = class {
|
|
|
1305
857
|
sessionId,
|
|
1306
858
|
initiator,
|
|
1307
859
|
err
|
|
1308
|
-
}, {
|
|
1309
|
-
F: __dxlog_file3,
|
|
1310
|
-
L: 347,
|
|
1311
|
-
S: this,
|
|
1312
|
-
C: (f, a) => f(...a)
|
|
1313
|
-
});
|
|
860
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 298, S: this });
|
|
1314
861
|
void this.closeConnection(err);
|
|
1315
862
|
});
|
|
1316
863
|
this.connection = connection;
|
|
@@ -1324,50 +871,30 @@ var Peer = class {
|
|
|
1324
871
|
log3("closing...", {
|
|
1325
872
|
peerId: this.remoteInfo,
|
|
1326
873
|
sessionId: connection.sessionId
|
|
1327
|
-
}, {
|
|
1328
|
-
F: __dxlog_file3,
|
|
1329
|
-
L: 372,
|
|
1330
|
-
S: this,
|
|
1331
|
-
C: (f, a) => f(...a)
|
|
1332
|
-
});
|
|
874
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 317, S: this });
|
|
1333
875
|
await connection.close({
|
|
1334
876
|
error: err
|
|
1335
877
|
});
|
|
1336
878
|
log3("closed", {
|
|
1337
879
|
peerId: this.remoteInfo,
|
|
1338
880
|
sessionId: connection.sessionId
|
|
1339
|
-
}, {
|
|
1340
|
-
F: __dxlog_file3,
|
|
1341
|
-
L: 378,
|
|
1342
|
-
S: this,
|
|
1343
|
-
C: (f, a) => f(...a)
|
|
1344
|
-
});
|
|
881
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 326, S: this });
|
|
1345
882
|
}
|
|
1346
|
-
async onSignal(message) {
|
|
883
|
+
async onSignal(ctx, message) {
|
|
1347
884
|
if (!this.connection) {
|
|
1348
885
|
log3("dropping signal message for non-existent connection", {
|
|
1349
886
|
message
|
|
1350
|
-
}, {
|
|
1351
|
-
F: __dxlog_file3,
|
|
1352
|
-
L: 383,
|
|
1353
|
-
S: this,
|
|
1354
|
-
C: (f, a) => f(...a)
|
|
1355
|
-
});
|
|
887
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 333, S: this });
|
|
1356
888
|
return;
|
|
1357
889
|
}
|
|
1358
|
-
await this.connection.signal(message);
|
|
890
|
+
await this.connection.signal(ctx, message);
|
|
1359
891
|
}
|
|
1360
892
|
async safeDestroy(reason) {
|
|
1361
893
|
await this._ctx.dispose();
|
|
1362
894
|
log3("Destroying peer", {
|
|
1363
895
|
peerId: this.remoteInfo,
|
|
1364
896
|
topic: this.topic
|
|
1365
|
-
}, {
|
|
1366
|
-
F: __dxlog_file3,
|
|
1367
|
-
L: 393,
|
|
1368
|
-
S: this,
|
|
1369
|
-
C: (f, a) => f(...a)
|
|
1370
|
-
});
|
|
897
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 342, S: this });
|
|
1371
898
|
await this?.connection?.close({
|
|
1372
899
|
reason
|
|
1373
900
|
});
|
|
@@ -1390,13 +917,13 @@ var increaseInterval = (interval) => {
|
|
|
1390
917
|
};
|
|
1391
918
|
|
|
1392
919
|
// src/swarm/swarm.ts
|
|
920
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1393
921
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
1394
922
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1395
923
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1396
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;
|
|
1397
925
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1398
926
|
}
|
|
1399
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1400
927
|
var INITIATION_DELAY = 100;
|
|
1401
928
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1402
929
|
var Swarm = class {
|
|
@@ -1410,10 +937,7 @@ var Swarm = class {
|
|
|
1410
937
|
_connectionLimiter;
|
|
1411
938
|
_initiationDelay;
|
|
1412
939
|
_swarmMessenger;
|
|
1413
|
-
_ctx = new
|
|
1414
|
-
F: __dxlog_file4,
|
|
1415
|
-
L: 39
|
|
1416
|
-
});
|
|
940
|
+
_ctx = new Context3(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 39 });
|
|
1417
941
|
_listeningHandle = void 0;
|
|
1418
942
|
/**
|
|
1419
943
|
* PeerInfo -> Peer.
|
|
@@ -1423,7 +947,7 @@ var Swarm = class {
|
|
|
1423
947
|
/**
|
|
1424
948
|
* Unique id of the swarm, local to the current peer, generated when swarm is joined.
|
|
1425
949
|
*/
|
|
1426
|
-
_instanceId =
|
|
950
|
+
_instanceId = PublicKey3.random().toHex();
|
|
1427
951
|
/**
|
|
1428
952
|
* New connection to a peer is started.
|
|
1429
953
|
* @internal
|
|
@@ -1452,47 +976,23 @@ var Swarm = class {
|
|
|
1452
976
|
this._label = _label;
|
|
1453
977
|
this._connectionLimiter = _connectionLimiter;
|
|
1454
978
|
this._initiationDelay = _initiationDelay;
|
|
1455
|
-
log4.trace("dxos.mesh.swarm.constructor", trace2.begin({
|
|
1456
|
-
id: this._instanceId,
|
|
1457
|
-
data: {
|
|
1458
|
-
topic: this._topic.toHex(),
|
|
1459
|
-
peer: this._ownPeer
|
|
1460
|
-
}
|
|
1461
|
-
}), {
|
|
1462
|
-
F: __dxlog_file4,
|
|
1463
|
-
L: 89,
|
|
1464
|
-
S: this,
|
|
1465
|
-
C: (f, a) => f(...a)
|
|
1466
|
-
});
|
|
1467
979
|
log4("creating swarm", {
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
L: 93,
|
|
1472
|
-
S: this,
|
|
1473
|
-
C: (f, a) => f(...a)
|
|
1474
|
-
});
|
|
980
|
+
topic: this._topic.toHex(),
|
|
981
|
+
peer: this._ownPeer
|
|
982
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 73, S: this });
|
|
1475
983
|
_topology.init(this._getSwarmController());
|
|
1476
984
|
this._swarmMessenger = new SwarmMessenger({
|
|
1477
|
-
sendMessage: async (msg) => await this._messenger.sendMessage(msg),
|
|
1478
|
-
onSignal: async (msg) => await this.onSignal(msg),
|
|
1479
|
-
onOffer: async (msg) => await this.onOffer(msg),
|
|
985
|
+
sendMessage: async (ctx, msg) => await this._messenger.sendMessage(ctx, msg),
|
|
986
|
+
onSignal: async (ctx, msg) => await this.onSignal(ctx, msg),
|
|
987
|
+
onOffer: async (ctx, msg) => await this.onOffer(ctx, msg),
|
|
1480
988
|
topic: this._topic
|
|
1481
989
|
});
|
|
1482
|
-
log4.trace("dxos.mesh.swarm.constructor", trace2.end({
|
|
1483
|
-
id: this._instanceId
|
|
1484
|
-
}), {
|
|
1485
|
-
F: __dxlog_file4,
|
|
1486
|
-
L: 102,
|
|
1487
|
-
S: this,
|
|
1488
|
-
C: (f, a) => f(...a)
|
|
1489
|
-
});
|
|
1490
990
|
}
|
|
1491
991
|
get connections() {
|
|
1492
992
|
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable);
|
|
1493
993
|
}
|
|
1494
994
|
get ownPeerId() {
|
|
1495
|
-
return
|
|
995
|
+
return PublicKey3.from(this._ownPeer.peerKey);
|
|
1496
996
|
}
|
|
1497
997
|
get ownPeer() {
|
|
1498
998
|
return this._ownPeer;
|
|
@@ -1507,71 +1007,35 @@ var Swarm = class {
|
|
|
1507
1007
|
return this._topic;
|
|
1508
1008
|
}
|
|
1509
1009
|
async open() {
|
|
1510
|
-
invariant4(!this._listeningHandle, void 0, {
|
|
1511
|
-
F: __dxlog_file4,
|
|
1512
|
-
L: 133,
|
|
1513
|
-
S: this,
|
|
1514
|
-
A: [
|
|
1515
|
-
"!this._listeningHandle",
|
|
1516
|
-
""
|
|
1517
|
-
]
|
|
1518
|
-
});
|
|
1010
|
+
invariant4(!this._listeningHandle, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 103, S: this, A: ["!this._listeningHandle", ""] });
|
|
1519
1011
|
this._listeningHandle = await this._messenger.listen({
|
|
1520
1012
|
peer: this._ownPeer,
|
|
1521
1013
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
1522
1014
|
onMessage: async (message) => {
|
|
1523
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) => log4.info("Error while receiving message", {
|
|
1015
|
+
await this._swarmMessenger.receiveMessage(this._ctx, message).catch((err) => log4.info("Error while receiving message", {
|
|
1524
1016
|
err
|
|
1525
|
-
}, {
|
|
1526
|
-
F: __dxlog_file4,
|
|
1527
|
-
L: 141,
|
|
1528
|
-
S: this,
|
|
1529
|
-
C: (f, a) => f(...a)
|
|
1530
|
-
}));
|
|
1017
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 109, S: this }));
|
|
1531
1018
|
}
|
|
1532
1019
|
});
|
|
1533
1020
|
}
|
|
1534
1021
|
async destroy() {
|
|
1535
|
-
log4("destroying...", void 0, {
|
|
1536
|
-
F: __dxlog_file4,
|
|
1537
|
-
L: 147,
|
|
1538
|
-
S: this,
|
|
1539
|
-
C: (f, a) => f(...a)
|
|
1540
|
-
});
|
|
1022
|
+
log4("destroying...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 116, S: this });
|
|
1541
1023
|
await this._listeningHandle?.unsubscribe();
|
|
1542
1024
|
this._listeningHandle = void 0;
|
|
1543
1025
|
await this._ctx.dispose();
|
|
1544
1026
|
await this._topology.destroy();
|
|
1545
1027
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1546
|
-
log4("destroyed", void 0, {
|
|
1547
|
-
F: __dxlog_file4,
|
|
1548
|
-
L: 154,
|
|
1549
|
-
S: this,
|
|
1550
|
-
C: (f, a) => f(...a)
|
|
1551
|
-
});
|
|
1028
|
+
log4("destroyed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 122, S: this });
|
|
1552
1029
|
}
|
|
1553
1030
|
async setTopology(topology) {
|
|
1554
|
-
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1555
|
-
F: __dxlog_file4,
|
|
1556
|
-
L: 158,
|
|
1557
|
-
S: this,
|
|
1558
|
-
A: [
|
|
1559
|
-
"!this._ctx.disposed",
|
|
1560
|
-
"'Swarm is offline'"
|
|
1561
|
-
]
|
|
1562
|
-
});
|
|
1031
|
+
invariant4(!this._ctx.disposed, "Swarm is offline", { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 125, S: this, A: ["!this._ctx.disposed", "'Swarm is offline'"] });
|
|
1563
1032
|
if (topology === this._topology) {
|
|
1564
1033
|
return;
|
|
1565
1034
|
}
|
|
1566
1035
|
log4("setting topology", {
|
|
1567
1036
|
previous: getClassName(this._topology),
|
|
1568
1037
|
topology: getClassName(topology)
|
|
1569
|
-
}, {
|
|
1570
|
-
F: __dxlog_file4,
|
|
1571
|
-
L: 162,
|
|
1572
|
-
S: this,
|
|
1573
|
-
C: (f, a) => f(...a)
|
|
1574
|
-
});
|
|
1038
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 129, S: this });
|
|
1575
1039
|
await this._topology.destroy();
|
|
1576
1040
|
this._topology = topology;
|
|
1577
1041
|
this._topology.init(this._getSwarmController());
|
|
@@ -1580,19 +1044,9 @@ var Swarm = class {
|
|
|
1580
1044
|
async onSwarmEvent(swarmEvent) {
|
|
1581
1045
|
log4("swarm event", {
|
|
1582
1046
|
swarmEvent
|
|
1583
|
-
}, {
|
|
1584
|
-
F: __dxlog_file4,
|
|
1585
|
-
L: 175,
|
|
1586
|
-
S: this,
|
|
1587
|
-
C: (f, a) => f(...a)
|
|
1588
|
-
});
|
|
1047
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 139, S: this });
|
|
1589
1048
|
if (this._ctx.disposed) {
|
|
1590
|
-
log4("swarm event ignored for disposed swarm", void 0, {
|
|
1591
|
-
F: __dxlog_file4,
|
|
1592
|
-
L: 178,
|
|
1593
|
-
S: this,
|
|
1594
|
-
C: (f, a) => f(...a)
|
|
1595
|
-
});
|
|
1049
|
+
log4("swarm event ignored for disposed swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 143, S: this });
|
|
1596
1050
|
return;
|
|
1597
1051
|
}
|
|
1598
1052
|
if (swarmEvent.peerAvailable) {
|
|
@@ -1600,12 +1054,7 @@ var Swarm = class {
|
|
|
1600
1054
|
if (peerId !== this._ownPeer.peerKey) {
|
|
1601
1055
|
log4("new peer", {
|
|
1602
1056
|
peerId
|
|
1603
|
-
}, {
|
|
1604
|
-
F: __dxlog_file4,
|
|
1605
|
-
L: 185,
|
|
1606
|
-
S: this,
|
|
1607
|
-
C: (f, a) => f(...a)
|
|
1608
|
-
});
|
|
1057
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 149, S: this });
|
|
1609
1058
|
const peer = this._getOrCreatePeer(swarmEvent.peerAvailable.peer);
|
|
1610
1059
|
peer.advertizing = true;
|
|
1611
1060
|
}
|
|
@@ -1614,70 +1063,32 @@ var Swarm = class {
|
|
|
1614
1063
|
if (peer) {
|
|
1615
1064
|
peer.advertizing = false;
|
|
1616
1065
|
if (this._isConnectionEstablishmentInProgress(peer)) {
|
|
1617
|
-
log4(`destroying peer, state: ${peer.connection?.state}`, void 0, {
|
|
1618
|
-
|
|
1619
|
-
L: 196,
|
|
1620
|
-
S: this,
|
|
1621
|
-
C: (f, a) => f(...a)
|
|
1622
|
-
});
|
|
1623
|
-
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log4.catch(err, void 0, {
|
|
1624
|
-
F: __dxlog_file4,
|
|
1625
|
-
L: 197,
|
|
1626
|
-
S: this,
|
|
1627
|
-
C: (f, a) => f(...a)
|
|
1628
|
-
}));
|
|
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 }));
|
|
1629
1068
|
}
|
|
1630
1069
|
} else {
|
|
1631
1070
|
log4("received peerLeft but no peer found", {
|
|
1632
1071
|
peer: swarmEvent.peerLeft.peer.peerKey
|
|
1633
|
-
}, {
|
|
1634
|
-
F: __dxlog_file4,
|
|
1635
|
-
L: 200,
|
|
1636
|
-
S: this,
|
|
1637
|
-
C: (f, a) => f(...a)
|
|
1638
|
-
});
|
|
1072
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 166, S: this });
|
|
1639
1073
|
}
|
|
1640
1074
|
}
|
|
1641
1075
|
this._topology.update();
|
|
1642
1076
|
}
|
|
1643
|
-
async onOffer(message) {
|
|
1077
|
+
async onOffer(ctx, message) {
|
|
1644
1078
|
log4("offer", {
|
|
1645
1079
|
message
|
|
1646
|
-
}, {
|
|
1647
|
-
F: __dxlog_file4,
|
|
1648
|
-
L: 209,
|
|
1649
|
-
S: this,
|
|
1650
|
-
C: (f, a) => f(...a)
|
|
1651
|
-
});
|
|
1080
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 174, S: this });
|
|
1652
1081
|
if (this._ctx.disposed) {
|
|
1653
|
-
log4("ignored for disposed swarm", void 0, {
|
|
1654
|
-
F: __dxlog_file4,
|
|
1655
|
-
L: 211,
|
|
1656
|
-
S: this,
|
|
1657
|
-
C: (f, a) => f(...a)
|
|
1658
|
-
});
|
|
1082
|
+
log4("ignored for disposed swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 178, S: this });
|
|
1659
1083
|
return {
|
|
1660
1084
|
accept: false
|
|
1661
1085
|
};
|
|
1662
1086
|
}
|
|
1663
|
-
invariant4(message.author, void 0, {
|
|
1664
|
-
F: __dxlog_file4,
|
|
1665
|
-
L: 216,
|
|
1666
|
-
S: this,
|
|
1667
|
-
A: [
|
|
1668
|
-
"message.author",
|
|
1669
|
-
""
|
|
1670
|
-
]
|
|
1671
|
-
});
|
|
1087
|
+
invariant4(message.author, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 184, S: this, A: ["message.author", ""] });
|
|
1672
1088
|
if (message.recipient.peerKey !== this._ownPeer.peerKey) {
|
|
1673
1089
|
log4("rejecting offer with incorrect peerId", {
|
|
1674
1090
|
message
|
|
1675
|
-
}, {
|
|
1676
|
-
F: __dxlog_file4,
|
|
1677
|
-
L: 218,
|
|
1678
|
-
S: this,
|
|
1679
|
-
C: (f, a) => f(...a)
|
|
1680
|
-
});
|
|
1091
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 186, S: this });
|
|
1681
1092
|
return {
|
|
1682
1093
|
accept: false
|
|
1683
1094
|
};
|
|
@@ -1685,18 +1096,13 @@ var Swarm = class {
|
|
|
1685
1096
|
if (!message.topic?.equals(this._topic)) {
|
|
1686
1097
|
log4("rejecting offer with incorrect topic", {
|
|
1687
1098
|
message
|
|
1688
|
-
}, {
|
|
1689
|
-
F: __dxlog_file4,
|
|
1690
|
-
L: 222,
|
|
1691
|
-
S: this,
|
|
1692
|
-
C: (f, a) => f(...a)
|
|
1693
|
-
});
|
|
1099
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 194, S: this });
|
|
1694
1100
|
return {
|
|
1695
1101
|
accept: false
|
|
1696
1102
|
};
|
|
1697
1103
|
}
|
|
1698
1104
|
const peer = this._getOfferSenderPeer(message.author);
|
|
1699
|
-
const answer = await peer.onOffer(message);
|
|
1105
|
+
const answer = await peer.onOffer(ctx, message);
|
|
1700
1106
|
this._topology.update();
|
|
1701
1107
|
return answer;
|
|
1702
1108
|
}
|
|
@@ -1710,53 +1116,19 @@ var Swarm = class {
|
|
|
1710
1116
|
}
|
|
1711
1117
|
return peer;
|
|
1712
1118
|
}
|
|
1713
|
-
async onSignal(message) {
|
|
1119
|
+
async onSignal(ctx, message) {
|
|
1714
1120
|
log4("signal", {
|
|
1715
1121
|
message
|
|
1716
|
-
}, {
|
|
1717
|
-
F: __dxlog_file4,
|
|
1718
|
-
L: 247,
|
|
1719
|
-
S: this,
|
|
1720
|
-
C: (f, a) => f(...a)
|
|
1721
|
-
});
|
|
1122
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 218, S: this });
|
|
1722
1123
|
if (this._ctx.disposed) {
|
|
1723
|
-
log4.info("ignored for offline swarm", void 0, {
|
|
1724
|
-
F: __dxlog_file4,
|
|
1725
|
-
L: 249,
|
|
1726
|
-
S: this,
|
|
1727
|
-
C: (f, a) => f(...a)
|
|
1728
|
-
});
|
|
1124
|
+
log4.info("ignored for offline swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 222, S: this });
|
|
1729
1125
|
return;
|
|
1730
1126
|
}
|
|
1731
|
-
invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
S: this,
|
|
1735
|
-
A: [
|
|
1736
|
-
"message.recipient.peerKey === this._ownPeer.peerKey",
|
|
1737
|
-
"`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
|
|
1738
|
-
]
|
|
1739
|
-
});
|
|
1740
|
-
invariant4(message.topic?.equals(this._topic), void 0, {
|
|
1741
|
-
F: __dxlog_file4,
|
|
1742
|
-
L: 256,
|
|
1743
|
-
S: this,
|
|
1744
|
-
A: [
|
|
1745
|
-
"message.topic?.equals(this._topic)",
|
|
1746
|
-
""
|
|
1747
|
-
]
|
|
1748
|
-
});
|
|
1749
|
-
invariant4(message.author, void 0, {
|
|
1750
|
-
F: __dxlog_file4,
|
|
1751
|
-
L: 257,
|
|
1752
|
-
S: this,
|
|
1753
|
-
A: [
|
|
1754
|
-
"message.author",
|
|
1755
|
-
""
|
|
1756
|
-
]
|
|
1757
|
-
});
|
|
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", ""] });
|
|
1758
1130
|
const peer = this._getOrCreatePeer(message.author);
|
|
1759
|
-
await peer.onSignal(message);
|
|
1131
|
+
await peer.onSignal(ctx, message);
|
|
1760
1132
|
}
|
|
1761
1133
|
// For debug purposes
|
|
1762
1134
|
async goOffline() {
|
|
@@ -1767,21 +1139,10 @@ var Swarm = class {
|
|
|
1767
1139
|
}
|
|
1768
1140
|
// For debug purposes
|
|
1769
1141
|
async goOnline() {
|
|
1770
|
-
this._ctx = new
|
|
1771
|
-
F: __dxlog_file4,
|
|
1772
|
-
L: 273
|
|
1773
|
-
});
|
|
1142
|
+
this._ctx = new Context3(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 240 });
|
|
1774
1143
|
}
|
|
1775
1144
|
_getOrCreatePeer(peerInfo) {
|
|
1776
|
-
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
|
|
1777
|
-
F: __dxlog_file4,
|
|
1778
|
-
L: 277,
|
|
1779
|
-
S: this,
|
|
1780
|
-
A: [
|
|
1781
|
-
"peerInfo.peerKey",
|
|
1782
|
-
"'PeerInfo.peerKey is required'"
|
|
1783
|
-
]
|
|
1784
|
-
});
|
|
1145
|
+
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 243, S: this, A: ["peerInfo.peerKey", "'PeerInfo.peerKey is required'"] });
|
|
1785
1146
|
let peer = this._peers.get(peerInfo);
|
|
1786
1147
|
if (!peer) {
|
|
1787
1148
|
peer = new Peer(peerInfo, this._topic, this._ownPeer, this._swarmMessenger, this._protocolProvider, this._transportFactory, this._connectionLimiter, {
|
|
@@ -1793,12 +1154,7 @@ var Swarm = class {
|
|
|
1793
1154
|
},
|
|
1794
1155
|
onDisconnected: async () => {
|
|
1795
1156
|
if (this._isUnregistered(peer)) {
|
|
1796
|
-
log4.verbose("ignored onDisconnected for unregistered peer", void 0, {
|
|
1797
|
-
F: __dxlog_file4,
|
|
1798
|
-
L: 297,
|
|
1799
|
-
S: this,
|
|
1800
|
-
C: (f, a) => f(...a)
|
|
1801
|
-
});
|
|
1157
|
+
log4.verbose("ignored onDisconnected for unregistered peer", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 255, S: this });
|
|
1802
1158
|
return;
|
|
1803
1159
|
}
|
|
1804
1160
|
if (!peer.advertizing) {
|
|
@@ -1811,12 +1167,7 @@ var Swarm = class {
|
|
|
1811
1167
|
if (!this._isUnregistered(peer)) {
|
|
1812
1168
|
log4("peer rejected connection", {
|
|
1813
1169
|
peerInfo
|
|
1814
|
-
}, {
|
|
1815
|
-
F: __dxlog_file4,
|
|
1816
|
-
L: 311,
|
|
1817
|
-
S: this,
|
|
1818
|
-
C: (f, a) => f(...a)
|
|
1819
|
-
});
|
|
1170
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 268, S: this });
|
|
1820
1171
|
void this._destroyPeer(peerInfo, "peer rejected connection");
|
|
1821
1172
|
}
|
|
1822
1173
|
},
|
|
@@ -1824,7 +1175,7 @@ var Swarm = class {
|
|
|
1824
1175
|
this._topology.update();
|
|
1825
1176
|
},
|
|
1826
1177
|
onOffer: (remoteId) => {
|
|
1827
|
-
return this._topology.onOffer(
|
|
1178
|
+
return this._topology.onOffer(PublicKey3.from(remoteId.peerKey));
|
|
1828
1179
|
},
|
|
1829
1180
|
onPeerAvailable: () => {
|
|
1830
1181
|
this._topology.update();
|
|
@@ -1838,32 +1189,19 @@ var Swarm = class {
|
|
|
1838
1189
|
log4("destroy peer", {
|
|
1839
1190
|
peerKey: peerInfo.peerKey,
|
|
1840
1191
|
reason
|
|
1841
|
-
}, {
|
|
1842
|
-
F: __dxlog_file4,
|
|
1843
|
-
L: 333,
|
|
1844
|
-
S: this,
|
|
1845
|
-
C: (f, a) => f(...a)
|
|
1846
|
-
});
|
|
1192
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 289, S: this });
|
|
1847
1193
|
const peer = this._peers.get(peerInfo);
|
|
1848
|
-
invariant4(peer, void 0, {
|
|
1849
|
-
F: __dxlog_file4,
|
|
1850
|
-
L: 335,
|
|
1851
|
-
S: this,
|
|
1852
|
-
A: [
|
|
1853
|
-
"peer",
|
|
1854
|
-
""
|
|
1855
|
-
]
|
|
1856
|
-
});
|
|
1194
|
+
invariant4(peer, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 294, S: this, A: ["peer", ""] });
|
|
1857
1195
|
this._peers.delete(peerInfo);
|
|
1858
1196
|
await peer.safeDestroy(reason);
|
|
1859
1197
|
}
|
|
1860
1198
|
_getSwarmController() {
|
|
1861
1199
|
return {
|
|
1862
1200
|
getState: () => ({
|
|
1863
|
-
ownPeerId:
|
|
1864
|
-
connected: Array.from(this._peers.entries()).filter(([_, peer]) => peer.connection).map(([info]) =>
|
|
1865
|
-
candidates: Array.from(this._peers.entries()).filter(([_, peer]) => !peer.connection && peer.advertizing && peer.availableToConnect).map(([info]) =>
|
|
1866
|
-
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))
|
|
1867
1205
|
}),
|
|
1868
1206
|
connect: (peer) => {
|
|
1869
1207
|
if (this._ctx.disposed) {
|
|
@@ -1875,12 +1213,7 @@ var Swarm = class {
|
|
|
1875
1213
|
peerKey: peer.toHex()
|
|
1876
1214
|
});
|
|
1877
1215
|
} catch (err) {
|
|
1878
|
-
log4("initiation error", err, {
|
|
1879
|
-
F: __dxlog_file4,
|
|
1880
|
-
L: 362,
|
|
1881
|
-
S: this,
|
|
1882
|
-
C: (f, a) => f(...a)
|
|
1883
|
-
});
|
|
1216
|
+
log4("initiation error", err, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 317, S: this });
|
|
1884
1217
|
}
|
|
1885
1218
|
});
|
|
1886
1219
|
},
|
|
@@ -1906,12 +1239,7 @@ var Swarm = class {
|
|
|
1906
1239
|
if (remotePeer.peerKey < this._ownPeer.peerKey) {
|
|
1907
1240
|
log4("initiation delay", {
|
|
1908
1241
|
remotePeer
|
|
1909
|
-
}, {
|
|
1910
|
-
F: __dxlog_file4,
|
|
1911
|
-
L: 390,
|
|
1912
|
-
S: this,
|
|
1913
|
-
C: (f, a) => f(...a)
|
|
1914
|
-
});
|
|
1242
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 343, S: this });
|
|
1915
1243
|
await sleep2(this._initiationDelay);
|
|
1916
1244
|
}
|
|
1917
1245
|
if (ctx.disposed) {
|
|
@@ -1925,22 +1253,12 @@ var Swarm = class {
|
|
|
1925
1253
|
}
|
|
1926
1254
|
log4("initiating connection...", {
|
|
1927
1255
|
remotePeer
|
|
1928
|
-
}, {
|
|
1929
|
-
|
|
1930
|
-
L: 406,
|
|
1931
|
-
S: this,
|
|
1932
|
-
C: (f, a) => f(...a)
|
|
1933
|
-
});
|
|
1934
|
-
await peer.initiateConnection();
|
|
1256
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 358, S: this });
|
|
1257
|
+
await peer.initiateConnection(ctx);
|
|
1935
1258
|
this._topology.update();
|
|
1936
1259
|
log4("initiated", {
|
|
1937
1260
|
remotePeer
|
|
1938
|
-
}, {
|
|
1939
|
-
F: __dxlog_file4,
|
|
1940
|
-
L: 409,
|
|
1941
|
-
S: this,
|
|
1942
|
-
C: (f, a) => f(...a)
|
|
1943
|
-
});
|
|
1261
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 363, S: this });
|
|
1944
1262
|
}
|
|
1945
1263
|
async _closeConnection(peerInfo) {
|
|
1946
1264
|
const peer = this._peers.get(peerInfo);
|
|
@@ -1987,7 +1305,7 @@ _ts_decorate3([
|
|
|
1987
1305
|
|
|
1988
1306
|
// src/swarm/swarm-mapper.ts
|
|
1989
1307
|
import { Event as Event4, SubscriptionList } from "@dxos/async";
|
|
1990
|
-
import { PublicKey as
|
|
1308
|
+
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
1991
1309
|
import { log as log5 } from "@dxos/log";
|
|
1992
1310
|
import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
|
|
1993
1311
|
import { ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
@@ -2017,12 +1335,7 @@ var SwarmMapper = class {
|
|
|
2017
1335
|
this._update();
|
|
2018
1336
|
}
|
|
2019
1337
|
_update() {
|
|
2020
|
-
log5("updating swarm", void 0, {
|
|
2021
|
-
F: __dxlog_file5,
|
|
2022
|
-
L: 71,
|
|
2023
|
-
S: this,
|
|
2024
|
-
C: (f, a) => f(...a)
|
|
2025
|
-
});
|
|
1338
|
+
log5("updating swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 40, S: this });
|
|
2026
1339
|
this._peers.clear();
|
|
2027
1340
|
this._peers.set(this._swarm.ownPeer, {
|
|
2028
1341
|
id: this._swarm.ownPeerId,
|
|
@@ -2031,7 +1344,7 @@ var SwarmMapper = class {
|
|
|
2031
1344
|
});
|
|
2032
1345
|
for (const connection of this._swarm.connections) {
|
|
2033
1346
|
this._peers.set(connection.remoteInfo, {
|
|
2034
|
-
id:
|
|
1347
|
+
id: PublicKey4.from(connection.remoteInfo.peerKey),
|
|
2035
1348
|
state: connection.state,
|
|
2036
1349
|
connections: [
|
|
2037
1350
|
this._swarm.ownPeerId
|
|
@@ -2041,12 +1354,7 @@ var SwarmMapper = class {
|
|
|
2041
1354
|
log5("graph changed", {
|
|
2042
1355
|
directConnections: this._swarm.connections.length,
|
|
2043
1356
|
totalPeersInSwarm: this._peers.size
|
|
2044
|
-
}, {
|
|
2045
|
-
F: __dxlog_file5,
|
|
2046
|
-
L: 112,
|
|
2047
|
-
S: this,
|
|
2048
|
-
C: (f, a) => f(...a)
|
|
2049
|
-
});
|
|
1357
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 77, S: this });
|
|
2050
1358
|
this.mapUpdated.emit(Array.from(this._peers.values()));
|
|
2051
1359
|
}
|
|
2052
1360
|
// TODO(burdon): Async open/close.
|
|
@@ -2059,24 +1367,21 @@ var SwarmMapper = class {
|
|
|
2059
1367
|
|
|
2060
1368
|
// src/swarm/connection-limiter.ts
|
|
2061
1369
|
import { DeferredTask as DeferredTask2 } from "@dxos/async";
|
|
2062
|
-
import { Context as
|
|
1370
|
+
import { Context as Context4 } from "@dxos/context";
|
|
2063
1371
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
2064
|
-
import { PublicKey as
|
|
1372
|
+
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
2065
1373
|
import { log as log6 } from "@dxos/log";
|
|
2066
1374
|
import { CancelledError as CancelledError3 } from "@dxos/protocols";
|
|
2067
1375
|
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
2068
1376
|
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
2069
1377
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
|
|
2070
1378
|
var ConnectionLimiter = class {
|
|
2071
|
-
_ctx = new
|
|
2072
|
-
F: __dxlog_file6,
|
|
2073
|
-
L: 23
|
|
2074
|
-
});
|
|
1379
|
+
_ctx = new Context4(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 15 });
|
|
2075
1380
|
_maxConcurrentInitConnections;
|
|
2076
1381
|
/**
|
|
2077
1382
|
* Queue of promises to resolve when initiating connections amount is below the limit.
|
|
2078
1383
|
*/
|
|
2079
|
-
_waitingPromises = new ComplexMap4(
|
|
1384
|
+
_waitingPromises = new ComplexMap4(PublicKey5.hash);
|
|
2080
1385
|
resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
|
|
2081
1386
|
Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
|
|
2082
1387
|
resolve();
|
|
@@ -2089,23 +1394,10 @@ var ConnectionLimiter = class {
|
|
|
2089
1394
|
* @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
|
|
2090
1395
|
*/
|
|
2091
1396
|
async connecting(sessionId) {
|
|
2092
|
-
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
2093
|
-
F: __dxlog_file6,
|
|
2094
|
-
L: 48,
|
|
2095
|
-
S: this,
|
|
2096
|
-
A: [
|
|
2097
|
-
"!this._waitingPromises.has(sessionId)",
|
|
2098
|
-
"'Peer is already waiting for connection'"
|
|
2099
|
-
]
|
|
2100
|
-
});
|
|
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'"] });
|
|
2101
1398
|
log6("waiting", {
|
|
2102
1399
|
sessionId
|
|
2103
|
-
}, {
|
|
2104
|
-
F: __dxlog_file6,
|
|
2105
|
-
L: 49,
|
|
2106
|
-
S: this,
|
|
2107
|
-
C: (f, a) => f(...a)
|
|
2108
|
-
});
|
|
1400
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 32, S: this });
|
|
2109
1401
|
await new Promise((resolve, reject) => {
|
|
2110
1402
|
this._waitingPromises.set(sessionId, {
|
|
2111
1403
|
resolve,
|
|
@@ -2115,12 +1407,7 @@ var ConnectionLimiter = class {
|
|
|
2115
1407
|
});
|
|
2116
1408
|
log6("allow", {
|
|
2117
1409
|
sessionId
|
|
2118
|
-
}, {
|
|
2119
|
-
F: __dxlog_file6,
|
|
2120
|
-
L: 57,
|
|
2121
|
-
S: this,
|
|
2122
|
-
C: (f, a) => f(...a)
|
|
2123
|
-
});
|
|
1410
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 42, S: this });
|
|
2124
1411
|
}
|
|
2125
1412
|
/**
|
|
2126
1413
|
* Rejects promise returned by `connecting` method.
|
|
@@ -2128,12 +1415,7 @@ var ConnectionLimiter = class {
|
|
|
2128
1415
|
doneConnecting(sessionId) {
|
|
2129
1416
|
log6("done", {
|
|
2130
1417
|
sessionId
|
|
2131
|
-
}, {
|
|
2132
|
-
F: __dxlog_file6,
|
|
2133
|
-
L: 64,
|
|
2134
|
-
S: this,
|
|
2135
|
-
C: (f, a) => f(...a)
|
|
2136
|
-
});
|
|
1418
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 49, S: this });
|
|
2137
1419
|
if (!this._waitingPromises.has(sessionId)) {
|
|
2138
1420
|
return;
|
|
2139
1421
|
}
|
|
@@ -2146,7 +1428,7 @@ var ConnectionLimiter = class {
|
|
|
2146
1428
|
// src/connection-log.ts
|
|
2147
1429
|
import { Event as Event5 } from "@dxos/async";
|
|
2148
1430
|
import { raise } from "@dxos/debug";
|
|
2149
|
-
import { PublicKey as
|
|
1431
|
+
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
2150
1432
|
import { ComplexMap as ComplexMap5 } from "@dxos/util";
|
|
2151
1433
|
var CONNECTION_GC_THRESHOLD = 1e3 * 60 * 15;
|
|
2152
1434
|
var EventType = /* @__PURE__ */ (function(EventType2) {
|
|
@@ -2161,7 +1443,7 @@ var ConnectionLog = class {
|
|
|
2161
1443
|
/**
|
|
2162
1444
|
* SwarmId => info
|
|
2163
1445
|
*/
|
|
2164
|
-
_swarms = new ComplexMap5(
|
|
1446
|
+
_swarms = new ComplexMap5(PublicKey6.hash);
|
|
2165
1447
|
update = new Event5();
|
|
2166
1448
|
getSwarmInfo(swarmId) {
|
|
2167
1449
|
return this._swarms.get(swarmId) ?? raise(new Error(`Swarm not found: ${swarmId}`));
|
|
@@ -2171,19 +1453,19 @@ var ConnectionLog = class {
|
|
|
2171
1453
|
}
|
|
2172
1454
|
joinedSwarm(swarm) {
|
|
2173
1455
|
const info = {
|
|
2174
|
-
id:
|
|
1456
|
+
id: PublicKey6.from(swarm._instanceId),
|
|
2175
1457
|
topic: swarm.topic,
|
|
2176
1458
|
isActive: true,
|
|
2177
1459
|
label: swarm.label,
|
|
2178
1460
|
connections: []
|
|
2179
1461
|
};
|
|
2180
|
-
this._swarms.set(
|
|
1462
|
+
this._swarms.set(PublicKey6.from(swarm._instanceId), info);
|
|
2181
1463
|
this.update.emit();
|
|
2182
1464
|
swarm.connectionAdded.on((connection) => {
|
|
2183
1465
|
const connectionInfo = {
|
|
2184
1466
|
state: ConnectionState.CREATED,
|
|
2185
1467
|
closeReason: connection.closeReason,
|
|
2186
|
-
remotePeerId:
|
|
1468
|
+
remotePeerId: PublicKey6.from(connection.remoteInfo.peerKey),
|
|
2187
1469
|
sessionId: connection.sessionId,
|
|
2188
1470
|
transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
|
|
2189
1471
|
protocolExtensions: [],
|
|
@@ -2223,7 +1505,7 @@ var ConnectionLog = class {
|
|
|
2223
1505
|
});
|
|
2224
1506
|
}
|
|
2225
1507
|
leftSwarm(swarm) {
|
|
2226
|
-
this.getSwarmInfo(
|
|
1508
|
+
this.getSwarmInfo(PublicKey6.from(swarm._instanceId)).isActive = false;
|
|
2227
1509
|
this.update.emit();
|
|
2228
1510
|
}
|
|
2229
1511
|
};
|
|
@@ -2236,32 +1518,30 @@ var gcSwarm = (swarm) => {
|
|
|
2236
1518
|
// src/network-manager.ts
|
|
2237
1519
|
import { Event as Event6, synchronized as synchronized4 } from "@dxos/async";
|
|
2238
1520
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
2239
|
-
import { PublicKey as
|
|
1521
|
+
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
2240
1522
|
import { log as log7 } from "@dxos/log";
|
|
2241
1523
|
import { Messenger } from "@dxos/messaging";
|
|
2242
|
-
import { trace as trace3 } from "@dxos/protocols";
|
|
2243
1524
|
import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2244
1525
|
import { ComplexMap as ComplexMap6 } from "@dxos/util";
|
|
1526
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2245
1527
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
2246
1528
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2247
1529
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2248
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;
|
|
2249
1531
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2250
1532
|
}
|
|
2251
|
-
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2252
1533
|
var SwarmNetworkManager = class {
|
|
2253
1534
|
/**
|
|
2254
1535
|
* @internal
|
|
2255
1536
|
*/
|
|
2256
|
-
_swarms = new ComplexMap6(
|
|
2257
|
-
_mappers = new ComplexMap6(
|
|
1537
|
+
_swarms = new ComplexMap6(PublicKey7.hash);
|
|
1538
|
+
_mappers = new ComplexMap6(PublicKey7.hash);
|
|
2258
1539
|
_transportFactory;
|
|
2259
1540
|
_signalManager;
|
|
2260
1541
|
_messenger;
|
|
2261
1542
|
_signalConnection;
|
|
2262
1543
|
_connectionLimiter;
|
|
2263
1544
|
_connectionLog;
|
|
2264
|
-
_instanceId = PublicKey8.random().toHex();
|
|
2265
1545
|
_peerInfo = void 0;
|
|
2266
1546
|
_connectionState = ConnectionState2.ONLINE;
|
|
2267
1547
|
connectionStateChanged = new Event6();
|
|
@@ -2274,8 +1554,8 @@ var SwarmNetworkManager = class {
|
|
|
2274
1554
|
signalManager: this._signalManager
|
|
2275
1555
|
});
|
|
2276
1556
|
this._signalConnection = {
|
|
2277
|
-
join: (opts) => this._signalManager.join(opts),
|
|
2278
|
-
leave: (opts) => this._signalManager.leave(opts)
|
|
1557
|
+
join: (ctx, opts) => this._signalManager.join(ctx, opts),
|
|
1558
|
+
leave: (ctx, opts) => this._signalManager.leave(ctx, opts)
|
|
2279
1559
|
};
|
|
2280
1560
|
this._peerInfo = peerInfo;
|
|
2281
1561
|
this._connectionLimiter = new ConnectionLimiter();
|
|
@@ -2304,34 +1584,15 @@ var SwarmNetworkManager = class {
|
|
|
2304
1584
|
this._peerInfo = peerInfo;
|
|
2305
1585
|
}
|
|
2306
1586
|
async open() {
|
|
2307
|
-
log7
|
|
2308
|
-
id: this._instanceId
|
|
2309
|
-
}), {
|
|
2310
|
-
F: __dxlog_file7,
|
|
2311
|
-
L: 133,
|
|
2312
|
-
S: this,
|
|
2313
|
-
C: (f, a) => f(...a)
|
|
2314
|
-
});
|
|
1587
|
+
log7("opening network manager", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 76, S: this });
|
|
2315
1588
|
await this._messenger.open();
|
|
2316
1589
|
await this._signalManager.open();
|
|
2317
|
-
log7
|
|
2318
|
-
id: this._instanceId
|
|
2319
|
-
}), {
|
|
2320
|
-
F: __dxlog_file7,
|
|
2321
|
-
L: 136,
|
|
2322
|
-
S: this,
|
|
2323
|
-
C: (f, a) => f(...a)
|
|
2324
|
-
});
|
|
1590
|
+
log7("opened network manager", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 79, S: this });
|
|
2325
1591
|
}
|
|
2326
|
-
async close() {
|
|
1592
|
+
async close(ctx) {
|
|
2327
1593
|
for (const topic of this._swarms.keys()) {
|
|
2328
|
-
await this.leaveSwarm(topic).catch((err) => {
|
|
2329
|
-
log7(err, void 0, {
|
|
2330
|
-
F: __dxlog_file7,
|
|
2331
|
-
L: 142,
|
|
2332
|
-
S: this,
|
|
2333
|
-
C: (f, a) => f(...a)
|
|
2334
|
-
});
|
|
1594
|
+
await this.leaveSwarm(ctx, topic).catch((err) => {
|
|
1595
|
+
log7(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 84, S: this });
|
|
2335
1596
|
});
|
|
2336
1597
|
}
|
|
2337
1598
|
await this._messenger.close();
|
|
@@ -2340,111 +1601,54 @@ var SwarmNetworkManager = class {
|
|
|
2340
1601
|
/**
|
|
2341
1602
|
* Join the swarm.
|
|
2342
1603
|
*/
|
|
2343
|
-
async joinSwarm({ topic, topology, protocolProvider: protocol, label }) {
|
|
2344
|
-
invariant6(
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
A: [
|
|
2349
|
-
"PublicKey.isPublicKey(topic)",
|
|
2350
|
-
""
|
|
2351
|
-
]
|
|
2352
|
-
});
|
|
2353
|
-
invariant6(topology, void 0, {
|
|
2354
|
-
F: __dxlog_file7,
|
|
2355
|
-
L: 161,
|
|
2356
|
-
S: this,
|
|
2357
|
-
A: [
|
|
2358
|
-
"topology",
|
|
2359
|
-
""
|
|
2360
|
-
]
|
|
2361
|
-
});
|
|
2362
|
-
invariant6(this._peerInfo, void 0, {
|
|
2363
|
-
F: __dxlog_file7,
|
|
2364
|
-
L: 162,
|
|
2365
|
-
S: this,
|
|
2366
|
-
A: [
|
|
2367
|
-
"this._peerInfo",
|
|
2368
|
-
""
|
|
2369
|
-
]
|
|
2370
|
-
});
|
|
2371
|
-
invariant6(typeof protocol === "function", void 0, {
|
|
2372
|
-
F: __dxlog_file7,
|
|
2373
|
-
L: 163,
|
|
2374
|
-
S: this,
|
|
2375
|
-
A: [
|
|
2376
|
-
"typeof protocol === 'function'",
|
|
2377
|
-
""
|
|
2378
|
-
]
|
|
2379
|
-
});
|
|
1604
|
+
async joinSwarm(ctx, { topic, topology, protocolProvider: protocol, label }) {
|
|
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'", ""] });
|
|
2380
1609
|
if (this._swarms.has(topic)) {
|
|
2381
|
-
throw new Error(`Already connected to swarm: ${
|
|
1610
|
+
throw new Error(`Already connected to swarm: ${PublicKey7.from(topic)}`);
|
|
2382
1611
|
}
|
|
2383
1612
|
log7("joining", {
|
|
2384
|
-
topic:
|
|
1613
|
+
topic: PublicKey7.from(topic),
|
|
2385
1614
|
peerInfo: this._peerInfo,
|
|
2386
1615
|
topology: topology.toString()
|
|
2387
|
-
}, {
|
|
2388
|
-
F: __dxlog_file7,
|
|
2389
|
-
L: 168,
|
|
2390
|
-
S: this,
|
|
2391
|
-
C: (f, a) => f(...a)
|
|
2392
|
-
});
|
|
1616
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 100, S: this });
|
|
2393
1617
|
const swarm = new Swarm(topic, this._peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
2394
1618
|
swarm.errors.handle((error) => {
|
|
2395
1619
|
log7("swarm error", {
|
|
2396
1620
|
error
|
|
2397
|
-
}, {
|
|
2398
|
-
F: __dxlog_file7,
|
|
2399
|
-
L: 181,
|
|
2400
|
-
S: this,
|
|
2401
|
-
C: (f, a) => f(...a)
|
|
2402
|
-
});
|
|
1621
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 107, S: this });
|
|
2403
1622
|
});
|
|
2404
1623
|
this._swarms.set(topic, swarm);
|
|
2405
1624
|
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
2406
1625
|
await swarm.open();
|
|
2407
|
-
this._signalConnection.join({
|
|
1626
|
+
this._signalConnection.join(ctx, {
|
|
2408
1627
|
topic,
|
|
2409
1628
|
peer: this._peerInfo
|
|
2410
|
-
}).catch((error) => log7.catch(error, void 0, {
|
|
2411
|
-
F: __dxlog_file7,
|
|
2412
|
-
L: 190,
|
|
2413
|
-
S: this,
|
|
2414
|
-
C: (f, a) => f(...a)
|
|
2415
|
-
}));
|
|
1629
|
+
}).catch((error) => log7.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 118, S: this }));
|
|
2416
1630
|
this.topicsUpdated.emit();
|
|
2417
1631
|
this._connectionLog?.joinedSwarm(swarm);
|
|
2418
1632
|
log7("joined", {
|
|
2419
|
-
topic:
|
|
1633
|
+
topic: PublicKey7.from(topic),
|
|
2420
1634
|
count: this._swarms.size
|
|
2421
|
-
}, {
|
|
2422
|
-
F: __dxlog_file7,
|
|
2423
|
-
L: 194,
|
|
2424
|
-
S: this,
|
|
2425
|
-
C: (f, a) => f(...a)
|
|
2426
|
-
});
|
|
1635
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 121, S: this });
|
|
2427
1636
|
return {
|
|
2428
|
-
close: () => this.leaveSwarm(topic)
|
|
1637
|
+
close: (ctx2) => this.leaveSwarm(ctx2, topic)
|
|
2429
1638
|
};
|
|
2430
1639
|
}
|
|
2431
1640
|
/**
|
|
2432
1641
|
* Close the connection.
|
|
2433
1642
|
*/
|
|
2434
|
-
async leaveSwarm(topic) {
|
|
1643
|
+
async leaveSwarm(ctx, topic) {
|
|
2435
1644
|
if (!this._swarms.has(topic)) {
|
|
2436
1645
|
return;
|
|
2437
1646
|
}
|
|
2438
1647
|
log7("leaving", {
|
|
2439
|
-
topic:
|
|
2440
|
-
}, {
|
|
2441
|
-
F: __dxlog_file7,
|
|
2442
|
-
L: 211,
|
|
2443
|
-
S: this,
|
|
2444
|
-
C: (f, a) => f(...a)
|
|
2445
|
-
});
|
|
1648
|
+
topic: PublicKey7.from(topic)
|
|
1649
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 136, S: this });
|
|
2446
1650
|
const swarm = this._swarms.get(topic);
|
|
2447
|
-
await this._signalConnection.leave({
|
|
1651
|
+
await this._signalConnection.leave(ctx, {
|
|
2448
1652
|
topic,
|
|
2449
1653
|
peer: swarm.ownPeer
|
|
2450
1654
|
});
|
|
@@ -2456,14 +1660,9 @@ var SwarmNetworkManager = class {
|
|
|
2456
1660
|
this._swarms.delete(topic);
|
|
2457
1661
|
this.topicsUpdated.emit();
|
|
2458
1662
|
log7("left", {
|
|
2459
|
-
topic:
|
|
1663
|
+
topic: PublicKey7.from(topic),
|
|
2460
1664
|
count: this._swarms.size
|
|
2461
|
-
}, {
|
|
2462
|
-
F: __dxlog_file7,
|
|
2463
|
-
L: 225,
|
|
2464
|
-
S: this,
|
|
2465
|
-
C: (f, a) => f(...a)
|
|
2466
|
-
});
|
|
1665
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 151, S: this });
|
|
2467
1666
|
}
|
|
2468
1667
|
async setConnectionState(state) {
|
|
2469
1668
|
if (state === this._connectionState) {
|
|
@@ -2508,27 +1707,11 @@ var FullyConnectedTopology = class {
|
|
|
2508
1707
|
return "FullyConnectedTopology";
|
|
2509
1708
|
}
|
|
2510
1709
|
init(controller) {
|
|
2511
|
-
invariant7(!this._controller, "Already initialized", {
|
|
2512
|
-
F: __dxlog_file8,
|
|
2513
|
-
L: 18,
|
|
2514
|
-
S: this,
|
|
2515
|
-
A: [
|
|
2516
|
-
"!this._controller",
|
|
2517
|
-
"'Already initialized'"
|
|
2518
|
-
]
|
|
2519
|
-
});
|
|
1710
|
+
invariant7(!this._controller, "Already initialized", { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 11, S: this, A: ["!this._controller", "'Already initialized'"] });
|
|
2520
1711
|
this._controller = controller;
|
|
2521
1712
|
}
|
|
2522
1713
|
update() {
|
|
2523
|
-
invariant7(this._controller, "Not initialized", {
|
|
2524
|
-
F: __dxlog_file8,
|
|
2525
|
-
L: 23,
|
|
2526
|
-
S: this,
|
|
2527
|
-
A: [
|
|
2528
|
-
"this._controller",
|
|
2529
|
-
"'Not initialized'"
|
|
2530
|
-
]
|
|
2531
|
-
});
|
|
1714
|
+
invariant7(this._controller, "Not initialized", { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 15, S: this, A: ["this._controller", "'Not initialized'"] });
|
|
2532
1715
|
const { candidates: discovered } = this._controller.getState();
|
|
2533
1716
|
for (const peer of discovered) {
|
|
2534
1717
|
this._controller.connect(peer);
|
|
@@ -2546,16 +1729,16 @@ import { Transform } from "@dxos/node-std/stream";
|
|
|
2546
1729
|
import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
|
|
2547
1730
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
2548
1731
|
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2549
|
-
import { PublicKey as
|
|
1732
|
+
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2550
1733
|
import { log as log8, logInfo as logInfo3 } from "@dxos/log";
|
|
2551
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";
|
|
2552
1736
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
2553
1737
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2554
1738
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2555
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;
|
|
2556
1740
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2557
1741
|
}
|
|
2558
|
-
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
2559
1742
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
2560
1743
|
var createStreamDelay = (delay) => {
|
|
2561
1744
|
return new Transform({
|
|
@@ -2571,8 +1754,8 @@ var MemoryTransportFactory = {
|
|
|
2571
1754
|
var MemoryTransport = class _MemoryTransport {
|
|
2572
1755
|
_options;
|
|
2573
1756
|
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
2574
|
-
static _connections = new ComplexMap7(
|
|
2575
|
-
_instanceId =
|
|
1757
|
+
static _connections = new ComplexMap7(PublicKey8.hash);
|
|
1758
|
+
_instanceId = PublicKey8.random();
|
|
2576
1759
|
_remote = new Trigger2();
|
|
2577
1760
|
_outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2578
1761
|
_incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
@@ -2584,34 +1767,16 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2584
1767
|
errors = new ErrorStream3();
|
|
2585
1768
|
constructor(_options) {
|
|
2586
1769
|
this._options = _options;
|
|
2587
|
-
invariant8(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2588
|
-
F: __dxlog_file9,
|
|
2589
|
-
L: 64,
|
|
2590
|
-
S: this,
|
|
2591
|
-
A: [
|
|
2592
|
-
"!MemoryTransport._connections.has(this._instanceId)",
|
|
2593
|
-
"'Duplicate memory connection'"
|
|
2594
|
-
]
|
|
2595
|
-
});
|
|
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'"] });
|
|
2596
1771
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
2597
1772
|
}
|
|
2598
1773
|
get isOpen() {
|
|
2599
1774
|
return !this._closed;
|
|
2600
1775
|
}
|
|
2601
1776
|
async open() {
|
|
2602
|
-
log8("opening...", void 0, {
|
|
2603
|
-
F: __dxlog_file9,
|
|
2604
|
-
L: 74,
|
|
2605
|
-
S: this,
|
|
2606
|
-
C: (f, a) => f(...a)
|
|
2607
|
-
});
|
|
1777
|
+
log8("opening...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 59, S: this });
|
|
2608
1778
|
if (this._options.initiator) {
|
|
2609
|
-
log8("sending signal", void 0, {
|
|
2610
|
-
F: __dxlog_file9,
|
|
2611
|
-
L: 78,
|
|
2612
|
-
S: this,
|
|
2613
|
-
C: (f, a) => f(...a)
|
|
2614
|
-
});
|
|
1779
|
+
log8("sending signal", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 62, S: this });
|
|
2615
1780
|
try {
|
|
2616
1781
|
await this._options.sendSignal({
|
|
2617
1782
|
payload: {
|
|
@@ -2637,23 +1802,10 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2637
1802
|
this.closed.emit();
|
|
2638
1803
|
return;
|
|
2639
1804
|
}
|
|
2640
|
-
invariant8(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2641
|
-
F: __dxlog_file9,
|
|
2642
|
-
L: 104,
|
|
2643
|
-
S: this,
|
|
2644
|
-
A: [
|
|
2645
|
-
"!this._remoteConnection._remoteConnection",
|
|
2646
|
-
"`Remote already connected: ${this._remoteInstanceId}`"
|
|
2647
|
-
]
|
|
2648
|
-
});
|
|
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}`"] });
|
|
2649
1806
|
this._remoteConnection._remoteConnection = this;
|
|
2650
1807
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
2651
|
-
log8("connected", void 0, {
|
|
2652
|
-
F: __dxlog_file9,
|
|
2653
|
-
L: 108,
|
|
2654
|
-
S: this,
|
|
2655
|
-
C: (f, a) => f(...a)
|
|
2656
|
-
});
|
|
1808
|
+
log8("connected", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 93, S: this });
|
|
2657
1809
|
this._options.stream.pipe(this._outgoingDelay).pipe(this._remoteConnection._options.stream).pipe(this._incomingDelay).pipe(this._options.stream);
|
|
2658
1810
|
this.connected.emit();
|
|
2659
1811
|
this._remoteConnection.connected.emit();
|
|
@@ -2667,12 +1819,7 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2667
1819
|
return this;
|
|
2668
1820
|
}
|
|
2669
1821
|
async close() {
|
|
2670
|
-
log8("closing...", void 0, {
|
|
2671
|
-
F: __dxlog_file9,
|
|
2672
|
-
L: 130,
|
|
2673
|
-
S: this,
|
|
2674
|
-
C: (f, a) => f(...a)
|
|
2675
|
-
});
|
|
1822
|
+
log8("closing...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 107, S: this });
|
|
2676
1823
|
this._closed = true;
|
|
2677
1824
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
2678
1825
|
if (this._remoteConnection) {
|
|
@@ -2688,29 +1835,19 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2688
1835
|
this._remoteConnection = void 0;
|
|
2689
1836
|
}
|
|
2690
1837
|
this.closed.emit();
|
|
2691
|
-
log8("closed", void 0, {
|
|
2692
|
-
F: __dxlog_file9,
|
|
2693
|
-
L: 158,
|
|
2694
|
-
S: this,
|
|
2695
|
-
C: (f, a) => f(...a)
|
|
2696
|
-
});
|
|
1838
|
+
log8("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 130, S: this });
|
|
2697
1839
|
return this;
|
|
2698
1840
|
}
|
|
2699
1841
|
async onSignal({ payload }) {
|
|
2700
1842
|
log8("received signal", {
|
|
2701
1843
|
payload
|
|
2702
|
-
}, {
|
|
2703
|
-
F: __dxlog_file9,
|
|
2704
|
-
L: 163,
|
|
2705
|
-
S: this,
|
|
2706
|
-
C: (f, a) => f(...a)
|
|
2707
|
-
});
|
|
1844
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 134, S: this });
|
|
2708
1845
|
if (!payload?.transportId) {
|
|
2709
1846
|
return;
|
|
2710
1847
|
}
|
|
2711
1848
|
const transportId = payload.transportId;
|
|
2712
1849
|
if (transportId) {
|
|
2713
|
-
const remoteId =
|
|
1850
|
+
const remoteId = PublicKey8.fromHex(transportId);
|
|
2714
1851
|
this._remote.wake(remoteId);
|
|
2715
1852
|
}
|
|
2716
1853
|
}
|
|
@@ -2793,7 +1930,7 @@ import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } f
|
|
|
2793
1930
|
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2794
1931
|
import { log as log10, logInfo as logInfo4 } from "@dxos/log";
|
|
2795
1932
|
import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
|
|
2796
|
-
import { trace
|
|
1933
|
+
import { trace } from "@dxos/tracing";
|
|
2797
1934
|
|
|
2798
1935
|
// src/transport/webrtc/rtc-transport-channel.ts
|
|
2799
1936
|
import { Duplex } from "@dxos/node-std/stream";
|
|
@@ -2877,15 +2014,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2877
2014
|
}
|
|
2878
2015
|
}
|
|
2879
2016
|
async _open() {
|
|
2880
|
-
invariant9(!this._isChannelCreationInProgress, void 0, {
|
|
2881
|
-
F: __dxlog_file10,
|
|
2882
|
-
L: 57,
|
|
2883
|
-
S: this,
|
|
2884
|
-
A: [
|
|
2885
|
-
"!this._isChannelCreationInProgress",
|
|
2886
|
-
""
|
|
2887
|
-
]
|
|
2888
|
-
});
|
|
2017
|
+
invariant9(!this._isChannelCreationInProgress, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 41, S: this, A: ["!this._isChannelCreationInProgress", ""] });
|
|
2889
2018
|
this._isChannelCreationInProgress = true;
|
|
2890
2019
|
this._connection.createDataChannel(this._options.topic).then((channel) => {
|
|
2891
2020
|
if (this.isOpen) {
|
|
@@ -2903,12 +2032,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2903
2032
|
} else {
|
|
2904
2033
|
log9.verbose("connection establishment failed after transport was closed", {
|
|
2905
2034
|
err
|
|
2906
|
-
}, {
|
|
2907
|
-
F: __dxlog_file10,
|
|
2908
|
-
L: 77,
|
|
2909
|
-
S: this,
|
|
2910
|
-
C: (f, a) => f(...a)
|
|
2911
|
-
});
|
|
2035
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 57, S: this });
|
|
2912
2036
|
}
|
|
2913
2037
|
}).finally(() => {
|
|
2914
2038
|
this._isChannelCreationInProgress = false;
|
|
@@ -2921,12 +2045,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2921
2045
|
this._stream = void 0;
|
|
2922
2046
|
}
|
|
2923
2047
|
this.closed.emit();
|
|
2924
|
-
log9("closed", void 0, {
|
|
2925
|
-
F: __dxlog_file10,
|
|
2926
|
-
L: 93,
|
|
2927
|
-
S: this,
|
|
2928
|
-
C: (f, a) => f(...a)
|
|
2929
|
-
});
|
|
2048
|
+
log9("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 72, S: this });
|
|
2930
2049
|
}
|
|
2931
2050
|
_initChannel(channel) {
|
|
2932
2051
|
Object.assign(channel, {
|
|
@@ -2934,21 +2053,11 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2934
2053
|
if (!this.isOpen) {
|
|
2935
2054
|
log9.warn("channel opened in a closed transport", {
|
|
2936
2055
|
topic: this._options.topic
|
|
2937
|
-
}, {
|
|
2938
|
-
F: __dxlog_file10,
|
|
2939
|
-
L: 100,
|
|
2940
|
-
S: this,
|
|
2941
|
-
C: (f, a) => f(...a)
|
|
2942
|
-
});
|
|
2056
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 78, S: this });
|
|
2943
2057
|
this._safeCloseChannel(channel);
|
|
2944
2058
|
return;
|
|
2945
2059
|
}
|
|
2946
|
-
log9("onopen", void 0, {
|
|
2947
|
-
F: __dxlog_file10,
|
|
2948
|
-
L: 105,
|
|
2949
|
-
S: this,
|
|
2950
|
-
C: (f, a) => f(...a)
|
|
2951
|
-
});
|
|
2060
|
+
log9("onopen", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 84, S: this });
|
|
2952
2061
|
const duplex = new Duplex({
|
|
2953
2062
|
read: () => {
|
|
2954
2063
|
},
|
|
@@ -2961,22 +2070,12 @@ var RtcTransportChannel = class extends Resource {
|
|
|
2961
2070
|
this.connected.emit();
|
|
2962
2071
|
},
|
|
2963
2072
|
onclose: async () => {
|
|
2964
|
-
log9("onclose", void 0, {
|
|
2965
|
-
F: __dxlog_file10,
|
|
2966
|
-
L: 118,
|
|
2967
|
-
S: this,
|
|
2968
|
-
C: (f, a) => f(...a)
|
|
2969
|
-
});
|
|
2073
|
+
log9("onclose", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 96, S: this });
|
|
2970
2074
|
await this.close();
|
|
2971
2075
|
},
|
|
2972
2076
|
onmessage: async (event) => {
|
|
2973
2077
|
if (!this._stream) {
|
|
2974
|
-
log9.warn("ignoring message on a closed channel", void 0, {
|
|
2975
|
-
F: __dxlog_file10,
|
|
2976
|
-
L: 124,
|
|
2977
|
-
S: this,
|
|
2978
|
-
C: (f, a) => f(...a)
|
|
2979
|
-
});
|
|
2078
|
+
log9.warn("ignoring message on a closed channel", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 101, S: this });
|
|
2980
2079
|
return;
|
|
2981
2080
|
}
|
|
2982
2081
|
let data = event.data;
|
|
@@ -3002,12 +2101,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3002
2101
|
}
|
|
3003
2102
|
async _handleChannelWrite(chunk, callback) {
|
|
3004
2103
|
if (!this._channel) {
|
|
3005
|
-
log9.warn("writing to a channel after a connection was closed", void 0, {
|
|
3006
|
-
F: __dxlog_file10,
|
|
3007
|
-
L: 154,
|
|
3008
|
-
S: this,
|
|
3009
|
-
C: (f, a) => f(...a)
|
|
3010
|
-
});
|
|
2104
|
+
log9.warn("writing to a channel after a connection was closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 127, S: this });
|
|
3011
2105
|
return;
|
|
3012
2106
|
}
|
|
3013
2107
|
if (chunk.length > MAX_MESSAGE_SIZE) {
|
|
@@ -3025,12 +2119,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3025
2119
|
}
|
|
3026
2120
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3027
2121
|
if (this._streamDataFlushedCallback !== null) {
|
|
3028
|
-
log9.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3029
|
-
F: __dxlog_file10,
|
|
3030
|
-
L: 175,
|
|
3031
|
-
S: this,
|
|
3032
|
-
C: (f, a) => f(...a)
|
|
3033
|
-
});
|
|
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 });
|
|
3034
2123
|
}
|
|
3035
2124
|
this._streamDataFlushedCallback = callback;
|
|
3036
2125
|
} else {
|
|
@@ -3041,12 +2130,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3041
2130
|
try {
|
|
3042
2131
|
channel.close();
|
|
3043
2132
|
} catch (error) {
|
|
3044
|
-
log9.catch(error, void 0, {
|
|
3045
|
-
F: __dxlog_file10,
|
|
3046
|
-
L: 187,
|
|
3047
|
-
S: this,
|
|
3048
|
-
C: (f, a) => f(...a)
|
|
3049
|
-
});
|
|
2133
|
+
log9.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 156, S: this });
|
|
3050
2134
|
}
|
|
3051
2135
|
}
|
|
3052
2136
|
onSignal(signal) {
|
|
@@ -3087,13 +2171,13 @@ var deduplicatedSdpLines = (sdp) => {
|
|
|
3087
2171
|
};
|
|
3088
2172
|
|
|
3089
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";
|
|
3090
2175
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
3091
2176
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3092
2177
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3093
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;
|
|
3094
2179
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3095
2180
|
}
|
|
3096
|
-
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
|
|
3097
2181
|
var RtcPeerConnection = class {
|
|
3098
2182
|
_factory;
|
|
3099
2183
|
_options;
|
|
@@ -3141,12 +2225,7 @@ var RtcPeerConnection = class {
|
|
|
3141
2225
|
if (existingChannel) {
|
|
3142
2226
|
return existingChannel;
|
|
3143
2227
|
}
|
|
3144
|
-
log10("waiting for initiator-peer to open a data channel", void 0, {
|
|
3145
|
-
F: __dxlog_file11,
|
|
3146
|
-
L: 96,
|
|
3147
|
-
S: this,
|
|
3148
|
-
C: (f, a) => f(...a)
|
|
3149
|
-
});
|
|
2228
|
+
log10("waiting for initiator-peer to open a data channel", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 63, S: this });
|
|
3150
2229
|
return new Promise((resolve, reject) => {
|
|
3151
2230
|
this._channelCreatedCallbacks.set(topic, {
|
|
3152
2231
|
resolve,
|
|
@@ -3172,36 +2251,18 @@ var RtcPeerConnection = class {
|
|
|
3172
2251
|
}
|
|
3173
2252
|
log10("initializing connection...", () => ({
|
|
3174
2253
|
remotePeer: this._options.remotePeerKey
|
|
3175
|
-
}), {
|
|
3176
|
-
F: __dxlog_file11,
|
|
3177
|
-
L: 121,
|
|
3178
|
-
S: this,
|
|
3179
|
-
C: (f, a) => f(...a)
|
|
3180
|
-
});
|
|
2254
|
+
}), { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 87, S: this });
|
|
3181
2255
|
const config = await this._loadConnectionConfig();
|
|
3182
2256
|
const connection = await this._factory.createConnection(config);
|
|
3183
2257
|
const iceCandidateErrors = [];
|
|
3184
2258
|
Object.assign(connection, {
|
|
3185
2259
|
onnegotiationneeded: async () => {
|
|
3186
|
-
invariant10(this._initiator, void 0, {
|
|
3187
|
-
F: __dxlog_file11,
|
|
3188
|
-
L: 136,
|
|
3189
|
-
S: this,
|
|
3190
|
-
A: [
|
|
3191
|
-
"this._initiator",
|
|
3192
|
-
""
|
|
3193
|
-
]
|
|
3194
|
-
});
|
|
2260
|
+
invariant10(this._initiator, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 100, S: this, A: ["this._initiator", ""] });
|
|
3195
2261
|
if (connection !== this._connection) {
|
|
3196
2262
|
this._onConnectionCallbackAfterClose("onnegotiationneeded", connection);
|
|
3197
2263
|
return;
|
|
3198
2264
|
}
|
|
3199
|
-
log10("onnegotiationneeded", void 0, {
|
|
3200
|
-
F: __dxlog_file11,
|
|
3201
|
-
L: 143,
|
|
3202
|
-
S: this,
|
|
3203
|
-
C: (f, a) => f(...a)
|
|
3204
|
-
});
|
|
2265
|
+
log10("onnegotiationneeded", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 105, S: this });
|
|
3205
2266
|
try {
|
|
3206
2267
|
const offer = await connection.createOffer();
|
|
3207
2268
|
await connection.setLocalDescription(offer);
|
|
@@ -3220,20 +2281,10 @@ var RtcPeerConnection = class {
|
|
|
3220
2281
|
if (event.candidate) {
|
|
3221
2282
|
log10("onicecandidate", {
|
|
3222
2283
|
candidate: event.candidate.candidate
|
|
3223
|
-
}, {
|
|
3224
|
-
F: __dxlog_file11,
|
|
3225
|
-
L: 162,
|
|
3226
|
-
S: this,
|
|
3227
|
-
C: (f, a) => f(...a)
|
|
3228
|
-
});
|
|
2284
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 122, S: this });
|
|
3229
2285
|
await this._sendIceCandidate(event.candidate);
|
|
3230
2286
|
} else {
|
|
3231
|
-
log10("onicecandidate gathering complete", void 0, {
|
|
3232
|
-
F: __dxlog_file11,
|
|
3233
|
-
L: 165,
|
|
3234
|
-
S: this,
|
|
3235
|
-
C: (f, a) => f(...a)
|
|
3236
|
-
});
|
|
2287
|
+
log10("onicecandidate gathering complete", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 127, S: this });
|
|
3237
2288
|
}
|
|
3238
2289
|
},
|
|
3239
2290
|
// When error occurs while performing ICE negotiations through a STUN or TURN server.
|
|
@@ -3256,12 +2307,7 @@ var RtcPeerConnection = class {
|
|
|
3256
2307
|
}
|
|
3257
2308
|
log10("oniceconnectionstatechange", {
|
|
3258
2309
|
state: connection.iceConnectionState
|
|
3259
|
-
}, {
|
|
3260
|
-
F: __dxlog_file11,
|
|
3261
|
-
L: 185,
|
|
3262
|
-
S: this,
|
|
3263
|
-
C: (f, a) => f(...a)
|
|
3264
|
-
});
|
|
2310
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 148, S: this });
|
|
3265
2311
|
if (connection.iceConnectionState === "failed") {
|
|
3266
2312
|
void this._lockAndAbort(connection, createIceFailureError(iceCandidateErrors));
|
|
3267
2313
|
}
|
|
@@ -3278,12 +2324,7 @@ var RtcPeerConnection = class {
|
|
|
3278
2324
|
}
|
|
3279
2325
|
log10("onconnectionstatechange", {
|
|
3280
2326
|
state: connection.connectionState
|
|
3281
|
-
}, {
|
|
3282
|
-
F: __dxlog_file11,
|
|
3283
|
-
L: 202,
|
|
3284
|
-
S: this,
|
|
3285
|
-
C: (f, a) => f(...a)
|
|
3286
|
-
});
|
|
2327
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 165, S: this });
|
|
3287
2328
|
if (connection.connectionState === "failed") {
|
|
3288
2329
|
void this._lockAndAbort(connection, new Error("Connection failed."));
|
|
3289
2330
|
}
|
|
@@ -3291,37 +2332,19 @@ var RtcPeerConnection = class {
|
|
|
3291
2332
|
onsignalingstatechange: () => {
|
|
3292
2333
|
log10("onsignalingstatechange", {
|
|
3293
2334
|
state: connection.signalingState
|
|
3294
|
-
}, {
|
|
3295
|
-
F: __dxlog_file11,
|
|
3296
|
-
L: 209,
|
|
3297
|
-
S: this,
|
|
3298
|
-
C: (f, a) => f(...a)
|
|
3299
|
-
});
|
|
2335
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 173, S: this });
|
|
3300
2336
|
},
|
|
3301
2337
|
// When channel is added to connection.
|
|
3302
2338
|
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event
|
|
3303
2339
|
ondatachannel: (event) => {
|
|
3304
|
-
invariant10(!this._initiator, "Initiator is expected to create data channels.", {
|
|
3305
|
-
F: __dxlog_file11,
|
|
3306
|
-
L: 215,
|
|
3307
|
-
S: this,
|
|
3308
|
-
A: [
|
|
3309
|
-
"!this._initiator",
|
|
3310
|
-
"'Initiator is expected to create data channels.'"
|
|
3311
|
-
]
|
|
3312
|
-
});
|
|
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.'"] });
|
|
3313
2341
|
if (connection !== this._connection) {
|
|
3314
2342
|
this._onConnectionCallbackAfterClose("ondatachannel", connection);
|
|
3315
2343
|
return;
|
|
3316
2344
|
}
|
|
3317
2345
|
log10("ondatachannel", {
|
|
3318
2346
|
label: event.channel.label
|
|
3319
|
-
}, {
|
|
3320
|
-
F: __dxlog_file11,
|
|
3321
|
-
L: 222,
|
|
3322
|
-
S: this,
|
|
3323
|
-
C: (f, a) => f(...a)
|
|
3324
|
-
});
|
|
2347
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 185, S: this });
|
|
3325
2348
|
this._dataChannels.set(event.channel.label, event.channel);
|
|
3326
2349
|
const pendingCallback = this._channelCreatedCallbacks.get(event.channel.label);
|
|
3327
2350
|
if (pendingCallback) {
|
|
@@ -3344,12 +2367,7 @@ var RtcPeerConnection = class {
|
|
|
3344
2367
|
if (connection !== this._connection) {
|
|
3345
2368
|
log10.error("attempted to abort an inactive connection", {
|
|
3346
2369
|
error
|
|
3347
|
-
}, {
|
|
3348
|
-
F: __dxlog_file11,
|
|
3349
|
-
L: 247,
|
|
3350
|
-
S: this,
|
|
3351
|
-
C: (f, a) => f(...a)
|
|
3352
|
-
});
|
|
2370
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 208, S: this });
|
|
3353
2371
|
this._safeCloseConnection(connection);
|
|
3354
2372
|
return;
|
|
3355
2373
|
}
|
|
@@ -3365,31 +2383,13 @@ var RtcPeerConnection = class {
|
|
|
3365
2383
|
this._safeCloseConnection();
|
|
3366
2384
|
log10("connection aborted", {
|
|
3367
2385
|
reason: error.message
|
|
3368
|
-
}, {
|
|
3369
|
-
F: __dxlog_file11,
|
|
3370
|
-
L: 261,
|
|
3371
|
-
S: this,
|
|
3372
|
-
C: (f, a) => f(...a)
|
|
3373
|
-
});
|
|
2386
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 224, S: this });
|
|
3374
2387
|
}
|
|
3375
2388
|
async _lockAndCloseConnection() {
|
|
3376
|
-
invariant10(this._transportChannels.size === 0, void 0, {
|
|
3377
|
-
F: __dxlog_file11,
|
|
3378
|
-
L: 266,
|
|
3379
|
-
S: this,
|
|
3380
|
-
A: [
|
|
3381
|
-
"this._transportChannels.size === 0",
|
|
3382
|
-
""
|
|
3383
|
-
]
|
|
3384
|
-
});
|
|
2389
|
+
invariant10(this._transportChannels.size === 0, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 229, S: this, A: ["this._transportChannels.size === 0", ""] });
|
|
3385
2390
|
if (this._connection) {
|
|
3386
2391
|
this._safeCloseConnection();
|
|
3387
|
-
log10("connection closed", void 0, {
|
|
3388
|
-
F: __dxlog_file11,
|
|
3389
|
-
L: 269,
|
|
3390
|
-
S: this,
|
|
3391
|
-
C: (f, a) => f(...a)
|
|
3392
|
-
});
|
|
2392
|
+
log10("connection closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 232, S: this });
|
|
3393
2393
|
}
|
|
3394
2394
|
}
|
|
3395
2395
|
async onSignal(signal) {
|
|
@@ -3397,12 +2397,7 @@ var RtcPeerConnection = class {
|
|
|
3397
2397
|
if (!connection) {
|
|
3398
2398
|
log10.warn("a signal ignored because the connection was closed", {
|
|
3399
2399
|
type: signal.payload.data.type
|
|
3400
|
-
}, {
|
|
3401
|
-
F: __dxlog_file11,
|
|
3402
|
-
L: 277,
|
|
3403
|
-
S: this,
|
|
3404
|
-
C: (f, a) => f(...a)
|
|
3405
|
-
});
|
|
2400
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 238, S: this });
|
|
3406
2401
|
return;
|
|
3407
2402
|
}
|
|
3408
2403
|
const data = signal.payload.data;
|
|
@@ -3464,12 +2459,7 @@ var RtcPeerConnection = class {
|
|
|
3464
2459
|
}
|
|
3465
2460
|
log10("signal processed", {
|
|
3466
2461
|
type: data.type
|
|
3467
|
-
}, {
|
|
3468
|
-
F: __dxlog_file11,
|
|
3469
|
-
L: 336,
|
|
3470
|
-
S: this,
|
|
3471
|
-
C: (f, a) => f(...a)
|
|
3472
|
-
});
|
|
2462
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 301, S: this });
|
|
3473
2463
|
}
|
|
3474
2464
|
async _processIceCandidate(connection, candidate) {
|
|
3475
2465
|
try {
|
|
@@ -3477,51 +2467,26 @@ var RtcPeerConnection = class {
|
|
|
3477
2467
|
if (connection === this._connection) {
|
|
3478
2468
|
log10("adding ice candidate", {
|
|
3479
2469
|
candidate
|
|
3480
|
-
}, {
|
|
3481
|
-
F: __dxlog_file11,
|
|
3482
|
-
L: 344,
|
|
3483
|
-
S: this,
|
|
3484
|
-
C: (f, a) => f(...a)
|
|
3485
|
-
});
|
|
2470
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 310, S: this });
|
|
3486
2471
|
await connection.addIceCandidate(candidate);
|
|
3487
2472
|
}
|
|
3488
2473
|
} catch (err) {
|
|
3489
|
-
log10.catch(err, void 0, {
|
|
3490
|
-
F: __dxlog_file11,
|
|
3491
|
-
L: 348,
|
|
3492
|
-
S: this,
|
|
3493
|
-
C: (f, a) => f(...a)
|
|
3494
|
-
});
|
|
2474
|
+
log10.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 316, S: this });
|
|
3495
2475
|
}
|
|
3496
2476
|
}
|
|
3497
2477
|
_onSessionNegotiated(connection) {
|
|
3498
2478
|
if (connection === this._connection) {
|
|
3499
|
-
log10("ready to process ice candidates", void 0, {
|
|
3500
|
-
F: __dxlog_file11,
|
|
3501
|
-
L: 354,
|
|
3502
|
-
S: this,
|
|
3503
|
-
C: (f, a) => f(...a)
|
|
3504
|
-
});
|
|
2479
|
+
log10("ready to process ice candidates", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 321, S: this });
|
|
3505
2480
|
this._readyForCandidates.wake();
|
|
3506
2481
|
} else {
|
|
3507
|
-
log10.warn("session was negotiated after connection became inactive", void 0, {
|
|
3508
|
-
F: __dxlog_file11,
|
|
3509
|
-
L: 357,
|
|
3510
|
-
S: this,
|
|
3511
|
-
C: (f, a) => f(...a)
|
|
3512
|
-
});
|
|
2482
|
+
log10.warn("session was negotiated after connection became inactive", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 324, S: this });
|
|
3513
2483
|
}
|
|
3514
2484
|
}
|
|
3515
2485
|
_onConnectionCallbackAfterClose(callback, connection) {
|
|
3516
2486
|
log10.warn("callback invoked after a connection was destroyed, this is probably a bug", {
|
|
3517
2487
|
callback,
|
|
3518
2488
|
state: connection.connectionState
|
|
3519
|
-
}, {
|
|
3520
|
-
F: __dxlog_file11,
|
|
3521
|
-
L: 362,
|
|
3522
|
-
S: this,
|
|
3523
|
-
C: (f, a) => f(...a)
|
|
3524
|
-
});
|
|
2489
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 328, S: this });
|
|
3525
2490
|
this._safeCloseConnection(connection);
|
|
3526
2491
|
}
|
|
3527
2492
|
_safeCloseConnection(connection = this._connection) {
|
|
@@ -3529,23 +2494,13 @@ var RtcPeerConnection = class {
|
|
|
3529
2494
|
try {
|
|
3530
2495
|
connection?.close();
|
|
3531
2496
|
} catch (err) {
|
|
3532
|
-
log10.catch(err, void 0, {
|
|
3533
|
-
F: __dxlog_file11,
|
|
3534
|
-
L: 374,
|
|
3535
|
-
S: this,
|
|
3536
|
-
C: (f, a) => f(...a)
|
|
3537
|
-
});
|
|
2497
|
+
log10.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 339, S: this });
|
|
3538
2498
|
}
|
|
3539
2499
|
if (resetFields) {
|
|
3540
2500
|
this._connection = void 0;
|
|
3541
2501
|
this._dataChannels.clear();
|
|
3542
2502
|
this._readyForCandidates.wake();
|
|
3543
|
-
void this._factory.onConnectionDestroyed().catch((err) => log10.catch(err, void 0, {
|
|
3544
|
-
F: __dxlog_file11,
|
|
3545
|
-
L: 380,
|
|
3546
|
-
S: this,
|
|
3547
|
-
C: (f, a) => f(...a)
|
|
3548
|
-
}));
|
|
2503
|
+
void this._factory.onConnectionDestroyed().catch((err) => log10.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 345, S: this }));
|
|
3549
2504
|
for (const [_, pendingCallback] of this._channelCreatedCallbacks.entries()) {
|
|
3550
2505
|
pendingCallback.reject("Connection closed.");
|
|
3551
2506
|
}
|
|
@@ -3565,12 +2520,7 @@ var RtcPeerConnection = class {
|
|
|
3565
2520
|
];
|
|
3566
2521
|
}
|
|
3567
2522
|
} catch (error) {
|
|
3568
|
-
log10.catch(error, void 0, {
|
|
3569
|
-
F: __dxlog_file11,
|
|
3570
|
-
L: 396,
|
|
3571
|
-
S: this,
|
|
3572
|
-
C: (f, a) => f(...a)
|
|
3573
|
-
});
|
|
2523
|
+
log10.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 365, S: this });
|
|
3574
2524
|
}
|
|
3575
2525
|
return config;
|
|
3576
2526
|
}
|
|
@@ -3592,12 +2542,7 @@ var RtcPeerConnection = class {
|
|
|
3592
2542
|
} catch (err) {
|
|
3593
2543
|
log10.warn("signaling error", {
|
|
3594
2544
|
err
|
|
3595
|
-
}, {
|
|
3596
|
-
F: __dxlog_file11,
|
|
3597
|
-
L: 417,
|
|
3598
|
-
S: this,
|
|
3599
|
-
C: (f, a) => f(...a)
|
|
3600
|
-
});
|
|
2545
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 385, S: this });
|
|
3601
2546
|
}
|
|
3602
2547
|
}
|
|
3603
2548
|
async _sendDescription(connection, description) {
|
|
@@ -3655,13 +2600,13 @@ _ts_decorate6([
|
|
|
3655
2600
|
synchronized5
|
|
3656
2601
|
], RtcPeerConnection.prototype, "onSignal", null);
|
|
3657
2602
|
_ts_decorate6([
|
|
3658
|
-
|
|
2603
|
+
trace.info()
|
|
3659
2604
|
], RtcPeerConnection.prototype, "_connectionInfo", null);
|
|
3660
2605
|
_ts_decorate6([
|
|
3661
2606
|
logInfo4
|
|
3662
2607
|
], RtcPeerConnection.prototype, "_loggerContext", null);
|
|
3663
2608
|
RtcPeerConnection = _ts_decorate6([
|
|
3664
|
-
|
|
2609
|
+
trace.resource()
|
|
3665
2610
|
], RtcPeerConnection);
|
|
3666
2611
|
var isRemoteDescriptionSet = (connection, data) => {
|
|
3667
2612
|
if (!connection.remoteDescription?.type || connection.remoteDescription?.type !== data.type) {
|
|
@@ -3701,7 +2646,7 @@ import { Event as Event8, scheduleTask as scheduleTask4 } from "@dxos/async";
|
|
|
3701
2646
|
import { Resource as Resource2 } from "@dxos/context";
|
|
3702
2647
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
3703
2648
|
import { invariant as invariant11 } from "@dxos/invariant";
|
|
3704
|
-
import { PublicKey as
|
|
2649
|
+
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
3705
2650
|
import { log as log11 } from "@dxos/log";
|
|
3706
2651
|
import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError4, TimeoutError as TimeoutError3 } from "@dxos/protocols";
|
|
3707
2652
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
@@ -3712,7 +2657,7 @@ var CLOSE_RPC_TIMEOUT = 3e3;
|
|
|
3712
2657
|
var RESP_MIN_THRESHOLD = 500;
|
|
3713
2658
|
var RtcTransportProxy = class extends Resource2 {
|
|
3714
2659
|
_options;
|
|
3715
|
-
_proxyId =
|
|
2660
|
+
_proxyId = PublicKey9.random();
|
|
3716
2661
|
closed = new Event8();
|
|
3717
2662
|
connected = new Event8();
|
|
3718
2663
|
errors = new ErrorStream5();
|
|
@@ -3739,12 +2684,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3739
2684
|
this._serviceStream = stream;
|
|
3740
2685
|
stream.waitUntilReady().then(() => {
|
|
3741
2686
|
stream.subscribe(async (event) => {
|
|
3742
|
-
log11("rtc transport proxy event", event, {
|
|
3743
|
-
F: __dxlog_file12,
|
|
3744
|
-
L: 66,
|
|
3745
|
-
S: this,
|
|
3746
|
-
C: (f, a) => f(...a)
|
|
3747
|
-
});
|
|
2687
|
+
log11("rtc transport proxy event", event, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 46, S: this });
|
|
3748
2688
|
if (event.connection) {
|
|
3749
2689
|
await this._handleConnection(event.connection);
|
|
3750
2690
|
} else if (event.data) {
|
|
@@ -3755,12 +2695,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3755
2695
|
}, (err) => {
|
|
3756
2696
|
log11("rtc bridge stream closed", {
|
|
3757
2697
|
err
|
|
3758
|
-
}, {
|
|
3759
|
-
F: __dxlog_file12,
|
|
3760
|
-
L: 76,
|
|
3761
|
-
S: this,
|
|
3762
|
-
C: (f, a) => f(...a)
|
|
3763
|
-
});
|
|
2698
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 55, S: this });
|
|
3764
2699
|
if (err) {
|
|
3765
2700
|
this._raiseIfOpen(err);
|
|
3766
2701
|
} else {
|
|
@@ -3777,12 +2712,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3777
2712
|
timeout: RPC_TIMEOUT
|
|
3778
2713
|
}).then(() => {
|
|
3779
2714
|
if (Date.now() - sendStartMs > RESP_MIN_THRESHOLD) {
|
|
3780
|
-
log11("slow response, delaying callback", void 0, {
|
|
3781
|
-
F: __dxlog_file12,
|
|
3782
|
-
L: 93,
|
|
3783
|
-
S: this,
|
|
3784
|
-
C: (f, a) => f(...a)
|
|
3785
|
-
});
|
|
2715
|
+
log11("slow response, delaying callback", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 74, S: this });
|
|
3786
2716
|
scheduleTask4(this._ctx, () => callback(), RESP_MIN_THRESHOLD);
|
|
3787
2717
|
} else {
|
|
3788
2718
|
callback();
|
|
@@ -3810,12 +2740,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3810
2740
|
await this._serviceStream?.close();
|
|
3811
2741
|
this._serviceStream = void 0;
|
|
3812
2742
|
} catch (err) {
|
|
3813
|
-
log11.catch(err, void 0, {
|
|
3814
|
-
F: __dxlog_file12,
|
|
3815
|
-
L: 128,
|
|
3816
|
-
S: this,
|
|
3817
|
-
C: (f, a) => f(...a)
|
|
3818
|
-
});
|
|
2743
|
+
log11.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 102, S: this });
|
|
3819
2744
|
}
|
|
3820
2745
|
try {
|
|
3821
2746
|
await this._options.bridgeService.close({
|
|
@@ -3824,12 +2749,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3824
2749
|
timeout: CLOSE_RPC_TIMEOUT
|
|
3825
2750
|
});
|
|
3826
2751
|
} catch (err) {
|
|
3827
|
-
log11.catch(err, void 0, {
|
|
3828
|
-
F: __dxlog_file12,
|
|
3829
|
-
L: 134,
|
|
3830
|
-
S: this,
|
|
3831
|
-
C: (f, a) => f(...a)
|
|
3832
|
-
});
|
|
2752
|
+
log11.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 111, S: this });
|
|
3833
2753
|
}
|
|
3834
2754
|
this.closed.emit();
|
|
3835
2755
|
}
|
|
@@ -3912,12 +2832,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
3912
2832
|
} else {
|
|
3913
2833
|
log11.info("error swallowed because transport was closed", {
|
|
3914
2834
|
message: error.message
|
|
3915
|
-
}, {
|
|
3916
|
-
F: __dxlog_file12,
|
|
3917
|
-
L: 217,
|
|
3918
|
-
S: this,
|
|
3919
|
-
C: (f, a) => f(...a)
|
|
3920
|
-
});
|
|
2835
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 195, S: this });
|
|
3921
2836
|
}
|
|
3922
2837
|
}
|
|
3923
2838
|
/**
|
|
@@ -3943,15 +2858,7 @@ var RtcTransportProxyFactory = class {
|
|
|
3943
2858
|
return this;
|
|
3944
2859
|
}
|
|
3945
2860
|
createTransport(options) {
|
|
3946
|
-
invariant11(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
|
|
3947
|
-
F: __dxlog_file12,
|
|
3948
|
-
L: 247,
|
|
3949
|
-
S: this,
|
|
3950
|
-
A: [
|
|
3951
|
-
"this._bridgeService",
|
|
3952
|
-
"'RtcTransportProxyFactory is not ready to open connections'"
|
|
3953
|
-
]
|
|
3954
|
-
});
|
|
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'"] });
|
|
3955
2862
|
const transport = new RtcTransportProxy({
|
|
3956
2863
|
...options,
|
|
3957
2864
|
bridgeService: this._bridgeService
|
|
@@ -3986,14 +2893,14 @@ var decodeError = (err) => {
|
|
|
3986
2893
|
import { Duplex as Duplex2 } from "@dxos/node-std/stream";
|
|
3987
2894
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
3988
2895
|
import { invariant as invariant12 } from "@dxos/invariant";
|
|
3989
|
-
import { PublicKey as
|
|
2896
|
+
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
3990
2897
|
import { log as log12 } from "@dxos/log";
|
|
3991
2898
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
3992
2899
|
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
3993
2900
|
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
|
|
3994
2901
|
var RtcTransportService = class {
|
|
3995
2902
|
_transportFactory;
|
|
3996
|
-
_openTransports = new ComplexMap8(
|
|
2903
|
+
_openTransports = new ComplexMap8(PublicKey10.hash);
|
|
3997
2904
|
constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
|
|
3998
2905
|
this._transportFactory = _transportFactory;
|
|
3999
2906
|
}
|
|
@@ -4003,12 +2910,7 @@ var RtcTransportService = class {
|
|
|
4003
2910
|
open(request) {
|
|
4004
2911
|
const existingTransport = this._openTransports.get(request.proxyId);
|
|
4005
2912
|
if (existingTransport) {
|
|
4006
|
-
log12.error("requesting a new transport bridge for an existing proxy", void 0, {
|
|
4007
|
-
F: __dxlog_file13,
|
|
4008
|
-
L: 54,
|
|
4009
|
-
S: this,
|
|
4010
|
-
C: (f, a) => f(...a)
|
|
4011
|
-
});
|
|
2913
|
+
log12.error("requesting a new transport bridge for an existing proxy", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 24, S: this });
|
|
4012
2914
|
void this._safeCloseTransport(existingTransport);
|
|
4013
2915
|
this._openTransports.delete(request.proxyId);
|
|
4014
2916
|
}
|
|
@@ -4069,69 +2971,32 @@ var RtcTransportService = class {
|
|
|
4069
2971
|
close(err);
|
|
4070
2972
|
});
|
|
4071
2973
|
ready();
|
|
4072
|
-
log12("stream ready", void 0, {
|
|
4073
|
-
F: __dxlog_file13,
|
|
4074
|
-
L: 116,
|
|
4075
|
-
S: this,
|
|
4076
|
-
C: (f, a) => f(...a)
|
|
4077
|
-
});
|
|
2974
|
+
log12("stream ready", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 85, S: this });
|
|
4078
2975
|
pushNewState(ConnectionState4.CONNECTING);
|
|
4079
2976
|
});
|
|
4080
2977
|
}
|
|
4081
2978
|
async sendSignal({ proxyId, signal }) {
|
|
4082
2979
|
const transport = this._openTransports.get(proxyId);
|
|
4083
|
-
invariant12(transport, void 0, {
|
|
4084
|
-
F: __dxlog_file13,
|
|
4085
|
-
L: 124,
|
|
4086
|
-
S: this,
|
|
4087
|
-
A: [
|
|
4088
|
-
"transport",
|
|
4089
|
-
""
|
|
4090
|
-
]
|
|
4091
|
-
});
|
|
2980
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 91, S: this, A: ["transport", ""] });
|
|
4092
2981
|
await transport.transport.onSignal(signal);
|
|
4093
2982
|
}
|
|
4094
2983
|
async getDetails({ proxyId }) {
|
|
4095
2984
|
const transport = this._openTransports.get(proxyId);
|
|
4096
|
-
invariant12(transport, void 0, {
|
|
4097
|
-
F: __dxlog_file13,
|
|
4098
|
-
L: 131,
|
|
4099
|
-
S: this,
|
|
4100
|
-
A: [
|
|
4101
|
-
"transport",
|
|
4102
|
-
""
|
|
4103
|
-
]
|
|
4104
|
-
});
|
|
2985
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 96, S: this, A: ["transport", ""] });
|
|
4105
2986
|
return {
|
|
4106
2987
|
details: await transport.transport.getDetails()
|
|
4107
2988
|
};
|
|
4108
2989
|
}
|
|
4109
2990
|
async getStats({ proxyId }) {
|
|
4110
2991
|
const transport = this._openTransports.get(proxyId);
|
|
4111
|
-
invariant12(transport, void 0, {
|
|
4112
|
-
F: __dxlog_file13,
|
|
4113
|
-
L: 138,
|
|
4114
|
-
S: this,
|
|
4115
|
-
A: [
|
|
4116
|
-
"transport",
|
|
4117
|
-
""
|
|
4118
|
-
]
|
|
4119
|
-
});
|
|
2992
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 103, S: this, A: ["transport", ""] });
|
|
4120
2993
|
return {
|
|
4121
2994
|
stats: await transport.transport.getStats()
|
|
4122
2995
|
};
|
|
4123
2996
|
}
|
|
4124
2997
|
async sendData({ proxyId, payload }) {
|
|
4125
2998
|
const transport = this._openTransports.get(proxyId);
|
|
4126
|
-
invariant12(transport, void 0, {
|
|
4127
|
-
F: __dxlog_file13,
|
|
4128
|
-
L: 145,
|
|
4129
|
-
S: this,
|
|
4130
|
-
A: [
|
|
4131
|
-
"transport",
|
|
4132
|
-
""
|
|
4133
|
-
]
|
|
4134
|
-
});
|
|
2999
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 110, S: this, A: ["transport", ""] });
|
|
4135
3000
|
const bufferHasSpace = transport.connectorStream.push(payload);
|
|
4136
3001
|
if (!bufferHasSpace) {
|
|
4137
3002
|
await new Promise((resolve) => {
|
|
@@ -4157,31 +3022,16 @@ var RtcTransportService = class {
|
|
|
4157
3022
|
} catch (error) {
|
|
4158
3023
|
log12.warn("transport close error", {
|
|
4159
3024
|
message: error?.message
|
|
4160
|
-
}, {
|
|
4161
|
-
F: __dxlog_file13,
|
|
4162
|
-
L: 175,
|
|
4163
|
-
S: this,
|
|
4164
|
-
C: (f, a) => f(...a)
|
|
4165
|
-
});
|
|
3025
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 134, S: this });
|
|
4166
3026
|
}
|
|
4167
3027
|
try {
|
|
4168
3028
|
transport.connectorStream.end();
|
|
4169
3029
|
} catch (error) {
|
|
4170
3030
|
log12.warn("connectorStream close error", {
|
|
4171
3031
|
message: error?.message
|
|
4172
|
-
}, {
|
|
4173
|
-
F: __dxlog_file13,
|
|
4174
|
-
L: 180,
|
|
4175
|
-
S: this,
|
|
4176
|
-
C: (f, a) => f(...a)
|
|
4177
|
-
});
|
|
3032
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 141, S: this });
|
|
4178
3033
|
}
|
|
4179
|
-
log12("closed", void 0, {
|
|
4180
|
-
F: __dxlog_file13,
|
|
4181
|
-
L: 182,
|
|
4182
|
-
S: this,
|
|
4183
|
-
C: (f, a) => f(...a)
|
|
4184
|
-
});
|
|
3034
|
+
log12("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 145, S: this });
|
|
4185
3035
|
}
|
|
4186
3036
|
};
|
|
4187
3037
|
var createStateUpdater = (next) => {
|
|
@@ -4242,4 +3092,4 @@ export {
|
|
|
4242
3092
|
RtcTransportService,
|
|
4243
3093
|
createTeleportProtocolFactory
|
|
4244
3094
|
};
|
|
4245
|
-
//# sourceMappingURL=chunk-
|
|
3095
|
+
//# sourceMappingURL=chunk-UFYPMUBI.mjs.map
|