@uuaid/pillar 2.7.2 → 2.7.3
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 +9 -0
- package/bin/pillar-directory.mjs +43 -95
- package/package.json +1 -1
- package/src/registry/directory-flags.mjs +182 -0
- package/src/registry/stats.mjs +1 -1
- package/src/vnext/verify-cli.mjs +1 -1
package/README.md
CHANGED
|
@@ -746,6 +746,15 @@ a UUAID is read as a file.
|
|
|
746
746
|
> `0` refuses every listing for a lineage the registry does not list yet,
|
|
747
747
|
> and still accepts updates to listed ones.
|
|
748
748
|
>
|
|
749
|
+
> From 2.7.3, `pillar-directory` exits 2 when it cannot use a flag or a
|
|
750
|
+
> value: an unknown flag, a flag with no value, a number that is out of
|
|
751
|
+
> range or not written in digits, or an empty `DIRECTORY_*` variable.
|
|
752
|
+
> `--flag value` and `--flag=value` are the same. The line after
|
|
753
|
+
> `listening on` shows the limits in effect (`limits: ...
|
|
754
|
+
> --max-new-lineages-per-hour 20 ...`); check it after each start.
|
|
755
|
+
> 2.7.2 and earlier ignore `--max-new-lineages-per-hour=0` and use 600:
|
|
756
|
+
> there, write `--max-new-lineages-per-hour 0`.
|
|
757
|
+
>
|
|
749
758
|
> Agents, carriers and private registries can use 2.7.1 or later. The UUAID
|
|
750
759
|
> registry at pillar.uuaid.org is upgraded separately; until then it does
|
|
751
760
|
> not answer /v1/resolve.
|
package/bin/pillar-directory.mjs
CHANGED
|
@@ -35,21 +35,12 @@ import { SeedRegistry } from "../src/net/seed-registry.mjs";
|
|
|
35
35
|
import { clientIpOf, parseTrustedProxies } from "../src/net/client-ip.mjs";
|
|
36
36
|
import { Keychain, mintNamespace, SERVICE_IDENTITY_NAMESPACE } from "../src/identity/keychain.mjs";
|
|
37
37
|
import { tryLoadBetterSqlite3 } from "../src/sqlite-loader.mjs";
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
DEFAULT_MAX_STRIKES,
|
|
41
|
-
DEFAULT_NEGATIVE_CACHE_TTL_MS,
|
|
42
|
-
DEFAULT_PULL_INTERVAL_MS,
|
|
43
|
-
DEFAULT_QUARANTINE_COOLDOWN_MS,
|
|
44
|
-
DEFAULT_RESOLVE_TIMEOUT_MS,
|
|
45
|
-
FederationCoordinator,
|
|
46
|
-
makeResolveMissRateLimiter,
|
|
47
|
-
openRegistryDb,
|
|
48
|
-
} from "../src/registry/federation.mjs";
|
|
38
|
+
import { FederationCoordinator, makeResolveMissRateLimiter, openRegistryDb } from "../src/registry/federation.mjs";
|
|
39
|
+
import { formatDirectoryLimits, parseDirectoryArgs } from "../src/registry/directory-flags.mjs";
|
|
49
40
|
import { GossipCoordinator } from "../src/registry/gossip.mjs";
|
|
50
41
|
import { HeartbeatStore } from "../src/registry/heartbeats.mjs";
|
|
51
42
|
import { LineageStore, isStrictDateTime } from "../src/registry/lineage.mjs";
|
|
52
|
-
import { ListingStore, isStrictHttpsUri,
|
|
43
|
+
import { ListingStore, isStrictHttpsUri, startTombstonePruning } from "../src/registry/listings.mjs";
|
|
53
44
|
import { handleRegistryRoute } from "../src/registry/resolve.mjs";
|
|
54
45
|
import {
|
|
55
46
|
buildRegistryStats,
|
|
@@ -60,32 +51,6 @@ import {
|
|
|
60
51
|
} from "../src/registry/stats.mjs";
|
|
61
52
|
import { exitWithHelp, wantsHelp } from "../src/cli-help.mjs";
|
|
62
53
|
|
|
63
|
-
function parsePeersArg(raw) {
|
|
64
|
-
if (!raw || typeof raw !== "string") return [];
|
|
65
|
-
const trimmed = raw.trim();
|
|
66
|
-
if (!trimmed) return [];
|
|
67
|
-
if (trimmed.startsWith("[")) {
|
|
68
|
-
const parsed = JSON.parse(trimmed);
|
|
69
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
70
|
-
}
|
|
71
|
-
return trimmed
|
|
72
|
-
.split(",")
|
|
73
|
-
.map((s) => s.trim())
|
|
74
|
-
.filter(Boolean);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function parseArgs(argv) {
|
|
78
|
-
const args = {};
|
|
79
|
-
for (let i = 0; i < argv.length; i++) {
|
|
80
|
-
const a = argv[i];
|
|
81
|
-
if (a.startsWith("--")) {
|
|
82
|
-
const k = a.slice(2);
|
|
83
|
-
args[k] = (argv[i + 1] && !argv[i + 1].startsWith("--")) ? argv[++i] : true;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return args;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
54
|
const USAGE = `usage: pillar-directory [flags]
|
|
90
55
|
|
|
91
56
|
Serves directory.json and the seed registry. Listens on 127.0.0.1 by default.
|
|
@@ -108,68 +73,50 @@ More flags (limits, federation timers, test hooks): --protocol, --allow-private-
|
|
|
108
73
|
--max-listings-per-ip-per-hour, --max-lineage-posts-per-ip-per-hour,
|
|
109
74
|
--max-heartbeats-per-ip-per-hour, --pull-interval-ms, --max-strikes,
|
|
110
75
|
--quarantine-cooldown-ms, --resolve-timeout-ms, --resolve-negative-ttl-ms,
|
|
111
|
-
--max-resolve-misses-per-ip-per-minute. Routes: see the header of bin/pillar-directory.mjs
|
|
76
|
+
--max-resolve-misses-per-ip-per-minute. Routes: see the header of bin/pillar-directory.mjs.
|
|
77
|
+
|
|
78
|
+
--flag value and --flag=value are the same. An unknown flag, a flag with no value,
|
|
79
|
+
a number that is not a whole number in range (digits only) or an empty DIRECTORY_*
|
|
80
|
+
variable exits 2 before anything is written. After "listening on" a line shows
|
|
81
|
+
the limits in effect.`;
|
|
112
82
|
if (wantsHelp(process.argv.slice(2))) await exitWithHelp(USAGE); // R2: before the registry key is minted or the db is opened
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
const
|
|
83
|
+
// 2.7.3 (V1 c9da71 P3): every flag and DIRECTORY_* value is checked here, before
|
|
84
|
+
// the registry key is minted or the db is opened; one it cannot use exits 2.
|
|
85
|
+
const parsed = parseDirectoryArgs(process.argv.slice(2), process.env);
|
|
86
|
+
if (!parsed.ok) {
|
|
87
|
+
console.error(`pillar-directory: ${parsed.error.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`)}. See pillar-directory --help.`);
|
|
88
|
+
process.exit(2);
|
|
89
|
+
}
|
|
90
|
+
const opts = parsed.values;
|
|
91
|
+
const home = opts.home ?? join(homedir(), ".pillar-directory");
|
|
92
|
+
const port = opts.port;
|
|
93
|
+
const host = opts.host ?? "127.0.0.1";
|
|
94
|
+
const dbPath = opts.db ?? join(home, "registry.db");
|
|
95
|
+
const carrier = opts.carrier ?? null;
|
|
96
|
+
const agentsPath = opts.agents ?? null;
|
|
97
|
+
const protocol = opts.protocol ?? "uacp/1.0-draft";
|
|
98
|
+
const probeMinutes = opts["probe-minutes"];
|
|
99
|
+
const allowPrivateUrls = opts["allow-private-urls"];
|
|
100
|
+
const publicUrlArg = opts["public-url"] ?? null;
|
|
101
|
+
const urlMap = opts.urlMap;
|
|
102
|
+
const clockFile = opts["clock-file"] ?? null;
|
|
127
103
|
const getNow = () => {
|
|
128
104
|
if (!clockFile || !existsSync(clockFile)) return undefined;
|
|
129
105
|
const raw = readFileSync(clockFile, "utf-8").trim();
|
|
130
106
|
return isStrictDateTime(raw) ? raw : undefined;
|
|
131
107
|
};
|
|
132
|
-
const stampBits =
|
|
133
|
-
const maxNewLineagesPerHour =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const maxLineagePostsPerIpPerHour = Number(
|
|
145
|
-
args["max-lineage-posts-per-ip-per-hour"] ??
|
|
146
|
-
process.env.DIRECTORY_MAX_LINEAGE_POSTS_PER_IP_PER_HOUR ??
|
|
147
|
-
DEFAULT_MAX_LINEAGE_POSTS_PER_IP_PER_HOUR,
|
|
148
|
-
);
|
|
149
|
-
const maxHeartbeatsPerIpPerHour = Number(
|
|
150
|
-
args["max-heartbeats-per-ip-per-hour"] ??
|
|
151
|
-
process.env.DIRECTORY_MAX_HEARTBEATS_PER_IP_PER_HOUR ??
|
|
152
|
-
DEFAULT_MAX_HEARTBEATS_PER_IP_PER_HOUR,
|
|
153
|
-
);
|
|
154
|
-
const configuredPeers = parsePeersArg(args.peers ?? args.peer ?? process.env.DIRECTORY_PEERS ?? "");
|
|
155
|
-
const pullIntervalMs = Number(
|
|
156
|
-
args["pull-interval-ms"] ?? process.env.DIRECTORY_PULL_INTERVAL_MS ?? DEFAULT_PULL_INTERVAL_MS,
|
|
157
|
-
);
|
|
158
|
-
const maxStrikes = Number(args["max-strikes"] ?? process.env.DIRECTORY_MAX_STRIKES ?? DEFAULT_MAX_STRIKES);
|
|
159
|
-
const quarantineCooldownMs = Number(
|
|
160
|
-
args["quarantine-cooldown-ms"] ?? process.env.DIRECTORY_QUARANTINE_COOLDOWN_MS ?? DEFAULT_QUARANTINE_COOLDOWN_MS,
|
|
161
|
-
);
|
|
162
|
-
const resolveTimeoutMs = Number(
|
|
163
|
-
args["resolve-timeout-ms"] ?? process.env.DIRECTORY_RESOLVE_TIMEOUT_MS ?? DEFAULT_RESOLVE_TIMEOUT_MS,
|
|
164
|
-
);
|
|
165
|
-
const negativeCacheTtlMs = Number(
|
|
166
|
-
args["resolve-negative-ttl-ms"] ?? process.env.DIRECTORY_RESOLVE_NEGATIVE_TTL_MS ?? DEFAULT_NEGATIVE_CACHE_TTL_MS,
|
|
167
|
-
);
|
|
168
|
-
const maxResolveMissesPerIpPerMinute = Number(
|
|
169
|
-
args["max-resolve-misses-per-ip-per-minute"] ??
|
|
170
|
-
process.env.DIRECTORY_MAX_RESOLVE_MISSES_PER_IP_PER_MINUTE ??
|
|
171
|
-
DEFAULT_MAX_RESOLVE_MISSES_PER_IP_PER_MINUTE,
|
|
172
|
-
);
|
|
108
|
+
const stampBits = opts["stamp-bits"];
|
|
109
|
+
const maxNewLineagesPerHour = opts["max-new-lineages-per-hour"];
|
|
110
|
+
const maxListingsPerIpPerHour = opts["max-listings-per-ip-per-hour"];
|
|
111
|
+
const maxLineagePostsPerIpPerHour = opts["max-lineage-posts-per-ip-per-hour"];
|
|
112
|
+
const maxHeartbeatsPerIpPerHour = opts["max-heartbeats-per-ip-per-hour"];
|
|
113
|
+
const configuredPeers = opts.peerList;
|
|
114
|
+
const pullIntervalMs = opts["pull-interval-ms"];
|
|
115
|
+
const maxStrikes = opts["max-strikes"];
|
|
116
|
+
const quarantineCooldownMs = opts["quarantine-cooldown-ms"];
|
|
117
|
+
const resolveTimeoutMs = opts["resolve-timeout-ms"];
|
|
118
|
+
const negativeCacheTtlMs = opts["resolve-negative-ttl-ms"];
|
|
119
|
+
const maxResolveMissesPerIpPerMinute = opts["max-resolve-misses-per-ip-per-minute"];
|
|
173
120
|
|
|
174
121
|
const MAX_ENROLLMENTS_PER_HOUR = 10; // per client IP
|
|
175
122
|
const MAX_BODY = 8 * 1024;
|
|
@@ -334,7 +281,7 @@ function readBody(req) {
|
|
|
334
281
|
|
|
335
282
|
// X-Forwarded-For counts only from a trusted proxy (2.5.3; src/net/client-ip.mjs).
|
|
336
283
|
let trustedProxies;
|
|
337
|
-
try { trustedProxies = parseTrustedProxies(
|
|
284
|
+
try { trustedProxies = parseTrustedProxies(opts["trusted-proxy"]); }
|
|
338
285
|
catch (e) { console.error(`pillar-directory: ${e.message}`); process.exit(2); }
|
|
339
286
|
const clientIp = (req) => clientIpOf(req, trustedProxies);
|
|
340
287
|
|
|
@@ -461,6 +408,7 @@ if (configuredPeers.length > 0 && pullIntervalMs > 0) {
|
|
|
461
408
|
federationCoordinator.start();
|
|
462
409
|
}
|
|
463
410
|
console.log(`pillar-directory listening on http://${formatHostForUrl(host)}:${boundPort}`);
|
|
411
|
+
console.log(` limits: ${formatDirectoryLimits(opts)}`);
|
|
464
412
|
console.log(` uuaid: ${registry.uuaid}`);
|
|
465
413
|
console.log(` issuer: ${registry.issuerKey}`);
|
|
466
414
|
console.log(` carrier: ${carrier ?? "(none — set --carrier)"}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uuaid/pillar",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.3",
|
|
4
4
|
"description": "Pillar (Protocol for Inter-agent Linked Ledger And Relay) — the secure delivery layer of UACP, the Universal Agent Communication Protocol. UACP = UUAID (identity) + Envelope (signed, encrypted container) + Pillar (relay, mailbox, routing, store-and-forward). Reference implementation of the UACP delivery layer; includes VDA-1 (IAASO-3901, in ballot) delivery attestation and a blind escrow for the Zilligon ZGN / EVM rails.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pillar-directory flags and environment (2.7.3, V1 c9da71 P3).
|
|
3
|
+
*
|
|
4
|
+
* Before 2.7.3 the bin stored `--k=v` under the key "k=v" and ignored it,
|
|
5
|
+
* ignored unknown flags, and read every limit with a bare Number(): a flag
|
|
6
|
+
* with no value gave 1, "abc" gave NaN (no registry-wide cap), an empty
|
|
7
|
+
* environment variable gave 0. None of it was visible. Now:
|
|
8
|
+
*
|
|
9
|
+
* - `--k=v` means the same as `--k v`; a value that starts with "-" must
|
|
10
|
+
* use the `=` form.
|
|
11
|
+
* - An unknown flag, a bare word, a boolean flag given a value, or a value
|
|
12
|
+
* flag given none is refused.
|
|
13
|
+
* - Every numeric flag and environment variable must be a whole number in
|
|
14
|
+
* its range, written as digits only ("0x10", "1e3", " 5", "-1" refused).
|
|
15
|
+
* - A DIRECTORY_* variable set to "" is refused (never a deliberate
|
|
16
|
+
* setting), as pillar-seed refuses its SEED_* ones.
|
|
17
|
+
* - --peers and --url-map must parse.
|
|
18
|
+
*
|
|
19
|
+
* parseDirectoryArgs never exits: the bin prints the error on one line and
|
|
20
|
+
* exits 2 before the registry key is minted or the db is opened.
|
|
21
|
+
*/
|
|
22
|
+
import {
|
|
23
|
+
DEFAULT_MAX_RESOLVE_MISSES_PER_IP_PER_MINUTE,
|
|
24
|
+
DEFAULT_MAX_STRIKES,
|
|
25
|
+
DEFAULT_NEGATIVE_CACHE_TTL_MS,
|
|
26
|
+
DEFAULT_PULL_INTERVAL_MS,
|
|
27
|
+
DEFAULT_QUARANTINE_COOLDOWN_MS,
|
|
28
|
+
DEFAULT_RESOLVE_TIMEOUT_MS,
|
|
29
|
+
} from "./federation.mjs";
|
|
30
|
+
import { MAX_NEW_LINEAGES_PER_HOUR } from "./listings.mjs";
|
|
31
|
+
|
|
32
|
+
/** Node clamps a longer timer to 1 ms, so a timer setting above this would fire at once. */
|
|
33
|
+
export const TIMER_MAX_MS = 2 ** 31 - 1;
|
|
34
|
+
const COUNT_MAX = 1_000_000;
|
|
35
|
+
|
|
36
|
+
const str = (flag, env) => ({ flag, env, kind: "string" });
|
|
37
|
+
const bool = (flag) => ({ flag, env: null, kind: "bool" });
|
|
38
|
+
const int = (flag, env, def, min, max) => ({ flag, env, kind: "int", def, min, max });
|
|
39
|
+
|
|
40
|
+
/** Every flag pillar-directory reads, in --help order. Numeric ones carry their default and range. */
|
|
41
|
+
export const DIRECTORY_FLAGS = Object.freeze([
|
|
42
|
+
str("home", "DIRECTORY_HOME"),
|
|
43
|
+
str("db", "DIRECTORY_DB"),
|
|
44
|
+
int("port", "DIRECTORY_PORT", 8800, 0, 65535),
|
|
45
|
+
str("host", "DIRECTORY_HOST"),
|
|
46
|
+
str("carrier", "DIRECTORY_CARRIER"),
|
|
47
|
+
str("agents", "DIRECTORY_AGENTS"),
|
|
48
|
+
str("public-url", "DIRECTORY_PUBLIC_URL"),
|
|
49
|
+
str("peers", "DIRECTORY_PEERS"),
|
|
50
|
+
str("peer", null), // older spelling of --peers
|
|
51
|
+
str("trusted-proxy", "DIRECTORY_TRUSTED_PROXIES"),
|
|
52
|
+
int("probe-minutes", "DIRECTORY_PROBE_MINUTES", 10, 1, Math.floor(TIMER_MAX_MS / 60_000)),
|
|
53
|
+
bool("help"),
|
|
54
|
+
str("protocol", "DIRECTORY_PROTOCOL"),
|
|
55
|
+
bool("allow-private-urls"),
|
|
56
|
+
str("url-map", "DIRECTORY_URL_MAP"),
|
|
57
|
+
str("clock-file", null),
|
|
58
|
+
int("stamp-bits", "DIRECTORY_STAMP_BITS", 18, 12, 24),
|
|
59
|
+
int("max-new-lineages-per-hour", "DIRECTORY_MAX_NEW_LINEAGES_PER_HOUR", MAX_NEW_LINEAGES_PER_HOUR, 0, COUNT_MAX),
|
|
60
|
+
int("max-listings-per-ip-per-hour", "DIRECTORY_MAX_LISTINGS_PER_IP_PER_HOUR", 60, 0, COUNT_MAX),
|
|
61
|
+
int("max-lineage-posts-per-ip-per-hour", "DIRECTORY_MAX_LINEAGE_POSTS_PER_IP_PER_HOUR", 300, 0, COUNT_MAX),
|
|
62
|
+
int("max-heartbeats-per-ip-per-hour", "DIRECTORY_MAX_HEARTBEATS_PER_IP_PER_HOUR", 120, 0, COUNT_MAX),
|
|
63
|
+
int("max-resolve-misses-per-ip-per-minute", "DIRECTORY_MAX_RESOLVE_MISSES_PER_IP_PER_MINUTE", DEFAULT_MAX_RESOLVE_MISSES_PER_IP_PER_MINUTE, 0, COUNT_MAX),
|
|
64
|
+
int("pull-interval-ms", "DIRECTORY_PULL_INTERVAL_MS", DEFAULT_PULL_INTERVAL_MS, 0, TIMER_MAX_MS),
|
|
65
|
+
int("max-strikes", "DIRECTORY_MAX_STRIKES", DEFAULT_MAX_STRIKES, 1, 1000),
|
|
66
|
+
int("quarantine-cooldown-ms", "DIRECTORY_QUARANTINE_COOLDOWN_MS", DEFAULT_QUARANTINE_COOLDOWN_MS, 0, TIMER_MAX_MS),
|
|
67
|
+
int("resolve-timeout-ms", "DIRECTORY_RESOLVE_TIMEOUT_MS", DEFAULT_RESOLVE_TIMEOUT_MS, 0, TIMER_MAX_MS),
|
|
68
|
+
int("resolve-negative-ttl-ms", "DIRECTORY_RESOLVE_NEGATIVE_TTL_MS", DEFAULT_NEGATIVE_CACHE_TTL_MS, 0, TIMER_MAX_MS),
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
const BY_FLAG = new Map(DIRECTORY_FLAGS.map((s) => [s.flag, s]));
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* --peers: a comma list of http(s) URLs, or a JSON list whose entries are
|
|
75
|
+
* http(s) URLs or peer objects ({ uuaid, url, publicKey }; the coordinator
|
|
76
|
+
* checks each object). Throws on bad JSON, a non-list, or another entry.
|
|
77
|
+
*/
|
|
78
|
+
export function parsePeersArg(raw) {
|
|
79
|
+
if (!raw || typeof raw !== "string") return [];
|
|
80
|
+
const trimmed = raw.trim();
|
|
81
|
+
if (!trimmed) return [];
|
|
82
|
+
if (trimmed.startsWith("[")) {
|
|
83
|
+
const parsed = JSON.parse(trimmed);
|
|
84
|
+
const entryOk = (e) => isHttpUrl(e) || (e !== null && typeof e === "object" && !Array.isArray(e));
|
|
85
|
+
if (!Array.isArray(parsed) || !parsed.every(entryOk)) throw new Error("a JSON list of peer URLs or peer objects");
|
|
86
|
+
return parsed;
|
|
87
|
+
}
|
|
88
|
+
const list = trimmed.split(",").map((s) => s.trim()).filter(Boolean);
|
|
89
|
+
if (!list.every(isHttpUrl)) throw new Error("a comma list of http(s) URLs");
|
|
90
|
+
return list;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** An http: or https: URL (the coordinator checks private and mapped hosts itself). */
|
|
94
|
+
function isHttpUrl(u) {
|
|
95
|
+
if (typeof u !== "string") return false;
|
|
96
|
+
try { const p = new URL(u.trim()).protocol; return p === "https:" || p === "http:"; } catch { return false; }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A token as an error message shows it: as typed when plain, else JSON-quoted. */
|
|
100
|
+
const shown = (t) => (/^[\x21-\x7e]+$/.test(t) ? t : JSON.stringify(t));
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Parse pillar-directory's argv and environment.
|
|
104
|
+
* Returns { ok: true, values } or { ok: false, error } (one sentence, no trailing period).
|
|
105
|
+
* `values` holds every flag by name (int: number with its default applied;
|
|
106
|
+
* string: string or undefined; bool: boolean), plus `peerList` and `urlMap`.
|
|
107
|
+
*/
|
|
108
|
+
export function parseDirectoryArgs(argv, env = process.env) {
|
|
109
|
+
const given = {};
|
|
110
|
+
const unknown = [];
|
|
111
|
+
const valued = [];
|
|
112
|
+
const missing = [];
|
|
113
|
+
const words = [];
|
|
114
|
+
for (let i = 0; i < argv.length; i++) {
|
|
115
|
+
const a = argv[i];
|
|
116
|
+
if (a === "-h") { given.help = true; continue; }
|
|
117
|
+
if (!(a.startsWith("--") && a.length > 2)) { words.push(a); continue; }
|
|
118
|
+
const eq = a.indexOf("=");
|
|
119
|
+
const k = eq === -1 ? a.slice(2) : a.slice(2, eq);
|
|
120
|
+
const spec = BY_FLAG.get(k);
|
|
121
|
+
if (!spec) {
|
|
122
|
+
unknown.push(`--${k}`);
|
|
123
|
+
// Its value, if it has one, is part of the mistake, not a second one.
|
|
124
|
+
if (eq === -1 && argv[i + 1] !== undefined && !argv[i + 1].startsWith("-")) i++;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (spec.kind === "bool") {
|
|
128
|
+
if (eq === -1) given[k] = true; else valued.push(`--${k}`);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
let v;
|
|
132
|
+
if (eq !== -1) v = a.slice(eq + 1);
|
|
133
|
+
else if (argv[i + 1] !== undefined && !argv[i + 1].startsWith("-")) v = argv[++i];
|
|
134
|
+
if (v === undefined || v === "") { missing.push(`--${k}`); continue; }
|
|
135
|
+
given[k] = v;
|
|
136
|
+
}
|
|
137
|
+
const parts = [];
|
|
138
|
+
if (unknown.length) parts.push(`unknown flag${unknown.length > 1 ? "s" : ""} ${unknown.map(shown).join(", ")}`);
|
|
139
|
+
if (valued.length) parts.push(`${valued.join(", ")} take${valued.length > 1 ? "" : "s"} no value`);
|
|
140
|
+
if (missing.length) parts.push(`${missing.join(", ")} need${missing.length > 1 ? "" : "s"} a value (one that starts with "-" is written ${missing[0]}=<value>)`);
|
|
141
|
+
if (words.length) parts.push(`unexpected argument${words.length > 1 ? "s" : ""} ${words.map((w) => JSON.stringify(w)).join(", ")} (pillar-directory takes only flags)`);
|
|
142
|
+
if (parts.length) return { ok: false, error: parts.join("; ") };
|
|
143
|
+
|
|
144
|
+
const emptyEnv = DIRECTORY_FLAGS.filter((s) => s.env && env[s.env] === "").map((s) => s.env);
|
|
145
|
+
if (emptyEnv.length) return { ok: false, error: `${emptyEnv.join(", ")} ${emptyEnv.length > 1 ? "are" : "is"} set but empty: unset ${emptyEnv.length > 1 ? "them" : "it"} or give a value` };
|
|
146
|
+
|
|
147
|
+
const values = {};
|
|
148
|
+
for (const s of DIRECTORY_FLAGS) {
|
|
149
|
+
const fromFlag = given[s.flag];
|
|
150
|
+
const fromEnv = s.env ? env[s.env] : undefined;
|
|
151
|
+
if (s.kind === "bool") { values[s.flag] = fromFlag === true; continue; }
|
|
152
|
+
if (s.kind === "string") { values[s.flag] = fromFlag ?? fromEnv ?? undefined; continue; }
|
|
153
|
+
const raw = fromFlag ?? fromEnv;
|
|
154
|
+
if (raw === undefined) { values[s.flag] = s.def; continue; }
|
|
155
|
+
const n = Number(raw);
|
|
156
|
+
if (!/^[0-9]+$/.test(raw) || n < s.min || n > s.max) {
|
|
157
|
+
const who = fromFlag !== undefined ? `--${s.flag}` : s.env;
|
|
158
|
+
return { ok: false, error: `${who} must be a whole number from ${s.min} to ${s.max}, not ${JSON.stringify(raw)}` };
|
|
159
|
+
}
|
|
160
|
+
values[s.flag] = n;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const peersRaw = values.peers ?? values.peer ?? "";
|
|
164
|
+
try { values.peerList = parsePeersArg(peersRaw); }
|
|
165
|
+
catch (e) {
|
|
166
|
+
const who = given.peers !== undefined || given.peer !== undefined ? "--peers" : "DIRECTORY_PEERS";
|
|
167
|
+
return { ok: false, error: `${who} must be ${e instanceof SyntaxError ? "a comma list of http(s) URLs or valid JSON" : e.message}` };
|
|
168
|
+
}
|
|
169
|
+
values.urlMap = null;
|
|
170
|
+
if (values["url-map"] !== undefined) {
|
|
171
|
+
let m;
|
|
172
|
+
try { m = JSON.parse(values["url-map"]); } catch { m = undefined; }
|
|
173
|
+
if (!m || typeof m !== "object" || Array.isArray(m)) return { ok: false, error: `${given["url-map"] !== undefined ? "--url-map" : "DIRECTORY_URL_MAP"} must be a JSON object` };
|
|
174
|
+
values.urlMap = m;
|
|
175
|
+
}
|
|
176
|
+
return { ok: true, values };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The effective limits, one line, values only (printed after "listening on"). */
|
|
180
|
+
export function formatDirectoryLimits(values) {
|
|
181
|
+
return DIRECTORY_FLAGS.filter((s) => s.kind === "int" && s.flag !== "port").map((s) => `--${s.flag} ${values[s.flag]}`).join(" ");
|
|
182
|
+
}
|
package/src/registry/stats.mjs
CHANGED
|
@@ -52,7 +52,7 @@ export const TTFA_METHODS = Object.freeze(["ci-canary", "field-cohort"]);
|
|
|
52
52
|
export const TTFA_MIN_N = 10;
|
|
53
53
|
|
|
54
54
|
/** Tool stamped on B8 verdicts (same string the `pillar verify` CLI uses). */
|
|
55
|
-
export const STATS_VERDICT_TOOL = "pillar/2.7.
|
|
55
|
+
export const STATS_VERDICT_TOOL = "pillar/2.7.3";
|
|
56
56
|
|
|
57
57
|
/** Closed key set of `pillar-ttfa-report/1`. */
|
|
58
58
|
export const TTFA_REPORT_KEYS = Object.freeze([
|
package/src/vnext/verify-cli.mjs
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
verifyStatsArtifact,
|
|
32
32
|
} from "../registry/stats.mjs";
|
|
33
33
|
|
|
34
|
-
export const VERIFY_CLI_TOOL = "pillar/2.7.
|
|
34
|
+
export const VERIFY_CLI_TOOL = "pillar/2.7.3";
|
|
35
35
|
const TYPE_SET = new Set([...VERIFY_TYPES, TTFA_VERDICT_TYPE, REGISTRY_STATS_VERDICT_TYPE]);
|
|
36
36
|
|
|
37
37
|
const VALUE_FLAGS = new Set([
|