agent-comms 9.0.14 → 9.1.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 -0
- package/dist/core/bridge-mesh.d.ts.map +1 -1
- package/dist/core/bridge-mesh.js +1 -0
- package/dist/core/bridge-mesh.js.map +1 -1
- package/dist/core/data-frame-routing.d.ts +18 -2
- package/dist/core/data-frame-routing.d.ts.map +1 -1
- package/dist/core/data-frame-routing.js +93 -26
- package/dist/core/data-frame-routing.js.map +1 -1
- package/dist/core/ledger-gaps.d.ts +68 -0
- package/dist/core/ledger-gaps.d.ts.map +1 -0
- package/dist/core/ledger-gaps.js +170 -0
- package/dist/core/ledger-gaps.js.map +1 -0
- package/dist/core/tool.d.ts +6 -0
- package/dist/core/tool.d.ts.map +1 -1
- package/dist/core/tool.js +18 -1
- package/dist/core/tool.js.map +1 -1
- package/dist/core/wire-mesh-transport.d.ts +3 -2
- package/dist/core/wire-mesh-transport.d.ts.map +1 -1
- package/dist/core/wire-mesh-transport.js +1 -1
- package/dist/core/wire-mesh-transport.js.map +1 -1
- package/package.json +2 -2
- package/src/core/bridge-mesh.ts +1 -0
- package/src/core/data-frame-routing.ts +113 -26
- package/src/core/ledger-gaps.ts +234 -0
- package/src/core/tool.ts +30 -0
- package/src/core/wire-mesh-transport.ts +2 -2
package/README.md
CHANGED
|
@@ -601,3 +601,5 @@ npx agent-comms account import ~/account.bundle # on the other machine, then d
|
|
|
601
601
|
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.
|
|
602
602
|
|
|
603
603
|
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. A ledger entry that cannot be read does not stop the rest of it being read, so listing and revoking a device's grants still work. Each unreadable entry is reported once, naming its log and position, and is listed by `whoami`. It may hold a grant or a revocation: a grant recorded only in it is not revoked, and a revocation recorded only in it is not applied on this machine, until the entry is repaired or replaced from another machine's replica of the account. A removal or a `dm_revoke` that skipped one says so and is reported as incomplete, never as a clean success, and a bridge that starts with one reports that revocations may be missing.
|
|
604
|
+
|
|
605
|
+
A machine that stays behind a writer log notices it. Each replication round it compares this side's head of every log with the highest head a live peer of the account announced for it, and a log that stays behind for three rounds in a row with no new entry arriving is reported on the error output and listed by `whoami` and `update`, one line per log: `Account ledger log <log id> is behind: this machine holds up to entry <n>, a peer announces <m>, and <r> rounds have passed without the missing entries arriving; a grant or a revocation in them is not applied here`. At most eight such lines are printed, then `Account ledger: <k> more logs are behind`. That wording is part of the interface and changes only with a release that says so. The same gap is reported again only when it has grown and ten rounds have passed since the last report, and every peer that announced a higher head is asked again for the missing entries on each round the stall lasts. A round counts towards a stall unless this machine reached no peer of the account in it: an offer that fails or goes unanswered at one device never stops the count while another device is reached. At most 256 logs are tracked, preferring logs this machine already holds, and a head more than a million entries ahead of this machine's is ignored and reported once. What this cannot detect: a single path that withholds everything, including the head of the log, since the head is learned from the same frames; a log beyond the 256 tracked that this machine holds nothing of; a head more than a million entries ahead; a log that is behind but still advancing, since each new entry restarts the count; and any round in which this machine reaches no peer of the account at all. Bounding what a withheld log can cost takes a shorter lifetime for the grants themselves.
|
|
@@ -1 +1 @@
|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ACtS,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC5B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,cAAc,CAMhB;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC5B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,cAAc,CA0EhB;AAED,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC5B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,UAAU,CAAC,CAIrB;AAED,6JAA6J;AAC7J,wBAAsB,4BAA4B,CAChD,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC5B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,UAAU,CAAC,CAQrB"}
|
package/dist/core/bridge-mesh.js
CHANGED
|
@@ -79,6 +79,7 @@ export function createBridgeMeshSyncFromIdentity(identity, slot, options) {
|
|
|
79
79
|
naming: store.naming,
|
|
80
80
|
getNewerVersionIfAny: () => versionChecker.getNewerVersionIfAny(),
|
|
81
81
|
getUnreadableLedgerEntries: () => store.accountLedger?.unreadableEntries().length ?? 0,
|
|
82
|
+
getStalledLedgerLogs: () => transport.dataFrames.stalledLogs(),
|
|
82
83
|
});
|
|
83
84
|
const revocation = createRevocationView();
|
|
84
85
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-mesh.js","sourceRoot":"","sources":["../../src/core/bridge-mesh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,O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AAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAA4B,EAC5B,OAA2B;IAE3B,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5E,MAAM,cAAc,EAAE,CAAC;IACvB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC;AAED,6JAA6J;AAC7J,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,QAAsB,EACtB,IAA4B,EAC5B,OAA2B;IAE3B,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,gCAAgC,CACtE,QAAQ,EACR,IAAI,EACJ,OAAO,CACR,CAAC;IACF,MAAM,cAAc,EAAE,CAAC;IACvB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -6,6 +6,7 @@ import type { DataHaveFrame, DataRequestFrame, Frame } from "wire-mesh-core/gene
|
|
|
6
6
|
import type { Connection } from "wire-mesh-core/ports/transport";
|
|
7
7
|
import type { KeyValueStorage } from "wire-mesh-core/ports/storage";
|
|
8
8
|
import type { AccountLedgerReplica } from "./account-ledger.js";
|
|
9
|
+
import { LedgerGapTracker, type StalledLedgerLog } from "./ledger-gaps.js";
|
|
9
10
|
import type { WireMeshTransportOptions } from "./wire-mesh-transport-options.js";
|
|
10
11
|
/** 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. */
|
|
11
12
|
export declare const DATA_ENTRIES_RESPONSE_LIMIT = 100;
|
|
@@ -36,22 +37,31 @@ export declare function routeDataFrame(deps: Readonly<{
|
|
|
36
37
|
dataStorage: KeyValueStorage | undefined;
|
|
37
38
|
account: Readonly<AccountReplication> | undefined;
|
|
38
39
|
peerSessions: ReadonlyMap<string, unknown>;
|
|
40
|
+
gaps?: Pick<LedgerGapTracker, "noteHave"> | undefined;
|
|
39
41
|
onError: ((error: Error) => void) | undefined;
|
|
40
42
|
}>, connection: Readonly<Connection>, frame: Frame): Promise<void>;
|
|
41
43
|
/** 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
44
|
export declare function routeRelayedDataFrame(deps: Readonly<{
|
|
43
45
|
account: Readonly<AccountReplication> | undefined;
|
|
44
46
|
hub: Readonly<HubDataChannel> | undefined;
|
|
47
|
+
gaps?: Pick<LedgerGapTracker, "noteHave"> | undefined;
|
|
45
48
|
onError: ((error: Error) => void) | undefined;
|
|
46
49
|
}>, fromDeviceHex: string, frame: Readonly<DataDomainFrame>): Promise<void>;
|
|
47
|
-
/**
|
|
50
|
+
/** What one round of offering the account ledger found out. */
|
|
51
|
+
export interface LedgerOfferRound {
|
|
52
|
+
/** Whether this side reached any device of the account: an offer went out to at least one, or there was nothing to offer and a device was there to offer it to. False means this machine is offline as far as the account goes, which says nothing about whether any peer withholds anything; an offer to one device that failed does not make it false while another got through. */
|
|
53
|
+
reached: boolean;
|
|
54
|
+
/** This side's head sequence of each log it holds, by log id hex, read once for the round. */
|
|
55
|
+
localHeads: ReadonlyMap<string, number>;
|
|
56
|
+
}
|
|
57
|
+
/** 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 through onError and the rest carry on; the next round retries it. Resolves with whether any device was reached and with this side's heads, read once. */
|
|
48
58
|
export declare function announceAccountLedger(deps: Readonly<{
|
|
49
59
|
connectionsByPeer: ReadonlyMap<string, Readonly<Connection>>;
|
|
50
60
|
account: Readonly<AccountReplication>;
|
|
51
61
|
hub: Readonly<HubDataChannel> | undefined;
|
|
52
62
|
peerSessions: ReadonlyMap<string, unknown>;
|
|
53
63
|
onError: ((error: Error) => void) | undefined;
|
|
54
|
-
}>): Promise<
|
|
64
|
+
}>): Promise<LedgerOfferRound>;
|
|
55
65
|
export interface DataFrameRouterDeps {
|
|
56
66
|
dataStorage: KeyValueStorage | undefined;
|
|
57
67
|
/** Absent for a transport with no account ledger. */
|
|
@@ -72,9 +82,15 @@ export declare class DataFrameRouter {
|
|
|
72
82
|
/** 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. */
|
|
73
83
|
private readonly connectionsByPeer;
|
|
74
84
|
private announceInterval;
|
|
85
|
+
/** What each peer says the account's writer logs reach, and the rounds this side has stayed behind it. Undefined for a transport with no account ledger. */
|
|
86
|
+
private readonly gaps;
|
|
75
87
|
/** 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
88
|
private announcing;
|
|
77
89
|
constructor(deps: Readonly<DataFrameRouterDeps>);
|
|
90
|
+
/** Sends a data-request to one source, over its direct session when it has one and through the relay hub otherwise. */
|
|
91
|
+
private requestFrom;
|
|
92
|
+
/** The account ledger's logs this side has stayed behind for several rounds, for whoami. Empty when there is no account ledger. */
|
|
93
|
+
stalledLogs(): StalledLedgerLog[];
|
|
78
94
|
/** See routeDataFrame. */
|
|
79
95
|
route(connection: Readonly<Connection>, frame: Frame): Promise<void>;
|
|
80
96
|
/** See routeRelayedDataFrame. An arrow property, so the transport can hand it to the hub session as a callback. */
|
|
@@ -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,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,KAAK,EACN,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAEjF,iNAAiN;AACjN,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C,uFAAuF;AACvF,MAAM,WAAW,kBAAkB;IACjC,wMAAwM;IACxM,MAAM,EAAE,MAAM,oBAAoB,GAAG,SAAS,CAAC;IAC/C,wOAAwO;IACxO,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACxD;AAED,8MAA8M;AAC9M,MAAM,WAAW,cAAc;IAC7B,+HAA+H;IAC/H,KAAK,EAAE,MAAM,SAAS,MAAM,EAAE,CAAC;IAC/B,2FAA2F;IAC3F,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACpE;AAED,+JAA+J;AAC/J,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM;IACT,KAAK,EAAE,MAAM,SAAS,MAAM,EAAE,CAAC;IAC/B,aAAa,EAAE,CACb,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,KAC7B,OAAO,CAAC,IAAI,CAAC,C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,EAAE;IAIjC,0BAA0B;IACpB,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1E,mHAAmH;IACnH,QAAQ,CAAC,YAAY,GACnB,eAAe,MAAM,EACrB,OAAO,QAAQ,CAAC,eAAe,CAAC,KAC/B,OAAO,CAAC,IAAI,CAAC,CAWd;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"}
|
|
@@ -2,9 +2,10 @@
|
|
|
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
4
|
import { handleDataEntries, handleDataHave, handleDataRequest, } from "wire-mesh-core/domain/data-sync";
|
|
5
|
-
import { deviceIdToHex } from "wire-mesh-core/domain/device-id";
|
|
5
|
+
import { bytesToHex, deviceIdToHex } from "wire-mesh-core/domain/device-id";
|
|
6
6
|
import { isDataFrame } from "wire-mesh-core/domain/hub-mailbox";
|
|
7
7
|
import { readMembershipProof } from "./gossip-directory.js";
|
|
8
|
+
import { LedgerGapTracker } from "./ledger-gaps.js";
|
|
8
9
|
/** 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
10
|
export const DATA_ENTRIES_RESPONSE_LIMIT = 100;
|
|
10
11
|
/** 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. */
|
|
@@ -48,6 +49,9 @@ export async function routeDataFrame(deps, connection, frame) {
|
|
|
48
49
|
ledger.ownsLog(frame.peer)) {
|
|
49
50
|
if (!(await deps.account.isAccountPeer(deviceIdHex)))
|
|
50
51
|
return;
|
|
52
|
+
if (frame.type === "data-have") {
|
|
53
|
+
deps.gaps?.noteHave(deviceIdHex, frame.peer, frame["head-seq"]);
|
|
54
|
+
}
|
|
51
55
|
const reply = await ledger.handleDataFrame(frame);
|
|
52
56
|
if (reply !== null)
|
|
53
57
|
await connection.send(reply);
|
|
@@ -84,6 +88,9 @@ export async function routeRelayedDataFrame(deps, fromDeviceHex, frame) {
|
|
|
84
88
|
return;
|
|
85
89
|
if (!(await account.isAccountPeer(fromDeviceHex)))
|
|
86
90
|
return;
|
|
91
|
+
if (frame.type === "data-have") {
|
|
92
|
+
deps.gaps?.noteHave(fromDeviceHex, frame.peer, frame["head-seq"]);
|
|
93
|
+
}
|
|
87
94
|
const reply = await ledger.handleDataFrame(frame);
|
|
88
95
|
if (reply !== null)
|
|
89
96
|
await hub.send(fromDeviceHex, reply);
|
|
@@ -92,28 +99,44 @@ export async function routeRelayedDataFrame(deps, fromDeviceHex, frame) {
|
|
|
92
99
|
deps.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
93
100
|
}
|
|
94
101
|
}
|
|
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. */
|
|
102
|
+
/** 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 through onError and the rest carry on; the next round retries it. Resolves with whether any device was reached and with this side's heads, read once. */
|
|
96
103
|
export async function announceAccountLedger(deps) {
|
|
97
104
|
const ledger = deps.account.ledger();
|
|
98
105
|
if (ledger === undefined)
|
|
99
|
-
return;
|
|
106
|
+
return { reached: false, localHeads: new Map() };
|
|
100
107
|
const frames = await ledger.announcements();
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
const localHeads = new Map();
|
|
109
|
+
for (const frame of frames) {
|
|
110
|
+
localHeads.set(bytesToHex(frame.peer), frame["head-seq"]);
|
|
111
|
+
}
|
|
112
|
+
let devices = 0;
|
|
113
|
+
let sent = 0;
|
|
103
114
|
const reportError = (error) => {
|
|
104
115
|
deps.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
105
116
|
};
|
|
117
|
+
// A device whose membership cannot be read is reported and skipped: one device that makes this throw must not stop the round from being counted.
|
|
118
|
+
const isAccountPeer = async (deviceHex) => {
|
|
119
|
+
try {
|
|
120
|
+
return await deps.account.isAccountPeer(deviceHex);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
reportError(error);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
106
127
|
const direct = new Set();
|
|
107
128
|
const offers = [];
|
|
108
129
|
for (const [deviceHex, connection] of deps.connectionsByPeer) {
|
|
109
130
|
if (!deps.peerSessions.has(deviceHex))
|
|
110
131
|
continue;
|
|
111
|
-
if (!(await
|
|
132
|
+
if (!(await isAccountPeer(deviceHex)))
|
|
112
133
|
continue;
|
|
113
134
|
direct.add(deviceHex);
|
|
135
|
+
devices += 1;
|
|
114
136
|
for (const frame of frames) {
|
|
115
137
|
try {
|
|
116
138
|
await connection.send(frame);
|
|
139
|
+
sent += 1;
|
|
117
140
|
}
|
|
118
141
|
catch (error) {
|
|
119
142
|
reportError(error);
|
|
@@ -121,26 +144,39 @@ export async function announceAccountLedger(deps) {
|
|
|
121
144
|
}
|
|
122
145
|
}
|
|
123
146
|
const { hub } = deps;
|
|
124
|
-
if (hub
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
if (hub !== undefined) {
|
|
148
|
+
let hubPeers = [];
|
|
149
|
+
try {
|
|
150
|
+
hubPeers = hub.peers();
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
reportError(error);
|
|
154
|
+
}
|
|
155
|
+
for (const deviceHex of hubPeers) {
|
|
156
|
+
if (direct.has(deviceHex))
|
|
157
|
+
continue;
|
|
158
|
+
if (!(await isAccountPeer(deviceHex)))
|
|
159
|
+
continue;
|
|
160
|
+
devices += 1;
|
|
161
|
+
// 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.
|
|
162
|
+
offers.push((async () => {
|
|
163
|
+
for (const frame of frames) {
|
|
164
|
+
try {
|
|
165
|
+
await hub.send(deviceHex, frame);
|
|
166
|
+
sent += 1;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
reportError(error);
|
|
170
|
+
}
|
|
139
171
|
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
172
|
+
})());
|
|
173
|
+
}
|
|
142
174
|
}
|
|
143
175
|
await Promise.all(offers);
|
|
176
|
+
return {
|
|
177
|
+
reached: sent > 0 || (frames.length === 0 && devices > 0),
|
|
178
|
+
localHeads,
|
|
179
|
+
};
|
|
144
180
|
}
|
|
145
181
|
/** 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. */
|
|
146
182
|
export class DataFrameRouter {
|
|
@@ -150,6 +186,8 @@ export class DataFrameRouter {
|
|
|
150
186
|
/** 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. */
|
|
151
187
|
connectionsByPeer = new Map();
|
|
152
188
|
announceInterval;
|
|
189
|
+
/** What each peer says the account's writer logs reach, and the rounds this side has stayed behind it. Undefined for a transport with no account ledger. */
|
|
190
|
+
gaps;
|
|
153
191
|
/** 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
192
|
announcing = false;
|
|
155
193
|
constructor(deps) {
|
|
@@ -158,10 +196,22 @@ export class DataFrameRouter {
|
|
|
158
196
|
const { account } = deps;
|
|
159
197
|
if (account === undefined)
|
|
160
198
|
return;
|
|
199
|
+
const gaps = new LedgerGapTracker({
|
|
200
|
+
request: async (source, frame) => this.requestFrom(source, frame),
|
|
201
|
+
isLive: (source) => deps.peerSessions.has(source) ||
|
|
202
|
+
(deps.hub?.peers().includes(source) ?? false),
|
|
203
|
+
onError: (error) => {
|
|
204
|
+
deps.onError?.(error);
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
this.gaps = gaps;
|
|
161
208
|
this.announceInterval = setInterval(() => {
|
|
162
209
|
if (this.announcing)
|
|
163
210
|
return;
|
|
164
211
|
this.announcing = true;
|
|
212
|
+
const report = (error) => {
|
|
213
|
+
deps.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
214
|
+
};
|
|
165
215
|
announceAccountLedger({
|
|
166
216
|
connectionsByPeer: this.connectionsByPeer,
|
|
167
217
|
account,
|
|
@@ -169,15 +219,30 @@ export class DataFrameRouter {
|
|
|
169
219
|
peerSessions: deps.peerSessions,
|
|
170
220
|
onError: deps.onError,
|
|
171
221
|
})
|
|
172
|
-
.
|
|
173
|
-
|
|
174
|
-
})
|
|
222
|
+
.then(async (offered) => gaps.round(offered.localHeads, { offline: !offered.reached }))
|
|
223
|
+
.catch(report)
|
|
175
224
|
.finally(() => {
|
|
176
225
|
this.announcing = false;
|
|
177
226
|
});
|
|
178
227
|
}, deps.announceIntervalMs);
|
|
179
228
|
this.announceInterval.unref();
|
|
180
229
|
}
|
|
230
|
+
/** Sends a data-request to one source, over its direct session when it has one and through the relay hub otherwise. */
|
|
231
|
+
async requestFrom(source, frame) {
|
|
232
|
+
const connection = this.connectionsByPeer.get(source);
|
|
233
|
+
if (connection !== undefined && this.deps.peerSessions.has(source)) {
|
|
234
|
+
await connection.send(frame);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (this.deps.hub === undefined) {
|
|
238
|
+
throw new Error(`no route to ${source} to ask it for ledger entries`);
|
|
239
|
+
}
|
|
240
|
+
await this.deps.hub.send(source, frame);
|
|
241
|
+
}
|
|
242
|
+
/** The account ledger's logs this side has stayed behind for several rounds, for whoami. Empty when there is no account ledger. */
|
|
243
|
+
stalledLogs() {
|
|
244
|
+
return this.gaps?.stalled() ?? [];
|
|
245
|
+
}
|
|
181
246
|
/** See routeDataFrame. */
|
|
182
247
|
async route(connection, frame) {
|
|
183
248
|
await routeDataFrame({
|
|
@@ -185,6 +250,7 @@ export class DataFrameRouter {
|
|
|
185
250
|
dataStorage: this.dataStorage,
|
|
186
251
|
account: this.deps.account,
|
|
187
252
|
peerSessions: this.deps.peerSessions,
|
|
253
|
+
gaps: this.gaps,
|
|
188
254
|
onError: this.deps.onError,
|
|
189
255
|
}, connection, frame);
|
|
190
256
|
}
|
|
@@ -193,6 +259,7 @@ export class DataFrameRouter {
|
|
|
193
259
|
await routeRelayedDataFrame({
|
|
194
260
|
account: this.deps.account,
|
|
195
261
|
hub: this.deps.hub,
|
|
262
|
+
gaps: this.gaps,
|
|
196
263
|
onError: this.deps.onError,
|
|
197
264
|
}, fromDeviceHex, frame);
|
|
198
265
|
};
|
|
@@ -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;
|
|
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,UAAU,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAUhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAyB,MAAM,kBAAkB,CAAC;AAG3E,iNAAiN;AACjN,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAkB/C,+JAA+J;AAC/J,MAAM,UAAU,cAAc,CAC5B,GAMC;IAED,OAAO;QACL,KAAK,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE;QAC1B,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC;KACxE,CAAC;AACJ,CAAC;AAED,sRAAsR;AACtR,MAAM,UAAU,sBAAsB,CACpC,OAAiE,EACjE,QAEkD;IAElD,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC5C,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,SAAS;QACzB,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;YACjC,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;YACnC,MAAM,KAAK,G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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"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gap detection for the account ledger's replicated writer logs (agent-comms#344), with no wire change. A `data-have` frame already carries the head sequence of the log it names, so each machine can see how far every peer says a log goes. A machine that stays behind that head for several rounds in a row, while the entries it asks for do not arrive, has a log something is withholding or dropping: a revocation could be in the missing part.
|
|
3
|
+
*
|
|
4
|
+
* What is kept: for each log, each live source's own announced head. A source is a peer this side reached over a direct session or over the relay hub. Each replication round compares those heads with this side's own and counts the rounds a log has stayed behind without advancing. At LEDGER_STALL_ROUNDS the log is reported as stalled, and again only if the gap grew and LEDGER_REPORT_REPEAT_ROUNDS rounds have passed, and the entries are asked of every source that announced a higher head, not only the one that answered first. A log that catches up, or whose announcing sources have gone, is forgotten.
|
|
5
|
+
*
|
|
6
|
+
* What is bounded: the logs tracked (MAX_TRACKED_LEDGER_LOGS, preferring logs this side already holds), how far ahead of this side's head an announced head may be (MAX_ANNOUNCED_HEAD_DISTANCE), how many reports of an ignored announcement are remembered, and how often a repeated report is made. Reports of ignored announcements are remembered apart from the logs, so forgetting a log never makes a report repeat.
|
|
7
|
+
*
|
|
8
|
+
* What it cannot see: a single path that withholds everything, including the higher head, since the head is learned from the same frames; a log beyond the tracked limit that this side does not hold; a head more than MAX_ANNOUNCED_HEAD_DISTANCE ahead, which is ignored; a log that is slow but still advancing, which is never behind for LEDGER_STALL_ROUNDS rounds without moving; and a machine that reaches no peer of the account at all, whose rounds are not counted.
|
|
9
|
+
*/
|
|
10
|
+
import type { DataRequestFrame } from "wire-mesh-core/generated/protocol";
|
|
11
|
+
/** How many consecutive replication rounds a log may stay behind an announced head, without a new entry arriving, before it is reported as stalled. */
|
|
12
|
+
export declare const LEDGER_STALL_ROUNDS = 3;
|
|
13
|
+
/** How many rounds pass before a gap that has grown since it was last reported is reported again, so a peer that raises its head every round gets one report per interval and not one per round. */
|
|
14
|
+
export declare const LEDGER_REPORT_REPEAT_ROUNDS = 10;
|
|
15
|
+
/** The most writer logs tracked at once. The account's logs are one per machine that ever wrote, so this is far above any real account. At the limit a log this side holds takes the place of one it does not, and any other log announced is not tracked, which is reported at most once per LEDGER_REPORT_REPEAT_ROUNDS rounds. */
|
|
16
|
+
export declare const MAX_TRACKED_LEDGER_LOGS = 256;
|
|
17
|
+
/** The furthest an announced head may be ahead of this side's own and still be believed. Heads count ledger entries, which are grants and revocations, and a reply carries a bounded batch, so a head further ahead than this is not an honest gap: it is not recorded, and is reported once. */
|
|
18
|
+
export declare const MAX_ANNOUNCED_HEAD_DISTANCE = 1000000;
|
|
19
|
+
/** A log this side is behind, reported once it has stayed so for LEDGER_STALL_ROUNDS rounds. */
|
|
20
|
+
export interface StalledLedgerLog {
|
|
21
|
+
/** The writer log's id, hex. */
|
|
22
|
+
log: string;
|
|
23
|
+
/** This side's head sequence for it. */
|
|
24
|
+
localHead: number;
|
|
25
|
+
/** The highest head any live source announced. */
|
|
26
|
+
announcedHead: number;
|
|
27
|
+
/** The rounds it has stayed behind. */
|
|
28
|
+
rounds: number;
|
|
29
|
+
}
|
|
30
|
+
/** What the tracker needs from its owner. */
|
|
31
|
+
export interface LedgerGapDeps {
|
|
32
|
+
/** Sends a request for the entries after `frame["from-seq"]` of a log to one source, directly or through the hub. A rejection is reported and does not stop the others. */
|
|
33
|
+
request: (source: string, frame: Readonly<DataRequestFrame>) => Promise<void>;
|
|
34
|
+
/** Whether a source is still reachable: its announced heads are forgotten when it is not. */
|
|
35
|
+
isLive: (source: string) => boolean;
|
|
36
|
+
/** Where a stall is reported, and a failed request. */
|
|
37
|
+
onError: (error: Error) => void;
|
|
38
|
+
}
|
|
39
|
+
/** What a round is told about how it went. */
|
|
40
|
+
export interface LedgerRoundOptions {
|
|
41
|
+
/** True when this machine reached no peer of the account this round: no offer went out, so nothing was asked of anyone. The round still notices a log that has caught up, but it is not counted as a round the log stayed behind. */
|
|
42
|
+
offline?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare class LedgerGapTracker {
|
|
45
|
+
private readonly deps;
|
|
46
|
+
private readonly logs;
|
|
47
|
+
private roundNumber;
|
|
48
|
+
private overLimitReportedAtRound;
|
|
49
|
+
/** The logs this side held at the last round, which a log announced at the tracking limit is preferred for. */
|
|
50
|
+
private held;
|
|
51
|
+
/** The `log:source` of every out-of-range announcement reported, oldest first, kept apart from the logs so that a log forgotten and announced again is not reported again. */
|
|
52
|
+
private readonly reportedOutOfRange;
|
|
53
|
+
constructor(deps: Readonly<LedgerGapDeps>);
|
|
54
|
+
/** Records the head `source` announced for a log. Called for every `data-have` an account peer sends for one of the account's logs. */
|
|
55
|
+
noteHave(source: string, log: Uint8Array, head: number): void;
|
|
56
|
+
/** Makes room for a log at the tracking limit by dropping a tracked log this side holds nothing of, and only when this side holds the new one. */
|
|
57
|
+
private makeRoomFor;
|
|
58
|
+
private reportOverLimit;
|
|
59
|
+
/** Remembers that an out-of-range announcement was reported, and whether it had been before. */
|
|
60
|
+
private firstReportOfOutOfRange;
|
|
61
|
+
/**
|
|
62
|
+
* One replication round: compares every announced head with this side's (`localHeads`, by log id hex, absent for a log this side holds nothing of), counts the rounds each log stays behind without advancing, and on reaching LEDGER_STALL_ROUNDS reports it and asks every source that announced a higher head for the entries. Resolves once the requests have been sent.
|
|
63
|
+
*/
|
|
64
|
+
round(localHeads: ReadonlyMap<string, number>, options?: Readonly<LedgerRoundOptions>): Promise<void>;
|
|
65
|
+
/** The logs that have stayed behind for LEDGER_STALL_ROUNDS rounds or more as of the last round, for whoami. */
|
|
66
|
+
stalled(): StalledLedgerLog[];
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=ledger-gaps.d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