Skip to main content

Module wan_publish

Module wan_publish 

Source
Expand description

Publish each agent’s WAN key to the account’s cloud key directory, certified by this install’s instance key (SPEC_WAN_JEKT_VERIFICATION_2026_09_24.md §2.2, step D1b).

A receiver can verify a WAN jekt only against a key it can fetch, and it trusts that key only because this install’s instance key signed it — so the directory never has to be trusted, only reachable. The cloud checks the same chain on PUT (hygiene); the receiver checks it again.

When. The spawn path nudges the publisher after it provisions a key (nudge); a background loop also re-runs every [RETRY_SECS] so a key that failed to publish (logged out, cloud down) is retried, and every [IDLE_RECHECK_SECS] when idle, because a sign-in in another channel can change the directory without nudging this process. A cloud that answers 404 predates the directory (C1 not deployed): retried at most hourly, never hot.

Which token. The shared account token (load_valid_token), not a per-agent M2M token — a per-agent client may be unowned, and the directory is keyed by account.

Retired keys. When this install replaces an agent’s key, wan.db writes down a retirement for each directory that held the old one (wan_identity::revocations). The same pass signs a WanKeyRevocation for each with the instance key and puts it there, and the retirement goes once the directory has it. The revocation is also kept locally at once, so this install refuses the old key even while the directory is out of reach.

Nothing here ever makes a jekt fail: until a key is confirmed published, the relay simply sends that agent’s jekts unsigned (relay::wan_sign_at_origin, condition 2).

Functions§

directory_id
Which directory a publication is for: the relay’s REST base plus the account (the token’s sub). The directory is keyed by account, and a relay move or a sign-in to another account is a directory that has never seen this install’s keys — so wan.db records publications per this id, and a key counts as published only to the directory it went to.
nudge
Ask the publisher to run a pass soon — called by the spawn path after it provisions an agent’s WAN key. Cheap and safe to call with no publisher running.
spawn
Start the background publisher. No-op without a wan.db. Runs a pass on start, on every nudge, every [RETRY_SECS] while keys remain, and every [IDLE_RECHECK_SECS] when none do; after a 404 it waits [NOT_SUPPORTED_RETRY_SECS] (nudges included, so a burst of spawns can’t turn an old cloud into a hot loop).