Repository navigation
Add discovery.watch() for services that need to hear the network change - #22
Merged
Merged
Conversation
discover() asks the network once and returns, which is the right shape for a CLI and the wrong one for a service. A board broadcasts HELLO about ten seconds after it boots; a poller only finds out when its interval next comes round, so a machine that rebooted is invisible for up to that long. watch() keeps the socket open and yields as things happen: "joined" when a board announces itself, "roster" for a FULL frame. FULL is worth surfacing separately because it is the registry board's complete list and every board on the network checks it against what it knows and corrects it -- the closest thing to ground truth about who is live. It reuses discover()'s probing so quiet networks still answer (a lone board only announces itself every 15 s unprovoked), and it owns the discovery port while running, which the docstring says plainly since a concurrent discover() would be pushed to an ephemeral port and go deaf. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VmtVSp58rDkDBRPzL9hJkt
Coverage report✅ Total coverage: 100.00% (0.00% vs base |
The coverage gate was right to complain: watch() had four unexercised branches, and each is a real behaviour rather than defensive padding. - An interface with no broadcast route makes sendto fail, and that must not stop the watch -- probing is best effort across every interface. - Windows reports an earlier datagram's ICMP port-unreachable on the next receive. It looks like a socket error and is not one. - A socket that genuinely dies ends the watch by returning, so the caller can start a fresh one, rather than raising into it. - The per-interface probe sockets get closed alongside the listening one. warpedpinball/discovery.py is back to 100%. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VmtVSp58rDkDBRPzL9hJkt
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.
What
discover()asks the network once and returns — the right shape for a CLI, the wrong one for a long-running service. A board broadcasts HELLO about ten seconds after it boots, but a poller only finds out when its interval next comes round, so a machine that rebooted is invisible until then.discovery.watch()keeps the socket open and yields as things happen:Why FULL gets its own event kind
A FULL frame is the registry board's complete list of live boards, and every board on the network checks it against what it knows and corrects it if it's wrong. That makes it the closest thing this protocol has to ground truth about who is on the network right now — worth handing to callers as an authoritative roster rather than folding into a stream of individual sightings.
HELLO is the complementary signal: one specific board saying "I just came up". Together they answer both questions a service has — what's out there, and what just changed.
Notes
discover()'s probing (PING + OFFLINE, every interface, limited and directed broadcast) so quiet networks still answer — a lone board only announces itself every 15 s unprovoked.watch()owns the discovery port while it runs. The docstring says so plainly: a concurrentdiscover()in the same process would be pushed to an ephemeral port by the_open_socket()fallback and go deaf to the FULL frames and unicast PONGs it's waiting for. That's a quiet failure worth warning about at the call site.Testing
python -m pytest— 322 passedruff check .— cleandiscover()), self-probe loopback filtering, garbage and PONG frames, probing, and socket cleanup on early exit.Version 0.4.0 → 0.5.0. Consumed by the Origin change that makes the discovery relay listen continuously instead of polling.
🤖 Generated with Claude Code
https://claude.ai/code/session_01VmtVSp58rDkDBRPzL9hJkt
Generated by Claude Code