agent-comms 1.27.3 → 1.28.1

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.
Files changed (75) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +1 -1
  4. package/dist/core/comms-store.d.ts +4 -37
  5. package/dist/core/comms-store.d.ts.map +1 -1
  6. package/dist/core/comms-store.js +3 -3
  7. package/dist/core/handshake.d.ts +101 -0
  8. package/dist/core/handshake.d.ts.map +1 -0
  9. package/dist/core/handshake.js +276 -0
  10. package/dist/core/handshake.js.map +1 -0
  11. package/dist/core/mesh-store.d.ts +12 -3
  12. package/dist/core/mesh-store.d.ts.map +1 -1
  13. package/dist/core/mesh-store.js +54 -35
  14. package/dist/core/mesh-store.js.map +1 -1
  15. package/dist/core/store.d.ts +1 -27
  16. package/dist/core/store.d.ts.map +1 -1
  17. package/dist/core/store.js +0 -62
  18. package/dist/core/store.js.map +1 -1
  19. package/dist/core/tls-transport.d.ts +12 -9
  20. package/dist/core/tls-transport.d.ts.map +1 -1
  21. package/dist/core/tls-transport.js +96 -58
  22. package/dist/core/tls-transport.js.map +1 -1
  23. package/dist/core/tool.d.ts +34 -5
  24. package/dist/core/tool.d.ts.map +1 -1
  25. package/dist/core/tool.js +41 -0
  26. package/dist/core/tool.js.map +1 -1
  27. package/dist/core/wire-protocol.d.ts +21 -2
  28. package/dist/core/wire-protocol.d.ts.map +1 -1
  29. package/dist/core/wire-protocol.js +23 -2
  30. package/dist/core/wire-protocol.js.map +1 -1
  31. package/dist/test/approval.integration.test.js +320 -285
  32. package/dist/test/approval.integration.test.js.map +1 -1
  33. package/dist/test/become-coordinator-actual-port.integration.test.js +0 -19
  34. package/dist/test/become-coordinator-actual-port.integration.test.js.map +1 -1
  35. package/dist/test/coordinator-socket-error.integration.test.js +2 -0
  36. package/dist/test/coordinator-socket-error.integration.test.js.map +1 -1
  37. package/dist/test/delivery-receipt.helper.js +15 -0
  38. package/dist/test/delivery-receipt.helper.js.map +1 -1
  39. package/dist/test/downtime-replay.test.js +5 -2
  40. package/dist/test/downtime-replay.test.js.map +1 -1
  41. package/dist/test/federation.integration.test.js +2 -0
  42. package/dist/test/federation.integration.test.js.map +1 -1
  43. package/dist/test/handshake.test.d.ts +5 -0
  44. package/dist/test/handshake.test.d.ts.map +1 -0
  45. package/dist/test/handshake.test.js +196 -0
  46. package/dist/test/handshake.test.js.map +1 -0
  47. package/dist/test/listener-policy.integration.test.js +214 -158
  48. package/dist/test/listener-policy.integration.test.js.map +1 -1
  49. package/dist/test/mesh-e2e.integration.test.js +2 -0
  50. package/dist/test/mesh-e2e.integration.test.js.map +1 -1
  51. package/dist/test/mesh-smoke.integration.test.d.ts +2 -4
  52. package/dist/test/mesh-smoke.integration.test.d.ts.map +1 -1
  53. package/dist/test/mesh-smoke.integration.test.js +28 -5
  54. package/dist/test/mesh-smoke.integration.test.js.map +1 -1
  55. package/dist/test/state-sync-convergence.test.js +5 -2
  56. package/dist/test/state-sync-convergence.test.js.map +1 -1
  57. package/dist/test/test-transport.d.ts +8 -0
  58. package/dist/test/test-transport.d.ts.map +1 -0
  59. package/dist/test/test-transport.js +29 -0
  60. package/dist/test/test-transport.js.map +1 -0
  61. package/dist/test/visibility.integration.test.js +6 -0
  62. package/dist/test/visibility.integration.test.js.map +1 -1
  63. package/package.json +4 -2
  64. package/dist/core/tcp-transport.d.ts +0 -85
  65. package/dist/core/tcp-transport.d.ts.map +0 -1
  66. package/dist/core/tcp-transport.js +0 -659
  67. package/dist/core/tcp-transport.js.map +0 -1
  68. package/dist/core/ws-transport.d.ts +0 -79
  69. package/dist/core/ws-transport.d.ts.map +0 -1
  70. package/dist/core/ws-transport.js +0 -621
  71. package/dist/core/ws-transport.js.map +0 -1
  72. package/dist/test/ws-broadcast-window.integration.test.d.ts +0 -7
  73. package/dist/test/ws-broadcast-window.integration.test.d.ts.map +0 -1
  74. package/dist/test/ws-broadcast-window.integration.test.js +0 -94
  75. package/dist/test/ws-broadcast-window.integration.test.js.map +0 -1
