Repository navigation
feat(relay): self-election trigger — isolated node auto-becomes a relay (#1247 slice 4b) - #1252
Merged
Merged
Conversation
…ay (#1247 slice 4b) Completes self-election: slice 4a gave a node the MECHANISM to be a relay; this is the daemon TRIGGER that decides when. With both, the fleet reconnects itself with zero ops — a reachable node self-elects, the rest find it through the gist directory (slices 1-3 carry the traffic). - `RouteDiscoverySnapshot::should_self_elect_as_relay(enrolled_peers)` — the pure decision (unit-tested independent of the daemon loop): a node should become a relay when it knows peers exist but can reach NONE of them right now — no live relay route AND no directly-connected LAN peer. Deliberately simple because slice 4a made reachability EMPIRICAL: a wrong "yes" is harmless (an unreachable self-elected relay accumulates no connections, its gist entry goes stale), so we never try to predict our own reachability. - The daemon's 60s route-refresh loop (`refresh_routes_once`) evaluates it each tick and calls `become_relay(0.0.0.0:0)` when true — all interfaces (LAN + Tailscale reachable, not loopback), OS-assigned port (the gist advertises whatever port the OS gave, so the durable pointer survives restarts). Idempotent → re-evaluating "yes" just re-advertises. Election is logged loudly ("self-elected as a relay on <addr>"); a bind failure logs + retries next tick (self-heal). The next account-registry publish carries the advertised endpoint into the gist automatically (publish_account_registry already includes route_endpoints). Tests: 4 decision cases — isolated-with-peers elects; a connected LAN peer or a live relay suppresses it; grid-of-one (no enrolled peers) never elects. clippy -D warnings + fmt clean; existing relay tests still green. Slice 4 (self-election) complete. Next: slice 8 (relay↔relay federation), slice 9 (relay durable mailbox), slice 10 (gist room directory). Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes self-election (#1247 slice 4). Slice 4a (#1251) gave a node the mechanism to be a relay; this is the daemon trigger that decides when. With both, the fleet reconnects itself with zero ops — a reachable node self-elects, the rest discover it through the gist directory, and slices 1–3 carry the traffic.
Change
RouteDiscoverySnapshot::should_self_elect_as_relay(enrolled_peers)— the pure decision (unit-tested independent of the loop): become a relay when the node knows peers exist but can reach none of them — no live relay route AND no directly-connected LAN peer. Deliberately simple because slice 4a made reachability empirical: a wrong "yes" is harmless (an unreachable self-elected relay gets no connections, its gist entry goes stale), so we never predict our own reachability.become_relay(0.0.0.0:0)when true — all interfaces (LAN + Tailscale reachable, not loopback), OS-assigned port (the gist advertises the actual port, so the durable pointer survives restarts). Idempotent → re-evaluating "yes" just re-advertises. Election logged loudly; a bind failure logs + retries next tick (self-heal). The nextpublish_account_registrycarries the advertised endpoint into the gist automatically (it already includesroute_endpoints()).Tests
4 decision cases: isolated-with-peers elects; a connected LAN peer or a live relay suppresses it; grid-of-one (no enrolled peers) never elects. clippy
-D warnings+ fmt clean; existing relay tests still green.Where this leaves the backbone
Self-election is complete. A node that can't reach anyone becomes a relay and advertises itself; reachable peers find it through the gist and route through it. So for the fleet: once these land and daemons refresh, an isolated-but-reachable node (e.g. a Mac that accepts inbound) will self-elect, and BigMama↔M5↔IntelMac can re-form over the relay — and continuum's grid with them (same transport). Remaining polish: slice 8 (relay↔relay federation), 9 (relay durable mailbox), 10 (gist room directory).
🤖 Generated with Claude Code