@dxos/network-manager 0.8.4-main.fffef41 → 0.9.0
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-E3P563GT.mjs → chunk-ERB3AQAF.mjs} +424 -1897
- package/dist/lib/browser/chunk-ERB3AQAF.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +198 -4
- package/dist/lib/browser/index.mjs.map +4 -4
- 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/index.mjs +2 -33
- package/dist/lib/browser/transport/tcp/index.mjs.map +4 -4
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs +36 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs.map +7 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs +125 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-PKBROUZV.mjs → chunk-KYLPLEZQ.mjs} +424 -1897
- package/dist/lib/node-esm/chunk-KYLPLEZQ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +198 -4
- package/dist/lib/node-esm/index.mjs.map +4 -4
- 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/index.mjs +2 -157
- package/dist/lib/node-esm/transport/tcp/index.mjs.map +4 -4
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs +36 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs.map +7 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs +125 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs.map +7 -0
- 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/index.d.ts +1 -1
- package/dist/types/src/transport/tcp/index.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 +5 -5
- package/dist/types/src/wire-protocol.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +33 -33
- package/src/network-manager.ts +24 -22
- 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 +15 -22
- package/src/swarm/peer.ts +7 -7
- 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/tcp/index.ts +1 -1
- package/src/transport/webrtc/rtc-peer-connection.ts +1 -2
- package/src/transport/webrtc/rtc-transport-channel.test.ts +0 -2
- package/src/transport/webrtc/rtc-transport-channel.ts +1 -2
- 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-proxy.ts +6 -4
- package/src/transport/webrtc/rtc-transport-service.ts +0 -1
- package/src/transport/webrtc/rtc-transport.test.ts +0 -1
- package/src/wire-protocol.ts +6 -6
- package/dist/lib/browser/chunk-E3P563GT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-PKBROUZV.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,69 +89,35 @@ 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
|
-
error: new ProtocolError(
|
|
109
|
+
error: new ProtocolError({
|
|
110
|
+
message: "protocol stream closed"
|
|
111
|
+
})
|
|
148
112
|
}).catch((err) => this.errors.raise(err));
|
|
149
113
|
});
|
|
150
114
|
scheduleTask(this.connectedTimeoutContext, async () => {
|
|
151
|
-
log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
C: (f, a) => f(...a)
|
|
156
|
-
});
|
|
157
|
-
await this.abort(new TimeoutError(`${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`)).catch((err) => this.errors.raise(err));
|
|
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 });
|
|
116
|
+
await this.abort(new TimeoutError({
|
|
117
|
+
message: `${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`
|
|
118
|
+
})).catch((err) => this.errors.raise(err));
|
|
158
119
|
}, TRANSPORT_CONNECTION_TIMEOUT);
|
|
159
|
-
invariant(!this._transport, void 0, {
|
|
160
|
-
F: __dxlog_file,
|
|
161
|
-
L: 202,
|
|
162
|
-
S: this,
|
|
163
|
-
A: [
|
|
164
|
-
"!this._transport",
|
|
165
|
-
""
|
|
166
|
-
]
|
|
167
|
-
});
|
|
120
|
+
invariant(!this._transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 145, S: this, A: ["!this._transport", ""] });
|
|
168
121
|
this._transport = this._transportFactory.createTransport({
|
|
169
122
|
ownPeerKey: this.localInfo.peerKey,
|
|
170
123
|
remotePeerKey: this.remoteInfo.peerKey,
|
|
@@ -183,41 +136,21 @@ var Connection = class {
|
|
|
183
136
|
this._transport.closed.once(() => {
|
|
184
137
|
this._transport = void 0;
|
|
185
138
|
this._transportClosed.wake();
|
|
186
|
-
log("abort triggered by transport close", void 0, {
|
|
187
|
-
F: __dxlog_file,
|
|
188
|
-
L: 224,
|
|
189
|
-
S: this,
|
|
190
|
-
C: (f, a) => f(...a)
|
|
191
|
-
});
|
|
139
|
+
log("abort triggered by transport close", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 164, S: this });
|
|
192
140
|
this.abort().catch((err) => this.errors.raise(err));
|
|
193
141
|
});
|
|
194
142
|
this._transport.errors.handle(async (err) => {
|
|
195
143
|
log("transport error:", {
|
|
196
144
|
err
|
|
197
|
-
}, {
|
|
198
|
-
F: __dxlog_file,
|
|
199
|
-
L: 229,
|
|
200
|
-
S: this,
|
|
201
|
-
C: (f, a) => f(...a)
|
|
202
|
-
});
|
|
145
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 168, S: this });
|
|
203
146
|
if (!this.closeReason) {
|
|
204
147
|
this.closeReason = err?.message;
|
|
205
148
|
}
|
|
206
149
|
if (err instanceof ConnectionResetError) {
|
|
207
|
-
log.info("aborting due to transport ConnectionResetError", void 0, {
|
|
208
|
-
F: __dxlog_file,
|
|
209
|
-
L: 236,
|
|
210
|
-
S: this,
|
|
211
|
-
C: (f, a) => f(...a)
|
|
212
|
-
});
|
|
150
|
+
log.info("aborting due to transport ConnectionResetError", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 176, S: this });
|
|
213
151
|
this.abort(err).catch((err2) => this.errors.raise(err2));
|
|
214
152
|
} else if (err instanceof ConnectivityError) {
|
|
215
|
-
log.info("aborting due to transport ConnectivityError", void 0, {
|
|
216
|
-
F: __dxlog_file,
|
|
217
|
-
L: 239,
|
|
218
|
-
S: this,
|
|
219
|
-
C: (f, a) => f(...a)
|
|
220
|
-
});
|
|
153
|
+
log.info("aborting due to transport ConnectivityError", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 179, S: this });
|
|
221
154
|
this.abort(err).catch((err2) => this.errors.raise(err2));
|
|
222
155
|
}
|
|
223
156
|
if (this._state !== "CLOSED" && this._state !== "CLOSING") {
|
|
@@ -230,31 +163,14 @@ var Connection = class {
|
|
|
230
163
|
void this._transport.onSignal(signal);
|
|
231
164
|
}
|
|
232
165
|
this._incomingSignalBuffer = [];
|
|
233
|
-
log
|
|
234
|
-
id: this._instanceId
|
|
235
|
-
}), {
|
|
236
|
-
F: __dxlog_file,
|
|
237
|
-
L: 258,
|
|
238
|
-
S: this,
|
|
239
|
-
C: (f, a) => f(...a)
|
|
240
|
-
});
|
|
166
|
+
log("opened connection", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 193, S: this });
|
|
241
167
|
}
|
|
242
168
|
async abort(err) {
|
|
243
169
|
log("abort", {
|
|
244
170
|
err
|
|
245
|
-
}, {
|
|
246
|
-
F: __dxlog_file,
|
|
247
|
-
L: 265,
|
|
248
|
-
S: this,
|
|
249
|
-
C: (f, a) => f(...a)
|
|
250
|
-
});
|
|
171
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 196, S: this });
|
|
251
172
|
if (this._state === "CLOSED" || this._state === "ABORTED") {
|
|
252
|
-
log(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
253
|
-
F: __dxlog_file,
|
|
254
|
-
L: 267,
|
|
255
|
-
S: this,
|
|
256
|
-
C: (f, a) => f(...a)
|
|
257
|
-
});
|
|
173
|
+
log(`abort ignored: already ${this._state}`, this.closeReason, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 200, S: this });
|
|
258
174
|
return;
|
|
259
175
|
}
|
|
260
176
|
await this.connectedTimeoutContext.dispose();
|
|
@@ -266,55 +182,30 @@ var Connection = class {
|
|
|
266
182
|
log("aborting...", {
|
|
267
183
|
peerId: this.localInfo,
|
|
268
184
|
err
|
|
269
|
-
}, {
|
|
270
|
-
F: __dxlog_file,
|
|
271
|
-
L: 279,
|
|
272
|
-
S: this,
|
|
273
|
-
C: (f, a) => f(...a)
|
|
274
|
-
});
|
|
185
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 209, S: this });
|
|
275
186
|
try {
|
|
276
187
|
await this._closeProtocol({
|
|
277
188
|
abort: true
|
|
278
189
|
});
|
|
279
190
|
} catch (err2) {
|
|
280
|
-
log.catch(err2, void 0, {
|
|
281
|
-
F: __dxlog_file,
|
|
282
|
-
L: 285,
|
|
283
|
-
S: this,
|
|
284
|
-
C: (f, a) => f(...a)
|
|
285
|
-
});
|
|
191
|
+
log.catch(err2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 219, S: this });
|
|
286
192
|
}
|
|
287
193
|
try {
|
|
288
194
|
await this._closeTransport();
|
|
289
195
|
} catch (err2) {
|
|
290
|
-
log.catch(err2, void 0, {
|
|
291
|
-
F: __dxlog_file,
|
|
292
|
-
L: 292,
|
|
293
|
-
S: this,
|
|
294
|
-
C: (f, a) => f(...a)
|
|
295
|
-
});
|
|
196
|
+
log.catch(err2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 225, S: this });
|
|
296
197
|
}
|
|
297
198
|
try {
|
|
298
199
|
this._callbacks?.onClosed?.(err);
|
|
299
200
|
} catch (err2) {
|
|
300
|
-
log.catch(err2, void 0, {
|
|
301
|
-
F: __dxlog_file,
|
|
302
|
-
L: 298,
|
|
303
|
-
S: this,
|
|
304
|
-
C: (f, a) => f(...a)
|
|
305
|
-
});
|
|
201
|
+
log.catch(err2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 230, S: this });
|
|
306
202
|
}
|
|
307
203
|
this._changeState("ABORTED");
|
|
308
204
|
}
|
|
309
205
|
async close({ error, reason } = {}) {
|
|
310
206
|
log("close", {
|
|
311
207
|
error
|
|
312
|
-
}, {
|
|
313
|
-
F: __dxlog_file,
|
|
314
|
-
L: 305,
|
|
315
|
-
S: this,
|
|
316
|
-
C: (f, a) => f(...a)
|
|
317
|
-
});
|
|
208
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 235, S: this });
|
|
318
209
|
if (!this.closeReason) {
|
|
319
210
|
this.closeReason = reason ?? error?.message;
|
|
320
211
|
} else {
|
|
@@ -324,12 +215,7 @@ var Connection = class {
|
|
|
324
215
|
log("close ignored: already in progress", {
|
|
325
216
|
state: this._state,
|
|
326
217
|
error
|
|
327
|
-
}, {
|
|
328
|
-
F: __dxlog_file,
|
|
329
|
-
L: 316,
|
|
330
|
-
S: this,
|
|
331
|
-
C: (f, a) => f(...a)
|
|
332
|
-
});
|
|
218
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 244, S: this });
|
|
333
219
|
return;
|
|
334
220
|
}
|
|
335
221
|
const lastState = this._state;
|
|
@@ -338,111 +224,66 @@ var Connection = class {
|
|
|
338
224
|
await this._ctx.dispose();
|
|
339
225
|
let abortProtocol = false;
|
|
340
226
|
if (lastState !== "CONNECTED" || error != null) {
|
|
341
|
-
log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
342
|
-
F: __dxlog_file,
|
|
343
|
-
L: 327,
|
|
344
|
-
S: this,
|
|
345
|
-
C: (f, a) => f(...a)
|
|
346
|
-
});
|
|
227
|
+
log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 256, S: this });
|
|
347
228
|
abortProtocol = true;
|
|
348
229
|
}
|
|
349
230
|
log("closing...", {
|
|
350
231
|
peerId: this.localInfo,
|
|
351
232
|
abortProtocol,
|
|
352
233
|
error
|
|
353
|
-
}, {
|
|
354
|
-
F: __dxlog_file,
|
|
355
|
-
L: 331,
|
|
356
|
-
S: this,
|
|
357
|
-
C: (f, a) => f(...a)
|
|
358
|
-
});
|
|
234
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 259, S: this });
|
|
359
235
|
try {
|
|
360
236
|
await this._closeProtocol({
|
|
361
237
|
abort: abortProtocol
|
|
362
238
|
});
|
|
363
239
|
} catch (err) {
|
|
364
|
-
log.catch(err, void 0, {
|
|
365
|
-
F: __dxlog_file,
|
|
366
|
-
L: 336,
|
|
367
|
-
S: this,
|
|
368
|
-
C: (f, a) => f(...a)
|
|
369
|
-
});
|
|
240
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 269, S: this });
|
|
370
241
|
}
|
|
371
242
|
try {
|
|
372
243
|
await this._closeTransport();
|
|
373
244
|
} catch (err) {
|
|
374
|
-
log.catch(err, void 0, {
|
|
375
|
-
F: __dxlog_file,
|
|
376
|
-
L: 342,
|
|
377
|
-
S: this,
|
|
378
|
-
C: (f, a) => f(...a)
|
|
379
|
-
});
|
|
245
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 275, S: this });
|
|
380
246
|
}
|
|
381
247
|
log("closed", {
|
|
382
248
|
peerId: this.localInfo
|
|
383
|
-
}, {
|
|
384
|
-
F: __dxlog_file,
|
|
385
|
-
L: 345,
|
|
386
|
-
S: this,
|
|
387
|
-
C: (f, a) => f(...a)
|
|
388
|
-
});
|
|
249
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 277, S: this });
|
|
389
250
|
this._changeState("CLOSED");
|
|
390
251
|
this._callbacks?.onClosed?.(error);
|
|
391
252
|
}
|
|
392
253
|
async _closeProtocol(options) {
|
|
393
|
-
log("closing protocol", options, {
|
|
394
|
-
F: __dxlog_file,
|
|
395
|
-
L: 351,
|
|
396
|
-
S: this,
|
|
397
|
-
C: (f, a) => f(...a)
|
|
398
|
-
});
|
|
254
|
+
log("closing protocol", options, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 284, S: this });
|
|
399
255
|
await Promise.race([
|
|
400
256
|
options?.abort ? this._protocol.abort() : this._protocol.close(),
|
|
401
257
|
this._protocolClosed.wait()
|
|
402
258
|
]);
|
|
403
|
-
log("protocol closed", options, {
|
|
404
|
-
F: __dxlog_file,
|
|
405
|
-
L: 353,
|
|
406
|
-
S: this,
|
|
407
|
-
C: (f, a) => f(...a)
|
|
408
|
-
});
|
|
259
|
+
log("protocol closed", options, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 289, S: this });
|
|
409
260
|
}
|
|
410
261
|
async _closeTransport() {
|
|
411
|
-
log("closing transport", void 0, {
|
|
412
|
-
F: __dxlog_file,
|
|
413
|
-
L: 357,
|
|
414
|
-
S: this,
|
|
415
|
-
C: (f, a) => f(...a)
|
|
416
|
-
});
|
|
262
|
+
log("closing transport", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 292, S: this });
|
|
417
263
|
await Promise.race([
|
|
418
264
|
this._transport?.close(),
|
|
419
265
|
this._transportClosed.wait()
|
|
420
266
|
]);
|
|
421
|
-
log("transport closed", void 0, {
|
|
422
|
-
F: __dxlog_file,
|
|
423
|
-
L: 359,
|
|
424
|
-
S: this,
|
|
425
|
-
C: (f, a) => f(...a)
|
|
426
|
-
});
|
|
267
|
+
log("transport closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 297, S: this });
|
|
427
268
|
}
|
|
428
269
|
_sendSignal(signal) {
|
|
429
270
|
this._outgoingSignalBuffer.push(signal);
|
|
430
271
|
this._signalSendTask.schedule();
|
|
431
272
|
}
|
|
432
|
-
async _flushSignalBuffer() {
|
|
273
|
+
async _flushSignalBuffer(ctx) {
|
|
433
274
|
if (this._outgoingSignalBuffer.length === 0) {
|
|
434
275
|
return;
|
|
435
276
|
}
|
|
436
277
|
try {
|
|
437
278
|
if (process.env.NODE_ENV !== "test") {
|
|
438
|
-
await cancelWithContext(
|
|
279
|
+
await cancelWithContext(ctx, sleep(this._signallingDelay));
|
|
439
280
|
this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
|
|
440
281
|
}
|
|
441
282
|
const signals = [
|
|
442
283
|
...this._outgoingSignalBuffer
|
|
443
284
|
];
|
|
444
285
|
this._outgoingSignalBuffer.length = 0;
|
|
445
|
-
await this._signalMessaging.signal({
|
|
286
|
+
await this._signalMessaging.signal(ctx, {
|
|
446
287
|
author: this.localInfo,
|
|
447
288
|
recipient: this.remoteInfo,
|
|
448
289
|
sessionId: this.sessionId,
|
|
@@ -459,66 +300,27 @@ var Connection = class {
|
|
|
459
300
|
}
|
|
460
301
|
log.info("signal message failed to deliver", {
|
|
461
302
|
err
|
|
462
|
-
}, {
|
|
463
|
-
F: __dxlog_file,
|
|
464
|
-
L: 399,
|
|
465
|
-
S: this,
|
|
466
|
-
C: (f, a) => f(...a)
|
|
467
|
-
});
|
|
303
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 333, S: this });
|
|
468
304
|
await this.close({
|
|
469
|
-
error: new ConnectivityError(
|
|
305
|
+
error: new ConnectivityError({
|
|
306
|
+
message: "signal message failed to deliver",
|
|
307
|
+
cause: err
|
|
308
|
+
})
|
|
470
309
|
});
|
|
471
310
|
}
|
|
472
311
|
}
|
|
473
312
|
/**
|
|
474
313
|
* Receive a signal from the remote peer.
|
|
475
314
|
*/
|
|
476
|
-
async signal(msg) {
|
|
477
|
-
invariant(msg.sessionId, void 0, {
|
|
478
|
-
F: __dxlog_file,
|
|
479
|
-
L: 408,
|
|
480
|
-
S: this,
|
|
481
|
-
A: [
|
|
482
|
-
"msg.sessionId",
|
|
483
|
-
""
|
|
484
|
-
]
|
|
485
|
-
});
|
|
315
|
+
async signal(_ctx, msg) {
|
|
316
|
+
invariant(msg.sessionId, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 347, S: this, A: ["msg.sessionId", ""] });
|
|
486
317
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
487
|
-
log("dropping signal for incorrect session id", void 0, {
|
|
488
|
-
F: __dxlog_file,
|
|
489
|
-
L: 410,
|
|
490
|
-
S: this,
|
|
491
|
-
C: (f, a) => f(...a)
|
|
492
|
-
});
|
|
318
|
+
log("dropping signal for incorrect session id", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 349, S: this });
|
|
493
319
|
return;
|
|
494
320
|
}
|
|
495
|
-
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
S: this,
|
|
499
|
-
A: [
|
|
500
|
-
"msg.data.signal || msg.data.signalBatch",
|
|
501
|
-
""
|
|
502
|
-
]
|
|
503
|
-
});
|
|
504
|
-
invariant(msg.author.peerKey === this.remoteInfo.peerKey, void 0, {
|
|
505
|
-
F: __dxlog_file,
|
|
506
|
-
L: 414,
|
|
507
|
-
S: this,
|
|
508
|
-
A: [
|
|
509
|
-
"msg.author.peerKey === this.remoteInfo.peerKey",
|
|
510
|
-
""
|
|
511
|
-
]
|
|
512
|
-
});
|
|
513
|
-
invariant(msg.recipient.peerKey === this.localInfo.peerKey, void 0, {
|
|
514
|
-
F: __dxlog_file,
|
|
515
|
-
L: 415,
|
|
516
|
-
S: this,
|
|
517
|
-
A: [
|
|
518
|
-
"msg.recipient.peerKey === this.localInfo.peerKey",
|
|
519
|
-
""
|
|
520
|
-
]
|
|
521
|
-
});
|
|
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", ""] });
|
|
522
324
|
const signals = msg.data.signalBatch ? msg.data.signalBatch.signals ?? [] : [
|
|
523
325
|
msg.data.signal
|
|
524
326
|
];
|
|
@@ -534,33 +336,15 @@ var Connection = class {
|
|
|
534
336
|
peerId: this.localInfo,
|
|
535
337
|
remoteId: this.remoteInfo,
|
|
536
338
|
msg: msg.data
|
|
537
|
-
}, {
|
|
538
|
-
F: __dxlog_file,
|
|
539
|
-
L: 424,
|
|
540
|
-
S: this,
|
|
541
|
-
C: (f, a) => f(...a)
|
|
542
|
-
});
|
|
339
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 366, S: this });
|
|
543
340
|
this._incomingSignalBuffer.push(signal);
|
|
544
341
|
} else {
|
|
545
|
-
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
546
|
-
F: __dxlog_file,
|
|
547
|
-
L: 427,
|
|
548
|
-
S: this,
|
|
549
|
-
A: [
|
|
550
|
-
"this._transport",
|
|
551
|
-
"'Connection not ready to accept signals.'"
|
|
552
|
-
]
|
|
553
|
-
});
|
|
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.'"] });
|
|
554
343
|
log("received signal", {
|
|
555
344
|
peerId: this.localInfo,
|
|
556
345
|
remoteId: this.remoteInfo,
|
|
557
346
|
msg: msg.data
|
|
558
|
-
}, {
|
|
559
|
-
F: __dxlog_file,
|
|
560
|
-
L: 428,
|
|
561
|
-
S: this,
|
|
562
|
-
C: (f, a) => f(...a)
|
|
563
|
-
});
|
|
347
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 374, S: this });
|
|
564
348
|
await this._transport.onSignal(signal);
|
|
565
349
|
}
|
|
566
350
|
}
|
|
@@ -573,21 +357,8 @@ var Connection = class {
|
|
|
573
357
|
from: this._state,
|
|
574
358
|
to: state,
|
|
575
359
|
peerId: this.localInfo
|
|
576
|
-
}, {
|
|
577
|
-
|
|
578
|
-
L: 439,
|
|
579
|
-
S: this,
|
|
580
|
-
C: (f, a) => f(...a)
|
|
581
|
-
});
|
|
582
|
-
invariant(state !== this._state, "Already in this state.", {
|
|
583
|
-
F: __dxlog_file,
|
|
584
|
-
L: 440,
|
|
585
|
-
S: this,
|
|
586
|
-
A: [
|
|
587
|
-
"state !== this._state",
|
|
588
|
-
"'Already in this state.'"
|
|
589
|
-
]
|
|
590
|
-
});
|
|
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.'"] });
|
|
591
362
|
this._state = state;
|
|
592
363
|
this.stateChanged.emit(state);
|
|
593
364
|
}
|
|
@@ -608,54 +379,16 @@ _ts_decorate([
|
|
|
608
379
|
synchronized
|
|
609
380
|
], Connection.prototype, "close", null);
|
|
610
381
|
|
|
611
|
-
// src/signal/ice.ts
|
|
612
|
-
import { asyncTimeout } from "@dxos/async";
|
|
613
|
-
import { log as log2 } from "@dxos/log";
|
|
614
|
-
import { isNonNullable } from "@dxos/util";
|
|
615
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/ice.ts";
|
|
616
|
-
var createIceProvider = (iceProviders) => {
|
|
617
|
-
let cachedIceServers;
|
|
618
|
-
return {
|
|
619
|
-
getIceServers: async () => {
|
|
620
|
-
if (cachedIceServers) {
|
|
621
|
-
return cachedIceServers;
|
|
622
|
-
}
|
|
623
|
-
cachedIceServers = (await Promise.all(iceProviders.map(({ urls }) => asyncTimeout(fetch(urls, {
|
|
624
|
-
method: "GET"
|
|
625
|
-
}), 1e4).then((response) => response.json()).catch((err) => {
|
|
626
|
-
const isDev = typeof window !== "undefined" && window.location.href.includes("localhost");
|
|
627
|
-
if (!isDev) {
|
|
628
|
-
log2.error("Failed to fetch ICE servers from provider", {
|
|
629
|
-
urls,
|
|
630
|
-
err
|
|
631
|
-
}, {
|
|
632
|
-
F: __dxlog_file2,
|
|
633
|
-
L: 30,
|
|
634
|
-
S: void 0,
|
|
635
|
-
C: (f, a) => f(...a)
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
})))).filter(isNonNullable).map(({ iceServers }) => iceServers).flat();
|
|
639
|
-
return cachedIceServers;
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
};
|
|
643
|
-
|
|
644
382
|
// src/signal/swarm-messenger.ts
|
|
645
|
-
import { Context as Context2 } from "@dxos/context";
|
|
646
383
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
647
|
-
import { PublicKey
|
|
648
|
-
import { log as
|
|
384
|
+
import { PublicKey } from "@dxos/keys";
|
|
385
|
+
import { log as log2 } from "@dxos/log";
|
|
649
386
|
import { TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
650
387
|
import { schema } from "@dxos/protocols/proto";
|
|
651
388
|
import { ComplexMap } from "@dxos/util";
|
|
652
|
-
var
|
|
389
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
653
390
|
var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
654
391
|
var SwarmMessenger = class {
|
|
655
|
-
_ctx = new Context2(void 0, {
|
|
656
|
-
F: __dxlog_file3,
|
|
657
|
-
L: 35
|
|
658
|
-
});
|
|
659
392
|
_sendMessage;
|
|
660
393
|
_onSignal;
|
|
661
394
|
_onOffer;
|
|
@@ -667,7 +400,7 @@ var SwarmMessenger = class {
|
|
|
667
400
|
this._onOffer = onOffer;
|
|
668
401
|
this._topic = topic;
|
|
669
402
|
}
|
|
670
|
-
async receiveMessage({ author, recipient, payload }) {
|
|
403
|
+
async receiveMessage(ctx, { author, recipient, payload }) {
|
|
671
404
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
672
405
|
return;
|
|
673
406
|
}
|
|
@@ -675,18 +408,13 @@ var SwarmMessenger = class {
|
|
|
675
408
|
if (!this._topic.equals(message.topic)) {
|
|
676
409
|
return;
|
|
677
410
|
}
|
|
678
|
-
|
|
411
|
+
log2("received", {
|
|
679
412
|
from: author,
|
|
680
413
|
to: recipient,
|
|
681
414
|
msg: message
|
|
682
|
-
}, {
|
|
683
|
-
F: __dxlog_file3,
|
|
684
|
-
L: 71,
|
|
685
|
-
S: this,
|
|
686
|
-
C: (f, a) => f(...a)
|
|
687
|
-
});
|
|
415
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 35, S: this });
|
|
688
416
|
if (message.data?.offer) {
|
|
689
|
-
await this._handleOffer({
|
|
417
|
+
await this._handleOffer(ctx, {
|
|
690
418
|
author,
|
|
691
419
|
recipient,
|
|
692
420
|
message
|
|
@@ -694,77 +422,59 @@ var SwarmMessenger = class {
|
|
|
694
422
|
} else if (message.data?.answer) {
|
|
695
423
|
await this._resolveAnswers(message);
|
|
696
424
|
} else if (message.data?.signal) {
|
|
697
|
-
await this._handleSignal({
|
|
425
|
+
await this._handleSignal(ctx, {
|
|
698
426
|
author,
|
|
699
427
|
recipient,
|
|
700
428
|
message
|
|
701
429
|
});
|
|
702
430
|
} else if (message.data?.signalBatch) {
|
|
703
|
-
await this._handleSignal({
|
|
431
|
+
await this._handleSignal(ctx, {
|
|
704
432
|
author,
|
|
705
433
|
recipient,
|
|
706
434
|
message
|
|
707
435
|
});
|
|
708
436
|
} else {
|
|
709
|
-
|
|
437
|
+
log2.warn("unknown message", {
|
|
710
438
|
message
|
|
711
|
-
}, {
|
|
712
|
-
F: __dxlog_file3,
|
|
713
|
-
L: 82,
|
|
714
|
-
S: this,
|
|
715
|
-
C: (f, a) => f(...a)
|
|
716
|
-
});
|
|
439
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 61, S: this });
|
|
717
440
|
}
|
|
718
441
|
}
|
|
719
|
-
async signal(message) {
|
|
720
|
-
invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
721
|
-
|
|
722
|
-
L: 87,
|
|
723
|
-
S: this,
|
|
724
|
-
A: [
|
|
725
|
-
"message.data?.signal || message.data?.signalBatch",
|
|
726
|
-
"'Invalid message'"
|
|
727
|
-
]
|
|
728
|
-
});
|
|
729
|
-
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, {
|
|
730
445
|
author: message.author,
|
|
731
446
|
recipient: message.recipient,
|
|
732
447
|
message
|
|
733
448
|
});
|
|
734
449
|
}
|
|
735
|
-
async offer(message) {
|
|
450
|
+
async offer(ctx, message) {
|
|
736
451
|
const networkMessage = {
|
|
737
452
|
...message,
|
|
738
|
-
messageId:
|
|
453
|
+
messageId: PublicKey.random()
|
|
739
454
|
};
|
|
740
455
|
return new Promise((resolve, reject) => {
|
|
741
456
|
this._offerRecords.set(networkMessage.messageId, {
|
|
742
457
|
resolve
|
|
743
458
|
});
|
|
744
|
-
this._sendReliableMessage({
|
|
459
|
+
this._sendReliableMessage(ctx, {
|
|
745
460
|
author: message.author,
|
|
746
461
|
recipient: message.recipient,
|
|
747
462
|
message: networkMessage
|
|
748
463
|
}).catch((err) => reject(err));
|
|
749
464
|
});
|
|
750
465
|
}
|
|
751
|
-
async _sendReliableMessage({ author, recipient, message }) {
|
|
466
|
+
async _sendReliableMessage(ctx, { author, recipient, message }) {
|
|
752
467
|
const networkMessage = {
|
|
753
468
|
...message,
|
|
754
469
|
// Setting unique message_id if it not specified yet.
|
|
755
|
-
messageId: message.messageId ??
|
|
470
|
+
messageId: message.messageId ?? PublicKey.random()
|
|
756
471
|
};
|
|
757
|
-
|
|
472
|
+
log2("sending", {
|
|
758
473
|
from: author,
|
|
759
474
|
to: recipient,
|
|
760
475
|
msg: networkMessage
|
|
761
|
-
}, {
|
|
762
|
-
|
|
763
|
-
L: 125,
|
|
764
|
-
S: this,
|
|
765
|
-
C: (f, a) => f(...a)
|
|
766
|
-
});
|
|
767
|
-
await this._sendMessage({
|
|
476
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 96, S: this });
|
|
477
|
+
await this._sendMessage(ctx, {
|
|
768
478
|
author,
|
|
769
479
|
recipient,
|
|
770
480
|
payload: {
|
|
@@ -774,48 +484,19 @@ var SwarmMessenger = class {
|
|
|
774
484
|
});
|
|
775
485
|
}
|
|
776
486
|
async _resolveAnswers(message) {
|
|
777
|
-
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
778
|
-
F: __dxlog_file3,
|
|
779
|
-
L: 137,
|
|
780
|
-
S: this,
|
|
781
|
-
A: [
|
|
782
|
-
"message.data?.answer?.offerMessageId",
|
|
783
|
-
"'No offerMessageId'"
|
|
784
|
-
]
|
|
785
|
-
});
|
|
487
|
+
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 111, S: this, A: ["message.data?.answer?.offerMessageId", "'No offerMessageId'"] });
|
|
786
488
|
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
787
489
|
if (offerRecord) {
|
|
788
490
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
789
|
-
invariant2(message.data?.answer, "No answer", {
|
|
790
|
-
|
|
791
|
-
L: 141,
|
|
792
|
-
S: this,
|
|
793
|
-
A: [
|
|
794
|
-
"message.data?.answer",
|
|
795
|
-
"'No answer'"
|
|
796
|
-
]
|
|
797
|
-
});
|
|
798
|
-
log3("resolving", {
|
|
491
|
+
invariant2(message.data?.answer, "No answer", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 115, S: this, A: ["message.data?.answer", "'No answer'"] });
|
|
492
|
+
log2("resolving", {
|
|
799
493
|
answer: message.data.answer
|
|
800
|
-
}, {
|
|
801
|
-
F: __dxlog_file3,
|
|
802
|
-
L: 142,
|
|
803
|
-
S: this,
|
|
804
|
-
C: (f, a) => f(...a)
|
|
805
|
-
});
|
|
494
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 116, S: this });
|
|
806
495
|
offerRecord.resolve(message.data.answer);
|
|
807
496
|
}
|
|
808
497
|
}
|
|
809
|
-
async _handleOffer({ author, recipient, message }) {
|
|
810
|
-
invariant2(message.data.offer, "No offer", {
|
|
811
|
-
F: __dxlog_file3,
|
|
812
|
-
L: 156,
|
|
813
|
-
S: this,
|
|
814
|
-
A: [
|
|
815
|
-
"message.data.offer",
|
|
816
|
-
"'No offer'"
|
|
817
|
-
]
|
|
818
|
-
});
|
|
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'"] });
|
|
819
500
|
const offerMessage = {
|
|
820
501
|
author,
|
|
821
502
|
recipient,
|
|
@@ -824,10 +505,10 @@ var SwarmMessenger = class {
|
|
|
824
505
|
offer: message.data.offer
|
|
825
506
|
}
|
|
826
507
|
};
|
|
827
|
-
const answer = await this._onOffer(offerMessage);
|
|
508
|
+
const answer = await this._onOffer(ctx, offerMessage);
|
|
828
509
|
answer.offerMessageId = message.messageId;
|
|
829
510
|
try {
|
|
830
|
-
await this._sendReliableMessage({
|
|
511
|
+
await this._sendReliableMessage(ctx, {
|
|
831
512
|
author: recipient,
|
|
832
513
|
recipient: author,
|
|
833
514
|
message: {
|
|
@@ -840,45 +521,19 @@ var SwarmMessenger = class {
|
|
|
840
521
|
});
|
|
841
522
|
} catch (err) {
|
|
842
523
|
if (err instanceof TimeoutError2) {
|
|
843
|
-
|
|
524
|
+
log2.info("timeout sending answer to offer", {
|
|
844
525
|
err
|
|
845
|
-
}, {
|
|
846
|
-
F: __dxlog_file3,
|
|
847
|
-
L: 177,
|
|
848
|
-
S: this,
|
|
849
|
-
C: (f, a) => f(...a)
|
|
850
|
-
});
|
|
526
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 148, S: this });
|
|
851
527
|
} else {
|
|
852
|
-
|
|
528
|
+
log2.info("error sending answer to offer", {
|
|
853
529
|
err
|
|
854
|
-
}, {
|
|
855
|
-
F: __dxlog_file3,
|
|
856
|
-
L: 179,
|
|
857
|
-
S: this,
|
|
858
|
-
C: (f, a) => f(...a)
|
|
859
|
-
});
|
|
530
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 152, S: this });
|
|
860
531
|
}
|
|
861
532
|
}
|
|
862
533
|
}
|
|
863
|
-
async _handleSignal({ author, recipient, message }) {
|
|
864
|
-
invariant2(message.messageId, void 0, {
|
|
865
|
-
|
|
866
|
-
L: 193,
|
|
867
|
-
S: this,
|
|
868
|
-
A: [
|
|
869
|
-
"message.messageId",
|
|
870
|
-
""
|
|
871
|
-
]
|
|
872
|
-
});
|
|
873
|
-
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
874
|
-
F: __dxlog_file3,
|
|
875
|
-
L: 194,
|
|
876
|
-
S: this,
|
|
877
|
-
A: [
|
|
878
|
-
"message.data.signal || message.data.signalBatch",
|
|
879
|
-
"'Invalid message'"
|
|
880
|
-
]
|
|
881
|
-
});
|
|
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'"] });
|
|
882
537
|
const signalMessage = {
|
|
883
538
|
author,
|
|
884
539
|
recipient,
|
|
@@ -888,38 +543,39 @@ var SwarmMessenger = class {
|
|
|
888
543
|
signalBatch: message.data.signalBatch
|
|
889
544
|
}
|
|
890
545
|
};
|
|
891
|
-
await this._onSignal(signalMessage);
|
|
546
|
+
await this._onSignal(ctx, signalMessage);
|
|
892
547
|
}
|
|
893
548
|
};
|
|
894
549
|
|
|
895
550
|
// src/swarm/swarm.ts
|
|
896
551
|
import { Event as Event3, scheduleTask as scheduleTask3, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
|
|
897
|
-
import { Context as
|
|
552
|
+
import { Context as Context3 } from "@dxos/context";
|
|
898
553
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
899
554
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
900
|
-
import { PublicKey as
|
|
901
|
-
import { log as
|
|
555
|
+
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
556
|
+
import { log as log4, logInfo as logInfo2 } from "@dxos/log";
|
|
902
557
|
import { PeerInfoHash } from "@dxos/messaging";
|
|
903
|
-
import {
|
|
904
|
-
import { ComplexMap as ComplexMap2, isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
558
|
+
import { ComplexMap as ComplexMap2, isNonNullable } from "@dxos/util";
|
|
905
559
|
|
|
906
560
|
// src/swarm/peer.ts
|
|
907
561
|
import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
|
|
908
|
-
import { Context as
|
|
562
|
+
import { Context as Context2 } from "@dxos/context";
|
|
909
563
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
910
|
-
import { PublicKey as
|
|
911
|
-
import { log as
|
|
564
|
+
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
565
|
+
import { log as log3 } from "@dxos/log";
|
|
912
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";
|
|
913
568
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
914
569
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
915
570
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
916
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;
|
|
917
572
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
918
573
|
}
|
|
919
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
920
574
|
var ConnectionDisplacedError = class extends SystemError {
|
|
921
575
|
constructor() {
|
|
922
|
-
super(
|
|
576
|
+
super({
|
|
577
|
+
message: "Connection displaced by remote initiator."
|
|
578
|
+
});
|
|
923
579
|
}
|
|
924
580
|
};
|
|
925
581
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
@@ -938,10 +594,7 @@ var Peer = class {
|
|
|
938
594
|
_availableAfter = 0;
|
|
939
595
|
availableToConnect = true;
|
|
940
596
|
_lastConnectionTime;
|
|
941
|
-
_ctx = new
|
|
942
|
-
F: __dxlog_file4,
|
|
943
|
-
L: 81
|
|
944
|
-
});
|
|
597
|
+
_ctx = new Context2(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 44 });
|
|
945
598
|
_connectionCtx;
|
|
946
599
|
connection;
|
|
947
600
|
/**
|
|
@@ -963,36 +616,26 @@ var Peer = class {
|
|
|
963
616
|
/**
|
|
964
617
|
* Respond to remote offer.
|
|
965
618
|
*/
|
|
966
|
-
async onOffer(message) {
|
|
619
|
+
async onOffer(_ctx, message) {
|
|
967
620
|
const remote = message.author;
|
|
968
621
|
if (this.connection && ![
|
|
969
622
|
ConnectionState.CREATED,
|
|
970
623
|
ConnectionState.INITIAL,
|
|
971
624
|
ConnectionState.CONNECTING
|
|
972
625
|
].includes(this.connection.state)) {
|
|
973
|
-
|
|
974
|
-
F: __dxlog_file4,
|
|
975
|
-
L: 116,
|
|
976
|
-
S: this,
|
|
977
|
-
C: (f, a) => f(...a)
|
|
978
|
-
});
|
|
626
|
+
log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 71, S: this });
|
|
979
627
|
return {
|
|
980
628
|
accept: false
|
|
981
629
|
};
|
|
982
630
|
}
|
|
983
631
|
if (this.connection || this.initiating) {
|
|
984
632
|
if (remote.peerKey < this.localInfo.peerKey) {
|
|
985
|
-
|
|
633
|
+
log3("close local connection", {
|
|
986
634
|
localPeer: this.localInfo,
|
|
987
635
|
topic: this.topic,
|
|
988
636
|
remotePeer: this.remoteInfo,
|
|
989
637
|
sessionId: this.connection?.sessionId
|
|
990
|
-
}, {
|
|
991
|
-
F: __dxlog_file4,
|
|
992
|
-
L: 125,
|
|
993
|
-
S: this,
|
|
994
|
-
C: (f, a) => f(...a)
|
|
995
|
-
});
|
|
638
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 82, S: this });
|
|
996
639
|
if (this.connection) {
|
|
997
640
|
await this.closeConnection(new ConnectionDisplacedError());
|
|
998
641
|
}
|
|
@@ -1004,15 +647,7 @@ var Peer = class {
|
|
|
1004
647
|
}
|
|
1005
648
|
if (await this._callbacks.onOffer(remote)) {
|
|
1006
649
|
if (!this.connection) {
|
|
1007
|
-
invariant3(message.sessionId, void 0, {
|
|
1008
|
-
F: __dxlog_file4,
|
|
1009
|
-
L: 145,
|
|
1010
|
-
S: this,
|
|
1011
|
-
A: [
|
|
1012
|
-
"message.sessionId",
|
|
1013
|
-
""
|
|
1014
|
-
]
|
|
1015
|
-
});
|
|
650
|
+
invariant3(message.sessionId, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 102, S: this, A: ["message.sessionId", ""] });
|
|
1016
651
|
const connection = this._createConnection(false, message.sessionId);
|
|
1017
652
|
try {
|
|
1018
653
|
await this._connectionLimiter.connecting(message.sessionId);
|
|
@@ -1020,17 +655,12 @@ var Peer = class {
|
|
|
1020
655
|
await connection.openConnection();
|
|
1021
656
|
} catch (err) {
|
|
1022
657
|
if (!(err instanceof CancelledError2)) {
|
|
1023
|
-
|
|
658
|
+
log3.info("connection error", {
|
|
1024
659
|
topic: this.topic,
|
|
1025
660
|
peerId: this.localInfo,
|
|
1026
661
|
remoteId: this.remoteInfo,
|
|
1027
662
|
err
|
|
1028
|
-
}, {
|
|
1029
|
-
F: __dxlog_file4,
|
|
1030
|
-
L: 155,
|
|
1031
|
-
S: this,
|
|
1032
|
-
C: (f, a) => f(...a)
|
|
1033
|
-
});
|
|
663
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 110, S: this });
|
|
1034
664
|
}
|
|
1035
665
|
await this.closeConnection(err);
|
|
1036
666
|
}
|
|
@@ -1046,44 +676,23 @@ var Peer = class {
|
|
|
1046
676
|
/**
|
|
1047
677
|
* Initiate a connection to the remote peer.
|
|
1048
678
|
*/
|
|
1049
|
-
async initiateConnection() {
|
|
1050
|
-
invariant3(!this.initiating, "Initiation in progress.", {
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
A: [
|
|
1055
|
-
"!this.initiating",
|
|
1056
|
-
"'Initiation in progress.'"
|
|
1057
|
-
]
|
|
1058
|
-
});
|
|
1059
|
-
invariant3(!this.connection, "Already connected.", {
|
|
1060
|
-
F: __dxlog_file4,
|
|
1061
|
-
L: 173,
|
|
1062
|
-
S: this,
|
|
1063
|
-
A: [
|
|
1064
|
-
"!this.connection",
|
|
1065
|
-
"'Already connected.'"
|
|
1066
|
-
]
|
|
1067
|
-
});
|
|
1068
|
-
const sessionId = PublicKey3.random();
|
|
1069
|
-
log4("initiating...", {
|
|
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();
|
|
683
|
+
log3("initiating...", {
|
|
1070
684
|
local: this.localInfo,
|
|
1071
685
|
topic: this.topic,
|
|
1072
686
|
remote: this.remoteInfo,
|
|
1073
687
|
sessionId
|
|
1074
|
-
}, {
|
|
1075
|
-
F: __dxlog_file4,
|
|
1076
|
-
L: 175,
|
|
1077
|
-
S: this,
|
|
1078
|
-
C: (f, a) => f(...a)
|
|
1079
|
-
});
|
|
688
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 135, S: this });
|
|
1080
689
|
const connection = this._createConnection(true, sessionId);
|
|
1081
690
|
this.initiating = true;
|
|
1082
691
|
let answer;
|
|
1083
692
|
try {
|
|
1084
693
|
await this._connectionLimiter.connecting(sessionId);
|
|
1085
694
|
connection.initiate();
|
|
1086
|
-
answer = await this._signalMessaging.offer({
|
|
695
|
+
answer = await this._signalMessaging.offer(ctx, {
|
|
1087
696
|
author: this.localInfo,
|
|
1088
697
|
recipient: this.remoteInfo,
|
|
1089
698
|
sessionId,
|
|
@@ -1092,38 +701,23 @@ var Peer = class {
|
|
|
1092
701
|
offer: {}
|
|
1093
702
|
}
|
|
1094
703
|
});
|
|
1095
|
-
|
|
704
|
+
log3("received", {
|
|
1096
705
|
answer,
|
|
1097
706
|
topic: this.topic,
|
|
1098
707
|
local: this.localInfo,
|
|
1099
708
|
remote: this.remoteInfo
|
|
1100
|
-
}, {
|
|
1101
|
-
F: __dxlog_file4,
|
|
1102
|
-
L: 192,
|
|
1103
|
-
S: this,
|
|
1104
|
-
C: (f, a) => f(...a)
|
|
1105
|
-
});
|
|
709
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 156, S: this });
|
|
1106
710
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1107
|
-
|
|
1108
|
-
F: __dxlog_file4,
|
|
1109
|
-
L: 194,
|
|
1110
|
-
S: this,
|
|
1111
|
-
C: (f, a) => f(...a)
|
|
1112
|
-
});
|
|
711
|
+
log3("ignoring response", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 163, S: this });
|
|
1113
712
|
return;
|
|
1114
713
|
}
|
|
1115
714
|
} catch (err) {
|
|
1116
|
-
|
|
715
|
+
log3("initiation error: send offer", {
|
|
1117
716
|
err,
|
|
1118
717
|
topic: this.topic,
|
|
1119
718
|
local: this.localInfo,
|
|
1120
719
|
remote: this.remoteInfo
|
|
1121
|
-
}, {
|
|
1122
|
-
F: __dxlog_file4,
|
|
1123
|
-
L: 198,
|
|
1124
|
-
S: this,
|
|
1125
|
-
C: (f, a) => f(...a)
|
|
1126
|
-
});
|
|
720
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 167, S: this });
|
|
1127
721
|
await connection.abort(err);
|
|
1128
722
|
throw err;
|
|
1129
723
|
} finally {
|
|
@@ -1135,51 +729,31 @@ var Peer = class {
|
|
|
1135
729
|
return;
|
|
1136
730
|
}
|
|
1137
731
|
} catch (err) {
|
|
1138
|
-
|
|
732
|
+
log3("initiation error: accept answer", {
|
|
1139
733
|
err,
|
|
1140
734
|
topic: this.topic,
|
|
1141
735
|
local: this.localInfo,
|
|
1142
736
|
remote: this.remoteInfo
|
|
1143
|
-
}, {
|
|
1144
|
-
F: __dxlog_file4,
|
|
1145
|
-
L: 211,
|
|
1146
|
-
S: this,
|
|
1147
|
-
C: (f, a) => f(...a)
|
|
1148
|
-
});
|
|
737
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 184, S: this });
|
|
1149
738
|
await connection.abort(err);
|
|
1150
739
|
throw err;
|
|
1151
740
|
} finally {
|
|
1152
741
|
this.initiating = false;
|
|
1153
742
|
}
|
|
1154
743
|
try {
|
|
1155
|
-
|
|
1156
|
-
F: __dxlog_file4,
|
|
1157
|
-
L: 224,
|
|
1158
|
-
S: this,
|
|
1159
|
-
C: (f, a) => f(...a)
|
|
1160
|
-
});
|
|
744
|
+
log3("opening connection as initiator", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 196, S: this });
|
|
1161
745
|
await connection.openConnection();
|
|
1162
746
|
this._callbacks.onAccepted();
|
|
1163
747
|
} catch (err) {
|
|
1164
|
-
|
|
748
|
+
log3("initiation error: open connection", {
|
|
1165
749
|
err,
|
|
1166
750
|
topic: this.topic,
|
|
1167
751
|
local: this.localInfo,
|
|
1168
752
|
remote: this.remoteInfo
|
|
1169
|
-
}, {
|
|
1170
|
-
|
|
1171
|
-
L: 228,
|
|
1172
|
-
S: this,
|
|
1173
|
-
C: (f, a) => f(...a)
|
|
1174
|
-
});
|
|
1175
|
-
log4.warn("closing connection due to unhandled error on openConnection", {
|
|
753
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 200, S: this });
|
|
754
|
+
log3.warn("closing connection due to unhandled error on openConnection", {
|
|
1176
755
|
err
|
|
1177
|
-
}, {
|
|
1178
|
-
F: __dxlog_file4,
|
|
1179
|
-
L: 235,
|
|
1180
|
-
S: this,
|
|
1181
|
-
C: (f, a) => f(...a)
|
|
1182
|
-
});
|
|
756
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 207, S: this });
|
|
1183
757
|
await this.closeConnection(err);
|
|
1184
758
|
throw err;
|
|
1185
759
|
} finally {
|
|
@@ -1191,27 +765,14 @@ var Peer = class {
|
|
|
1191
765
|
* Either we're initiating a connection or creating one in response to an offer from the other peer.
|
|
1192
766
|
*/
|
|
1193
767
|
_createConnection(initiator, sessionId) {
|
|
1194
|
-
|
|
768
|
+
log3("creating connection", {
|
|
1195
769
|
topic: this.topic,
|
|
1196
770
|
peerId: this.localInfo,
|
|
1197
771
|
remoteId: this.remoteInfo,
|
|
1198
772
|
initiator,
|
|
1199
773
|
sessionId
|
|
1200
|
-
}, {
|
|
1201
|
-
|
|
1202
|
-
L: 249,
|
|
1203
|
-
S: this,
|
|
1204
|
-
C: (f, a) => f(...a)
|
|
1205
|
-
});
|
|
1206
|
-
invariant3(!this.connection, "Already connected.", {
|
|
1207
|
-
F: __dxlog_file4,
|
|
1208
|
-
L: 256,
|
|
1209
|
-
S: this,
|
|
1210
|
-
A: [
|
|
1211
|
-
"!this.connection",
|
|
1212
|
-
"'Already connected.'"
|
|
1213
|
-
]
|
|
1214
|
-
});
|
|
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.'"] });
|
|
1215
776
|
const connection = new Connection(
|
|
1216
777
|
this.topic,
|
|
1217
778
|
this.localInfo,
|
|
@@ -1222,8 +783,8 @@ var Peer = class {
|
|
|
1222
783
|
// TODO(dmaretskyi): Init only when connection is established.
|
|
1223
784
|
this._protocolProvider({
|
|
1224
785
|
initiator,
|
|
1225
|
-
localPeerId:
|
|
1226
|
-
remotePeerId:
|
|
786
|
+
localPeerId: PublicKey2.from(this.localInfo.peerKey),
|
|
787
|
+
remotePeerId: PublicKey2.from(this.remoteInfo.peerKey),
|
|
1227
788
|
topic: this.topic
|
|
1228
789
|
}),
|
|
1229
790
|
this._transportFactory,
|
|
@@ -1233,18 +794,13 @@ var Peer = class {
|
|
|
1233
794
|
this._lastConnectionTime = Date.now();
|
|
1234
795
|
this._callbacks.onConnected();
|
|
1235
796
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1236
|
-
|
|
797
|
+
log3.trace("dxos.mesh.connection.connected", {
|
|
1237
798
|
topic: this.topic,
|
|
1238
799
|
localPeerId: this.localInfo,
|
|
1239
800
|
remotePeerId: this.remoteInfo,
|
|
1240
801
|
sessionId,
|
|
1241
802
|
initiator
|
|
1242
|
-
}, {
|
|
1243
|
-
F: __dxlog_file4,
|
|
1244
|
-
L: 280,
|
|
1245
|
-
S: this,
|
|
1246
|
-
C: (f, a) => f(...a)
|
|
1247
|
-
});
|
|
803
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 241, S: this });
|
|
1248
804
|
},
|
|
1249
805
|
onClosed: (err) => {
|
|
1250
806
|
const logMeta = {
|
|
@@ -1253,34 +809,16 @@ var Peer = class {
|
|
|
1253
809
|
remoteId: this.remoteInfo,
|
|
1254
810
|
initiator
|
|
1255
811
|
};
|
|
1256
|
-
|
|
1257
|
-
F: __dxlog_file4,
|
|
1258
|
-
L: 290,
|
|
1259
|
-
S: this,
|
|
1260
|
-
C: (f, a) => f(...a)
|
|
1261
|
-
});
|
|
812
|
+
log3("connection closed", logMeta, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 256, S: this });
|
|
1262
813
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1263
|
-
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1264
|
-
|
|
1265
|
-
L: 295,
|
|
1266
|
-
S: this,
|
|
1267
|
-
A: [
|
|
1268
|
-
"this.connection === connection",
|
|
1269
|
-
"'Connection mismatch (race condition).'"
|
|
1270
|
-
]
|
|
1271
|
-
});
|
|
1272
|
-
log4.trace("dxos.mesh.connection.closed", {
|
|
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).'"] });
|
|
815
|
+
log3.trace("dxos.mesh.connection.closed", {
|
|
1273
816
|
topic: this.topic,
|
|
1274
817
|
localPeerId: this.localInfo,
|
|
1275
818
|
remotePeerId: this.remoteInfo,
|
|
1276
819
|
sessionId,
|
|
1277
820
|
initiator
|
|
1278
|
-
}, {
|
|
1279
|
-
F: __dxlog_file4,
|
|
1280
|
-
L: 297,
|
|
1281
|
-
S: this,
|
|
1282
|
-
C: (f, a) => f(...a)
|
|
1283
|
-
});
|
|
821
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 260, S: this });
|
|
1284
822
|
if (err instanceof ConnectionDisplacedError) {
|
|
1285
823
|
this.connectionDisplaced.emit(this.connection);
|
|
1286
824
|
} else {
|
|
@@ -1292,12 +830,7 @@ var Peer = class {
|
|
|
1292
830
|
}
|
|
1293
831
|
this._callbacks.onDisconnected();
|
|
1294
832
|
scheduleTask2(this._connectionCtx, () => {
|
|
1295
|
-
|
|
1296
|
-
F: __dxlog_file4,
|
|
1297
|
-
L: 321,
|
|
1298
|
-
S: this,
|
|
1299
|
-
C: (f, a) => f(...a)
|
|
1300
|
-
});
|
|
833
|
+
log3("peer became available", logMeta, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 279, S: this });
|
|
1301
834
|
this.availableToConnect = true;
|
|
1302
835
|
this._callbacks.onPeerAvailable();
|
|
1303
836
|
}, this._availableAfter);
|
|
@@ -1310,31 +843,21 @@ var Peer = class {
|
|
|
1310
843
|
void this._connectionCtx?.dispose();
|
|
1311
844
|
this._connectionCtx = this._ctx.derive();
|
|
1312
845
|
connection.errors.handle((err) => {
|
|
1313
|
-
|
|
846
|
+
log3.info("connection error, closing", {
|
|
1314
847
|
topic: this.topic,
|
|
1315
848
|
peerId: this.localInfo,
|
|
1316
849
|
remoteId: this.remoteInfo,
|
|
1317
850
|
initiator,
|
|
1318
851
|
err
|
|
1319
|
-
}, {
|
|
1320
|
-
|
|
1321
|
-
L: 339,
|
|
1322
|
-
S: this,
|
|
1323
|
-
C: (f, a) => f(...a)
|
|
1324
|
-
});
|
|
1325
|
-
log4.trace("dxos.mesh.connection.error", {
|
|
852
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 291, S: this });
|
|
853
|
+
log3.trace("dxos.mesh.connection.error", {
|
|
1326
854
|
topic: this.topic,
|
|
1327
855
|
localPeerId: this.localInfo,
|
|
1328
856
|
remotePeerId: this.remoteInfo,
|
|
1329
857
|
sessionId,
|
|
1330
858
|
initiator,
|
|
1331
859
|
err
|
|
1332
|
-
}, {
|
|
1333
|
-
F: __dxlog_file4,
|
|
1334
|
-
L: 346,
|
|
1335
|
-
S: this,
|
|
1336
|
-
C: (f, a) => f(...a)
|
|
1337
|
-
});
|
|
860
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 298, S: this });
|
|
1338
861
|
void this.closeConnection(err);
|
|
1339
862
|
});
|
|
1340
863
|
this.connection = connection;
|
|
@@ -1345,53 +868,33 @@ var Peer = class {
|
|
|
1345
868
|
return;
|
|
1346
869
|
}
|
|
1347
870
|
const connection = this.connection;
|
|
1348
|
-
|
|
871
|
+
log3("closing...", {
|
|
1349
872
|
peerId: this.remoteInfo,
|
|
1350
873
|
sessionId: connection.sessionId
|
|
1351
|
-
}, {
|
|
1352
|
-
F: __dxlog_file4,
|
|
1353
|
-
L: 371,
|
|
1354
|
-
S: this,
|
|
1355
|
-
C: (f, a) => f(...a)
|
|
1356
|
-
});
|
|
874
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 317, S: this });
|
|
1357
875
|
await connection.close({
|
|
1358
876
|
error: err
|
|
1359
877
|
});
|
|
1360
|
-
|
|
878
|
+
log3("closed", {
|
|
1361
879
|
peerId: this.remoteInfo,
|
|
1362
880
|
sessionId: connection.sessionId
|
|
1363
|
-
}, {
|
|
1364
|
-
F: __dxlog_file4,
|
|
1365
|
-
L: 377,
|
|
1366
|
-
S: this,
|
|
1367
|
-
C: (f, a) => f(...a)
|
|
1368
|
-
});
|
|
881
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 326, S: this });
|
|
1369
882
|
}
|
|
1370
|
-
async onSignal(message) {
|
|
883
|
+
async onSignal(ctx, message) {
|
|
1371
884
|
if (!this.connection) {
|
|
1372
|
-
|
|
885
|
+
log3("dropping signal message for non-existent connection", {
|
|
1373
886
|
message
|
|
1374
|
-
}, {
|
|
1375
|
-
F: __dxlog_file4,
|
|
1376
|
-
L: 382,
|
|
1377
|
-
S: this,
|
|
1378
|
-
C: (f, a) => f(...a)
|
|
1379
|
-
});
|
|
887
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 333, S: this });
|
|
1380
888
|
return;
|
|
1381
889
|
}
|
|
1382
|
-
await this.connection.signal(message);
|
|
890
|
+
await this.connection.signal(ctx, message);
|
|
1383
891
|
}
|
|
1384
892
|
async safeDestroy(reason) {
|
|
1385
893
|
await this._ctx.dispose();
|
|
1386
|
-
|
|
894
|
+
log3("Destroying peer", {
|
|
1387
895
|
peerId: this.remoteInfo,
|
|
1388
896
|
topic: this.topic
|
|
1389
|
-
}, {
|
|
1390
|
-
F: __dxlog_file4,
|
|
1391
|
-
L: 392,
|
|
1392
|
-
S: this,
|
|
1393
|
-
C: (f, a) => f(...a)
|
|
1394
|
-
});
|
|
897
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 342, S: this });
|
|
1395
898
|
await this?.connection?.close({
|
|
1396
899
|
reason
|
|
1397
900
|
});
|
|
@@ -1414,13 +917,13 @@ var increaseInterval = (interval) => {
|
|
|
1414
917
|
};
|
|
1415
918
|
|
|
1416
919
|
// src/swarm/swarm.ts
|
|
920
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1417
921
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
1418
922
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1419
923
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1420
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;
|
|
1421
925
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1422
926
|
}
|
|
1423
|
-
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1424
927
|
var INITIATION_DELAY = 100;
|
|
1425
928
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1426
929
|
var Swarm = class {
|
|
@@ -1434,10 +937,7 @@ var Swarm = class {
|
|
|
1434
937
|
_connectionLimiter;
|
|
1435
938
|
_initiationDelay;
|
|
1436
939
|
_swarmMessenger;
|
|
1437
|
-
_ctx = new
|
|
1438
|
-
F: __dxlog_file5,
|
|
1439
|
-
L: 39
|
|
1440
|
-
});
|
|
940
|
+
_ctx = new Context3(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 39 });
|
|
1441
941
|
_listeningHandle = void 0;
|
|
1442
942
|
/**
|
|
1443
943
|
* PeerInfo -> Peer.
|
|
@@ -1447,7 +947,7 @@ var Swarm = class {
|
|
|
1447
947
|
/**
|
|
1448
948
|
* Unique id of the swarm, local to the current peer, generated when swarm is joined.
|
|
1449
949
|
*/
|
|
1450
|
-
_instanceId =
|
|
950
|
+
_instanceId = PublicKey3.random().toHex();
|
|
1451
951
|
/**
|
|
1452
952
|
* New connection to a peer is started.
|
|
1453
953
|
* @internal
|
|
@@ -1476,47 +976,23 @@ var Swarm = class {
|
|
|
1476
976
|
this._label = _label;
|
|
1477
977
|
this._connectionLimiter = _connectionLimiter;
|
|
1478
978
|
this._initiationDelay = _initiationDelay;
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
peer: this._ownPeer
|
|
1484
|
-
}
|
|
1485
|
-
}), {
|
|
1486
|
-
F: __dxlog_file5,
|
|
1487
|
-
L: 89,
|
|
1488
|
-
S: this,
|
|
1489
|
-
C: (f, a) => f(...a)
|
|
1490
|
-
});
|
|
1491
|
-
log5("creating swarm", {
|
|
1492
|
-
peerId: _ownPeer
|
|
1493
|
-
}, {
|
|
1494
|
-
F: __dxlog_file5,
|
|
1495
|
-
L: 93,
|
|
1496
|
-
S: this,
|
|
1497
|
-
C: (f, a) => f(...a)
|
|
1498
|
-
});
|
|
979
|
+
log4("creating swarm", {
|
|
980
|
+
topic: this._topic.toHex(),
|
|
981
|
+
peer: this._ownPeer
|
|
982
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 73, S: this });
|
|
1499
983
|
_topology.init(this._getSwarmController());
|
|
1500
984
|
this._swarmMessenger = new SwarmMessenger({
|
|
1501
|
-
sendMessage: async (msg) => await this._messenger.sendMessage(msg),
|
|
1502
|
-
onSignal: async (msg) => await this.onSignal(msg),
|
|
1503
|
-
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),
|
|
1504
988
|
topic: this._topic
|
|
1505
989
|
});
|
|
1506
|
-
log5.trace("dxos.mesh.swarm.constructor", trace2.end({
|
|
1507
|
-
id: this._instanceId
|
|
1508
|
-
}), {
|
|
1509
|
-
F: __dxlog_file5,
|
|
1510
|
-
L: 102,
|
|
1511
|
-
S: this,
|
|
1512
|
-
C: (f, a) => f(...a)
|
|
1513
|
-
});
|
|
1514
990
|
}
|
|
1515
991
|
get connections() {
|
|
1516
|
-
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(
|
|
992
|
+
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable);
|
|
1517
993
|
}
|
|
1518
994
|
get ownPeerId() {
|
|
1519
|
-
return
|
|
995
|
+
return PublicKey3.from(this._ownPeer.peerKey);
|
|
1520
996
|
}
|
|
1521
997
|
get ownPeer() {
|
|
1522
998
|
return this._ownPeer;
|
|
@@ -1531,105 +1007,54 @@ var Swarm = class {
|
|
|
1531
1007
|
return this._topic;
|
|
1532
1008
|
}
|
|
1533
1009
|
async open() {
|
|
1534
|
-
invariant4(!this._listeningHandle, void 0, {
|
|
1535
|
-
F: __dxlog_file5,
|
|
1536
|
-
L: 133,
|
|
1537
|
-
S: this,
|
|
1538
|
-
A: [
|
|
1539
|
-
"!this._listeningHandle",
|
|
1540
|
-
""
|
|
1541
|
-
]
|
|
1542
|
-
});
|
|
1010
|
+
invariant4(!this._listeningHandle, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 103, S: this, A: ["!this._listeningHandle", ""] });
|
|
1543
1011
|
this._listeningHandle = await this._messenger.listen({
|
|
1544
1012
|
peer: this._ownPeer,
|
|
1545
1013
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
1546
1014
|
onMessage: async (message) => {
|
|
1547
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) =>
|
|
1015
|
+
await this._swarmMessenger.receiveMessage(this._ctx, message).catch((err) => log4.info("Error while receiving message", {
|
|
1548
1016
|
err
|
|
1549
|
-
}, {
|
|
1550
|
-
F: __dxlog_file5,
|
|
1551
|
-
L: 141,
|
|
1552
|
-
S: this,
|
|
1553
|
-
C: (f, a) => f(...a)
|
|
1554
|
-
}));
|
|
1017
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 109, S: this }));
|
|
1555
1018
|
}
|
|
1556
1019
|
});
|
|
1557
1020
|
}
|
|
1558
1021
|
async destroy() {
|
|
1559
|
-
|
|
1560
|
-
F: __dxlog_file5,
|
|
1561
|
-
L: 147,
|
|
1562
|
-
S: this,
|
|
1563
|
-
C: (f, a) => f(...a)
|
|
1564
|
-
});
|
|
1022
|
+
log4("destroying...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 116, S: this });
|
|
1565
1023
|
await this._listeningHandle?.unsubscribe();
|
|
1566
1024
|
this._listeningHandle = void 0;
|
|
1567
1025
|
await this._ctx.dispose();
|
|
1568
1026
|
await this._topology.destroy();
|
|
1569
1027
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1570
|
-
|
|
1571
|
-
F: __dxlog_file5,
|
|
1572
|
-
L: 154,
|
|
1573
|
-
S: this,
|
|
1574
|
-
C: (f, a) => f(...a)
|
|
1575
|
-
});
|
|
1028
|
+
log4("destroyed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 122, S: this });
|
|
1576
1029
|
}
|
|
1577
1030
|
async setTopology(topology) {
|
|
1578
|
-
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1579
|
-
F: __dxlog_file5,
|
|
1580
|
-
L: 158,
|
|
1581
|
-
S: this,
|
|
1582
|
-
A: [
|
|
1583
|
-
"!this._ctx.disposed",
|
|
1584
|
-
"'Swarm is offline'"
|
|
1585
|
-
]
|
|
1586
|
-
});
|
|
1031
|
+
invariant4(!this._ctx.disposed, "Swarm is offline", { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 125, S: this, A: ["!this._ctx.disposed", "'Swarm is offline'"] });
|
|
1587
1032
|
if (topology === this._topology) {
|
|
1588
1033
|
return;
|
|
1589
1034
|
}
|
|
1590
|
-
|
|
1035
|
+
log4("setting topology", {
|
|
1591
1036
|
previous: getClassName(this._topology),
|
|
1592
1037
|
topology: getClassName(topology)
|
|
1593
|
-
}, {
|
|
1594
|
-
F: __dxlog_file5,
|
|
1595
|
-
L: 162,
|
|
1596
|
-
S: this,
|
|
1597
|
-
C: (f, a) => f(...a)
|
|
1598
|
-
});
|
|
1038
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 129, S: this });
|
|
1599
1039
|
await this._topology.destroy();
|
|
1600
1040
|
this._topology = topology;
|
|
1601
1041
|
this._topology.init(this._getSwarmController());
|
|
1602
1042
|
this._topology.update();
|
|
1603
1043
|
}
|
|
1604
1044
|
async onSwarmEvent(swarmEvent) {
|
|
1605
|
-
|
|
1045
|
+
log4("swarm event", {
|
|
1606
1046
|
swarmEvent
|
|
1607
|
-
}, {
|
|
1608
|
-
F: __dxlog_file5,
|
|
1609
|
-
L: 175,
|
|
1610
|
-
S: this,
|
|
1611
|
-
C: (f, a) => f(...a)
|
|
1612
|
-
});
|
|
1047
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 139, S: this });
|
|
1613
1048
|
if (this._ctx.disposed) {
|
|
1614
|
-
|
|
1615
|
-
F: __dxlog_file5,
|
|
1616
|
-
L: 178,
|
|
1617
|
-
S: this,
|
|
1618
|
-
C: (f, a) => f(...a)
|
|
1619
|
-
});
|
|
1049
|
+
log4("swarm event ignored for disposed swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 143, S: this });
|
|
1620
1050
|
return;
|
|
1621
1051
|
}
|
|
1622
1052
|
if (swarmEvent.peerAvailable) {
|
|
1623
1053
|
const peerId = swarmEvent.peerAvailable.peer.peerKey;
|
|
1624
1054
|
if (peerId !== this._ownPeer.peerKey) {
|
|
1625
|
-
|
|
1055
|
+
log4("new peer", {
|
|
1626
1056
|
peerId
|
|
1627
|
-
}, {
|
|
1628
|
-
F: __dxlog_file5,
|
|
1629
|
-
L: 185,
|
|
1630
|
-
S: this,
|
|
1631
|
-
C: (f, a) => f(...a)
|
|
1632
|
-
});
|
|
1057
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 149, S: this });
|
|
1633
1058
|
const peer = this._getOrCreatePeer(swarmEvent.peerAvailable.peer);
|
|
1634
1059
|
peer.advertizing = true;
|
|
1635
1060
|
}
|
|
@@ -1638,89 +1063,46 @@ var Swarm = class {
|
|
|
1638
1063
|
if (peer) {
|
|
1639
1064
|
peer.advertizing = false;
|
|
1640
1065
|
if (this._isConnectionEstablishmentInProgress(peer)) {
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
L: 196,
|
|
1644
|
-
S: this,
|
|
1645
|
-
C: (f, a) => f(...a)
|
|
1646
|
-
});
|
|
1647
|
-
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log5.catch(err, void 0, {
|
|
1648
|
-
F: __dxlog_file5,
|
|
1649
|
-
L: 197,
|
|
1650
|
-
S: this,
|
|
1651
|
-
C: (f, a) => f(...a)
|
|
1652
|
-
}));
|
|
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 }));
|
|
1653
1068
|
}
|
|
1654
1069
|
} else {
|
|
1655
|
-
|
|
1070
|
+
log4("received peerLeft but no peer found", {
|
|
1656
1071
|
peer: swarmEvent.peerLeft.peer.peerKey
|
|
1657
|
-
}, {
|
|
1658
|
-
F: __dxlog_file5,
|
|
1659
|
-
L: 200,
|
|
1660
|
-
S: this,
|
|
1661
|
-
C: (f, a) => f(...a)
|
|
1662
|
-
});
|
|
1072
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 166, S: this });
|
|
1663
1073
|
}
|
|
1664
1074
|
}
|
|
1665
1075
|
this._topology.update();
|
|
1666
1076
|
}
|
|
1667
|
-
async onOffer(message) {
|
|
1668
|
-
|
|
1077
|
+
async onOffer(ctx, message) {
|
|
1078
|
+
log4("offer", {
|
|
1669
1079
|
message
|
|
1670
|
-
}, {
|
|
1671
|
-
F: __dxlog_file5,
|
|
1672
|
-
L: 209,
|
|
1673
|
-
S: this,
|
|
1674
|
-
C: (f, a) => f(...a)
|
|
1675
|
-
});
|
|
1080
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 174, S: this });
|
|
1676
1081
|
if (this._ctx.disposed) {
|
|
1677
|
-
|
|
1678
|
-
F: __dxlog_file5,
|
|
1679
|
-
L: 211,
|
|
1680
|
-
S: this,
|
|
1681
|
-
C: (f, a) => f(...a)
|
|
1682
|
-
});
|
|
1082
|
+
log4("ignored for disposed swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 178, S: this });
|
|
1683
1083
|
return {
|
|
1684
1084
|
accept: false
|
|
1685
1085
|
};
|
|
1686
1086
|
}
|
|
1687
|
-
invariant4(message.author, void 0, {
|
|
1688
|
-
F: __dxlog_file5,
|
|
1689
|
-
L: 216,
|
|
1690
|
-
S: this,
|
|
1691
|
-
A: [
|
|
1692
|
-
"message.author",
|
|
1693
|
-
""
|
|
1694
|
-
]
|
|
1695
|
-
});
|
|
1087
|
+
invariant4(message.author, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 184, S: this, A: ["message.author", ""] });
|
|
1696
1088
|
if (message.recipient.peerKey !== this._ownPeer.peerKey) {
|
|
1697
|
-
|
|
1089
|
+
log4("rejecting offer with incorrect peerId", {
|
|
1698
1090
|
message
|
|
1699
|
-
}, {
|
|
1700
|
-
F: __dxlog_file5,
|
|
1701
|
-
L: 218,
|
|
1702
|
-
S: this,
|
|
1703
|
-
C: (f, a) => f(...a)
|
|
1704
|
-
});
|
|
1091
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 186, S: this });
|
|
1705
1092
|
return {
|
|
1706
1093
|
accept: false
|
|
1707
1094
|
};
|
|
1708
1095
|
}
|
|
1709
1096
|
if (!message.topic?.equals(this._topic)) {
|
|
1710
|
-
|
|
1097
|
+
log4("rejecting offer with incorrect topic", {
|
|
1711
1098
|
message
|
|
1712
|
-
}, {
|
|
1713
|
-
F: __dxlog_file5,
|
|
1714
|
-
L: 222,
|
|
1715
|
-
S: this,
|
|
1716
|
-
C: (f, a) => f(...a)
|
|
1717
|
-
});
|
|
1099
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 194, S: this });
|
|
1718
1100
|
return {
|
|
1719
1101
|
accept: false
|
|
1720
1102
|
};
|
|
1721
1103
|
}
|
|
1722
1104
|
const peer = this._getOfferSenderPeer(message.author);
|
|
1723
|
-
const answer = await peer.onOffer(message);
|
|
1105
|
+
const answer = await peer.onOffer(ctx, message);
|
|
1724
1106
|
this._topology.update();
|
|
1725
1107
|
return answer;
|
|
1726
1108
|
}
|
|
@@ -1734,53 +1116,19 @@ var Swarm = class {
|
|
|
1734
1116
|
}
|
|
1735
1117
|
return peer;
|
|
1736
1118
|
}
|
|
1737
|
-
async onSignal(message) {
|
|
1738
|
-
|
|
1119
|
+
async onSignal(ctx, message) {
|
|
1120
|
+
log4("signal", {
|
|
1739
1121
|
message
|
|
1740
|
-
}, {
|
|
1741
|
-
F: __dxlog_file5,
|
|
1742
|
-
L: 247,
|
|
1743
|
-
S: this,
|
|
1744
|
-
C: (f, a) => f(...a)
|
|
1745
|
-
});
|
|
1122
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 218, S: this });
|
|
1746
1123
|
if (this._ctx.disposed) {
|
|
1747
|
-
|
|
1748
|
-
F: __dxlog_file5,
|
|
1749
|
-
L: 249,
|
|
1750
|
-
S: this,
|
|
1751
|
-
C: (f, a) => f(...a)
|
|
1752
|
-
});
|
|
1124
|
+
log4.info("ignored for offline swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 222, S: this });
|
|
1753
1125
|
return;
|
|
1754
1126
|
}
|
|
1755
|
-
invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
S: this,
|
|
1759
|
-
A: [
|
|
1760
|
-
"message.recipient.peerKey === this._ownPeer.peerKey",
|
|
1761
|
-
"`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
|
|
1762
|
-
]
|
|
1763
|
-
});
|
|
1764
|
-
invariant4(message.topic?.equals(this._topic), void 0, {
|
|
1765
|
-
F: __dxlog_file5,
|
|
1766
|
-
L: 256,
|
|
1767
|
-
S: this,
|
|
1768
|
-
A: [
|
|
1769
|
-
"message.topic?.equals(this._topic)",
|
|
1770
|
-
""
|
|
1771
|
-
]
|
|
1772
|
-
});
|
|
1773
|
-
invariant4(message.author, void 0, {
|
|
1774
|
-
F: __dxlog_file5,
|
|
1775
|
-
L: 257,
|
|
1776
|
-
S: this,
|
|
1777
|
-
A: [
|
|
1778
|
-
"message.author",
|
|
1779
|
-
""
|
|
1780
|
-
]
|
|
1781
|
-
});
|
|
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", ""] });
|
|
1782
1130
|
const peer = this._getOrCreatePeer(message.author);
|
|
1783
|
-
await peer.onSignal(message);
|
|
1131
|
+
await peer.onSignal(ctx, message);
|
|
1784
1132
|
}
|
|
1785
1133
|
// For debug purposes
|
|
1786
1134
|
async goOffline() {
|
|
@@ -1791,21 +1139,10 @@ var Swarm = class {
|
|
|
1791
1139
|
}
|
|
1792
1140
|
// For debug purposes
|
|
1793
1141
|
async goOnline() {
|
|
1794
|
-
this._ctx = new
|
|
1795
|
-
F: __dxlog_file5,
|
|
1796
|
-
L: 273
|
|
1797
|
-
});
|
|
1142
|
+
this._ctx = new Context3(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 240 });
|
|
1798
1143
|
}
|
|
1799
1144
|
_getOrCreatePeer(peerInfo) {
|
|
1800
|
-
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
|
|
1801
|
-
F: __dxlog_file5,
|
|
1802
|
-
L: 277,
|
|
1803
|
-
S: this,
|
|
1804
|
-
A: [
|
|
1805
|
-
"peerInfo.peerKey",
|
|
1806
|
-
"'PeerInfo.peerKey is required'"
|
|
1807
|
-
]
|
|
1808
|
-
});
|
|
1145
|
+
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 243, S: this, A: ["peerInfo.peerKey", "'PeerInfo.peerKey is required'"] });
|
|
1809
1146
|
let peer = this._peers.get(peerInfo);
|
|
1810
1147
|
if (!peer) {
|
|
1811
1148
|
peer = new Peer(peerInfo, this._topic, this._ownPeer, this._swarmMessenger, this._protocolProvider, this._transportFactory, this._connectionLimiter, {
|
|
@@ -1817,12 +1154,7 @@ var Swarm = class {
|
|
|
1817
1154
|
},
|
|
1818
1155
|
onDisconnected: async () => {
|
|
1819
1156
|
if (this._isUnregistered(peer)) {
|
|
1820
|
-
|
|
1821
|
-
F: __dxlog_file5,
|
|
1822
|
-
L: 297,
|
|
1823
|
-
S: this,
|
|
1824
|
-
C: (f, a) => f(...a)
|
|
1825
|
-
});
|
|
1157
|
+
log4.verbose("ignored onDisconnected for unregistered peer", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 255, S: this });
|
|
1826
1158
|
return;
|
|
1827
1159
|
}
|
|
1828
1160
|
if (!peer.advertizing) {
|
|
@@ -1833,14 +1165,9 @@ var Swarm = class {
|
|
|
1833
1165
|
},
|
|
1834
1166
|
onRejected: () => {
|
|
1835
1167
|
if (!this._isUnregistered(peer)) {
|
|
1836
|
-
|
|
1168
|
+
log4("peer rejected connection", {
|
|
1837
1169
|
peerInfo
|
|
1838
|
-
}, {
|
|
1839
|
-
F: __dxlog_file5,
|
|
1840
|
-
L: 311,
|
|
1841
|
-
S: this,
|
|
1842
|
-
C: (f, a) => f(...a)
|
|
1843
|
-
});
|
|
1170
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 268, S: this });
|
|
1844
1171
|
void this._destroyPeer(peerInfo, "peer rejected connection");
|
|
1845
1172
|
}
|
|
1846
1173
|
},
|
|
@@ -1848,7 +1175,7 @@ var Swarm = class {
|
|
|
1848
1175
|
this._topology.update();
|
|
1849
1176
|
},
|
|
1850
1177
|
onOffer: (remoteId) => {
|
|
1851
|
-
return this._topology.onOffer(
|
|
1178
|
+
return this._topology.onOffer(PublicKey3.from(remoteId.peerKey));
|
|
1852
1179
|
},
|
|
1853
1180
|
onPeerAvailable: () => {
|
|
1854
1181
|
this._topology.update();
|
|
@@ -1859,35 +1186,22 @@ var Swarm = class {
|
|
|
1859
1186
|
return peer;
|
|
1860
1187
|
}
|
|
1861
1188
|
async _destroyPeer(peerInfo, reason) {
|
|
1862
|
-
|
|
1189
|
+
log4("destroy peer", {
|
|
1863
1190
|
peerKey: peerInfo.peerKey,
|
|
1864
1191
|
reason
|
|
1865
|
-
}, {
|
|
1866
|
-
F: __dxlog_file5,
|
|
1867
|
-
L: 333,
|
|
1868
|
-
S: this,
|
|
1869
|
-
C: (f, a) => f(...a)
|
|
1870
|
-
});
|
|
1192
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 289, S: this });
|
|
1871
1193
|
const peer = this._peers.get(peerInfo);
|
|
1872
|
-
invariant4(peer, void 0, {
|
|
1873
|
-
F: __dxlog_file5,
|
|
1874
|
-
L: 335,
|
|
1875
|
-
S: this,
|
|
1876
|
-
A: [
|
|
1877
|
-
"peer",
|
|
1878
|
-
""
|
|
1879
|
-
]
|
|
1880
|
-
});
|
|
1194
|
+
invariant4(peer, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 294, S: this, A: ["peer", ""] });
|
|
1881
1195
|
this._peers.delete(peerInfo);
|
|
1882
1196
|
await peer.safeDestroy(reason);
|
|
1883
1197
|
}
|
|
1884
1198
|
_getSwarmController() {
|
|
1885
1199
|
return {
|
|
1886
1200
|
getState: () => ({
|
|
1887
|
-
ownPeerId:
|
|
1888
|
-
connected: Array.from(this._peers.entries()).filter(([_, peer]) => peer.connection).map(([info]) =>
|
|
1889
|
-
candidates: Array.from(this._peers.entries()).filter(([_, peer]) => !peer.connection && peer.advertizing && peer.availableToConnect).map(([info]) =>
|
|
1890
|
-
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))
|
|
1891
1205
|
}),
|
|
1892
1206
|
connect: (peer) => {
|
|
1893
1207
|
if (this._ctx.disposed) {
|
|
@@ -1899,12 +1213,7 @@ var Swarm = class {
|
|
|
1899
1213
|
peerKey: peer.toHex()
|
|
1900
1214
|
});
|
|
1901
1215
|
} catch (err) {
|
|
1902
|
-
|
|
1903
|
-
F: __dxlog_file5,
|
|
1904
|
-
L: 362,
|
|
1905
|
-
S: this,
|
|
1906
|
-
C: (f, a) => f(...a)
|
|
1907
|
-
});
|
|
1216
|
+
log4("initiation error", err, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 317, S: this });
|
|
1908
1217
|
}
|
|
1909
1218
|
});
|
|
1910
1219
|
},
|
|
@@ -1928,14 +1237,9 @@ var Swarm = class {
|
|
|
1928
1237
|
const ctx = this._ctx;
|
|
1929
1238
|
const peer = this._getOrCreatePeer(remotePeer);
|
|
1930
1239
|
if (remotePeer.peerKey < this._ownPeer.peerKey) {
|
|
1931
|
-
|
|
1240
|
+
log4("initiation delay", {
|
|
1932
1241
|
remotePeer
|
|
1933
|
-
}, {
|
|
1934
|
-
F: __dxlog_file5,
|
|
1935
|
-
L: 390,
|
|
1936
|
-
S: this,
|
|
1937
|
-
C: (f, a) => f(...a)
|
|
1938
|
-
});
|
|
1242
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 343, S: this });
|
|
1939
1243
|
await sleep2(this._initiationDelay);
|
|
1940
1244
|
}
|
|
1941
1245
|
if (ctx.disposed) {
|
|
@@ -1947,24 +1251,14 @@ var Swarm = class {
|
|
|
1947
1251
|
if (peer.connection) {
|
|
1948
1252
|
return;
|
|
1949
1253
|
}
|
|
1950
|
-
|
|
1254
|
+
log4("initiating connection...", {
|
|
1951
1255
|
remotePeer
|
|
1952
|
-
}, {
|
|
1953
|
-
|
|
1954
|
-
L: 406,
|
|
1955
|
-
S: this,
|
|
1956
|
-
C: (f, a) => f(...a)
|
|
1957
|
-
});
|
|
1958
|
-
await peer.initiateConnection();
|
|
1256
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 358, S: this });
|
|
1257
|
+
await peer.initiateConnection(ctx);
|
|
1959
1258
|
this._topology.update();
|
|
1960
|
-
|
|
1259
|
+
log4("initiated", {
|
|
1961
1260
|
remotePeer
|
|
1962
|
-
}, {
|
|
1963
|
-
F: __dxlog_file5,
|
|
1964
|
-
L: 409,
|
|
1965
|
-
S: this,
|
|
1966
|
-
C: (f, a) => f(...a)
|
|
1967
|
-
});
|
|
1261
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 363, S: this });
|
|
1968
1262
|
}
|
|
1969
1263
|
async _closeConnection(peerInfo) {
|
|
1970
1264
|
const peer = this._peers.get(peerInfo);
|
|
@@ -2011,11 +1305,11 @@ _ts_decorate3([
|
|
|
2011
1305
|
|
|
2012
1306
|
// src/swarm/swarm-mapper.ts
|
|
2013
1307
|
import { Event as Event4, SubscriptionList } from "@dxos/async";
|
|
2014
|
-
import { PublicKey as
|
|
2015
|
-
import { log as
|
|
1308
|
+
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
1309
|
+
import { log as log5 } from "@dxos/log";
|
|
2016
1310
|
import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
|
|
2017
1311
|
import { ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
2018
|
-
var
|
|
1312
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
2019
1313
|
var SwarmMapper = class {
|
|
2020
1314
|
_swarm;
|
|
2021
1315
|
_subscriptions = new SubscriptionList();
|
|
@@ -2041,12 +1335,7 @@ var SwarmMapper = class {
|
|
|
2041
1335
|
this._update();
|
|
2042
1336
|
}
|
|
2043
1337
|
_update() {
|
|
2044
|
-
|
|
2045
|
-
F: __dxlog_file6,
|
|
2046
|
-
L: 71,
|
|
2047
|
-
S: this,
|
|
2048
|
-
C: (f, a) => f(...a)
|
|
2049
|
-
});
|
|
1338
|
+
log5("updating swarm", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 40, S: this });
|
|
2050
1339
|
this._peers.clear();
|
|
2051
1340
|
this._peers.set(this._swarm.ownPeer, {
|
|
2052
1341
|
id: this._swarm.ownPeerId,
|
|
@@ -2055,22 +1344,17 @@ var SwarmMapper = class {
|
|
|
2055
1344
|
});
|
|
2056
1345
|
for (const connection of this._swarm.connections) {
|
|
2057
1346
|
this._peers.set(connection.remoteInfo, {
|
|
2058
|
-
id:
|
|
1347
|
+
id: PublicKey4.from(connection.remoteInfo.peerKey),
|
|
2059
1348
|
state: connection.state,
|
|
2060
1349
|
connections: [
|
|
2061
1350
|
this._swarm.ownPeerId
|
|
2062
1351
|
]
|
|
2063
1352
|
});
|
|
2064
1353
|
}
|
|
2065
|
-
|
|
1354
|
+
log5("graph changed", {
|
|
2066
1355
|
directConnections: this._swarm.connections.length,
|
|
2067
1356
|
totalPeersInSwarm: this._peers.size
|
|
2068
|
-
}, {
|
|
2069
|
-
F: __dxlog_file6,
|
|
2070
|
-
L: 112,
|
|
2071
|
-
S: this,
|
|
2072
|
-
C: (f, a) => f(...a)
|
|
2073
|
-
});
|
|
1357
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 77, S: this });
|
|
2074
1358
|
this.mapUpdated.emit(Array.from(this._peers.values()));
|
|
2075
1359
|
}
|
|
2076
1360
|
// TODO(burdon): Async open/close.
|
|
@@ -2083,24 +1367,21 @@ var SwarmMapper = class {
|
|
|
2083
1367
|
|
|
2084
1368
|
// src/swarm/connection-limiter.ts
|
|
2085
1369
|
import { DeferredTask as DeferredTask2 } from "@dxos/async";
|
|
2086
|
-
import { Context as
|
|
1370
|
+
import { Context as Context4 } from "@dxos/context";
|
|
2087
1371
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
2088
|
-
import { PublicKey as
|
|
2089
|
-
import { log as
|
|
1372
|
+
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1373
|
+
import { log as log6 } from "@dxos/log";
|
|
2090
1374
|
import { CancelledError as CancelledError3 } from "@dxos/protocols";
|
|
2091
1375
|
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
2092
|
-
var
|
|
1376
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
2093
1377
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
|
|
2094
1378
|
var ConnectionLimiter = class {
|
|
2095
|
-
_ctx = new
|
|
2096
|
-
F: __dxlog_file7,
|
|
2097
|
-
L: 23
|
|
2098
|
-
});
|
|
1379
|
+
_ctx = new Context4(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 15 });
|
|
2099
1380
|
_maxConcurrentInitConnections;
|
|
2100
1381
|
/**
|
|
2101
1382
|
* Queue of promises to resolve when initiating connections amount is below the limit.
|
|
2102
1383
|
*/
|
|
2103
|
-
_waitingPromises = new ComplexMap4(
|
|
1384
|
+
_waitingPromises = new ComplexMap4(PublicKey5.hash);
|
|
2104
1385
|
resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
|
|
2105
1386
|
Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
|
|
2106
1387
|
resolve();
|
|
@@ -2113,23 +1394,10 @@ var ConnectionLimiter = class {
|
|
|
2113
1394
|
* @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
|
|
2114
1395
|
*/
|
|
2115
1396
|
async connecting(sessionId) {
|
|
2116
|
-
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
2117
|
-
|
|
2118
|
-
L: 48,
|
|
2119
|
-
S: this,
|
|
2120
|
-
A: [
|
|
2121
|
-
"!this._waitingPromises.has(sessionId)",
|
|
2122
|
-
"'Peer is already waiting for connection'"
|
|
2123
|
-
]
|
|
2124
|
-
});
|
|
2125
|
-
log7("waiting", {
|
|
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'"] });
|
|
1398
|
+
log6("waiting", {
|
|
2126
1399
|
sessionId
|
|
2127
|
-
}, {
|
|
2128
|
-
F: __dxlog_file7,
|
|
2129
|
-
L: 49,
|
|
2130
|
-
S: this,
|
|
2131
|
-
C: (f, a) => f(...a)
|
|
2132
|
-
});
|
|
1400
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 32, S: this });
|
|
2133
1401
|
await new Promise((resolve, reject) => {
|
|
2134
1402
|
this._waitingPromises.set(sessionId, {
|
|
2135
1403
|
resolve,
|
|
@@ -2137,27 +1405,17 @@ var ConnectionLimiter = class {
|
|
|
2137
1405
|
});
|
|
2138
1406
|
this.resolveWaitingPromises.schedule();
|
|
2139
1407
|
});
|
|
2140
|
-
|
|
1408
|
+
log6("allow", {
|
|
2141
1409
|
sessionId
|
|
2142
|
-
}, {
|
|
2143
|
-
F: __dxlog_file7,
|
|
2144
|
-
L: 57,
|
|
2145
|
-
S: this,
|
|
2146
|
-
C: (f, a) => f(...a)
|
|
2147
|
-
});
|
|
1410
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 42, S: this });
|
|
2148
1411
|
}
|
|
2149
1412
|
/**
|
|
2150
1413
|
* Rejects promise returned by `connecting` method.
|
|
2151
1414
|
*/
|
|
2152
1415
|
doneConnecting(sessionId) {
|
|
2153
|
-
|
|
1416
|
+
log6("done", {
|
|
2154
1417
|
sessionId
|
|
2155
|
-
}, {
|
|
2156
|
-
F: __dxlog_file7,
|
|
2157
|
-
L: 64,
|
|
2158
|
-
S: this,
|
|
2159
|
-
C: (f, a) => f(...a)
|
|
2160
|
-
});
|
|
1418
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 49, S: this });
|
|
2161
1419
|
if (!this._waitingPromises.has(sessionId)) {
|
|
2162
1420
|
return;
|
|
2163
1421
|
}
|
|
@@ -2170,7 +1428,7 @@ var ConnectionLimiter = class {
|
|
|
2170
1428
|
// src/connection-log.ts
|
|
2171
1429
|
import { Event as Event5 } from "@dxos/async";
|
|
2172
1430
|
import { raise } from "@dxos/debug";
|
|
2173
|
-
import { PublicKey as
|
|
1431
|
+
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
2174
1432
|
import { ComplexMap as ComplexMap5 } from "@dxos/util";
|
|
2175
1433
|
var CONNECTION_GC_THRESHOLD = 1e3 * 60 * 15;
|
|
2176
1434
|
var EventType = /* @__PURE__ */ (function(EventType2) {
|
|
@@ -2185,7 +1443,7 @@ var ConnectionLog = class {
|
|
|
2185
1443
|
/**
|
|
2186
1444
|
* SwarmId => info
|
|
2187
1445
|
*/
|
|
2188
|
-
_swarms = new ComplexMap5(
|
|
1446
|
+
_swarms = new ComplexMap5(PublicKey6.hash);
|
|
2189
1447
|
update = new Event5();
|
|
2190
1448
|
getSwarmInfo(swarmId) {
|
|
2191
1449
|
return this._swarms.get(swarmId) ?? raise(new Error(`Swarm not found: ${swarmId}`));
|
|
@@ -2195,19 +1453,19 @@ var ConnectionLog = class {
|
|
|
2195
1453
|
}
|
|
2196
1454
|
joinedSwarm(swarm) {
|
|
2197
1455
|
const info = {
|
|
2198
|
-
id:
|
|
1456
|
+
id: PublicKey6.from(swarm._instanceId),
|
|
2199
1457
|
topic: swarm.topic,
|
|
2200
1458
|
isActive: true,
|
|
2201
1459
|
label: swarm.label,
|
|
2202
1460
|
connections: []
|
|
2203
1461
|
};
|
|
2204
|
-
this._swarms.set(
|
|
1462
|
+
this._swarms.set(PublicKey6.from(swarm._instanceId), info);
|
|
2205
1463
|
this.update.emit();
|
|
2206
1464
|
swarm.connectionAdded.on((connection) => {
|
|
2207
1465
|
const connectionInfo = {
|
|
2208
1466
|
state: ConnectionState.CREATED,
|
|
2209
1467
|
closeReason: connection.closeReason,
|
|
2210
|
-
remotePeerId:
|
|
1468
|
+
remotePeerId: PublicKey6.from(connection.remoteInfo.peerKey),
|
|
2211
1469
|
sessionId: connection.sessionId,
|
|
2212
1470
|
transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
|
|
2213
1471
|
protocolExtensions: [],
|
|
@@ -2247,7 +1505,7 @@ var ConnectionLog = class {
|
|
|
2247
1505
|
});
|
|
2248
1506
|
}
|
|
2249
1507
|
leftSwarm(swarm) {
|
|
2250
|
-
this.getSwarmInfo(
|
|
1508
|
+
this.getSwarmInfo(PublicKey6.from(swarm._instanceId)).isActive = false;
|
|
2251
1509
|
this.update.emit();
|
|
2252
1510
|
}
|
|
2253
1511
|
};
|
|
@@ -2259,33 +1517,31 @@ var gcSwarm = (swarm) => {
|
|
|
2259
1517
|
|
|
2260
1518
|
// src/network-manager.ts
|
|
2261
1519
|
import { Event as Event6, synchronized as synchronized4 } from "@dxos/async";
|
|
2262
|
-
import { invariant as invariant6 } from "@dxos/invariant";
|
|
2263
|
-
import { PublicKey as
|
|
2264
|
-
import { log as
|
|
1520
|
+
import { assertArgument, invariant as invariant6 } from "@dxos/invariant";
|
|
1521
|
+
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
1522
|
+
import { log as log7 } from "@dxos/log";
|
|
2265
1523
|
import { Messenger } from "@dxos/messaging";
|
|
2266
|
-
import { trace as trace3 } from "@dxos/protocols";
|
|
2267
1524
|
import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2268
1525
|
import { ComplexMap as ComplexMap6 } from "@dxos/util";
|
|
1526
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2269
1527
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
2270
1528
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2271
1529
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2272
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;
|
|
2273
1531
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2274
1532
|
}
|
|
2275
|
-
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2276
1533
|
var SwarmNetworkManager = class {
|
|
2277
1534
|
/**
|
|
2278
1535
|
* @internal
|
|
2279
1536
|
*/
|
|
2280
|
-
_swarms = new ComplexMap6(
|
|
2281
|
-
_mappers = new ComplexMap6(
|
|
1537
|
+
_swarms = new ComplexMap6(PublicKey7.hash);
|
|
1538
|
+
_mappers = new ComplexMap6(PublicKey7.hash);
|
|
2282
1539
|
_transportFactory;
|
|
2283
1540
|
_signalManager;
|
|
2284
1541
|
_messenger;
|
|
2285
1542
|
_signalConnection;
|
|
2286
1543
|
_connectionLimiter;
|
|
2287
1544
|
_connectionLog;
|
|
2288
|
-
_instanceId = PublicKey8.random().toHex();
|
|
2289
1545
|
_peerInfo = void 0;
|
|
2290
1546
|
_connectionState = ConnectionState2.ONLINE;
|
|
2291
1547
|
connectionStateChanged = new Event6();
|
|
@@ -2298,8 +1554,8 @@ var SwarmNetworkManager = class {
|
|
|
2298
1554
|
signalManager: this._signalManager
|
|
2299
1555
|
});
|
|
2300
1556
|
this._signalConnection = {
|
|
2301
|
-
join: (opts) => this._signalManager.join(opts),
|
|
2302
|
-
leave: (opts) => this._signalManager.leave(opts)
|
|
1557
|
+
join: (ctx, opts) => this._signalManager.join(ctx, opts),
|
|
1558
|
+
leave: (ctx, opts) => this._signalManager.leave(ctx, opts)
|
|
2303
1559
|
};
|
|
2304
1560
|
this._peerInfo = peerInfo;
|
|
2305
1561
|
this._connectionLimiter = new ConnectionLimiter();
|
|
@@ -2328,34 +1584,15 @@ var SwarmNetworkManager = class {
|
|
|
2328
1584
|
this._peerInfo = peerInfo;
|
|
2329
1585
|
}
|
|
2330
1586
|
async open() {
|
|
2331
|
-
|
|
2332
|
-
id: this._instanceId
|
|
2333
|
-
}), {
|
|
2334
|
-
F: __dxlog_file8,
|
|
2335
|
-
L: 133,
|
|
2336
|
-
S: this,
|
|
2337
|
-
C: (f, a) => f(...a)
|
|
2338
|
-
});
|
|
1587
|
+
log7("opening network manager", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 76, S: this });
|
|
2339
1588
|
await this._messenger.open();
|
|
2340
1589
|
await this._signalManager.open();
|
|
2341
|
-
|
|
2342
|
-
id: this._instanceId
|
|
2343
|
-
}), {
|
|
2344
|
-
F: __dxlog_file8,
|
|
2345
|
-
L: 136,
|
|
2346
|
-
S: this,
|
|
2347
|
-
C: (f, a) => f(...a)
|
|
2348
|
-
});
|
|
1590
|
+
log7("opened network manager", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 79, S: this });
|
|
2349
1591
|
}
|
|
2350
|
-
async close() {
|
|
1592
|
+
async close(ctx) {
|
|
2351
1593
|
for (const topic of this._swarms.keys()) {
|
|
2352
|
-
await this.leaveSwarm(topic).catch((err) => {
|
|
2353
|
-
|
|
2354
|
-
F: __dxlog_file8,
|
|
2355
|
-
L: 142,
|
|
2356
|
-
S: this,
|
|
2357
|
-
C: (f, a) => f(...a)
|
|
2358
|
-
});
|
|
1594
|
+
await this.leaveSwarm(ctx, topic).catch((err) => {
|
|
1595
|
+
log7(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 84, S: this });
|
|
2359
1596
|
});
|
|
2360
1597
|
}
|
|
2361
1598
|
await this._messenger.close();
|
|
@@ -2364,111 +1601,54 @@ var SwarmNetworkManager = class {
|
|
|
2364
1601
|
/**
|
|
2365
1602
|
* Join the swarm.
|
|
2366
1603
|
*/
|
|
2367
|
-
async joinSwarm({ topic, topology, protocolProvider: protocol, label }) {
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
A: [
|
|
2373
|
-
"PublicKey.isPublicKey(topic)",
|
|
2374
|
-
""
|
|
2375
|
-
]
|
|
2376
|
-
});
|
|
2377
|
-
invariant6(topology, void 0, {
|
|
2378
|
-
F: __dxlog_file8,
|
|
2379
|
-
L: 161,
|
|
2380
|
-
S: this,
|
|
2381
|
-
A: [
|
|
2382
|
-
"topology",
|
|
2383
|
-
""
|
|
2384
|
-
]
|
|
2385
|
-
});
|
|
2386
|
-
invariant6(this._peerInfo, void 0, {
|
|
2387
|
-
F: __dxlog_file8,
|
|
2388
|
-
L: 162,
|
|
2389
|
-
S: this,
|
|
2390
|
-
A: [
|
|
2391
|
-
"this._peerInfo",
|
|
2392
|
-
""
|
|
2393
|
-
]
|
|
2394
|
-
});
|
|
2395
|
-
invariant6(typeof protocol === "function", void 0, {
|
|
2396
|
-
F: __dxlog_file8,
|
|
2397
|
-
L: 163,
|
|
2398
|
-
S: this,
|
|
2399
|
-
A: [
|
|
2400
|
-
"typeof protocol === 'function'",
|
|
2401
|
-
""
|
|
2402
|
-
]
|
|
2403
|
-
});
|
|
1604
|
+
async joinSwarm(ctx, { topic, topology, protocolProvider: protocol, label }) {
|
|
1605
|
+
assertArgument(PublicKey7.isPublicKey(topic), "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
|
+
assertArgument(typeof protocol === "function", "protocolProvider");
|
|
2404
1609
|
if (this._swarms.has(topic)) {
|
|
2405
|
-
throw new Error(`Already connected to swarm: ${
|
|
1610
|
+
throw new Error(`Already connected to swarm: ${PublicKey7.from(topic)}`);
|
|
2406
1611
|
}
|
|
2407
|
-
|
|
2408
|
-
topic:
|
|
1612
|
+
log7("joining", {
|
|
1613
|
+
topic: PublicKey7.from(topic),
|
|
2409
1614
|
peerInfo: this._peerInfo,
|
|
2410
1615
|
topology: topology.toString()
|
|
2411
|
-
}, {
|
|
2412
|
-
F: __dxlog_file8,
|
|
2413
|
-
L: 168,
|
|
2414
|
-
S: this,
|
|
2415
|
-
C: (f, a) => f(...a)
|
|
2416
|
-
});
|
|
1616
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 100, S: this });
|
|
2417
1617
|
const swarm = new Swarm(topic, this._peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
2418
1618
|
swarm.errors.handle((error) => {
|
|
2419
|
-
|
|
1619
|
+
log7("swarm error", {
|
|
2420
1620
|
error
|
|
2421
|
-
}, {
|
|
2422
|
-
F: __dxlog_file8,
|
|
2423
|
-
L: 181,
|
|
2424
|
-
S: this,
|
|
2425
|
-
C: (f, a) => f(...a)
|
|
2426
|
-
});
|
|
1621
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 107, S: this });
|
|
2427
1622
|
});
|
|
2428
1623
|
this._swarms.set(topic, swarm);
|
|
2429
1624
|
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
2430
1625
|
await swarm.open();
|
|
2431
|
-
this._signalConnection.join({
|
|
1626
|
+
this._signalConnection.join(ctx, {
|
|
2432
1627
|
topic,
|
|
2433
1628
|
peer: this._peerInfo
|
|
2434
|
-
}).catch((error) =>
|
|
2435
|
-
F: __dxlog_file8,
|
|
2436
|
-
L: 190,
|
|
2437
|
-
S: this,
|
|
2438
|
-
C: (f, a) => f(...a)
|
|
2439
|
-
}));
|
|
1629
|
+
}).catch((error) => log7.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 118, S: this }));
|
|
2440
1630
|
this.topicsUpdated.emit();
|
|
2441
1631
|
this._connectionLog?.joinedSwarm(swarm);
|
|
2442
|
-
|
|
2443
|
-
topic:
|
|
1632
|
+
log7("joined", {
|
|
1633
|
+
topic: PublicKey7.from(topic),
|
|
2444
1634
|
count: this._swarms.size
|
|
2445
|
-
}, {
|
|
2446
|
-
F: __dxlog_file8,
|
|
2447
|
-
L: 194,
|
|
2448
|
-
S: this,
|
|
2449
|
-
C: (f, a) => f(...a)
|
|
2450
|
-
});
|
|
1635
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 121, S: this });
|
|
2451
1636
|
return {
|
|
2452
|
-
close: () => this.leaveSwarm(topic)
|
|
1637
|
+
close: (ctx2) => this.leaveSwarm(ctx2, topic)
|
|
2453
1638
|
};
|
|
2454
1639
|
}
|
|
2455
1640
|
/**
|
|
2456
1641
|
* Close the connection.
|
|
2457
1642
|
*/
|
|
2458
|
-
async leaveSwarm(topic) {
|
|
1643
|
+
async leaveSwarm(ctx, topic) {
|
|
2459
1644
|
if (!this._swarms.has(topic)) {
|
|
2460
1645
|
return;
|
|
2461
1646
|
}
|
|
2462
|
-
|
|
2463
|
-
topic:
|
|
2464
|
-
}, {
|
|
2465
|
-
F: __dxlog_file8,
|
|
2466
|
-
L: 211,
|
|
2467
|
-
S: this,
|
|
2468
|
-
C: (f, a) => f(...a)
|
|
2469
|
-
});
|
|
1647
|
+
log7("leaving", {
|
|
1648
|
+
topic: PublicKey7.from(topic)
|
|
1649
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 136, S: this });
|
|
2470
1650
|
const swarm = this._swarms.get(topic);
|
|
2471
|
-
await this._signalConnection.leave({
|
|
1651
|
+
await this._signalConnection.leave(ctx, {
|
|
2472
1652
|
topic,
|
|
2473
1653
|
peer: swarm.ownPeer
|
|
2474
1654
|
});
|
|
@@ -2479,15 +1659,10 @@ var SwarmNetworkManager = class {
|
|
|
2479
1659
|
await swarm.destroy();
|
|
2480
1660
|
this._swarms.delete(topic);
|
|
2481
1661
|
this.topicsUpdated.emit();
|
|
2482
|
-
|
|
2483
|
-
topic:
|
|
1662
|
+
log7("left", {
|
|
1663
|
+
topic: PublicKey7.from(topic),
|
|
2484
1664
|
count: this._swarms.size
|
|
2485
|
-
}, {
|
|
2486
|
-
F: __dxlog_file8,
|
|
2487
|
-
L: 225,
|
|
2488
|
-
S: this,
|
|
2489
|
-
C: (f, a) => f(...a)
|
|
2490
|
-
});
|
|
1665
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 151, S: this });
|
|
2491
1666
|
}
|
|
2492
1667
|
async setConnectionState(state) {
|
|
2493
1668
|
if (state === this._connectionState) {
|
|
@@ -2525,34 +1700,18 @@ _ts_decorate4([
|
|
|
2525
1700
|
|
|
2526
1701
|
// src/topology/fully-connected-topology.ts
|
|
2527
1702
|
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2528
|
-
var
|
|
1703
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
2529
1704
|
var FullyConnectedTopology = class {
|
|
2530
1705
|
_controller;
|
|
2531
1706
|
toString() {
|
|
2532
1707
|
return "FullyConnectedTopology";
|
|
2533
1708
|
}
|
|
2534
1709
|
init(controller) {
|
|
2535
|
-
invariant7(!this._controller, "Already initialized", {
|
|
2536
|
-
F: __dxlog_file9,
|
|
2537
|
-
L: 18,
|
|
2538
|
-
S: this,
|
|
2539
|
-
A: [
|
|
2540
|
-
"!this._controller",
|
|
2541
|
-
"'Already initialized'"
|
|
2542
|
-
]
|
|
2543
|
-
});
|
|
1710
|
+
invariant7(!this._controller, "Already initialized", { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 11, S: this, A: ["!this._controller", "'Already initialized'"] });
|
|
2544
1711
|
this._controller = controller;
|
|
2545
1712
|
}
|
|
2546
1713
|
update() {
|
|
2547
|
-
invariant7(this._controller, "Not initialized", {
|
|
2548
|
-
F: __dxlog_file9,
|
|
2549
|
-
L: 23,
|
|
2550
|
-
S: this,
|
|
2551
|
-
A: [
|
|
2552
|
-
"this._controller",
|
|
2553
|
-
"'Not initialized'"
|
|
2554
|
-
]
|
|
2555
|
-
});
|
|
1714
|
+
invariant7(this._controller, "Not initialized", { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 15, S: this, A: ["this._controller", "'Not initialized'"] });
|
|
2556
1715
|
const { candidates: discovered } = this._controller.getState();
|
|
2557
1716
|
for (const peer of discovered) {
|
|
2558
1717
|
this._controller.connect(peer);
|
|
@@ -2565,329 +1724,21 @@ var FullyConnectedTopology = class {
|
|
|
2565
1724
|
}
|
|
2566
1725
|
};
|
|
2567
1726
|
|
|
2568
|
-
// src/topology/mmst-topology.ts
|
|
2569
|
-
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2570
|
-
import { log as log9 } from "@dxos/log";
|
|
2571
|
-
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2572
|
-
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2573
|
-
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2574
|
-
var MMSTTopology = class {
|
|
2575
|
-
_originateConnections;
|
|
2576
|
-
_maxPeers;
|
|
2577
|
-
_sampleSize;
|
|
2578
|
-
_controller;
|
|
2579
|
-
_sampleCollected = false;
|
|
2580
|
-
_lastAction = /* @__PURE__ */ new Date(0);
|
|
2581
|
-
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2582
|
-
this._originateConnections = originateConnections;
|
|
2583
|
-
this._maxPeers = maxPeers;
|
|
2584
|
-
this._sampleSize = sampleSize;
|
|
2585
|
-
}
|
|
2586
|
-
init(controller) {
|
|
2587
|
-
invariant8(!this._controller, "Already initialized", {
|
|
2588
|
-
F: __dxlog_file10,
|
|
2589
|
-
L: 49,
|
|
2590
|
-
S: this,
|
|
2591
|
-
A: [
|
|
2592
|
-
"!this._controller",
|
|
2593
|
-
"'Already initialized'"
|
|
2594
|
-
]
|
|
2595
|
-
});
|
|
2596
|
-
this._controller = controller;
|
|
2597
|
-
}
|
|
2598
|
-
update() {
|
|
2599
|
-
invariant8(this._controller, "Not initialized", {
|
|
2600
|
-
F: __dxlog_file10,
|
|
2601
|
-
L: 54,
|
|
2602
|
-
S: this,
|
|
2603
|
-
A: [
|
|
2604
|
-
"this._controller",
|
|
2605
|
-
"'Not initialized'"
|
|
2606
|
-
]
|
|
2607
|
-
});
|
|
2608
|
-
const { connected, candidates } = this._controller.getState();
|
|
2609
|
-
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2610
|
-
log9("Running the algorithm.", void 0, {
|
|
2611
|
-
F: __dxlog_file10,
|
|
2612
|
-
L: 58,
|
|
2613
|
-
S: this,
|
|
2614
|
-
C: (f, a) => f(...a)
|
|
2615
|
-
});
|
|
2616
|
-
this._sampleCollected = true;
|
|
2617
|
-
this._runAlgorithm();
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
forceUpdate() {
|
|
2621
|
-
this._lastAction = /* @__PURE__ */ new Date(0);
|
|
2622
|
-
this.update();
|
|
2623
|
-
}
|
|
2624
|
-
async onOffer(peer) {
|
|
2625
|
-
invariant8(this._controller, "Not initialized", {
|
|
2626
|
-
F: __dxlog_file10,
|
|
2627
|
-
L: 70,
|
|
2628
|
-
S: this,
|
|
2629
|
-
A: [
|
|
2630
|
-
"this._controller",
|
|
2631
|
-
"'Not initialized'"
|
|
2632
|
-
]
|
|
2633
|
-
});
|
|
2634
|
-
const { connected } = this._controller.getState();
|
|
2635
|
-
const accept = connected.length < this._maxPeers;
|
|
2636
|
-
log9(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2637
|
-
F: __dxlog_file10,
|
|
2638
|
-
L: 73,
|
|
2639
|
-
S: this,
|
|
2640
|
-
C: (f, a) => f(...a)
|
|
2641
|
-
});
|
|
2642
|
-
return accept;
|
|
2643
|
-
}
|
|
2644
|
-
async destroy() {
|
|
2645
|
-
}
|
|
2646
|
-
_runAlgorithm() {
|
|
2647
|
-
invariant8(this._controller, "Not initialized", {
|
|
2648
|
-
F: __dxlog_file10,
|
|
2649
|
-
L: 82,
|
|
2650
|
-
S: this,
|
|
2651
|
-
A: [
|
|
2652
|
-
"this._controller",
|
|
2653
|
-
"'Not initialized'"
|
|
2654
|
-
]
|
|
2655
|
-
});
|
|
2656
|
-
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2657
|
-
if (connected.length > this._maxPeers) {
|
|
2658
|
-
log9(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2659
|
-
F: __dxlog_file10,
|
|
2660
|
-
L: 88,
|
|
2661
|
-
S: this,
|
|
2662
|
-
C: (f, a) => f(...a)
|
|
2663
|
-
});
|
|
2664
|
-
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2665
|
-
invariant8(sorted.length === 0, void 0, {
|
|
2666
|
-
F: __dxlog_file10,
|
|
2667
|
-
L: 92,
|
|
2668
|
-
S: this,
|
|
2669
|
-
A: [
|
|
2670
|
-
"sorted.length === 0",
|
|
2671
|
-
""
|
|
2672
|
-
]
|
|
2673
|
-
});
|
|
2674
|
-
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2675
|
-
log9(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2676
|
-
F: __dxlog_file10,
|
|
2677
|
-
L: 95,
|
|
2678
|
-
S: this,
|
|
2679
|
-
C: (f, a) => f(...a)
|
|
2680
|
-
});
|
|
2681
|
-
}
|
|
2682
|
-
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2683
|
-
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2684
|
-
log9(`Disconnect ${peer}.`, void 0, {
|
|
2685
|
-
F: __dxlog_file10,
|
|
2686
|
-
L: 100,
|
|
2687
|
-
S: this,
|
|
2688
|
-
C: (f, a) => f(...a)
|
|
2689
|
-
});
|
|
2690
|
-
this._controller.disconnect(peer);
|
|
2691
|
-
}
|
|
2692
|
-
this._lastAction = /* @__PURE__ */ new Date();
|
|
2693
|
-
} else {
|
|
2694
|
-
log9("rate limited disconnect", void 0, {
|
|
2695
|
-
F: __dxlog_file10,
|
|
2696
|
-
L: 105,
|
|
2697
|
-
S: this,
|
|
2698
|
-
C: (f, a) => f(...a)
|
|
2699
|
-
});
|
|
2700
|
-
}
|
|
2701
|
-
} else if (connected.length < this._originateConnections) {
|
|
2702
|
-
log9(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2703
|
-
F: __dxlog_file10,
|
|
2704
|
-
L: 109,
|
|
2705
|
-
S: this,
|
|
2706
|
-
C: (f, a) => f(...a)
|
|
2707
|
-
});
|
|
2708
|
-
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2709
|
-
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2710
|
-
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2711
|
-
log9(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2712
|
-
F: __dxlog_file10,
|
|
2713
|
-
L: 114,
|
|
2714
|
-
S: this,
|
|
2715
|
-
C: (f, a) => f(...a)
|
|
2716
|
-
});
|
|
2717
|
-
}
|
|
2718
|
-
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2719
|
-
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2720
|
-
log9(`Connect ${peer}.`, void 0, {
|
|
2721
|
-
F: __dxlog_file10,
|
|
2722
|
-
L: 118,
|
|
2723
|
-
S: this,
|
|
2724
|
-
C: (f, a) => f(...a)
|
|
2725
|
-
});
|
|
2726
|
-
this._controller.connect(peer);
|
|
2727
|
-
}
|
|
2728
|
-
this._lastAction = /* @__PURE__ */ new Date();
|
|
2729
|
-
} else {
|
|
2730
|
-
log9("rate limited connect", void 0, {
|
|
2731
|
-
F: __dxlog_file10,
|
|
2732
|
-
L: 123,
|
|
2733
|
-
S: this,
|
|
2734
|
-
C: (f, a) => f(...a)
|
|
2735
|
-
});
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
}
|
|
2739
|
-
toString() {
|
|
2740
|
-
return "MMSTTopology";
|
|
2741
|
-
}
|
|
2742
|
-
};
|
|
2743
|
-
var sortByXorDistance = (keys, reference) => {
|
|
2744
|
-
const sorted = keys.sort((a, b) => {
|
|
2745
|
-
return compareXor(distXor(a.asBuffer(), reference.asBuffer()), distXor(b.asBuffer(), reference.asBuffer()));
|
|
2746
|
-
});
|
|
2747
|
-
log9("Sorted keys", {
|
|
2748
|
-
keys,
|
|
2749
|
-
reference,
|
|
2750
|
-
sorted
|
|
2751
|
-
}, {
|
|
2752
|
-
F: __dxlog_file10,
|
|
2753
|
-
L: 137,
|
|
2754
|
-
S: void 0,
|
|
2755
|
-
C: (f, a) => f(...a)
|
|
2756
|
-
});
|
|
2757
|
-
return sorted;
|
|
2758
|
-
};
|
|
2759
|
-
var distXor = (a, b) => {
|
|
2760
|
-
const maxLength = Math.max(a.length, b.length);
|
|
2761
|
-
const result = Buffer.allocUnsafe(maxLength);
|
|
2762
|
-
for (let i = 0; i < maxLength; i++) {
|
|
2763
|
-
result[i] = (a[i] || 0) ^ (b[i] || 0);
|
|
2764
|
-
}
|
|
2765
|
-
return result;
|
|
2766
|
-
};
|
|
2767
|
-
var compareXor = (a, b) => {
|
|
2768
|
-
const maxLength = Math.max(a.length, b.length);
|
|
2769
|
-
for (let i = 0; i < maxLength; i++) {
|
|
2770
|
-
if ((a[i] || 0) === (b[i] || 0)) {
|
|
2771
|
-
continue;
|
|
2772
|
-
}
|
|
2773
|
-
return (a[i] || 0) < (b[i] || 0) ? -1 : 1;
|
|
2774
|
-
}
|
|
2775
|
-
return 0;
|
|
2776
|
-
};
|
|
2777
|
-
|
|
2778
|
-
// src/topology/star-topology.ts
|
|
2779
|
-
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2780
|
-
import { log as log10 } from "@dxos/log";
|
|
2781
|
-
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
2782
|
-
var StarTopology = class {
|
|
2783
|
-
_centralPeer;
|
|
2784
|
-
_controller;
|
|
2785
|
-
constructor(_centralPeer) {
|
|
2786
|
-
this._centralPeer = _centralPeer;
|
|
2787
|
-
}
|
|
2788
|
-
toString() {
|
|
2789
|
-
return `StarTopology(${this._centralPeer.truncate()})`;
|
|
2790
|
-
}
|
|
2791
|
-
init(controller) {
|
|
2792
|
-
invariant9(!this._controller, "Already initialized.", {
|
|
2793
|
-
F: __dxlog_file11,
|
|
2794
|
-
L: 21,
|
|
2795
|
-
S: this,
|
|
2796
|
-
A: [
|
|
2797
|
-
"!this._controller",
|
|
2798
|
-
"'Already initialized.'"
|
|
2799
|
-
]
|
|
2800
|
-
});
|
|
2801
|
-
this._controller = controller;
|
|
2802
|
-
}
|
|
2803
|
-
update() {
|
|
2804
|
-
invariant9(this._controller, "Not initialized.", {
|
|
2805
|
-
F: __dxlog_file11,
|
|
2806
|
-
L: 26,
|
|
2807
|
-
S: this,
|
|
2808
|
-
A: [
|
|
2809
|
-
"this._controller",
|
|
2810
|
-
"'Not initialized.'"
|
|
2811
|
-
]
|
|
2812
|
-
});
|
|
2813
|
-
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
2814
|
-
if (!ownPeerId.equals(this._centralPeer)) {
|
|
2815
|
-
log10("leaf peer dropping all connections apart from central peer.", void 0, {
|
|
2816
|
-
F: __dxlog_file11,
|
|
2817
|
-
L: 29,
|
|
2818
|
-
S: this,
|
|
2819
|
-
C: (f, a) => f(...a)
|
|
2820
|
-
});
|
|
2821
|
-
for (const peer of connected) {
|
|
2822
|
-
if (!peer.equals(this._centralPeer)) {
|
|
2823
|
-
log10("dropping connection", {
|
|
2824
|
-
peer
|
|
2825
|
-
}, {
|
|
2826
|
-
F: __dxlog_file11,
|
|
2827
|
-
L: 34,
|
|
2828
|
-
S: this,
|
|
2829
|
-
C: (f, a) => f(...a)
|
|
2830
|
-
});
|
|
2831
|
-
this._controller.disconnect(peer);
|
|
2832
|
-
}
|
|
2833
|
-
}
|
|
2834
|
-
}
|
|
2835
|
-
for (const peer of candidates) {
|
|
2836
|
-
if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
|
|
2837
|
-
log10("connecting to peer", {
|
|
2838
|
-
peer
|
|
2839
|
-
}, {
|
|
2840
|
-
F: __dxlog_file11,
|
|
2841
|
-
L: 43,
|
|
2842
|
-
S: this,
|
|
2843
|
-
C: (f, a) => f(...a)
|
|
2844
|
-
});
|
|
2845
|
-
this._controller.connect(peer);
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
|
-
}
|
|
2849
|
-
async onOffer(peer) {
|
|
2850
|
-
invariant9(this._controller, "Not initialized.", {
|
|
2851
|
-
F: __dxlog_file11,
|
|
2852
|
-
L: 50,
|
|
2853
|
-
S: this,
|
|
2854
|
-
A: [
|
|
2855
|
-
"this._controller",
|
|
2856
|
-
"'Not initialized.'"
|
|
2857
|
-
]
|
|
2858
|
-
});
|
|
2859
|
-
const { ownPeerId } = this._controller.getState();
|
|
2860
|
-
log10("offer", {
|
|
2861
|
-
peer,
|
|
2862
|
-
isCentral: peer.equals(this._centralPeer),
|
|
2863
|
-
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
2864
|
-
}, {
|
|
2865
|
-
F: __dxlog_file11,
|
|
2866
|
-
L: 52,
|
|
2867
|
-
S: this,
|
|
2868
|
-
C: (f, a) => f(...a)
|
|
2869
|
-
});
|
|
2870
|
-
return ownPeerId.equals(this._centralPeer) || peer.equals(this._centralPeer);
|
|
2871
|
-
}
|
|
2872
|
-
async destroy() {
|
|
2873
|
-
}
|
|
2874
|
-
};
|
|
2875
|
-
|
|
2876
1727
|
// src/transport/memory-transport.ts
|
|
2877
1728
|
import { Transform } from "node:stream";
|
|
2878
1729
|
import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
|
|
2879
1730
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
2880
|
-
import { invariant as
|
|
2881
|
-
import { PublicKey as
|
|
2882
|
-
import { log as
|
|
1731
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
1732
|
+
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
1733
|
+
import { log as log8, logInfo as logInfo3 } from "@dxos/log";
|
|
2883
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";
|
|
2884
1736
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
2885
1737
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2886
1738
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2887
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;
|
|
2888
1740
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2889
1741
|
}
|
|
2890
|
-
var __dxlog_file12 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
2891
1742
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
2892
1743
|
var createStreamDelay = (delay) => {
|
|
2893
1744
|
return new Transform({
|
|
@@ -2903,8 +1754,8 @@ var MemoryTransportFactory = {
|
|
|
2903
1754
|
var MemoryTransport = class _MemoryTransport {
|
|
2904
1755
|
_options;
|
|
2905
1756
|
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
2906
|
-
static _connections = new ComplexMap7(
|
|
2907
|
-
_instanceId =
|
|
1757
|
+
static _connections = new ComplexMap7(PublicKey8.hash);
|
|
1758
|
+
_instanceId = PublicKey8.random();
|
|
2908
1759
|
_remote = new Trigger2();
|
|
2909
1760
|
_outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2910
1761
|
_incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
@@ -2916,34 +1767,16 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2916
1767
|
errors = new ErrorStream3();
|
|
2917
1768
|
constructor(_options) {
|
|
2918
1769
|
this._options = _options;
|
|
2919
|
-
|
|
2920
|
-
F: __dxlog_file12,
|
|
2921
|
-
L: 64,
|
|
2922
|
-
S: this,
|
|
2923
|
-
A: [
|
|
2924
|
-
"!MemoryTransport._connections.has(this._instanceId)",
|
|
2925
|
-
"'Duplicate memory connection'"
|
|
2926
|
-
]
|
|
2927
|
-
});
|
|
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'"] });
|
|
2928
1771
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
2929
1772
|
}
|
|
2930
1773
|
get isOpen() {
|
|
2931
1774
|
return !this._closed;
|
|
2932
1775
|
}
|
|
2933
1776
|
async open() {
|
|
2934
|
-
|
|
2935
|
-
F: __dxlog_file12,
|
|
2936
|
-
L: 74,
|
|
2937
|
-
S: this,
|
|
2938
|
-
C: (f, a) => f(...a)
|
|
2939
|
-
});
|
|
1777
|
+
log8("opening...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 59, S: this });
|
|
2940
1778
|
if (this._options.initiator) {
|
|
2941
|
-
|
|
2942
|
-
F: __dxlog_file12,
|
|
2943
|
-
L: 78,
|
|
2944
|
-
S: this,
|
|
2945
|
-
C: (f, a) => f(...a)
|
|
2946
|
-
});
|
|
1779
|
+
log8("sending signal", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 62, S: this });
|
|
2947
1780
|
try {
|
|
2948
1781
|
await this._options.sendSignal({
|
|
2949
1782
|
payload: {
|
|
@@ -2969,23 +1802,10 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2969
1802
|
this.closed.emit();
|
|
2970
1803
|
return;
|
|
2971
1804
|
}
|
|
2972
|
-
|
|
2973
|
-
F: __dxlog_file12,
|
|
2974
|
-
L: 104,
|
|
2975
|
-
S: this,
|
|
2976
|
-
A: [
|
|
2977
|
-
"!this._remoteConnection._remoteConnection",
|
|
2978
|
-
"`Remote already connected: ${this._remoteInstanceId}`"
|
|
2979
|
-
]
|
|
2980
|
-
});
|
|
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}`"] });
|
|
2981
1806
|
this._remoteConnection._remoteConnection = this;
|
|
2982
1807
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
2983
|
-
|
|
2984
|
-
F: __dxlog_file12,
|
|
2985
|
-
L: 108,
|
|
2986
|
-
S: this,
|
|
2987
|
-
C: (f, a) => f(...a)
|
|
2988
|
-
});
|
|
1808
|
+
log8("connected", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 93, S: this });
|
|
2989
1809
|
this._options.stream.pipe(this._outgoingDelay).pipe(this._remoteConnection._options.stream).pipe(this._incomingDelay).pipe(this._options.stream);
|
|
2990
1810
|
this.connected.emit();
|
|
2991
1811
|
this._remoteConnection.connected.emit();
|
|
@@ -2999,12 +1819,7 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2999
1819
|
return this;
|
|
3000
1820
|
}
|
|
3001
1821
|
async close() {
|
|
3002
|
-
|
|
3003
|
-
F: __dxlog_file12,
|
|
3004
|
-
L: 130,
|
|
3005
|
-
S: this,
|
|
3006
|
-
C: (f, a) => f(...a)
|
|
3007
|
-
});
|
|
1822
|
+
log8("closing...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 107, S: this });
|
|
3008
1823
|
this._closed = true;
|
|
3009
1824
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
3010
1825
|
if (this._remoteConnection) {
|
|
@@ -3020,29 +1835,19 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3020
1835
|
this._remoteConnection = void 0;
|
|
3021
1836
|
}
|
|
3022
1837
|
this.closed.emit();
|
|
3023
|
-
|
|
3024
|
-
F: __dxlog_file12,
|
|
3025
|
-
L: 158,
|
|
3026
|
-
S: this,
|
|
3027
|
-
C: (f, a) => f(...a)
|
|
3028
|
-
});
|
|
1838
|
+
log8("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 130, S: this });
|
|
3029
1839
|
return this;
|
|
3030
1840
|
}
|
|
3031
1841
|
async onSignal({ payload }) {
|
|
3032
|
-
|
|
1842
|
+
log8("received signal", {
|
|
3033
1843
|
payload
|
|
3034
|
-
}, {
|
|
3035
|
-
F: __dxlog_file12,
|
|
3036
|
-
L: 163,
|
|
3037
|
-
S: this,
|
|
3038
|
-
C: (f, a) => f(...a)
|
|
3039
|
-
});
|
|
1844
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 134, S: this });
|
|
3040
1845
|
if (!payload?.transportId) {
|
|
3041
1846
|
return;
|
|
3042
1847
|
}
|
|
3043
1848
|
const transportId = payload.transportId;
|
|
3044
1849
|
if (transportId) {
|
|
3045
|
-
const remoteId =
|
|
1850
|
+
const remoteId = PublicKey8.fromHex(transportId);
|
|
3046
1851
|
this._remote.wake(remoteId);
|
|
3047
1852
|
}
|
|
3048
1853
|
}
|
|
@@ -3122,18 +1927,18 @@ var getRtcConnectionFactory = () => {
|
|
|
3122
1927
|
|
|
3123
1928
|
// src/transport/webrtc/rtc-peer-connection.ts
|
|
3124
1929
|
import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } from "@dxos/async";
|
|
3125
|
-
import { invariant as
|
|
3126
|
-
import { log as
|
|
1930
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
1931
|
+
import { log as log10, logInfo as logInfo4 } from "@dxos/log";
|
|
3127
1932
|
import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
|
|
3128
|
-
import { trace
|
|
1933
|
+
import { trace } from "@dxos/tracing";
|
|
3129
1934
|
|
|
3130
1935
|
// src/transport/webrtc/rtc-transport-channel.ts
|
|
3131
1936
|
import { Duplex } from "node:stream";
|
|
3132
1937
|
import { Event as AsyncEvent } from "@dxos/async";
|
|
3133
1938
|
import { Resource } from "@dxos/context";
|
|
3134
1939
|
import { ErrorStream as ErrorStream4 } from "@dxos/debug";
|
|
3135
|
-
import { invariant as
|
|
3136
|
-
import { log as
|
|
1940
|
+
import { invariant as invariant9 } from "@dxos/invariant";
|
|
1941
|
+
import { log as log9 } from "@dxos/log";
|
|
3137
1942
|
import { ConnectivityError as ConnectivityError2 } from "@dxos/protocols";
|
|
3138
1943
|
|
|
3139
1944
|
// src/transport/webrtc/rtc-transport-stats.ts
|
|
@@ -3184,7 +1989,7 @@ var getRtcConnectionStats = async (connection, channelTopic) => {
|
|
|
3184
1989
|
};
|
|
3185
1990
|
|
|
3186
1991
|
// src/transport/webrtc/rtc-transport-channel.ts
|
|
3187
|
-
var
|
|
1992
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
|
|
3188
1993
|
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
3189
1994
|
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3190
1995
|
var RtcTransportChannel = class extends Resource {
|
|
@@ -3209,15 +2014,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3209
2014
|
}
|
|
3210
2015
|
}
|
|
3211
2016
|
async _open() {
|
|
3212
|
-
|
|
3213
|
-
F: __dxlog_file13,
|
|
3214
|
-
L: 57,
|
|
3215
|
-
S: this,
|
|
3216
|
-
A: [
|
|
3217
|
-
"!this._isChannelCreationInProgress",
|
|
3218
|
-
""
|
|
3219
|
-
]
|
|
3220
|
-
});
|
|
2017
|
+
invariant9(!this._isChannelCreationInProgress, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 41, S: this, A: ["!this._isChannelCreationInProgress", ""] });
|
|
3221
2018
|
this._isChannelCreationInProgress = true;
|
|
3222
2019
|
this._connection.createDataChannel(this._options.topic).then((channel) => {
|
|
3223
2020
|
if (this.isOpen) {
|
|
@@ -3228,17 +2025,14 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3228
2025
|
}
|
|
3229
2026
|
}).catch((err) => {
|
|
3230
2027
|
if (this.isOpen) {
|
|
3231
|
-
const error = err instanceof Error ? err : new ConnectivityError2(
|
|
2028
|
+
const error = err instanceof Error ? err : new ConnectivityError2({
|
|
2029
|
+
message: `Failed to create a channel: ${JSON.stringify(err?.message)}`
|
|
2030
|
+
});
|
|
3232
2031
|
this.errors.raise(error);
|
|
3233
2032
|
} else {
|
|
3234
|
-
|
|
2033
|
+
log9.verbose("connection establishment failed after transport was closed", {
|
|
3235
2034
|
err
|
|
3236
|
-
}, {
|
|
3237
|
-
F: __dxlog_file13,
|
|
3238
|
-
L: 77,
|
|
3239
|
-
S: this,
|
|
3240
|
-
C: (f, a) => f(...a)
|
|
3241
|
-
});
|
|
2035
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 57, S: this });
|
|
3242
2036
|
}
|
|
3243
2037
|
}).finally(() => {
|
|
3244
2038
|
this._isChannelCreationInProgress = false;
|
|
@@ -3251,34 +2045,19 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3251
2045
|
this._stream = void 0;
|
|
3252
2046
|
}
|
|
3253
2047
|
this.closed.emit();
|
|
3254
|
-
|
|
3255
|
-
F: __dxlog_file13,
|
|
3256
|
-
L: 93,
|
|
3257
|
-
S: this,
|
|
3258
|
-
C: (f, a) => f(...a)
|
|
3259
|
-
});
|
|
2048
|
+
log9("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 72, S: this });
|
|
3260
2049
|
}
|
|
3261
2050
|
_initChannel(channel) {
|
|
3262
2051
|
Object.assign(channel, {
|
|
3263
2052
|
onopen: () => {
|
|
3264
2053
|
if (!this.isOpen) {
|
|
3265
|
-
|
|
2054
|
+
log9.warn("channel opened in a closed transport", {
|
|
3266
2055
|
topic: this._options.topic
|
|
3267
|
-
}, {
|
|
3268
|
-
F: __dxlog_file13,
|
|
3269
|
-
L: 100,
|
|
3270
|
-
S: this,
|
|
3271
|
-
C: (f, a) => f(...a)
|
|
3272
|
-
});
|
|
2056
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 78, S: this });
|
|
3273
2057
|
this._safeCloseChannel(channel);
|
|
3274
2058
|
return;
|
|
3275
2059
|
}
|
|
3276
|
-
|
|
3277
|
-
F: __dxlog_file13,
|
|
3278
|
-
L: 105,
|
|
3279
|
-
S: this,
|
|
3280
|
-
C: (f, a) => f(...a)
|
|
3281
|
-
});
|
|
2060
|
+
log9("onopen", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 84, S: this });
|
|
3282
2061
|
const duplex = new Duplex({
|
|
3283
2062
|
read: () => {
|
|
3284
2063
|
},
|
|
@@ -3291,22 +2070,12 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3291
2070
|
this.connected.emit();
|
|
3292
2071
|
},
|
|
3293
2072
|
onclose: async () => {
|
|
3294
|
-
|
|
3295
|
-
F: __dxlog_file13,
|
|
3296
|
-
L: 118,
|
|
3297
|
-
S: this,
|
|
3298
|
-
C: (f, a) => f(...a)
|
|
3299
|
-
});
|
|
2073
|
+
log9("onclose", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 96, S: this });
|
|
3300
2074
|
await this.close();
|
|
3301
2075
|
},
|
|
3302
2076
|
onmessage: async (event) => {
|
|
3303
2077
|
if (!this._stream) {
|
|
3304
|
-
|
|
3305
|
-
F: __dxlog_file13,
|
|
3306
|
-
L: 124,
|
|
3307
|
-
S: this,
|
|
3308
|
-
C: (f, a) => f(...a)
|
|
3309
|
-
});
|
|
2078
|
+
log9.warn("ignoring message on a closed channel", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 101, S: this });
|
|
3310
2079
|
return;
|
|
3311
2080
|
}
|
|
3312
2081
|
let data = event.data;
|
|
@@ -3332,12 +2101,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3332
2101
|
}
|
|
3333
2102
|
async _handleChannelWrite(chunk, callback) {
|
|
3334
2103
|
if (!this._channel) {
|
|
3335
|
-
|
|
3336
|
-
F: __dxlog_file13,
|
|
3337
|
-
L: 154,
|
|
3338
|
-
S: this,
|
|
3339
|
-
C: (f, a) => f(...a)
|
|
3340
|
-
});
|
|
2104
|
+
log9.warn("writing to a channel after a connection was closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 127, S: this });
|
|
3341
2105
|
return;
|
|
3342
2106
|
}
|
|
3343
2107
|
if (chunk.length > MAX_MESSAGE_SIZE) {
|
|
@@ -3355,12 +2119,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3355
2119
|
}
|
|
3356
2120
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3357
2121
|
if (this._streamDataFlushedCallback !== null) {
|
|
3358
|
-
|
|
3359
|
-
F: __dxlog_file13,
|
|
3360
|
-
L: 175,
|
|
3361
|
-
S: this,
|
|
3362
|
-
C: (f, a) => f(...a)
|
|
3363
|
-
});
|
|
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 });
|
|
3364
2123
|
}
|
|
3365
2124
|
this._streamDataFlushedCallback = callback;
|
|
3366
2125
|
} else {
|
|
@@ -3371,12 +2130,7 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3371
2130
|
try {
|
|
3372
2131
|
channel.close();
|
|
3373
2132
|
} catch (error) {
|
|
3374
|
-
|
|
3375
|
-
F: __dxlog_file13,
|
|
3376
|
-
L: 187,
|
|
3377
|
-
S: this,
|
|
3378
|
-
C: (f, a) => f(...a)
|
|
3379
|
-
});
|
|
2133
|
+
log9.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 156, S: this });
|
|
3380
2134
|
}
|
|
3381
2135
|
}
|
|
3382
2136
|
onSignal(signal) {
|
|
@@ -3417,13 +2171,13 @@ var deduplicatedSdpLines = (sdp) => {
|
|
|
3417
2171
|
};
|
|
3418
2172
|
|
|
3419
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";
|
|
3420
2175
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
3421
2176
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3422
2177
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3423
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;
|
|
3424
2179
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3425
2180
|
}
|
|
3426
|
-
var __dxlog_file14 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
|
|
3427
2181
|
var RtcPeerConnection = class {
|
|
3428
2182
|
_factory;
|
|
3429
2183
|
_options;
|
|
@@ -3471,12 +2225,7 @@ var RtcPeerConnection = class {
|
|
|
3471
2225
|
if (existingChannel) {
|
|
3472
2226
|
return existingChannel;
|
|
3473
2227
|
}
|
|
3474
|
-
|
|
3475
|
-
F: __dxlog_file14,
|
|
3476
|
-
L: 96,
|
|
3477
|
-
S: this,
|
|
3478
|
-
C: (f, a) => f(...a)
|
|
3479
|
-
});
|
|
2228
|
+
log10("waiting for initiator-peer to open a data channel", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 63, S: this });
|
|
3480
2229
|
return new Promise((resolve, reject) => {
|
|
3481
2230
|
this._channelCreatedCallbacks.set(topic, {
|
|
3482
2231
|
resolve,
|
|
@@ -3500,38 +2249,20 @@ var RtcPeerConnection = class {
|
|
|
3500
2249
|
if (this._connection) {
|
|
3501
2250
|
return this._connection;
|
|
3502
2251
|
}
|
|
3503
|
-
|
|
2252
|
+
log10("initializing connection...", () => ({
|
|
3504
2253
|
remotePeer: this._options.remotePeerKey
|
|
3505
|
-
}), {
|
|
3506
|
-
F: __dxlog_file14,
|
|
3507
|
-
L: 121,
|
|
3508
|
-
S: this,
|
|
3509
|
-
C: (f, a) => f(...a)
|
|
3510
|
-
});
|
|
2254
|
+
}), { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 87, S: this });
|
|
3511
2255
|
const config = await this._loadConnectionConfig();
|
|
3512
2256
|
const connection = await this._factory.createConnection(config);
|
|
3513
2257
|
const iceCandidateErrors = [];
|
|
3514
2258
|
Object.assign(connection, {
|
|
3515
2259
|
onnegotiationneeded: async () => {
|
|
3516
|
-
|
|
3517
|
-
F: __dxlog_file14,
|
|
3518
|
-
L: 136,
|
|
3519
|
-
S: this,
|
|
3520
|
-
A: [
|
|
3521
|
-
"this._initiator",
|
|
3522
|
-
""
|
|
3523
|
-
]
|
|
3524
|
-
});
|
|
2260
|
+
invariant10(this._initiator, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 100, S: this, A: ["this._initiator", ""] });
|
|
3525
2261
|
if (connection !== this._connection) {
|
|
3526
2262
|
this._onConnectionCallbackAfterClose("onnegotiationneeded", connection);
|
|
3527
2263
|
return;
|
|
3528
2264
|
}
|
|
3529
|
-
|
|
3530
|
-
F: __dxlog_file14,
|
|
3531
|
-
L: 143,
|
|
3532
|
-
S: this,
|
|
3533
|
-
C: (f, a) => f(...a)
|
|
3534
|
-
});
|
|
2265
|
+
log10("onnegotiationneeded", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 105, S: this });
|
|
3535
2266
|
try {
|
|
3536
2267
|
const offer = await connection.createOffer();
|
|
3537
2268
|
await connection.setLocalDescription(offer);
|
|
@@ -3548,22 +2279,12 @@ var RtcPeerConnection = class {
|
|
|
3548
2279
|
return;
|
|
3549
2280
|
}
|
|
3550
2281
|
if (event.candidate) {
|
|
3551
|
-
|
|
2282
|
+
log10("onicecandidate", {
|
|
3552
2283
|
candidate: event.candidate.candidate
|
|
3553
|
-
}, {
|
|
3554
|
-
F: __dxlog_file14,
|
|
3555
|
-
L: 162,
|
|
3556
|
-
S: this,
|
|
3557
|
-
C: (f, a) => f(...a)
|
|
3558
|
-
});
|
|
2284
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 122, S: this });
|
|
3559
2285
|
await this._sendIceCandidate(event.candidate);
|
|
3560
2286
|
} else {
|
|
3561
|
-
|
|
3562
|
-
F: __dxlog_file14,
|
|
3563
|
-
L: 165,
|
|
3564
|
-
S: this,
|
|
3565
|
-
C: (f, a) => f(...a)
|
|
3566
|
-
});
|
|
2287
|
+
log10("onicecandidate gathering complete", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 127, S: this });
|
|
3567
2288
|
}
|
|
3568
2289
|
},
|
|
3569
2290
|
// When error occurs while performing ICE negotiations through a STUN or TURN server.
|
|
@@ -3584,14 +2305,9 @@ var RtcPeerConnection = class {
|
|
|
3584
2305
|
this._onConnectionCallbackAfterClose("oniceconnectionstatechange", connection);
|
|
3585
2306
|
return;
|
|
3586
2307
|
}
|
|
3587
|
-
|
|
2308
|
+
log10("oniceconnectionstatechange", {
|
|
3588
2309
|
state: connection.iceConnectionState
|
|
3589
|
-
}, {
|
|
3590
|
-
F: __dxlog_file14,
|
|
3591
|
-
L: 185,
|
|
3592
|
-
S: this,
|
|
3593
|
-
C: (f, a) => f(...a)
|
|
3594
|
-
});
|
|
2310
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 148, S: this });
|
|
3595
2311
|
if (connection.iceConnectionState === "failed") {
|
|
3596
2312
|
void this._lockAndAbort(connection, createIceFailureError(iceCandidateErrors));
|
|
3597
2313
|
}
|
|
@@ -3606,52 +2322,29 @@ var RtcPeerConnection = class {
|
|
|
3606
2322
|
}
|
|
3607
2323
|
return;
|
|
3608
2324
|
}
|
|
3609
|
-
|
|
2325
|
+
log10("onconnectionstatechange", {
|
|
3610
2326
|
state: connection.connectionState
|
|
3611
|
-
}, {
|
|
3612
|
-
F: __dxlog_file14,
|
|
3613
|
-
L: 202,
|
|
3614
|
-
S: this,
|
|
3615
|
-
C: (f, a) => f(...a)
|
|
3616
|
-
});
|
|
2327
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 165, S: this });
|
|
3617
2328
|
if (connection.connectionState === "failed") {
|
|
3618
2329
|
void this._lockAndAbort(connection, new Error("Connection failed."));
|
|
3619
2330
|
}
|
|
3620
2331
|
},
|
|
3621
2332
|
onsignalingstatechange: () => {
|
|
3622
|
-
|
|
2333
|
+
log10("onsignalingstatechange", {
|
|
3623
2334
|
state: connection.signalingState
|
|
3624
|
-
}, {
|
|
3625
|
-
F: __dxlog_file14,
|
|
3626
|
-
L: 209,
|
|
3627
|
-
S: this,
|
|
3628
|
-
C: (f, a) => f(...a)
|
|
3629
|
-
});
|
|
2335
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 173, S: this });
|
|
3630
2336
|
},
|
|
3631
2337
|
// When channel is added to connection.
|
|
3632
2338
|
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event
|
|
3633
2339
|
ondatachannel: (event) => {
|
|
3634
|
-
|
|
3635
|
-
F: __dxlog_file14,
|
|
3636
|
-
L: 215,
|
|
3637
|
-
S: this,
|
|
3638
|
-
A: [
|
|
3639
|
-
"!this._initiator",
|
|
3640
|
-
"'Initiator is expected to create data channels.'"
|
|
3641
|
-
]
|
|
3642
|
-
});
|
|
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.'"] });
|
|
3643
2341
|
if (connection !== this._connection) {
|
|
3644
2342
|
this._onConnectionCallbackAfterClose("ondatachannel", connection);
|
|
3645
2343
|
return;
|
|
3646
2344
|
}
|
|
3647
|
-
|
|
2345
|
+
log10("ondatachannel", {
|
|
3648
2346
|
label: event.channel.label
|
|
3649
|
-
}, {
|
|
3650
|
-
F: __dxlog_file14,
|
|
3651
|
-
L: 222,
|
|
3652
|
-
S: this,
|
|
3653
|
-
C: (f, a) => f(...a)
|
|
3654
|
-
});
|
|
2347
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 185, S: this });
|
|
3655
2348
|
this._dataChannels.set(event.channel.label, event.channel);
|
|
3656
2349
|
const pendingCallback = this._channelCreatedCallbacks.get(event.channel.label);
|
|
3657
2350
|
if (pendingCallback) {
|
|
@@ -3672,14 +2365,9 @@ var RtcPeerConnection = class {
|
|
|
3672
2365
|
}
|
|
3673
2366
|
_abortConnection(connection, error) {
|
|
3674
2367
|
if (connection !== this._connection) {
|
|
3675
|
-
|
|
2368
|
+
log10.error("attempted to abort an inactive connection", {
|
|
3676
2369
|
error
|
|
3677
|
-
}, {
|
|
3678
|
-
F: __dxlog_file14,
|
|
3679
|
-
L: 247,
|
|
3680
|
-
S: this,
|
|
3681
|
-
C: (f, a) => f(...a)
|
|
3682
|
-
});
|
|
2370
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 208, S: this });
|
|
3683
2371
|
this._safeCloseConnection(connection);
|
|
3684
2372
|
return;
|
|
3685
2373
|
}
|
|
@@ -3693,46 +2381,23 @@ var RtcPeerConnection = class {
|
|
|
3693
2381
|
}
|
|
3694
2382
|
this._transportChannels.clear();
|
|
3695
2383
|
this._safeCloseConnection();
|
|
3696
|
-
|
|
2384
|
+
log10("connection aborted", {
|
|
3697
2385
|
reason: error.message
|
|
3698
|
-
}, {
|
|
3699
|
-
F: __dxlog_file14,
|
|
3700
|
-
L: 261,
|
|
3701
|
-
S: this,
|
|
3702
|
-
C: (f, a) => f(...a)
|
|
3703
|
-
});
|
|
2386
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 224, S: this });
|
|
3704
2387
|
}
|
|
3705
2388
|
async _lockAndCloseConnection() {
|
|
3706
|
-
|
|
3707
|
-
F: __dxlog_file14,
|
|
3708
|
-
L: 266,
|
|
3709
|
-
S: this,
|
|
3710
|
-
A: [
|
|
3711
|
-
"this._transportChannels.size === 0",
|
|
3712
|
-
""
|
|
3713
|
-
]
|
|
3714
|
-
});
|
|
2389
|
+
invariant10(this._transportChannels.size === 0, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 229, S: this, A: ["this._transportChannels.size === 0", ""] });
|
|
3715
2390
|
if (this._connection) {
|
|
3716
2391
|
this._safeCloseConnection();
|
|
3717
|
-
|
|
3718
|
-
F: __dxlog_file14,
|
|
3719
|
-
L: 269,
|
|
3720
|
-
S: this,
|
|
3721
|
-
C: (f, a) => f(...a)
|
|
3722
|
-
});
|
|
2392
|
+
log10("connection closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 232, S: this });
|
|
3723
2393
|
}
|
|
3724
2394
|
}
|
|
3725
2395
|
async onSignal(signal) {
|
|
3726
2396
|
const connection = this._connection;
|
|
3727
2397
|
if (!connection) {
|
|
3728
|
-
|
|
2398
|
+
log10.warn("a signal ignored because the connection was closed", {
|
|
3729
2399
|
type: signal.payload.data.type
|
|
3730
|
-
}, {
|
|
3731
|
-
F: __dxlog_file14,
|
|
3732
|
-
L: 277,
|
|
3733
|
-
S: this,
|
|
3734
|
-
C: (f, a) => f(...a)
|
|
3735
|
-
});
|
|
2400
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 238, S: this });
|
|
3736
2401
|
return;
|
|
3737
2402
|
}
|
|
3738
2403
|
const data = signal.payload.data;
|
|
@@ -3792,66 +2457,36 @@ var RtcPeerConnection = class {
|
|
|
3792
2457
|
this._abortConnection(connection, new Error(`Unknown signal type ${data.type}.`));
|
|
3793
2458
|
break;
|
|
3794
2459
|
}
|
|
3795
|
-
|
|
2460
|
+
log10("signal processed", {
|
|
3796
2461
|
type: data.type
|
|
3797
|
-
}, {
|
|
3798
|
-
F: __dxlog_file14,
|
|
3799
|
-
L: 336,
|
|
3800
|
-
S: this,
|
|
3801
|
-
C: (f, a) => f(...a)
|
|
3802
|
-
});
|
|
2462
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 301, S: this });
|
|
3803
2463
|
}
|
|
3804
2464
|
async _processIceCandidate(connection, candidate) {
|
|
3805
2465
|
try {
|
|
3806
2466
|
await this._readyForCandidates.wait();
|
|
3807
2467
|
if (connection === this._connection) {
|
|
3808
|
-
|
|
2468
|
+
log10("adding ice candidate", {
|
|
3809
2469
|
candidate
|
|
3810
|
-
}, {
|
|
3811
|
-
F: __dxlog_file14,
|
|
3812
|
-
L: 344,
|
|
3813
|
-
S: this,
|
|
3814
|
-
C: (f, a) => f(...a)
|
|
3815
|
-
});
|
|
2470
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 310, S: this });
|
|
3816
2471
|
await connection.addIceCandidate(candidate);
|
|
3817
2472
|
}
|
|
3818
2473
|
} catch (err) {
|
|
3819
|
-
|
|
3820
|
-
F: __dxlog_file14,
|
|
3821
|
-
L: 348,
|
|
3822
|
-
S: this,
|
|
3823
|
-
C: (f, a) => f(...a)
|
|
3824
|
-
});
|
|
2474
|
+
log10.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 316, S: this });
|
|
3825
2475
|
}
|
|
3826
2476
|
}
|
|
3827
2477
|
_onSessionNegotiated(connection) {
|
|
3828
2478
|
if (connection === this._connection) {
|
|
3829
|
-
|
|
3830
|
-
F: __dxlog_file14,
|
|
3831
|
-
L: 354,
|
|
3832
|
-
S: this,
|
|
3833
|
-
C: (f, a) => f(...a)
|
|
3834
|
-
});
|
|
2479
|
+
log10("ready to process ice candidates", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 321, S: this });
|
|
3835
2480
|
this._readyForCandidates.wake();
|
|
3836
2481
|
} else {
|
|
3837
|
-
|
|
3838
|
-
F: __dxlog_file14,
|
|
3839
|
-
L: 357,
|
|
3840
|
-
S: this,
|
|
3841
|
-
C: (f, a) => f(...a)
|
|
3842
|
-
});
|
|
2482
|
+
log10.warn("session was negotiated after connection became inactive", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 324, S: this });
|
|
3843
2483
|
}
|
|
3844
2484
|
}
|
|
3845
2485
|
_onConnectionCallbackAfterClose(callback, connection) {
|
|
3846
|
-
|
|
2486
|
+
log10.warn("callback invoked after a connection was destroyed, this is probably a bug", {
|
|
3847
2487
|
callback,
|
|
3848
2488
|
state: connection.connectionState
|
|
3849
|
-
}, {
|
|
3850
|
-
F: __dxlog_file14,
|
|
3851
|
-
L: 362,
|
|
3852
|
-
S: this,
|
|
3853
|
-
C: (f, a) => f(...a)
|
|
3854
|
-
});
|
|
2489
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 328, S: this });
|
|
3855
2490
|
this._safeCloseConnection(connection);
|
|
3856
2491
|
}
|
|
3857
2492
|
_safeCloseConnection(connection = this._connection) {
|
|
@@ -3859,23 +2494,13 @@ var RtcPeerConnection = class {
|
|
|
3859
2494
|
try {
|
|
3860
2495
|
connection?.close();
|
|
3861
2496
|
} catch (err) {
|
|
3862
|
-
|
|
3863
|
-
F: __dxlog_file14,
|
|
3864
|
-
L: 374,
|
|
3865
|
-
S: this,
|
|
3866
|
-
C: (f, a) => f(...a)
|
|
3867
|
-
});
|
|
2497
|
+
log10.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 339, S: this });
|
|
3868
2498
|
}
|
|
3869
2499
|
if (resetFields) {
|
|
3870
2500
|
this._connection = void 0;
|
|
3871
2501
|
this._dataChannels.clear();
|
|
3872
2502
|
this._readyForCandidates.wake();
|
|
3873
|
-
void this._factory.onConnectionDestroyed().catch((err) =>
|
|
3874
|
-
F: __dxlog_file14,
|
|
3875
|
-
L: 380,
|
|
3876
|
-
S: this,
|
|
3877
|
-
C: (f, a) => f(...a)
|
|
3878
|
-
}));
|
|
2503
|
+
void this._factory.onConnectionDestroyed().catch((err) => log10.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 345, S: this }));
|
|
3879
2504
|
for (const [_, pendingCallback] of this._channelCreatedCallbacks.entries()) {
|
|
3880
2505
|
pendingCallback.reject("Connection closed.");
|
|
3881
2506
|
}
|
|
@@ -3895,12 +2520,7 @@ var RtcPeerConnection = class {
|
|
|
3895
2520
|
];
|
|
3896
2521
|
}
|
|
3897
2522
|
} catch (error) {
|
|
3898
|
-
|
|
3899
|
-
F: __dxlog_file14,
|
|
3900
|
-
L: 396,
|
|
3901
|
-
S: this,
|
|
3902
|
-
C: (f, a) => f(...a)
|
|
3903
|
-
});
|
|
2523
|
+
log10.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 365, S: this });
|
|
3904
2524
|
}
|
|
3905
2525
|
return config;
|
|
3906
2526
|
}
|
|
@@ -3920,14 +2540,9 @@ var RtcPeerConnection = class {
|
|
|
3920
2540
|
}
|
|
3921
2541
|
});
|
|
3922
2542
|
} catch (err) {
|
|
3923
|
-
|
|
2543
|
+
log10.warn("signaling error", {
|
|
3924
2544
|
err
|
|
3925
|
-
}, {
|
|
3926
|
-
F: __dxlog_file14,
|
|
3927
|
-
L: 417,
|
|
3928
|
-
S: this,
|
|
3929
|
-
C: (f, a) => f(...a)
|
|
3930
|
-
});
|
|
2545
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 385, S: this });
|
|
3931
2546
|
}
|
|
3932
2547
|
}
|
|
3933
2548
|
async _sendDescription(connection, description) {
|
|
@@ -3985,13 +2600,13 @@ _ts_decorate6([
|
|
|
3985
2600
|
synchronized5
|
|
3986
2601
|
], RtcPeerConnection.prototype, "onSignal", null);
|
|
3987
2602
|
_ts_decorate6([
|
|
3988
|
-
|
|
2603
|
+
trace.info()
|
|
3989
2604
|
], RtcPeerConnection.prototype, "_connectionInfo", null);
|
|
3990
2605
|
_ts_decorate6([
|
|
3991
2606
|
logInfo4
|
|
3992
2607
|
], RtcPeerConnection.prototype, "_loggerContext", null);
|
|
3993
2608
|
RtcPeerConnection = _ts_decorate6([
|
|
3994
|
-
|
|
2609
|
+
trace.resource()
|
|
3995
2610
|
], RtcPeerConnection);
|
|
3996
2611
|
var isRemoteDescriptionSet = (connection, data) => {
|
|
3997
2612
|
if (!connection.remoteDescription?.type || connection.remoteDescription?.type !== data.type) {
|
|
@@ -4001,8 +2616,10 @@ var isRemoteDescriptionSet = (connection, data) => {
|
|
|
4001
2616
|
};
|
|
4002
2617
|
var createIceFailureError = (details) => {
|
|
4003
2618
|
const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
|
|
4004
|
-
return new ConnectivityError3(
|
|
4005
|
-
|
|
2619
|
+
return new ConnectivityError3({
|
|
2620
|
+
message: `ICE failed:
|
|
2621
|
+
${candidateErrors.join("\n")}`
|
|
2622
|
+
});
|
|
4006
2623
|
};
|
|
4007
2624
|
|
|
4008
2625
|
// src/transport/webrtc/rtc-transport-factory.ts
|
|
@@ -4028,19 +2645,19 @@ import { Writable } from "node:stream";
|
|
|
4028
2645
|
import { Event as Event8, scheduleTask as scheduleTask4 } from "@dxos/async";
|
|
4029
2646
|
import { Resource as Resource2 } from "@dxos/context";
|
|
4030
2647
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
4031
|
-
import { invariant as
|
|
4032
|
-
import { PublicKey as
|
|
4033
|
-
import { log as
|
|
2648
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
2649
|
+
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
2650
|
+
import { log as log11 } from "@dxos/log";
|
|
4034
2651
|
import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError4, TimeoutError as TimeoutError3 } from "@dxos/protocols";
|
|
4035
2652
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
4036
2653
|
import { arrayToBuffer } from "@dxos/util";
|
|
4037
|
-
var
|
|
2654
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
|
|
4038
2655
|
var RPC_TIMEOUT = 1e4;
|
|
4039
2656
|
var CLOSE_RPC_TIMEOUT = 3e3;
|
|
4040
2657
|
var RESP_MIN_THRESHOLD = 500;
|
|
4041
2658
|
var RtcTransportProxy = class extends Resource2 {
|
|
4042
2659
|
_options;
|
|
4043
|
-
_proxyId =
|
|
2660
|
+
_proxyId = PublicKey9.random();
|
|
4044
2661
|
closed = new Event8();
|
|
4045
2662
|
connected = new Event8();
|
|
4046
2663
|
errors = new ErrorStream5();
|
|
@@ -4067,12 +2684,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4067
2684
|
this._serviceStream = stream;
|
|
4068
2685
|
stream.waitUntilReady().then(() => {
|
|
4069
2686
|
stream.subscribe(async (event) => {
|
|
4070
|
-
|
|
4071
|
-
F: __dxlog_file15,
|
|
4072
|
-
L: 66,
|
|
4073
|
-
S: this,
|
|
4074
|
-
C: (f, a) => f(...a)
|
|
4075
|
-
});
|
|
2687
|
+
log11("rtc transport proxy event", event, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 46, S: this });
|
|
4076
2688
|
if (event.connection) {
|
|
4077
2689
|
await this._handleConnection(event.connection);
|
|
4078
2690
|
} else if (event.data) {
|
|
@@ -4081,14 +2693,9 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4081
2693
|
await this._handleSignal(event.signal);
|
|
4082
2694
|
}
|
|
4083
2695
|
}, (err) => {
|
|
4084
|
-
|
|
2696
|
+
log11("rtc bridge stream closed", {
|
|
4085
2697
|
err
|
|
4086
|
-
}, {
|
|
4087
|
-
F: __dxlog_file15,
|
|
4088
|
-
L: 76,
|
|
4089
|
-
S: this,
|
|
4090
|
-
C: (f, a) => f(...a)
|
|
4091
|
-
});
|
|
2698
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 55, S: this });
|
|
4092
2699
|
if (err) {
|
|
4093
2700
|
this._raiseIfOpen(err);
|
|
4094
2701
|
} else {
|
|
@@ -4105,12 +2712,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4105
2712
|
timeout: RPC_TIMEOUT
|
|
4106
2713
|
}).then(() => {
|
|
4107
2714
|
if (Date.now() - sendStartMs > RESP_MIN_THRESHOLD) {
|
|
4108
|
-
|
|
4109
|
-
F: __dxlog_file15,
|
|
4110
|
-
L: 93,
|
|
4111
|
-
S: this,
|
|
4112
|
-
C: (f, a) => f(...a)
|
|
4113
|
-
});
|
|
2715
|
+
log11("slow response, delaying callback", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 74, S: this });
|
|
4114
2716
|
scheduleTask4(this._ctx, () => callback(), RESP_MIN_THRESHOLD);
|
|
4115
2717
|
} else {
|
|
4116
2718
|
callback();
|
|
@@ -4138,12 +2740,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4138
2740
|
await this._serviceStream?.close();
|
|
4139
2741
|
this._serviceStream = void 0;
|
|
4140
2742
|
} catch (err) {
|
|
4141
|
-
|
|
4142
|
-
F: __dxlog_file15,
|
|
4143
|
-
L: 128,
|
|
4144
|
-
S: this,
|
|
4145
|
-
C: (f, a) => f(...a)
|
|
4146
|
-
});
|
|
2743
|
+
log11.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 102, S: this });
|
|
4147
2744
|
}
|
|
4148
2745
|
try {
|
|
4149
2746
|
await this._options.bridgeService.close({
|
|
@@ -4152,12 +2749,7 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4152
2749
|
timeout: CLOSE_RPC_TIMEOUT
|
|
4153
2750
|
});
|
|
4154
2751
|
} catch (err) {
|
|
4155
|
-
|
|
4156
|
-
F: __dxlog_file15,
|
|
4157
|
-
L: 134,
|
|
4158
|
-
S: this,
|
|
4159
|
-
C: (f, a) => f(...a)
|
|
4160
|
-
});
|
|
2752
|
+
log11.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 111, S: this });
|
|
4161
2753
|
}
|
|
4162
2754
|
this.closed.emit();
|
|
4163
2755
|
}
|
|
@@ -4198,7 +2790,9 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4198
2790
|
} catch (error) {
|
|
4199
2791
|
const type = signalEvent.payload.payload.data?.type;
|
|
4200
2792
|
if (type === "offer" || type === "answer") {
|
|
4201
|
-
this._raiseIfOpen(new ConnectivityError4(
|
|
2793
|
+
this._raiseIfOpen(new ConnectivityError4({
|
|
2794
|
+
message: `Session establishment failed: ${type} couldn't be sent.`
|
|
2795
|
+
}));
|
|
4202
2796
|
}
|
|
4203
2797
|
}
|
|
4204
2798
|
}
|
|
@@ -4236,14 +2830,9 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4236
2830
|
if (this.isOpen) {
|
|
4237
2831
|
this.errors.raise(error);
|
|
4238
2832
|
} else {
|
|
4239
|
-
|
|
2833
|
+
log11.info("error swallowed because transport was closed", {
|
|
4240
2834
|
message: error.message
|
|
4241
|
-
}, {
|
|
4242
|
-
F: __dxlog_file15,
|
|
4243
|
-
L: 215,
|
|
4244
|
-
S: this,
|
|
4245
|
-
C: (f, a) => f(...a)
|
|
4246
|
-
});
|
|
2835
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 195, S: this });
|
|
4247
2836
|
}
|
|
4248
2837
|
}
|
|
4249
2838
|
/**
|
|
@@ -4269,15 +2858,7 @@ var RtcTransportProxyFactory = class {
|
|
|
4269
2858
|
return this;
|
|
4270
2859
|
}
|
|
4271
2860
|
createTransport(options) {
|
|
4272
|
-
|
|
4273
|
-
F: __dxlog_file15,
|
|
4274
|
-
L: 245,
|
|
4275
|
-
S: this,
|
|
4276
|
-
A: [
|
|
4277
|
-
"this._bridgeService",
|
|
4278
|
-
"'RtcTransportProxyFactory is not ready to open connections'"
|
|
4279
|
-
]
|
|
4280
|
-
});
|
|
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'"] });
|
|
4281
2862
|
const transport = new RtcTransportProxy({
|
|
4282
2863
|
...options,
|
|
4283
2864
|
bridgeService: this._bridgeService
|
|
@@ -4292,11 +2873,17 @@ var RtcTransportProxyFactory = class {
|
|
|
4292
2873
|
var decodeError = (err) => {
|
|
4293
2874
|
const message = typeof err === "string" ? err : err.message;
|
|
4294
2875
|
if (message.includes("CONNECTION_RESET")) {
|
|
4295
|
-
return new ConnectionResetError2(
|
|
2876
|
+
return new ConnectionResetError2({
|
|
2877
|
+
message
|
|
2878
|
+
});
|
|
4296
2879
|
} else if (message.includes("TIMEOUT")) {
|
|
4297
|
-
return new TimeoutError3(
|
|
2880
|
+
return new TimeoutError3({
|
|
2881
|
+
message
|
|
2882
|
+
});
|
|
4298
2883
|
} else if (message.includes("CONNECTIVITY_ERROR")) {
|
|
4299
|
-
return new ConnectivityError4(
|
|
2884
|
+
return new ConnectivityError4({
|
|
2885
|
+
message
|
|
2886
|
+
});
|
|
4300
2887
|
} else {
|
|
4301
2888
|
return typeof err === "string" ? new Error(err) : err;
|
|
4302
2889
|
}
|
|
@@ -4305,15 +2892,15 @@ var decodeError = (err) => {
|
|
|
4305
2892
|
// src/transport/webrtc/rtc-transport-service.ts
|
|
4306
2893
|
import { Duplex as Duplex2 } from "node:stream";
|
|
4307
2894
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
4308
|
-
import { invariant as
|
|
4309
|
-
import { PublicKey as
|
|
4310
|
-
import { log as
|
|
2895
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
2896
|
+
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
2897
|
+
import { log as log12 } from "@dxos/log";
|
|
4311
2898
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
4312
2899
|
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
4313
|
-
var
|
|
2900
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
|
|
4314
2901
|
var RtcTransportService = class {
|
|
4315
2902
|
_transportFactory;
|
|
4316
|
-
_openTransports = new ComplexMap8(
|
|
2903
|
+
_openTransports = new ComplexMap8(PublicKey10.hash);
|
|
4317
2904
|
constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
|
|
4318
2905
|
this._transportFactory = _transportFactory;
|
|
4319
2906
|
}
|
|
@@ -4323,12 +2910,7 @@ var RtcTransportService = class {
|
|
|
4323
2910
|
open(request) {
|
|
4324
2911
|
const existingTransport = this._openTransports.get(request.proxyId);
|
|
4325
2912
|
if (existingTransport) {
|
|
4326
|
-
|
|
4327
|
-
F: __dxlog_file16,
|
|
4328
|
-
L: 54,
|
|
4329
|
-
S: this,
|
|
4330
|
-
C: (f, a) => f(...a)
|
|
4331
|
-
});
|
|
2913
|
+
log12.error("requesting a new transport bridge for an existing proxy", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 24, S: this });
|
|
4332
2914
|
void this._safeCloseTransport(existingTransport);
|
|
4333
2915
|
this._openTransports.delete(request.proxyId);
|
|
4334
2916
|
}
|
|
@@ -4389,69 +2971,32 @@ var RtcTransportService = class {
|
|
|
4389
2971
|
close(err);
|
|
4390
2972
|
});
|
|
4391
2973
|
ready();
|
|
4392
|
-
|
|
4393
|
-
F: __dxlog_file16,
|
|
4394
|
-
L: 116,
|
|
4395
|
-
S: this,
|
|
4396
|
-
C: (f, a) => f(...a)
|
|
4397
|
-
});
|
|
2974
|
+
log12("stream ready", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 85, S: this });
|
|
4398
2975
|
pushNewState(ConnectionState4.CONNECTING);
|
|
4399
2976
|
});
|
|
4400
2977
|
}
|
|
4401
2978
|
async sendSignal({ proxyId, signal }) {
|
|
4402
2979
|
const transport = this._openTransports.get(proxyId);
|
|
4403
|
-
|
|
4404
|
-
F: __dxlog_file16,
|
|
4405
|
-
L: 124,
|
|
4406
|
-
S: this,
|
|
4407
|
-
A: [
|
|
4408
|
-
"transport",
|
|
4409
|
-
""
|
|
4410
|
-
]
|
|
4411
|
-
});
|
|
2980
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 91, S: this, A: ["transport", ""] });
|
|
4412
2981
|
await transport.transport.onSignal(signal);
|
|
4413
2982
|
}
|
|
4414
2983
|
async getDetails({ proxyId }) {
|
|
4415
2984
|
const transport = this._openTransports.get(proxyId);
|
|
4416
|
-
|
|
4417
|
-
F: __dxlog_file16,
|
|
4418
|
-
L: 131,
|
|
4419
|
-
S: this,
|
|
4420
|
-
A: [
|
|
4421
|
-
"transport",
|
|
4422
|
-
""
|
|
4423
|
-
]
|
|
4424
|
-
});
|
|
2985
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 96, S: this, A: ["transport", ""] });
|
|
4425
2986
|
return {
|
|
4426
2987
|
details: await transport.transport.getDetails()
|
|
4427
2988
|
};
|
|
4428
2989
|
}
|
|
4429
2990
|
async getStats({ proxyId }) {
|
|
4430
2991
|
const transport = this._openTransports.get(proxyId);
|
|
4431
|
-
|
|
4432
|
-
F: __dxlog_file16,
|
|
4433
|
-
L: 138,
|
|
4434
|
-
S: this,
|
|
4435
|
-
A: [
|
|
4436
|
-
"transport",
|
|
4437
|
-
""
|
|
4438
|
-
]
|
|
4439
|
-
});
|
|
2992
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 103, S: this, A: ["transport", ""] });
|
|
4440
2993
|
return {
|
|
4441
2994
|
stats: await transport.transport.getStats()
|
|
4442
2995
|
};
|
|
4443
2996
|
}
|
|
4444
2997
|
async sendData({ proxyId, payload }) {
|
|
4445
2998
|
const transport = this._openTransports.get(proxyId);
|
|
4446
|
-
|
|
4447
|
-
F: __dxlog_file16,
|
|
4448
|
-
L: 145,
|
|
4449
|
-
S: this,
|
|
4450
|
-
A: [
|
|
4451
|
-
"transport",
|
|
4452
|
-
""
|
|
4453
|
-
]
|
|
4454
|
-
});
|
|
2999
|
+
invariant12(transport, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 110, S: this, A: ["transport", ""] });
|
|
4455
3000
|
const bufferHasSpace = transport.connectorStream.push(payload);
|
|
4456
3001
|
if (!bufferHasSpace) {
|
|
4457
3002
|
await new Promise((resolve) => {
|
|
@@ -4475,33 +3020,18 @@ var RtcTransportService = class {
|
|
|
4475
3020
|
try {
|
|
4476
3021
|
await transport.transport.close();
|
|
4477
3022
|
} catch (error) {
|
|
4478
|
-
|
|
3023
|
+
log12.warn("transport close error", {
|
|
4479
3024
|
message: error?.message
|
|
4480
|
-
}, {
|
|
4481
|
-
F: __dxlog_file16,
|
|
4482
|
-
L: 175,
|
|
4483
|
-
S: this,
|
|
4484
|
-
C: (f, a) => f(...a)
|
|
4485
|
-
});
|
|
3025
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 134, S: this });
|
|
4486
3026
|
}
|
|
4487
3027
|
try {
|
|
4488
3028
|
transport.connectorStream.end();
|
|
4489
3029
|
} catch (error) {
|
|
4490
|
-
|
|
3030
|
+
log12.warn("connectorStream close error", {
|
|
4491
3031
|
message: error?.message
|
|
4492
|
-
}, {
|
|
4493
|
-
F: __dxlog_file16,
|
|
4494
|
-
L: 180,
|
|
4495
|
-
S: this,
|
|
4496
|
-
C: (f, a) => f(...a)
|
|
4497
|
-
});
|
|
3032
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 141, S: this });
|
|
4498
3033
|
}
|
|
4499
|
-
|
|
4500
|
-
F: __dxlog_file16,
|
|
4501
|
-
L: 182,
|
|
4502
|
-
S: this,
|
|
4503
|
-
C: (f, a) => f(...a)
|
|
4504
|
-
});
|
|
3034
|
+
log12("closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 145, S: this });
|
|
4505
3035
|
}
|
|
4506
3036
|
};
|
|
4507
3037
|
var createStateUpdater = (next) => {
|
|
@@ -4519,10 +3049,10 @@ var createStateUpdater = (next) => {
|
|
|
4519
3049
|
|
|
4520
3050
|
// src/wire-protocol.ts
|
|
4521
3051
|
import { Teleport } from "@dxos/teleport";
|
|
4522
|
-
var createTeleportProtocolFactory = (onConnection,
|
|
3052
|
+
var createTeleportProtocolFactory = (onConnection, defaultProps) => {
|
|
4523
3053
|
return (params) => {
|
|
4524
3054
|
const teleport = new Teleport({
|
|
4525
|
-
...
|
|
3055
|
+
...defaultProps,
|
|
4526
3056
|
...params
|
|
4527
3057
|
});
|
|
4528
3058
|
return {
|
|
@@ -4544,7 +3074,6 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
|
|
|
4544
3074
|
export {
|
|
4545
3075
|
ConnectionState,
|
|
4546
3076
|
Connection,
|
|
4547
|
-
createIceProvider,
|
|
4548
3077
|
SwarmMessenger,
|
|
4549
3078
|
Swarm,
|
|
4550
3079
|
SwarmMapper,
|
|
@@ -4554,8 +3083,6 @@ export {
|
|
|
4554
3083
|
ConnectionLog,
|
|
4555
3084
|
SwarmNetworkManager,
|
|
4556
3085
|
FullyConnectedTopology,
|
|
4557
|
-
MMSTTopology,
|
|
4558
|
-
StarTopology,
|
|
4559
3086
|
MemoryTransportFactory,
|
|
4560
3087
|
MemoryTransport,
|
|
4561
3088
|
TransportKind,
|
|
@@ -4565,4 +3092,4 @@ export {
|
|
|
4565
3092
|
RtcTransportService,
|
|
4566
3093
|
createTeleportProtocolFactory
|
|
4567
3094
|
};
|
|
4568
|
-
//# sourceMappingURL=chunk-
|
|
3095
|
+
//# sourceMappingURL=chunk-KYLPLEZQ.mjs.map
|