@uuaid/pillar 2.6.0 → 2.7.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/HOSTING-LIMITS.md +12 -0
- package/README.md +201 -5
- package/bin/carrier.mjs +72 -2
- package/bin/pillar-ask.mjs +4 -1
- package/bin/pillar-blob.mjs +6 -0
- package/bin/pillar-directory.mjs +280 -16
- package/bin/pillar-escrow.mjs +4 -1
- package/bin/pillar-group-v2.mjs +6 -0
- package/bin/pillar-notify.mjs +13 -0
- package/bin/pillar-responder.mjs +266 -23
- package/bin/pillar.mjs +504 -255
- package/package.json +17 -25
- package/src/cli-help.mjs +23 -0
- package/src/group-v2-cli.mjs +1 -1
- package/src/identity/trust.mjs +72 -6
- package/src/mailbox/mailbox.mjs +308 -12
- package/src/net/carrier-server.mjs +34 -2
- package/src/net/refusals.mjs +2 -0
- package/src/net/seed-registry.mjs +2 -1
- package/src/net/transport.mjs +308 -92
- package/src/node-check.mjs +29 -8
- package/src/notify-events.mjs +148 -0
- package/src/notify-log.mjs +124 -0
- package/src/notify-runner.mjs +372 -0
- package/src/notify-store.mjs +725 -0
- package/src/notify.mjs +350 -0
- package/src/pillar.mjs +382 -27
- package/src/readers.mjs +2 -2
- package/src/registry/federation.mjs +3056 -0
- package/src/registry/gossip.mjs +294 -0
- package/src/registry/heartbeats.mjs +195 -0
- package/src/registry/lineage-verifier.mjs +972 -0
- package/src/registry/lineage.mjs +984 -0
- package/src/registry/listings.mjs +549 -0
- package/src/registry/resolve.mjs +376 -0
- package/src/registry/stats.mjs +508 -0
- package/src/sqlite-loader.mjs +40 -0
- package/src/vendor/pillar-core.mjs +22 -0
- package/src/vendor/uuaid-soul.mjs +2246 -0
- package/src/vnext/a6b-common.mjs +270 -0
- package/src/vnext/b1-cli.mjs +970 -0
- package/src/vnext/card-cli.mjs +370 -0
- package/src/vnext/greeter-operator.mjs +160 -0
- package/src/vnext/greeter-suggest.mjs +318 -0
- package/src/vnext/greeter.mjs +571 -0
- package/src/vnext/homes.mjs +48 -0
- package/src/vnext/init-cli.mjs +489 -0
- package/src/vnext/intro-cli.mjs +81 -0
- package/src/vnext/json-dir-mailbox.mjs +296 -0
- package/src/vnext/jsonl-mailbox.mjs +1066 -0
- package/src/vnext/knock-answer.mjs +162 -0
- package/src/vnext/knock-cli.mjs +520 -0
- package/src/vnext/knock-lane.mjs +312 -0
- package/src/vnext/knock-responder.mjs +344 -0
- package/src/vnext/lineage-cli.mjs +653 -0
- package/src/vnext/listing-cli.mjs +323 -0
- package/src/vnext/resolve-cli.mjs +86 -0
- package/src/vnext/soul-cli.mjs +666 -0
- package/src/vnext/verify-cli.mjs +251 -0
- package/src/vnext/w4-redirect.mjs +178 -0
- package/src/vnext/wave-a.mjs +193 -0
- package/src/vnext/witness-cli.mjs +547 -0
package/bin/pillar-directory.mjs
CHANGED
|
@@ -17,10 +17,14 @@
|
|
|
17
17
|
* GET /v1/seeds every enrolled seed and its standing
|
|
18
18
|
* GET /v1/seeds/<uuaid> one seed's standing + what is left to earn
|
|
19
19
|
* GET /v1/seeds/<uuaid>/grant that seed's current earned tier grant
|
|
20
|
+
* POST /v1/listings publish a verified pillar-listing/1
|
|
21
|
+
* POST /v1/lineage publish a verified uuaid-lineage/1 event (Guard C)
|
|
22
|
+
* GET /v1/lineage/<uuaid> uuaid-lineage-log/1 presentation (receipts: [] in Wave A)
|
|
23
|
+
* GET /v1/resolve/<uuaid> pillar-resolve/1 single-registry answer
|
|
24
|
+
* GET /v1/stats pillar-registry-stats/1 signed daily aggregate
|
|
20
25
|
* GET /v1/health
|
|
21
26
|
*
|
|
22
|
-
* `agents.json` is passed through
|
|
23
|
-
* not the address book.
|
|
27
|
+
* `agents.json` is passed through alongside non-withdrawn live `pillar-listing/1` projections.
|
|
24
28
|
*/
|
|
25
29
|
import "../src/node-check.mjs"; // must stay the first import: refuses Node < 22 before any dependency loads
|
|
26
30
|
import { createServer } from "node:http";
|
|
@@ -30,6 +34,45 @@ import { join } from "node:path";
|
|
|
30
34
|
import { SeedRegistry } from "../src/net/seed-registry.mjs";
|
|
31
35
|
import { clientIpOf, parseTrustedProxies } from "../src/net/client-ip.mjs";
|
|
32
36
|
import { Keychain, mintNamespace, SERVICE_IDENTITY_NAMESPACE } from "../src/identity/keychain.mjs";
|
|
37
|
+
import { tryLoadBetterSqlite3 } from "../src/sqlite-loader.mjs";
|
|
38
|
+
import {
|
|
39
|
+
DEFAULT_MAX_RESOLVE_MISSES_PER_IP_PER_MINUTE,
|
|
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";
|
|
49
|
+
import { GossipCoordinator } from "../src/registry/gossip.mjs";
|
|
50
|
+
import { HeartbeatStore } from "../src/registry/heartbeats.mjs";
|
|
51
|
+
import { LineageStore, isStrictDateTime } from "../src/registry/lineage.mjs";
|
|
52
|
+
import { ListingStore, isStrictHttpsUri, MAX_NEW_LINEAGES_PER_HOUR, startTombstonePruning } from "../src/registry/listings.mjs";
|
|
53
|
+
import { handleRegistryRoute } from "../src/registry/resolve.mjs";
|
|
54
|
+
import {
|
|
55
|
+
buildRegistryStats,
|
|
56
|
+
collectRegistryCounts,
|
|
57
|
+
loadRegistryStatsSnapshot,
|
|
58
|
+
persistFirstRegistryStats,
|
|
59
|
+
utcDay,
|
|
60
|
+
} from "../src/registry/stats.mjs";
|
|
61
|
+
import { exitWithHelp, wantsHelp } from "../src/cli-help.mjs";
|
|
62
|
+
|
|
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
|
+
}
|
|
33
76
|
|
|
34
77
|
function parseArgs(argv) {
|
|
35
78
|
const args = {};
|
|
@@ -43,6 +86,30 @@ function parseArgs(argv) {
|
|
|
43
86
|
return args;
|
|
44
87
|
}
|
|
45
88
|
|
|
89
|
+
const USAGE = `usage: pillar-directory [flags]
|
|
90
|
+
|
|
91
|
+
Serves directory.json and the seed registry. Listens on 127.0.0.1 by default.
|
|
92
|
+
The first start mints the registry key in --home.
|
|
93
|
+
|
|
94
|
+
--home <dir> registry key directory (DIRECTORY_HOME, default ~/.pillar-directory)
|
|
95
|
+
--db <file> SQLite database (DIRECTORY_DB, default <home>/registry.db)
|
|
96
|
+
--port <n> listen port (DIRECTORY_PORT, default 8800)
|
|
97
|
+
--host <addr> listen address (DIRECTORY_HOST, default 127.0.0.1)
|
|
98
|
+
--carrier <url> carrier named in directory.json (DIRECTORY_CARRIER)
|
|
99
|
+
--agents <file> agents.json passed through (DIRECTORY_AGENTS)
|
|
100
|
+
--public-url <url> this registry's public URL (DIRECTORY_PUBLIC_URL)
|
|
101
|
+
--peers <url,...> peer registries (DIRECTORY_PEERS)
|
|
102
|
+
--trusted-proxy <ips> whose X-Forwarded-For counts (DIRECTORY_TRUSTED_PROXIES)
|
|
103
|
+
--probe-minutes <n> seed probe interval (DIRECTORY_PROBE_MINUTES, default 10)
|
|
104
|
+
-h, --help print this help and exit
|
|
105
|
+
|
|
106
|
+
More flags (limits, federation timers, test hooks): --protocol, --allow-private-urls,
|
|
107
|
+
--url-map, --clock-file, --stamp-bits, --max-new-lineages-per-hour,
|
|
108
|
+
--max-listings-per-ip-per-hour, --max-lineage-posts-per-ip-per-hour,
|
|
109
|
+
--max-heartbeats-per-ip-per-hour, --pull-interval-ms, --max-strikes,
|
|
110
|
+
--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.`;
|
|
112
|
+
if (wantsHelp(process.argv.slice(2))) await exitWithHelp(USAGE); // R2: before the registry key is minted or the db is opened
|
|
46
113
|
const args = parseArgs(process.argv.slice(2));
|
|
47
114
|
const home = args.home ?? process.env.DIRECTORY_HOME ?? join(homedir(), ".pillar-directory");
|
|
48
115
|
const port = Number(args.port ?? process.env.DIRECTORY_PORT ?? 8800);
|
|
@@ -53,6 +120,56 @@ const agentsPath = args.agents ?? process.env.DIRECTORY_AGENTS ?? null;
|
|
|
53
120
|
const protocol = args.protocol ?? process.env.DIRECTORY_PROTOCOL ?? "uacp/1.0-draft";
|
|
54
121
|
const probeMinutes = Number(args["probe-minutes"] ?? process.env.DIRECTORY_PROBE_MINUTES ?? 10);
|
|
55
122
|
const allowPrivateUrls = Boolean(args["allow-private-urls"]);
|
|
123
|
+
const publicUrlArg = args["public-url"] ?? process.env.DIRECTORY_PUBLIC_URL ?? null;
|
|
124
|
+
const rawUrlMap = args["url-map"] ?? process.env.DIRECTORY_URL_MAP ?? null;
|
|
125
|
+
const urlMap = rawUrlMap ? JSON.parse(rawUrlMap) : null;
|
|
126
|
+
const clockFile = typeof args["clock-file"] === "string" ? args["clock-file"] : null;
|
|
127
|
+
const getNow = () => {
|
|
128
|
+
if (!clockFile || !existsSync(clockFile)) return undefined;
|
|
129
|
+
const raw = readFileSync(clockFile, "utf-8").trim();
|
|
130
|
+
return isStrictDateTime(raw) ? raw : undefined;
|
|
131
|
+
};
|
|
132
|
+
const stampBits = Number(args["stamp-bits"] ?? process.env.DIRECTORY_STAMP_BITS ?? 18);
|
|
133
|
+
const maxNewLineagesPerHour = Number(
|
|
134
|
+
args["max-new-lineages-per-hour"] ?? process.env.DIRECTORY_MAX_NEW_LINEAGES_PER_HOUR ?? MAX_NEW_LINEAGES_PER_HOUR,
|
|
135
|
+
);
|
|
136
|
+
const DEFAULT_MAX_LISTINGS_PER_IP_PER_HOUR = 60;
|
|
137
|
+
const DEFAULT_MAX_LINEAGE_POSTS_PER_IP_PER_HOUR = 300;
|
|
138
|
+
const DEFAULT_MAX_HEARTBEATS_PER_IP_PER_HOUR = 120;
|
|
139
|
+
const maxListingsPerIpPerHour = Number(
|
|
140
|
+
args["max-listings-per-ip-per-hour"] ??
|
|
141
|
+
process.env.DIRECTORY_MAX_LISTINGS_PER_IP_PER_HOUR ??
|
|
142
|
+
DEFAULT_MAX_LISTINGS_PER_IP_PER_HOUR,
|
|
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
|
+
);
|
|
56
173
|
|
|
57
174
|
const MAX_ENROLLMENTS_PER_HOUR = 10; // per client IP
|
|
58
175
|
const MAX_BODY = 8 * 1024;
|
|
@@ -65,7 +182,93 @@ if (!keychain.exists()) {
|
|
|
65
182
|
}
|
|
66
183
|
keychain.load();
|
|
67
184
|
|
|
68
|
-
|
|
185
|
+
// B8: one signed `pillar-registry-stats/1` per registry per UTC day. The first one
|
|
186
|
+
// signed for a day is persisted under <home>/stats/ before it is served; the Map only
|
|
187
|
+
// saves a disk read.
|
|
188
|
+
const statsDir = join(home, "stats");
|
|
189
|
+
const statsAggregates = new Map();
|
|
190
|
+
|
|
191
|
+
const hasSqlite = Boolean(tryLoadBetterSqlite3());
|
|
192
|
+
const registry = hasSqlite
|
|
193
|
+
? new SeedRegistry({ keychain, carrierUrl: carrier, dbPath, protocol, allowPrivateUrls })
|
|
194
|
+
: (() => {
|
|
195
|
+
const fallbackDb = openRegistryDb(dbPath, { forcePureJs: true });
|
|
196
|
+
const normCarrier = carrier ? String(carrier).replace(/\/+$/, "") : null;
|
|
197
|
+
return {
|
|
198
|
+
db: fallbackDb,
|
|
199
|
+
uuaid: keychain._identity.uuaid,
|
|
200
|
+
issuerKey: keychain._identity.publicKeyHex,
|
|
201
|
+
all: () => [],
|
|
202
|
+
get: () => null,
|
|
203
|
+
status: () => ({ ok: false, reason: "unknown-seed" }),
|
|
204
|
+
grantFor: () => null,
|
|
205
|
+
enroll: async () => ({ ok: false, reason: "sqlite-not-installed" }),
|
|
206
|
+
observeAll: async () => [],
|
|
207
|
+
directory: ({ agents: dirAgents = [], now = Date.now() } = {}) => ({
|
|
208
|
+
protocol,
|
|
209
|
+
carrier: normCarrier,
|
|
210
|
+
updated: new Date(now).toISOString(),
|
|
211
|
+
issuer: keychain._identity.publicKeyHex,
|
|
212
|
+
agents: dirAgents,
|
|
213
|
+
seeds: [],
|
|
214
|
+
}),
|
|
215
|
+
close: () => fallbackDb.close(),
|
|
216
|
+
};
|
|
217
|
+
})();
|
|
218
|
+
const lineageStore = new LineageStore({
|
|
219
|
+
db: registry.db,
|
|
220
|
+
registryKey: keychain,
|
|
221
|
+
});
|
|
222
|
+
const listingStore = new ListingStore({
|
|
223
|
+
db: registry.db,
|
|
224
|
+
registryUuaid: registry.uuaid,
|
|
225
|
+
lineageStore,
|
|
226
|
+
requiredStampBits: stampBits,
|
|
227
|
+
maxNewLineagesPerHour,
|
|
228
|
+
});
|
|
229
|
+
const heartbeatStore = new HeartbeatStore({ db: registry.db, lineageStore, listingStore });
|
|
230
|
+
listingStore.setHeartbeatStore(heartbeatStore);
|
|
231
|
+
// V1 F2: pruning re-verifies every listing, so it never runs inside a request:
|
|
232
|
+
// one pass now, then one every 10 minutes.
|
|
233
|
+
const tombstonePruning = startTombstonePruning(listingStore, { getNow });
|
|
234
|
+
let boundPort = port;
|
|
235
|
+
const formatHostForUrl = (h) => (h.includes(":") && !h.startsWith("[") ? `[${h}]` : h);
|
|
236
|
+
const getAnsweredBy = () => {
|
|
237
|
+
if (publicUrlArg && isStrictHttpsUri(publicUrlArg)) return publicUrlArg.replace(/\/+$/, "");
|
|
238
|
+
if (carrier && isStrictHttpsUri(carrier)) return carrier.replace(/\/+$/, "");
|
|
239
|
+
return `https://${formatHostForUrl(host)}:${boundPort}`;
|
|
240
|
+
};
|
|
241
|
+
const gossipCoordinator = new GossipCoordinator({
|
|
242
|
+
lineageStore,
|
|
243
|
+
listingStore,
|
|
244
|
+
keychain,
|
|
245
|
+
registryUuaid: registry.uuaid,
|
|
246
|
+
getSelfUrl: getAnsweredBy,
|
|
247
|
+
getNow,
|
|
248
|
+
defaultCarrierUrl: carrier,
|
|
249
|
+
allowPrivateUrls,
|
|
250
|
+
urlMap,
|
|
251
|
+
});
|
|
252
|
+
const federationCoordinator = new FederationCoordinator({
|
|
253
|
+
db: registry.db,
|
|
254
|
+
lineageStore,
|
|
255
|
+
listingStore,
|
|
256
|
+
heartbeatStore,
|
|
257
|
+
keychain,
|
|
258
|
+
registryUuaid: registry.uuaid,
|
|
259
|
+
publicKey: registry.issuerKey,
|
|
260
|
+
peers: configuredPeers,
|
|
261
|
+
getSelfUrl: getAnsweredBy,
|
|
262
|
+
getNow,
|
|
263
|
+
allowPrivateUrls,
|
|
264
|
+
urlMap,
|
|
265
|
+
pullIntervalMs,
|
|
266
|
+
maxStrikes,
|
|
267
|
+
quarantineCooldownMs,
|
|
268
|
+
maxNewLineagesPerHour,
|
|
269
|
+
resolveTimeoutMs,
|
|
270
|
+
negativeCacheTtlMs,
|
|
271
|
+
});
|
|
69
272
|
|
|
70
273
|
/**
|
|
71
274
|
* agents[] is read fresh on each render rather than cached at boot, so
|
|
@@ -83,18 +286,25 @@ function agents() {
|
|
|
83
286
|
}
|
|
84
287
|
}
|
|
85
288
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
289
|
+
function makeIpRateLimiter(maxPerHour) {
|
|
290
|
+
const buckets = new Map(); // ip -> [ms]
|
|
291
|
+
return (ip) => {
|
|
292
|
+
const now = Date.now();
|
|
293
|
+
const arr = (buckets.get(ip) ?? []).filter(t => t > now - 3600_000);
|
|
294
|
+
if (arr.length >= maxPerHour) { buckets.set(ip, arr); return false; }
|
|
295
|
+
arr.push(now);
|
|
296
|
+
buckets.set(ip, arr);
|
|
297
|
+
if (buckets.size > 10_000) {
|
|
298
|
+
for (const [k, v] of buckets) if (!v.some(t => t > now - 3600_000)) buckets.delete(k);
|
|
299
|
+
}
|
|
300
|
+
return true;
|
|
301
|
+
};
|
|
97
302
|
}
|
|
303
|
+
const enrollAllowed = makeIpRateLimiter(MAX_ENROLLMENTS_PER_HOUR);
|
|
304
|
+
const listingRateAllowed = makeIpRateLimiter(maxListingsPerIpPerHour);
|
|
305
|
+
const lineageRateAllowed = makeIpRateLimiter(maxLineagePostsPerIpPerHour);
|
|
306
|
+
const heartbeatRateAllowed = makeIpRateLimiter(maxHeartbeatsPerIpPerHour);
|
|
307
|
+
const resolveMissAllowed = makeResolveMissRateLimiter({ maxPerMinute: maxResolveMissesPerIpPerMinute, getNow });
|
|
98
308
|
|
|
99
309
|
function send(res, code, obj) {
|
|
100
310
|
const body = JSON.stringify(obj, null, 2);
|
|
@@ -132,7 +342,52 @@ const server = createServer(async (req, res) => {
|
|
|
132
342
|
const url = new URL(req.url, `http://${req.headers.host ?? "localhost"}`);
|
|
133
343
|
|
|
134
344
|
if (req.method === "GET" && (url.pathname === "/directory.json" || url.pathname === "/")) {
|
|
135
|
-
|
|
345
|
+
const mergedAgents = listingStore.projectLiveAgents({ staticAgents: agents(), now: getNow() });
|
|
346
|
+
return send(res, 200, registry.directory({ agents: mergedAgents }));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (req.method === "GET" && url.pathname === "/v1/stats") {
|
|
350
|
+
// B8: one signed aggregate per registry per UTC day. Its counts are taken
|
|
351
|
+
// from the very projection /directory.json serves, so the registry can
|
|
352
|
+
// never sign a count it does not already publish. The first aggregate of
|
|
353
|
+
// the day is persisted atomically; a restart on the same day serves it again.
|
|
354
|
+
const nowIso = getNow() ?? new Date().toISOString();
|
|
355
|
+
const day = utcDay(nowIso);
|
|
356
|
+
const cacheKey = `${registry.uuaid} ${day}`;
|
|
357
|
+
let aggregate = statsAggregates.get(cacheKey);
|
|
358
|
+
if (!aggregate) {
|
|
359
|
+
const pin = { now: nowIso, publicKey: keychain._identity.publicKeyHex };
|
|
360
|
+
try {
|
|
361
|
+
aggregate = loadRegistryStatsSnapshot(statsDir, registry.uuaid, day, pin);
|
|
362
|
+
if (!aggregate) {
|
|
363
|
+
const projected = listingStore.projectLiveAgents({ staticAgents: agents(), now: getNow() });
|
|
364
|
+
const built = buildRegistryStats(collectRegistryCounts(projected), keychain, { day });
|
|
365
|
+
aggregate = persistFirstRegistryStats(statsDir, built, pin);
|
|
366
|
+
}
|
|
367
|
+
if (!aggregate) throw new Error("snapshot missing after persist");
|
|
368
|
+
} catch (e) {
|
|
369
|
+
console.error(`[directory] stats snapshot ${day} refused: ${e.message}`);
|
|
370
|
+
return send(res, 500, { ok: false, reason: "stats-snapshot-invalid" });
|
|
371
|
+
}
|
|
372
|
+
statsAggregates.set(cacheKey, aggregate);
|
|
373
|
+
}
|
|
374
|
+
return send(res, 200, aggregate);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (await handleRegistryRoute(req, res, url, {
|
|
378
|
+
lineageStore,
|
|
379
|
+
listingStore,
|
|
380
|
+
heartbeatStore,
|
|
381
|
+
gossipCoordinator,
|
|
382
|
+
federationCoordinator,
|
|
383
|
+
getAnsweredBy,
|
|
384
|
+
getNow,
|
|
385
|
+
checkListingRateLimit: () => listingRateAllowed(clientIp(req)),
|
|
386
|
+
checkLineageRateLimit: () => lineageRateAllowed(clientIp(req)),
|
|
387
|
+
checkHeartbeatRateLimit: () => heartbeatRateAllowed(clientIp(req)),
|
|
388
|
+
checkResolveMissRateLimit: () => resolveMissAllowed(clientIp(req)),
|
|
389
|
+
})) {
|
|
390
|
+
return;
|
|
136
391
|
}
|
|
137
392
|
|
|
138
393
|
if (req.method === "POST" && url.pathname === "/v1/seeds") {
|
|
@@ -180,6 +435,7 @@ const server = createServer(async (req, res) => {
|
|
|
180
435
|
if (req.method === "GET" && url.pathname === "/v1/health") {
|
|
181
436
|
return send(res, 200, {
|
|
182
437
|
ok: true,
|
|
438
|
+
uuaid: registry.uuaid,
|
|
183
439
|
seeds: registry.all().length,
|
|
184
440
|
issuer: registry.issuerKey,
|
|
185
441
|
uptimeMs: Date.now() - startedAt,
|
|
@@ -195,7 +451,12 @@ const server = createServer(async (req, res) => {
|
|
|
195
451
|
|
|
196
452
|
const startedAt = Date.now();
|
|
197
453
|
await new Promise(r => server.listen(port, host, r));
|
|
198
|
-
|
|
454
|
+
boundPort = server.address().port;
|
|
455
|
+
if (configuredPeers.length > 0 && pullIntervalMs > 0) {
|
|
456
|
+
federationCoordinator.start();
|
|
457
|
+
}
|
|
458
|
+
console.log(`pillar-directory listening on http://${formatHostForUrl(host)}:${boundPort}`);
|
|
459
|
+
console.log(` uuaid: ${registry.uuaid}`);
|
|
199
460
|
console.log(` issuer: ${registry.issuerKey}`);
|
|
200
461
|
console.log(` carrier: ${carrier ?? "(none — set --carrier)"}`);
|
|
201
462
|
console.log(` db: ${dbPath}`);
|
|
@@ -226,6 +487,9 @@ const probeTimer = setInterval(async () => {
|
|
|
226
487
|
|
|
227
488
|
const shutdown = async () => {
|
|
228
489
|
clearInterval(probeTimer);
|
|
490
|
+
tombstonePruning.stop();
|
|
491
|
+
federationCoordinator.stop();
|
|
492
|
+
server.closeAllConnections?.();
|
|
229
493
|
await new Promise(r => server.close(r));
|
|
230
494
|
registry.close();
|
|
231
495
|
process.exit(0);
|
package/bin/pillar-escrow.mjs
CHANGED
|
@@ -63,6 +63,7 @@ import {
|
|
|
63
63
|
makeTerms, signTerms, verifyReceiptSig, validatePayout, fingerprint, allocateFee,
|
|
64
64
|
} from "../src/escrow/terms.mjs";
|
|
65
65
|
import { sealBox, openBox, sha256Hex } from "../src/escrow/box.mjs";
|
|
66
|
+
import { exitWithHelp, wantsHelp } from "../src/cli-help.mjs";
|
|
66
67
|
|
|
67
68
|
const MAX_CONTENT_BYTES = 64 * 1024; // alpha cap
|
|
68
69
|
const HEX64 = /^[0-9a-f]{64}$/i;
|
|
@@ -654,6 +655,8 @@ async function cmdDirectory(args) {
|
|
|
654
655
|
|
|
655
656
|
/* ------------------------------------------------ main ------------------- */
|
|
656
657
|
|
|
658
|
+
const USAGE = "usage: pillar-escrow <init|run-escrow|sell|buy|token-apply|chain-apply|token-list|token-review|verify|verify-attestation|ack|attest-delivery|verify-receipt|verify-quorum|directory> [--home DIR] [--carrier URL] ...";
|
|
659
|
+
if (wantsHelp(argv.slice(2))) await exitWithHelp(USAGE); // R2: before any home, key or carrier is touched
|
|
657
660
|
const args = parseArgs(argv.slice(2));
|
|
658
661
|
const cmd = args._[0];
|
|
659
662
|
const handlers = {
|
|
@@ -666,7 +669,7 @@ const handlers = {
|
|
|
666
669
|
directory: cmdDirectory,
|
|
667
670
|
};
|
|
668
671
|
if (!handlers[cmd]) {
|
|
669
|
-
console.error(
|
|
672
|
+
console.error(USAGE);
|
|
670
673
|
exit(2);
|
|
671
674
|
}
|
|
672
675
|
handlers[cmd](args).catch((e) => {
|
package/bin/pillar-group-v2.mjs
CHANGED
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import "../src/node-check.mjs"; // must stay the first import: refuses Node < 22 before any dependency loads
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { exitWithHelp, wantsHelp } from "../src/cli-help.mjs";
|
|
12
|
+
|
|
13
|
+
if (wantsHelp(process.argv.slice(2))) {
|
|
14
|
+
const { GROUP_V2_USAGE } = await import("../src/group-v2-cli.mjs");
|
|
15
|
+
await exitWithHelp(GROUP_V2_USAGE); // R2: before pillar opens the home
|
|
16
|
+
}
|
|
11
17
|
|
|
12
18
|
const [verb, ...rest] = process.argv.slice(2);
|
|
13
19
|
process.argv = [
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* pillar-notify — alias of `pillar notify` (kept for The Eze's proposal and
|
|
4
|
+
* any automation that calls it). Same flags, same output, same exit codes:
|
|
5
|
+
*
|
|
6
|
+
* pillar-notify [--home DIR] [--fleet FILE] [--groups FILE]
|
|
7
|
+
* pillar-notify --print-unit launchd|systemd|cron
|
|
8
|
+
*/
|
|
9
|
+
import "../src/node-check.mjs"; // must stay the first import (as in bin/pillar.mjs)
|
|
10
|
+
import { argv } from "node:process";
|
|
11
|
+
|
|
12
|
+
argv.splice(2, 0, "notify");
|
|
13
|
+
await import("./pillar.mjs");
|