@culture.dev/agents 0.16.2 → 0.17.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/README.md +26 -3
- package/dist/contract-schemas/api.json +324 -1
- package/dist/contract-schemas/fleet.json +114 -0
- package/dist/contract-schemas/reachability.json +51 -0
- package/dist/contract-schemas/remote.json +150 -0
- package/dist/contract-schemas/run.json +17 -3
- package/dist/contract-schemas/unreadable.json +45 -0
- package/dist/contract-schemas/version.json +1 -1
- package/dist/src/contract/api.d.ts +10 -0
- package/dist/src/contract/api.js +18 -0
- package/dist/src/contract/api.js.map +1 -1
- package/dist/src/contract/generated/fleet.d.ts +50 -0
- package/dist/src/contract/generated/fleet.js +3 -0
- package/dist/src/contract/generated/fleet.js.map +1 -0
- package/dist/src/contract/generated/index.d.ts +24 -0
- package/dist/src/contract/generated/reachability.d.ts +20 -0
- package/dist/src/contract/generated/reachability.js +3 -0
- package/dist/src/contract/generated/reachability.js.map +1 -0
- package/dist/src/contract/generated/remote.d.ts +64 -0
- package/dist/src/contract/generated/remote.js +3 -0
- package/dist/src/contract/generated/remote.js.map +1 -0
- package/dist/src/contract/generated/run.d.ts +3 -1
- package/dist/src/contract/generated/unreadable.d.ts +15 -0
- package/dist/src/contract/generated/unreadable.js +3 -0
- package/dist/src/contract/generated/unreadable.js.map +1 -0
- package/dist/src/contract/generated/version.d.ts +1 -1
- package/dist/src/contract/index.d.ts +1 -1
- package/dist/src/contract/index.js +1 -1
- package/dist/src/contract/index.js.map +1 -1
- package/dist/src/daemon/daemon.d.ts +6 -0
- package/dist/src/daemon/daemon.js +2 -0
- package/dist/src/daemon/daemon.js.map +1 -1
- package/dist/src/daemon/fleet-routes.d.ts +40 -0
- package/dist/src/daemon/fleet-routes.js +111 -0
- package/dist/src/daemon/fleet-routes.js.map +1 -0
- package/dist/src/daemon/http.d.ts +2 -2
- package/dist/src/daemon/http.js +5 -4
- package/dist/src/daemon/http.js.map +1 -1
- package/dist/src/daemon/main.js +16 -1
- package/dist/src/daemon/main.js.map +1 -1
- package/dist/src/daemon/ports.d.ts +22 -4
- package/dist/src/daemon/routes.d.ts +6 -1
- package/dist/src/daemon/routes.js +34 -0
- package/dist/src/daemon/routes.js.map +1 -1
- package/dist/src/daemon/secrets.js +2 -0
- package/dist/src/daemon/secrets.js.map +1 -1
- package/dist/src/fleet/aliases.d.ts +17 -0
- package/dist/src/fleet/aliases.js +62 -0
- package/dist/src/fleet/aliases.js.map +1 -0
- package/dist/src/fleet/announce.d.ts +53 -0
- package/dist/src/fleet/announce.js +126 -0
- package/dist/src/fleet/announce.js.map +1 -0
- package/dist/src/fleet/bundle.d.ts +21 -0
- package/dist/src/fleet/bundle.js +88 -0
- package/dist/src/fleet/bundle.js.map +1 -0
- package/dist/src/fleet/cert.d.ts +43 -0
- package/dist/src/fleet/cert.js +110 -0
- package/dist/src/fleet/cert.js.map +1 -0
- package/dist/src/fleet/command.d.ts +5 -0
- package/dist/src/fleet/command.js +71 -0
- package/dist/src/fleet/command.js.map +1 -0
- package/dist/src/fleet/config.d.ts +36 -0
- package/dist/src/fleet/config.js +69 -0
- package/dist/src/fleet/config.js.map +1 -0
- package/dist/src/fleet/index.d.ts +69 -0
- package/dist/src/fleet/index.js +120 -0
- package/dist/src/fleet/index.js.map +1 -0
- package/dist/src/fleet/members.d.ts +47 -0
- package/dist/src/fleet/members.js +131 -0
- package/dist/src/fleet/members.js.map +1 -0
- package/dist/src/fleet/peers.d.ts +18 -0
- package/dist/src/fleet/peers.js +76 -0
- package/dist/src/fleet/peers.js.map +1 -0
- package/dist/src/fleet/remote-attach.d.ts +33 -0
- package/dist/src/fleet/remote-attach.js +109 -0
- package/dist/src/fleet/remote-attach.js.map +1 -0
- package/dist/src/fleet/remote.d.ts +85 -0
- package/dist/src/fleet/remote.js +115 -0
- package/dist/src/fleet/remote.js.map +1 -0
- package/dist/src/fleet/serve-runs.d.ts +56 -0
- package/dist/src/fleet/serve-runs.js +176 -0
- package/dist/src/fleet/serve-runs.js.map +1 -0
- package/dist/src/fleet/transport.d.ts +85 -0
- package/dist/src/fleet/transport.js +243 -0
- package/dist/src/fleet/transport.js.map +1 -0
- package/dist/src/fleet/trust.d.ts +35 -0
- package/dist/src/fleet/trust.js +136 -0
- package/dist/src/fleet/trust.js.map +1 -0
- package/dist/src/harness/stub/backend.js +3 -1
- package/dist/src/harness/stub/backend.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/runs/admission.d.ts +15 -0
- package/dist/src/runs/admission.js +24 -1
- package/dist/src/runs/admission.js.map +1 -1
- package/dist/src/runs/gateway.d.ts +1 -0
- package/dist/src/runs/gateway.js +4 -0
- package/dist/src/runs/gateway.js.map +1 -1
- package/dist/src/runs/keys.js +5 -3
- package/dist/src/runs/keys.js.map +1 -1
- package/dist/src/runs/service.d.ts +6 -5
- package/dist/src/runs/service.js +25 -14
- package/dist/src/runs/service.js.map +1 -1
- package/dist/src/runs/unreadable.d.ts +8 -0
- package/dist/src/runs/unreadable.js +64 -0
- package/dist/src/runs/unreadable.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { API_VERSION_HEADER, isPeerCompatible, parseApiVersion, parseMeshId, validate, } from "../contract/index.js";
|
|
2
|
+
import { matchAllowlist } from "../daemon/allowlist.js";
|
|
3
|
+
import { ControlError, invalid, notFound, unsupported } from "../daemon/errors.js";
|
|
4
|
+
import { checkBody, readJsonBody, sendJson } from "../daemon/http.js";
|
|
5
|
+
import { hostEnv, runCommand } from "../sandbox/host-command.js";
|
|
6
|
+
import { aliasList, resolveAlias } from "./aliases.js";
|
|
7
|
+
import { BUNDLE_TIMEOUT_MS, markUnredacted, serveRunBundle } from "./bundle.js";
|
|
8
|
+
import { MAX_PAGE_BYTES } from "./remote-attach.js";
|
|
9
|
+
import { allowReplyFor, FLEET_TIMEOUT_MS } from "./transport.js";
|
|
10
|
+
/** The most events one page over the fleet transport carries (the caller asks for fewer). */
|
|
11
|
+
export const MAX_MEMBER_PAGE = 50;
|
|
12
|
+
async function gitHasCommit(repo, sha) {
|
|
13
|
+
// `sha` is a 40-hex commit id (checked by the schema), never an option or a ref expression.
|
|
14
|
+
const res = await runCommand("git", ["cat-file", "-e", "--end-of-options", `${sha}^{commit}`], { cwd: repo, env: hostEnv() });
|
|
15
|
+
return res.code === 0;
|
|
16
|
+
}
|
|
17
|
+
/** Same MAJOR, any MINOR. Required on the remote-run routes; checked when present on the 3.1 routes (announce, members). */
|
|
18
|
+
export function checkPeerVersion(req, own, required = true) {
|
|
19
|
+
const raw = req.headers[API_VERSION_HEADER.toLowerCase()];
|
|
20
|
+
const caller = Array.isArray(raw) ? raw.join(",") : raw;
|
|
21
|
+
if (caller === undefined && !required)
|
|
22
|
+
return;
|
|
23
|
+
if (caller === undefined || parseApiVersion(caller) === null)
|
|
24
|
+
throw invalid(`A call between cores must carry the ${API_VERSION_HEADER} header as MAJOR.MINOR.`, API_VERSION_HEADER);
|
|
25
|
+
if (isPeerCompatible(caller, own))
|
|
26
|
+
return;
|
|
27
|
+
throw new ControlError("incompatible_version", `This core speaks API ${own} and the calling core ${caller}; cores call each other only within one MAJOR version.`, {
|
|
28
|
+
client_api_version: caller,
|
|
29
|
+
server_api_version: own,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** The run as another member sees it: no repository path. */
|
|
33
|
+
export function remoteView(run) {
|
|
34
|
+
if (run.submitter === undefined || run.base_commit === undefined)
|
|
35
|
+
throw new ControlError("internal", `Run ${run.id} has no recorded submitter or base commit.`);
|
|
36
|
+
const { id, agent_id, harness, state, terminal, cursor, submitter, base_commit, deadline, created_at, updated_at } = run;
|
|
37
|
+
return { id, agent_id, harness, state, terminal, cursor, submitter, base_commit, deadline, created_at, updated_at };
|
|
38
|
+
}
|
|
39
|
+
/** A run this member submitted, or `not_found` / `denied`. */
|
|
40
|
+
async function ownRun(c) {
|
|
41
|
+
const run = await c.d.service.getRun(c.runId);
|
|
42
|
+
if (!run)
|
|
43
|
+
throw notFound(`No run ${c.runId} on ${c.d.node}.`, { run_id: c.runId });
|
|
44
|
+
const by = run.submitter;
|
|
45
|
+
// A member is its key: a run recorded with one is matched by it, so a node name moved to another key
|
|
46
|
+
// inherits nothing. A run recorded before the key was kept is matched by node.
|
|
47
|
+
const sameKey = by?.key === undefined || by.key === c.member.fingerprint;
|
|
48
|
+
if (by?.kind !== "member" || by.node !== c.member.node || !sameKey) {
|
|
49
|
+
throw new ControlError("denied", `Run ${c.runId} on ${c.d.node} was not submitted by ${c.member.node}; a member acts only on the runs it submitted, and the operator of ${c.d.node} keeps control of every run.`);
|
|
50
|
+
}
|
|
51
|
+
return run;
|
|
52
|
+
}
|
|
53
|
+
/** The checks of a remote submit, in order, then the request the run service takes. */
|
|
54
|
+
async function localRequest(d, r) {
|
|
55
|
+
if (parseMeshId(r.agent_id)?.node !== d.node)
|
|
56
|
+
throw unsupported("placement", `Agent ${r.agent_id} is not on ${d.node}; a core runs only its own agents and never forwards a submit.`);
|
|
57
|
+
const aliased = resolveAlias(d.aliases(), r.alias);
|
|
58
|
+
if (aliased === null)
|
|
59
|
+
throw notFound(`${d.node} defines no alias ${r.alias}; its operator adds it to the fleet alias file (aliases.json).`);
|
|
60
|
+
const repo = matchAllowlist(d.allowlist().entries, { agent_id: r.agent_id, harness: r.harness, repo: aliased });
|
|
61
|
+
if (repo === null)
|
|
62
|
+
throw new ControlError("denied", `No allow-list entry on ${d.node} permits agent ${r.agent_id} with harness ${r.harness} on alias ${r.alias}; that host's operator must add one.`);
|
|
63
|
+
if (r.base_commit !== undefined && !(await (d.hasCommit ?? gitHasCommit)(repo, r.base_commit))) {
|
|
64
|
+
throw invalid(`The checkout that alias ${r.alias} names on ${d.node} has no commit ${r.base_commit}; push or fetch it there first (nothing was fetched).`, "/base_commit");
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
agent_id: r.agent_id,
|
|
68
|
+
harness: r.harness,
|
|
69
|
+
repo,
|
|
70
|
+
task: r.task,
|
|
71
|
+
caller: r.caller,
|
|
72
|
+
...(r.idempotency_key !== undefined && { idempotency_key: r.idempotency_key }),
|
|
73
|
+
// A duration, counted on this core's clock from acceptance: the caller's clock is never read (c42).
|
|
74
|
+
...(r.deadline_ms !== undefined && { deadline: new Date(d.now().getTime() + r.deadline_ms).toISOString() }),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
async function submit({ d, member, req, res }) {
|
|
78
|
+
const body = await readJsonBody(req);
|
|
79
|
+
checkBody("remote#submit_request", body);
|
|
80
|
+
const r = body;
|
|
81
|
+
const request = await localRequest(d, r);
|
|
82
|
+
const submitter = { kind: "member", node: member.node, key: member.fingerprint };
|
|
83
|
+
const sent = await d.service.submit(request, submitter, { keyNamespace: `member:${member.node}`, digestOf: r, remote: true, ...(r.base_commit !== undefined && { baseRef: r.base_commit }) });
|
|
84
|
+
return sendJson(res, 201, "remote#submit_response", { run: remoteView(sent.run), ...(sent.replayed === true && { replayed: true }), ...(sent.warnings && { warnings: sent.warnings }) });
|
|
85
|
+
}
|
|
86
|
+
function intParam(url, name, max, fallback) {
|
|
87
|
+
const raw = url.searchParams.get(name);
|
|
88
|
+
if (raw === null)
|
|
89
|
+
return fallback;
|
|
90
|
+
if (!/^\d{1,16}$/.test(raw) || Number(raw) > max)
|
|
91
|
+
throw invalid(`Query parameter ${name} must be an integer from 0 to ${max}.`, name);
|
|
92
|
+
return Number(raw);
|
|
93
|
+
}
|
|
94
|
+
/** The most one events page may hold, well under the caller's `MAX_PAGE_BYTES` read cap. */
|
|
95
|
+
export const PAGE_BUDGET_BYTES = MAX_PAGE_BYTES / 2;
|
|
96
|
+
/**
|
|
97
|
+
* `page` cut to the first events that fit `PAGE_BUDGET_BYTES`, with `more` set when any were left
|
|
98
|
+
* out. At least one event stays: one event's text is at most 100 000 characters, far under it.
|
|
99
|
+
*/
|
|
100
|
+
export function fitPage(page) {
|
|
101
|
+
let bytes = Buffer.byteLength(JSON.stringify({ ...page, events: [] }));
|
|
102
|
+
let kept = 0;
|
|
103
|
+
for (const event of page.events) {
|
|
104
|
+
const size = Buffer.byteLength(JSON.stringify(event)) + 1;
|
|
105
|
+
if (kept > 0 && bytes + size > PAGE_BUDGET_BYTES)
|
|
106
|
+
break;
|
|
107
|
+
bytes += size;
|
|
108
|
+
kept += 1;
|
|
109
|
+
}
|
|
110
|
+
return kept === page.events.length ? page : { ...page, events: page.events.slice(0, kept), more: true };
|
|
111
|
+
}
|
|
112
|
+
async function events(c) {
|
|
113
|
+
const run = await ownRun(c);
|
|
114
|
+
const after = intParam(c.url, "after", Number.MAX_SAFE_INTEGER, 0);
|
|
115
|
+
const limit = Math.max(1, intParam(c.url, "limit", MAX_MEMBER_PAGE, MAX_MEMBER_PAGE));
|
|
116
|
+
if (after > run.cursor)
|
|
117
|
+
throw invalid(`after (${after}) is beyond the run's newest cursor (${run.cursor}).`, "after");
|
|
118
|
+
const page = await c.d.service.readEvents(run.id, after, limit);
|
|
119
|
+
if (!page)
|
|
120
|
+
throw notFound(`No run ${run.id} on ${c.d.node}.`, { run_id: run.id });
|
|
121
|
+
markUnredacted(c.res);
|
|
122
|
+
return sendJson(c.res, 200, "event#event_page", fitPage(page));
|
|
123
|
+
}
|
|
124
|
+
async function control(c, kind) {
|
|
125
|
+
await ownRun(c);
|
|
126
|
+
const body = await readJsonBody(c.req);
|
|
127
|
+
checkBody(`control-action#${kind}_request`, body);
|
|
128
|
+
const options = { keyNamespace: `member:${c.member.node}` }; // as a remote submit's key: one namespace per member
|
|
129
|
+
const accepted = kind === "steer" ? await c.d.service.steer(c.runId, body, options) : await c.d.service.cancel(c.runId, body, options);
|
|
130
|
+
return sendJson(c.res, 202, "control-action#accepted_response", accepted);
|
|
131
|
+
}
|
|
132
|
+
const RUN_ROUTES = {
|
|
133
|
+
"GET ": async (c) => sendJson(c.res, 200, "remote", remoteView(await ownRun(c))),
|
|
134
|
+
"GET events": events,
|
|
135
|
+
"GET result": async (c) => sendJson(c.res, 200, "run#run_result", await c.d.service.getResult((await ownRun(c)).id)),
|
|
136
|
+
"GET bundle": async (c) => {
|
|
137
|
+
allowReplyFor(c.req, BUNDLE_TIMEOUT_MS + FLEET_TIMEOUT_MS); // git may take up to BUNDLE_TIMEOUT_MS
|
|
138
|
+
const run = await ownRun(c);
|
|
139
|
+
return serveRunBundle(run, await c.d.service.getResult(run.id), c.d.node, c.res);
|
|
140
|
+
},
|
|
141
|
+
"POST steer": (c) => control(c, "steer"),
|
|
142
|
+
"POST cancel": (c) => control(c, "cancel"),
|
|
143
|
+
};
|
|
144
|
+
/** The handler for `method path`, with the run id of the path as sent; null when it is none of these routes. */
|
|
145
|
+
function route(method, path) {
|
|
146
|
+
if (method === "POST" && path === "/v1/fleet/runs")
|
|
147
|
+
return { handler: submit, rawId: "" };
|
|
148
|
+
if (method === "GET" && path === "/v1/fleet/aliases")
|
|
149
|
+
return { handler: async (c) => sendJson(c.res, 200, "remote#alias_list", aliasList(c.d.node, c.d.aliases(), c.d.allowlist().entries)), rawId: "" };
|
|
150
|
+
const m = /^\/v1\/fleet\/runs\/([^/]+)(?:\/(events|result|bundle|steer|cancel))?$/.exec(path);
|
|
151
|
+
const handler = m ? RUN_ROUTES[`${method} ${m[2] ?? ""}`] : undefined;
|
|
152
|
+
return m && handler ? { handler, rawId: m[1] ?? "" } : null;
|
|
153
|
+
}
|
|
154
|
+
function runIdOf(raw) {
|
|
155
|
+
let runId;
|
|
156
|
+
try {
|
|
157
|
+
runId = decodeURIComponent(raw);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
throw invalid("The request path holds a malformed percent-encoding.");
|
|
161
|
+
}
|
|
162
|
+
if (!validate("common#run_id", runId).ok)
|
|
163
|
+
throw invalid("Path parameter run_id is malformed.", "run_id");
|
|
164
|
+
return runId;
|
|
165
|
+
}
|
|
166
|
+
/** Serve one remote-run route; false when `method path` is not one (the caller answers `not_found`). The version is checked first. */
|
|
167
|
+
export async function serveRuns(d, member, req, res, url) {
|
|
168
|
+
const found = route(req.method ?? "", url.pathname);
|
|
169
|
+
if (!found)
|
|
170
|
+
return false;
|
|
171
|
+
checkPeerVersion(req, d.apiVersion);
|
|
172
|
+
const runId = found.rawId === "" ? "" : runIdOf(found.rawId);
|
|
173
|
+
await found.handler({ d, member, req, res, url, runId });
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=serve-runs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-runs.js","sourceRoot":"","sources":["../../../src/fleet/serve-runs.ts"],"names":[],"mappings":"AAyBA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,QAAQ,GAOT,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAuB,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAmB,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGjE,6FAA6F;AAC7F,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAwBlC,KAAK,UAAU,YAAY,CAAC,IAAY,EAAE,GAAW;IACnD,4FAA4F;IAC5F,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,IAAI,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AAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IACzD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The network transport between cores (docs/d2/part-two-design.md, Decision 1), beside the Unix
|
|
3
|
+
* socket and off unless configured (fleet/config.ts). Node's standard library only.
|
|
4
|
+
*
|
|
5
|
+
* - TLS 1.3 only, authenticated in both directions. Each core presents the certificate derived in
|
|
6
|
+
* memory from its Ed25519 key (cert.ts) and trusts exactly the certificates in its trust list
|
|
7
|
+
* (trust.ts). A member is its key, not a name: the host name check is replaced by the trust check.
|
|
8
|
+
* - Server: the trust file is read again as each TCP connection arrives, before its handshake, and a
|
|
9
|
+
* changed list is installed with `setSecureContext`, so adding or removing a member takes effect on
|
|
10
|
+
* the next connection. After the handshake the peer's public key must match an entry of that list;
|
|
11
|
+
* otherwise the socket is destroyed and no request byte is read. Only then is the socket handed to
|
|
12
|
+
* the HTTP server. Every handshake has a timeout, every connection a request timeout, headers a cap.
|
|
13
|
+
* - No session resumption: `SSL_OP_NO_TICKET` stops the stateless ticket that would let a peer resume
|
|
14
|
+
* without presenting its certificate again (a reusable secret). In TLS 1.3 OpenSSL then still sends
|
|
15
|
+
* a stateful ticket, a session id, but Node keeps no server-side session cache unless asked to
|
|
16
|
+
* (no `newSession` listener here), so no session can be resumed. One connection per call, no keep-alive.
|
|
17
|
+
* - Client: it checks the server against its own trust list after the handshake and writes nothing
|
|
18
|
+
* before that check passes. Every call has one timeout and a cap on the response it reads.
|
|
19
|
+
*/
|
|
20
|
+
import { type KeyObject } from "node:crypto";
|
|
21
|
+
import { type IncomingMessage, type ServerResponse } from "node:http";
|
|
22
|
+
import { type TrustEntry, type TrustList } from "./trust.js";
|
|
23
|
+
/** One interval of the announcement (Decision 3): no handshake or call may take longer by default. */
|
|
24
|
+
export declare const FLEET_TIMEOUT_MS = 5000;
|
|
25
|
+
export declare const MAX_RESPONSE_BYTES: number;
|
|
26
|
+
export interface FleetServerOptions {
|
|
27
|
+
key: KeyObject;
|
|
28
|
+
trustPath: string;
|
|
29
|
+
/** An IP address (config.ts refuses a name). */
|
|
30
|
+
host: string;
|
|
31
|
+
/** 0 picks a free port (tests). */
|
|
32
|
+
port: number;
|
|
33
|
+
/** Called for each request of an authenticated member, never for anyone else. */
|
|
34
|
+
onRequest: (member: TrustEntry, req: IncomingMessage, res: ServerResponse) => void;
|
|
35
|
+
log: (line: string) => void;
|
|
36
|
+
handshakeTimeoutMs?: number;
|
|
37
|
+
requestTimeoutMs?: number;
|
|
38
|
+
maxConnections?: number;
|
|
39
|
+
/** The most connections one remote address may hold at once, before or after authentication (default 8). */
|
|
40
|
+
maxPerAddress?: number;
|
|
41
|
+
/** Refused and failed handshakes are logged at most once per address in this window (default 60 s). */
|
|
42
|
+
logEveryMs?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface FleetServer {
|
|
45
|
+
readonly address: {
|
|
46
|
+
host: string;
|
|
47
|
+
port: number;
|
|
48
|
+
};
|
|
49
|
+
stop(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
/** Start listening. Rejects when the address cannot be bound. */
|
|
52
|
+
export declare function startFleetServer(o: FleetServerOptions): Promise<FleetServer>;
|
|
53
|
+
/**
|
|
54
|
+
* Lift the idle limit of the socket a request came on, for a route whose reply takes longer than
|
|
55
|
+
* `FLEET_TIMEOUT_MS` to start (a run's bundle). The socket is still closed after `ms` idle.
|
|
56
|
+
*/
|
|
57
|
+
export declare function allowReplyFor(req: IncomingMessage, ms: number): void;
|
|
58
|
+
export declare class FleetCallError extends Error {
|
|
59
|
+
readonly code: "ETIMEDOUT" | "EUNTRUSTED" | "ETOOLARGE" | "ECLOSED";
|
|
60
|
+
readonly name = "FleetCallError";
|
|
61
|
+
constructor(code: "ETIMEDOUT" | "EUNTRUSTED" | "ETOOLARGE" | "ECLOSED", message: string);
|
|
62
|
+
}
|
|
63
|
+
export interface FleetCallOptions {
|
|
64
|
+
key: KeyObject;
|
|
65
|
+
trust: TrustList;
|
|
66
|
+
host: string;
|
|
67
|
+
port: number;
|
|
68
|
+
method: "GET" | "POST";
|
|
69
|
+
path: string;
|
|
70
|
+
body?: string;
|
|
71
|
+
/** When set, the server's key must be the one the trust list gives this node name. */
|
|
72
|
+
expectNode?: string;
|
|
73
|
+
/** Extra request headers (the remote calls send `Agents-Api-Version`). */
|
|
74
|
+
headers?: Readonly<Record<string, string>>;
|
|
75
|
+
timeoutMs?: number;
|
|
76
|
+
maxResponseBytes?: number;
|
|
77
|
+
}
|
|
78
|
+
export interface FleetResponse {
|
|
79
|
+
status: number;
|
|
80
|
+
body: Buffer;
|
|
81
|
+
/** The trust-list entry of the server that answered. */
|
|
82
|
+
member: TrustEntry;
|
|
83
|
+
}
|
|
84
|
+
/** One call to a member over one fresh connection. Rejects with `FleetCallError` or the socket's error. */
|
|
85
|
+
export declare function fleetCall(o: FleetCallOptions): Promise<FleetResponse>;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The network transport between cores (docs/d2/part-two-design.md, Decision 1), beside the Unix
|
|
3
|
+
* socket and off unless configured (fleet/config.ts). Node's standard library only.
|
|
4
|
+
*
|
|
5
|
+
* - TLS 1.3 only, authenticated in both directions. Each core presents the certificate derived in
|
|
6
|
+
* memory from its Ed25519 key (cert.ts) and trusts exactly the certificates in its trust list
|
|
7
|
+
* (trust.ts). A member is its key, not a name: the host name check is replaced by the trust check.
|
|
8
|
+
* - Server: the trust file is read again as each TCP connection arrives, before its handshake, and a
|
|
9
|
+
* changed list is installed with `setSecureContext`, so adding or removing a member takes effect on
|
|
10
|
+
* the next connection. After the handshake the peer's public key must match an entry of that list;
|
|
11
|
+
* otherwise the socket is destroyed and no request byte is read. Only then is the socket handed to
|
|
12
|
+
* the HTTP server. Every handshake has a timeout, every connection a request timeout, headers a cap.
|
|
13
|
+
* - No session resumption: `SSL_OP_NO_TICKET` stops the stateless ticket that would let a peer resume
|
|
14
|
+
* without presenting its certificate again (a reusable secret). In TLS 1.3 OpenSSL then still sends
|
|
15
|
+
* a stateful ticket, a session id, but Node keeps no server-side session cache unless asked to
|
|
16
|
+
* (no `newSession` listener here), so no session can be resumed. One connection per call, no keep-alive.
|
|
17
|
+
* - Client: it checks the server against its own trust list after the handshake and writes nothing
|
|
18
|
+
* before that check passes. Every call has one timeout and a cap on the response it reads.
|
|
19
|
+
*/
|
|
20
|
+
import { constants } from "node:crypto";
|
|
21
|
+
import { createServer as createHttpServer, request as httpRequest } from "node:http";
|
|
22
|
+
import { connect as tlsConnect, createServer as createTlsServer } from "node:tls";
|
|
23
|
+
import { certificateFor, fingerprint } from "./cert.js";
|
|
24
|
+
import { memberFor, trustSource } from "./trust.js";
|
|
25
|
+
/** One interval of the announcement (Decision 3): no handshake or call may take longer by default. */
|
|
26
|
+
export const FLEET_TIMEOUT_MS = 5000;
|
|
27
|
+
export const MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
28
|
+
const MAX_HEADER_BYTES = 16 * 1024;
|
|
29
|
+
function contextOptions(key, trust) {
|
|
30
|
+
return {
|
|
31
|
+
key: key.export({ type: "pkcs8", format: "pem" }),
|
|
32
|
+
cert: certificateFor(key).pem,
|
|
33
|
+
ca: trust.map((t) => t.pem), // always an array: never the system's root certificates
|
|
34
|
+
minVersion: "TLSv1.3",
|
|
35
|
+
maxVersion: "TLSv1.3",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const serverContext = (key, trust) => ({ ...contextOptions(key, trust), secureOptions: constants.SSL_OP_NO_TICKET });
|
|
39
|
+
/**
|
|
40
|
+
* A log that writes at most one line per key in each `everyMs` window; the rest are counted and the
|
|
41
|
+
* count is reported with the next line written. Keys older than a window are dropped as it grows.
|
|
42
|
+
*/
|
|
43
|
+
function windowedLog(log, everyMs) {
|
|
44
|
+
const seen = new Map();
|
|
45
|
+
return (key, line) => {
|
|
46
|
+
const now = Date.now();
|
|
47
|
+
const last = seen.get(key);
|
|
48
|
+
if (last && now - last.at < everyMs) {
|
|
49
|
+
last.dropped += 1;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (seen.size > 1000)
|
|
53
|
+
for (const [k, v] of seen)
|
|
54
|
+
if (now - v.at >= everyMs)
|
|
55
|
+
seen.delete(k);
|
|
56
|
+
seen.set(key, { at: now, dropped: 0 });
|
|
57
|
+
log(last && last.dropped > 0 ? `${line} (and ${last.dropped} more from this address in the last window)` : line);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const shortPrint = (fp) => fp?.slice(0, 16) ?? "none";
|
|
61
|
+
/** The trust-list entry of a peer whose handshake finished, or undefined after logging why it is refused. */
|
|
62
|
+
function admit(socket, trust, log) {
|
|
63
|
+
const peer = socket.getPeerX509Certificate();
|
|
64
|
+
const member = socket.authorized ? memberFor(peer, trust) : undefined;
|
|
65
|
+
if (member)
|
|
66
|
+
return member;
|
|
67
|
+
const reason = socket.authorized ? "not in the trust list" : String(socket.authorizationError ?? "no certificate");
|
|
68
|
+
log(`culture-agents core: fleet: refused a peer before reading any request (${reason}; key ${shortPrint(peer && fingerprint(peer))})`);
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
function listenOn(server, host, port) {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
server.once("error", reject);
|
|
74
|
+
server.listen({ host, port }, () => {
|
|
75
|
+
server.off("error", reject);
|
|
76
|
+
const bound = server.address();
|
|
77
|
+
resolve(typeof bound === "object" && bound ? bound.port : port);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/** Start listening. Rejects when the address cannot be bound. */
|
|
82
|
+
export async function startFleetServer(o) {
|
|
83
|
+
const source = trustSource(o.trustPath, (m) => o.log(`culture-agents core: fleet: ${m}`));
|
|
84
|
+
let current = source().list;
|
|
85
|
+
const members = new WeakMap();
|
|
86
|
+
const live = new Set(); // every TCP connection, authenticated or not, so a stop ends them all
|
|
87
|
+
const requestTimeoutMs = o.requestTimeoutMs ?? FLEET_TIMEOUT_MS;
|
|
88
|
+
const http = createHttpServer({ maxHeaderSize: MAX_HEADER_BYTES, requestTimeout: requestTimeoutMs, headersTimeout: requestTimeoutMs }, (req, res) => {
|
|
89
|
+
const member = members.get(req.socket);
|
|
90
|
+
res.setHeader("Connection", "close");
|
|
91
|
+
if (member)
|
|
92
|
+
o.onRequest(member, req, res);
|
|
93
|
+
else
|
|
94
|
+
res.destroy(); // unreachable: only checked sockets reach this server
|
|
95
|
+
});
|
|
96
|
+
http.maxRequestsPerSocket = 1;
|
|
97
|
+
const maxPerAddress = o.maxPerAddress ?? 8;
|
|
98
|
+
const perAddress = new Map();
|
|
99
|
+
const limited = windowedLog(o.log, o.logEveryMs ?? 60_000);
|
|
100
|
+
const tls = createTlsServer({ ...serverContext(o.key, current), requestCert: true, rejectUnauthorized: false, handshakeTimeout: o.handshakeTimeoutMs ?? FLEET_TIMEOUT_MS });
|
|
101
|
+
tls.maxConnections = o.maxConnections ?? 64;
|
|
102
|
+
// Before the TLS layer sees the connection: the trust list this handshake is checked against.
|
|
103
|
+
tls.prependListener("connection", (raw) => {
|
|
104
|
+
const address = raw.remoteAddress ?? "";
|
|
105
|
+
const held = perAddress.get(address) ?? 0;
|
|
106
|
+
if (held >= maxPerAddress) {
|
|
107
|
+
// Before any read: one address may not take the slots every member needs.
|
|
108
|
+
limited(address, `culture-agents core: fleet: refused a connection from ${address}: it already holds ${held}, the most one address may`);
|
|
109
|
+
raw.destroy();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
perAddress.set(address, held + 1);
|
|
113
|
+
live.add(raw);
|
|
114
|
+
raw.once("close", () => {
|
|
115
|
+
live.delete(raw);
|
|
116
|
+
const left = (perAddress.get(address) ?? 1) - 1;
|
|
117
|
+
if (left > 0)
|
|
118
|
+
perAddress.set(address, left);
|
|
119
|
+
else
|
|
120
|
+
perAddress.delete(address);
|
|
121
|
+
});
|
|
122
|
+
const { list, changed } = source();
|
|
123
|
+
current = list;
|
|
124
|
+
if (changed)
|
|
125
|
+
tls.setSecureContext(serverContext(o.key, list));
|
|
126
|
+
});
|
|
127
|
+
tls.on("secureConnection", (socket) => {
|
|
128
|
+
const member = admit(socket, current, (line) => limited(socket.remoteAddress ?? "", line));
|
|
129
|
+
if (!member) {
|
|
130
|
+
socket.destroy();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
members.set(socket, member);
|
|
134
|
+
socket.setTimeout(requestTimeoutMs, () => socket.destroy());
|
|
135
|
+
http.emit("connection", socket);
|
|
136
|
+
});
|
|
137
|
+
// With a listener here Node leaves the socket open (a handshake timeout included): close it.
|
|
138
|
+
tls.on("tlsClientError", (e, socket) => {
|
|
139
|
+
limited(socket.remoteAddress ?? "", `culture-agents core: fleet: a handshake failed (${e.code ?? e.message})`);
|
|
140
|
+
socket.destroy();
|
|
141
|
+
});
|
|
142
|
+
const port = await listenOn(tls, o.host, o.port);
|
|
143
|
+
tls.on("error", (e) => o.log(`culture-agents core: fleet: the listener reported an error: ${e.message}`));
|
|
144
|
+
let stopped = null;
|
|
145
|
+
const stop = () => {
|
|
146
|
+
stopped ??= new Promise((resolve) => {
|
|
147
|
+
tls.close(() => resolve());
|
|
148
|
+
for (const s of live)
|
|
149
|
+
s.destroy();
|
|
150
|
+
http.close();
|
|
151
|
+
});
|
|
152
|
+
return stopped;
|
|
153
|
+
};
|
|
154
|
+
return { address: { host: o.host, port }, stop };
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Lift the idle limit of the socket a request came on, for a route whose reply takes longer than
|
|
158
|
+
* `FLEET_TIMEOUT_MS` to start (a run's bundle). The socket is still closed after `ms` idle.
|
|
159
|
+
*/
|
|
160
|
+
export function allowReplyFor(req, ms) {
|
|
161
|
+
req.socket.setTimeout(ms);
|
|
162
|
+
}
|
|
163
|
+
// ---------------------------------------------------------------- client
|
|
164
|
+
export class FleetCallError extends Error {
|
|
165
|
+
code;
|
|
166
|
+
name = "FleetCallError";
|
|
167
|
+
constructor(code, message) {
|
|
168
|
+
super(message);
|
|
169
|
+
this.code = code;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** OpenSSL's verification codes: the server presented a certificate the trust list does not hold. */
|
|
173
|
+
const isTrustFailure = (e) => /CERT|SELF_SIGNED|UNABLE_TO_(GET|VERIFY)/.test(e.code ?? "");
|
|
174
|
+
/** The server's entry in the trust list, or why it is not trusted. */
|
|
175
|
+
function checkServer(socket, o) {
|
|
176
|
+
if (!socket.authorized)
|
|
177
|
+
return `the server's certificate is not in the trust list (${String(socket.authorizationError)})`;
|
|
178
|
+
const member = memberFor(socket.getPeerX509Certificate(), o.trust);
|
|
179
|
+
if (!member)
|
|
180
|
+
return "the server's key is not in the trust list";
|
|
181
|
+
if (o.expectNode !== undefined && member.node !== o.expectNode)
|
|
182
|
+
return `the server is ${member.node}, not ${o.expectNode}`;
|
|
183
|
+
return member;
|
|
184
|
+
}
|
|
185
|
+
function readCapped(res, max, member, finish) {
|
|
186
|
+
const declared = Number(res.headers["content-length"] ?? "0");
|
|
187
|
+
if (declared > max) {
|
|
188
|
+
finish(new FleetCallError("ETOOLARGE", `the response is larger than ${max} bytes`));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const chunks = [];
|
|
192
|
+
let total = 0;
|
|
193
|
+
res.on("data", (chunk) => {
|
|
194
|
+
total += chunk.length;
|
|
195
|
+
if (total > max)
|
|
196
|
+
finish(new FleetCallError("ETOOLARGE", `the response is larger than ${max} bytes`));
|
|
197
|
+
else
|
|
198
|
+
chunks.push(chunk);
|
|
199
|
+
});
|
|
200
|
+
res.on("end", () => finish(null, { status: res.statusCode ?? 0, body: Buffer.concat(chunks), member }));
|
|
201
|
+
res.on("error", (e) => finish(e));
|
|
202
|
+
}
|
|
203
|
+
function sendRequest(socket, member, o, finish) {
|
|
204
|
+
const headers = { ...o.headers, host: "culture-agents-fleet", connection: "close" };
|
|
205
|
+
if (o.body !== undefined) {
|
|
206
|
+
headers["content-type"] = "application/json";
|
|
207
|
+
headers["content-length"] = String(Buffer.byteLength(o.body));
|
|
208
|
+
}
|
|
209
|
+
const req = httpRequest({ createConnection: () => socket, method: o.method, path: o.path, headers });
|
|
210
|
+
req.on("response", (res) => readCapped(res, o.maxResponseBytes ?? MAX_RESPONSE_BYTES, member, finish));
|
|
211
|
+
req.on("error", (e) => finish(e));
|
|
212
|
+
req.end(o.body);
|
|
213
|
+
}
|
|
214
|
+
/** One call to a member over one fresh connection. Rejects with `FleetCallError` or the socket's error. */
|
|
215
|
+
export function fleetCall(o) {
|
|
216
|
+
return new Promise((resolve, reject) => {
|
|
217
|
+
const timeoutMs = o.timeoutMs ?? FLEET_TIMEOUT_MS;
|
|
218
|
+
const socket = tlsConnect({ ...contextOptions(o.key, o.trust), host: o.host, port: o.port, rejectUnauthorized: true, checkServerIdentity: () => undefined });
|
|
219
|
+
let settled = false;
|
|
220
|
+
const finish = (error, value) => {
|
|
221
|
+
if (settled)
|
|
222
|
+
return;
|
|
223
|
+
settled = true;
|
|
224
|
+
clearTimeout(timer);
|
|
225
|
+
socket.destroy();
|
|
226
|
+
if (error)
|
|
227
|
+
reject(error);
|
|
228
|
+
else if (value)
|
|
229
|
+
resolve(value);
|
|
230
|
+
};
|
|
231
|
+
const timer = setTimeout(() => finish(new FleetCallError("ETIMEDOUT", `no answer from the member within ${timeoutMs} ms`)), timeoutMs);
|
|
232
|
+
socket.once("secureConnect", () => {
|
|
233
|
+
const member = checkServer(socket, o);
|
|
234
|
+
if (typeof member === "string")
|
|
235
|
+
finish(new FleetCallError("EUNTRUSTED", member));
|
|
236
|
+
else
|
|
237
|
+
sendRequest(socket, member, o, finish);
|
|
238
|
+
});
|
|
239
|
+
socket.once("error", (e) => finish(isTrustFailure(e) ? new FleetCallError("EUNTRUSTED", `the server's certificate is not in the trust list (${e.code ?? ""})`) : e));
|
|
240
|
+
socket.once("close", () => finish(new FleetCallError("ECLOSED", "the member closed the connection")));
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/fleet/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,SAAS,EAAkB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,OAAO,IAAI,WAAW,EAA6C,MAAM,WAAW,CAAC;AAEhI,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,YAAY,IAAI,eAAe,EAA6C,MAAM,UAAU,CAAC;AAE7H,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAmC,MAAM,YAAY,CAAC;AAErF,sGAAsG;AACtG,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AACrC,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,GAAG,IAAI,CAAC;AAC9C,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,SAAS,cAAc,CAAC,GAAc,EAAE,KAAgB;IACtD,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QACjD,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG;QAC7B,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,wDAAwD;QACrF,UAAU,EAAE,SAAS;QACrB,UAAU,EAAE,SAAS;KACtB,CAAC;AACJ,CAAC;AAED,MAAM,aAAa,GAAG,CAAC,GAAc,EAAE,KAAgB,EAAwB,EAAE,CAAC,CAAC,EAAE,GAAG,cAAc,CAAC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,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,cAAc,CAAC,SAAS,EAAE,kCAAkC,CAAC,CAAC,CAAC,CAAC;IACxG,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { X509Certificate } from "node:crypto";
|
|
2
|
+
export interface TrustEntry {
|
|
3
|
+
readonly node: string;
|
|
4
|
+
/** The certificate's one-line form, as written in the file. */
|
|
5
|
+
readonly cert: string;
|
|
6
|
+
readonly pem: string;
|
|
7
|
+
/** SHA-256 of the member's public key, hex. */
|
|
8
|
+
readonly fingerprint: string;
|
|
9
|
+
}
|
|
10
|
+
export type TrustList = readonly TrustEntry[];
|
|
11
|
+
export declare class TrustConfigError extends Error {
|
|
12
|
+
readonly name = "TrustConfigError";
|
|
13
|
+
}
|
|
14
|
+
/** The most a trust file may hold. A member entry is about 300 bytes. */
|
|
15
|
+
export declare const MAX_TRUST_FILE_BYTES: number;
|
|
16
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
17
|
+
export declare function resolveTrustPath(env?: Env): string;
|
|
18
|
+
/** Parse the text of a trust file. Throws `TrustConfigError` on anything but a valid, unambiguous list. */
|
|
19
|
+
export declare function parseTrust(text: string, path: string): TrustList;
|
|
20
|
+
/** The file's text, read with a cap; null when it does not exist. */
|
|
21
|
+
export declare function readTrustText(path: string): string | null;
|
|
22
|
+
/** The trust list in `path`; empty when the file does not exist (nobody is trusted). */
|
|
23
|
+
export declare function loadTrust(path: string): TrustList;
|
|
24
|
+
/** The entry for a peer's certificate, matched on its public key; undefined when the peer is not a member. */
|
|
25
|
+
export declare function memberFor(peer: X509Certificate | undefined, trust: TrustList): TrustEntry | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* A trust list read again on every call, for the transport's per-connection check. When the file
|
|
28
|
+
* changes to something invalid, the list is empty (every peer refused) and `onError` says why.
|
|
29
|
+
* `changed` tells the caller to install the new list in the TLS context.
|
|
30
|
+
*/
|
|
31
|
+
export declare function trustSource(path: string, onError: (message: string) => void): () => {
|
|
32
|
+
list: TrustList;
|
|
33
|
+
changed: boolean;
|
|
34
|
+
};
|
|
35
|
+
export {};
|