@dxos/edge-client 0.8.2-main.5885341 → 0.8.2-main.85fa0e5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-TKYUZ5ZK.mjs → chunk-CFIVYHE6.mjs} +277 -28
- package/dist/lib/browser/chunk-CFIVYHE6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +62 -312
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -3
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/chunk-FQM4JFRT.cjs +586 -0
- package/dist/lib/node/chunk-FQM4JFRT.cjs.map +7 -0
- package/dist/lib/node/index.cjs +60 -319
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +5 -6
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-25HGRGNZ.mjs → chunk-APWFVC3U.mjs} +277 -28
- package/dist/lib/node-esm/chunk-APWFVC3U.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +62 -312
- 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 +3 -3
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/edge-ws-connection.d.ts +5 -0
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts +1 -4
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/package.json +14 -19
- package/src/edge-ws-connection.ts +9 -4
- package/src/edge-ws-muxer.ts +6 -21
- package/src/index.ts +1 -0
- package/src/testing/test-utils.ts +2 -2
- package/dist/lib/browser/chunk-TKYUZ5ZK.mjs.map +0 -7
- package/dist/lib/browser/edge-ws-muxer.mjs +0 -11
- package/dist/lib/browser/edge-ws-muxer.mjs.map +0 -7
- package/dist/lib/node/chunk-ZOL3YSDR.cjs +0 -322
- package/dist/lib/node/chunk-ZOL3YSDR.cjs.map +0 -7
- package/dist/lib/node/edge-ws-muxer.cjs +0 -33
- package/dist/lib/node/edge-ws-muxer.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-25HGRGNZ.mjs.map +0 -7
- package/dist/lib/node-esm/edge-ws-muxer.mjs +0 -12
- package/dist/lib/node-esm/edge-ws-muxer.mjs.map +0 -7
- package/dist/types/src/edge-ws-muxer.test.d.ts +0 -2
- package/dist/types/src/edge-ws-muxer.test.d.ts.map +0 -1
- package/src/edge-ws-muxer.test.ts +0 -55
|
@@ -2,20 +2,23 @@ import { createRequire } from 'node:module';const require = createRequire(import
|
|
|
2
2
|
import {
|
|
3
3
|
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
4
4
|
CLOUDFLARE_RPC_MAX_BYTES,
|
|
5
|
+
EDGE_WEBSOCKET_PROTOCOL_V0,
|
|
6
|
+
EDGE_WEBSOCKET_PROTOCOL_V1,
|
|
7
|
+
EdgeWsConnection,
|
|
5
8
|
Protocol,
|
|
6
9
|
WebSocketMuxer,
|
|
7
10
|
getTypename,
|
|
8
11
|
protocol,
|
|
9
12
|
toUint8Array
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-APWFVC3U.mjs";
|
|
11
14
|
|
|
12
15
|
// packages/core/mesh/edge-client/src/index.ts
|
|
13
16
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
14
17
|
|
|
15
18
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
16
19
|
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle, Event } from "@dxos/async";
|
|
17
|
-
import { Resource
|
|
18
|
-
import { log
|
|
20
|
+
import { Resource } from "@dxos/context";
|
|
21
|
+
import { log, logInfo } from "@dxos/log";
|
|
19
22
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
20
23
|
|
|
21
24
|
// packages/core/mesh/edge-client/src/edge-identity.ts
|
|
@@ -58,261 +61,6 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
58
61
|
return schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
|
|
59
62
|
};
|
|
60
63
|
|
|
61
|
-
// packages/core/mesh/edge-client/src/edge-ws-connection.ts
|
|
62
|
-
import WebSocket from "isomorphic-ws";
|
|
63
|
-
import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
64
|
-
import { Context, Resource } from "@dxos/context";
|
|
65
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
66
|
-
import { log, logInfo } from "@dxos/log";
|
|
67
|
-
import { EdgeWebsocketProtocol } from "@dxos/protocols";
|
|
68
|
-
import { buf } from "@dxos/protocols/buf";
|
|
69
|
-
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
70
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
71
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
72
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
73
|
-
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;
|
|
74
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
75
|
-
}
|
|
76
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
77
|
-
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
78
|
-
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
79
|
-
var EdgeWsConnection = class extends Resource {
|
|
80
|
-
constructor(_identity, _connectionInfo, _callbacks) {
|
|
81
|
-
super();
|
|
82
|
-
this._identity = _identity;
|
|
83
|
-
this._connectionInfo = _connectionInfo;
|
|
84
|
-
this._callbacks = _callbacks;
|
|
85
|
-
}
|
|
86
|
-
get info() {
|
|
87
|
-
return {
|
|
88
|
-
open: this.isOpen,
|
|
89
|
-
identity: this._identity.identityKey,
|
|
90
|
-
device: this._identity.peerKey
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
send(message) {
|
|
94
|
-
invariant2(this._ws, void 0, {
|
|
95
|
-
F: __dxlog_file2,
|
|
96
|
-
L: 52,
|
|
97
|
-
S: this,
|
|
98
|
-
A: [
|
|
99
|
-
"this._ws",
|
|
100
|
-
""
|
|
101
|
-
]
|
|
102
|
-
});
|
|
103
|
-
invariant2(this._wsMuxer, void 0, {
|
|
104
|
-
F: __dxlog_file2,
|
|
105
|
-
L: 53,
|
|
106
|
-
S: this,
|
|
107
|
-
A: [
|
|
108
|
-
"this._wsMuxer",
|
|
109
|
-
""
|
|
110
|
-
]
|
|
111
|
-
});
|
|
112
|
-
log("sending...", {
|
|
113
|
-
peerKey: this._identity.peerKey,
|
|
114
|
-
payload: protocol.getPayloadType(message)
|
|
115
|
-
}, {
|
|
116
|
-
F: __dxlog_file2,
|
|
117
|
-
L: 54,
|
|
118
|
-
S: this,
|
|
119
|
-
C: (f, a) => f(...a)
|
|
120
|
-
});
|
|
121
|
-
if (this._ws?.protocol.includes(EdgeWebsocketProtocol.V0)) {
|
|
122
|
-
const binary = buf.toBinary(MessageSchema, message);
|
|
123
|
-
if (binary.length > CLOUDFLARE_MESSAGE_MAX_BYTES) {
|
|
124
|
-
log.error("Message dropped because it was too large (>1MB).", {
|
|
125
|
-
byteLength: binary.byteLength,
|
|
126
|
-
serviceId: message.serviceId,
|
|
127
|
-
payload: protocol.getPayloadType(message)
|
|
128
|
-
}, {
|
|
129
|
-
F: __dxlog_file2,
|
|
130
|
-
L: 58,
|
|
131
|
-
S: this,
|
|
132
|
-
C: (f, a) => f(...a)
|
|
133
|
-
});
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
this._ws.send(binary);
|
|
137
|
-
} else {
|
|
138
|
-
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
|
|
139
|
-
F: __dxlog_file2,
|
|
140
|
-
L: 67,
|
|
141
|
-
S: this,
|
|
142
|
-
C: (f, a) => f(...a)
|
|
143
|
-
}));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
async _open() {
|
|
147
|
-
const baseProtocols = [
|
|
148
|
-
...Object.values(EdgeWebsocketProtocol)
|
|
149
|
-
];
|
|
150
|
-
this._ws = new WebSocket(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
|
|
151
|
-
...baseProtocols,
|
|
152
|
-
this._connectionInfo.protocolHeader
|
|
153
|
-
] : [
|
|
154
|
-
...baseProtocols
|
|
155
|
-
]);
|
|
156
|
-
const muxer = new WebSocketMuxer(this._ws);
|
|
157
|
-
this._wsMuxer = muxer;
|
|
158
|
-
this._ws.onopen = () => {
|
|
159
|
-
if (this.isOpen) {
|
|
160
|
-
log("connected", void 0, {
|
|
161
|
-
F: __dxlog_file2,
|
|
162
|
-
L: 84,
|
|
163
|
-
S: this,
|
|
164
|
-
C: (f, a) => f(...a)
|
|
165
|
-
});
|
|
166
|
-
this._callbacks.onConnected();
|
|
167
|
-
this._scheduleHeartbeats();
|
|
168
|
-
} else {
|
|
169
|
-
log.verbose("connected after becoming inactive", {
|
|
170
|
-
currentIdentity: this._identity
|
|
171
|
-
}, {
|
|
172
|
-
F: __dxlog_file2,
|
|
173
|
-
L: 88,
|
|
174
|
-
S: this,
|
|
175
|
-
C: (f, a) => f(...a)
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
this._ws.onclose = (event) => {
|
|
180
|
-
if (this.isOpen) {
|
|
181
|
-
log.warn("disconnected while being open", {
|
|
182
|
-
code: event.code,
|
|
183
|
-
reason: event.reason
|
|
184
|
-
}, {
|
|
185
|
-
F: __dxlog_file2,
|
|
186
|
-
L: 93,
|
|
187
|
-
S: this,
|
|
188
|
-
C: (f, a) => f(...a)
|
|
189
|
-
});
|
|
190
|
-
this._callbacks.onRestartRequired();
|
|
191
|
-
muxer.destroy();
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
this._ws.onerror = (event) => {
|
|
195
|
-
if (this.isOpen) {
|
|
196
|
-
log.warn("edge connection socket error", {
|
|
197
|
-
error: event.error,
|
|
198
|
-
info: event.message
|
|
199
|
-
}, {
|
|
200
|
-
F: __dxlog_file2,
|
|
201
|
-
L: 100,
|
|
202
|
-
S: this,
|
|
203
|
-
C: (f, a) => f(...a)
|
|
204
|
-
});
|
|
205
|
-
this._callbacks.onRestartRequired();
|
|
206
|
-
} else {
|
|
207
|
-
log.verbose("error ignored on closed connection", {
|
|
208
|
-
error: event.error
|
|
209
|
-
}, {
|
|
210
|
-
F: __dxlog_file2,
|
|
211
|
-
L: 103,
|
|
212
|
-
S: this,
|
|
213
|
-
C: (f, a) => f(...a)
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
this._ws.onmessage = async (event) => {
|
|
218
|
-
if (!this.isOpen) {
|
|
219
|
-
log.verbose("message ignored on closed connection", {
|
|
220
|
-
event: event.type
|
|
221
|
-
}, {
|
|
222
|
-
F: __dxlog_file2,
|
|
223
|
-
L: 111,
|
|
224
|
-
S: this,
|
|
225
|
-
C: (f, a) => f(...a)
|
|
226
|
-
});
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
if (event.data === "__pong__") {
|
|
230
|
-
this._rescheduleHeartbeatTimeout();
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
const bytes = await toUint8Array(event.data);
|
|
234
|
-
if (!this.isOpen) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
const message = this._ws?.protocol?.includes(EdgeWebsocketProtocol.V0) ? buf.fromBinary(MessageSchema, bytes) : muxer.receiveData(bytes);
|
|
238
|
-
if (message) {
|
|
239
|
-
log("received", {
|
|
240
|
-
from: message.source,
|
|
241
|
-
payload: protocol.getPayloadType(message)
|
|
242
|
-
}, {
|
|
243
|
-
F: __dxlog_file2,
|
|
244
|
-
L: 128,
|
|
245
|
-
S: this,
|
|
246
|
-
C: (f, a) => f(...a)
|
|
247
|
-
});
|
|
248
|
-
this._callbacks.onMessage(message);
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
async _close() {
|
|
253
|
-
void this._inactivityTimeoutCtx?.dispose().catch(() => {
|
|
254
|
-
});
|
|
255
|
-
try {
|
|
256
|
-
this._ws?.close();
|
|
257
|
-
this._ws = void 0;
|
|
258
|
-
this._wsMuxer?.destroy();
|
|
259
|
-
this._wsMuxer = void 0;
|
|
260
|
-
} catch (err) {
|
|
261
|
-
if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
log.warn("Error closing websocket", {
|
|
265
|
-
err
|
|
266
|
-
}, {
|
|
267
|
-
F: __dxlog_file2,
|
|
268
|
-
L: 146,
|
|
269
|
-
S: this,
|
|
270
|
-
C: (f, a) => f(...a)
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
_scheduleHeartbeats() {
|
|
275
|
-
invariant2(this._ws, void 0, {
|
|
276
|
-
F: __dxlog_file2,
|
|
277
|
-
L: 151,
|
|
278
|
-
S: this,
|
|
279
|
-
A: [
|
|
280
|
-
"this._ws",
|
|
281
|
-
""
|
|
282
|
-
]
|
|
283
|
-
});
|
|
284
|
-
scheduleTaskInterval(this._ctx, async () => {
|
|
285
|
-
this._ws?.send("__ping__");
|
|
286
|
-
}, SIGNAL_KEEPALIVE_INTERVAL);
|
|
287
|
-
this._ws.send("__ping__");
|
|
288
|
-
this._rescheduleHeartbeatTimeout();
|
|
289
|
-
}
|
|
290
|
-
_rescheduleHeartbeatTimeout() {
|
|
291
|
-
if (!this.isOpen) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
void this._inactivityTimeoutCtx?.dispose();
|
|
295
|
-
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
296
|
-
F: __dxlog_file2,
|
|
297
|
-
L: 170
|
|
298
|
-
});
|
|
299
|
-
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
300
|
-
if (this.isOpen) {
|
|
301
|
-
log.warn("restart due to inactivity timeout", void 0, {
|
|
302
|
-
F: __dxlog_file2,
|
|
303
|
-
L: 175,
|
|
304
|
-
S: this,
|
|
305
|
-
C: (f, a) => f(...a)
|
|
306
|
-
});
|
|
307
|
-
this._callbacks.onRestartRequired();
|
|
308
|
-
}
|
|
309
|
-
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
_ts_decorate([
|
|
313
|
-
logInfo
|
|
314
|
-
], EdgeWsConnection.prototype, "info", null);
|
|
315
|
-
|
|
316
64
|
// packages/core/mesh/edge-client/src/errors.ts
|
|
317
65
|
var EdgeConnectionClosedError = class extends Error {
|
|
318
66
|
constructor() {
|
|
@@ -334,15 +82,15 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
334
82
|
};
|
|
335
83
|
|
|
336
84
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
337
|
-
function
|
|
85
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
338
86
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
339
87
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
340
88
|
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;
|
|
341
89
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
342
90
|
}
|
|
343
|
-
var
|
|
91
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
344
92
|
var DEFAULT_TIMEOUT = 1e4;
|
|
345
|
-
var EdgeClient = class extends
|
|
93
|
+
var EdgeClient = class extends Resource {
|
|
346
94
|
constructor(_identity, _config) {
|
|
347
95
|
super();
|
|
348
96
|
this._identity = _identity;
|
|
@@ -379,11 +127,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
379
127
|
}
|
|
380
128
|
setIdentity(identity) {
|
|
381
129
|
if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
|
|
382
|
-
|
|
130
|
+
log("Edge identity changed", {
|
|
383
131
|
identity,
|
|
384
132
|
oldIdentity: this._identity
|
|
385
133
|
}, {
|
|
386
|
-
F:
|
|
134
|
+
F: __dxlog_file2,
|
|
387
135
|
L: 99,
|
|
388
136
|
S: this,
|
|
389
137
|
C: (f, a) => f(...a)
|
|
@@ -405,8 +153,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
405
153
|
try {
|
|
406
154
|
listener();
|
|
407
155
|
} catch (error) {
|
|
408
|
-
|
|
409
|
-
F:
|
|
156
|
+
log.catch(error, void 0, {
|
|
157
|
+
F: __dxlog_file2,
|
|
410
158
|
L: 121,
|
|
411
159
|
S: this,
|
|
412
160
|
C: (f, a) => f(...a)
|
|
@@ -421,19 +169,19 @@ var EdgeClient = class extends Resource2 {
|
|
|
421
169
|
* Open connection to messaging service.
|
|
422
170
|
*/
|
|
423
171
|
async _open() {
|
|
424
|
-
|
|
172
|
+
log("opening...", {
|
|
425
173
|
info: this.info
|
|
426
174
|
}, {
|
|
427
|
-
F:
|
|
175
|
+
F: __dxlog_file2,
|
|
428
176
|
L: 133,
|
|
429
177
|
S: this,
|
|
430
178
|
C: (f, a) => f(...a)
|
|
431
179
|
});
|
|
432
180
|
this._persistentLifecycle.open().catch((err) => {
|
|
433
|
-
|
|
181
|
+
log.warn("Error while opening connection", {
|
|
434
182
|
err
|
|
435
183
|
}, {
|
|
436
|
-
F:
|
|
184
|
+
F: __dxlog_file2,
|
|
437
185
|
L: 135,
|
|
438
186
|
S: this,
|
|
439
187
|
C: (f, a) => f(...a)
|
|
@@ -444,10 +192,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
444
192
|
* Close connection and free resources.
|
|
445
193
|
*/
|
|
446
194
|
async _close() {
|
|
447
|
-
|
|
195
|
+
log("closing...", {
|
|
448
196
|
peerKey: this._identity.peerKey
|
|
449
197
|
}, {
|
|
450
|
-
F:
|
|
198
|
+
F: __dxlog_file2,
|
|
451
199
|
L: 143,
|
|
452
200
|
S: this,
|
|
453
201
|
C: (f, a) => f(...a)
|
|
@@ -463,8 +211,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
463
211
|
const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
|
|
464
212
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
465
213
|
if (this._identity !== identity) {
|
|
466
|
-
|
|
467
|
-
F:
|
|
214
|
+
log("identity changed during auth header request", void 0, {
|
|
215
|
+
F: __dxlog_file2,
|
|
468
216
|
L: 157,
|
|
469
217
|
S: this,
|
|
470
218
|
C: (f, a) => f(...a)
|
|
@@ -473,11 +221,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
473
221
|
}
|
|
474
222
|
const restartRequired = new Trigger();
|
|
475
223
|
const url = new URL(path, this._baseWsUrl);
|
|
476
|
-
|
|
224
|
+
log("Opening websocket", {
|
|
477
225
|
url: url.toString(),
|
|
478
226
|
protocolHeader
|
|
479
227
|
}, {
|
|
480
|
-
F:
|
|
228
|
+
F: __dxlog_file2,
|
|
481
229
|
L: 163,
|
|
482
230
|
S: this,
|
|
483
231
|
C: (f, a) => f(...a)
|
|
@@ -491,8 +239,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
491
239
|
this._ready.wake();
|
|
492
240
|
this._notifyReconnected();
|
|
493
241
|
} else {
|
|
494
|
-
|
|
495
|
-
F:
|
|
242
|
+
log.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
243
|
+
F: __dxlog_file2,
|
|
496
244
|
L: 173,
|
|
497
245
|
S: this,
|
|
498
246
|
C: (f, a) => f(...a)
|
|
@@ -504,8 +252,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
504
252
|
this._closeCurrentConnection();
|
|
505
253
|
void this._persistentLifecycle.scheduleRestart();
|
|
506
254
|
} else {
|
|
507
|
-
|
|
508
|
-
F:
|
|
255
|
+
log.verbose("restart requested by inactive connection", void 0, {
|
|
256
|
+
F: __dxlog_file2,
|
|
509
257
|
L: 181,
|
|
510
258
|
S: this,
|
|
511
259
|
C: (f, a) => f(...a)
|
|
@@ -517,11 +265,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
517
265
|
if (this._isActive(connection)) {
|
|
518
266
|
this._notifyMessageReceived(message);
|
|
519
267
|
} else {
|
|
520
|
-
|
|
268
|
+
log.verbose("ignored a message on inactive connection", {
|
|
521
269
|
from: message.source,
|
|
522
270
|
type: message.payload?.typeUrl
|
|
523
271
|
}, {
|
|
524
|
-
F:
|
|
272
|
+
F: __dxlog_file2,
|
|
525
273
|
L: 189,
|
|
526
274
|
S: this,
|
|
527
275
|
C: (f, a) => f(...a)
|
|
@@ -555,10 +303,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
555
303
|
try {
|
|
556
304
|
listener();
|
|
557
305
|
} catch (err) {
|
|
558
|
-
|
|
306
|
+
log.error("ws reconnect listener failed", {
|
|
559
307
|
err
|
|
560
308
|
}, {
|
|
561
|
-
F:
|
|
309
|
+
F: __dxlog_file2,
|
|
562
310
|
L: 225,
|
|
563
311
|
S: this,
|
|
564
312
|
C: (f, a) => f(...a)
|
|
@@ -571,11 +319,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
571
319
|
try {
|
|
572
320
|
listener(message);
|
|
573
321
|
} catch (err) {
|
|
574
|
-
|
|
322
|
+
log.error("ws incoming message processing failed", {
|
|
575
323
|
err,
|
|
576
324
|
payload: protocol.getPayloadType(message)
|
|
577
325
|
}, {
|
|
578
|
-
F:
|
|
326
|
+
F: __dxlog_file2,
|
|
579
327
|
L: 235,
|
|
580
328
|
S: this,
|
|
581
329
|
C: (f, a) => f(...a)
|
|
@@ -589,8 +337,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
589
337
|
*/
|
|
590
338
|
async send(message) {
|
|
591
339
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
592
|
-
|
|
593
|
-
F:
|
|
340
|
+
log("waiting for websocket to become ready", void 0, {
|
|
341
|
+
F: __dxlog_file2,
|
|
594
342
|
L: 246,
|
|
595
343
|
S: this,
|
|
596
344
|
C: (f, a) => f(...a)
|
|
@@ -616,11 +364,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
616
364
|
if (response.status === 401) {
|
|
617
365
|
return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));
|
|
618
366
|
} else {
|
|
619
|
-
|
|
367
|
+
log.warn("no auth challenge from edge", {
|
|
620
368
|
status: response.status,
|
|
621
369
|
statusText: response.statusText
|
|
622
370
|
}, {
|
|
623
|
-
F:
|
|
371
|
+
F: __dxlog_file2,
|
|
624
372
|
L: 271,
|
|
625
373
|
S: this,
|
|
626
374
|
C: (f, a) => f(...a)
|
|
@@ -629,8 +377,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
629
377
|
}
|
|
630
378
|
}
|
|
631
379
|
};
|
|
632
|
-
|
|
633
|
-
|
|
380
|
+
_ts_decorate([
|
|
381
|
+
logInfo
|
|
634
382
|
], EdgeClient.prototype, "info", null);
|
|
635
383
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
636
384
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
@@ -639,10 +387,10 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
|
639
387
|
|
|
640
388
|
// packages/core/mesh/edge-client/src/auth.ts
|
|
641
389
|
import { createCredential, signPresentation } from "@dxos/credentials";
|
|
642
|
-
import { invariant as
|
|
390
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
643
391
|
import { Keyring } from "@dxos/keyring";
|
|
644
392
|
import { PublicKey } from "@dxos/keys";
|
|
645
|
-
var
|
|
393
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
646
394
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
647
395
|
return {
|
|
648
396
|
identityKey: key.toHex(),
|
|
@@ -686,8 +434,8 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
686
434
|
identityKey: identityKey.toHex(),
|
|
687
435
|
peerKey: peerKey.toHex(),
|
|
688
436
|
presentCredentials: async ({ challenge }) => {
|
|
689
|
-
|
|
690
|
-
F:
|
|
437
|
+
invariant2(chain, void 0, {
|
|
438
|
+
F: __dxlog_file3,
|
|
691
439
|
L: 75,
|
|
692
440
|
S: void 0,
|
|
693
441
|
A: [
|
|
@@ -750,20 +498,20 @@ var createStubEdgeIdentity = () => {
|
|
|
750
498
|
|
|
751
499
|
// packages/core/mesh/edge-client/src/edge-http-client.ts
|
|
752
500
|
import { sleep } from "@dxos/async";
|
|
753
|
-
import { Context
|
|
754
|
-
import { log as
|
|
501
|
+
import { Context } from "@dxos/context";
|
|
502
|
+
import { log as log2 } from "@dxos/log";
|
|
755
503
|
import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
|
|
756
|
-
var
|
|
504
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
757
505
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
758
506
|
var DEFAULT_RETRY_JITTER = 500;
|
|
759
507
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
760
508
|
var EdgeHttpClient = class {
|
|
761
509
|
constructor(baseUrl) {
|
|
762
510
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
763
|
-
|
|
511
|
+
log2("created", {
|
|
764
512
|
url: this._baseUrl
|
|
765
513
|
}, {
|
|
766
|
-
F:
|
|
514
|
+
F: __dxlog_file4,
|
|
767
515
|
L: 53,
|
|
768
516
|
S: this,
|
|
769
517
|
C: (f, a) => f(...a)
|
|
@@ -895,8 +643,8 @@ var EdgeHttpClient = class {
|
|
|
895
643
|
});
|
|
896
644
|
}
|
|
897
645
|
async _call(path, args) {
|
|
898
|
-
const requestContext = args.context ?? new
|
|
899
|
-
F:
|
|
646
|
+
const requestContext = args.context ?? new Context(void 0, {
|
|
647
|
+
F: __dxlog_file4,
|
|
900
648
|
L: 192
|
|
901
649
|
});
|
|
902
650
|
const shouldRetry = createRetryHandler(args);
|
|
@@ -908,12 +656,12 @@ var EdgeHttpClient = class {
|
|
|
908
656
|
}
|
|
909
657
|
url += `?${queryParams.toString()}`;
|
|
910
658
|
}
|
|
911
|
-
|
|
659
|
+
log2("call", {
|
|
912
660
|
method: args.method,
|
|
913
661
|
path,
|
|
914
662
|
request: args.body
|
|
915
663
|
}, {
|
|
916
|
-
F:
|
|
664
|
+
F: __dxlog_file4,
|
|
917
665
|
L: 204,
|
|
918
666
|
S: this,
|
|
919
667
|
C: (f, a) => f(...a)
|
|
@@ -932,11 +680,11 @@ var EdgeHttpClient = class {
|
|
|
932
680
|
if (body.success) {
|
|
933
681
|
return body.data;
|
|
934
682
|
}
|
|
935
|
-
|
|
683
|
+
log2("unsuccessful edge response", {
|
|
936
684
|
path,
|
|
937
685
|
body
|
|
938
686
|
}, {
|
|
939
|
-
F:
|
|
687
|
+
F: __dxlog_file4,
|
|
940
688
|
L: 223,
|
|
941
689
|
S: this,
|
|
942
690
|
C: (f, a) => f(...a)
|
|
@@ -957,11 +705,11 @@ var EdgeHttpClient = class {
|
|
|
957
705
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
958
706
|
}
|
|
959
707
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
960
|
-
|
|
708
|
+
log2("retrying edge request", {
|
|
961
709
|
path,
|
|
962
710
|
processingError
|
|
963
711
|
}, {
|
|
964
|
-
F:
|
|
712
|
+
F: __dxlog_file4,
|
|
965
713
|
L: 242,
|
|
966
714
|
S: this,
|
|
967
715
|
C: (f, a) => f(...a)
|
|
@@ -973,8 +721,8 @@ var EdgeHttpClient = class {
|
|
|
973
721
|
}
|
|
974
722
|
async _handleUnauthorized(response) {
|
|
975
723
|
if (!this._edgeIdentity) {
|
|
976
|
-
|
|
977
|
-
F:
|
|
724
|
+
log2.warn("edge unauthorized response received before identity was set", void 0, {
|
|
725
|
+
F: __dxlog_file4,
|
|
978
726
|
L: 251,
|
|
979
727
|
S: this,
|
|
980
728
|
C: (f, a) => f(...a)
|
|
@@ -983,8 +731,8 @@ var EdgeHttpClient = class {
|
|
|
983
731
|
}
|
|
984
732
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
985
733
|
this._authHeader = encodeAuthHeader(challenge);
|
|
986
|
-
|
|
987
|
-
F:
|
|
734
|
+
log2("auth header updated", void 0, {
|
|
735
|
+
F: __dxlog_file4,
|
|
988
736
|
L: 256,
|
|
989
737
|
S: this,
|
|
990
738
|
C: (f, a) => f(...a)
|
|
@@ -1029,6 +777,8 @@ var encodeAuthHeader = (challenge) => {
|
|
|
1029
777
|
export {
|
|
1030
778
|
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
1031
779
|
CLOUDFLARE_RPC_MAX_BYTES,
|
|
780
|
+
EDGE_WEBSOCKET_PROTOCOL_V0,
|
|
781
|
+
EDGE_WEBSOCKET_PROTOCOL_V1,
|
|
1032
782
|
EdgeClient,
|
|
1033
783
|
EdgeConnectionClosedError,
|
|
1034
784
|
EdgeHttpClient,
|