agent-comms 8.9.3 → 8.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +2 -2
- package/dist/core/data-frame-routing.d.ts +28 -2
- package/dist/core/data-frame-routing.d.ts.map +1 -1
- package/dist/core/data-frame-routing.js +75 -4
- package/dist/core/data-frame-routing.js.map +1 -1
- package/dist/core/hub-session.d.ts +7 -1
- package/dist/core/hub-session.d.ts.map +1 -1
- package/dist/core/hub-session.js +25 -0
- package/dist/core/hub-session.js.map +1 -1
- package/dist/core/peer-lifecycle.d.ts +1 -1
- package/dist/core/peer-lifecycle.d.ts.map +1 -1
- package/dist/core/peer-lifecycle.js +21 -11
- package/dist/core/peer-lifecycle.js.map +1 -1
- package/dist/core/wire-mesh-transport.d.ts +0 -1
- package/dist/core/wire-mesh-transport.d.ts.map +1 -1
- package/dist/core/wire-mesh-transport.js +3 -2
- package/dist/core/wire-mesh-transport.js.map +1 -1
- package/dist/test/account-ledger-helpers.d.ts +35 -0
- package/dist/test/account-ledger-helpers.d.ts.map +1 -0
- package/dist/test/account-ledger-helpers.js +81 -0
- package/dist/test/account-ledger-helpers.js.map +1 -0
- package/dist/test/account-ledger-hub-replication.integration.test.d.ts +5 -0
- package/dist/test/account-ledger-hub-replication.integration.test.d.ts.map +1 -0
- package/dist/test/account-ledger-hub-replication.integration.test.js +100 -0
- package/dist/test/account-ledger-hub-replication.integration.test.js.map +1 -0
- package/dist/test/account-ledger-replication.integration.test.js +4 -66
- package/dist/test/account-ledger-replication.integration.test.js.map +1 -1
- package/dist/test/coordinator-failover-hub.integration.test.js +9 -2
- package/dist/test/coordinator-failover-hub.integration.test.js.map +1 -1
- package/dist/test/coordinator-failover.unit.test.js +51 -1
- package/dist/test/coordinator-failover.unit.test.js.map +1 -1
- package/dist/test/data-frame-routing.unit.test.d.ts +5 -0
- package/dist/test/data-frame-routing.unit.test.d.ts.map +1 -0
- package/dist/test/data-frame-routing.unit.test.js +79 -0
- package/dist/test/data-frame-routing.unit.test.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/ExaDev/agent-comms)
|
|
4
4
|
[](https://www.npmjs.com/package/agent-comms)
|
|
5
|
-
[](https://github.com/ExaDev/agent-comms/releases/tag/v8.10.0)
|
|
6
6
|
[](https://github.com/ExaDev/agent-comms/actions)
|
|
7
7
|
|
|
8
8
|
Cross-harness communication mesh for LLM agents: rooms, DMs, presence, and visibility over TCP with zero filesystem dependencies.
|
|
@@ -555,4 +555,4 @@ npx agent-comms account import ~/account.bundle # on the other machine, then d
|
|
|
555
555
|
|
|
556
556
|
Copy the account this way or by joining, never by copying `~/.agent-comms` between machines: each machine keeps a writer id of its own for the grant ledger below, and two machines sharing one would corrupt it.
|
|
557
557
|
|
|
558
|
-
Every grant your account issues, and every revocation of one, is recorded in a replicated ledger rather than on the machine that minted it: each machine appends to a data-domain log of its own (wire-mesh's replicated issuer grant ledger pattern, `spec/PATTERNS.md`), and the logs replicate to every machine holding the account, so `dm_revoke` on any of them finds and revokes a grant another one issued. Entries are sealed under a key derived from the account key, so a device that stores or relays them without holding the account sees only ciphertext, and writing to the ledger still needs the account's private key. The ledger replicates over direct peer connections (the local mesh, or machines that reach each other directly)
|
|
558
|
+
Every grant your account issues, and every revocation of one, is recorded in a replicated ledger rather than on the machine that minted it: each machine appends to a data-domain log of its own (wire-mesh's replicated issuer grant ledger pattern, `spec/PATTERNS.md`), and the logs replicate to every machine holding the account, so `dm_revoke` on any of them finds and revokes a grant another one issued. Entries are sealed under a key derived from the account key, so a device that stores or relays them without holding the account sees only ciphertext, and writing to the ledger still needs the account's private key. The ledger replicates over direct peer connections (the local mesh, or machines that reach each other directly) and between machines that meet only through the relay hub, over a relay pairing sealed end to end between the two devices so the hub carries ciphertext; either way a log is offered only to a device whose membership proof names this account, and a hub-reachable device of any other account is never offered it. A revocation itself is also announced to every connected peer the moment it is made. Grants a build before the ledger recorded in `user-identity.json` are moved into it the first time a bridge starts, with nothing to do by hand.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WireMeshTransport's own core/data frame dispatch (data-have, data-request, data-entries), split out under the repo's max-lines cap the same way gossip-directory.ts and hub-forwarding.ts were each split from the same owning file.
|
|
3
3
|
*/
|
|
4
|
+
import type { DataDomainFrame } from "wire-mesh-core/domain/mesh-session";
|
|
4
5
|
import type { DataHaveFrame, DataRequestFrame, Frame } from "wire-mesh-core/generated/protocol";
|
|
5
6
|
import type { Connection } from "wire-mesh-core/ports/transport";
|
|
6
7
|
import type { KeyValueStorage } from "wire-mesh-core/ports/storage";
|
|
@@ -15,6 +16,18 @@ export interface AccountReplication {
|
|
|
15
16
|
/** Whether the peer whose session authenticated it as `deviceHex` holds the same account. Only such a peer is offered the ledger or answered for it, so a device of another account never stores the ciphertext or follows its head. */
|
|
16
17
|
isAccountPeer: (deviceHex: string) => Promise<boolean>;
|
|
17
18
|
}
|
|
19
|
+
/** How core/data frames reach a device that this side meets only through the relay hub, over a relay pairing sealed end to end between the two devices: the hub carries ciphertext and never sees a frame. */
|
|
20
|
+
export interface HubDataChannel {
|
|
21
|
+
/** The devices (hex) the hub's gossiped directory has admitted, whether or not this side also has a direct session to them. */
|
|
22
|
+
peers: () => readonly string[];
|
|
23
|
+
/** Sends one frame to `deviceHex` through the hub. Rejects when no hub session is live. */
|
|
24
|
+
send: (deviceHex: string, frame: DataDomainFrame) => Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/** The hub data channel over whatever hub session `hub()` currently returns, read on each call because the router is built before the hub it talks through. */
|
|
27
|
+
export declare function hubDataChannel(hub: () => {
|
|
28
|
+
peers: () => readonly string[];
|
|
29
|
+
sendDataFrame: (deviceHex: string, frame: Readonly<DataDomainFrame>) => Promise<void>;
|
|
30
|
+
}): HubDataChannel;
|
|
18
31
|
/** Builds the router's account replication from the transport option: a peer is an account peer when the membership proof in its gossiped advert (looked up through `advertOf`) verifies against this machine's own principal. Undefined when the transport has no account ledger. */
|
|
19
32
|
export declare function accountReplicationFrom(options: Readonly<WireMeshTransportOptions>["accountReplication"], advertOf: (deviceHex: string) => Readonly<Record<string, unknown>> | undefined): AccountReplication | undefined;
|
|
20
33
|
/** Routes one frame received on a raw data connection, tracking the connection against its peer's device-id along the way (connectionsByPeer, mutated in place) so a later data-have, data-request or data-entries send addressed to that same peer reuses it. Nothing further happens until the sender is a tracked peer session. A frame naming one of the account's writer logs goes to the account ledger when the sender holds the same account and is dropped otherwise, without reaching dataStorage either way; any other data frame goes to wire-mesh-core's own core/data handlers over dataStorage, and is dropped when this side has no dataStorage. Any handler error is reported via onError and swallowed, never thrown, since this runs inside the transport's own onFrame callback with no caller awaiting it directly. */
|
|
@@ -25,10 +38,17 @@ export declare function routeDataFrame(deps: Readonly<{
|
|
|
25
38
|
peerSessions: ReadonlyMap<string, unknown>;
|
|
26
39
|
onError: ((error: Error) => void) | undefined;
|
|
27
40
|
}>, connection: Readonly<Connection>, frame: Frame): Promise<void>;
|
|
28
|
-
/**
|
|
41
|
+
/** Handles one core/data frame that arrived through a relay pairing, from the device the pairing's secure channel authenticated as `fromDeviceHex`. Only a frame naming one of the account's writer logs, from a device that holds the same account, is acted on, and any answer goes back through the same pairing; every other relayed data frame is dropped, since a device met only through the hub has no standing to read or write this side's other logs. Any handler error is reported via onError and swallowed, as in routeDataFrame. */
|
|
42
|
+
export declare function routeRelayedDataFrame(deps: Readonly<{
|
|
43
|
+
account: Readonly<AccountReplication> | undefined;
|
|
44
|
+
hub: Readonly<HubDataChannel> | undefined;
|
|
45
|
+
onError: ((error: Error) => void) | undefined;
|
|
46
|
+
}>, fromDeviceHex: string, frame: Readonly<DataDomainFrame>): Promise<void>;
|
|
47
|
+
/** Offers every account writer log this machine holds to every device that holds the same account and that this side can reach (agent-comms#344): over a live, trusted data connection, or, for a device it meets only through the relay hub, over a relay pairing. Such a device that is behind asks for what it is missing, which is the data-domain fan-out that carries each machine's grants and revocations to every other. A device reachable both ways is offered the logs once, directly. Called on the gossip cadence, so a machine that was away when an entry was written still catches up the next time it is reachable. A send that fails is reported and the rest carry on; the next round retries it. */
|
|
29
48
|
export declare function announceAccountLedger(deps: Readonly<{
|
|
30
49
|
connectionsByPeer: ReadonlyMap<string, Readonly<Connection>>;
|
|
31
50
|
account: Readonly<AccountReplication>;
|
|
51
|
+
hub: Readonly<HubDataChannel> | undefined;
|
|
32
52
|
peerSessions: ReadonlyMap<string, unknown>;
|
|
33
53
|
onError: ((error: Error) => void) | undefined;
|
|
34
54
|
}>): Promise<void>;
|
|
@@ -39,10 +59,12 @@ export interface DataFrameRouterDeps {
|
|
|
39
59
|
/** The transport's own trusted sessions, keyed by device-id hex: the gate every data frame and every announcement passes. */
|
|
40
60
|
peerSessions: ReadonlyMap<string, unknown>;
|
|
41
61
|
onError: ((error: Error) => void) | undefined;
|
|
62
|
+
/** Absent for a transport that never dials a relay hub. */
|
|
63
|
+
hub: Readonly<HubDataChannel> | undefined;
|
|
42
64
|
/** How often the account ledger is offered to peers: the transport's own re-advertise cadence. */
|
|
43
65
|
announceIntervalMs: number;
|
|
44
66
|
}
|
|
45
|
-
/** WireMeshTransport's core/data state and dispatch, split out under the repo's max-lines cap: the connection each peer's frames arrive on, routing of every data frame received, the mechanical send primitive, and the periodic offer of the account ledger's writer logs. */
|
|
67
|
+
/** WireMeshTransport's core/data state and dispatch, split out under the repo's max-lines cap: the connection each peer's frames arrive on, routing of every data frame received, the mechanical send primitive, and the periodic offer of the account ledger's writer logs, and the same exchange with a device met only through the relay hub. */
|
|
46
68
|
export declare class DataFrameRouter {
|
|
47
69
|
private readonly deps;
|
|
48
70
|
/** Backs this side's own responder for an incoming data-have, data-request or data-entries frame about any log other than the account ledger's (agent-comms#50's P5 integration). When undefined, such frames are dropped; the account ledger's are routed either way. For those logs, deciding when to proactively call sendDataFrame at all (the catch-up policy: which peers' logs to track, when to send an initial data-have) stays the caller's business and this field only backs the mechanical parts (answering a have or request, storing entries); the account ledger's own offers are the router's, sent every announceIntervalMs. */
|
|
@@ -50,9 +72,13 @@ export declare class DataFrameRouter {
|
|
|
50
72
|
/** Every peer this side has ever received a frame from, keyed by device-id hex, tracking the raw wire-mesh-core Connection each frame arrived on: what sendDataFrame needs, since neither AcceptedMeshSession nor MeshSession exposes a generic "send an arbitrary frame" method the way the raw Connection itself does. Registered eagerly on the very first frame from a connection (including one still in quarantine, e.g. before connect_request approval) so a later sendDataFrame call can reach it; routeDataFrame's own trust gate (peerSessions.has) is what actually decides whether to act on anything received this way, not this map. */
|
|
51
73
|
private readonly connectionsByPeer;
|
|
52
74
|
private announceInterval;
|
|
75
|
+
/** Whether an announcement round is still running, so a round slowed by an unreachable hub peer is not stacked on by the next tick. */
|
|
76
|
+
private announcing;
|
|
53
77
|
constructor(deps: Readonly<DataFrameRouterDeps>);
|
|
54
78
|
/** See routeDataFrame. */
|
|
55
79
|
route(connection: Readonly<Connection>, frame: Frame): Promise<void>;
|
|
80
|
+
/** See routeRelayedDataFrame. An arrow property, so the transport can hand it to the hub session as a callback. */
|
|
81
|
+
readonly routeRelayed: (fromDeviceHex: string, frame: Readonly<DataDomainFrame>) => Promise<void>;
|
|
56
82
|
/** Sends one frame on the connection peerDeviceHex's frames last arrived on. Throws if none has arrived from it yet. */
|
|
57
83
|
send(peerDeviceHex: string, frame: Readonly<DataHaveFrame> | Readonly<DataRequestFrame>): Promise<void>;
|
|
58
84
|
/** Stops offering the account ledger. A router that never started offering it has no timer to clear. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-frame-routing.d.ts","sourceRoot":"","sources":["../../src/core/data-frame-routing.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,KAAK,EACN,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU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E,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAc1E,mHAAmH;IACnH,QAAQ,CAAC,YAAY,GACnB,eAAe,MAAM,EACrB,OAAO,QAAQ,CAAC,eAAe,CAAC,KAC/B,OAAO,CAAC,IAAI,CAAC,CAUd;IAEF,wHAAwH;IAClH,IAAI,CACR,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC,gBAAgB,CAAC,GAC1D,OAAO,CAAC,IAAI,CAAC;IAUhB,wGAAwG;IACxG,IAAI,IAAI,IAAI;CAKb"}
|
|
@@ -7,6 +7,13 @@ import { isDataFrame } from "wire-mesh-core/domain/hub-mailbox";
|
|
|
7
7
|
import { readMembershipProof } from "./gossip-directory.js";
|
|
8
8
|
/** The most entries one data-entries reply carries, for every log this side answers for, the account ledger's included: a longer log catches up over several rounds, so the bound only caps one frame's size. */
|
|
9
9
|
export const DATA_ENTRIES_RESPONSE_LIMIT = 100;
|
|
10
|
+
/** The hub data channel over whatever hub session `hub()` currently returns, read on each call because the router is built before the hub it talks through. */
|
|
11
|
+
export function hubDataChannel(hub) {
|
|
12
|
+
return {
|
|
13
|
+
peers: () => hub().peers(),
|
|
14
|
+
send: async (deviceHex, frame) => hub().sendDataFrame(deviceHex, frame),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
10
17
|
/** Builds the router's account replication from the transport option: a peer is an account peer when the membership proof in its gossiped advert (looked up through `advertOf`) verifies against this machine's own principal. Undefined when the transport has no account ledger. */
|
|
11
18
|
export function accountReplicationFrom(options, advertOf) {
|
|
12
19
|
if (options === undefined)
|
|
@@ -66,7 +73,26 @@ export async function routeDataFrame(deps, connection, frame) {
|
|
|
66
73
|
deps.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
67
74
|
}
|
|
68
75
|
}
|
|
69
|
-
/**
|
|
76
|
+
/** Handles one core/data frame that arrived through a relay pairing, from the device the pairing's secure channel authenticated as `fromDeviceHex`. Only a frame naming one of the account's writer logs, from a device that holds the same account, is acted on, and any answer goes back through the same pairing; every other relayed data frame is dropped, since a device met only through the hub has no standing to read or write this side's other logs. Any handler error is reported via onError and swallowed, as in routeDataFrame. */
|
|
77
|
+
export async function routeRelayedDataFrame(deps, fromDeviceHex, frame) {
|
|
78
|
+
const { account, hub } = deps;
|
|
79
|
+
if (account === undefined || hub === undefined)
|
|
80
|
+
return;
|
|
81
|
+
try {
|
|
82
|
+
const ledger = account.ledger();
|
|
83
|
+
if (ledger?.ownsLog(frame.peer) !== true)
|
|
84
|
+
return;
|
|
85
|
+
if (!(await account.isAccountPeer(fromDeviceHex)))
|
|
86
|
+
return;
|
|
87
|
+
const reply = await ledger.handleDataFrame(frame);
|
|
88
|
+
if (reply !== null)
|
|
89
|
+
await hub.send(fromDeviceHex, reply);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
deps.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Offers every account writer log this machine holds to every device that holds the same account and that this side can reach (agent-comms#344): over a live, trusted data connection, or, for a device it meets only through the relay hub, over a relay pairing. Such a device that is behind asks for what it is missing, which is the data-domain fan-out that carries each machine's grants and revocations to every other. A device reachable both ways is offered the logs once, directly. Called on the gossip cadence, so a machine that was away when an entry was written still catches up the next time it is reachable. A send that fails is reported and the rest carry on; the next round retries it. */
|
|
70
96
|
export async function announceAccountLedger(deps) {
|
|
71
97
|
const ledger = deps.account.ledger();
|
|
72
98
|
if (ledger === undefined)
|
|
@@ -74,22 +100,49 @@ export async function announceAccountLedger(deps) {
|
|
|
74
100
|
const frames = await ledger.announcements();
|
|
75
101
|
if (frames.length === 0)
|
|
76
102
|
return;
|
|
103
|
+
const reportError = (error) => {
|
|
104
|
+
deps.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
105
|
+
};
|
|
106
|
+
const direct = new Set();
|
|
107
|
+
const offers = [];
|
|
77
108
|
for (const [deviceHex, connection] of deps.connectionsByPeer) {
|
|
78
109
|
if (!deps.peerSessions.has(deviceHex))
|
|
79
110
|
continue;
|
|
80
111
|
if (!(await deps.account.isAccountPeer(deviceHex)))
|
|
81
112
|
continue;
|
|
113
|
+
direct.add(deviceHex);
|
|
82
114
|
for (const frame of frames) {
|
|
83
115
|
try {
|
|
84
116
|
await connection.send(frame);
|
|
85
117
|
}
|
|
86
118
|
catch (error) {
|
|
87
|
-
|
|
119
|
+
reportError(error);
|
|
88
120
|
}
|
|
89
121
|
}
|
|
90
122
|
}
|
|
123
|
+
const { hub } = deps;
|
|
124
|
+
if (hub === undefined)
|
|
125
|
+
return;
|
|
126
|
+
for (const deviceHex of hub.peers()) {
|
|
127
|
+
if (direct.has(deviceHex))
|
|
128
|
+
continue;
|
|
129
|
+
if (!(await deps.account.isAccountPeer(deviceHex)))
|
|
130
|
+
continue;
|
|
131
|
+
// Each device is offered concurrently: a pairing to a device that is not there waits out its own handshake, which must not hold up the others.
|
|
132
|
+
offers.push((async () => {
|
|
133
|
+
for (const frame of frames) {
|
|
134
|
+
try {
|
|
135
|
+
await hub.send(deviceHex, frame);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
reportError(error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
})());
|
|
142
|
+
}
|
|
143
|
+
await Promise.all(offers);
|
|
91
144
|
}
|
|
92
|
-
/** WireMeshTransport's core/data state and dispatch, split out under the repo's max-lines cap: the connection each peer's frames arrive on, routing of every data frame received, the mechanical send primitive, and the periodic offer of the account ledger's writer logs. */
|
|
145
|
+
/** WireMeshTransport's core/data state and dispatch, split out under the repo's max-lines cap: the connection each peer's frames arrive on, routing of every data frame received, the mechanical send primitive, and the periodic offer of the account ledger's writer logs, and the same exchange with a device met only through the relay hub. */
|
|
93
146
|
export class DataFrameRouter {
|
|
94
147
|
deps;
|
|
95
148
|
/** Backs this side's own responder for an incoming data-have, data-request or data-entries frame about any log other than the account ledger's (agent-comms#50's P5 integration). When undefined, such frames are dropped; the account ledger's are routed either way. For those logs, deciding when to proactively call sendDataFrame at all (the catch-up policy: which peers' logs to track, when to send an initial data-have) stays the caller's business and this field only backs the mechanical parts (answering a have or request, storing entries); the account ledger's own offers are the router's, sent every announceIntervalMs. */
|
|
@@ -97,6 +150,8 @@ export class DataFrameRouter {
|
|
|
97
150
|
/** Every peer this side has ever received a frame from, keyed by device-id hex, tracking the raw wire-mesh-core Connection each frame arrived on: what sendDataFrame needs, since neither AcceptedMeshSession nor MeshSession exposes a generic "send an arbitrary frame" method the way the raw Connection itself does. Registered eagerly on the very first frame from a connection (including one still in quarantine, e.g. before connect_request approval) so a later sendDataFrame call can reach it; routeDataFrame's own trust gate (peerSessions.has) is what actually decides whether to act on anything received this way, not this map. */
|
|
98
151
|
connectionsByPeer = new Map();
|
|
99
152
|
announceInterval;
|
|
153
|
+
/** Whether an announcement round is still running, so a round slowed by an unreachable hub peer is not stacked on by the next tick. */
|
|
154
|
+
announcing = false;
|
|
100
155
|
constructor(deps) {
|
|
101
156
|
this.deps = deps;
|
|
102
157
|
this.dataStorage = deps.dataStorage;
|
|
@@ -104,13 +159,21 @@ export class DataFrameRouter {
|
|
|
104
159
|
if (account === undefined)
|
|
105
160
|
return;
|
|
106
161
|
this.announceInterval = setInterval(() => {
|
|
162
|
+
if (this.announcing)
|
|
163
|
+
return;
|
|
164
|
+
this.announcing = true;
|
|
107
165
|
announceAccountLedger({
|
|
108
166
|
connectionsByPeer: this.connectionsByPeer,
|
|
109
167
|
account,
|
|
168
|
+
hub: deps.hub,
|
|
110
169
|
peerSessions: deps.peerSessions,
|
|
111
170
|
onError: deps.onError,
|
|
112
|
-
})
|
|
171
|
+
})
|
|
172
|
+
.catch((error) => {
|
|
113
173
|
deps.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
174
|
+
})
|
|
175
|
+
.finally(() => {
|
|
176
|
+
this.announcing = false;
|
|
114
177
|
});
|
|
115
178
|
}, deps.announceIntervalMs);
|
|
116
179
|
this.announceInterval.unref();
|
|
@@ -125,6 +188,14 @@ export class DataFrameRouter {
|
|
|
125
188
|
onError: this.deps.onError,
|
|
126
189
|
}, connection, frame);
|
|
127
190
|
}
|
|
191
|
+
/** See routeRelayedDataFrame. An arrow property, so the transport can hand it to the hub session as a callback. */
|
|
192
|
+
routeRelayed = async (fromDeviceHex, frame) => {
|
|
193
|
+
await routeRelayedDataFrame({
|
|
194
|
+
account: this.deps.account,
|
|
195
|
+
hub: this.deps.hub,
|
|
196
|
+
onError: this.deps.onError,
|
|
197
|
+
}, fromDeviceHex, frame);
|
|
198
|
+
};
|
|
128
199
|
/** Sends one frame on the connection peerDeviceHex's frames last arrived on. Throws if none has arrived from it yet. */
|
|
129
200
|
async send(peerDeviceHex, frame) {
|
|
130
201
|
const connection = this.connectionsByPeer.get(peerDeviceHex);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-frame-routing.js","sourceRoot":"","sources":["../../src/core/data-frame-routing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"data-frame-routing.js","sourceRoot":"","sources":["../../src/core/data-frame-routing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAUhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,iNAAiN;AACjN,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAkB/C,+JAA+J;A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AI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,kDAAkD,aAAa,EAAE,CAClE,CAAC;QACJ,CAAC;QACD,MAAM,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,wGAAwG;IACxG,IAAI;QACF,IAAI,IAAI,CAAC,gBAAgB,KAAK,SAAS;YAAE,OAAO;QAChD,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACrC,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* HubSession -- the relay-hub connection mode (agent-comms#151), split from wire-mesh-transport.ts under the max-lines cap the same way connection-approval.ts and its siblings were. A hub connection (wss://mesh.exadev.io/) is a RELAY, not a coordinator: no connect_request/introduce approval applies. The session's own self-advert is forwarded by the hub to every other connected agent and the hub answers with a catch-up of everyone already there, so peers discover each other purely through gossip. Messages ride relay-connect pairings -- sendManageRequest's own targetDevice routing, which the session layer wraps as relay-data to exactly that device.
|
|
3
3
|
*/
|
|
4
|
-
import { type AcceptedMeshSession, type DirectoryEntry, type IncomingManageRequest, type ManageOutcome } from "wire-mesh-core/domain/mesh-session";
|
|
4
|
+
import { type AcceptedMeshSession, type DataDomainFrame, type DirectoryEntry, type IncomingManageRequest, type ManageOutcome } from "wire-mesh-core/domain/mesh-session";
|
|
5
5
|
import type { CapabilityScope, CapabilityToken, Frame, ManageCommand } from "wire-mesh-core/generated/protocol";
|
|
6
6
|
import type { IdentityPort } from "wire-mesh-core/ports/identity";
|
|
7
7
|
import type { Connection } from "wire-mesh-core/ports/transport";
|
|
@@ -21,6 +21,8 @@ export interface HubSessionDeps {
|
|
|
21
21
|
advertisedAddresses: readonly string[];
|
|
22
22
|
/** Registers a frame observer + dispatch for raw frames arriving on the hub connection (the transport's own handleDataFrame path). */
|
|
23
23
|
onFrame: (connection: Readonly<Connection>, frame: Readonly<Frame>) => void | Promise<void>;
|
|
24
|
+
/** Receives each core/data frame that arrived through a relay pairing, with the device (hex) the pairing's secure channel authenticated as its sender, never the one the hub stamps. Frames that arrived directly on the hub connection are the hub mailbox's, not a device's, and never reach it. */
|
|
25
|
+
onRelayedDataFrame: (fromDeviceHex: string, frame: Readonly<DataDomainFrame>) => Promise<void>;
|
|
24
26
|
/** Tracks the session for shutdown -- every session the transport ever creates, always. */
|
|
25
27
|
trackForShutdown: (session: AcceptedMeshSession) => void;
|
|
26
28
|
/** Stops tracking a session that has ended, so a store that redials the hub for as long as it runs does not accumulate dead sessions the transport would keep gossiping to. */
|
|
@@ -79,6 +81,10 @@ export declare class HubSession {
|
|
|
79
81
|
private consumeEvents;
|
|
80
82
|
/** Consumes one hub session's inbound relayed manage-requests until it ends, dispatching each in arrival order to dispatchHubRequest -- see that function's own doc for the actual per-request trust decision. Split out purely so the decision itself is directly unit-testable against fake requests/deps (hub-session-dispatch.test.ts), the same reason hub-forwarding.ts's own routeRoomRequestViaHub is a standalone function rather than a private method. Passes this.url through as dispatchHubRequest's own hubAddress -- this side's own dialled address for the hub every request on this specific session arrived over (agent-comms#216), the answering-side equivalent of tracePath's own local.hubAddress above. */
|
|
81
83
|
private consume;
|
|
84
|
+
/** Consumes one hub session's inbound core/data frames until it ends, handing each one that came through a relay pairing to onRelayedDataFrame in arrival order. A failure in the handler is reported and the loop carries on, since one bad frame must not stop every later one. */
|
|
85
|
+
private consumeDataFrames;
|
|
86
|
+
/** Sends one core/data frame to a specific hub-reachable device through a relay pairing, sealed end to end with that device. Rejects when no hub session is live. */
|
|
87
|
+
sendDataFrame(peerDeviceHex: string, frame: Readonly<DataDomainFrame>): Promise<void>;
|
|
82
88
|
/** Sends a real core/room manage-request to a specific hub-reachable peer, through the hub's relay-connect/relay-data pairing -- the local-to-remote leg of agent-comms#155's routing, mirroring MeshTransport.sendRoomRequest's own not_connected/outcome contract so WireMeshTransport can fall back to this uniformly when memberId isn't a local peer session. Bounded by HUB_ROOM_REQUEST_TIMEOUT_MS (see its own doc) since an unreachable target-device is silently dropped by the hub with no error frame, unlike a local session's own connection-level failure. */
|
|
83
89
|
sendRoomRequest(peerDeviceHex: string, command: ManageCommand, scope: Readonly<CapabilityScope>, token?: CapabilityToken): Promise<ManageOutcome>;
|
|
84
90
|
/** Sends path.trace to a specific hub-reachable peer, through the hub's relay-connect/relay-data pairing -- WireMeshTransport.meshTrace's own hub-relayed fallback (agent-comms#199), mirroring sendRoomRequest's own not_connected contract and HUB_ROOM_REQUEST_TIMEOUT_MS default for the identical reason (an unreachable target-device is silently dropped by the hub, not answered with an error). Delegates the actual send/RTT-measurement/response-parsing to wire-mesh-core's own tracePath, reporting this.url (the address this side itself dialled to reach the hub) as local.hubAddress. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hub-session.d.ts","sourceRoot":"","sources":["../../src/core/hub-session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EACnB,MAAM,oCAAoC,CAAC;AAG5C,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,KAAK,EACL,aAAa,EACd,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAKxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,2fAA2f;AAE3f,MAAM,WAAW,cAAc;IAC7B,oIAAoI;IACpI,yBAAyB,EAAE,MAAM,CAAC;IAClC,yDAAyD;IACzD,aAAa,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AAI,CAAC;IAOjC,qFAAqF;IACrF,KAAK,IAAI,SAAS,MAAM,EAAE;IAI1B,wGAAwG;IAClG,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkCzC;;;;;;OAMG;YACW,aAAa;IAuB3B,msBAAmsB;IACnsB,OAAO,CAAC,OAAO;IAgBf,qRAAqR;IACrR,OAAO,CAAC,iBAAiB;IAmBzB,qKAAqK;IAC/J,aAAa,CACjB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC;IAUhB,6iBAA6iB;IACviB,eAAe,CACnB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,EAChC,KAAK,CAAC,EAAE,eAAe,GACtB,OAAO,CAAC,aAAa,CAAC;IAczB,0kBAA0kB;IACpkB,SAAS,CACb,aAAa,EAAE,MAAM,EACrB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,CAAC;CAiB5B;AAUD,2JAA2J;AAC3J,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,cAAc,EACd,WAAW,GAAG,mBAAmB,CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,OAAO,EAAE,qBAAqB,CAAC;IAC/B,IAAI,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAAC;IACvC,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BhB"}
|
package/dist/core/hub-session.js
CHANGED
|
@@ -111,6 +111,7 @@ export class HubSession {
|
|
|
111
111
|
this.deps.events.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
112
112
|
});
|
|
113
113
|
this.consume(session);
|
|
114
|
+
this.consumeDataFrames(session);
|
|
114
115
|
}
|
|
115
116
|
/**
|
|
116
117
|
* The single consumer of one hub session's own event stream: merges the hub's directory (its catch-up arrives as the first event, and it is refreshed on every subsequent one) and, once the session ends, drops the held connection so isConnected answers honestly.
|
|
@@ -156,6 +157,30 @@ export class HubSession {
|
|
|
156
157
|
}
|
|
157
158
|
})();
|
|
158
159
|
}
|
|
160
|
+
/** Consumes one hub session's inbound core/data frames until it ends, handing each one that came through a relay pairing to onRelayedDataFrame in arrival order. A failure in the handler is reported and the loop carries on, since one bad frame must not stop every later one. */
|
|
161
|
+
consumeDataFrames(session) {
|
|
162
|
+
void (async () => {
|
|
163
|
+
for await (const incoming of session.incomingDataFrames) {
|
|
164
|
+
if (this.deps.isShuttingDown())
|
|
165
|
+
break;
|
|
166
|
+
if (incoming.fromDevice === undefined)
|
|
167
|
+
continue;
|
|
168
|
+
await this.deps
|
|
169
|
+
.onRelayedDataFrame(deviceIdToHex(incoming.fromDevice), incoming.frame)
|
|
170
|
+
.catch((error) => {
|
|
171
|
+
this.deps.events.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
})();
|
|
175
|
+
}
|
|
176
|
+
/** Sends one core/data frame to a specific hub-reachable device through a relay pairing, sealed end to end with that device. Rejects when no hub session is live. */
|
|
177
|
+
async sendDataFrame(peerDeviceHex, frame) {
|
|
178
|
+
const session = this.session;
|
|
179
|
+
if (session === undefined) {
|
|
180
|
+
throw new Error("HubSession: no live hub session to send a data frame on");
|
|
181
|
+
}
|
|
182
|
+
await session.sendDataFrame(frame, hexToBytes(peerDeviceHex));
|
|
183
|
+
}
|
|
159
184
|
/** Sends a real core/room manage-request to a specific hub-reachable peer, through the hub's relay-connect/relay-data pairing -- the local-to-remote leg of agent-comms#155's routing, mirroring MeshTransport.sendRoomRequest's own not_connected/outcome contract so WireMeshTransport can fall back to this uniformly when memberId isn't a local peer session. Bounded by HUB_ROOM_REQUEST_TIMEOUT_MS (see its own doc) since an unreachable target-device is silently dropped by the hub with no error frame, unlike a local session's own connection-level failure. */
|
|
160
185
|
async sendRoomRequest(peerDeviceHex, command, scope, token) {
|
|
161
186
|
const session = this.session;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hub-session.js","sourceRoot":"","sources":["../../src/core/hub-session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"hub-session.js","sourceRoot":"","sources":["../../src/core/hub-session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,iBAAiB,GAMlB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAc9E,OAAO,EACL,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AA4C9D,MAAM,OAAO,UAAU;IAYQ;IAXrB,OAAO,CAAkC;IACjD,yGAAyG;IACjG,UAAU,CAAmC;IACrD,2IAA2I;IACnI,MAAM,CAAyB;IACvC,wLAAwL;IAChL,GAAG,CAAqB;IACf,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IACnD,4FAA4F;IAC3E,iBAAiB,GAAmB,EAAE,CAAC;IAExD,YAA6B,IAA8B;QAA9B,SAAI,GAAJ,IAAI,CAA0B;IAAG,CAAC;IAE/D,wFAAwF;IACxF,KAAK,CAAC,YAAY;QAChB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;QAC/C,OAAO,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,k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,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;aACtD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC1B,OAAO;IACT,CAAC;IAED,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,OAAO;aACV,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;aAClD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC1B,OAAO;IACT,CAAC;IAED,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,MAAM,GAA+B,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC;IAE7D,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;QAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAEtD,MAAM,IAAI,CAAC,iBAAiB,CAC1B,OAAO,EACP,MAAM,EACN,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAChE,CAAC;AACJ,CAAC"}
|
|
@@ -60,7 +60,7 @@ export declare class PeerLifecycle {
|
|
|
60
60
|
handlePeerDeparture(peerId: string): Promise<void>;
|
|
61
61
|
/** Races every other surviving peer to rebind the well-known port, which is what keeps the compatibility first-contact address answering after its holder CRASHES: unlike the graceful handover, a killed holder names no successor, so each survivor contests independently and the operating system's own exclusive bind decides the single winner. The winner runs the ordinary takeover path (handleBecomeCoordinator) over the peers it still holds connections to; a loser (the one case where the bind fails specifically because the port is already taken) re-introduces itself to the winner so it is a full member of the new mesh again, with its own data port known to whoever joins next. Direct peer-to-peer data connections are untouched throughout, so traffic between survivors never depends on the outcome of this race. */
|
|
62
62
|
private contestCoordinatorRole;
|
|
63
|
-
/** Re-introduces this side to whichever survivor won the bind race, over a fresh coordinator connection to the same well-known port. Without it this peer would keep its existing data connections but be unknown to the new coordinator, so it would never appear in the peer list handed to the next joiner.
|
|
63
|
+
/** Re-introduces this side to whichever survivor won the bind race, over a fresh coordinator connection to the same well-known port. Without it this peer would keep its existing data connections but be unknown to the new coordinator, so it would never appear in the peer list handed to the next joiner. Only a dial that reaches a different device than the lost holder counts as joining: the lost holder's listener can still be accepting while its transport closes, and a peer introduced to it would hold a session to a coordinator that is going away while nobody holds the port. Every dial failure is treated as unsettled rather than final for the same reason, since a connection torn down mid-handshake is what a closing listener produces; the caller answers by re-entering the bind race and reports the last failure only once it has run out of rounds. */
|
|
64
64
|
private rejoinUnderNewCoordinator;
|
|
65
65
|
/** Marks a departed peer's own agent offline and announces it, but only from the elected coordinator: the same single-authority rule StaleAgentChecker's PID probe already follows, so a departure produces one announcement rather than one per surviving peer. An agent's id is its peer's id (AgentRegistry.registerAgent), so the departed peer names its own record directly; the PID probe remains the backstop for an agent whose process dies without its session closing, and an already-offline record is left alone, so a successor that took over late announces nothing twice. */
|
|
66
66
|
private retireDepartedAgent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer-lifecycle.d.ts","sourceRoot":"","sources":["../../src/core/peer-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,eAAe,EAChB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"peer-lifecycle.d.ts","sourceRoot":"","sources":["../../src/core/peer-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAU5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,C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B,IAAI,IAAI;IAKxB;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAgCxC,qeAAqe;YACvd,eAAe;IAQ7B,cAAc,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,IAAI;IAUhD,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI;IAO1C,kBAAkB,CACtB,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,EAClC,GAAG,EAAE,QAAQ,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,GAClD,OAAO,CAAC,IAAI,CAAC;IAyBV,mBAAmB,CACvB,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,EAClC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,GACxB,OAAO,CAAC,IAAI,CAAC;IAkBV,iBAAiB,CACrB,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,EAClC,GAAG,EAAE,WAAW,GACf,OAAO,CAAC,IAAI,CAAC;IAQhB,yWAAyW;IACnW,uBAAuB,CAAC,QAAQ,EAAE,SAAS,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB3E,sBAAsB,CAAC,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,IAAI;IAIhE,kcAAkc;IAC5b,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWxD,mzBAAmzB;YACryB,sBAAsB;IA6CpC,y1BAAy1B;YAC30B,yBAAyB;IAyBvC,+jBAA+jB;YACjjB,mBAAmB;IAejC,miCAAmiC;IAC7hC,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;CAuB/C"}
|
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
* Two roles are kept apart here (agent-comms#341). The well-known port listener is only the compatibility first-contact address and introduction path, and is still passed on by graceful handover and recovered by the bind race. The coordinator duties (the stale-agent probe, single-authority departure announcements, the default cc-peer front) follow the elected CoordinatorRole instead, whose holder need not be the peer that bound the port.
|
|
5
5
|
*/
|
|
6
6
|
import { normaliseWireState } from "./wire-protocol.js";
|
|
7
|
-
import { isAddrInUse, isConnectionRefused } from "./bind-retry.js";
|
|
7
|
+
import { BECOME_COORDINATOR_BIND_RETRIES, BECOME_COORDINATOR_BIND_RETRY_DELAY_MS, isAddrInUse, isConnectionRefused, } from "./bind-retry.js";
|
|
8
|
+
import { ROOM_REQUEST_TIMEOUT_MS } from "./request-timeouts.js";
|
|
8
9
|
import { COORDINATOR_HOST } from "./mesh-store-shared.js";
|
|
9
10
|
import { startFirstContact } from "./first-contact.js";
|
|
10
11
|
/** The message an unknown thrown value is reported as, so a takeover or rejoin failure reads the same whether the transport rejected with an Error or something else. */
|
|
11
12
|
function describe(error) {
|
|
12
13
|
return error instanceof Error ? error.message : String(error);
|
|
13
14
|
}
|
|
14
|
-
/** How many times a peer that has lost its coordinator alternates between binding the vacated port and joining whoever bound it first.
|
|
15
|
-
const COORDINATOR_TAKEOVER_ROUNDS =
|
|
15
|
+
/** How many times a peer that has lost its coordinator alternates between binding the vacated port and joining whoever bound it first. A round that loses the bind has already spent a full becomeCoordinator retry window (BECOME_COORDINATOR_BIND_RETRIES attempts, BECOME_COORDINATOR_BIND_RETRY_DELAY_MS apart), so the rounds together are bounded by ROOM_REQUEST_TIMEOUT_MS, the ordinary bound on a peer completing a step. Several rounds are genuinely needed because the departed holder's own listener can outlast the sessions that reported its departure: its close only finishes once its transport has closed every session, which under load takes far longer than one retry window, and every bind and dial in that interval meets the dying listener. */
|
|
16
|
+
const COORDINATOR_TAKEOVER_ROUNDS = Math.ceil(ROOM_REQUEST_TIMEOUT_MS /
|
|
17
|
+
(BECOME_COORDINATOR_BIND_RETRIES * BECOME_COORDINATOR_BIND_RETRY_DELAY_MS));
|
|
16
18
|
export class PeerLifecycle {
|
|
17
19
|
deps;
|
|
18
20
|
/** Guards against a second contest running while the first is still binding or rejoining -- a coordinator whose process dies can close more than one session to this side, and each close arrives as its own disconnect. */
|
|
@@ -182,6 +184,7 @@ export class PeerLifecycle {
|
|
|
182
184
|
try {
|
|
183
185
|
const selfId = this.deps.getPeerId();
|
|
184
186
|
const survivors = [...this.deps.peerInfo.values()].filter((peer) => peer.id !== selfId && peer.id !== lostCoordinatorId);
|
|
187
|
+
let lastDialFailure;
|
|
185
188
|
for (let round = 0; round < COORDINATOR_TAKEOVER_ROUNDS; round++) {
|
|
186
189
|
try {
|
|
187
190
|
await this.handleBecomeCoordinator(survivors);
|
|
@@ -196,28 +199,35 @@ export class PeerLifecycle {
|
|
|
196
199
|
// A graceful handover racing this crash race can have made this side the coordinator while the bind above was in flight: the bind then fails against this side's own freshly bound listener, and dialling it would be this peer introducing itself to itself. Re-read through requireTransport() rather than the narrowed local, which TypeScript still believes is false from the guard at the top of this method.
|
|
197
200
|
if (this.deps.requireTransport().isCoordinator)
|
|
198
201
|
return;
|
|
199
|
-
|
|
202
|
+
const rejoin = await this.rejoinUnderNewCoordinator(selfId, lostCoordinatorId);
|
|
203
|
+
if (rejoin.outcome === "joined")
|
|
200
204
|
return;
|
|
205
|
+
lastDialFailure = rejoin.cause;
|
|
201
206
|
}
|
|
202
|
-
this.deps.onError?.(new Error(
|
|
207
|
+
this.deps.onError?.(new Error(`PeerLifecycle: the vacated coordinator port kept changing hands and this peer neither took it nor found a successor holding it${lastDialFailure === undefined ? "" : `; the last dial failed: ${lastDialFailure.message}`}`));
|
|
203
208
|
}
|
|
204
209
|
finally {
|
|
205
210
|
this.contestingCoordinatorRole = false;
|
|
206
211
|
}
|
|
207
212
|
}
|
|
208
|
-
/** Re-introduces this side to whichever survivor won the bind race, over a fresh coordinator connection to the same well-known port. Without it this peer would keep its existing data connections but be unknown to the new coordinator, so it would never appear in the peer list handed to the next joiner.
|
|
209
|
-
async rejoinUnderNewCoordinator(selfId) {
|
|
213
|
+
/** Re-introduces this side to whichever survivor won the bind race, over a fresh coordinator connection to the same well-known port. Without it this peer would keep its existing data connections but be unknown to the new coordinator, so it would never appear in the peer list handed to the next joiner. Only a dial that reaches a different device than the lost holder counts as joining: the lost holder's listener can still be accepting while its transport closes, and a peer introduced to it would hold a session to a coordinator that is going away while nobody holds the port. Every dial failure is treated as unsettled rather than final for the same reason, since a connection torn down mid-handshake is what a closing listener produces; the caller answers by re-entering the bind race and reports the last failure only once it has run out of rounds. */
|
|
214
|
+
async rejoinUnderNewCoordinator(selfId, lostCoordinatorId) {
|
|
210
215
|
const transport = this.deps.requireTransport();
|
|
211
216
|
try {
|
|
212
217
|
await transport.connectToCoordinator(COORDINATOR_HOST, this.deps.coordinatorPort, selfId, transport.dataPort);
|
|
213
|
-
return "joined";
|
|
214
218
|
}
|
|
215
219
|
catch (error) {
|
|
216
220
|
if (isConnectionRefused(error))
|
|
217
|
-
return "
|
|
218
|
-
|
|
219
|
-
|
|
221
|
+
return { outcome: "unsettled" };
|
|
222
|
+
return {
|
|
223
|
+
outcome: "unsettled",
|
|
224
|
+
cause: error instanceof Error ? error : new Error(describe(error)),
|
|
225
|
+
};
|
|
220
226
|
}
|
|
227
|
+
if (this.deps.requireTransport().coordinatorPeerId === lostCoordinatorId) {
|
|
228
|
+
return { outcome: "unsettled" };
|
|
229
|
+
}
|
|
230
|
+
return { outcome: "joined" };
|
|
221
231
|
}
|
|
222
232
|
/** Marks a departed peer's own agent offline and announces it, but only from the elected coordinator: the same single-authority rule StaleAgentChecker's PID probe already follows, so a departure produces one announcement rather than one per surviving peer. An agent's id is its peer's id (AgentRegistry.registerAgent), so the departed peer names its own record directly; the PID probe remains the backstop for an agent whose process dies without its session closing, and an already-offline record is left alone, so a successor that took over late announces nothing twice. */
|
|
223
233
|
async retireDepartedAgent(peerId) {
|