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