@@ -1,621 +0,0 @@
1
- /**
2
- * WebSocketTransport — WebSocket transport for the peer mesh.
3
- *
4
- * Carries the same wire protocol as TcpTransport but over WebSocket frames.
5
- * Each WS frame is a complete JSON message — no newline delimiter or
6
- * MessageBuffer needed. This enables browser-based peers (PWAs) to
7
- * participate in the mesh.
8
- *
9
- * The transport is a drop-in replacement for TcpTransport. Same interface,
10
- * same wire protocol, same event callbacks. MeshStore cannot tell the
11
- * difference.
12
- */
13
- import { WebSocket, WebSocketServer } from "ws";
14
- import { isMeshMessage } from "./wire-protocol.js";
15
- // ---------------------------------------------------------------------------
16
- // Constants
17
- // ---------------------------------------------------------------------------
18
- /** Timeout for connecting to the coordinator before giving up. */
19
- const CONNECT_TIMEOUT_MS = 2000;
20
- // ---------------------------------------------------------------------------
21
- // Async WS send helper (not exported)
22
- // ---------------------------------------------------------------------------
23
- /**
24
- * Safety valve so a dial that never completes cannot grow its outbound queue
25
- * unbounded; oldest entries are dropped first (#23).
26
- */
27
- const MAX_PENDING_PER_PEER = 100;
28
- function sendAsync(ws, data) {
29
- return new Promise((resolve, reject) => {
30
- if (ws.readyState !== WebSocket.OPEN) {
31
- resolve();
32
- return;
33
- }
34
- ws.send(data, (err) => {
35
- if (err)
36
- reject(err);
37
- else
38
- resolve();
39
- });
40
- });
41
- }
42
- // ---------------------------------------------------------------------------
43
- // WebSocketTransport
44
- // ---------------------------------------------------------------------------
45
- export class WebSocketTransport {
46
- // -- Data server (accepts incoming peer data connections) --
47
- dataServer;
48
- _dataPort = 0;
49
- // -- Coordinator server (accepts introductions from new peers) --
50
- coordinatorServer;
51
- _isCoordinator = false;
52
- // -- Coordinator client socket (connection to the coordinator) --
53
- coordinatorWs;
54
- // -- Coordinator introduction handshake (resolved on the peer list) --
55
- resolveCoordinatorHandshake;
56
- coordinatorHandshakeTimer;
57
- // -- Peer data connections (peer ID → WebSocket) --
58
- peerConnections = new Map();
59
- // -- Messages queued for peers whose dial is still in flight (#23) --
60
- pendingOutbound = new Map();
61
- // -- All WS connections accepted by the data server (for shutdown cleanup) --
62
- dataServerSockets = new Set();
63
- // -- All WS connections accepted by the coordinator server (for shutdown cleanup) --
64
- coordinatorServerSockets = new Set();
65
- // -- Coordinator introduction connections (handle ID → WebSocket) --
66
- // Maps the introducing peer's ID to the coordinator server WS, so
67
- // MeshStore can send the peer_list response via transport.send().
68
- introConnections = new Map();
69
- // -- Pending connections awaiting approval (handle ID → WS + request info) --
70
- pendingConnections = new Map();
71
- // -- Shutdown sentinel — prevents callbacks after shutdown() --
72
- shutDown = false;
73
- // -- This peer's ID (set during connectToCoordinator or becomeCoordinator) --
74
- _peerId = "";
75
- events;
76
- constructor(events) {
77
- this.events = events;
78
- }
79
- // -- Public getters for interface properties --
80
- get dataPort() {
81
- return this._dataPort;
82
- }
83
- get isCoordinator() {
84
- return this._isCoordinator;
85
- }
86
- get hasCoordinatorConnection() {
87
- return this.coordinatorWs?.readyState === WebSocket.OPEN;
88
- }
89
- // -----------------------------------------------------------------------
90
- // MeshTransport — Data server
91
- // -----------------------------------------------------------------------
92
- async startDataServer() {
93
- await new Promise((resolve, reject) => {
94
- // WebSocketServer needs an underlying HTTP server to get an
95
- // OS-assigned port via port 0.
96
- this.dataServer = new WebSocketServer({ port: 0, host: "0.0.0.0" });
97
- this.dataServer.on("error", reject);
98
- this.dataServer.on("listening", () => {
99
- const addr = this.dataServer?.address();
100
- if (typeof addr === "object" && addr !== null) {
101
- this._dataPort = addr.port;
102
- }
103
- resolve();
104
- });
105
- this.dataServer.on("connection", (ws) => {
106
- this.handleIncomingDataConnection(ws);
107
- });
108
- });
109
- }
110
- // -----------------------------------------------------------------------
111
- // MeshTransport — Coordinator connection (client side)
112
- // -----------------------------------------------------------------------
113
- async connectToCoordinator(host, port, peerId, localDataPort) {
114
- this._peerId = peerId;
115
- await new Promise((resolve, reject) => {
116
- const url = `ws://${host}:${String(port)}`;
117
- const ws = new WebSocket(url);
118
- const timer = setTimeout(() => {
119
- ws.terminate();
120
- reject(new Error("Coordinator connection timeout"));
121
- }, CONNECT_TIMEOUT_MS);
122
- ws.on("unexpected-response", () => {
123
- clearTimeout(timer);
124
- ws.terminate();
125
- reject(new Error("Coordinator connection rejected"));
126
- });
127
- ws.on("open", () => {
128
- this.coordinatorWs = ws;
129
- // Send introduction
130
- const intro = {
131
- method: "introduce",
132
- peerId,
133
- dataPort: localDataPort,
134
- };
135
- ws.send(JSON.stringify(intro));
136
- // Wire up coordinator message handling
137
- ws.on("message", (raw) => {
138
- const msg = parseMessage(raw);
139
- if (msg !== undefined) {
140
- this.dispatchCoordinatorClientMessage(msg);
141
- }
142
- });
143
- ws.on("error", () => {
144
- /* ignore late errors on coordinator connection */
145
- });
146
- clearTimeout(timer);
147
- // Resolve on the coordinator's peer list rather than on sending the
148
- // introduction: MeshStore.init() then returns only after the post-join
149
- // peer dials have started, so the first broadcasts are queued for the
150
- // dialling peers instead of dropped (#23). A timeout keeps today's
151
- // degraded behaviour for a coordinator that never answers.
152
- this.resolveCoordinatorHandshake = resolve;
153
- this.coordinatorHandshakeTimer = setTimeout(() => {
154
- this.resolveCoordinatorHandshake = undefined;
155
- resolve();
156
- }, CONNECT_TIMEOUT_MS);
157
- });
158
- ws.on("error", (err) => {
159
- clearTimeout(timer);
160
- ws.terminate();
161
- reject(err);
162
- });
163
- });
164
- }
165
- // -----------------------------------------------------------------------
166
- // MeshTransport — Connect to remote coordinator with approval
167
- // -----------------------------------------------------------------------
168
- async connectToRemote(host, port, peerId, _localDataPort, name, fingerprint) {
169
- this._peerId = peerId;
170
- await new Promise((resolve, reject) => {
171
- const url = `ws://${host}:${String(port)}`;
172
- const ws = new WebSocket(url);
173
- const timer = setTimeout(() => {
174
- ws.terminate();
175
- reject(new Error("Remote connection timeout"));
176
- }, CONNECT_TIMEOUT_MS);
177
- ws.on("unexpected-response", () => {
178
- clearTimeout(timer);
179
- ws.terminate();
180
- reject(new Error("Remote connection rejected"));
181
- });
182
- ws.on("open", () => {
183
- this.coordinatorWs = ws;
184
- // Send connect_request instead of introduce
185
- const req = {
186
- method: "connect_request",
187
- peerId,
188
- dataPort: _localDataPort,
189
- name,
190
- fingerprint,
191
- };
192
- ws.send(JSON.stringify(req));
193
- // Wait for connect_accepted or connect_rejected
194
- let approved = false;
195
- ws.on("message", (raw) => {
196
- const msg = parseMessage(raw);
197
- if (msg === undefined)
198
- return;
199
- if (!approved) {
200
- if (msg.method === "connect_accepted") {
201
- approved = true;
202
- clearTimeout(timer);
203
- resolve();
204
- }
205
- else if (msg.method === "connect_rejected") {
206
- clearTimeout(timer);
207
- ws.terminate();
208
- reject(new Error(`Connection rejected: ${msg.reason}`));
209
- return;
210
- }
211
- }
212
- else {
213
- this.dispatchCoordinatorClientMessage(msg);
214
- }
215
- });
216
- ws.on("error", () => {
217
- /* ignore late errors on coordinator connection */
218
- });
219
- });
220
- ws.on("error", (err) => {
221
- clearTimeout(timer);
222
- ws.terminate();
223
- reject(err);
224
- });
225
- });
226
- }
227
- // -----------------------------------------------------------------------
228
- // MeshTransport — Become coordinator (server side)
229
- // -----------------------------------------------------------------------
230
- async becomeCoordinator(host, port) {
231
- await new Promise((resolve, reject) => {
232
- this.coordinatorServer = new WebSocketServer({ host, port });
233
- this.coordinatorServer.on("error", (err) => {
234
- reject(err instanceof Error ? err : new Error(String(err)));
235
- });
236
- this.coordinatorServer.on("listening", () => {
237
- this._isCoordinator = true;
238
- resolve();
239
- });
240
- this.coordinatorServer.on("connection", (ws) => {
241
- this.handleCoordinatorServerConnection(ws);
242
- });
243
- });
244
- }
245
- // -----------------------------------------------------------------------
246
- // MeshTransport — Connect to a peer's data server
247
- // -----------------------------------------------------------------------
248
- async connectToPeer(peer, ownPeerId) {
249
- if (this.peerConnections.has(peer.id))
250
- return;
251
- // Queue broadcasts until the connection registers: messages sent in the
252
- // dial window previously had nowhere to go and were silently dropped.
253
- this.pendingOutbound.set(peer.id, this.pendingOutbound.get(peer.id) ?? []);
254
- await new Promise((resolve) => {
255
- const url = `ws://127.0.0.1:${String(peer.port)}`;
256
- const ws = new WebSocket(url);
257
- ws.on("open", () => {
258
- this.peerConnections.set(peer.id, ws);
259
- // Identify ourselves
260
- const pong = { method: "pong", peerId: ownPeerId };
261
- ws.send(JSON.stringify(pong));
262
- void this.flushPending(peer.id, ws);
263
- // Wire up ongoing message handling
264
- ws.on("message", (raw) => {
265
- const msg = parseMessage(raw);
266
- if (msg !== undefined) {
267
- const handle = { id: peer.id };
268
- this.dispatchDataMessage(handle, msg);
269
- }
270
- });
271
- resolve();
272
- });
273
- const handle = { id: peer.id };
274
- let disconnected = false;
275
- const onDisconnect = () => {
276
- if (disconnected)
277
- return;
278
- disconnected = true;
279
- const wasConnected = this.peerConnections.has(peer.id);
280
- this.peerConnections.delete(peer.id);
281
- if (wasConnected && !this.shutDown) {
282
- this.events.onPeerDisconnected(handle);
283
- }
284
- };
285
- ws.on("close", onDisconnect);
286
- ws.on("error", () => {
287
- this.pendingOutbound.delete(peer.id);
288
- onDisconnect();
289
- ws.terminate();
290
- resolve();
291
- });
292
- });
293
- }
294
- // -----------------------------------------------------------------------
295
- // MeshTransport — Send / broadcast
296
- // -----------------------------------------------------------------------
297
- async send(handle, message) {
298
- const data = JSON.stringify(message);
299
- // Check data connections first
300
- const peerWs = this.peerConnections.get(handle.id);
301
- if (peerWs) {
302
- await sendAsync(peerWs, data);
303
- return;
304
- }
305
- // Check coordinator introduction connections
306
- const introWs = this.introConnections.get(handle.id);
307
- if (introWs) {
308
- await sendAsync(introWs, data);
309
- return;
310
- }
311
- throw new Error(`No connection for handle ${handle.id}`);
312
- }
313
- async acceptConnection(handle) {
314
- const pending = this.pendingConnections.get(handle.id);
315
- if (!pending) {
316
- throw new Error(`No pending connection for handle ${handle.id}`);
317
- }
318
- this.pendingConnections.delete(handle.id);
319
- const { ws, peerId, dataPort } = pending;
320
- // Move to introConnections so send() can reach this peer
321
- this.introConnections.set(peerId, ws);
322
- // Send acceptance to the connecting peer
323
- const accepted = {
324
- method: "connect_accepted",
325
- peerId: this._peerId,
326
- dataPort: this._dataPort,
327
- };
328
- await sendAsync(ws, JSON.stringify(accepted));
329
- // Fire onIntroduction so MeshStore processes the new peer normally
330
- const connHandle = { id: peerId };
331
- this.events.onIntroduction(connHandle, { peerId, dataPort });
332
- }
333
- async rejectConnection(handle, reason) {
334
- const pending = this.pendingConnections.get(handle.id);
335
- if (!pending) {
336
- throw new Error(`No pending connection for handle ${handle.id}`);
337
- }
338
- this.pendingConnections.delete(handle.id);
339
- const { ws } = pending;
340
- const rejected = {
341
- method: "connect_rejected",
342
- peerId: handle.id,
343
- reason,
344
- };
345
- await sendAsync(ws, JSON.stringify(rejected));
346
- ws.terminate();
347
- }
348
- async broadcast(message) {
349
- const data = JSON.stringify(message);
350
- const writes = [];
351
- for (const [, ws] of this.peerConnections) {
352
- writes.push(sendAsync(ws, data).catch(() => {
353
- /* broken connection — cleanup handled by close/error listeners */
354
- }));
355
- }
356
- for (const queue of this.pendingOutbound.values()) {
357
- queue.push(message);
358
- if (queue.length > MAX_PENDING_PER_PEER)
359
- queue.shift();
360
- }
361
- await Promise.all(writes);
362
- }
363
- /** Send messages queued while the peer's connection was being dialled. */
364
- async flushPending(peerId, ws) {
365
- const queue = this.pendingOutbound.get(peerId);
366
- this.pendingOutbound.delete(peerId);
367
- if (queue === undefined)
368
- return;
369
- for (const message of queue) {
370
- const sent = await sendAsync(ws, JSON.stringify(message)).then(() => true, () => false);
371
- if (!sent)
372
- return; // connection is dying; close listeners clean up
373
- }
374
- }
375
- // -----------------------------------------------------------------------
376
- // MeshTransport — Listener management (not supported over WebSocket)
377
- // -----------------------------------------------------------------------
378
- addListener() {
379
- throw new Error("WebSocketTransport does not support listener management");
380
- }
381
- removeListener() {
382
- throw new Error("WebSocketTransport does not support listener management");
383
- }
384
- listListeners() {
385
- return [];
386
- }
387
- // -----------------------------------------------------------------------
388
- // MeshTransport — Shutdown / unref
389
- // -----------------------------------------------------------------------
390
- shutdown() {
391
- this.shutDown = true;
392
- if (this.coordinatorHandshakeTimer !== undefined) {
393
- clearTimeout(this.coordinatorHandshakeTimer);
394
- this.coordinatorHandshakeTimer = undefined;
395
- }
396
- this.resolveCoordinatorHandshake = undefined;
397
- // Destroy the coordinator client socket
398
- this.coordinatorWs?.terminate();
399
- this.coordinatorWs = undefined;
400
- // Destroy all identified peer connections
401
- for (const [, ws] of this.peerConnections) {
402
- ws.terminate();
403
- }
404
- this.peerConnections.clear();
405
- // Destroy all data server accepted sockets (including unidentified)
406
- for (const ws of this.dataServerSockets) {
407
- ws.terminate();
408
- }
409
- this.dataServerSockets.clear();
410
- // Destroy all coordinator server accepted sockets
411
- for (const ws of this.coordinatorServerSockets) {
412
- ws.terminate();
413
- }
414
- this.coordinatorServerSockets.clear();
415
- // Clear introduction connection tracking
416
- this.introConnections.clear();
417
- // Clear pending connections
418
- for (const [, pending] of this.pendingConnections) {
419
- pending.ws.terminate();
420
- }
421
- this.pendingConnections.clear();
422
- // Close servers — stop accepting new connections
423
- this.dataServer?.close();
424
- this.dataServer = undefined;
425
- this.coordinatorServer?.close();
426
- this.coordinatorServer = undefined;
427
- this._isCoordinator = false;
428
- return Promise.resolve();
429
- }
430
- unref() {
431
- // WebSocketServer doesn't have an unref() method the way net.Server
432
- // does. The servers will be closed on shutdown(). Peer WS connections
433
- // are cleaned up on shutdown() as well.
434
- }
435
- // -----------------------------------------------------------------------
436
- // Internal — Coordinator client message dispatch
437
- // -----------------------------------------------------------------------
438
- /**
439
- * Handles messages received on the coordinator client socket (the
440
- * connection from this peer TO the coordinator). Fires the appropriate
441
- * TransportEvents for peer_list, peer_joined, and become_coordinator.
442
- */
443
- dispatchCoordinatorClientMessage(msg) {
444
- if (this.shutDown)
445
- return;
446
- if (msg.method === "peer_list") {
447
- // Fire onPeerList first: it starts the post-join dials (and their
448
- // broadcast queues) before init() resolves.
449
- this.events.onPeerList(msg.peers);
450
- this.completeCoordinatorHandshake();
451
- }
452
- else if (msg.method === "peer_joined") {
453
- this.events.onPeerJoined(msg.peer);
454
- }
455
- else if (msg.method === "become_coordinator") {
456
- this.events.onBecomeCoordinator(msg.peerList);
457
- }
458
- }
459
- /** Complete connectToCoordinator's handshake after the peer list arrives. */
460
- completeCoordinatorHandshake() {
461
- if (this.coordinatorHandshakeTimer !== undefined) {
462
- clearTimeout(this.coordinatorHandshakeTimer);
463
- this.coordinatorHandshakeTimer = undefined;
464
- }
465
- this.resolveCoordinatorHandshake?.();
466
- this.resolveCoordinatorHandshake = undefined;
467
- }
468
- // -----------------------------------------------------------------------
469
- // Internal — Data message dispatch
470
- // -----------------------------------------------------------------------
471
- /**
472
- * Routes a message received on a peer data connection to the
473
- * appropriate event. become_coordinator has its own event; all
474
- * other messages fire onMessage for MeshStore to handle.
475
- */
476
- dispatchDataMessage(handle, msg) {
477
- if (this.shutDown)
478
- return;
479
- if (msg.method === "become_coordinator") {
480
- this.events.onBecomeCoordinator(msg.peerList);
481
- }
482
- else {
483
- this.events.onMessage(handle, msg);
484
- }
485
- }
486
- // -----------------------------------------------------------------------
487
- // Internal — Coordinator server connection handling
488
- // -----------------------------------------------------------------------
489
- /**
490
- * Accepts a new connection on the coordinator server. Reads
491
- * introduce messages and fires onIntroduction so MeshStore can
492
- * respond with the peer list and broadcast the arrival.
493
- */
494
- handleCoordinatorServerConnection(ws) {
495
- if (this.shutDown) {
496
- ws.terminate();
497
- return;
498
- }
499
- this.coordinatorServerSockets.add(ws);
500
- ws.on("close", () => this.coordinatorServerSockets.delete(ws));
501
- ws.on("error", () => this.coordinatorServerSockets.delete(ws));
502
- ws.on("message", (raw) => {
503
- const msg = parseMessage(raw);
504
- if (msg === undefined)
505
- return;
506
- if (msg.method === "introduce") {
507
- const handle = { id: msg.peerId };
508
- this.introConnections.set(handle.id, ws);
509
- this.events.onIntroduction(handle, {
510
- peerId: msg.peerId,
511
- dataPort: msg.dataPort,
512
- });
513
- }
514
- else if (msg.method === "connect_request") {
515
- const handle = { id: msg.peerId };
516
- this.pendingConnections.set(handle.id, {
517
- ws,
518
- peerId: msg.peerId,
519
- dataPort: msg.dataPort,
520
- name: msg.name,
521
- fingerprint: msg.fingerprint,
522
- });
523
- this.events.onConnectionRequest(handle, {
524
- peerId: msg.peerId,
525
- dataPort: msg.dataPort,
526
- name: msg.name,
527
- fingerprint: msg.fingerprint,
528
- });
529
- }
530
- });
531
- }
532
- // -----------------------------------------------------------------------
533
- // Internal — Incoming data connection handling
534
- // -----------------------------------------------------------------------
535
- /**
536
- * Accepts a new connection on the data server. Reads the initial
537
- * pong to identify the peer, then fires onMessage for subsequent
538
- * messages. Tracks the connection for cleanup on close/error.
539
- */
540
- handleIncomingDataConnection(ws) {
541
- if (this.shutDown) {
542
- ws.terminate();
543
- return;
544
- }
545
- this.dataServerSockets.add(ws);
546
- ws.on("close", () => this.dataServerSockets.delete(ws));
547
- let remotePeerId;
548
- let disconnected = false;
549
- ws.on("message", (raw) => {
550
- const msg = parseMessage(raw);
551
- if (msg === undefined)
552
- return;
553
- if (msg.method === "pong") {
554
- const peerId = msg.peerId;
555
- remotePeerId = peerId;
556
- if (!this.peerConnections.has(peerId)) {
557
- this.peerConnections.set(peerId, ws);
558
- }
559
- void this.flushPending(peerId, ws);
560
- const handle = { id: peerId };
561
- const info = {
562
- id: peerId,
563
- port: 0,
564
- startedAt: new Date().toISOString(),
565
- };
566
- this.events.onPeerConnected(handle, info);
567
- }
568
- else if (remotePeerId !== undefined) {
569
- const handle = { id: remotePeerId };
570
- this.dispatchDataMessage(handle, msg);
571
- }
572
- });
573
- const onDisconnect = () => {
574
- if (disconnected)
575
- return;
576
- disconnected = true;
577
- if (remotePeerId !== undefined) {
578
- this.peerConnections.delete(remotePeerId);
579
- if (!this.shutDown) {
580
- this.events.onPeerDisconnected({ id: remotePeerId });
581
- }
582
- }
583
- };
584
- ws.on("close", onDisconnect);
585
- ws.on("error", onDisconnect);
586
- }
587
- }
588
- // ---------------------------------------------------------------------------
589
- // Message parsing (not exported)
590
- // ---------------------------------------------------------------------------
591
- /**
592
- * Parse a raw WS message into a MeshMessage, returning undefined for
593
- * malformed data. Unlike TCP, each WS frame is a complete message —
594
- * no newline delimiter or buffer splitting required.
595
- */
596
- function parseMessage(raw) {
597
- if (raw === undefined)
598
- return undefined;
599
- // WS data arrives as Buffer in Node, string in browsers
600
- let text;
601
- if (typeof raw === "string") {
602
- text = raw;
603
- }
604
- else if (raw instanceof Buffer || ArrayBuffer.isView(raw)) {
605
- text = new TextDecoder().decode(raw instanceof Buffer ? raw : new Uint8Array(raw.buffer));
606
- }
607
- else if (raw instanceof ArrayBuffer) {
608
- text = new TextDecoder().decode(raw);
609
- }
610
- else {
611
- return undefined;
612
- }
613
- try {
614
- const parsed = JSON.parse(text);
615
- return isMeshMessage(parsed) ? parsed : undefined;
616
- }
617
- catch {
618
- return undefined;
619
- }
620
- }
621
- //# sourceMappingURL=ws-transport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ws-transport.js","sourceRoot":"","sources":["../../src/core/ws-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AASnD,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,kEAAkE;AAClE,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC,8EAA8E;AAC9E,sCAAsC;AACtC,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC,SAAS,SAAS,CAAC,EAAa,EAAE,IAAY;IAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,EAAE,CAAC,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;YACrC,OAAO,EAAE,CAAC;YACV,OAAO;QACT,CAAC;QACD,EAAE,CAAC,IAAI,CAAC,IA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CAAC;QAEF,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC7B,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC/B,CAAC;CACF;AAED,8EAA8E;AAC9E,iCAAiC;AACjC,8EAA8E;AAE9E;;;;GAIG;AACH,SAAS,YAAY,CAAC,GAAY;IAChC,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAExC,wDAAwD;IACxD,IAAI,IAAY,CAAC;IACjB,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,GAAG,GAAG,CAAC;IACb,CAAC;SAAM,IAAI,GAAG,YAAY,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5D,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAC7B,GAAG,YAAY,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CACzD,CAAC;IACJ,CAAC;SAAM,IAAI,GAAG,YAAY,WAAW,EAAE,CAAC;QACtC,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Integration test for the WebSocket transport's broadcast queue: state patches broadcast before the WS data connections are established must be queued and flushed on registration, not dropped (#23).
3
- *
4
- * Mirrors broadcast-window.integration.test.ts over TlsTransport; the queue logic is implemented per transport, so each needs its own coverage.
5
- */
6
- export {};
7
- //# sourceMappingURL=ws-broadcast-window.integration.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ws-broadcast-window.integration.test.d.ts","sourceRoot":"","sources":["../../src/test/ws-broadcast-window.integration.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}