registry: link channels and link placement for forward rows
Linked deployments slice 1, Task 1 (spec §6.1-§6.2). A link_channels table holds each link's token hash, owner, status and generation, with the hub's connection record (connected, seen_at, seq) beside it and left out of Fingerprint. PutLinkChannel is the one writer's door: it applies only a newer generation and never over a revoked row. RevokeLinkChannel revokes and deletes the link's forward rows in one transaction. PutForward accepts link/<id> placements, needs an active channel of the row's account in the same transaction (ErrLinkInactive), and keeps fleet and link placements disjoint (ErrHostHeld). DeleteForward refuses link rows; DeleteLinkForward and LinkForwards are the link's own doors. All new methods go over the remote transport and into consoleRegistry, which also gains PutForward. Census overlay linked-deployments-slice1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 files changed,
+1,080
−19
docs/superpowers/notes/census-proposal-linked-deployments-slice1.md+42 −0internal/console/view.go+13 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv+38 −0internal/registry/forward.go+38 −16internal/registry/links.go+413 −0internal/registry/links_test.go+470 −0internal/registry/registry.go+37 −2internal/registry/remote.go+1 −1internal/registry/remote_dispatch.go+27 −0
diff --git a/docs/superpowers/notes/census-proposal-linked-deployments-slice1.md b/docs/superpowers/notes/census-proposal-linked-deployments-slice1.md| new file mode 100644 |
| index 000000000..4001f62e4 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-linked-deployments-slice1.md |
| @@ -0,0 +1,42 @@ |
| +# Census approval: linked-deployments-slice1 |
| + |
| +Ruling `census-ruling-linked-deployments-slice1`. The independent reviewer approves or rejects every change below, 14 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/registry/forward.go` `Registry.DeleteForward` | body | unchanged (7) | linked deployments slice 1 Task 1: the one DELETE also refuses a link-placed forward row (AND substr(region, 1, 5) <> 'link/'); a narrower delete, no read added | |
| +| `internal/registry/registry.go` `Registry.migrate` | body | unchanged (22) | linked deployments slice 1 Task 1: calls migrateLinks after migrateHADuties (one CREATE TABLE IF NOT EXISTS link_channels, an in-binary literal); additive, no existing statement changed | |
| +| `internal/registry/forward.go` `Registry.PutForward` | sites | +registry:Account, +registry:FleetLabel, +registry:Host, +registry:Region ×2 | linked deployments slice 1 Task 1: also accepts a Region that LinkPlacement parses (link/ + 12 hex), refusing a link row with a FleetLabel (ErrNotForward); the existing in-transaction SELECT also reads the held row's region and refuses a different placement class (ErrHostHeld); a link row additionally needs an active link_channels row of its account in the same transaction (linkAdmits, ErrLinkInactive). Same transaction and statement; the added reads are the argument and the box's own registry database, as carlos | |
| +| `internal/registry/registry.go` `Registry.Fingerprint` | sites | +file:Query | linked deployments slice 1 Task 1: hashes link_channels (link_id, account, token_hash, status, generation; connected, seen_at, seq and created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no links digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; a digest, never a decision | |
| + |
| +Envelopes re-pinned: `internal/registry`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `internal/registry/forward.go` `Registry.DeleteForward`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 2: deletes a forward row only (WHERE kind = 'forward'); remote-or-local shape of every narrow setter (+file:Exec, +registry:Changed, +registry:remote x2, +registry:sql, +whole:remoteClient x2). |
| +- `internal/registry/registry.go` `Registry.migrate`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user), on every registry open; a box CLI verb that opens the registry directly runs it as whoever runs the verb: census-ruling-seeded-instances's body with two more columns added to routes (incarnation and serving_seq, INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule); self-serve moves 1 Task 7;rev3=census-ruling-rootfs-apps-2;basis=one more ALTER TABLE, routes ADD COLUMN runtime TEXT NOT NULL DEFAULT '', beside main's rate_limit, assets_off, asset_gen, incarnation and serving_seq (the last four from the merges of origin/main 3c33f2eb and 953b9fda); the same sixteen sites, no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328/#329 plan 1 Task 4: three more ALTER TABLE statements in the existing loop, routes ADD COLUMN egress_allow, size and policy_expires_at, each TEXT NOT NULL DEFAULT '' and idempotent through the duplicate-column rule; the same sixteen sites, no read added.;rev3=census-ruling-region-ha-p1a;basis=one more ALTER TABLE in the existing loop: routes ADD COLUMN ha INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule; the same sixteen sites, no read added;rev3=census-ruling-ha-p1a-433;basis=the registry's SQLite side as carlos (agent, registry child; a box CLI verb that opens the registry directly runs it as whoever runs it), on every registry open: the ALTER TABLE routes statements are now built from the one migration definition routeAddedColumns (addedColumn name, type, default; review r1 P2): for each entry without the Claim mark, "ALTER TABLE routes ADD COLUMN " + spec(), byte for byte the statements main runs, in main's order, under the same duplicate-column rule. +registry:Claim is that mark, +whole:addedColumn the struct. Every name, type and default is an in-binary literal; no statement added, removed or changed; no read added.;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: one more CREATE TABLE IF NOT EXISTS regional_domains (host TEXT PRIMARY KEY, target, account, app, region TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL DEFAULT 0), beside wildcard_domains; the added sites are that statement (+file:Exec, +registry:sql), an in-binary literal; additive, no existing statement changed;rev3=census-ruling-region-ha-p1b3b-t;basis=Create local HA duty/replay tables and revision triggers in the existing registry connection; no new database path.;rev3=census-ruling-agent-start-demo-3;basis=Create moved-notice storage as a single (id, wire) row; fingerprints include the stored wire bytes. Census read-site delta: +file:Exec, +registry:sql. |
| +- `internal/registry/forward.go` `Registry.PutForward`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 2: the only writer of a forward row's declared columns: refuses an argument whose kind is not forward; copies only the declared fields from its argument (Status ready, Provisioned true; no forbidden column is ever written); inside one IMMEDIATE transaction refuses a host a non-forward row holds (ErrHostHeld); keeps FleetBox while Region is unchanged; preserves the observational columns (+file:Exec, +file:QueryRow, +registry:Account, App, Channel, RateLimit, Region, Slug, +registry:Host x3, +registry:Kind, +registry:remote x2, +whole:Route x3, +whole:remoteClient x2).;rev3=census-ruling-fleet-routes-followups;basis=refuses up front, with the new sentinel ErrNotForward and before any read or write, an rt that is not a forward row (as before, now a sentinel), has an empty Host, or whose Region is not a fleet placement (registry.FleetPlacement); +registry:Host x2 and +registry:Region x2 read only the argument in those checks; the transaction and statement are unchanged;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (Task 5, rule 3), merged with main's ErrNotForward refusals (kept unchanged): the written row also carries FleetLabel = rt.FleetLabel and FleetBox = rt.FleetLabel; its conflict arm (forwardKept) writes fleet_label from the call and fleet_box as the call's label when set, else kept while the region is unchanged. The hub's forward phase in the agent, not root.;rev3=census-ruling-stateless-replicas-1;basis=Carry declarative Stateless into forward rows under existing transaction and shape guards; projection only.;rev3=census-ruling-agent-start-demo-1;basis=Reads and carries the four demo fields in the existing forward INSERT; the guarded conflict SQL refuses downgrade or identity change.;rev3=census-ruling-stateless-replicas-2;basis=Validates canonical set projection, writes explicit declarative columns and clears single-box binding; all forbidden columns zero. Same transaction/read source. merge of origin/main 6be08467: Retain main demo columns and immutable descriptor conflict guard alongside set validation/projection; merge-only existing route fields. |
| +- `internal/registry/registry.go` `Registry.Fingerprint`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user); the remote arm, unchanged, in the process that holds a remote handle: census-ruling-seeded-instances's body with the row's lifetime pair (incarnation, serving_seq) folded into the edge's change poll, each only when non-zero, so a registry with no pair digests as before; self-serve moves 1 Task 7;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: hashes regional_domains (host, target, account, app, region; created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no regional rows digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; no file path read;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): review R1 finding 1: the routes SELECT also reads host, kind, account, app, platform and fingerprintForwardInert (one CASE over the ForwardForbidden columns), and every row folds host, kind, account and app (tagged, quoted), platform when set, and forward_inert=0 for a forward row that is not inert, so a rowid reused by another hostname, an in-place account or app rewrite, or a stray forbidden column moves the edge's change poll. Same one SELECT per table on the same fresh connection to the box's own registry database, as carlos; no table, file or bucket read added; a digest, never a decision.;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (Task 5): the SELECT also reads fleet_label and, only when it is set, hashes "fleet_label=<q>" into the digest, so labelling a row moves the edge's reload fingerprint. Read sites unchanged (33). Registry side, not root; an unlabelled registry's digest is byte-identical.;rev3=census-ruling-stateless-replicas-1;basis=Read the additive stateless projection in the existing registry SELECT and hash only when set; no new read source.;rev3=census-ruling-agent-start-demo-1;basis=Existing SELECT reads four more demo columns; only a marked row adds them to the hash, so ordinary hashes remain unchanged.;rev3=census-ruling-stateless-replicas-2;basis=Four additive projection columns join the existing routes SELECT and hash only when nonzero; no new query or file read. merge of origin/main 6be08467: Union main demo identity and expiry with replica columns in the same SELECT and hash; merge-only body change.;rev3=census-ruling-agent-start-demo-3;basis=Hash moved-notice wire bytes so notice-only changes invalidate an edge route snapshot. Census read-site delta: +file:QueryRow.;rev3=census-ruling-edge-page-cache-1;basis=selects the new pages_off column with the rest and folds "pages_off=1" into the hash only when set, as assets_off, so a registry that never sets it fingerprints as before; same routes SELECT, no new table; read sites unchanged (34); no read added |
| + |
| +New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff: |
| + |
| +- new `internal/registry/links.go:Registry.DeleteLinkForward`: reads +file:Exec, +registry:Changed, +registry:remote ×2, +registry:sql, +whole:remoteClient ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:Registry.LinkChannelAuth`: reads +registry:StringMap, +registry:remote ×2, +whole:remoteClient ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:Registry.LinkForwards`: reads +file:Query, +registry:Routes, +registry:remote ×2, +whole:Route ×5, +whole:remoteClient ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:Registry.LinkOwners`: reads +registry:StringMap, +registry:remote ×2, +whole:remoteClient ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:Registry.LinkSeen`: reads +file:Query, +registry:At, +registry:LinkSeen, +registry:remote ×2, +whole:LinkSeen ×4, +whole:remoteClient ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:Registry.PutLinkChannel`: reads +file:Exec ×2, +registry:Account ×2, +registry:Changed, +registry:CreatedAt ×2, +registry:Generation ×3, +registry:LinkID ×9, +registry:Status ×4, +registry:TokenHash ×2, +registry:remote ×2, +whole:LinkChannel ×2, +whole:remoteClient ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:Registry.ResetLinkSeen`: reads +file:Exec, +registry:remote ×2, +registry:sql, +whole:remoteClient ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:Registry.RevokeLinkChannel`: reads +file:Exec ×2, +registry:Changed, +registry:remote ×2, +whole:remoteClient ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:Registry.SetLinkSeen`: reads +file:Exec ×2, +registry:remote ×2, +registry:sql ×2, +whole:remoteClient ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:Registry.activeLinkMap`: reads +file:Query; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:Registry.migrateLinks`: reads +file:Exec, +registry:sql; written legacy, accepted-legacy, frozen |
| +- new `internal/registry/links.go:linkAdmits`: reads +file:QueryRow; written legacy, accepted-legacy, frozen |
| +- other `changed registry schema`: closed only if it is the registry schema (re-pinned) |
| +- reads `internal/registry/remote_dispatch.go:Registry.dispatchRemote`: +registry:Changed ×3, +registry:Host, +registry:Link, +registry:LinkID ×4, +registry:LinkSeen, +registry:On, +registry:Routes, +registry:SeenAt, +registry:Seq, +registry:StringMap ×2, +whole:LinkChannel, +whole:LinkSeen, +whole:Route; keeps hint, task E2 |
| + |
| +Seal: `6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f83022504aa04c7684c72c93aa9a` → `4bcb934c032609d263f304730dd24003c56abfb9def6aec6e27dd847659bcf5d`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/console/view.go b/internal/console/view.go| index f26562d10..baf5fa197 100644 |
| --- a/internal/console/view.go |
| +++ b/internal/console/view.go |
| @@ -543,6 +543,19 @@ type consoleRegistry interface { |
| SetFleetBoxDraining(fleet, label string, since int64) (int64, error) |
| ClearFleetBoxDraining(fleet, label string, since int64) (bool, error) |
| MarkFleetBoxLabelled(fleet, label string, at int64) error |
| + PutForward(registry.Route) error |
| + |
| + // Linked deployments (§6.2): only the console's channel sync calls |
| + // PutLinkChannel (one writer). |
| + PutLinkChannel(registry.LinkChannel) (bool, error) |
| + RevokeLinkChannel(linkID string) (bool, error) |
| + LinkChannelAuth() (map[string]string, error) |
| + LinkOwners() (map[string]string, error) |
| + SetLinkSeen(linkID string, seq uint64, connected bool, at time.Time) error |
| + ResetLinkSeen() error |
| + LinkSeen() (map[string]registry.LinkSeen, error) |
| + LinkForwards(linkID string) ([]registry.Route, error) |
| + DeleteLinkForward(host, linkID string) (bool, error) |
| } |
| var ( |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 38f9dc899..e4c9268fd 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -155,3 +155,4 @@ plan14-root-reads-gvisor-probe-diag.tsv a9ae6b238b6b2e177be1f9c7ae06ea0f24477e4e |
| plan14-root-reads-deploy-happy-path.tsv a9ae6b238b6b2e177be1f9c7ae06ea0f24477e4eb0e58abda63f4b7337dbe3ee |
| plan14-root-reads-held-move-speed.tsv 837f27a6b7b6ed272f8c68aca07650fa32cf3ec92ce28bf9d812a4282eeb0b58 |
| plan14-root-reads-litestream-quiet-802.tsv 6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f83022504aa04c7684c72c93aa9a |
| +plan14-root-reads-linked-deployments-slice1.tsv 4bcb934c032609d263f304730dd24003c56abfb9def6aec6e27dd847659bcf5d |
diff --git a/internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv b/internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv| new file mode 100644 |
| index 000000000..1e16957d7 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv |
| @@ -0,0 +1,38 @@ |
| +# Census overlay linked-deployments-slice1, written by census-propose (#369). census-ruling-linked-deployments-slice1, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-linked-deployments-slice1.md. |
| +# 2 body, 2 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 14 new dispositions: 1 reads re-frozen at their disposition with the claim, 12 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 1 other. |
| +@legacy 6487af86ec8ee5c304f749f5e9653f5a6e3dc28412ef29bebe655ec471de70ff internal/registry/forward.go Registry.DeleteForward legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 2: deletes a forward row only (WHERE kind = 'forward'); remote-or-local shape of every narrow setter (+file:Exec, +registry:Changed, +registry:remote x2, +registry:sql, +whole:remoteClient x2).;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: the one DELETE also refuses a link-placed forward row (AND substr(region, 1, 5) <> 'link/'); a narrower delete, no read added file:Exec@217,registry:Changed@183,registry:remote@66,registry:remote@98,registry:sql@217,whole:remoteClient@100,whole:remoteClient@68 b8340d223ba36ae1cc71c54f86c2d9202dbc8e87aaf968c3054eb7068ad2400c |
| +@legacy 544abafd127151ae3d3af1f0a32503ab414f37952965e3c3acc76f881ffdcec4 internal/registry/registry.go Registry.migrate legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user), on every registry open; a box CLI verb that opens the registry directly runs it as whoever runs the verb: census-ruling-seeded-instances's body with two more columns added to routes (incarnation and serving_seq, INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule); self-serve moves 1 Task 7;rev3=census-ruling-rootfs-apps-2;basis=one more ALTER TABLE, routes ADD COLUMN runtime TEXT NOT NULL DEFAULT '', beside main's rate_limit, assets_off, asset_gen, incarnation and serving_seq (the last four from the merges of origin/main 3c33f2eb and 953b9fda); the same sixteen sites, no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328/#329 plan 1 Task 4: three more ALTER TABLE statements in the existing loop, routes ADD COLUMN egress_allow, size and policy_expires_at, each TEXT NOT NULL DEFAULT '' and idempotent through the duplicate-column rule; the same sixteen sites, no read added.;rev3=census-ruling-region-ha-p1a;basis=one more ALTER TABLE in the existing loop: routes ADD COLUMN ha INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule; the same sixteen sites, no read added;rev3=census-ruling-ha-p1a-433;basis=the registry's SQLite side as carlos (agent, registry child; a box CLI verb that opens the registry directly runs it as whoever runs it), on every registry open: the ALTER TABLE routes statements are now built from the one migration definition routeAddedColumns (addedColumn name, type, default; review r1 P2): for each entry without the Claim mark, "ALTER TABLE routes ADD COLUMN " + spec(), byte for byte the statements main runs, in main's order, under the same duplicate-column rule. +registry:Claim is that mark, +whole:addedColumn the struct. Every name, type and default is an in-binary literal; no statement added, removed or changed; no read added.;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: one more CREATE TABLE IF NOT EXISTS regional_domains (host TEXT PRIMARY KEY, target, account, app, region TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL DEFAULT 0), beside wildcard_domains; the added sites are that statement (+file:Exec, +registry:sql), an in-binary literal; additive, no existing statement changed;rev3=census-ruling-region-ha-p1b3b-t;basis=Create local HA duty/replay tables and revision triggers in the existing registry connection; no new database path.;rev3=census-ruling-agent-start-demo-3;basis=Create moved-notice storage as a single (id, wire) row; fingerprints include the stored wire bytes. Census read-site delta: +file:Exec, +registry:sql.;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: calls migrateLinks after migrateHADuties (one CREATE TABLE IF NOT EXISTS link_channels, an in-binary literal); additive, no existing statement changed file:Exec@1124,file:Exec@1855,file:Exec@212,file:Exec@2409,file:Exec@3347,file:Exec@3626,file:Exec@4489,file:Exec@4665,file:Exec@51,file:Exec@761,registry:Claim@686,registry:sql@1124,registry:sql@1855,registry:sql@212,registry:sql@2409,registry:sql@3347,registry:sql@3626,registry:sql@4489,registry:sql@4665,registry:sql@51,registry:sql@761,whole:addedColumn@661 4a7dc13b176666371df45f6eda53688a3f8f9579de7ad8a2e459afb3d4dba116 |
| +@legacy e70f7d3114b383da7bd236ef53642b4ded74f395d22741ffa42f30638472a597 internal/registry/links.go Registry.DeleteLinkForward legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: deletes host's row only while it is a forward row placed exactly link/<linkID> (validated ID); remote-or-local shape of every narrow setter file:Exec@346,registry:Changed@312,registry:remote@175,registry:remote@207,registry:sql@346,whole:remoteClient@177,whole:remoteClient@209 b4eb7a228abe47f59f7d7b24e852014f1bc0eb1a468b88510b51239371d53e22 |
| +@legacy 11c4910fcedf49657f3161d0b7d079becedc2be530f32d09c5149c3c88208b24 internal/registry/links.go Registry.LinkChannelAuth legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: active link_channels token hashes keyed by link:<id>/home, via activeLinkMap; remote-or-local shape registry:StringMap@177,registry:remote@102,registry:remote@70,whole:remoteClient@104,whole:remoteClient@72 7dd9c9b6f9df7401d71b9dfaec929083111f19aa96c37f4dd058d8d2664deb3f |
| +@legacy a0b67cb74b6908970585ef8431ce450014c7c1e5d8110fae4a08efab095dcfc6 internal/registry/links.go Registry.LinkForwards legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: SELECT routeCols FROM routes for forward rows placed link/<linkID> over a fresh connection to the box's own registry database; remote-or-local shape file:Query@407,registry:Routes@285,registry:remote@165,registry:remote@197,whole:Route@289,whole:Route@702,whole:Route@715,whole:Route@720,whole:Route@734,whole:remoteClient@167,whole:remoteClient@199 0e111abd6943c2f4c6c0be4100df66d1b06f7f98589ce9e5980e6cf6c47e2111 |
| +@legacy 075506406cdd9c5ed33762054436dcc8a8d2a277b11a53d054c98df6d08908fd internal/registry/links.go Registry.LinkOwners legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: active link_channels link ID to account, via activeLinkMap; remote-or-local shape registry:StringMap@167,registry:remote@65,registry:remote@97,whole:remoteClient@67,whole:remoteClient@99 e1051c3e409bddac3cb28a387f9fb91cc20a665468cd0af6e72bf317d89d1215 |
| +@legacy 5356aa82dc1cb0865b3c423fc5fe7aa9340c36151e5c781681781f1bbcd1c523 internal/registry/links.go Registry.LinkSeen legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: link_channels link_id, connected, seen_at over a fresh connection to the box's own registry database; remote-or-local shape file:Query@289,registry:At@650,registry:LinkSeen@165,registry:remote@65,registry:remote@97,whole:LinkSeen@169,whole:LinkSeen@680,whole:LinkSeen@690,whole:LinkSeen@703,whole:remoteClient@67,whole:remoteClient@99 e1c2ee1ae476d7fc7caa9eb9a91077f140e8121fd3c98245177f46925bb07444 |
| +@legacy 1fee766ac3979cb8d3cf05e5c3754590b08a4dc41391c898bcadaf081afe4bb4 internal/registry/links.go Registry.PutLinkChannel legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: validates ID, account, 64-hex hash, status, then in one IMMEDIATE transaction upserts link_channels only when the generation is newer and the stored row is not revoked, and prunes the link's forward rows the channel no longer admits; the box's own registry database, as carlos file:Exec@1008,file:Exec@1626,registry:Account@1399,registry:Account@192,registry:Changed@836,registry:CreatedAt@892,registry:CreatedAt@927,registry:Generation@1448,registry:Generation@584,registry:Generation@700,registry:LinkID@106,registry:LinkID@1389,registry:LinkID@1656,registry:LinkID@1666,registry:LinkID@176,registry:LinkID@269,registry:LinkID@411,registry:LinkID@558,registry:LinkID@690,registry:Status@1423,registry:Status@427,registry:Status@451,registry:Status@568,registry:TokenHash@1410,registry:TokenHash@301,registry:remote@721,registry:remote@753,whole:LinkChannel@812,whole:LinkChannel@818,whole:remoteClient@723,whole:remoteClient@755 5554d5b3cb8c0118b2187df2be4cb9a9331b4b996ee0a66f56ff71aed1d2ae0f |
| +@legacy 274bc260b765279dec8fcbe2b2b4a5500b4f196cbdee860753e4a440ac64a353 internal/registry/links.go Registry.ResetLinkSeen legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: one UPDATE link_channels SET connected = 0; remote-or-local shape file:Exec@168,registry:remote@47,registry:remote@77,registry:sql@168,whole:remoteClient@49,whole:remoteClient@79 d421540828c003ee534eed9f9fba13cbafca153cb1b542656f89f1d6ddfb9747 |
| +@legacy 8bb8f3d4620c24a7bc24ed874a218538a40dbea6360446cf614a434fc2e9de29 internal/registry/links.go Registry.RevokeLinkChannel legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: in one IMMEDIATE transaction marks link_channels revoked (inserting a revoked tombstone for an unknown ID) and deletes the link's forward rows; validated ID file:Exec@393,file:Exec@768,registry:Changed@294,registry:remote@169,registry:remote@201,whole:remoteClient@171,whole:remoteClient@203 122015cd6b79de82e2c193772ed7cc7b63acbedaabc96365ce589808037a8664 |
| +@legacy b1f8c9cdff5b44d02bff35c43f9db9b56788bd1b1ad13030e3a7cf2ac82d0403 internal/registry/links.go Registry.SetLinkSeen legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: one UPDATE of link_channels connected, seq, seen_at; a disconnect only while the stored seq matches; validated ID file:Exec@555,file:Exec@695,registry:remote@294,registry:remote@324,registry:sql@555,registry:sql@695,whole:remoteClient@296,whole:remoteClient@326 76aff8f316119b7227092cfb54906f336beb5714d76b5011d9e23a9b5bf8969f |
| +@legacy ff46e8db406d2db6eaabe630355aac9f0b68247a7712908f2bbb5780e7dba390 internal/registry/links.go Registry.activeLinkMap legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: runs an in-binary SELECT of two link_channels columns over a fresh connection (freshFleetsConn) to the box's own registry database file:Query@203 8382e06eb0164a59e0d0819cca99fd70e1753815cd08e3d19b86ad78bc5e09bb |
| +@legacy bc6cfd76dc7ea2df82dd63923661e77b19caa5a4a35671304c0fa49c5a167a6a internal/registry/links.go Registry.migrateLinks legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: one CREATE TABLE IF NOT EXISTS link_channels, an in-binary literal file:Exec@53,registry:sql@53 43b435d6429ffc5e031bf1a40a27a6c8318a5113879fc3bef1adf76e023dd174 |
| +@legacy 7c5b1ee8dcbb696d502ea9898d712f8d8995dc38cc0c7c4393db09bbfefc2584 internal/registry/links.go linkAdmits legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: one SELECT 1 FROM link_channels inside PutForward's transaction file:QueryRow@78 f1b3b63e4ffacabb08c4d981a181aa73d0117da0875544a43abf6284b7df7483 |
| +@legacy 645f2b6273823f863b1b1fefa4d84b4d683a3956d4de8d6b06fede15c938fcd4 internal/registry/forward.go Registry.PutForward legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 2: the only writer of a forward row's declared columns: refuses an argument whose kind is not forward; copies only the declared fields from its argument (Status ready, Provisioned true; no forbidden column is ever written); inside one IMMEDIATE transaction refuses a host a non-forward row holds (ErrHostHeld); keeps FleetBox while Region is unchanged; preserves the observational columns (+file:Exec, +file:QueryRow, +registry:Account, App, Channel, RateLimit, Region, Slug, +registry:Host x3, +registry:Kind, +registry:remote x2, +whole:Route x3, +whole:remoteClient x2).;rev3=census-ruling-fleet-routes-followups;basis=refuses up front, with the new sentinel ErrNotForward and before any read or write, an rt that is not a forward row (as before, now a sentinel), has an empty Host, or whose Region is not a fleet placement (registry.FleetPlacement); +registry:Host x2 and +registry:Region x2 read only the argument in those checks; the transaction and statement are unchanged;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (Task 5, rule 3), merged with main's ErrNotForward refusals (kept unchanged): the written row also carries FleetLabel = rt.FleetLabel and FleetBox = rt.FleetLabel; its conflict arm (forwardKept) writes fleet_label from the call and fleet_box as the call's label when set, else kept while the region is unchanged. The hub's forward phase in the agent, not root.;rev3=census-ruling-stateless-replicas-1;basis=Carry declarative Stateless into forward rows under existing transaction and shape guards; projection only.;rev3=census-ruling-agent-start-demo-1;basis=Reads and carries the four demo fields in the existing forward INSERT; the guarded conflict SQL refuses downgrade or identity change.;rev3=census-ruling-stateless-replicas-2;basis=Validates canonical set projection, writes explicit declarative columns and clears single-box binding; all forbidden columns zero. Same transaction/read source. merge of origin/main 6be08467: Retain main demo columns and immutable descriptor conflict guard alongside set validation/projection; merge-only existing route fields.;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: also accepts a Region that LinkPlacement parses (link/ + 12 hex), refusing a link row with a FleetLabel (ErrNotForward); the existing in-transaction SELECT also reads the held row's region and refuses a different placement class (ErrHostHeld); a link row additionally needs an active link_channels row of its account in the same transaction (linkAdmits, ErrLinkInactive). Same transaction and statement; the added reads are the argument and the box's own registry database, as carlos file:Exec@2052,file:QueryRow@1631,registry:Account@1092,registry:Account@1989,registry:App@1069,registry:Channel@1145,registry:Copies@1392,registry:DemoExpiresAt@960,registry:DemoHost@901,registry:DemoID@880,registry:DemoLifetime@928,registry:FleetBox@1513,registry:FleetBoxes@1369,registry:FleetBoxes@1490,registry:FleetLabel@1280,registry:FleetLabel@1310,registry:FleetLabel@1525,registry:FleetLabel@540,registry:Host@1693,registry:Host@250,registry:Host@287,registry:Host@500,registry:Host@660,registry:Host@993,registry:Kind@259,registry:RateLimit@1172,registry:Region@1119,registry:Region@130,registry:Region@1898,registry:Region@509,registry:Region@82,registry:ReplicaIncarnation@1460,registry:ReplicaRevision@1420,registry:Slug@1045,registry:Stateless@1340,registry:remote@737,registry:remote@767,whole:Route@2085,whole:Route@822,whole:Route@830,whole:remoteClient@739,whole:remoteClient@769 92749de50752ac228f653180d60ea0b177331657a7062598c8b877b35c694106 |
| +@legacy a6cb59b1acada968c3228a1a943bec945ec3d72ae1609dcaaed0277feef63043 internal/registry/registry.go Registry.Fingerprint legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user); the remote arm, unchanged, in the process that holds a remote handle: census-ruling-seeded-instances's body with the row's lifetime pair (incarnation, serving_seq) folded into the edge's change poll, each only when non-zero, so a registry with no pair digests as before; self-serve moves 1 Task 7;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: hashes regional_domains (host, target, account, app, region; created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no regional rows digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; no file path read;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): review R1 finding 1: the routes SELECT also reads host, kind, account, app, platform and fingerprintForwardInert (one CASE over the ForwardForbidden columns), and every row folds host, kind, account and app (tagged, quoted), platform when set, and forward_inert=0 for a forward row that is not inert, so a rowid reused by another hostname, an in-place account or app rewrite, or a stray forbidden column moves the edge's change poll. Same one SELECT per table on the same fresh connection to the box's own registry database, as carlos; no table, file or bucket read added; a digest, never a decision.;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (Task 5): the SELECT also reads fleet_label and, only when it is set, hashes "fleet_label=<q>" into the digest, so labelling a row moves the edge's reload fingerprint. Read sites unchanged (33). Registry side, not root; an unlabelled registry's digest is byte-identical.;rev3=census-ruling-stateless-replicas-1;basis=Read the additive stateless projection in the existing registry SELECT and hash only when set; no new read source.;rev3=census-ruling-agent-start-demo-1;basis=Existing SELECT reads four more demo columns; only a marked row adds them to the hash, so ordinary hashes remain unchanged.;rev3=census-ruling-stateless-replicas-2;basis=Four additive projection columns join the existing routes SELECT and hash only when nonzero; no new query or file read. merge of origin/main 6be08467: Union main demo identity and expiry with replica columns in the same SELECT and hash; merge-only body change.;rev3=census-ruling-agent-start-demo-3;basis=Hash moved-notice wire bytes so notice-only changes invalidate an edge route snapshot. Census read-site delta: +file:QueryRow.;rev3=census-ruling-edge-page-cache-1;basis=selects the new pages_off column with the rest and folds "pages_off=1" into the hash only when set, as assets_off, so a registry that never sets it fingerprints as before; same routes SELECT, no new table; read sites unchanged (34); no read added;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: hashes link_channels (link_id, account, token_hash, status, generation; connected, seen_at, seq and created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no links digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; a digest, never a decision file:Exec@284,file:Open@188,file:Query@10785,file:Query@11990,file:Query@368,file:Query@6655,file:Query@7134,file:Query@8120,file:Query@8816,file:Query@9728,file:QueryRow@12638,registry:ClaimIncarnation@1729,registry:ClaimIncarnation@5563,registry:ClaimIncarnation@5640,registry:ClaimOwner@1773,registry:ClaimOwner@5764,registry:ClaimOwner@5829,registry:ClaimRowID@1792,registry:ClaimRowID@5856,registry:ClaimRowID@5922,registry:ClaimStamp@1754,registry:ClaimStamp@5673,registry:ClaimStamp@5737,registry:Incarnation@1848,registry:Incarnation@6143,registry:Incarnation@6207,registry:ServingSeq@1867,registry:ServingSeq@6234,registry:ServingSeq@6297,registry:Text@158,registry:path@207,registry:remote@55,registry:remote@87,whole:remoteClient@57,whole:remoteClient@89 65a6883d3e8b0b81a4861d22ddc434fd63670f42e3c64fb70c07c2cf0603ee08 |
| +internal/registry/forward.go Registry.DeleteForward legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 2: deletes a forward row only (WHERE kind = 'forward'); remote-or-local shape of every narrow setter (+file:Exec, +registry:Changed, +registry:remote x2, +registry:sql, +whole:remoteClient x2).;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: the one DELETE also refuses a link-placed forward row (AND substr(region, 1, 5) <> 'link/'); a narrower delete, no read added file:Exec@217,registry:Changed@183,registry:remote@66,registry:remote@98,registry:sql@217,whole:remoteClient@100,whole:remoteClient@68 b8340d223ba36ae1cc71c54f86c2d9202dbc8e87aaf968c3054eb7068ad2400c |
| +internal/registry/registry.go Registry.migrate legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user), on every registry open; a box CLI verb that opens the registry directly runs it as whoever runs the verb: census-ruling-seeded-instances's body with two more columns added to routes (incarnation and serving_seq, INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule); self-serve moves 1 Task 7;rev3=census-ruling-rootfs-apps-2;basis=one more ALTER TABLE, routes ADD COLUMN runtime TEXT NOT NULL DEFAULT '', beside main's rate_limit, assets_off, asset_gen, incarnation and serving_seq (the last four from the merges of origin/main 3c33f2eb and 953b9fda); the same sixteen sites, no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328/#329 plan 1 Task 4: three more ALTER TABLE statements in the existing loop, routes ADD COLUMN egress_allow, size and policy_expires_at, each TEXT NOT NULL DEFAULT '' and idempotent through the duplicate-column rule; the same sixteen sites, no read added.;rev3=census-ruling-region-ha-p1a;basis=one more ALTER TABLE in the existing loop: routes ADD COLUMN ha INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule; the same sixteen sites, no read added;rev3=census-ruling-ha-p1a-433;basis=the registry's SQLite side as carlos (agent, registry child; a box CLI verb that opens the registry directly runs it as whoever runs it), on every registry open: the ALTER TABLE routes statements are now built from the one migration definition routeAddedColumns (addedColumn name, type, default; review r1 P2): for each entry without the Claim mark, "ALTER TABLE routes ADD COLUMN " + spec(), byte for byte the statements main runs, in main's order, under the same duplicate-column rule. +registry:Claim is that mark, +whole:addedColumn the struct. Every name, type and default is an in-binary literal; no statement added, removed or changed; no read added.;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: one more CREATE TABLE IF NOT EXISTS regional_domains (host TEXT PRIMARY KEY, target, account, app, region TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL DEFAULT 0), beside wildcard_domains; the added sites are that statement (+file:Exec, +registry:sql), an in-binary literal; additive, no existing statement changed;rev3=census-ruling-region-ha-p1b3b-t;basis=Create local HA duty/replay tables and revision triggers in the existing registry connection; no new database path.;rev3=census-ruling-agent-start-demo-3;basis=Create moved-notice storage as a single (id, wire) row; fingerprints include the stored wire bytes. Census read-site delta: +file:Exec, +registry:sql.;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: calls migrateLinks after migrateHADuties (one CREATE TABLE IF NOT EXISTS link_channels, an in-binary literal); additive, no existing statement changed file:Exec@1124,file:Exec@1855,file:Exec@212,file:Exec@2409,file:Exec@3347,file:Exec@3626,file:Exec@4489,file:Exec@4665,file:Exec@51,file:Exec@761,registry:Claim@686,registry:sql@1124,registry:sql@1855,registry:sql@212,registry:sql@2409,registry:sql@3347,registry:sql@3626,registry:sql@4489,registry:sql@4665,registry:sql@51,registry:sql@761,whole:addedColumn@661 4a7dc13b176666371df45f6eda53688a3f8f9579de7ad8a2e459afb3d4dba116 |
| +internal/registry/links.go Registry.DeleteLinkForward legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: deletes host's row only while it is a forward row placed exactly link/<linkID> (validated ID); remote-or-local shape of every narrow setter file:Exec@346,registry:Changed@312,registry:remote@175,registry:remote@207,registry:sql@346,whole:remoteClient@177,whole:remoteClient@209 b4eb7a228abe47f59f7d7b24e852014f1bc0eb1a468b88510b51239371d53e22 |
| +internal/registry/links.go Registry.LinkChannelAuth legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: active link_channels token hashes keyed by link:<id>/home, via activeLinkMap; remote-or-local shape registry:StringMap@177,registry:remote@102,registry:remote@70,whole:remoteClient@104,whole:remoteClient@72 7dd9c9b6f9df7401d71b9dfaec929083111f19aa96c37f4dd058d8d2664deb3f |
| +internal/registry/links.go Registry.LinkForwards legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: SELECT routeCols FROM routes for forward rows placed link/<linkID> over a fresh connection to the box's own registry database; remote-or-local shape file:Query@407,registry:Routes@285,registry:remote@165,registry:remote@197,whole:Route@289,whole:Route@702,whole:Route@715,whole:Route@720,whole:Route@734,whole:remoteClient@167,whole:remoteClient@199 0e111abd6943c2f4c6c0be4100df66d1b06f7f98589ce9e5980e6cf6c47e2111 |
| +internal/registry/links.go Registry.LinkOwners legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: active link_channels link ID to account, via activeLinkMap; remote-or-local shape registry:StringMap@167,registry:remote@65,registry:remote@97,whole:remoteClient@67,whole:remoteClient@99 e1051c3e409bddac3cb28a387f9fb91cc20a665468cd0af6e72bf317d89d1215 |
| +internal/registry/links.go Registry.LinkSeen legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: link_channels link_id, connected, seen_at over a fresh connection to the box's own registry database; remote-or-local shape file:Query@289,registry:At@650,registry:LinkSeen@165,registry:remote@65,registry:remote@97,whole:LinkSeen@169,whole:LinkSeen@680,whole:LinkSeen@690,whole:LinkSeen@703,whole:remoteClient@67,whole:remoteClient@99 e1c2ee1ae476d7fc7caa9eb9a91077f140e8121fd3c98245177f46925bb07444 |
| +internal/registry/links.go Registry.PutLinkChannel legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: validates ID, account, 64-hex hash, status, then in one IMMEDIATE transaction upserts link_channels only when the generation is newer and the stored row is not revoked, and prunes the link's forward rows the channel no longer admits; the box's own registry database, as carlos file:Exec@1008,file:Exec@1626,registry:Account@1399,registry:Account@192,registry:Changed@836,registry:CreatedAt@892,registry:CreatedAt@927,registry:Generation@1448,registry:Generation@584,registry:Generation@700,registry:LinkID@106,registry:LinkID@1389,registry:LinkID@1656,registry:LinkID@1666,registry:LinkID@176,registry:LinkID@269,registry:LinkID@411,registry:LinkID@558,registry:LinkID@690,registry:Status@1423,registry:Status@427,registry:Status@451,registry:Status@568,registry:TokenHash@1410,registry:TokenHash@301,registry:remote@721,registry:remote@753,whole:LinkChannel@812,whole:LinkChannel@818,whole:remoteClient@723,whole:remoteClient@755 5554d5b3cb8c0118b2187df2be4cb9a9331b4b996ee0a66f56ff71aed1d2ae0f |
| +internal/registry/links.go Registry.ResetLinkSeen legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: one UPDATE link_channels SET connected = 0; remote-or-local shape file:Exec@168,registry:remote@47,registry:remote@77,registry:sql@168,whole:remoteClient@49,whole:remoteClient@79 d421540828c003ee534eed9f9fba13cbafca153cb1b542656f89f1d6ddfb9747 |
| +internal/registry/links.go Registry.RevokeLinkChannel legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: in one IMMEDIATE transaction marks link_channels revoked (inserting a revoked tombstone for an unknown ID) and deletes the link's forward rows; validated ID file:Exec@393,file:Exec@768,registry:Changed@294,registry:remote@169,registry:remote@201,whole:remoteClient@171,whole:remoteClient@203 122015cd6b79de82e2c193772ed7cc7b63acbedaabc96365ce589808037a8664 |
| +internal/registry/links.go Registry.SetLinkSeen legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: one UPDATE of link_channels connected, seq, seen_at; a disconnect only while the stored seq matches; validated ID file:Exec@555,file:Exec@695,registry:remote@294,registry:remote@324,registry:sql@555,registry:sql@695,whole:remoteClient@296,whole:remoteClient@326 76aff8f316119b7227092cfb54906f336beb5714d76b5011d9e23a9b5bf8969f |
| +internal/registry/links.go Registry.activeLinkMap legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: runs an in-binary SELECT of two link_channels columns over a fresh connection (freshFleetsConn) to the box's own registry database file:Query@203 8382e06eb0164a59e0d0819cca99fd70e1753815cd08e3d19b86ad78bc5e09bb |
| +internal/registry/links.go Registry.migrateLinks legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: one CREATE TABLE IF NOT EXISTS link_channels, an in-binary literal file:Exec@53,registry:sql@53 43b435d6429ffc5e031bf1a40a27a6c8318a5113879fc3bef1adf76e023dd174 |
| +internal/registry/links.go linkAdmits legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new: one SELECT 1 FROM link_channels inside PutForward's transaction file:QueryRow@78 f1b3b63e4ffacabb08c4d981a181aa73d0117da0875544a43abf6284b7df7483 |
| +internal/registry/remote_dispatch.go Registry.dispatchRemote hint E2 rev3=census-ruling-self-serve-moves-1;basis=the registry child (carlos __registry-child, the service user a root pass forks): plan14-root-reads-e's mixed declaration (E2 adds only the ArtifactHosts read; every other arm is the local method of the same name), with three more write arms, SetHoldIfSeq, ReleaseHoldSeq and InstallLifetimeIf, each calling the local setter; no read operation added; self-serve moves 1 Task 7;rev3=census-ruling-instance-egress-sizes-328-329;identity=the registry child (carlos __registry-child, the service user a root pass forks);basis=#328/#329 plan 1 Task 4: one more write arm, SetPolicy, calling the local Registry.SetPolicy with the request's Host, EgressAllow, Size and PolicyExpiresAt (remoteRequest fields sent by the remote handle's holder); the new kinds registry:EgressAllow, registry:Size and registry:PolicyExpiresAt, one site each, plus one more registry:Host site, all of the request; no read operation added; the read-only worker never reaches it (serveRemote's method gate); no production root pass sends SetPolicy;rev3=census-ruling-region-ha-p1a;basis=the registry child (carlos __registry-child, the service user a root pass forks): one more write arm, SetHA, calling the local Registry.SetHA with the request's Host (+registry:Host); no read operation added; only the provision pass sends it;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 2 and 8: two new remote methods, UpsertUnlessRootfs (carlos add's guarded write) and ResidentInstances (the residency sweep's list), each calling the same-named Registry method;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: two more methods on the existing remote registry transport, ListRegional and ReplaceRegionalSet (request field RDs, response field Regional), each calling the local method of the same name, which validates its own input; no new kind of read;rev3=census-ruling-fleet-secrets-key;basis=one new case, SetFleetSecretsKey, reading the request's Name, Pub, KeyFP, By and At fields and calling SetFleetSecretsKey;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Tasks 1-2: three new cases (SetFleetBoxIf reads the request's Fleet and answers Changed; PutForward reads TValue, a whole Route; DeleteForward reads Host and answers Changed); SetFleetBox gone (+registry:Changed x2, +registry:Fleet, +registry:Host, +registry:TValue, +whole:Route). Each case calls the local writer with its own guards.;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (Tasks 2 and 6b): three more remote methods dispatched to their local forms, SetFleetBoxDraining (q.Fleet, q.Label, q.At, answering Number64), MarkFleetBoxLabelled (q.Fleet, q.Label, q.At) and SetFleetAssignment (q.Host, q.Assigned, q.Moved); remoteRequest gains Assigned and Moved. The registry child, not root.;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Add SetServingMode dispatch using the existing remote request Host, Ver and On fields; the same local narrow writer handles it. No new transport or root path. Task 4 R24: dispatch SeedStateless with the existing Observed Route and On carriers to its symmetric guarded local method. No new transport; the existing read-only service gate still refuses writes.;rev3=census-ruling-region-ha-p1b3b-t;basis=Dispatch typed duty, import, exact replacement and guarded receipt operations through the existing service-user registry transport, preserving comparisons and errors. B2 fix r1: dispatch AdvanceHADuty through the existing service-user registry channel and error mapping, reading the request Host only. Read-only method allowlist remains unchanged. B3b: transport bounded typed local journal requests and results over the existing authenticated registry channel; no arbitrary SQL or disk path.;rev3=census-ruling-managed-fleets-2a;basis=Expose the two owned managed preparation methods with Fleet envelope fields, preserving conditional result. Witness TestManagedRegistryPreparationMethods local/remote parity. Dispatch ClearFleetBoxDraining with fleet, label and timestamp to validated local method; no new transport or root path. Witness TestManagedConditionalDrainClear. Dispatch managed insert with FleetBox and At, and return Changed for conditional drain clear. Existing transport and local validation; no new root path. Witness TestAddManagedFleetBox local/remote parity.;rev3=census-ruling-stateless-replicas-2;basis=Slice 3b: adds ClearReplicaAssignment over the existing typed registry RPC; local writer checks the complete observed row. Existing read-only RPC gate unchanged. merge of origin/main 9b8b2c50: retain all HA journal/duty/wake/adoption RPCs alongside replica assignment RPCs; union of request/response fields and error sentinels, unchanged transport and read-only gate. Merge 0b3098cb also retains main's two managed fleet RPCs; the replica RPCs and shared refusal gate remain intact.;rev3=census-ruling-managed-fleets-2b1;basis=managed fleets 2b-1 Task 1: the registry child (carlos __registry-child, the service user a root pass forks) answers GetFleet and ListFleetBoxes with GetFleetContext(ctx, q.Name) and ListFleetBoxesContext(ctx, q.Fleet), passing its existing request context so a cancelled caller ends the child's SQL read; same request fields (Name, Fleet) and same local queries; no method, field or read operation added; read-only method gate unchanged;rev3=census-ruling-edge-page-cache-1;basis=adds the SetPages method: r.SetPages(q.Host, q.PagesOff), the request's PagesOff field (the +registry:Host and +registry:PagesOff sites); the same dispatch as SetAssets. Merged onto main's body at 04dc1dc0 (managed fleets 2b-1: GetFleet and ListFleetBoxes now go through their Context forms with the dispatch ctx), which this branch does not change;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: nine more cases (PutLinkChannel, RevokeLinkChannel, LinkChannelAuth, LinkOwners, SetLinkSeen, ResetLinkSeen, LinkSeen, LinkForwards, DeleteLinkForward), each calling the local method with request fields; no other case changed registry:A@10075,registry:Account@2988,registry:Account@3087,registry:Account@6291,registry:Accounts@4953,registry:Addr@6868,registry:Addrs@6876,registry:Adoption@1013,registry:Adoption@818,registry:Alias@10123,registry:Alias@10187,registry:Alias@10275,registry:Aliases@9997,registry:Alive@11950,registry:Args@9699,registry:AssetGen@7075,registry:AssetsOff@7062,registry:Assigned@7553,registry:Assignment@8969,registry:Assignment@9067,registry:At@10206,registry:At@10284,registry:At@11698,registry:At@3322,registry:At@3390,registry:At@3782,registry:At@3879,registry:At@3964,registry:At@8447,registry:Attempts@11720,registry:B@3385,registry:B@3439,registry:Backing@6687,registry:Bucket@3100,registry:BuildState@7312,registry:By@3316,registry:Changed@11630,registry:Changed@2860,registry:Changed@2933,registry:Changed@3034,registry:Changed@322,registry:Changed@3721,registry:Changed@4152,registry:Changed@4225,registry:Changed@464,registry:Changed@4674,registry:Changed@5376,registry:Changed@5463,registry:Changed@5552,registry:Changed@5623,registry:Changed@564,registry:Changed@5727,registry:Changed@5814,registry:Changed@5907,registry:Changed@5989,registry:Changed@7900,registry:Changed@8037,registry:Changed@832,registry:Changed@8634,registry:Changed@8822,registry:Changed@929,registry:Channel@6351,registry:Channel@7743,registry:Channel@8292,registry:CheckedAt@8373,registry:Class@6806,registry:DoneBefore@11959,registry:Due@11742,registry:Due@9400,registry:Due@9464,registry:Duty@312,registry:Duty@390,registry:Duty@634,registry:EgressAllow@7215,registry:Env@7811,registry:Env@8203,registry:Env@8303,registry:ExcludeHosts@11425,registry:ExcludeHosts@11520,registry:ExpectGood@8572,registry:ExpectOp@5431,registry:ExpectOp@5681,registry:ExpectPair@5861,registry:Expected@1001,registry:Expected@1153,registry:Expected@1626,registry:Expected@1803,registry:Expected@2114,registry:F@2832,registry:F@2893,registry:F@2978,registry:F@2988,registry:F@3077,registry:F@3087,registry:F@3100,registry:Fleet@3132,registry:Fleet@3497,registry:Fleet@3579,registry:Fleet@3660,registry:Fleet@3764,registry:Fleet@3861,registry:Fleet@3946,registry:Fleet@4047,registry:Fleet@7943,registry:FleetBoxes@3996,registry:Fleets@3202,registry:From@6462,registry:From@6523,registry:FromDB@6598,registry:FromOp@5519,registry:FromSock@6608,registry:HAJournal@183,registry:HAJournal@221,registry:Hash@7617,registry:Health@6885,registry:Host@10493,registry:Host@10619,registry:Host@10773,registry:Host@11061,registry:Host@11125,registry:Host@11184,registry:Host@11267,registry:Host@11350,registry:Host@1136,registry:Host@11581,registry:Host@11666,registry:Host@11798,registry:Host@11879,registry:Host@12042,registry:Host@1888,registry:Host@1999,registry:Host@286,registry:Host@350,registry:Host@422,registry:Host@4713,registry:Host@501,registry:Host@5137,registry:Host@5178,registry:Host@5331,registry:Host@5407,registry:Host@5493,registry:Host@5585,registry:Host@5657,registry:Host@5763,registry:Host@5853,registry:Host@5941,registry:Host@602,registry:Host@6033,registry:Host@6283,registry:Host@6343,registry:Host@6401,registry:Host@6454,registry:Host@6515,registry:Host@6590,registry:Host@6679,registry:Host@6733,registry:Host@6798,registry:Host@6860,registry:Host@6938,registry:Host@694,registry:Host@6995,registry:Host@7054,registry:Host@7142,registry:Host@7207,registry:Host@7304,registry:Host@7369,registry:Host@7430,registry:Host@7480,registry:Host@7545,registry:Host@7609,registry:Host@7670,registry:Host@772,registry:Host@7803,registry:Host@7857,registry:Host@7935,registry:Host@8072,registry:Host@8125,registry:Host@8355,registry:Host@8439,registry:Host@8496,registry:Host@8564,registry:Host@869,registry:Host@8779,registry:Host@9044,registry:Host@9201,registry:Host@9277,registry:Host@9337,registry:Host@9392,registry:Host@9456,registry:Host@9640,registry:Host@9691,registry:Host@973,registry:Host@9758,registry:Host@9833,registry:Host@9896,registry:Hosts@1051,registry:Hosts@5016,registry:Hosts@7734,registry:Hosts@8194,registry:Hosts@8283,registry:Id@2108,registry:Id@2419,registry:Id@2518,registry:Id@2598,registry:Id@2749,registry:IdValue@4772,registry:Idle@9766,registry:Import@734,registry:Journal@1306,registry:Journal@2126,registry:Journal@2425,registry:Journal@2604,registry:Keep@12058,registry:KeyFP@3307,registry:Kind@11887,registry:Kind@12050,registry:Label@3506,registry:Label@3588,registry:Label@3669,registry:Label@3773,registry:Label@3870,registry:Label@3955,registry:Label@7952,registry:Lifetime@358,registry:Lifetime@430,registry:Lifetime@517,registry:Lifetime@610,registry:Lifetime@877,registry:Limit@11416,registry:Limit@11511,registry:Link@4188,registry:LinkID@4264,registry:LinkID@4443,registry:LinkID@4635,registry:LinkID@4721,registry:LinkSeen@4545,registry:MaxRun@9774,registry:Method@151,registry:Moved@7565,registry:Ms@11714,registry:Name@11133,registry:Name@11192,registry:Name@11275,registry:Name@11589,registry:Name@11674,registry:Name@11806,registry:Name@1896,registry:Name@2007,registry:Name@2978,registry:Name@3077,registry:Name@3172,registry:Name@3292,registry:Name@4791,registry:Next@1165,registry:NextAt@11732,registry:NextGood@8586,registry:NextValue@2678,registry:NextValue@2776,registry:Now@11409,registry:Now@11504,registry:Now@11597,registry:Now@2031,registry:Now@9967,registry:Number64@3819,registry:Number64@4879,registry:Number@11847,registry:Number@11918,registry:Number@12003,registry:Observed@1229,registry:Observed@8680,registry:Observed@8767,registry:Observed@8867,registry:Observed@8942,registry:Observed@9134,registry:ObservedValue@1507,registry:Old@2671,registry:Old@2769,registry:On@4460,registry:On@9081,registry:On@9146,registry:On@9216,registry:On@9345,registry:On@9841,registry:On@9904,registry:Op@5349,registry:Op@5425,registry:Op@5593,registry:Op@5675,registry:Op@5771,registry:Op@5949,registry:Op@6041,registry:Owner@1144,registry:Owner@1241,registry:Owner@1524,registry:P@10727,registry:PagesOff@7003,registry:Pair@509,registry:Pair@5693,registry:Pair@5777,registry:Pair@5875,registry:Pair@780,registry:Pair@981,registry:Path@10958,registry:Paths@10655,registry:PolicyExpiresAt@7238,registry:Prefix@10781,registry:Prev@8511,registry:Pub@3300,registry:RDs@10627,registry:RateLimit@7678,registry:Receipt@889,registry:Regional@10525,registry:Registration@11283,registry:Registration@11682,registry:Registration@1904,registry:Registration@2015,registry:Replica@7438,registry:ReplicaLife@8954,registry:ReplicaLife@9052,registry:Replicas@7377,registry:Retirement@2755,registry:Revision@529,registry:Revision@622,registry:Revision@989,registry:Route@5114,registry:Routes@4602,registry:Routes@5072,registry:Routes@6067,registry:Routes@9498,registry:Routes@9565,registry:Routes@9934,registry:Rows@11069,registry:Seed@9648,registry:SeenAt@4466,registry:Seq@4453,registry:Size@7230,registry:Sqid@4783,registry:Sqid@4846,registry:Sqid@4925,registry:Status@10196,registry:Status@11704,registry:Status@11814,registry:Status@1920,registry:Status@3678,registry:Status@5339,registry:Status@5415,registry:Status@5501,registry:Status@5665,registry:Status@6409,registry:Status@8363,registry:Steering@6946,registry:StringMap@4084,registry:StringMap@4301,registry:StringMap@4364,registry:T@11009,registry:T@1621,registry:T@1715,registry:T@1798,registry:TValue@5219,registry:TValue@5286,registry:TValue@8002,registry:TValue@8692,registry:Tags@3597,registry:Target@8133,registry:Targets@1317,registry:Text@10814,registry:Text@10877,registry:Text@2324,registry:Text@2471,registry:Text@4893,registry:Timer@11097,registry:Timer@1573,registry:Timer@1755,registry:Timers@11320,registry:Timers@11379,registry:Timers@11468,registry:Times@12092,registry:To@6470,registry:To@6531,registry:ToDB@6620,registry:ToOp@5511,registry:ToSock@6628,registry:TokenHash@3515,registry:Tunnel@7865,registry:Unit@6741,registry:UpdateSettings@7150,registry:Ver@8504,registry:Ver@9209,registry:Ver@9285,registry:W@10427,registry:Wake@702,registry:Wake@788,registry:Wildcards@10321,whole:Account@4957,whole:ClaimOwnership@1146,whole:ClaimOwnership@1243,whole:ClaimOwnership@1526,whole:ClaimRow@1319,whole:ClaimRowArchive@1425,whole:ClaimRowArchive@1435,whole:ColdRows@2673,whole:ColdRows@2680,whole:ColdRows@2771,whole:ColdRows@2778,whole:DutyState@316,whole:DutyState@394,whole:DutyState@636,whole:Fleet@2834,whole:Fleet@2895,whole:Fleet@2980,whole:Fleet@2990,whole:Fleet@3079,whole:Fleet@3089,whole:Fleet@3102,whole:Fleet@3136,whole:Fleet@3206,whole:FleetBox@3387,whole:FleetBox@3441,whole:FleetBox@4000,whole:GoodBuild@8574,whole:GoodBuild@8588,whole:HAAdoption@1015,whole:HAAdoption@822,whole:HAWakeImport@704,whole:HAWakeImport@790,whole:LinkChannel@4190,whole:LinkSeen@4549,whole:Pair@511,whole:Pair@5695,whole:Pair@5779,whole:Pair@5863,whole:Pair@5877,whole:Pair@782,whole:Pair@983,whole:RegionalDomain@10529,whole:RegionalDomain@10629,whole:Route@1231,whole:Route@4606,whole:Route@5076,whole:Route@5118,whole:Route@5221,whole:Route@5288,whole:Route@6071,whole:Route@6226,whole:Route@6232,whole:Route@8004,whole:Route@8682,whole:Route@8694,whole:Route@8769,whole:Route@8869,whole:Route@8944,whole:Route@9136,whole:Route@9502,whole:Route@9569,whole:Route@9938,whole:RouteAlias@10001,whole:RouteAlias@10077,whole:RoutePath@10659,whole:RoutePath@10729,whole:Timer@11011,whole:Timer@11071,whole:Timer@11101,whole:Timer@11324,whole:Timer@11383,whole:Timer@11472,whole:Timer@1509,whole:Timer@1577,whole:Timer@1623,whole:Timer@1717,whole:Timer@1759,whole:Timer@1800,whole:WildcardDomain@10325,whole:WildcardDomain@10429,whole:haJournalRequest@223,whole:haJournalResponse@187 1b38ef86a9afe595b0f5aee2ad267074b7c5b84d63c0d45513618ddc11fbc776 |
| +internal/registry/forward.go Registry.PutForward legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 2: the only writer of a forward row's declared columns: refuses an argument whose kind is not forward; copies only the declared fields from its argument (Status ready, Provisioned true; no forbidden column is ever written); inside one IMMEDIATE transaction refuses a host a non-forward row holds (ErrHostHeld); keeps FleetBox while Region is unchanged; preserves the observational columns (+file:Exec, +file:QueryRow, +registry:Account, App, Channel, RateLimit, Region, Slug, +registry:Host x3, +registry:Kind, +registry:remote x2, +whole:Route x3, +whole:remoteClient x2).;rev3=census-ruling-fleet-routes-followups;basis=refuses up front, with the new sentinel ErrNotForward and before any read or write, an rt that is not a forward row (as before, now a sentinel), has an empty Host, or whose Region is not a fleet placement (registry.FleetPlacement); +registry:Host x2 and +registry:Region x2 read only the argument in those checks; the transaction and statement are unchanged;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (Task 5, rule 3), merged with main's ErrNotForward refusals (kept unchanged): the written row also carries FleetLabel = rt.FleetLabel and FleetBox = rt.FleetLabel; its conflict arm (forwardKept) writes fleet_label from the call and fleet_box as the call's label when set, else kept while the region is unchanged. The hub's forward phase in the agent, not root.;rev3=census-ruling-stateless-replicas-1;basis=Carry declarative Stateless into forward rows under existing transaction and shape guards; projection only.;rev3=census-ruling-agent-start-demo-1;basis=Reads and carries the four demo fields in the existing forward INSERT; the guarded conflict SQL refuses downgrade or identity change.;rev3=census-ruling-stateless-replicas-2;basis=Validates canonical set projection, writes explicit declarative columns and clears single-box binding; all forbidden columns zero. Same transaction/read source. merge of origin/main 6be08467: Retain main demo columns and immutable descriptor conflict guard alongside set validation/projection; merge-only existing route fields.;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: also accepts a Region that LinkPlacement parses (link/ + 12 hex), refusing a link row with a FleetLabel (ErrNotForward); the existing in-transaction SELECT also reads the held row's region and refuses a different placement class (ErrHostHeld); a link row additionally needs an active link_channels row of its account in the same transaction (linkAdmits, ErrLinkInactive). Same transaction and statement; the added reads are the argument and the box's own registry database, as carlos file:Exec@2052,file:QueryRow@1631,registry:Account@1092,registry:Account@1989,registry:App@1069,registry:Channel@1145,registry:Copies@1392,registry:DemoExpiresAt@960,registry:DemoHost@901,registry:DemoID@880,registry:DemoLifetime@928,registry:FleetBox@1513,registry:FleetBoxes@1369,registry:FleetBoxes@1490,registry:FleetLabel@1280,registry:FleetLabel@1310,registry:FleetLabel@1525,registry:FleetLabel@540,registry:Host@1693,registry:Host@250,registry:Host@287,registry:Host@500,registry:Host@660,registry:Host@993,registry:Kind@259,registry:RateLimit@1172,registry:Region@1119,registry:Region@130,registry:Region@1898,registry:Region@509,registry:Region@82,registry:ReplicaIncarnation@1460,registry:ReplicaRevision@1420,registry:Slug@1045,registry:Stateless@1340,registry:remote@737,registry:remote@767,whole:Route@2085,whole:Route@822,whole:Route@830,whole:remoteClient@739,whole:remoteClient@769 92749de50752ac228f653180d60ea0b177331657a7062598c8b877b35c694106 |
| +internal/registry/registry.go Registry.Fingerprint legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user); the remote arm, unchanged, in the process that holds a remote handle: census-ruling-seeded-instances's body with the row's lifetime pair (incarnation, serving_seq) folded into the edge's change poll, each only when non-zero, so a registry with no pair digests as before; self-serve moves 1 Task 7;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: hashes regional_domains (host, target, account, app, region; created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no regional rows digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; no file path read;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): review R1 finding 1: the routes SELECT also reads host, kind, account, app, platform and fingerprintForwardInert (one CASE over the ForwardForbidden columns), and every row folds host, kind, account and app (tagged, quoted), platform when set, and forward_inert=0 for a forward row that is not inert, so a rowid reused by another hostname, an in-place account or app rewrite, or a stray forbidden column moves the edge's change poll. Same one SELECT per table on the same fresh connection to the box's own registry database, as carlos; no table, file or bucket read added; a digest, never a decision.;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (Task 5): the SELECT also reads fleet_label and, only when it is set, hashes "fleet_label=<q>" into the digest, so labelling a row moves the edge's reload fingerprint. Read sites unchanged (33). Registry side, not root; an unlabelled registry's digest is byte-identical.;rev3=census-ruling-stateless-replicas-1;basis=Read the additive stateless projection in the existing registry SELECT and hash only when set; no new read source.;rev3=census-ruling-agent-start-demo-1;basis=Existing SELECT reads four more demo columns; only a marked row adds them to the hash, so ordinary hashes remain unchanged.;rev3=census-ruling-stateless-replicas-2;basis=Four additive projection columns join the existing routes SELECT and hash only when nonzero; no new query or file read. merge of origin/main 6be08467: Union main demo identity and expiry with replica columns in the same SELECT and hash; merge-only body change.;rev3=census-ruling-agent-start-demo-3;basis=Hash moved-notice wire bytes so notice-only changes invalidate an edge route snapshot. Census read-site delta: +file:QueryRow.;rev3=census-ruling-edge-page-cache-1;basis=selects the new pages_off column with the rest and folds "pages_off=1" into the hash only when set, as assets_off, so a registry that never sets it fingerprints as before; same routes SELECT, no new table; read sites unchanged (34); no read added;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: hashes link_channels (link_id, account, token_hash, status, generation; connected, seen_at, seq and created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no links digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; a digest, never a decision file:Exec@284,file:Open@188,file:Query@10785,file:Query@11990,file:Query@368,file:Query@6655,file:Query@7134,file:Query@8120,file:Query@8816,file:Query@9728,file:QueryRow@12638,registry:ClaimIncarnation@1729,registry:ClaimIncarnation@5563,registry:ClaimIncarnation@5640,registry:ClaimOwner@1773,registry:ClaimOwner@5764,registry:ClaimOwner@5829,registry:ClaimRowID@1792,registry:ClaimRowID@5856,registry:ClaimRowID@5922,registry:ClaimStamp@1754,registry:ClaimStamp@5673,registry:ClaimStamp@5737,registry:Incarnation@1848,registry:Incarnation@6143,registry:Incarnation@6207,registry:ServingSeq@1867,registry:ServingSeq@6234,registry:ServingSeq@6297,registry:Text@158,registry:path@207,registry:remote@55,registry:remote@87,whole:remoteClient@57,whole:remoteClient@89 65a6883d3e8b0b81a4861d22ddc434fd63670f42e3c64fb70c07c2cf0603ee08 |
| +@coverage internal/registry b292d21b32a57a29c87a1c3d23b73383b643c459848adad05bf7a1f573f68235 |
| +@fields ?,A,Account,Accounts,AcquiredGeneration,AddedAt,Addr,Addrs,Adoption,Alias,Aliases,Alive,AllowAbsent,App,Archives,Args,AssetGen,AssetsOff,Assigned,Assignment,At,Attempts,B,Backing,Basis,Binding,Blocked,Body,Bucket,BuildState,By,Callback,CallbackError,CallbackFailed,Canary,Caps,CertExpiresAt,Changed,Channel,CheckedAt,Claim,ClaimIncarnation,ClaimOwner,ClaimOwnership,ClaimRowID,ClaimStamp,Class,Code,Column,Connected,Contents,Copies,Count,CreatedAt,Cursor,DBPath,DNSCheckedAt,DNSStatus,Deadline,Default,DeleteUncertain,Demand,DemoExpiresAt,DemoHost,DemoID,DemoLifetime,Departure,DepartureIID,DepartureRef,Departures,Digest,DoneBefore,DrainingSince,Due,DueAt,Duty,EdgesETag,EgressAllow,EnrolledAt,Env,EnvBefore,Environment,Error,ErrorKind,ExcludeHosts,ExpectGood,ExpectOp,ExpectPair,Expected,ExpectedPair,F,Failed,FenceGen,Field,FillLegacyRegistration,Fleet,FleetBox,FleetBoxes,FleetLabel,Fleets,Found,From,FromDB,FromOp,FromSock,Gate,Generation,GoodDemand,GoodDigest,GoodVersion,HA,HAJournal,Hash,Health,Held,Hibernate,Hint,Hints,HoldOp,HolderEpoch,HolderIID,HolderRef,Host,Hosts,ID,IID,Id,IdValue,Identity,Idle,IdleSeconds,Import,ImportGate,Inbox,Incarnation,InventoryGeneration,Journal,Keep,Key,KeyFP,Keys,Kind,Label,LabelledAt,LastAt,LastBlocked,LastError,LastMs,LastPage,LastStatus,Lifetime,Limit,Link,LinkID,LinkSeen,LockETag,LockGeneration,Managed,MaxRun,MaxRunSeconds,MessageID,Method,Moved,Ms,Name,Next,NextAt,NextAttempt,NextDue,NextGood,NextValue,NotBefore,Now,Number,Number64,Observation,Observed,ObservedValue,Offset,Old,Oldest,On,OnConflict,Op,Original,Owner,Ownership,P,Page,PagesOff,Pair,Path,Paths,PermissionAlerted,Phase,Platform,PolicyExpiresAt,Pool,Prefix,Prev,PrevVersion,ProofDigest,ProofKey,Provisioned,Pub,RDs,RateLimit,Raw,Receipt,ReceivedAt,RecordDigest,RecordKey,Ref,Region,Regional,Registration,Replica,ReplicaIncarnation,ReplicaLife,ReplicaRevision,Replicas,Replication,Rescan,Result,Retirement,RetryCount,Revision,Route,Routes,Row,Rows,Runtime,Scan,SecretsKeyFP,SecretsKeySetAt,SecretsKeySetBy,SecretsPub,Seed,SeedID,SeedSource,SeenAt,Seq,Sequence,ServingSeq,ServingVersion,Size,Slug,Socket,Spec,Sqid,StartedAt,State,Stateless,Status,StatusNamed,Steering,StringMap,Summary,T,TValue,Tags,Target,Targets,Text,Timer,Timers,Times,To,ToDB,ToOp,ToSock,TokenHash,Tunnel,Type,Unit,Unresolved,UpdateSettings,Ver,Version,ViewKey,Visited,W,Waiting,Wake,WakeDigest,WakeIncarnation,Walk,Wildcards,closed,conn,connect,ctx,d,dec,done,enc,full,input,output,path,readOnly,remote,slot,sql,wait |
diff --git a/internal/registry/forward.go b/internal/registry/forward.go| index 1d808d787..5db3c4c57 100644 |
| --- a/internal/registry/forward.go |
| +++ b/internal/registry/forward.go |
| @@ -71,13 +71,15 @@ func (t Route) IsForward() bool { return t.Kind == KindForward } |
| var ErrForwardRow = errors.New("registry: the host is a forward row") |
| // ErrNotForward is PutForward's answer when the row it is handed is not a |
| -// forward row it may write: another kind, no host, or a Region that is not |
| -// a fleet placement. Nothing is read or written. One of remoteErrors. |
| +// forward row it may write: another kind, no host, a Region that is neither |
| +// a fleet placement nor a link placement, or a link-placed row carrying a |
| +// fleet label. Nothing is read or written. One of remoteErrors. |
| var ErrNotForward = errors.New("registry: not a forward row") |
| // ErrHostHeld is PutForward's answer when a row that is not a forward row |
| -// already holds the host: that row is another writer's, and PutForward |
| -// writes nothing. One of remoteErrors. |
| +// already holds the host, or a forward row of another placement class does |
| +// (fleet against link, or another link's): that row is another writer's, |
| +// and PutForward writes nothing. One of remoteErrors. |
| var ErrHostHeld = errors.New("registry: another row holds the host") |
| // forwardShape classes every persisted field of Route, the embedded |
| @@ -348,9 +350,16 @@ WHERE routes.kind = 'forward' AND ((routes.demo_id = '' AND routes.demo_host = ' |
| // PutForward writes rt as a forward row (spec §4.2), in one transaction. It |
| // refuses, with ErrNotForward and before any read, an rt that is not a |
| -// forward row, has no Host, or whose Region is not a fleet placement |
| -// (FleetPlacement). A row at the host that is not a |
| -// forward row is another writer's: ErrHostHeld, nothing written. Otherwise |
| +// forward row, has no Host, or whose Region is neither a fleet placement |
| +// (FleetPlacement) nor a link placement (LinkPlacement, linked deployments |
| +// §6.2), and a link-placed rt that carries a FleetLabel. A row at the host |
| +// that is not a forward row is another writer's: ErrHostHeld, nothing |
| +// written. Placement classes are disjoint (forwardClass): a forward row of |
| +// the fleet class never replaces a link's row, nor a link's row a fleet |
| +// row or another link's, so those are ErrHostHeld too. A link-placed rt is |
| +// written only while its link has an active channel owned by rt.Account, |
| +// read in the same transaction, else ErrLinkInactive: a publication racing |
| +// an unlink (RevokeLinkChannel) cannot leave a row behind. Otherwise |
| // it writes the declared columns from rt (Host, Kind, Slug, App, Account, |
| // Region, Channel, RateLimit, FleetLabel; Status "ready" and Provisioned |
| // true whatever rt says), keeps CreatedAt (now on a new row) and the |
| @@ -361,13 +370,17 @@ WHERE routes.kind = 'forward' AND ((routes.demo_id = '' AND routes.demo_host = ' |
| // is unchanged (empty on a new row). Never Upsert, which keeps non-empty |
| // stored values. |
| func (r *Registry) PutForward(rt Route) error { |
| - switch _, placed := FleetPlacement(rt.Region); { |
| + _, fleetPlaced := FleetPlacement(rt.Region) |
| + linkID, linkPlaced := LinkPlacement(rt.Region) |
| + switch { |
| case !rt.IsForward(): |
| return fmt.Errorf("%w: PutForward(%q): kind %q is not %q", ErrNotForward, rt.Host, rt.Kind, KindForward) |
| case rt.Host == "": |
| return fmt.Errorf("%w: PutForward: no host", ErrNotForward) |
| - case !placed: |
| - return fmt.Errorf("%w: PutForward(%q): region %q is not a fleet placement", ErrNotForward, rt.Host, rt.Region) |
| + case !fleetPlaced && !linkPlaced: |
| + return fmt.Errorf("%w: PutForward(%q): region %q is not a fleet or link placement", ErrNotForward, rt.Host, rt.Region) |
| + case linkPlaced && rt.FleetLabel != "": |
| + return fmt.Errorf("%w: PutForward(%q): a link-placed row carries no fleet label", ErrNotForward, rt.Host) |
| } |
| if !rt.ValidReplicaProjection() { |
| return ErrNotForward |
| @@ -399,14 +412,21 @@ func (r *Registry) PutForward(rt Route) error { |
| w.FleetBox, w.FleetLabel = "", "" |
| } |
| return r.inImmediateTx(func(tx txer) error { |
| - var kind string |
| - err := tx.QueryRow(`SELECT kind FROM routes WHERE host = ?`, w.Host).Scan(&kind) |
| + var kind, region string |
| + err := tx.QueryRow(`SELECT kind, region FROM routes WHERE host = ?`, w.Host).Scan(&kind, ®ion) |
| switch { |
| case errors.Is(err, sql.ErrNoRows): |
| case err != nil: |
| return err |
| case kind != KindForward: |
| return ErrHostHeld |
| + case forwardClass(region) != forwardClass(w.Region): |
| + return ErrHostHeld |
| + } |
| + if linkPlaced { |
| + if err := linkAdmits(tx, linkID, w.Account); err != nil { |
| + return err |
| + } |
| } |
| res, err := tx.Exec(putForwardSQL, routeArgs(w)...) |
| if err != nil { |
| @@ -423,16 +443,18 @@ func (r *Registry) PutForward(rt Route) error { |
| }) |
| } |
| -// DeleteForward deletes host's row only while it is a forward row, in the |
| -// same statement, and reports whether it deleted one. Any other row at the |
| -// host, or none, is false with no error. |
| +// DeleteForward deletes host's row only while it is a forward row that is |
| +// not link-placed, in the same statement, and reports whether it deleted |
| +// one. Any other row at the host, a link's row included (only its link's |
| +// own doors remove it: DeleteLinkForward, RevokeLinkChannel), or none, is |
| +// false with no error. |
| func (r *Registry) DeleteForward(host string) (bool, error) { |
| if r.remote != nil { |
| out, err := r.remote.call(nil, remoteRequest{Method: "DeleteForward", Host: host}, nil) |
| return out.Changed, err |
| } |
| - res, err := r.sql.Exec(`DELETE FROM routes WHERE host = ? AND kind = 'forward'`, host) |
| + res, err := r.sql.Exec(`DELETE FROM routes WHERE host = ? AND kind = 'forward' AND substr(region, 1, 5) <> 'link/'`, host) |
| if err != nil { |
| return false, err |
| } |
diff --git a/internal/registry/links.go b/internal/registry/links.go| new file mode 100644 |
| index 000000000..c5acaf10c |
| --- /dev/null |
| +++ b/internal/registry/links.go |
| @@ -0,0 +1,413 @@ |
| +package registry |
| + |
| +import ( |
| + "database/sql" |
| + "errors" |
| + "fmt" |
| + "math" |
| + "regexp" |
| + "strings" |
| + "time" |
| +) |
| + |
| +// Linked deployments (spec 2026-11-10-linked-deployments-design.md §6.1, |
| +// §6.2): a home deployment publishes apps through the hub over a tunnel |
| +// channel of its own. The serving console writes the link's channel row |
| +// (its token hash) and the publication's forward rows straight into the |
| +// hub's registry, as it does for fleets; the hub's reload picks them up. |
| + |
| +// LinkPlacementPrefix is the Region-column prefix of a forward row served |
| +// over a link's channel: "link/<link id>", where a fleet row is |
| +// "fleet/<fleet>". LinkPlacement is its one parser. |
| +const LinkPlacementPrefix = "link/" |
| + |
| +// linkIDRe: a link ID is 12 lowercase hex characters, minted from |
| +// crypto/rand by the serving console. |
| +var linkIDRe = regexp.MustCompile(`^[0-9a-f]{12}$`) |
| + |
| +// ValidLinkID reports whether id is a well-formed link ID. |
| +func ValidLinkID(id string) bool { return linkIDRe.MatchString(id) } |
| + |
| +// LinkPlacement parses a Route.Region value as a link placement: |
| +// "link/0123456789ab" -> ("0123456789ab", true). Anything else, a fleet |
| +// placement or a malformed link ID included, is ("", false). |
| +func LinkPlacement(region string) (linkID string, ok bool) { |
| + id, hasPrefix := strings.CutPrefix(region, LinkPlacementPrefix) |
| + if !hasPrefix || !ValidLinkID(id) { |
| + return "", false |
| + } |
| + return id, true |
| +} |
| + |
| +// linkChannelPrefix and linkChannelSuffix frame a link's channel name. The |
| +// ':' is outside ValidTunnelName's alphabet, so no fleet name can begin a |
| +// link channel name and no link channel name is "<fleet>/<label>". |
| +const ( |
| + linkChannelPrefix = "link:" |
| + linkChannelSuffix = "/home" |
| +) |
| + |
| +// LinkChannelName is the tunnel channel name a link dials as: |
| +// "link:<link id>/home". It does not validate linkID. |
| +func LinkChannelName(linkID string) string { |
| + return linkChannelPrefix + linkID + linkChannelSuffix |
| +} |
| + |
| +// LinkOfChannel is LinkChannelName's inverse: the link ID of a well-formed |
| +// link channel name. Every fleet channel name ("<fleet>/<label>") is false. |
| +func LinkOfChannel(name string) (linkID string, ok bool) { |
| + rest, hasPrefix := strings.CutPrefix(name, linkChannelPrefix) |
| + if !hasPrefix { |
| + return "", false |
| + } |
| + id, hasSuffix := strings.CutSuffix(rest, linkChannelSuffix) |
| + if !hasSuffix || !ValidLinkID(id) { |
| + return "", false |
| + } |
| + return id, true |
| +} |
| + |
| +// LinkChannel is one link's row in the hub registry's link_channels table. |
| +// Status is "active" or "revoked"; revoked is terminal, and a revoked link |
| +// ID is never reused. Generation orders the serving console's writes |
| +// (PutLinkChannel). TokenHash is the sha256 hex of the link credential, |
| +// never the credential itself. |
| +type LinkChannel struct { |
| + LinkID, Account, TokenHash, Status string |
| + Generation uint64 |
| + CreatedAt time.Time |
| +} |
| + |
| +// LinkSeen is a link's connection state as the hub last recorded it. |
| +type LinkSeen struct { |
| + Connected bool |
| + At time.Time |
| +} |
| + |
| +// ErrLinkInactive is PutForward's answer for a link-placed row when the |
| +// link has no active channel owned by the row's account: never written, |
| +// revoked, or another account's. Nothing is written. One of remoteErrors. |
| +var ErrLinkInactive = errors.New("registry: the link is not active for this account") |
| + |
| +// migrateLinks creates link_channels, additive like migrateFleets. The |
| +// connected, seen_at and seq columns are the hub's connection record |
| +// (SetLinkSeen); Fingerprint does not hash them. |
| +func (r *Registry) migrateLinks() error { |
| + _, err := r.sql.Exec(` |
| +CREATE TABLE IF NOT EXISTS link_channels ( |
| + link_id TEXT PRIMARY KEY, |
| + account TEXT NOT NULL, |
| + token_hash TEXT NOT NULL, |
| + status TEXT NOT NULL, |
| + created_at INTEGER NOT NULL, |
| + generation INTEGER NOT NULL DEFAULT 0, |
| + connected INTEGER NOT NULL DEFAULT 0, |
| + seen_at INTEGER NOT NULL DEFAULT 0, |
| + seq INTEGER NOT NULL DEFAULT 0 |
| +);`) |
| + return err |
| +} |
| + |
| +// pruneLinkForwardsSQL deletes the forward rows placed on one link (both |
| +// arguments the link ID) that its channel no longer admits: the channel is |
| +// missing or not active, or the row's account is not the channel's. Run in |
| +// the transaction of every link_channels write, so no write can leave a row |
| +// that PutForward would refuse. |
| +const pruneLinkForwardsSQL = ` |
| +DELETE FROM routes |
| + WHERE kind = 'forward' AND region = 'link/' || ? |
| + AND NOT EXISTS (SELECT 1 FROM link_channels lc |
| + WHERE lc.link_id = ? AND lc.status = 'active' AND lc.account = routes.account)` |
| + |
| +// PutLinkChannel writes c, the serving console's view of one link, and |
| +// reports whether it applied. One writer: only the serving console's |
| +// channel sync calls it. It applies only when c.Generation is greater than |
| +// the stored generation and the stored row is not revoked, so a stale or |
| +// replayed write returns false and changes nothing. A new row applies at any |
| +// generation. CreatedAt is kept from the stored row (now on a new row when |
| +// c.CreatedAt is zero). In the same transaction it deletes the link's |
| +// forward rows the written channel no longer admits (pruneLinkForwardsSQL). |
| +// It refuses, before any write, a malformed link ID, a token hash that is |
| +// not 64 lowercase hex characters, an empty account and a status other than |
| +// "active" or "revoked". |
| +func (r *Registry) PutLinkChannel(c LinkChannel) (applied bool, err error) { |
| + switch { |
| + case !ValidLinkID(c.LinkID): |
| + return false, fmt.Errorf("registry: invalid link id %q", c.LinkID) |
| + case c.Account == "": |
| + return false, fmt.Errorf("registry: link %s: no account", c.LinkID) |
| + case !validTokenHash(c.TokenHash): |
| + return false, fmt.Errorf("registry: link %s: token hash must be 64 lowercase hex characters", c.LinkID) |
| + case c.Status != "active" && c.Status != "revoked": |
| + return false, fmt.Errorf("registry: link %s: status %q is not active or revoked", c.LinkID, c.Status) |
| + case c.Generation > math.MaxInt64: |
| + return false, fmt.Errorf("registry: link %s: generation %d out of range", c.LinkID, c.Generation) |
| + } |
| + if r.remote != nil { |
| + out, err := r.remote.call(nil, remoteRequest{Method: "PutLinkChannel", Link: c}, nil) |
| + return out.Changed, err |
| + } |
| + |
| + created := time.Now().Unix() |
| + if !c.CreatedAt.IsZero() { |
| + created = c.CreatedAt.Unix() |
| + } |
| + err = r.inImmediateTx(func(tx txer) error { |
| + res, err := tx.Exec(` |
| +INSERT INTO link_channels (link_id, account, token_hash, status, created_at, generation) |
| +VALUES (?, ?, ?, ?, ?, ?) |
| +ON CONFLICT(link_id) DO UPDATE SET |
| + account = excluded.account, token_hash = excluded.token_hash, |
| + status = excluded.status, generation = excluded.generation |
| +WHERE link_channels.status <> 'revoked' AND excluded.generation > link_channels.generation`, |
| + c.LinkID, c.Account, c.TokenHash, c.Status, created, int64(c.Generation)) |
| + if err != nil { |
| + return err |
| + } |
| + n, err := res.RowsAffected() |
| + if err != nil { |
| + return err |
| + } |
| + if n == 0 { |
| + return nil |
| + } |
| + applied = true |
| + _, err = tx.Exec(pruneLinkForwardsSQL, c.LinkID, c.LinkID) |
| + return err |
| + }) |
| + return applied, err |
| +} |
| + |
| +// RevokeLinkChannel marks linkID's channel revoked and, in the same |
| +// transaction, deletes every forward row placed on the link. An ID with no |
| +// row is recorded revoked (account and hash empty), so a channel write that |
| +// arrives after its own revocation is refused. It reports whether the link |
| +// moved to revoked: false when it already was. |
| +func (r *Registry) RevokeLinkChannel(linkID string) (bool, error) { |
| + if !ValidLinkID(linkID) { |
| + return false, fmt.Errorf("registry: invalid link id %q", linkID) |
| + } |
| + if r.remote != nil { |
| + out, err := r.remote.call(nil, remoteRequest{Method: "RevokeLinkChannel", LinkID: linkID}, nil) |
| + return out.Changed, err |
| + } |
| + |
| + revoked := false |
| + err := r.inImmediateTx(func(tx txer) error { |
| + res, err := tx.Exec(` |
| +INSERT INTO link_channels (link_id, account, token_hash, status, created_at) |
| +VALUES (?, '', '', 'revoked', ?) |
| +ON CONFLICT(link_id) DO UPDATE SET status = 'revoked' |
| +WHERE link_channels.status <> 'revoked'`, linkID, time.Now().Unix()) |
| + if err != nil { |
| + return err |
| + } |
| + n, err := res.RowsAffected() |
| + if err != nil { |
| + return err |
| + } |
| + revoked = n > 0 |
| + _, err = tx.Exec(`DELETE FROM routes WHERE kind = 'forward' AND region = 'link/' || ?`, linkID) |
| + return err |
| + }) |
| + return revoked, err |
| +} |
| + |
| +// LinkChannelAuth returns every active link's token hash keyed by its |
| +// channel name (LinkChannelName): the hub's auth table for a link dial-in, |
| +// beside FleetChannelAuth. Fresh connection, for the same cross-process |
| +// reason as FleetChannelAuth. |
| +func (r *Registry) LinkChannelAuth() (map[string]string, error) { |
| + if r.remote != nil { |
| + out, err := r.remote.call(nil, remoteRequest{Method: "LinkChannelAuth"}, nil) |
| + return out.StringMap, err |
| + } |
| + return r.activeLinkMap(`SELECT link_id, token_hash FROM link_channels WHERE status = 'active'`, LinkChannelName) |
| +} |
| + |
| +// LinkOwners returns every active link's owning account sqid keyed by link |
| +// ID: what the hub judges a link-placed forward row by, as FleetOwners is |
| +// for fleet rows. Never nil when err is nil. |
| +func (r *Registry) LinkOwners() (map[string]string, error) { |
| + if r.remote != nil { |
| + out, err := r.remote.call(nil, remoteRequest{Method: "LinkOwners"}, nil) |
| + return out.StringMap, err |
| + } |
| + return r.activeLinkMap(`SELECT link_id, account FROM link_channels WHERE status = 'active'`, func(id string) string { return id }) |
| +} |
| + |
| +// activeLinkMap runs query (two string columns: the link ID and a value) |
| +// over a fresh connection and folds it into a map keyed by key(link ID). |
| +func (r *Registry) activeLinkMap(query string, key func(string) string) (map[string]string, error) { |
| + db, err := r.freshFleetsConn() |
| + if err != nil { |
| + return nil, err |
| + } |
| + defer db.Close() |
| + rows, err := db.Query(query) |
| + if err != nil { |
| + return nil, err |
| + } |
| + defer rows.Close() |
| + out := make(map[string]string) |
| + for rows.Next() { |
| + var id, v string |
| + if err := rows.Scan(&id, &v); err != nil { |
| + return nil, err |
| + } |
| + out[key(id)] = v |
| + } |
| + return out, rows.Err() |
| +} |
| + |
| +// SetLinkSeen records a link connection's state. seq is the connection's |
| +// registration sequence. A connect always applies and stores seq; a |
| +// disconnect applies only while the stored seq is seq, so the close of an |
| +// older connection never overwrites a re-register's newer connect. An |
| +// unknown link ID changes nothing. Not hashed by Fingerprint. |
| +func (r *Registry) SetLinkSeen(linkID string, seq uint64, connected bool, at time.Time) error { |
| + if !ValidLinkID(linkID) { |
| + return fmt.Errorf("registry: invalid link id %q", linkID) |
| + } |
| + if seq > math.MaxInt64 { |
| + return fmt.Errorf("registry: link %s: seq %d out of range", linkID, seq) |
| + } |
| + if r.remote != nil { |
| + _, err := r.remote.call(nil, remoteRequest{Method: "SetLinkSeen", LinkID: linkID, Seq: seq, On: connected, SeenAt: at}, nil) |
| + return err |
| + } |
| + |
| + var seen int64 |
| + if !at.IsZero() { |
| + seen = at.Unix() |
| + } |
| + var err error |
| + if connected { |
| + _, err = r.sql.Exec(`UPDATE link_channels SET connected = 1, seq = ?, seen_at = ? WHERE link_id = ?`, int64(seq), seen, linkID) |
| + } else { |
| + _, err = r.sql.Exec(`UPDATE link_channels SET connected = 0, seen_at = ? WHERE link_id = ? AND seq = ?`, seen, linkID, int64(seq)) |
| + } |
| + return err |
| +} |
| + |
| +// ResetLinkSeen marks every link disconnected. The hub calls it at start: |
| +// no connection outlives the process that held it. |
| +func (r *Registry) ResetLinkSeen() error { |
| + if r.remote != nil { |
| + _, err := r.remote.call(nil, remoteRequest{Method: "ResetLinkSeen"}, nil) |
| + return err |
| + } |
| + _, err := r.sql.Exec(`UPDATE link_channels SET connected = 0 WHERE connected <> 0`) |
| + return err |
| +} |
| + |
| +// LinkSeen returns every link's connection state keyed by link ID, revoked |
| +// links included. Fresh connection. |
| +func (r *Registry) LinkSeen() (map[string]LinkSeen, error) { |
| + if r.remote != nil { |
| + out, err := r.remote.call(nil, remoteRequest{Method: "LinkSeen"}, nil) |
| + return out.LinkSeen, err |
| + } |
| + |
| + db, err := r.freshFleetsConn() |
| + if err != nil { |
| + return nil, err |
| + } |
| + defer db.Close() |
| + rows, err := db.Query(`SELECT link_id, connected, seen_at FROM link_channels`) |
| + if err != nil { |
| + return nil, err |
| + } |
| + defer rows.Close() |
| + out := make(map[string]LinkSeen) |
| + for rows.Next() { |
| + var id string |
| + var connected, at int64 |
| + if err := rows.Scan(&id, &connected, &at); err != nil { |
| + return nil, err |
| + } |
| + s := LinkSeen{Connected: connected != 0} |
| + if at != 0 { |
| + s.At = time.Unix(at, 0) |
| + } |
| + out[id] = s |
| + } |
| + return out, rows.Err() |
| +} |
| + |
| +// LinkForwards returns every forward row placed on linkID, ordered by host. |
| +// Unlink deletes from this list, not from the console's app rows. Fresh |
| +// connection. |
| +func (r *Registry) LinkForwards(linkID string) ([]Route, error) { |
| + if !ValidLinkID(linkID) { |
| + return nil, fmt.Errorf("registry: invalid link id %q", linkID) |
| + } |
| + if r.remote != nil { |
| + out, err := r.remote.call(nil, remoteRequest{Method: "LinkForwards", LinkID: linkID}, nil) |
| + return out.Routes, err |
| + } |
| + |
| + db, err := r.freshFleetsConn() |
| + if err != nil { |
| + return nil, err |
| + } |
| + defer db.Close() |
| + rows, err := db.Query(`SELECT `+routeCols+` FROM routes WHERE kind = 'forward' AND region = ? ORDER BY host`, LinkPlacementPrefix+linkID) |
| + if err != nil { |
| + return nil, err |
| + } |
| + defer rows.Close() |
| + var out []Route |
| + for rows.Next() { |
| + t, err := scanRoute(rows.Scan) |
| + if err != nil { |
| + return nil, err |
| + } |
| + out = append(out, t) |
| + } |
| + return out, rows.Err() |
| +} |
| + |
| +// DeleteLinkForward deletes host's row only while it is a forward row placed |
| +// exactly on linkID, in one statement, and reports whether it deleted one. |
| +// It is the only door that deletes a link-placed row besides |
| +// RevokeLinkChannel and the prune of a channel write; DeleteForward refuses |
| +// them. |
| +func (r *Registry) DeleteLinkForward(host, linkID string) (bool, error) { |
| + if !ValidLinkID(linkID) { |
| + return false, fmt.Errorf("registry: invalid link id %q", linkID) |
| + } |
| + if r.remote != nil { |
| + out, err := r.remote.call(nil, remoteRequest{Method: "DeleteLinkForward", Host: host, LinkID: linkID}, nil) |
| + return out.Changed, err |
| + } |
| + |
| + res, err := r.sql.Exec(`DELETE FROM routes WHERE host = ? AND kind = 'forward' AND region = ?`, host, LinkPlacementPrefix+linkID) |
| + if err != nil { |
| + return false, err |
| + } |
| + n, err := res.RowsAffected() |
| + return n > 0, err |
| +} |
| + |
| +// forwardClass is the placement class PutForward keeps disjoint: a row |
| +// placed on a link is its own class per link ("link/<id>"), and every other |
| +// forward row is the fleet class. The prefix decides, not LinkPlacement, so |
| +// a stored "link/..." value that does not parse is still never fleet. |
| +func forwardClass(region string) string { |
| + if strings.HasPrefix(region, LinkPlacementPrefix) { |
| + return region |
| + } |
| + return "fleet" |
| +} |
| + |
| +// linkAdmits is nil when, inside tx, linkID has an active channel owned by |
| +// account, and ErrLinkInactive when it has none. |
| +func linkAdmits(tx txer, linkID, account string) error { |
| + var one int |
| + err := tx.QueryRow(`SELECT 1 FROM link_channels WHERE link_id = ? AND status = 'active' AND account = ?`, linkID, account).Scan(&one) |
| + if errors.Is(err, sql.ErrNoRows) { |
| + return fmt.Errorf("%w: link %s, account %q", ErrLinkInactive, linkID, account) |
| + } |
| + return err |
| +} |
diff --git a/internal/registry/links_test.go b/internal/registry/links_test.go| new file mode 100644 |
| index 000000000..d26d92e4c |
| --- /dev/null |
| +++ b/internal/registry/links_test.go |
| @@ -0,0 +1,470 @@ |
| +package registry |
| + |
| +import ( |
| + "errors" |
| + "math/rand/v2" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +const ( |
| + testLinkA = "0123456789ab" |
| + testLinkB = "ba9876543210" |
| +) |
| + |
| +// testHash is a well-formed token hash: 64 lowercase hex characters. |
| +func testHash(c byte) string { return strings.Repeat(string(c), 64) } |
| + |
| +func activeLink(id, account string, gen uint64) LinkChannel { |
| + return LinkChannel{LinkID: id, Account: account, TokenHash: testHash('a'), Status: "active", Generation: gen} |
| +} |
| + |
| +func putLink(t *testing.T, reg *Registry, c LinkChannel) { |
| + t.Helper() |
| + applied, err := reg.PutLinkChannel(c) |
| + if err != nil || !applied { |
| + t.Fatalf("PutLinkChannel(%+v) = %v, %v; want applied", c, applied, err) |
| + } |
| +} |
| + |
| +func linkForward(host, account, linkID string) Route { |
| + return Route{Kind: KindForward, Host: host, App: "shop", Account: account, Region: LinkPlacementPrefix + linkID} |
| +} |
| + |
| +// randomTunnelName is a random string ValidTunnelName accepts. |
| +func randomTunnelName(rng *rand.Rand) string { |
| + const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789-" |
| + b := make([]byte, 1+rng.IntN(32)) |
| + for i := range b { |
| + b[i] = alphabet[rng.IntN(len(alphabet))] |
| + } |
| + return string(b) |
| +} |
| + |
| +func TestLinkChannelNameNeverAFleet(t *testing.T) { |
| + rng := rand.New(rand.NewPCG(1, 2)) |
| + for range 2000 { |
| + f, l := randomTunnelName(rng), randomTunnelName(rng) |
| + if !ValidTunnelName(f) || !ValidTunnelName(l) { |
| + t.Fatalf("generator produced an invalid tunnel name %q / %q", f, l) |
| + } |
| + if id, ok := LinkOfChannel(f + "/" + l); ok { |
| + t.Fatalf("LinkOfChannel(%q) = %q, true; a fleet channel is never a link", f+"/"+l, id) |
| + } |
| + } |
| + for _, id := range []string{testLinkA, testLinkB, "000000000000", "ffffffffffff"} { |
| + if !ValidLinkID(id) { |
| + t.Fatalf("ValidLinkID(%q) = false", id) |
| + } |
| + name := LinkChannelName(id) |
| + if name != "link:"+id+"/home" { |
| + t.Fatalf("LinkChannelName(%q) = %q", id, name) |
| + } |
| + if got, ok := LinkOfChannel(name); !ok || got != id { |
| + t.Fatalf("LinkOfChannel(%q) = %q, %v; want %q, true", name, got, ok, id) |
| + } |
| + if got, ok := LinkPlacement(LinkPlacementPrefix + id); !ok || got != id { |
| + t.Fatalf("LinkPlacement(link/%s) = %q, %v", id, got, ok) |
| + } |
| + } |
| + for _, bad := range []string{"", "0123456789a", "0123456789abc", "0123456789AB", "0123456789ag", "NOTHEX"} { |
| + if ValidLinkID(bad) { |
| + t.Errorf("ValidLinkID(%q) = true", bad) |
| + } |
| + if _, ok := LinkOfChannel("link:" + bad + "/home"); ok { |
| + t.Errorf("LinkOfChannel(link:%s/home) = true", bad) |
| + } |
| + } |
| + for _, name := range []string{"link:" + testLinkA, "link:" + testLinkA + "/other", testLinkA + "/home", "link:" + testLinkA + "/home/x"} { |
| + if _, ok := LinkOfChannel(name); ok { |
| + t.Errorf("LinkOfChannel(%q) = true", name) |
| + } |
| + } |
| + for _, region := range []string{"fleet/x", "link/NOTHEX", "link/", "link/bad", "", "eu", "link/" + testLinkA + "/x"} { |
| + if _, ok := LinkPlacement(region); ok { |
| + t.Errorf("LinkPlacement(%q) = true", region) |
| + } |
| + } |
| + if _, ok := FleetPlacement(LinkPlacementPrefix + testLinkA); ok { |
| + t.Error("FleetPlacement accepts a link placement") |
| + } |
| +} |
| + |
| +func TestLinkChannelAuthOnlyActive(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + a := activeLink(testLinkA, "acct1", 1) |
| + b := activeLink(testLinkB, "acct2", 1) |
| + b.TokenHash = testHash('b') |
| + putLink(t, reg, a) |
| + putLink(t, reg, b) |
| + if revoked, err := reg.RevokeLinkChannel(testLinkB); err != nil || !revoked { |
| + t.Fatalf("RevokeLinkChannel = %v, %v", revoked, err) |
| + } |
| + auth, err := reg.LinkChannelAuth() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(auth) != 1 || auth["link:"+testLinkA+"/home"] != a.TokenHash { |
| + t.Fatalf("LinkChannelAuth = %v; want only link:%s/home", auth, testLinkA) |
| + } |
| + owners, err := reg.LinkOwners() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(owners) != 1 || owners[testLinkA] != "acct1" { |
| + t.Fatalf("LinkOwners = %v; want only %s -> acct1", owners, testLinkA) |
| + } |
| +} |
| + |
| +func TestPutForwardAcceptsLinkPlacement(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + putLink(t, reg, activeLink(testLinkA, "acct1", 1)) |
| + rt := Route{Kind: KindForward, Host: "shop.acct1.apps.example.com", App: "shop", Account: "acct1", Region: "link/0123456789ab"} |
| + if err := reg.PutForward(rt); err != nil { |
| + t.Fatalf("PutForward(link row) = %v", err) |
| + } |
| + got, err := reg.Get(rt.Host) |
| + if err != nil || got == nil || !got.IsForward() || got.Region != rt.Region || got.Account != "acct1" || !got.InertForward() { |
| + t.Fatalf("stored row = %+v, %v", got, err) |
| + } |
| + bad := rt |
| + bad.Host = "blog.acct1.apps.example.com" |
| + bad.Region = "link/bad" |
| + if err := reg.PutForward(bad); !errors.Is(err, ErrNotForward) { |
| + t.Fatalf("PutForward(link/bad) = %v; want ErrNotForward", err) |
| + } |
| + labelled := rt |
| + labelled.Host = "blog.acct1.apps.example.com" |
| + labelled.FleetLabel = "box-1" |
| + if err := reg.PutForward(labelled); !errors.Is(err, ErrNotForward) { |
| + t.Fatalf("PutForward(link row with a fleet label) = %v; want ErrNotForward", err) |
| + } |
| + if got, err := reg.Get("blog.acct1.apps.example.com"); err != nil || got != nil { |
| + t.Fatalf("a refused put wrote %+v, %v", got, err) |
| + } |
| +} |
| + |
| +func TestLinkSeenDoesNotMoveFingerprint(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + empty, err := reg.Fingerprint() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + putLink(t, reg, activeLink(testLinkA, "acct1", 1)) |
| + before, err := reg.Fingerprint() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if before == empty { |
| + t.Fatal("PutLinkChannel did not move the fingerprint") |
| + } |
| + if err := reg.SetLinkSeen(testLinkA, 1, true, time.Unix(1000, 0)); err != nil { |
| + t.Fatal(err) |
| + } |
| + after, err := reg.Fingerprint() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if after != before { |
| + t.Fatal("SetLinkSeen moved the fingerprint") |
| + } |
| + if err := reg.ResetLinkSeen(); err != nil { |
| + t.Fatal(err) |
| + } |
| + if again, err := reg.Fingerprint(); err != nil || again != before { |
| + t.Fatalf("ResetLinkSeen moved the fingerprint (%v)", err) |
| + } |
| + rotated := activeLink(testLinkA, "acct1", 2) |
| + rotated.TokenHash = testHash('c') |
| + putLink(t, reg, rotated) |
| + if rot, err := reg.Fingerprint(); err != nil || rot == before { |
| + t.Fatalf("a rotated token hash did not move the fingerprint (%v)", err) |
| + } |
| + mid, _ := reg.Fingerprint() |
| + if _, err := reg.RevokeLinkChannel(testLinkA); err != nil { |
| + t.Fatal(err) |
| + } |
| + if rev, err := reg.Fingerprint(); err != nil || rev == mid { |
| + t.Fatalf("a revocation did not move the fingerprint (%v)", err) |
| + } |
| +} |
| + |
| +func TestForwardClassesDisjoint(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + putLink(t, reg, activeLink(testLinkA, "acct1", 1)) |
| + putLink(t, reg, activeLink(testLinkB, "acct1", 1)) |
| + const h = "shop.acct1.apps.example.com" |
| + |
| + // A link row on H: a fleet row cannot take it, nor another link's row. |
| + link := linkForward(h, "acct1", testLinkA) |
| + if err := reg.PutForward(link); err != nil { |
| + t.Fatal(err) |
| + } |
| + fleet := validForward(h, "home") |
| + fleet.Account = "acct1" |
| + if err := reg.PutForward(fleet); !errors.Is(err, ErrHostHeld) { |
| + t.Fatalf("fleet row over a link row = %v; want ErrHostHeld", err) |
| + } |
| + if err := reg.PutForward(linkForward(h, "acct1", testLinkB)); !errors.Is(err, ErrHostHeld) { |
| + t.Fatalf("link B's row over link A's = %v; want ErrHostHeld", err) |
| + } |
| + if got, err := reg.Get(h); err != nil || got == nil || got.Region != link.Region { |
| + t.Fatalf("H changed: %+v, %v", got, err) |
| + } |
| + if deleted, err := reg.DeleteForward(h); err != nil || deleted { |
| + t.Fatalf("DeleteForward(link row) = %v, %v; want false", deleted, err) |
| + } |
| + if deleted, err := reg.DeleteLinkForward(h, testLinkB); err != nil || deleted { |
| + t.Fatalf("DeleteLinkForward(H, other link) = %v, %v; want false", deleted, err) |
| + } |
| + if got, err := reg.Get(h); err != nil || got == nil || got.Region != link.Region { |
| + t.Fatalf("H changed: %+v, %v", got, err) |
| + } |
| + // The same link may rewrite its own row. |
| + if err := reg.PutForward(link); err != nil { |
| + t.Fatalf("link A rewriting its own row = %v", err) |
| + } |
| + if deleted, err := reg.DeleteLinkForward(h, testLinkA); err != nil || !deleted { |
| + t.Fatalf("DeleteLinkForward(H, own link) = %v, %v; want true", deleted, err) |
| + } |
| + |
| + // The reverse: a fleet row on H cannot be taken by a link row. |
| + if err := reg.PutForward(fleet); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.PutForward(link); !errors.Is(err, ErrHostHeld) { |
| + t.Fatalf("link row over a fleet row = %v; want ErrHostHeld", err) |
| + } |
| + if got, err := reg.Get(h); err != nil || got == nil || got.Region != fleet.Region { |
| + t.Fatalf("H changed: %+v, %v", got, err) |
| + } |
| + if deleted, err := reg.DeleteLinkForward(h, testLinkA); err != nil || deleted { |
| + t.Fatalf("DeleteLinkForward(fleet row) = %v, %v; want false", deleted, err) |
| + } |
| + if deleted, err := reg.DeleteForward(h); err != nil || !deleted { |
| + t.Fatalf("DeleteForward(fleet row) = %v, %v; want true", deleted, err) |
| + } |
| +} |
| + |
| +func TestLinkSeenOrdering(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + putLink(t, reg, activeLink(testLinkA, "acct1", 1)) |
| + b := activeLink(testLinkB, "acct1", 1) |
| + putLink(t, reg, b) |
| + at := func(s int64) time.Time { return time.Unix(s, 0) } |
| + seen := func(id string) LinkSeen { |
| + t.Helper() |
| + all, err := reg.LinkSeen() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return all[id] |
| + } |
| + |
| + for _, step := range []struct { |
| + seq uint64 |
| + connected bool |
| + at int64 |
| + want bool |
| + }{ |
| + {1, true, 10, true}, |
| + {2, true, 20, true}, |
| + {1, false, 30, true}, // the older connection's close |
| + {2, false, 40, false}, |
| + } { |
| + if err := reg.SetLinkSeen(testLinkA, step.seq, step.connected, at(step.at)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := seen(testLinkA); got.Connected != step.want { |
| + t.Fatalf("after seq %d connected=%v: %+v; want connected %v", step.seq, step.connected, got, step.want) |
| + } |
| + } |
| + if got := seen(testLinkA); !got.At.Equal(at(40)) { |
| + t.Fatalf("At = %v; want %v", got.At, at(40)) |
| + } |
| + |
| + if err := reg.SetLinkSeen(testLinkA, 3, true, at(50)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.SetLinkSeen(testLinkB, 1, true, at(50)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.ResetLinkSeen(); err != nil { |
| + t.Fatal(err) |
| + } |
| + all, err := reg.LinkSeen() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for id, s := range all { |
| + if s.Connected { |
| + t.Fatalf("after ResetLinkSeen %s is still connected", id) |
| + } |
| + } |
| + if len(all) != 2 { |
| + t.Fatalf("LinkSeen = %v; want both links", all) |
| + } |
| +} |
| + |
| +func TestPutLinkChannelOneWriter(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + stored := func() LinkChannel { |
| + t.Helper() |
| + var c LinkChannel |
| + if err := reg.sql.QueryRow(`SELECT link_id, account, token_hash, status, generation FROM link_channels WHERE link_id = ?`, testLinkA). |
| + Scan(&c.LinkID, &c.Account, &c.TokenHash, &c.Status, &c.Generation); err != nil { |
| + t.Fatal(err) |
| + } |
| + return c |
| + } |
| + |
| + putLink(t, reg, activeLink(testLinkA, "acct1", 2)) |
| + stale := activeLink(testLinkA, "acct1", 1) |
| + stale.TokenHash = testHash('d') |
| + if applied, err := reg.PutLinkChannel(stale); err != nil || applied { |
| + t.Fatalf("generation 1 after 2 = %v, %v; want not applied", applied, err) |
| + } |
| + replay := activeLink(testLinkA, "acct1", 2) |
| + replay.TokenHash = testHash('d') |
| + if applied, err := reg.PutLinkChannel(replay); err != nil || applied { |
| + t.Fatalf("generation 2 replayed = %v, %v; want not applied", applied, err) |
| + } |
| + if got := stored(); got.TokenHash != testHash('a') || got.Generation != 2 { |
| + t.Fatalf("stored = %+v; want the generation-2 hash", got) |
| + } |
| + |
| + if revoked, err := reg.RevokeLinkChannel(testLinkA); err != nil || !revoked { |
| + t.Fatalf("RevokeLinkChannel = %v, %v", revoked, err) |
| + } |
| + later := activeLink(testLinkA, "acct1", 3) |
| + if applied, err := reg.PutLinkChannel(later); err != nil || applied { |
| + t.Fatalf("generation 3 after revoke = %v, %v; want not applied", applied, err) |
| + } |
| + if got := stored(); got.Status != "revoked" { |
| + t.Fatalf("stored = %+v; want revoked", got) |
| + } |
| + if revoked, err := reg.RevokeLinkChannel(testLinkA); err != nil || revoked { |
| + t.Fatalf("second RevokeLinkChannel = %v, %v; want false", revoked, err) |
| + } |
| + |
| + // A revocation that arrives before the channel was ever written still |
| + // reserves the ID: the late put is refused. |
| + if _, err := reg.RevokeLinkChannel(testLinkB); err != nil { |
| + t.Fatal(err) |
| + } |
| + if applied, err := reg.PutLinkChannel(activeLink(testLinkB, "acct1", 1)); err != nil || applied { |
| + t.Fatalf("put after an early revoke = %v, %v; want not applied", applied, err) |
| + } |
| + |
| + for _, bad := range []LinkChannel{ |
| + {LinkID: "NOTHEX", Account: "acct1", TokenHash: testHash('a'), Status: "active", Generation: 9}, |
| + {LinkID: "aaaaaaaaaaaa", Account: "", TokenHash: testHash('a'), Status: "active", Generation: 9}, |
| + {LinkID: "aaaaaaaaaaaa", Account: "acct1", TokenHash: "plaintext-token", Status: "active", Generation: 9}, |
| + {LinkID: "aaaaaaaaaaaa", Account: "acct1", TokenHash: testHash('a'), Status: "paused", Generation: 9}, |
| + } { |
| + if applied, err := reg.PutLinkChannel(bad); err == nil || applied { |
| + t.Errorf("PutLinkChannel(%+v) = %v, %v; want an error", bad, applied, err) |
| + } |
| + } |
| +} |
| + |
| +func TestLinkForwardNeedsActiveChannel(t *testing.T) { |
| + reg := openTestRegistry(t) |
| + const h = "shop.acct1.apps.example.com" |
| + |
| + if err := reg.PutForward(linkForward(h, "acct1", testLinkA)); !errors.Is(err, ErrLinkInactive) { |
| + t.Fatalf("link row with no channel = %v; want ErrLinkInactive", err) |
| + } |
| + putLink(t, reg, activeLink(testLinkA, "acct1", 1)) |
| + if err := reg.PutForward(linkForward(h, "acct2", testLinkA)); !errors.Is(err, ErrLinkInactive) { |
| + t.Fatalf("link row of another account = %v; want ErrLinkInactive", err) |
| + } |
| + if err := reg.PutForward(linkForward(h, "acct1", testLinkA)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.PutForward(linkForward("blog.acct1.apps.example.com", "acct1", testLinkA)); err != nil { |
| + t.Fatal(err) |
| + } |
| + fwds, err := reg.LinkForwards(testLinkA) |
| + if err != nil || len(fwds) != 2 { |
| + t.Fatalf("LinkForwards = %+v, %v; want two rows", fwds, err) |
| + } |
| + |
| + // Revocation removes the link's rows in the same transaction, and a |
| + // fleet row elsewhere is untouched. |
| + if err := reg.PutForward(validForward("other.example.com", "home")); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := reg.RevokeLinkChannel(testLinkA); err != nil { |
| + t.Fatal(err) |
| + } |
| + if fwds, err := reg.LinkForwards(testLinkA); err != nil || len(fwds) != 0 { |
| + t.Fatalf("LinkForwards after revoke = %+v, %v; want none", fwds, err) |
| + } |
| + if got, err := reg.Get("other.example.com"); err != nil || got == nil { |
| + t.Fatalf("revocation touched a fleet row: %+v, %v", got, err) |
| + } |
| + if err := reg.PutForward(linkForward(h, "acct1", testLinkA)); !errors.Is(err, ErrLinkInactive) { |
| + t.Fatalf("link row on a revoked channel = %v; want ErrLinkInactive", err) |
| + } |
| + if got, err := reg.Get(h); err != nil || got != nil { |
| + t.Fatalf("a refused put wrote %+v, %v", got, err) |
| + } |
| + |
| + // A channel write that revokes prunes the link's rows the same way. |
| + putLink(t, reg, activeLink(testLinkB, "acct1", 1)) |
| + if err := reg.PutForward(linkForward(h, "acct1", testLinkB)); err != nil { |
| + t.Fatal(err) |
| + } |
| + revoked := activeLink(testLinkB, "acct1", 2) |
| + revoked.Status = "revoked" |
| + putLink(t, reg, revoked) |
| + if fwds, err := reg.LinkForwards(testLinkB); err != nil || len(fwds) != 0 { |
| + t.Fatalf("LinkForwards after a revoking write = %+v, %v; want none", fwds, err) |
| + } |
| +} |
| + |
| +// TestLinkCallsOverRemote: every link door crosses the remote transport, |
| +// and ErrLinkInactive survives it. |
| +func TestLinkCallsOverRemote(t *testing.T) { |
| + reg, _ := remoteTestRegistry(t) |
| + const h = "shop.acct1.apps.example.com" |
| + if err := reg.PutForward(linkForward(h, "acct1", testLinkA)); !errors.Is(err, ErrLinkInactive) { |
| + t.Fatalf("remote PutForward with no channel = %v; want ErrLinkInactive", err) |
| + } |
| + putLink(t, reg, activeLink(testLinkA, "acct1", 1)) |
| + if applied, err := reg.PutLinkChannel(activeLink(testLinkA, "acct1", 1)); err != nil || applied { |
| + t.Fatalf("remote replay = %v, %v", applied, err) |
| + } |
| + if err := reg.PutForward(linkForward(h, "acct1", testLinkA)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if auth, err := reg.LinkChannelAuth(); err != nil || auth[LinkChannelName(testLinkA)] != testHash('a') { |
| + t.Fatalf("remote LinkChannelAuth = %v, %v", auth, err) |
| + } |
| + if owners, err := reg.LinkOwners(); err != nil || owners[testLinkA] != "acct1" { |
| + t.Fatalf("remote LinkOwners = %v, %v", owners, err) |
| + } |
| + if err := reg.SetLinkSeen(testLinkA, 1, true, time.Unix(77, 0)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if seen, err := reg.LinkSeen(); err != nil || !seen[testLinkA].Connected || !seen[testLinkA].At.Equal(time.Unix(77, 0)) { |
| + t.Fatalf("remote LinkSeen = %v, %v", seen, err) |
| + } |
| + if err := reg.ResetLinkSeen(); err != nil { |
| + t.Fatal(err) |
| + } |
| + if seen, err := reg.LinkSeen(); err != nil || seen[testLinkA].Connected { |
| + t.Fatalf("remote LinkSeen after reset = %v, %v", seen, err) |
| + } |
| + if fwds, err := reg.LinkForwards(testLinkA); err != nil || len(fwds) != 1 || fwds[0].Host != h { |
| + t.Fatalf("remote LinkForwards = %+v, %v", fwds, err) |
| + } |
| + if deleted, err := reg.DeleteLinkForward(h, testLinkA); err != nil || !deleted { |
| + t.Fatalf("remote DeleteLinkForward = %v, %v", deleted, err) |
| + } |
| + if revoked, err := reg.RevokeLinkChannel(testLinkA); err != nil || !revoked { |
| + t.Fatalf("remote RevokeLinkChannel = %v, %v", revoked, err) |
| + } |
| +} |
diff --git a/internal/registry/registry.go b/internal/registry/registry.go| index f654c57b7..05b661267 100644 |
| --- a/internal/registry/registry.go |
| +++ b/internal/registry/registry.go |
| @@ -922,7 +922,10 @@ CREATE INDEX IF NOT EXISTS timers_due ON timers (next_at) WHERE next_at > 0;`); |
| if err := r.migrateFleets(); err != nil { |
| return err |
| } |
| - return r.migrateHADuties() |
| + if err := r.migrateHADuties(); err != nil { |
| + return err |
| + } |
| + return r.migrateLinks() |
| } |
| // migrateAccounts brings the accounts table to its multi-account shape: |
| @@ -3879,7 +3882,8 @@ func (r *Registry) DeletePath(host, prefix string) error { |
| } |
| // Fingerprint summarizes the routes, fleets, fleet_boxes, route_aliases, |
| -// wildcard_domains, route_paths and regional_domains tables over a fresh |
| +// wildcard_domains, route_paths, regional_domains and link_channels tables |
| +// (link_channels without its connection columns) over a fresh |
| // connection, for the |
| // edge's cheap |
| // change poll. It is content-accurate: it hashes the actual VALUES of the |
| @@ -4270,6 +4274,37 @@ FROM route_paths ORDER BY host, prefix`) |
| return "", err |
| } |
| + // link_channels (linked deployments §6.2): a link's token hash and |
| + // status decide whether the hub admits its channel, and its owner |
| + // decides whether the hub serves its forward rows, so a channel write or |
| + // a revocation must reload the edge. generation hashes too. connected, |
| + // seen_at and seq do NOT: the hub writes them on every connect and |
| + // disconnect, and hashing them would reload every edge each time a link |
| + // dials. created_at is not read at reload. Same marker rule as |
| + // regional_domains: written only when a row exists, so a registry with no |
| + // links digests as it did before the table existed. |
| + lrows, err := db.Query(`SELECT link_id, account, token_hash, status, generation FROM link_channels ORDER BY link_id`) |
| + if err != nil { |
| + return "", err |
| + } |
| + defer lrows.Close() |
| + marked = false |
| + for lrows.Next() { |
| + var linkID, account, tokenHash, status string |
| + var generation int64 |
| + if err := lrows.Scan(&linkID, &account, &tokenHash, &status, &generation); err != nil { |
| + return "", err |
| + } |
| + if !marked { |
| + fmt.Fprint(h, "\x1dlink_channels\x1e") |
| + marked = true |
| + } |
| + fmt.Fprintf(h, "%q\x1f%q\x1f%q\x1f%q\x1f%d\x1e", linkID, account, tokenHash, status, generation) |
| + } |
| + if err := lrows.Err(); err != nil { |
| + return "", err |
| + } |
| + |
| var moved []byte |
| if err := db.QueryRow(`SELECT wire FROM demo_moved_snapshot WHERE id=1`).Scan(&moved); err != nil && !errors.Is(err, sql.ErrNoRows) { |
| return "", err |
diff --git a/internal/registry/remote.go b/internal/registry/remote.go| index 6d32baac6..9bb28bc33 100644 |
| --- a/internal/registry/remote.go |
| +++ b/internal/registry/remote.go |
| @@ -13,7 +13,7 @@ import ( |
| var errRemoteMethod = errors.New("registry: unsupported remote operation") |
| -var remoteErrors = []error{os.ErrNotExist, os.ErrPermission, sql.ErrNoRows, ErrClaimOwnership, ErrTimerChanged, ErrTimerKind, ErrPathsChanged, ErrFleetBoxActive, context.Canceled, context.DeadlineExceeded, ErrGoodBuildChanged, ErrRuntimeFixed, ErrRootfsRow, ErrRuntimePlacement, ErrFleetKeyInUse, ErrForwardRow, ErrHostHeld, ErrNotForward, ErrHAChanged, ErrHAWake, ErrHAJournal, ErrReplicaAssignment} |
| +var remoteErrors = []error{os.ErrNotExist, os.ErrPermission, sql.ErrNoRows, ErrClaimOwnership, ErrTimerChanged, ErrTimerKind, ErrPathsChanged, ErrFleetBoxActive, context.Canceled, context.DeadlineExceeded, ErrGoodBuildChanged, ErrRuntimeFixed, ErrRootfsRow, ErrRuntimePlacement, ErrFleetKeyInUse, ErrForwardRow, ErrHostHeld, ErrNotForward, ErrHAChanged, ErrHAWake, ErrHAJournal, ErrReplicaAssignment, ErrLinkInactive} |
| func responseError(out remoteResponse) error { |
| if !out.Failed { |
diff --git a/internal/registry/remote_dispatch.go b/internal/registry/remote_dispatch.go| index 5353cb5cf..b05640391 100644 |
| --- a/internal/registry/remote_dispatch.go |
| +++ b/internal/registry/remote_dispatch.go |
| @@ -3,6 +3,8 @@ package registry |
| import ( |
| "context" |
| "encoding/json" |
| + "time" |
| + |
| "github.com/carlosframework/platform/internal/replicas" |
| ) |
| @@ -120,6 +122,12 @@ type remoteRequest struct { |
| // SetFleetAssignment's two columns (managed fleets 1b). |
| Assigned string |
| Moved bool |
| + |
| + // The link doors (linked deployments §6.2). |
| + Link LinkChannel |
| + LinkID string |
| + Seq uint64 |
| + SeenAt time.Time |
| } |
| type remoteResponse struct { |
| @@ -152,6 +160,7 @@ type remoteResponse struct { |
| Number int |
| Times map[string]int64 |
| Hosts []string |
| + LinkSeen map[string]LinkSeen |
| } |
| func (r *Registry) dispatchRemote(ctx context.Context, q remoteRequest, callback func(remoteResponse) error) (out remoteResponse, err error) { |
| @@ -253,6 +262,24 @@ func (r *Registry) dispatchRemote(ctx context.Context, q remoteRequest, callback |
| out.FleetBoxes, err = r.ListFleetBoxesContext(ctx, q.Fleet) |
| case "FleetChannelAuth": |
| out.StringMap, err = r.FleetChannelAuth() |
| + case "PutLinkChannel": |
| + out.Changed, err = r.PutLinkChannel(q.Link) |
| + case "RevokeLinkChannel": |
| + out.Changed, err = r.RevokeLinkChannel(q.LinkID) |
| + case "LinkChannelAuth": |
| + out.StringMap, err = r.LinkChannelAuth() |
| + case "LinkOwners": |
| + out.StringMap, err = r.LinkOwners() |
| + case "SetLinkSeen": |
| + err = r.SetLinkSeen(q.LinkID, q.Seq, q.On, q.SeenAt) |
| + case "ResetLinkSeen": |
| + err = r.ResetLinkSeen() |
| + case "LinkSeen": |
| + out.LinkSeen, err = r.LinkSeen() |
| + case "LinkForwards": |
| + out.Routes, err = r.LinkForwards(q.LinkID) |
| + case "DeleteLinkForward": |
| + out.Changed, err = r.DeleteLinkForward(q.Host, q.LinkID) |
| case "PutAccount": |
| err = r.PutAccount(q.IdValue, q.Sqid, q.Name) |
| case "DeleteAccount": |