@dxos/messaging 0.6.13 → 0.6.14-main.2b6a0f3
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-BZOQIXEW.mjs +691 -0
- package/dist/lib/browser/chunk-BZOQIXEW.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +256 -923
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +147 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/node/chunk-WDA7H2PO.cjs +688 -0
- package/dist/lib/node/chunk-WDA7H2PO.cjs.map +7 -0
- package/dist/lib/node/index.cjs +272 -916
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +162 -0
- package/dist/lib/node/testing/index.cjs.map +7 -0
- package/dist/lib/node-esm/chunk-RAYDHHAO.mjs +683 -0
- package/dist/lib/node-esm/chunk-RAYDHHAO.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1631 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +146 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/messenger.blueprint-test.d.ts +2 -3
- package/dist/types/src/messenger.blueprint-test.d.ts.map +1 -1
- package/dist/types/src/messenger.d.ts.map +1 -1
- package/dist/types/src/messenger.node.test.d.ts +2 -0
- package/dist/types/src/messenger.node.test.d.ts.map +1 -0
- package/dist/types/src/signal-client/signal-client.node.test.d.ts +2 -0
- package/dist/types/src/signal-client/signal-client.node.test.d.ts.map +1 -0
- package/dist/types/src/signal-client/signal-rpc-client.node.test.d.ts +2 -0
- package/dist/types/src/signal-client/signal-rpc-client.node.test.d.ts.map +1 -0
- package/dist/types/src/signal-manager/edge-signal-manager.d.ts.map +1 -1
- package/dist/types/src/signal-manager/websocket-signal-manager.node.test.d.ts +2 -0
- package/dist/types/src/signal-manager/websocket-signal-manager.node.test.d.ts.map +1 -0
- package/dist/types/src/testing/test-builder.d.ts +3 -4
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-peer.d.ts +0 -1
- package/dist/types/src/testing/test-peer.d.ts.map +1 -1
- package/package.json +32 -21
- package/src/messenger.blueprint-test.ts +25 -33
- package/src/{messenger.test.ts → messenger.node.test.ts} +6 -19
- package/src/messenger.ts +1 -1
- package/src/signal-client/{signal-client.test.ts → signal-client.node.test.ts} +9 -8
- package/src/signal-client/{signal-rpc-client.test.ts → signal-rpc-client.node.test.ts} +8 -13
- package/src/signal-manager/edge-signal-manager.ts +16 -6
- package/src/signal-manager/{websocket-signal-manager.test.ts → websocket-signal-manager.node.test.ts} +12 -30
- package/src/testing/test-builder.ts +3 -6
- package/src/testing/test-peer.ts +5 -7
- package/dist/types/src/messenger.test.d.ts +0 -2
- package/dist/types/src/messenger.test.d.ts.map +0 -1
- package/dist/types/src/signal-client/signal-client.test.d.ts +0 -2
- package/dist/types/src/signal-client/signal-client.test.d.ts.map +0 -1
- package/dist/types/src/signal-client/signal-rpc-client.test.d.ts +0 -2
- package/dist/types/src/signal-client/signal-rpc-client.test.d.ts.map +0 -1
- package/dist/types/src/signal-manager/edge-signal-manager.test.d.ts +0 -2
- package/dist/types/src/signal-manager/edge-signal-manager.test.d.ts.map +0 -1
- package/dist/types/src/signal-manager/websocket-signal-manager.test.d.ts +0 -2
- package/dist/types/src/signal-manager/websocket-signal-manager.test.d.ts.map +0 -1
- package/src/signal-manager/edge-signal-manager.test.ts +0 -67
|
@@ -1,432 +1,23 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
|
-
|
|
3
|
-
// inject-globals:@inject-globals
|
|
4
2
|
import {
|
|
5
|
-
global,
|
|
6
3
|
Buffer,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { Context } from "@dxos/context";
|
|
13
|
-
import { invariant } from "@dxos/invariant";
|
|
14
|
-
import { PublicKey } from "@dxos/keys";
|
|
15
|
-
import { log } from "@dxos/log";
|
|
16
|
-
import { TimeoutError as ProtocolTimeoutError, trace as trace2 } from "@dxos/protocols";
|
|
17
|
-
import { schema } from "@dxos/protocols/proto";
|
|
18
|
-
import { ComplexMap, ComplexSet } from "@dxos/util";
|
|
19
|
-
|
|
20
|
-
// packages/core/mesh/messaging/src/messenger-monitor.ts
|
|
21
|
-
import { trace } from "@dxos/tracing";
|
|
22
|
-
var MessengerMonitor = class {
|
|
23
|
-
recordMessageAckFailed() {
|
|
24
|
-
trace.metrics.increment("dxos.mesh.signal.messenger.failed-ack", 1);
|
|
25
|
-
}
|
|
26
|
-
recordReliableMessage(params) {
|
|
27
|
-
trace.metrics.increment("dxos.mesh.signal.messenger.reliable-send", 1, {
|
|
28
|
-
tags: {
|
|
29
|
-
success: params.sent,
|
|
30
|
-
attempts: params.sendAttempts
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// packages/core/mesh/messaging/src/timeouts.ts
|
|
37
|
-
var MESSAGE_TIMEOUT = 1e4;
|
|
38
|
-
|
|
39
|
-
// packages/core/mesh/messaging/src/messenger.ts
|
|
40
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/messenger.ts";
|
|
41
|
-
var ReliablePayload = schema.getCodecForType("dxos.mesh.messaging.ReliablePayload");
|
|
42
|
-
var Acknowledgement = schema.getCodecForType("dxos.mesh.messaging.Acknowledgement");
|
|
43
|
-
var RECEIVED_MESSAGES_GC_INTERVAL = 12e4;
|
|
44
|
-
var Messenger = class {
|
|
45
|
-
constructor({ signalManager, retryDelay = 300 }) {
|
|
46
|
-
this._monitor = new MessengerMonitor();
|
|
47
|
-
// { peerId, payloadType } => listeners set
|
|
48
|
-
this._listeners = new ComplexMap(({ peerId, payloadType }) => peerId + payloadType);
|
|
49
|
-
// peerId => listeners set
|
|
50
|
-
this._defaultListeners = /* @__PURE__ */ new Map();
|
|
51
|
-
this._onAckCallbacks = new ComplexMap(PublicKey.hash);
|
|
52
|
-
this._receivedMessages = new ComplexSet(PublicKey.hash);
|
|
53
|
-
/**
|
|
54
|
-
* Keys scheduled to be cleared from _receivedMessages on the next iteration.
|
|
55
|
-
*/
|
|
56
|
-
this._toClear = new ComplexSet(PublicKey.hash);
|
|
57
|
-
this._closed = true;
|
|
58
|
-
this._signalManager = signalManager;
|
|
59
|
-
this._retryDelay = retryDelay;
|
|
60
|
-
this.open();
|
|
61
|
-
}
|
|
62
|
-
open() {
|
|
63
|
-
if (!this._closed) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const traceId = PublicKey.random().toHex();
|
|
67
|
-
log.trace("dxos.mesh.messenger.open", trace2.begin({
|
|
68
|
-
id: traceId
|
|
69
|
-
}), {
|
|
70
|
-
F: __dxlog_file,
|
|
71
|
-
L: 72,
|
|
72
|
-
S: this,
|
|
73
|
-
C: (f, a) => f(...a)
|
|
74
|
-
});
|
|
75
|
-
this._ctx = new Context({
|
|
76
|
-
onError: (err) => log.catch(err, void 0, {
|
|
77
|
-
F: __dxlog_file,
|
|
78
|
-
L: 74,
|
|
79
|
-
S: this,
|
|
80
|
-
C: (f, a) => f(...a)
|
|
81
|
-
})
|
|
82
|
-
}, {
|
|
83
|
-
F: __dxlog_file,
|
|
84
|
-
L: 73
|
|
85
|
-
});
|
|
86
|
-
this._ctx.onDispose(this._signalManager.onMessage.on(async (message) => {
|
|
87
|
-
log("received message", {
|
|
88
|
-
from: message.author
|
|
89
|
-
}, {
|
|
90
|
-
F: __dxlog_file,
|
|
91
|
-
L: 78,
|
|
92
|
-
S: this,
|
|
93
|
-
C: (f, a) => f(...a)
|
|
94
|
-
});
|
|
95
|
-
await this._handleMessage(message);
|
|
96
|
-
}));
|
|
97
|
-
scheduleTaskInterval(this._ctx, async () => {
|
|
98
|
-
this._performGc();
|
|
99
|
-
}, RECEIVED_MESSAGES_GC_INTERVAL);
|
|
100
|
-
this._closed = false;
|
|
101
|
-
log.trace("dxos.mesh.messenger.open", trace2.end({
|
|
102
|
-
id: traceId
|
|
103
|
-
}), {
|
|
104
|
-
F: __dxlog_file,
|
|
105
|
-
L: 93,
|
|
106
|
-
S: this,
|
|
107
|
-
C: (f, a) => f(...a)
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
async close() {
|
|
111
|
-
if (this._closed) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
this._closed = true;
|
|
115
|
-
await this._ctx.dispose();
|
|
116
|
-
}
|
|
117
|
-
async sendMessage({ author, recipient, payload }) {
|
|
118
|
-
invariant(!this._closed, "Closed", {
|
|
119
|
-
F: __dxlog_file,
|
|
120
|
-
L: 105,
|
|
121
|
-
S: this,
|
|
122
|
-
A: [
|
|
123
|
-
"!this._closed",
|
|
124
|
-
"'Closed'"
|
|
125
|
-
]
|
|
126
|
-
});
|
|
127
|
-
const messageContext = this._ctx.derive();
|
|
128
|
-
const reliablePayload = {
|
|
129
|
-
messageId: PublicKey.random(),
|
|
130
|
-
payload
|
|
131
|
-
};
|
|
132
|
-
invariant(!this._onAckCallbacks.has(reliablePayload.messageId), void 0, {
|
|
133
|
-
F: __dxlog_file,
|
|
134
|
-
L: 112,
|
|
135
|
-
S: this,
|
|
136
|
-
A: [
|
|
137
|
-
"!this._onAckCallbacks.has(reliablePayload.messageId!)",
|
|
138
|
-
""
|
|
139
|
-
]
|
|
140
|
-
});
|
|
141
|
-
log("send message", {
|
|
142
|
-
messageId: reliablePayload.messageId,
|
|
143
|
-
author,
|
|
144
|
-
recipient
|
|
145
|
-
}, {
|
|
146
|
-
F: __dxlog_file,
|
|
147
|
-
L: 113,
|
|
148
|
-
S: this,
|
|
149
|
-
C: (f, a) => f(...a)
|
|
150
|
-
});
|
|
151
|
-
let messageReceived;
|
|
152
|
-
let timeoutHit;
|
|
153
|
-
let sendAttempts = 0;
|
|
154
|
-
const promise = new Promise((resolve, reject) => {
|
|
155
|
-
messageReceived = resolve;
|
|
156
|
-
timeoutHit = reject;
|
|
157
|
-
});
|
|
158
|
-
scheduleExponentialBackoffTaskInterval(messageContext, async () => {
|
|
159
|
-
log("retrying message", {
|
|
160
|
-
messageId: reliablePayload.messageId
|
|
161
|
-
}, {
|
|
162
|
-
F: __dxlog_file,
|
|
163
|
-
L: 128,
|
|
164
|
-
S: this,
|
|
165
|
-
C: (f, a) => f(...a)
|
|
166
|
-
});
|
|
167
|
-
sendAttempts++;
|
|
168
|
-
await this._encodeAndSend({
|
|
169
|
-
author,
|
|
170
|
-
recipient,
|
|
171
|
-
reliablePayload
|
|
172
|
-
}).catch((err) => log("failed to send message", {
|
|
173
|
-
err
|
|
174
|
-
}, {
|
|
175
|
-
F: __dxlog_file,
|
|
176
|
-
L: 131,
|
|
177
|
-
S: this,
|
|
178
|
-
C: (f, a) => f(...a)
|
|
179
|
-
}));
|
|
180
|
-
}, this._retryDelay);
|
|
181
|
-
scheduleTask(messageContext, () => {
|
|
182
|
-
log("message not delivered", {
|
|
183
|
-
messageId: reliablePayload.messageId
|
|
184
|
-
}, {
|
|
185
|
-
F: __dxlog_file,
|
|
186
|
-
L: 140,
|
|
187
|
-
S: this,
|
|
188
|
-
C: (f, a) => f(...a)
|
|
189
|
-
});
|
|
190
|
-
this._onAckCallbacks.delete(reliablePayload.messageId);
|
|
191
|
-
timeoutHit(new ProtocolTimeoutError("signaling message not delivered", new TimeoutError(MESSAGE_TIMEOUT, "Message not delivered")));
|
|
192
|
-
void messageContext.dispose();
|
|
193
|
-
this._monitor.recordReliableMessage({
|
|
194
|
-
sendAttempts,
|
|
195
|
-
sent: false
|
|
196
|
-
});
|
|
197
|
-
}, MESSAGE_TIMEOUT);
|
|
198
|
-
this._onAckCallbacks.set(reliablePayload.messageId, () => {
|
|
199
|
-
messageReceived();
|
|
200
|
-
this._onAckCallbacks.delete(reliablePayload.messageId);
|
|
201
|
-
void messageContext.dispose();
|
|
202
|
-
this._monitor.recordReliableMessage({
|
|
203
|
-
sendAttempts,
|
|
204
|
-
sent: true
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
await this._encodeAndSend({
|
|
208
|
-
author,
|
|
209
|
-
recipient,
|
|
210
|
-
reliablePayload
|
|
211
|
-
});
|
|
212
|
-
return promise;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Subscribes onMessage function to messages that contains payload with payloadType.
|
|
216
|
-
* @param payloadType if not specified, onMessage will be subscribed to all types of messages.
|
|
217
|
-
*/
|
|
218
|
-
async listen({ peer, payloadType, onMessage }) {
|
|
219
|
-
invariant(!this._closed, "Closed", {
|
|
220
|
-
F: __dxlog_file,
|
|
221
|
-
L: 178,
|
|
222
|
-
S: this,
|
|
223
|
-
A: [
|
|
224
|
-
"!this._closed",
|
|
225
|
-
"'Closed'"
|
|
226
|
-
]
|
|
227
|
-
});
|
|
228
|
-
await this._signalManager.subscribeMessages(peer);
|
|
229
|
-
let listeners;
|
|
230
|
-
invariant(peer.peerKey, "Peer key is required", {
|
|
231
|
-
F: __dxlog_file,
|
|
232
|
-
L: 182,
|
|
233
|
-
S: this,
|
|
234
|
-
A: [
|
|
235
|
-
"peer.peerKey",
|
|
236
|
-
"'Peer key is required'"
|
|
237
|
-
]
|
|
238
|
-
});
|
|
239
|
-
if (!payloadType) {
|
|
240
|
-
listeners = this._defaultListeners.get(peer.peerKey);
|
|
241
|
-
if (!listeners) {
|
|
242
|
-
listeners = /* @__PURE__ */ new Set();
|
|
243
|
-
this._defaultListeners.set(peer.peerKey, listeners);
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
listeners = this._listeners.get({
|
|
247
|
-
peerId: peer.peerKey,
|
|
248
|
-
payloadType
|
|
249
|
-
});
|
|
250
|
-
if (!listeners) {
|
|
251
|
-
listeners = /* @__PURE__ */ new Set();
|
|
252
|
-
this._listeners.set({
|
|
253
|
-
peerId: peer.peerKey,
|
|
254
|
-
payloadType
|
|
255
|
-
}, listeners);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
listeners.add(onMessage);
|
|
259
|
-
return {
|
|
260
|
-
unsubscribe: async () => {
|
|
261
|
-
listeners.delete(onMessage);
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
async _encodeAndSend({ author, recipient, reliablePayload }) {
|
|
266
|
-
await this._signalManager.sendMessage({
|
|
267
|
-
author,
|
|
268
|
-
recipient,
|
|
269
|
-
payload: {
|
|
270
|
-
type_url: "dxos.mesh.messaging.ReliablePayload",
|
|
271
|
-
value: ReliablePayload.encode(reliablePayload, {
|
|
272
|
-
preserveAny: true
|
|
273
|
-
})
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
async _handleMessage(message) {
|
|
278
|
-
switch (message.payload.type_url) {
|
|
279
|
-
case "dxos.mesh.messaging.ReliablePayload": {
|
|
280
|
-
await this._handleReliablePayload(message);
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
case "dxos.mesh.messaging.Acknowledgement": {
|
|
284
|
-
await this._handleAcknowledgement({
|
|
285
|
-
payload: message.payload
|
|
286
|
-
});
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async _handleReliablePayload({ author, recipient, payload }) {
|
|
292
|
-
invariant(payload.type_url === "dxos.mesh.messaging.ReliablePayload", void 0, {
|
|
293
|
-
F: __dxlog_file,
|
|
294
|
-
L: 240,
|
|
295
|
-
S: this,
|
|
296
|
-
A: [
|
|
297
|
-
"payload.type_url === 'dxos.mesh.messaging.ReliablePayload'",
|
|
298
|
-
""
|
|
299
|
-
]
|
|
300
|
-
});
|
|
301
|
-
const reliablePayload = ReliablePayload.decode(payload.value, {
|
|
302
|
-
preserveAny: true
|
|
303
|
-
});
|
|
304
|
-
log("handling message", {
|
|
305
|
-
messageId: reliablePayload.messageId
|
|
306
|
-
}, {
|
|
307
|
-
F: __dxlog_file,
|
|
308
|
-
L: 243,
|
|
309
|
-
S: this,
|
|
310
|
-
C: (f, a) => f(...a)
|
|
311
|
-
});
|
|
312
|
-
try {
|
|
313
|
-
await this._sendAcknowledgement({
|
|
314
|
-
author,
|
|
315
|
-
recipient,
|
|
316
|
-
messageId: reliablePayload.messageId
|
|
317
|
-
});
|
|
318
|
-
} catch (err) {
|
|
319
|
-
this._monitor.recordMessageAckFailed();
|
|
320
|
-
throw err;
|
|
321
|
-
}
|
|
322
|
-
if (this._receivedMessages.has(reliablePayload.messageId)) {
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
this._receivedMessages.add(reliablePayload.messageId);
|
|
326
|
-
await this._callListeners({
|
|
327
|
-
author,
|
|
328
|
-
recipient,
|
|
329
|
-
payload: reliablePayload.payload
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
async _handleAcknowledgement({ payload }) {
|
|
333
|
-
invariant(payload.type_url === "dxos.mesh.messaging.Acknowledgement", void 0, {
|
|
334
|
-
F: __dxlog_file,
|
|
335
|
-
L: 271,
|
|
336
|
-
S: this,
|
|
337
|
-
A: [
|
|
338
|
-
"payload.type_url === 'dxos.mesh.messaging.Acknowledgement'",
|
|
339
|
-
""
|
|
340
|
-
]
|
|
341
|
-
});
|
|
342
|
-
this._onAckCallbacks.get(Acknowledgement.decode(payload.value).messageId)?.();
|
|
343
|
-
}
|
|
344
|
-
async _sendAcknowledgement({ author, recipient, messageId }) {
|
|
345
|
-
log("sending ACK", {
|
|
346
|
-
messageId,
|
|
347
|
-
from: recipient,
|
|
348
|
-
to: author
|
|
349
|
-
}, {
|
|
350
|
-
F: __dxlog_file,
|
|
351
|
-
L: 284,
|
|
352
|
-
S: this,
|
|
353
|
-
C: (f, a) => f(...a)
|
|
354
|
-
});
|
|
355
|
-
await this._signalManager.sendMessage({
|
|
356
|
-
author: recipient,
|
|
357
|
-
recipient: author,
|
|
358
|
-
payload: {
|
|
359
|
-
type_url: "dxos.mesh.messaging.Acknowledgement",
|
|
360
|
-
value: Acknowledgement.encode({
|
|
361
|
-
messageId
|
|
362
|
-
})
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
async _callListeners(message) {
|
|
367
|
-
{
|
|
368
|
-
invariant(message.recipient.peerKey, "Peer key is required", {
|
|
369
|
-
F: __dxlog_file,
|
|
370
|
-
L: 298,
|
|
371
|
-
S: this,
|
|
372
|
-
A: [
|
|
373
|
-
"message.recipient.peerKey",
|
|
374
|
-
"'Peer key is required'"
|
|
375
|
-
]
|
|
376
|
-
});
|
|
377
|
-
const defaultListenerMap = this._defaultListeners.get(message.recipient.peerKey);
|
|
378
|
-
if (defaultListenerMap) {
|
|
379
|
-
for (const listener of defaultListenerMap) {
|
|
380
|
-
await listener(message);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
{
|
|
385
|
-
const listenerMap = this._listeners.get({
|
|
386
|
-
peerId: message.recipient.peerKey,
|
|
387
|
-
payloadType: message.payload.type_url
|
|
388
|
-
});
|
|
389
|
-
if (listenerMap) {
|
|
390
|
-
for (const listener of listenerMap) {
|
|
391
|
-
await listener(message);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
_performGc() {
|
|
397
|
-
const start = performance.now();
|
|
398
|
-
for (const key of this._toClear.keys()) {
|
|
399
|
-
this._receivedMessages.delete(key);
|
|
400
|
-
}
|
|
401
|
-
this._toClear.clear();
|
|
402
|
-
for (const key of this._receivedMessages.keys()) {
|
|
403
|
-
this._toClear.add(key);
|
|
404
|
-
}
|
|
405
|
-
const elapsed = performance.now() - start;
|
|
406
|
-
if (elapsed > 100) {
|
|
407
|
-
log.warn("GC took too long", {
|
|
408
|
-
elapsed
|
|
409
|
-
}, {
|
|
410
|
-
F: __dxlog_file,
|
|
411
|
-
L: 333,
|
|
412
|
-
S: this,
|
|
413
|
-
C: (f, a) => f(...a)
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
};
|
|
4
|
+
MemorySignalManager,
|
|
5
|
+
MemorySignalManagerContext,
|
|
6
|
+
Messenger,
|
|
7
|
+
PeerInfoHash
|
|
8
|
+
} from "./chunk-BZOQIXEW.mjs";
|
|
418
9
|
|
|
419
10
|
// packages/core/mesh/messaging/src/signal-client/signal-client.ts
|
|
420
|
-
import { DeferredTask, Event as Event2, Trigger as Trigger2, scheduleTask
|
|
11
|
+
import { DeferredTask, Event as Event2, Trigger as Trigger2, scheduleTask, scheduleTaskInterval as scheduleTaskInterval2, sleep } from "@dxos/async";
|
|
421
12
|
import { cancelWithContext as cancelWithContext2, Resource } from "@dxos/context";
|
|
422
|
-
import { invariant as
|
|
423
|
-
import { PublicKey as
|
|
424
|
-
import { log as
|
|
425
|
-
import { trace as
|
|
13
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
14
|
+
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
15
|
+
import { log as log3 } from "@dxos/log";
|
|
16
|
+
import { trace as trace4 } from "@dxos/protocols";
|
|
426
17
|
import { SignalState } from "@dxos/protocols/proto/dxos/mesh/signal";
|
|
427
18
|
|
|
428
19
|
// packages/core/mesh/messaging/src/signal-client/signal-client-monitor.ts
|
|
429
|
-
import { trace
|
|
20
|
+
import { trace } from "@dxos/tracing";
|
|
430
21
|
var SignalClientMonitor = class {
|
|
431
22
|
constructor() {
|
|
432
23
|
this._performance = {
|
|
@@ -459,7 +50,7 @@ var SignalClientMonitor = class {
|
|
|
459
50
|
}
|
|
460
51
|
recordReconnect(params) {
|
|
461
52
|
this._performance.reconnectCounter++;
|
|
462
|
-
|
|
53
|
+
trace.metrics.increment("dxos.mesh.signal.signal-client.reconnect", 1, {
|
|
463
54
|
tags: {
|
|
464
55
|
success: params.success
|
|
465
56
|
}
|
|
@@ -473,10 +64,10 @@ var SignalClientMonitor = class {
|
|
|
473
64
|
}
|
|
474
65
|
recordMessageReceived(message) {
|
|
475
66
|
this._performance.receivedMessages++;
|
|
476
|
-
|
|
67
|
+
trace.metrics.increment("dxos.mesh.signal.signal-client.received-total", 1, {
|
|
477
68
|
tags: createIdentityTags(message)
|
|
478
69
|
});
|
|
479
|
-
|
|
70
|
+
trace.metrics.distribution("dxos.mesh.signal.signal-client.bytes-in", getByteCount(message), {
|
|
480
71
|
tags: createIdentityTags(message)
|
|
481
72
|
});
|
|
482
73
|
}
|
|
@@ -488,16 +79,16 @@ var SignalClientMonitor = class {
|
|
|
488
79
|
const reqStart = Date.now();
|
|
489
80
|
await sendMessage();
|
|
490
81
|
const reqDuration = Date.now() - reqStart;
|
|
491
|
-
|
|
82
|
+
trace.metrics.distribution("dxos.mesh.signal.signal-client.send-duration", reqDuration, {
|
|
492
83
|
tags
|
|
493
84
|
});
|
|
494
|
-
|
|
85
|
+
trace.metrics.distribution("dxos.mesh.signal.signal-client.bytes-out", getByteCount(message), {
|
|
495
86
|
tags
|
|
496
87
|
});
|
|
497
88
|
} catch (err) {
|
|
498
89
|
success = false;
|
|
499
90
|
}
|
|
500
|
-
|
|
91
|
+
trace.metrics.increment("dxos.mesh.signal.signal-client.sent-total", 1, {
|
|
501
92
|
tags: {
|
|
502
93
|
...tags,
|
|
503
94
|
success
|
|
@@ -505,10 +96,10 @@ var SignalClientMonitor = class {
|
|
|
505
96
|
});
|
|
506
97
|
}
|
|
507
98
|
recordStreamCloseErrors(count) {
|
|
508
|
-
|
|
99
|
+
trace.metrics.increment("dxos.mesh.signal.signal-client.stream-close-errors", count);
|
|
509
100
|
}
|
|
510
101
|
recordReconciliation(params) {
|
|
511
|
-
|
|
102
|
+
trace.metrics.increment("dxos.mesh.signal.signal-client.reconciliation", 1, {
|
|
512
103
|
tags: {
|
|
513
104
|
success: params.success
|
|
514
105
|
}
|
|
@@ -527,18 +118,18 @@ var createIdentityTags = (message) => {
|
|
|
527
118
|
// packages/core/mesh/messaging/src/signal-client/signal-local-state.ts
|
|
528
119
|
import { asyncTimeout, Event } from "@dxos/async";
|
|
529
120
|
import { cancelWithContext } from "@dxos/context";
|
|
530
|
-
import { PublicKey
|
|
531
|
-
import { log
|
|
532
|
-
import { ComplexMap
|
|
533
|
-
var
|
|
121
|
+
import { PublicKey } from "@dxos/keys";
|
|
122
|
+
import { log } from "@dxos/log";
|
|
123
|
+
import { ComplexMap, ComplexSet, safeAwaitAll } from "@dxos/util";
|
|
124
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-client/signal-local-state.ts";
|
|
534
125
|
var SignalLocalState = class {
|
|
535
126
|
constructor(_onMessage, _onSwarmEvent) {
|
|
536
127
|
this._onMessage = _onMessage;
|
|
537
128
|
this._onSwarmEvent = _onSwarmEvent;
|
|
538
|
-
this._swarmStreams = new
|
|
539
|
-
this._joinedTopics = new
|
|
540
|
-
this._subscribedMessages = new
|
|
541
|
-
this.messageStreams = new
|
|
129
|
+
this._swarmStreams = new ComplexMap(({ topic, peerId }) => topic.toHex() + peerId.toHex());
|
|
130
|
+
this._joinedTopics = new ComplexSet(({ topic, peerId }) => topic.toHex() + peerId.toHex());
|
|
131
|
+
this._subscribedMessages = new ComplexSet(({ peerId }) => peerId.toHex());
|
|
132
|
+
this.messageStreams = new ComplexMap((key) => key.toHex());
|
|
542
133
|
this.reconciled = new Event();
|
|
543
134
|
}
|
|
544
135
|
async safeCloseStreams() {
|
|
@@ -580,10 +171,10 @@ var SignalLocalState = class {
|
|
|
580
171
|
});
|
|
581
172
|
}
|
|
582
173
|
unsubscribeMessages(peerId) {
|
|
583
|
-
|
|
174
|
+
log("unsubscribing from messages", {
|
|
584
175
|
peerId
|
|
585
176
|
}, {
|
|
586
|
-
F:
|
|
177
|
+
F: __dxlog_file,
|
|
587
178
|
L: 79,
|
|
588
179
|
S: this,
|
|
589
180
|
C: (f, a) => f(...a)
|
|
@@ -632,10 +223,10 @@ var SignalLocalState = class {
|
|
|
632
223
|
topic,
|
|
633
224
|
peerId
|
|
634
225
|
})) {
|
|
635
|
-
|
|
226
|
+
log("swarm event", {
|
|
636
227
|
swarmEvent
|
|
637
228
|
}, {
|
|
638
|
-
F:
|
|
229
|
+
F: __dxlog_file,
|
|
639
230
|
L: 115,
|
|
640
231
|
S: this,
|
|
641
232
|
C: (f, a) => f(...a)
|
|
@@ -645,7 +236,7 @@ var SignalLocalState = class {
|
|
|
645
236
|
peerAvailable: {
|
|
646
237
|
...swarmEvent.peerAvailable,
|
|
647
238
|
peer: {
|
|
648
|
-
peerKey:
|
|
239
|
+
peerKey: PublicKey.from(swarmEvent.peerAvailable.peer).toHex()
|
|
649
240
|
}
|
|
650
241
|
}
|
|
651
242
|
} : {
|
|
@@ -653,7 +244,7 @@ var SignalLocalState = class {
|
|
|
653
244
|
peerLeft: {
|
|
654
245
|
...swarmEvent.peerLeft,
|
|
655
246
|
peer: {
|
|
656
|
-
peerKey:
|
|
247
|
+
peerKey: PublicKey.from(swarmEvent.peerLeft.peer).toHex()
|
|
657
248
|
}
|
|
658
249
|
}
|
|
659
250
|
};
|
|
@@ -687,10 +278,10 @@ var SignalLocalState = class {
|
|
|
687
278
|
})) {
|
|
688
279
|
const message = {
|
|
689
280
|
author: {
|
|
690
|
-
peerKey:
|
|
281
|
+
peerKey: PublicKey.from(signalMessage.author).toHex()
|
|
691
282
|
},
|
|
692
283
|
recipient: {
|
|
693
|
-
peerKey:
|
|
284
|
+
peerKey: PublicKey.from(signalMessage.recipient).toHex()
|
|
694
285
|
},
|
|
695
286
|
payload: signalMessage.payload
|
|
696
287
|
};
|
|
@@ -704,20 +295,20 @@ var SignalLocalState = class {
|
|
|
704
295
|
|
|
705
296
|
// packages/core/mesh/messaging/src/signal-client/signal-rpc-client.ts
|
|
706
297
|
import WebSocket from "isomorphic-ws";
|
|
707
|
-
import { scheduleTaskInterval
|
|
708
|
-
import { Context
|
|
709
|
-
import { invariant
|
|
710
|
-
import { PublicKey as
|
|
711
|
-
import { log as
|
|
712
|
-
import { trace as
|
|
713
|
-
import { schema
|
|
298
|
+
import { scheduleTaskInterval, TimeoutError, Trigger } from "@dxos/async";
|
|
299
|
+
import { Context } from "@dxos/context";
|
|
300
|
+
import { invariant } from "@dxos/invariant";
|
|
301
|
+
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
302
|
+
import { log as log2 } from "@dxos/log";
|
|
303
|
+
import { trace as trace3 } from "@dxos/protocols";
|
|
304
|
+
import { schema } from "@dxos/protocols/proto";
|
|
714
305
|
import { createProtoRpcPeer } from "@dxos/rpc";
|
|
715
306
|
|
|
716
307
|
// packages/core/mesh/messaging/src/signal-client/signal-rpc-client-monitor.ts
|
|
717
|
-
import { trace as
|
|
308
|
+
import { trace as trace2 } from "@dxos/tracing";
|
|
718
309
|
var SignalRpcClientMonitor = class {
|
|
719
310
|
recordClientCloseFailure(params) {
|
|
720
|
-
|
|
311
|
+
trace2.metrics.increment("dxos.mesh.signal.signal-rpc-client.close-failure", 1, {
|
|
721
312
|
tags: {
|
|
722
313
|
reason: params.failureReason
|
|
723
314
|
}
|
|
@@ -726,7 +317,7 @@ var SignalRpcClientMonitor = class {
|
|
|
726
317
|
};
|
|
727
318
|
|
|
728
319
|
// packages/core/mesh/messaging/src/signal-client/signal-rpc-client.ts
|
|
729
|
-
var
|
|
320
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-client/signal-rpc-client.ts";
|
|
730
321
|
var SIGNAL_KEEPALIVE_INTERVAL = 1e4;
|
|
731
322
|
var SignalRPCClient = class {
|
|
732
323
|
constructor({ url, callbacks = {} }) {
|
|
@@ -734,11 +325,11 @@ var SignalRPCClient = class {
|
|
|
734
325
|
this._closed = false;
|
|
735
326
|
this._closeComplete = new Trigger();
|
|
736
327
|
this._monitor = new SignalRpcClientMonitor();
|
|
737
|
-
const traceId =
|
|
738
|
-
|
|
328
|
+
const traceId = PublicKey2.random().toHex();
|
|
329
|
+
log2.trace("dxos.mesh.signal-rpc-client.constructor", trace3.begin({
|
|
739
330
|
id: traceId
|
|
740
331
|
}), {
|
|
741
|
-
F:
|
|
332
|
+
F: __dxlog_file2,
|
|
742
333
|
L: 61,
|
|
743
334
|
S: this,
|
|
744
335
|
C: (f, a) => f(...a)
|
|
@@ -748,7 +339,7 @@ var SignalRPCClient = class {
|
|
|
748
339
|
this._socket = new WebSocket(this._url);
|
|
749
340
|
this._rpc = createProtoRpcPeer({
|
|
750
341
|
requested: {
|
|
751
|
-
Signal:
|
|
342
|
+
Signal: schema.getService("dxos.mesh.signal.Signal")
|
|
752
343
|
},
|
|
753
344
|
noHandshake: true,
|
|
754
345
|
port: {
|
|
@@ -759,8 +350,8 @@ var SignalRPCClient = class {
|
|
|
759
350
|
try {
|
|
760
351
|
this._socket.send(msg);
|
|
761
352
|
} catch (err) {
|
|
762
|
-
|
|
763
|
-
F:
|
|
353
|
+
log2.warn("send error", err, {
|
|
354
|
+
F: __dxlog_file2,
|
|
764
355
|
L: 80,
|
|
765
356
|
S: this,
|
|
766
357
|
C: (f, a) => f(...a)
|
|
@@ -788,19 +379,19 @@ var SignalRPCClient = class {
|
|
|
788
379
|
await this._safeCloseRpc();
|
|
789
380
|
return;
|
|
790
381
|
}
|
|
791
|
-
|
|
792
|
-
F:
|
|
382
|
+
log2(`RPC open ${this._url}`, void 0, {
|
|
383
|
+
F: __dxlog_file2,
|
|
793
384
|
L: 105,
|
|
794
385
|
S: this,
|
|
795
386
|
C: (f, a) => f(...a)
|
|
796
387
|
});
|
|
797
388
|
this._callbacks.onConnected?.();
|
|
798
389
|
this._connectTrigger.wake();
|
|
799
|
-
this._keepaliveCtx = new
|
|
800
|
-
F:
|
|
390
|
+
this._keepaliveCtx = new Context(void 0, {
|
|
391
|
+
F: __dxlog_file2,
|
|
801
392
|
L: 108
|
|
802
393
|
});
|
|
803
|
-
|
|
394
|
+
scheduleTaskInterval(this._keepaliveCtx, async () => {
|
|
804
395
|
this._socket?.send("__ping__");
|
|
805
396
|
}, SIGNAL_KEEPALIVE_INTERVAL);
|
|
806
397
|
} catch (err) {
|
|
@@ -810,8 +401,8 @@ var SignalRPCClient = class {
|
|
|
810
401
|
}
|
|
811
402
|
};
|
|
812
403
|
this._socket.onclose = async () => {
|
|
813
|
-
|
|
814
|
-
F:
|
|
404
|
+
log2(`Disconnected ${this._url}`, void 0, {
|
|
405
|
+
F: __dxlog_file2,
|
|
815
406
|
L: 128,
|
|
816
407
|
S: this,
|
|
817
408
|
C: (f, a) => f(...a)
|
|
@@ -828,20 +419,20 @@ var SignalRPCClient = class {
|
|
|
828
419
|
this._closed = true;
|
|
829
420
|
this._callbacks.onError?.(event.error ?? new Error(event.message));
|
|
830
421
|
await this._safeCloseRpc();
|
|
831
|
-
|
|
422
|
+
log2.warn(`Socket ${event.type ?? "unknown"} error`, {
|
|
832
423
|
message: event.message,
|
|
833
424
|
url: this._url
|
|
834
425
|
}, {
|
|
835
|
-
F:
|
|
426
|
+
F: __dxlog_file2,
|
|
836
427
|
L: 144,
|
|
837
428
|
S: this,
|
|
838
429
|
C: (f, a) => f(...a)
|
|
839
430
|
});
|
|
840
431
|
};
|
|
841
|
-
|
|
432
|
+
log2.trace("dxos.mesh.signal-rpc-client.constructor", trace3.end({
|
|
842
433
|
id: traceId
|
|
843
434
|
}), {
|
|
844
|
-
F:
|
|
435
|
+
F: __dxlog_file2,
|
|
845
436
|
L: 147,
|
|
846
437
|
S: this,
|
|
847
438
|
C: (f, a) => f(...a)
|
|
@@ -862,25 +453,25 @@ var SignalRPCClient = class {
|
|
|
862
453
|
timeout: 1e3
|
|
863
454
|
});
|
|
864
455
|
} catch (err) {
|
|
865
|
-
const failureReason = err instanceof
|
|
456
|
+
const failureReason = err instanceof TimeoutError ? "timeout" : err?.constructor?.name ?? "unknown";
|
|
866
457
|
this._monitor.recordClientCloseFailure({
|
|
867
458
|
failureReason
|
|
868
459
|
});
|
|
869
460
|
}
|
|
870
461
|
}
|
|
871
462
|
async join({ topic, peerId }) {
|
|
872
|
-
|
|
463
|
+
log2("join", {
|
|
873
464
|
topic,
|
|
874
465
|
peerId,
|
|
875
466
|
metadata: this._callbacks?.getMetadata?.()
|
|
876
467
|
}, {
|
|
877
|
-
F:
|
|
468
|
+
F: __dxlog_file2,
|
|
878
469
|
L: 173,
|
|
879
470
|
S: this,
|
|
880
471
|
C: (f, a) => f(...a)
|
|
881
472
|
});
|
|
882
|
-
|
|
883
|
-
F:
|
|
473
|
+
invariant(!this._closed, "SignalRPCClient is closed", {
|
|
474
|
+
F: __dxlog_file2,
|
|
884
475
|
L: 174,
|
|
885
476
|
S: this,
|
|
886
477
|
A: [
|
|
@@ -898,16 +489,16 @@ var SignalRPCClient = class {
|
|
|
898
489
|
return swarmStream;
|
|
899
490
|
}
|
|
900
491
|
async receiveMessages(peerId) {
|
|
901
|
-
|
|
492
|
+
log2("receiveMessages", {
|
|
902
493
|
peerId
|
|
903
494
|
}, {
|
|
904
|
-
F:
|
|
495
|
+
F: __dxlog_file2,
|
|
905
496
|
L: 186,
|
|
906
497
|
S: this,
|
|
907
498
|
C: (f, a) => f(...a)
|
|
908
499
|
});
|
|
909
|
-
|
|
910
|
-
F:
|
|
500
|
+
invariant(!this._closed, "SignalRPCClient is closed", {
|
|
501
|
+
F: __dxlog_file2,
|
|
911
502
|
L: 187,
|
|
912
503
|
S: this,
|
|
913
504
|
A: [
|
|
@@ -923,19 +514,19 @@ var SignalRPCClient = class {
|
|
|
923
514
|
return messageStream;
|
|
924
515
|
}
|
|
925
516
|
async sendMessage({ author, recipient, payload }) {
|
|
926
|
-
|
|
517
|
+
log2("sendMessage", {
|
|
927
518
|
author,
|
|
928
519
|
recipient,
|
|
929
520
|
payload,
|
|
930
521
|
metadata: this._callbacks?.getMetadata?.()
|
|
931
522
|
}, {
|
|
932
|
-
F:
|
|
523
|
+
F: __dxlog_file2,
|
|
933
524
|
L: 197,
|
|
934
525
|
S: this,
|
|
935
526
|
C: (f, a) => f(...a)
|
|
936
527
|
});
|
|
937
|
-
|
|
938
|
-
F:
|
|
528
|
+
invariant(!this._closed, "SignalRPCClient is closed", {
|
|
529
|
+
F: __dxlog_file2,
|
|
939
530
|
L: 198,
|
|
940
531
|
S: this,
|
|
941
532
|
A: [
|
|
@@ -956,8 +547,8 @@ var SignalRPCClient = class {
|
|
|
956
547
|
this._connectTrigger.reset();
|
|
957
548
|
await this._rpc.close();
|
|
958
549
|
} catch (err) {
|
|
959
|
-
|
|
960
|
-
F:
|
|
550
|
+
log2.catch(err, void 0, {
|
|
551
|
+
F: __dxlog_file2,
|
|
961
552
|
L: 213,
|
|
962
553
|
S: this,
|
|
963
554
|
C: (f, a) => f(...a)
|
|
@@ -967,7 +558,7 @@ var SignalRPCClient = class {
|
|
|
967
558
|
};
|
|
968
559
|
|
|
969
560
|
// packages/core/mesh/messaging/src/signal-client/signal-client.ts
|
|
970
|
-
var
|
|
561
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-client/signal-client.ts";
|
|
971
562
|
var DEFAULT_RECONNECT_TIMEOUT = 100;
|
|
972
563
|
var MAX_RECONNECT_TIMEOUT = 5e3;
|
|
973
564
|
var ERROR_RECONCILE_DELAY = 1e3;
|
|
@@ -988,7 +579,7 @@ var SignalClient = class extends Resource {
|
|
|
988
579
|
this._lastReconciliationFailed = false;
|
|
989
580
|
this._clientReady = new Trigger2();
|
|
990
581
|
this._reconnectAfter = DEFAULT_RECONNECT_TIMEOUT;
|
|
991
|
-
this._instanceId =
|
|
582
|
+
this._instanceId = PublicKey3.random().toHex();
|
|
992
583
|
this.statusChanged = new Event2();
|
|
993
584
|
this.onMessage = new Event2();
|
|
994
585
|
this.swarmEvent = new Event2();
|
|
@@ -1001,10 +592,10 @@ var SignalClient = class extends Resource {
|
|
|
1001
592
|
}, async (event) => this.swarmEvent.emit(event));
|
|
1002
593
|
}
|
|
1003
594
|
async _open() {
|
|
1004
|
-
|
|
595
|
+
log3.trace("dxos.mesh.signal-client.open", trace4.begin({
|
|
1005
596
|
id: this._instanceId
|
|
1006
597
|
}), {
|
|
1007
|
-
F:
|
|
598
|
+
F: __dxlog_file3,
|
|
1008
599
|
L: 92,
|
|
1009
600
|
S: this,
|
|
1010
601
|
C: (f, a) => f(...a)
|
|
@@ -1021,8 +612,8 @@ var SignalClient = class extends Resource {
|
|
|
1021
612
|
await cancelWithContext2(this._connectionCtx, this._clientReady.wait({
|
|
1022
613
|
timeout: 5e3
|
|
1023
614
|
}));
|
|
1024
|
-
|
|
1025
|
-
F:
|
|
615
|
+
invariant2(this._state === SignalState.CONNECTED, "Not connected to Signal Server", {
|
|
616
|
+
F: __dxlog_file3,
|
|
1026
617
|
L: 102,
|
|
1027
618
|
S: this,
|
|
1028
619
|
A: [
|
|
@@ -1043,7 +634,7 @@ var SignalClient = class extends Resource {
|
|
|
1043
634
|
throw err;
|
|
1044
635
|
}
|
|
1045
636
|
});
|
|
1046
|
-
|
|
637
|
+
scheduleTaskInterval2(this._ctx, async () => {
|
|
1047
638
|
if (this._state === SignalState.CONNECTED) {
|
|
1048
639
|
this._reconcileTask.schedule();
|
|
1049
640
|
}
|
|
@@ -1062,10 +653,10 @@ var SignalClient = class extends Resource {
|
|
|
1062
653
|
}
|
|
1063
654
|
});
|
|
1064
655
|
this._createClient();
|
|
1065
|
-
|
|
656
|
+
log3.trace("dxos.mesh.signal-client.open", trace4.end({
|
|
1066
657
|
id: this._instanceId
|
|
1067
658
|
}), {
|
|
1068
|
-
F:
|
|
659
|
+
F: __dxlog_file3,
|
|
1069
660
|
L: 135,
|
|
1070
661
|
S: this,
|
|
1071
662
|
C: (f, a) => f(...a)
|
|
@@ -1076,8 +667,8 @@ var SignalClient = class extends Resource {
|
|
|
1076
667
|
return;
|
|
1077
668
|
}
|
|
1078
669
|
if (this._state === SignalState.CONNECTED && !this._lastReconciliationFailed) {
|
|
1079
|
-
|
|
1080
|
-
F:
|
|
670
|
+
log3.warn("SignalClient error:", err, {
|
|
671
|
+
F: __dxlog_file3,
|
|
1081
672
|
L: 144,
|
|
1082
673
|
S: this,
|
|
1083
674
|
C: (f, a) => f(...a)
|
|
@@ -1086,8 +677,8 @@ var SignalClient = class extends Resource {
|
|
|
1086
677
|
this._scheduleReconcileAfterError();
|
|
1087
678
|
}
|
|
1088
679
|
async _close() {
|
|
1089
|
-
|
|
1090
|
-
F:
|
|
680
|
+
log3("closing...", void 0, {
|
|
681
|
+
F: __dxlog_file3,
|
|
1091
682
|
L: 150,
|
|
1092
683
|
S: this,
|
|
1093
684
|
C: (f, a) => f(...a)
|
|
@@ -1099,8 +690,8 @@ var SignalClient = class extends Resource {
|
|
|
1099
690
|
}
|
|
1100
691
|
this._setState(SignalState.CLOSED);
|
|
1101
692
|
await this._safeResetClient();
|
|
1102
|
-
|
|
1103
|
-
F:
|
|
693
|
+
log3("closed", void 0, {
|
|
694
|
+
F: __dxlog_file3,
|
|
1104
695
|
L: 158,
|
|
1105
696
|
S: this,
|
|
1106
697
|
C: (f, a) => f(...a)
|
|
@@ -1116,11 +707,11 @@ var SignalClient = class extends Resource {
|
|
|
1116
707
|
};
|
|
1117
708
|
}
|
|
1118
709
|
async join(args) {
|
|
1119
|
-
|
|
710
|
+
log3("joining", {
|
|
1120
711
|
topic: args.topic,
|
|
1121
712
|
peerId: args.peer.peerKey
|
|
1122
713
|
}, {
|
|
1123
|
-
F:
|
|
714
|
+
F: __dxlog_file3,
|
|
1124
715
|
L: 172,
|
|
1125
716
|
S: this,
|
|
1126
717
|
C: (f, a) => f(...a)
|
|
@@ -1128,16 +719,16 @@ var SignalClient = class extends Resource {
|
|
|
1128
719
|
this._monitor.recordJoin();
|
|
1129
720
|
this.localState.join({
|
|
1130
721
|
topic: args.topic,
|
|
1131
|
-
peerId:
|
|
722
|
+
peerId: PublicKey3.from(args.peer.peerKey)
|
|
1132
723
|
});
|
|
1133
724
|
this._reconcileTask?.schedule();
|
|
1134
725
|
}
|
|
1135
726
|
async leave(args) {
|
|
1136
|
-
|
|
727
|
+
log3("leaving", {
|
|
1137
728
|
topic: args.topic,
|
|
1138
729
|
peerId: args.peer.peerKey
|
|
1139
730
|
}, {
|
|
1140
|
-
F:
|
|
731
|
+
F: __dxlog_file3,
|
|
1141
732
|
L: 179,
|
|
1142
733
|
S: this,
|
|
1143
734
|
C: (f, a) => f(...a)
|
|
@@ -1145,14 +736,14 @@ var SignalClient = class extends Resource {
|
|
|
1145
736
|
this._monitor.recordLeave();
|
|
1146
737
|
this.localState.leave({
|
|
1147
738
|
topic: args.topic,
|
|
1148
|
-
peerId:
|
|
739
|
+
peerId: PublicKey3.from(args.peer.peerKey)
|
|
1149
740
|
});
|
|
1150
741
|
}
|
|
1151
742
|
async sendMessage(msg) {
|
|
1152
743
|
return this._monitor.recordMessageSending(msg, async () => {
|
|
1153
744
|
await this._clientReady.wait();
|
|
1154
|
-
|
|
1155
|
-
F:
|
|
745
|
+
invariant2(this._state === SignalState.CONNECTED, "Not connected to Signal Server", {
|
|
746
|
+
F: __dxlog_file3,
|
|
1156
747
|
L: 187,
|
|
1157
748
|
S: this,
|
|
1158
749
|
A: [
|
|
@@ -1160,8 +751,8 @@ var SignalClient = class extends Resource {
|
|
|
1160
751
|
"'Not connected to Signal Server'"
|
|
1161
752
|
]
|
|
1162
753
|
});
|
|
1163
|
-
|
|
1164
|
-
F:
|
|
754
|
+
invariant2(msg.author.peerKey, "Author key required", {
|
|
755
|
+
F: __dxlog_file3,
|
|
1165
756
|
L: 188,
|
|
1166
757
|
S: this,
|
|
1167
758
|
A: [
|
|
@@ -1169,8 +760,8 @@ var SignalClient = class extends Resource {
|
|
|
1169
760
|
"'Author key required'"
|
|
1170
761
|
]
|
|
1171
762
|
});
|
|
1172
|
-
|
|
1173
|
-
F:
|
|
763
|
+
invariant2(msg.recipient.peerKey, "Recipient key required", {
|
|
764
|
+
F: __dxlog_file3,
|
|
1174
765
|
L: 189,
|
|
1175
766
|
S: this,
|
|
1176
767
|
A: [
|
|
@@ -1179,15 +770,15 @@ var SignalClient = class extends Resource {
|
|
|
1179
770
|
]
|
|
1180
771
|
});
|
|
1181
772
|
await this._client.sendMessage({
|
|
1182
|
-
author:
|
|
1183
|
-
recipient:
|
|
773
|
+
author: PublicKey3.from(msg.author.peerKey),
|
|
774
|
+
recipient: PublicKey3.from(msg.recipient.peerKey),
|
|
1184
775
|
payload: msg.payload
|
|
1185
776
|
});
|
|
1186
777
|
});
|
|
1187
778
|
}
|
|
1188
779
|
async subscribeMessages(peer) {
|
|
1189
|
-
|
|
1190
|
-
F:
|
|
780
|
+
invariant2(peer.peerKey, "Peer key required", {
|
|
781
|
+
F: __dxlog_file3,
|
|
1191
782
|
L: 199,
|
|
1192
783
|
S: this,
|
|
1193
784
|
A: [
|
|
@@ -1195,20 +786,20 @@ var SignalClient = class extends Resource {
|
|
|
1195
786
|
"'Peer key required'"
|
|
1196
787
|
]
|
|
1197
788
|
});
|
|
1198
|
-
|
|
789
|
+
log3("subscribing to messages", {
|
|
1199
790
|
peer
|
|
1200
791
|
}, {
|
|
1201
|
-
F:
|
|
792
|
+
F: __dxlog_file3,
|
|
1202
793
|
L: 200,
|
|
1203
794
|
S: this,
|
|
1204
795
|
C: (f, a) => f(...a)
|
|
1205
796
|
});
|
|
1206
|
-
this.localState.subscribeMessages(
|
|
797
|
+
this.localState.subscribeMessages(PublicKey3.from(peer.peerKey));
|
|
1207
798
|
this._reconcileTask?.schedule();
|
|
1208
799
|
}
|
|
1209
800
|
async unsubscribeMessages(peer) {
|
|
1210
|
-
|
|
1211
|
-
F:
|
|
801
|
+
invariant2(peer.peerKey, "Peer key required", {
|
|
802
|
+
F: __dxlog_file3,
|
|
1212
803
|
L: 206,
|
|
1213
804
|
S: this,
|
|
1214
805
|
A: [
|
|
@@ -1216,31 +807,31 @@ var SignalClient = class extends Resource {
|
|
|
1216
807
|
"'Peer key required'"
|
|
1217
808
|
]
|
|
1218
809
|
});
|
|
1219
|
-
|
|
810
|
+
log3("unsubscribing from messages", {
|
|
1220
811
|
peer
|
|
1221
812
|
}, {
|
|
1222
|
-
F:
|
|
813
|
+
F: __dxlog_file3,
|
|
1223
814
|
L: 207,
|
|
1224
815
|
S: this,
|
|
1225
816
|
C: (f, a) => f(...a)
|
|
1226
817
|
});
|
|
1227
|
-
this.localState.unsubscribeMessages(
|
|
818
|
+
this.localState.unsubscribeMessages(PublicKey3.from(peer.peerKey));
|
|
1228
819
|
}
|
|
1229
820
|
_scheduleReconcileAfterError() {
|
|
1230
|
-
|
|
821
|
+
scheduleTask(this._ctx, () => this._reconcileTask.schedule(), ERROR_RECONCILE_DELAY);
|
|
1231
822
|
}
|
|
1232
823
|
_createClient() {
|
|
1233
|
-
|
|
824
|
+
log3("creating client", {
|
|
1234
825
|
host: this._host,
|
|
1235
826
|
state: this._state
|
|
1236
827
|
}, {
|
|
1237
|
-
F:
|
|
828
|
+
F: __dxlog_file3,
|
|
1238
829
|
L: 216,
|
|
1239
830
|
S: this,
|
|
1240
831
|
C: (f, a) => f(...a)
|
|
1241
832
|
});
|
|
1242
|
-
|
|
1243
|
-
F:
|
|
833
|
+
invariant2(!this._client, "Client already created", {
|
|
834
|
+
F: __dxlog_file3,
|
|
1244
835
|
L: 217,
|
|
1245
836
|
S: this,
|
|
1246
837
|
A: [
|
|
@@ -1251,8 +842,8 @@ var SignalClient = class extends Resource {
|
|
|
1251
842
|
this._monitor.recordConnectionStartTime();
|
|
1252
843
|
this._connectionCtx = this._ctx.derive();
|
|
1253
844
|
this._connectionCtx.onDispose(async () => {
|
|
1254
|
-
|
|
1255
|
-
F:
|
|
845
|
+
log3("connection context disposed", void 0, {
|
|
846
|
+
F: __dxlog_file3,
|
|
1256
847
|
L: 224,
|
|
1257
848
|
S: this,
|
|
1258
849
|
C: (f, a) => f(...a)
|
|
@@ -1266,8 +857,8 @@ var SignalClient = class extends Resource {
|
|
|
1266
857
|
callbacks: {
|
|
1267
858
|
onConnected: () => {
|
|
1268
859
|
if (client === this._client) {
|
|
1269
|
-
|
|
1270
|
-
F:
|
|
860
|
+
log3("socket connected", void 0, {
|
|
861
|
+
F: __dxlog_file3,
|
|
1271
862
|
L: 235,
|
|
1272
863
|
S: this,
|
|
1273
864
|
C: (f, a) => f(...a)
|
|
@@ -1279,10 +870,10 @@ var SignalClient = class extends Resource {
|
|
|
1279
870
|
if (client !== this._client) {
|
|
1280
871
|
return;
|
|
1281
872
|
}
|
|
1282
|
-
|
|
873
|
+
log3("socket disconnected", {
|
|
1283
874
|
state: this._state
|
|
1284
875
|
}, {
|
|
1285
|
-
F:
|
|
876
|
+
F: __dxlog_file3,
|
|
1286
877
|
L: 244,
|
|
1287
878
|
S: this,
|
|
1288
879
|
C: (f, a) => f(...a)
|
|
@@ -1295,11 +886,11 @@ var SignalClient = class extends Resource {
|
|
|
1295
886
|
},
|
|
1296
887
|
onError: (error) => {
|
|
1297
888
|
if (client === this._client) {
|
|
1298
|
-
|
|
889
|
+
log3("socket error", {
|
|
1299
890
|
error,
|
|
1300
891
|
state: this._state
|
|
1301
892
|
}, {
|
|
1302
|
-
F:
|
|
893
|
+
F: __dxlog_file3,
|
|
1303
894
|
L: 256,
|
|
1304
895
|
S: this,
|
|
1305
896
|
C: (f, a) => f(...a)
|
|
@@ -1321,17 +912,17 @@ var SignalClient = class extends Resource {
|
|
|
1321
912
|
}
|
|
1322
913
|
}
|
|
1323
914
|
async _reconnect() {
|
|
1324
|
-
|
|
915
|
+
log3(`reconnecting in ${this._reconnectAfter}ms`, {
|
|
1325
916
|
state: this._state
|
|
1326
917
|
}, {
|
|
1327
|
-
F:
|
|
918
|
+
F: __dxlog_file3,
|
|
1328
919
|
L: 271,
|
|
1329
920
|
S: this,
|
|
1330
921
|
C: (f, a) => f(...a)
|
|
1331
922
|
});
|
|
1332
923
|
if (this._state === SignalState.RECONNECTING) {
|
|
1333
|
-
|
|
1334
|
-
F:
|
|
924
|
+
log3.info("Signal api already reconnecting.", void 0, {
|
|
925
|
+
F: __dxlog_file3,
|
|
1335
926
|
L: 274,
|
|
1336
927
|
S: this,
|
|
1337
928
|
C: (f, a) => f(...a)
|
|
@@ -1370,10 +961,10 @@ var SignalClient = class extends Resource {
|
|
|
1370
961
|
_setState(newState) {
|
|
1371
962
|
this._state = newState;
|
|
1372
963
|
this._monitor.recordStateChangeTime();
|
|
1373
|
-
|
|
964
|
+
log3("signal state changed", {
|
|
1374
965
|
status: this.getStatus()
|
|
1375
966
|
}, {
|
|
1376
|
-
F:
|
|
967
|
+
F: __dxlog_file3,
|
|
1377
968
|
L: 315,
|
|
1378
969
|
S: this,
|
|
1379
970
|
C: (f, a) => f(...a)
|
|
@@ -1396,290 +987,23 @@ var SignalClient = class extends Resource {
|
|
|
1396
987
|
}
|
|
1397
988
|
};
|
|
1398
989
|
|
|
1399
|
-
// packages/core/mesh/messaging/src/signal-manager/memory-signal-manager.ts
|
|
1400
|
-
import { Event as Event3, Trigger as Trigger3 } from "@dxos/async";
|
|
1401
|
-
import { Context as Context3 } from "@dxos/context";
|
|
1402
|
-
import { invariant as invariant4 } from "@dxos/invariant";
|
|
1403
|
-
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1404
|
-
import { log as log5 } from "@dxos/log";
|
|
1405
|
-
import { schema as schema3 } from "@dxos/protocols/proto";
|
|
1406
|
-
import { ComplexMap as ComplexMap3, ComplexSet as ComplexSet3 } from "@dxos/util";
|
|
1407
|
-
|
|
1408
|
-
// packages/core/mesh/messaging/src/signal-methods.ts
|
|
1409
|
-
var PeerInfoHash = ({ peerKey }) => peerKey;
|
|
1410
|
-
|
|
1411
|
-
// packages/core/mesh/messaging/src/signal-manager/memory-signal-manager.ts
|
|
1412
|
-
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-manager/memory-signal-manager.ts";
|
|
1413
|
-
var MemorySignalManagerContext = class {
|
|
1414
|
-
constructor() {
|
|
1415
|
-
// Swarm messages.
|
|
1416
|
-
this.swarmEvent = new Event3();
|
|
1417
|
-
// Mapping from topic to set of peers.
|
|
1418
|
-
this.swarms = new ComplexMap3(PublicKey5.hash);
|
|
1419
|
-
// Map of connections for each peer for signaling.
|
|
1420
|
-
this.connections = new ComplexMap3(PeerInfoHash);
|
|
1421
|
-
}
|
|
1422
|
-
};
|
|
1423
|
-
var MemorySignalManager = class {
|
|
1424
|
-
constructor(_context) {
|
|
1425
|
-
this._context = _context;
|
|
1426
|
-
this.statusChanged = new Event3();
|
|
1427
|
-
this.swarmEvent = new Event3();
|
|
1428
|
-
this.onMessage = new Event3();
|
|
1429
|
-
this._joinedSwarms = new ComplexSet3(({ topic, peer }) => topic.toHex() + peer.peerKey);
|
|
1430
|
-
this._freezeTrigger = new Trigger3().wake();
|
|
1431
|
-
this._ctx = new Context3(void 0, {
|
|
1432
|
-
F: __dxlog_file5,
|
|
1433
|
-
L: 51
|
|
1434
|
-
});
|
|
1435
|
-
this._ctx.onDispose(this._context.swarmEvent.on((data) => this.swarmEvent.emit(data)));
|
|
1436
|
-
}
|
|
1437
|
-
async open() {
|
|
1438
|
-
if (!this._ctx.disposed) {
|
|
1439
|
-
return;
|
|
1440
|
-
}
|
|
1441
|
-
this._ctx = new Context3(void 0, {
|
|
1442
|
-
F: __dxlog_file5,
|
|
1443
|
-
L: 60
|
|
1444
|
-
});
|
|
1445
|
-
this._ctx.onDispose(this._context.swarmEvent.on((data) => this.swarmEvent.emit(data)));
|
|
1446
|
-
await Promise.all([
|
|
1447
|
-
...this._joinedSwarms.values()
|
|
1448
|
-
].map((value) => this.join(value)));
|
|
1449
|
-
}
|
|
1450
|
-
async close() {
|
|
1451
|
-
if (this._ctx.disposed) {
|
|
1452
|
-
return;
|
|
1453
|
-
}
|
|
1454
|
-
const joinedSwarmsCopy = new ComplexSet3(({ topic, peer }) => topic.toHex() + peer.peerKey, [
|
|
1455
|
-
...this._joinedSwarms.values()
|
|
1456
|
-
]);
|
|
1457
|
-
await Promise.all([
|
|
1458
|
-
...this._joinedSwarms.values()
|
|
1459
|
-
].map((value) => this.leave(value)));
|
|
1460
|
-
this._joinedSwarms = joinedSwarmsCopy;
|
|
1461
|
-
await this._ctx.dispose();
|
|
1462
|
-
}
|
|
1463
|
-
getStatus() {
|
|
1464
|
-
return [];
|
|
1465
|
-
}
|
|
1466
|
-
async join({ topic, peer }) {
|
|
1467
|
-
invariant4(!this._ctx.disposed, "Closed", {
|
|
1468
|
-
F: __dxlog_file5,
|
|
1469
|
-
L: 89,
|
|
1470
|
-
S: this,
|
|
1471
|
-
A: [
|
|
1472
|
-
"!this._ctx.disposed",
|
|
1473
|
-
"'Closed'"
|
|
1474
|
-
]
|
|
1475
|
-
});
|
|
1476
|
-
this._joinedSwarms.add({
|
|
1477
|
-
topic,
|
|
1478
|
-
peer
|
|
1479
|
-
});
|
|
1480
|
-
if (!this._context.swarms.has(topic)) {
|
|
1481
|
-
this._context.swarms.set(topic, new ComplexSet3(PeerInfoHash));
|
|
1482
|
-
}
|
|
1483
|
-
this._context.swarms.get(topic).add(peer);
|
|
1484
|
-
this._context.swarmEvent.emit({
|
|
1485
|
-
topic,
|
|
1486
|
-
peerAvailable: {
|
|
1487
|
-
peer,
|
|
1488
|
-
since: /* @__PURE__ */ new Date()
|
|
1489
|
-
}
|
|
1490
|
-
});
|
|
1491
|
-
for (const [topic2, peers] of this._context.swarms) {
|
|
1492
|
-
Array.from(peers).forEach((peer2) => {
|
|
1493
|
-
this.swarmEvent.emit({
|
|
1494
|
-
topic: topic2,
|
|
1495
|
-
peerAvailable: {
|
|
1496
|
-
peer: peer2,
|
|
1497
|
-
since: /* @__PURE__ */ new Date()
|
|
1498
|
-
}
|
|
1499
|
-
});
|
|
1500
|
-
});
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
async leave({ topic, peer }) {
|
|
1504
|
-
invariant4(!this._ctx.disposed, "Closed", {
|
|
1505
|
-
F: __dxlog_file5,
|
|
1506
|
-
L: 121,
|
|
1507
|
-
S: this,
|
|
1508
|
-
A: [
|
|
1509
|
-
"!this._ctx.disposed",
|
|
1510
|
-
"'Closed'"
|
|
1511
|
-
]
|
|
1512
|
-
});
|
|
1513
|
-
this._joinedSwarms.delete({
|
|
1514
|
-
topic,
|
|
1515
|
-
peer
|
|
1516
|
-
});
|
|
1517
|
-
if (!this._context.swarms.has(topic)) {
|
|
1518
|
-
this._context.swarms.set(topic, new ComplexSet3(PeerInfoHash));
|
|
1519
|
-
}
|
|
1520
|
-
this._context.swarms.get(topic).delete(peer);
|
|
1521
|
-
const swarmEvent = {
|
|
1522
|
-
topic,
|
|
1523
|
-
peerLeft: {
|
|
1524
|
-
peer
|
|
1525
|
-
}
|
|
1526
|
-
};
|
|
1527
|
-
this._context.swarmEvent.emit(swarmEvent);
|
|
1528
|
-
}
|
|
1529
|
-
async sendMessage({ author, recipient, payload }) {
|
|
1530
|
-
log5("send message", {
|
|
1531
|
-
author,
|
|
1532
|
-
recipient,
|
|
1533
|
-
...dec(payload)
|
|
1534
|
-
}, {
|
|
1535
|
-
F: __dxlog_file5,
|
|
1536
|
-
L: 142,
|
|
1537
|
-
S: this,
|
|
1538
|
-
C: (f, a) => f(...a)
|
|
1539
|
-
});
|
|
1540
|
-
invariant4(recipient, void 0, {
|
|
1541
|
-
F: __dxlog_file5,
|
|
1542
|
-
L: 144,
|
|
1543
|
-
S: this,
|
|
1544
|
-
A: [
|
|
1545
|
-
"recipient",
|
|
1546
|
-
""
|
|
1547
|
-
]
|
|
1548
|
-
});
|
|
1549
|
-
invariant4(!this._ctx.disposed, "Closed", {
|
|
1550
|
-
F: __dxlog_file5,
|
|
1551
|
-
L: 145,
|
|
1552
|
-
S: this,
|
|
1553
|
-
A: [
|
|
1554
|
-
"!this._ctx.disposed",
|
|
1555
|
-
"'Closed'"
|
|
1556
|
-
]
|
|
1557
|
-
});
|
|
1558
|
-
await this._freezeTrigger.wait();
|
|
1559
|
-
const remote = this._context.connections.get(recipient);
|
|
1560
|
-
if (!remote) {
|
|
1561
|
-
log5.warn("recipient is not subscribed for messages", {
|
|
1562
|
-
author,
|
|
1563
|
-
recipient
|
|
1564
|
-
}, {
|
|
1565
|
-
F: __dxlog_file5,
|
|
1566
|
-
L: 151,
|
|
1567
|
-
S: this,
|
|
1568
|
-
C: (f, a) => f(...a)
|
|
1569
|
-
});
|
|
1570
|
-
return;
|
|
1571
|
-
}
|
|
1572
|
-
if (remote._ctx.disposed) {
|
|
1573
|
-
log5.warn("recipient is disposed", {
|
|
1574
|
-
author,
|
|
1575
|
-
recipient
|
|
1576
|
-
}, {
|
|
1577
|
-
F: __dxlog_file5,
|
|
1578
|
-
L: 156,
|
|
1579
|
-
S: this,
|
|
1580
|
-
C: (f, a) => f(...a)
|
|
1581
|
-
});
|
|
1582
|
-
return;
|
|
1583
|
-
}
|
|
1584
|
-
remote._freezeTrigger.wait().then(() => {
|
|
1585
|
-
if (remote._ctx.disposed) {
|
|
1586
|
-
log5.warn("recipient is disposed", {
|
|
1587
|
-
author,
|
|
1588
|
-
recipient
|
|
1589
|
-
}, {
|
|
1590
|
-
F: __dxlog_file5,
|
|
1591
|
-
L: 164,
|
|
1592
|
-
S: this,
|
|
1593
|
-
C: (f, a) => f(...a)
|
|
1594
|
-
});
|
|
1595
|
-
return;
|
|
1596
|
-
}
|
|
1597
|
-
log5("receive message", {
|
|
1598
|
-
author,
|
|
1599
|
-
recipient,
|
|
1600
|
-
...dec(payload)
|
|
1601
|
-
}, {
|
|
1602
|
-
F: __dxlog_file5,
|
|
1603
|
-
L: 168,
|
|
1604
|
-
S: this,
|
|
1605
|
-
C: (f, a) => f(...a)
|
|
1606
|
-
});
|
|
1607
|
-
remote.onMessage.emit({
|
|
1608
|
-
author,
|
|
1609
|
-
recipient,
|
|
1610
|
-
payload
|
|
1611
|
-
});
|
|
1612
|
-
}).catch((err) => {
|
|
1613
|
-
log5.error("error while waiting for freeze", {
|
|
1614
|
-
err
|
|
1615
|
-
}, {
|
|
1616
|
-
F: __dxlog_file5,
|
|
1617
|
-
L: 173,
|
|
1618
|
-
S: this,
|
|
1619
|
-
C: (f, a) => f(...a)
|
|
1620
|
-
});
|
|
1621
|
-
});
|
|
1622
|
-
}
|
|
1623
|
-
async subscribeMessages(peerInfo) {
|
|
1624
|
-
log5("subscribing", {
|
|
1625
|
-
peerInfo
|
|
1626
|
-
}, {
|
|
1627
|
-
F: __dxlog_file5,
|
|
1628
|
-
L: 178,
|
|
1629
|
-
S: this,
|
|
1630
|
-
C: (f, a) => f(...a)
|
|
1631
|
-
});
|
|
1632
|
-
this._context.connections.set(peerInfo, this);
|
|
1633
|
-
}
|
|
1634
|
-
async unsubscribeMessages(peerInfo) {
|
|
1635
|
-
log5("unsubscribing", {
|
|
1636
|
-
peerInfo
|
|
1637
|
-
}, {
|
|
1638
|
-
F: __dxlog_file5,
|
|
1639
|
-
L: 183,
|
|
1640
|
-
S: this,
|
|
1641
|
-
C: (f, a) => f(...a)
|
|
1642
|
-
});
|
|
1643
|
-
this._context.connections.delete(peerInfo);
|
|
1644
|
-
}
|
|
1645
|
-
freeze() {
|
|
1646
|
-
this._freezeTrigger.reset();
|
|
1647
|
-
}
|
|
1648
|
-
unfreeze() {
|
|
1649
|
-
this._freezeTrigger.wake();
|
|
1650
|
-
}
|
|
1651
|
-
};
|
|
1652
|
-
var dec = (payload) => {
|
|
1653
|
-
if (!payload.type_url.endsWith("ReliablePayload")) {
|
|
1654
|
-
return {};
|
|
1655
|
-
}
|
|
1656
|
-
const relPayload = schema3.getCodecForType("dxos.mesh.messaging.ReliablePayload").decode(payload.value);
|
|
1657
|
-
if (typeof relPayload?.payload?.data === "object") {
|
|
1658
|
-
return {
|
|
1659
|
-
payload: Object.keys(relPayload?.payload?.data)[0],
|
|
1660
|
-
sessionId: relPayload?.payload?.sessionId
|
|
1661
|
-
};
|
|
1662
|
-
}
|
|
1663
|
-
return {};
|
|
1664
|
-
};
|
|
1665
|
-
|
|
1666
990
|
// packages/core/mesh/messaging/src/signal-manager/websocket-signal-manager.ts
|
|
1667
|
-
import { Event as
|
|
991
|
+
import { Event as Event3, sleep as sleep2, synchronized } from "@dxos/async";
|
|
1668
992
|
import { LifecycleState, Resource as Resource2 } from "@dxos/context";
|
|
1669
|
-
import { invariant as
|
|
1670
|
-
import { PublicKey as
|
|
1671
|
-
import { log as
|
|
1672
|
-
import { RateLimitExceededError, TimeoutError as
|
|
993
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
994
|
+
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
995
|
+
import { log as log4 } from "@dxos/log";
|
|
996
|
+
import { RateLimitExceededError, TimeoutError as TimeoutError2, trace as trace6 } from "@dxos/protocols";
|
|
1673
997
|
import { BitField, safeAwaitAll as safeAwaitAll2 } from "@dxos/util";
|
|
1674
998
|
|
|
1675
999
|
// packages/core/mesh/messaging/src/signal-manager/websocket-signal-manager-monitor.ts
|
|
1676
|
-
import { trace as
|
|
1000
|
+
import { trace as trace5 } from "@dxos/tracing";
|
|
1677
1001
|
var WebsocketSignalManagerMonitor = class {
|
|
1678
1002
|
recordRateLimitExceeded() {
|
|
1679
|
-
|
|
1003
|
+
trace5.metrics.increment("dxos.mesh.signal.signal-manager.rate-limit-hit", 1);
|
|
1680
1004
|
}
|
|
1681
1005
|
recordServerFailure(params) {
|
|
1682
|
-
|
|
1006
|
+
trace5.metrics.increment("dxos.mesh.signal.signal-manager.server-failure", 1, {
|
|
1683
1007
|
tags: {
|
|
1684
1008
|
server: params.serverName,
|
|
1685
1009
|
restarted: params.willRestart
|
|
@@ -1695,7 +1019,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
1695
1019
|
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;
|
|
1696
1020
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1697
1021
|
}
|
|
1698
|
-
var
|
|
1022
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-manager/websocket-signal-manager.ts";
|
|
1699
1023
|
var MAX_SERVER_FAILURES = 5;
|
|
1700
1024
|
var WSS_SIGNAL_SERVER_REBOOT_DELAY = 3e3;
|
|
1701
1025
|
var WebsocketSignalManager = class extends Resource2 {
|
|
@@ -1706,14 +1030,14 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1706
1030
|
this._servers = /* @__PURE__ */ new Map();
|
|
1707
1031
|
this._monitor = new WebsocketSignalManagerMonitor();
|
|
1708
1032
|
this.failureCount = /* @__PURE__ */ new Map();
|
|
1709
|
-
this.statusChanged = new
|
|
1710
|
-
this.swarmEvent = new
|
|
1711
|
-
this.onMessage = new
|
|
1712
|
-
this._instanceId =
|
|
1713
|
-
|
|
1033
|
+
this.statusChanged = new Event3();
|
|
1034
|
+
this.swarmEvent = new Event3();
|
|
1035
|
+
this.onMessage = new Event3();
|
|
1036
|
+
this._instanceId = PublicKey4.random().toHex();
|
|
1037
|
+
log4("Created WebsocketSignalManager", {
|
|
1714
1038
|
hosts: this._hosts
|
|
1715
1039
|
}, {
|
|
1716
|
-
F:
|
|
1040
|
+
F: __dxlog_file4,
|
|
1717
1041
|
L: 54,
|
|
1718
1042
|
S: this,
|
|
1719
1043
|
C: (f, a) => f(...a)
|
|
@@ -1732,27 +1056,27 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1732
1056
|
this._failedServersBitfield = BitField.zeros(this._hosts.length);
|
|
1733
1057
|
}
|
|
1734
1058
|
async _open() {
|
|
1735
|
-
|
|
1059
|
+
log4("open signal manager", {
|
|
1736
1060
|
hosts: this._hosts
|
|
1737
1061
|
}, {
|
|
1738
|
-
F:
|
|
1062
|
+
F: __dxlog_file4,
|
|
1739
1063
|
L: 74,
|
|
1740
1064
|
S: this,
|
|
1741
1065
|
C: (f, a) => f(...a)
|
|
1742
1066
|
});
|
|
1743
|
-
|
|
1067
|
+
log4.trace("dxos.mesh.websocket-signal-manager.open", trace6.begin({
|
|
1744
1068
|
id: this._instanceId
|
|
1745
1069
|
}), {
|
|
1746
|
-
F:
|
|
1070
|
+
F: __dxlog_file4,
|
|
1747
1071
|
L: 75,
|
|
1748
1072
|
S: this,
|
|
1749
1073
|
C: (f, a) => f(...a)
|
|
1750
1074
|
});
|
|
1751
1075
|
await safeAwaitAll2(this._servers.values(), (server) => server.open());
|
|
1752
|
-
|
|
1076
|
+
log4.trace("dxos.mesh.websocket-signal-manager.open", trace6.end({
|
|
1753
1077
|
id: this._instanceId
|
|
1754
1078
|
}), {
|
|
1755
|
-
F:
|
|
1079
|
+
F: __dxlog_file4,
|
|
1756
1080
|
L: 79,
|
|
1757
1081
|
S: this,
|
|
1758
1082
|
C: (f, a) => f(...a)
|
|
@@ -1762,16 +1086,16 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1762
1086
|
await safeAwaitAll2(this._servers.values(), (server) => server.close());
|
|
1763
1087
|
}
|
|
1764
1088
|
async restartServer(serverName) {
|
|
1765
|
-
|
|
1089
|
+
log4("restarting server", {
|
|
1766
1090
|
serverName
|
|
1767
1091
|
}, {
|
|
1768
|
-
F:
|
|
1092
|
+
F: __dxlog_file4,
|
|
1769
1093
|
L: 87,
|
|
1770
1094
|
S: this,
|
|
1771
1095
|
C: (f, a) => f(...a)
|
|
1772
1096
|
});
|
|
1773
|
-
|
|
1774
|
-
F:
|
|
1097
|
+
invariant3(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
1098
|
+
F: __dxlog_file4,
|
|
1775
1099
|
L: 88,
|
|
1776
1100
|
S: this,
|
|
1777
1101
|
A: [
|
|
@@ -1780,8 +1104,8 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1780
1104
|
]
|
|
1781
1105
|
});
|
|
1782
1106
|
const server = this._servers.get(serverName);
|
|
1783
|
-
|
|
1784
|
-
F:
|
|
1107
|
+
invariant3(server, "server not found", {
|
|
1108
|
+
F: __dxlog_file4,
|
|
1785
1109
|
L: 91,
|
|
1786
1110
|
S: this,
|
|
1787
1111
|
A: [
|
|
@@ -1797,17 +1121,17 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1797
1121
|
return Array.from(this._servers.values()).map((server) => server.getStatus());
|
|
1798
1122
|
}
|
|
1799
1123
|
async join({ topic, peer }) {
|
|
1800
|
-
|
|
1124
|
+
log4("join", {
|
|
1801
1125
|
topic,
|
|
1802
1126
|
peer
|
|
1803
1127
|
}, {
|
|
1804
|
-
F:
|
|
1128
|
+
F: __dxlog_file4,
|
|
1805
1129
|
L: 104,
|
|
1806
1130
|
S: this,
|
|
1807
1131
|
C: (f, a) => f(...a)
|
|
1808
1132
|
});
|
|
1809
|
-
|
|
1810
|
-
F:
|
|
1133
|
+
invariant3(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
1134
|
+
F: __dxlog_file4,
|
|
1811
1135
|
L: 105,
|
|
1812
1136
|
S: this,
|
|
1813
1137
|
A: [
|
|
@@ -1821,17 +1145,17 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1821
1145
|
}));
|
|
1822
1146
|
}
|
|
1823
1147
|
async leave({ topic, peer }) {
|
|
1824
|
-
|
|
1148
|
+
log4("leaving", {
|
|
1825
1149
|
topic,
|
|
1826
1150
|
peer
|
|
1827
1151
|
}, {
|
|
1828
|
-
F:
|
|
1152
|
+
F: __dxlog_file4,
|
|
1829
1153
|
L: 111,
|
|
1830
1154
|
S: this,
|
|
1831
1155
|
C: (f, a) => f(...a)
|
|
1832
1156
|
});
|
|
1833
|
-
|
|
1834
|
-
F:
|
|
1157
|
+
invariant3(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
1158
|
+
F: __dxlog_file4,
|
|
1835
1159
|
L: 112,
|
|
1836
1160
|
S: this,
|
|
1837
1161
|
A: [
|
|
@@ -1845,16 +1169,16 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1845
1169
|
}));
|
|
1846
1170
|
}
|
|
1847
1171
|
async sendMessage({ author, recipient, payload }) {
|
|
1848
|
-
|
|
1172
|
+
log4("signal", {
|
|
1849
1173
|
recipient
|
|
1850
1174
|
}, {
|
|
1851
|
-
F:
|
|
1175
|
+
F: __dxlog_file4,
|
|
1852
1176
|
L: 117,
|
|
1853
1177
|
S: this,
|
|
1854
1178
|
C: (f, a) => f(...a)
|
|
1855
1179
|
});
|
|
1856
|
-
|
|
1857
|
-
F:
|
|
1180
|
+
invariant3(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
1181
|
+
F: __dxlog_file4,
|
|
1858
1182
|
L: 118,
|
|
1859
1183
|
S: this,
|
|
1860
1184
|
A: [
|
|
@@ -1869,30 +1193,30 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1869
1193
|
payload
|
|
1870
1194
|
}).then(() => this._clearServerFailedFlag(serverName, index)).catch((err) => {
|
|
1871
1195
|
if (err instanceof RateLimitExceededError) {
|
|
1872
|
-
|
|
1196
|
+
log4.info("WSS rate limit exceeded", {
|
|
1873
1197
|
err
|
|
1874
1198
|
}, {
|
|
1875
|
-
F:
|
|
1199
|
+
F: __dxlog_file4,
|
|
1876
1200
|
L: 126,
|
|
1877
1201
|
S: this,
|
|
1878
1202
|
C: (f, a) => f(...a)
|
|
1879
1203
|
});
|
|
1880
1204
|
this._monitor.recordRateLimitExceeded();
|
|
1881
|
-
} else if (err instanceof
|
|
1882
|
-
|
|
1205
|
+
} else if (err instanceof TimeoutError2 || err.constructor.name === "TimeoutError") {
|
|
1206
|
+
log4.info("WSS sendMessage timeout", {
|
|
1883
1207
|
err
|
|
1884
1208
|
}, {
|
|
1885
|
-
F:
|
|
1209
|
+
F: __dxlog_file4,
|
|
1886
1210
|
L: 129,
|
|
1887
1211
|
S: this,
|
|
1888
1212
|
C: (f, a) => f(...a)
|
|
1889
1213
|
});
|
|
1890
1214
|
void this.checkServerFailure(serverName, index);
|
|
1891
1215
|
} else {
|
|
1892
|
-
|
|
1216
|
+
log4.warn(`error sending to ${serverName}`, {
|
|
1893
1217
|
err
|
|
1894
1218
|
}, {
|
|
1895
|
-
F:
|
|
1219
|
+
F: __dxlog_file4,
|
|
1896
1220
|
L: 132,
|
|
1897
1221
|
S: this,
|
|
1898
1222
|
C: (f, a) => f(...a)
|
|
@@ -1911,11 +1235,11 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1911
1235
|
});
|
|
1912
1236
|
if (isRestartRequired) {
|
|
1913
1237
|
if (!BitField.get(this._failedServersBitfield, index)) {
|
|
1914
|
-
|
|
1238
|
+
log4.warn("too many failures for ws-server, restarting", {
|
|
1915
1239
|
serverName,
|
|
1916
1240
|
failureCount
|
|
1917
1241
|
}, {
|
|
1918
|
-
F:
|
|
1242
|
+
F: __dxlog_file4,
|
|
1919
1243
|
L: 146,
|
|
1920
1244
|
S: this,
|
|
1921
1245
|
C: (f, a) => f(...a)
|
|
@@ -1930,10 +1254,10 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1930
1254
|
}
|
|
1931
1255
|
_clearServerFailedFlag(serverName, index) {
|
|
1932
1256
|
if (BitField.get(this._failedServersBitfield, index)) {
|
|
1933
|
-
|
|
1257
|
+
log4.info("server connection restored", {
|
|
1934
1258
|
serverName
|
|
1935
1259
|
}, {
|
|
1936
|
-
F:
|
|
1260
|
+
F: __dxlog_file4,
|
|
1937
1261
|
L: 159,
|
|
1938
1262
|
S: this,
|
|
1939
1263
|
C: (f, a) => f(...a)
|
|
@@ -1943,16 +1267,16 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1943
1267
|
}
|
|
1944
1268
|
}
|
|
1945
1269
|
async subscribeMessages(peer) {
|
|
1946
|
-
|
|
1270
|
+
log4("subscribed for message stream", {
|
|
1947
1271
|
peer
|
|
1948
1272
|
}, {
|
|
1949
|
-
F:
|
|
1273
|
+
F: __dxlog_file4,
|
|
1950
1274
|
L: 166,
|
|
1951
1275
|
S: this,
|
|
1952
1276
|
C: (f, a) => f(...a)
|
|
1953
1277
|
});
|
|
1954
|
-
|
|
1955
|
-
F:
|
|
1278
|
+
invariant3(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
1279
|
+
F: __dxlog_file4,
|
|
1956
1280
|
L: 167,
|
|
1957
1281
|
S: this,
|
|
1958
1282
|
A: [
|
|
@@ -1963,16 +1287,16 @@ var WebsocketSignalManager = class extends Resource2 {
|
|
|
1963
1287
|
await this._forEachServer(async (server) => server.subscribeMessages(peer));
|
|
1964
1288
|
}
|
|
1965
1289
|
async unsubscribeMessages(peer) {
|
|
1966
|
-
|
|
1290
|
+
log4("subscribed for message stream", {
|
|
1967
1291
|
peer
|
|
1968
1292
|
}, {
|
|
1969
|
-
F:
|
|
1293
|
+
F: __dxlog_file4,
|
|
1970
1294
|
L: 173,
|
|
1971
1295
|
S: this,
|
|
1972
1296
|
C: (f, a) => f(...a)
|
|
1973
1297
|
});
|
|
1974
|
-
|
|
1975
|
-
F:
|
|
1298
|
+
invariant3(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
1299
|
+
F: __dxlog_file4,
|
|
1976
1300
|
L: 174,
|
|
1977
1301
|
S: this,
|
|
1978
1302
|
A: [
|
|
@@ -1997,27 +1321,27 @@ _ts_decorate([
|
|
|
1997
1321
|
], WebsocketSignalManager.prototype, "checkServerFailure", null);
|
|
1998
1322
|
|
|
1999
1323
|
// packages/core/mesh/messaging/src/signal-manager/edge-signal-manager.ts
|
|
2000
|
-
import {
|
|
2001
|
-
import { Event as Event5 } from "@dxos/async";
|
|
1324
|
+
import { Event as Event4 } from "@dxos/async";
|
|
2002
1325
|
import { Resource as Resource3 } from "@dxos/context";
|
|
2003
1326
|
import { protocol } from "@dxos/edge-client";
|
|
2004
|
-
import { invariant as
|
|
2005
|
-
import { PublicKey as
|
|
2006
|
-
import { log as
|
|
1327
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
1328
|
+
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1329
|
+
import { log as log5 } from "@dxos/log";
|
|
2007
1330
|
import { EdgeService } from "@dxos/protocols";
|
|
1331
|
+
import { bufWkt } from "@dxos/protocols/buf";
|
|
2008
1332
|
import { SwarmRequestSchema, SwarmRequest_Action as SwarmRequestAction, SwarmResponseSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
2009
|
-
import { ComplexMap as
|
|
2010
|
-
var
|
|
1333
|
+
import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet2 } from "@dxos/util";
|
|
1334
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-manager/edge-signal-manager.ts";
|
|
2011
1335
|
var EdgeSignalManager = class extends Resource3 {
|
|
2012
1336
|
constructor({ edgeConnection }) {
|
|
2013
1337
|
super();
|
|
2014
|
-
this.swarmEvent = new
|
|
2015
|
-
this.onMessage = new
|
|
1338
|
+
this.swarmEvent = new Event4();
|
|
1339
|
+
this.onMessage = new Event4();
|
|
2016
1340
|
/**
|
|
2017
1341
|
* swarm key -> peerKeys in the swarm
|
|
2018
1342
|
*/
|
|
2019
1343
|
// TODO(mykola): This class should not contain swarm state. Temporary before network-manager API changes to accept list of peers.
|
|
2020
|
-
this._swarmPeers = new
|
|
1344
|
+
this._swarmPeers = new ComplexMap2(PublicKey5.hash);
|
|
2021
1345
|
this._edgeConnection = edgeConnection;
|
|
2022
1346
|
}
|
|
2023
1347
|
async _open() {
|
|
@@ -2030,22 +1354,23 @@ var EdgeSignalManager = class extends Resource3 {
|
|
|
2030
1354
|
*/
|
|
2031
1355
|
async join({ topic, peer }) {
|
|
2032
1356
|
if (!this._matchSelfPeerInfo(peer)) {
|
|
2033
|
-
|
|
1357
|
+
log5.warn("ignoring peer info on join request", {
|
|
2034
1358
|
peer,
|
|
2035
1359
|
expected: {
|
|
2036
1360
|
peerKey: this._edgeConnection.peerKey,
|
|
2037
1361
|
identityKey: this._edgeConnection.identityKey
|
|
2038
1362
|
}
|
|
2039
1363
|
}, {
|
|
2040
|
-
F:
|
|
1364
|
+
F: __dxlog_file5,
|
|
2041
1365
|
L: 53,
|
|
2042
1366
|
S: this,
|
|
2043
1367
|
C: (f, a) => f(...a)
|
|
2044
1368
|
});
|
|
2045
1369
|
}
|
|
2046
|
-
this._swarmPeers.set(topic, new
|
|
1370
|
+
this._swarmPeers.set(topic, new ComplexSet2(PeerInfoHash));
|
|
2047
1371
|
await this._edgeConnection.send(protocol.createMessage(SwarmRequestSchema, {
|
|
2048
1372
|
serviceId: EdgeService.SWARM_SERVICE_ID,
|
|
1373
|
+
source: createMessageSource(topic, peer),
|
|
2049
1374
|
payload: {
|
|
2050
1375
|
action: SwarmRequestAction.JOIN,
|
|
2051
1376
|
swarmKeys: [
|
|
@@ -2058,6 +1383,7 @@ var EdgeSignalManager = class extends Resource3 {
|
|
|
2058
1383
|
this._swarmPeers.delete(topic);
|
|
2059
1384
|
await this._edgeConnection.send(protocol.createMessage(SwarmRequestSchema, {
|
|
2060
1385
|
serviceId: EdgeService.SWARM_SERVICE_ID,
|
|
1386
|
+
source: createMessageSource(topic, peer),
|
|
2061
1387
|
payload: {
|
|
2062
1388
|
action: SwarmRequestAction.LEAVE,
|
|
2063
1389
|
swarmKeys: [
|
|
@@ -2068,20 +1394,20 @@ var EdgeSignalManager = class extends Resource3 {
|
|
|
2068
1394
|
}
|
|
2069
1395
|
async sendMessage(message) {
|
|
2070
1396
|
if (!this._matchSelfPeerInfo(message.author)) {
|
|
2071
|
-
|
|
1397
|
+
log5.warn("ignoring author on send request", {
|
|
2072
1398
|
author: message.author,
|
|
2073
1399
|
expected: {
|
|
2074
1400
|
peerKey: this._edgeConnection.peerKey,
|
|
2075
1401
|
identityKey: this._edgeConnection.identityKey
|
|
2076
1402
|
}
|
|
2077
1403
|
}, {
|
|
2078
|
-
F:
|
|
2079
|
-
L:
|
|
1404
|
+
F: __dxlog_file5,
|
|
1405
|
+
L: 86,
|
|
2080
1406
|
S: this,
|
|
2081
1407
|
C: (f, a) => f(...a)
|
|
2082
1408
|
});
|
|
2083
1409
|
}
|
|
2084
|
-
await this._edgeConnection.send(protocol.createMessage(AnySchema, {
|
|
1410
|
+
await this._edgeConnection.send(protocol.createMessage(bufWkt.AnySchema, {
|
|
2085
1411
|
serviceId: EdgeService.SIGNAL_SERVICE_ID,
|
|
2086
1412
|
source: message.author,
|
|
2087
1413
|
target: [
|
|
@@ -2109,9 +1435,9 @@ var EdgeSignalManager = class extends Resource3 {
|
|
|
2109
1435
|
}
|
|
2110
1436
|
}
|
|
2111
1437
|
_processSwarmResponse(message) {
|
|
2112
|
-
|
|
2113
|
-
F:
|
|
2114
|
-
L:
|
|
1438
|
+
invariant4(protocol.getPayloadType(message) === SwarmResponseSchema.typeName, "Wrong payload type", {
|
|
1439
|
+
F: __dxlog_file5,
|
|
1440
|
+
L: 123,
|
|
2115
1441
|
S: this,
|
|
2116
1442
|
A: [
|
|
2117
1443
|
"protocol.getPayloadType(message) === SwarmResponseSchema.typeName",
|
|
@@ -2119,21 +1445,21 @@ var EdgeSignalManager = class extends Resource3 {
|
|
|
2119
1445
|
]
|
|
2120
1446
|
});
|
|
2121
1447
|
const payload = protocol.getPayload(message, SwarmResponseSchema);
|
|
2122
|
-
const topic =
|
|
1448
|
+
const topic = PublicKey5.from(payload.swarmKey);
|
|
2123
1449
|
if (!this._swarmPeers.has(topic)) {
|
|
2124
|
-
|
|
1450
|
+
log5.warn("Received message from wrong topic", {
|
|
2125
1451
|
topic
|
|
2126
1452
|
}, {
|
|
2127
|
-
F:
|
|
2128
|
-
L:
|
|
1453
|
+
F: __dxlog_file5,
|
|
1454
|
+
L: 127,
|
|
2129
1455
|
S: this,
|
|
2130
1456
|
C: (f, a) => f(...a)
|
|
2131
1457
|
});
|
|
2132
1458
|
return;
|
|
2133
1459
|
}
|
|
2134
1460
|
const oldPeers = this._swarmPeers.get(topic);
|
|
2135
|
-
const timestamp = new Date(Date.parse(message.timestamp));
|
|
2136
|
-
const newPeers = new
|
|
1461
|
+
const timestamp = message.timestamp ? new Date(Date.parse(message.timestamp)) : /* @__PURE__ */ new Date();
|
|
1462
|
+
const newPeers = new ComplexSet2(PeerInfoHash, payload.peers);
|
|
2137
1463
|
for (const peer of newPeers) {
|
|
2138
1464
|
if (oldPeers.has(peer)) {
|
|
2139
1465
|
continue;
|
|
@@ -2160,37 +1486,37 @@ var EdgeSignalManager = class extends Resource3 {
|
|
|
2160
1486
|
this._swarmPeers.set(topic, newPeers);
|
|
2161
1487
|
}
|
|
2162
1488
|
_processMessage(message) {
|
|
2163
|
-
|
|
2164
|
-
F:
|
|
2165
|
-
L:
|
|
1489
|
+
invariant4(protocol.getPayloadType(message) === bufWkt.AnySchema.typeName, "Wrong payload type", {
|
|
1490
|
+
F: __dxlog_file5,
|
|
1491
|
+
L: 160,
|
|
2166
1492
|
S: this,
|
|
2167
1493
|
A: [
|
|
2168
|
-
"protocol.getPayloadType(message) === AnySchema.typeName",
|
|
1494
|
+
"protocol.getPayloadType(message) === bufWkt.AnySchema.typeName",
|
|
2169
1495
|
"'Wrong payload type'"
|
|
2170
1496
|
]
|
|
2171
1497
|
});
|
|
2172
|
-
const payload = protocol.getPayload(message, AnySchema);
|
|
2173
|
-
|
|
2174
|
-
F:
|
|
2175
|
-
L:
|
|
1498
|
+
const payload = protocol.getPayload(message, bufWkt.AnySchema);
|
|
1499
|
+
invariant4(message.source, "source is missing", {
|
|
1500
|
+
F: __dxlog_file5,
|
|
1501
|
+
L: 162,
|
|
2176
1502
|
S: this,
|
|
2177
1503
|
A: [
|
|
2178
1504
|
"message.source",
|
|
2179
1505
|
"'source is missing'"
|
|
2180
1506
|
]
|
|
2181
1507
|
});
|
|
2182
|
-
|
|
2183
|
-
F:
|
|
2184
|
-
L:
|
|
1508
|
+
invariant4(message.target, "target is missing", {
|
|
1509
|
+
F: __dxlog_file5,
|
|
1510
|
+
L: 163,
|
|
2185
1511
|
S: this,
|
|
2186
1512
|
A: [
|
|
2187
1513
|
"message.target",
|
|
2188
1514
|
"'target is missing'"
|
|
2189
1515
|
]
|
|
2190
1516
|
});
|
|
2191
|
-
|
|
2192
|
-
F:
|
|
2193
|
-
L:
|
|
1517
|
+
invariant4(message.target.length === 1, "target should have exactly one item", {
|
|
1518
|
+
F: __dxlog_file5,
|
|
1519
|
+
L: 164,
|
|
2194
1520
|
S: this,
|
|
2195
1521
|
A: [
|
|
2196
1522
|
"message.target.length === 1",
|
|
@@ -2210,11 +1536,11 @@ var EdgeSignalManager = class extends Resource3 {
|
|
|
2210
1536
|
return peer && (peer.peerKey === this._edgeConnection.peerKey || peer.identityKey === this._edgeConnection.identityKey);
|
|
2211
1537
|
}
|
|
2212
1538
|
async _rejoinAllSwarms() {
|
|
2213
|
-
|
|
1539
|
+
log5("rejoin swarms", {
|
|
2214
1540
|
swarms: Array.from(this._swarmPeers.keys())
|
|
2215
1541
|
}, {
|
|
2216
|
-
F:
|
|
2217
|
-
L:
|
|
1542
|
+
F: __dxlog_file5,
|
|
1543
|
+
L: 183,
|
|
2218
1544
|
S: this,
|
|
2219
1545
|
C: (f, a) => f(...a)
|
|
2220
1546
|
});
|
|
@@ -2229,19 +1555,26 @@ var EdgeSignalManager = class extends Resource3 {
|
|
|
2229
1555
|
}
|
|
2230
1556
|
}
|
|
2231
1557
|
};
|
|
1558
|
+
var createMessageSource = (topic, peerInfo) => {
|
|
1559
|
+
return {
|
|
1560
|
+
swarmKey: topic.toHex(),
|
|
1561
|
+
identityKey: peerInfo.identityKey,
|
|
1562
|
+
peerKey: peerInfo.peerKey
|
|
1563
|
+
};
|
|
1564
|
+
};
|
|
2232
1565
|
|
|
2233
1566
|
// packages/core/mesh/messaging/src/signal-manager/utils.ts
|
|
2234
|
-
import { invariant as
|
|
2235
|
-
import { log as
|
|
1567
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1568
|
+
import { log as log6 } from "@dxos/log";
|
|
2236
1569
|
import { DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
|
|
2237
|
-
var
|
|
1570
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/messaging/src/signal-manager/utils.ts";
|
|
2238
1571
|
var setIdentityTags = ({ identityService, devicesService, setTag }) => {
|
|
2239
1572
|
identityService.queryIdentity().subscribe((idqr) => {
|
|
2240
1573
|
if (!idqr?.identity?.identityKey) {
|
|
2241
|
-
|
|
1574
|
+
log6("empty response from identity service", {
|
|
2242
1575
|
idqr
|
|
2243
1576
|
}, {
|
|
2244
|
-
F:
|
|
1577
|
+
F: __dxlog_file6,
|
|
2245
1578
|
L: 21,
|
|
2246
1579
|
S: void 0,
|
|
2247
1580
|
C: (f, a) => f(...a)
|
|
@@ -2252,18 +1585,18 @@ var setIdentityTags = ({ identityService, devicesService, setTag }) => {
|
|
|
2252
1585
|
});
|
|
2253
1586
|
devicesService.queryDevices().subscribe((dqr) => {
|
|
2254
1587
|
if (!dqr || !dqr.devices || dqr.devices.length === 0) {
|
|
2255
|
-
|
|
1588
|
+
log6("empty response from device service", {
|
|
2256
1589
|
device: dqr
|
|
2257
1590
|
}, {
|
|
2258
|
-
F:
|
|
1591
|
+
F: __dxlog_file6,
|
|
2259
1592
|
L: 30,
|
|
2260
1593
|
S: void 0,
|
|
2261
1594
|
C: (f, a) => f(...a)
|
|
2262
1595
|
});
|
|
2263
1596
|
return;
|
|
2264
1597
|
}
|
|
2265
|
-
|
|
2266
|
-
F:
|
|
1598
|
+
invariant5(dqr, "empty response from device service", {
|
|
1599
|
+
F: __dxlog_file6,
|
|
2267
1600
|
L: 33,
|
|
2268
1601
|
S: void 0,
|
|
2269
1602
|
A: [
|
|
@@ -2273,10 +1606,10 @@ var setIdentityTags = ({ identityService, devicesService, setTag }) => {
|
|
|
2273
1606
|
});
|
|
2274
1607
|
const thisDevice = dqr.devices.find((device) => device.kind === DeviceKind.CURRENT);
|
|
2275
1608
|
if (!thisDevice) {
|
|
2276
|
-
|
|
1609
|
+
log6("no current device", {
|
|
2277
1610
|
device: dqr
|
|
2278
1611
|
}, {
|
|
2279
|
-
F:
|
|
1612
|
+
F: __dxlog_file6,
|
|
2280
1613
|
L: 37,
|
|
2281
1614
|
S: void 0,
|
|
2282
1615
|
C: (f, a) => f(...a)
|