Skip to content

feat: report detailed state in DaemonStatus::Running - #524

Merged
keepsimple1 merged 9 commits into
mainfrom
feat/running-state
Nov 14, 2026
Merged

keepsimple1 merged 9 commits into
mainfrom
feat/running-state

Conversation

@keepsimple1

@keepsimple1 keepsimple1 commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Part of #514.
Also address issue #544.

Problem

The multicast sockets are set up only once, when the daemon starts, and failures were only logged at debug!. A daemon that couldn't bind sockets (neither IPv4 or IPv6) still started, register() returned Ok, and status() said Running. Such failures can't be reported as a DaemonEvent either, since no monitor exists that early. Failed multicast joins on an interface were likewise only logged.

Changes

  • new() fails when nothing can work. ServiceDaemon::new() / new_with_port() now create both sockets and register them with the poller before spawning the daemon thread. They return an error if neither the IPv4 nor the IPv6 socket can be bound, or if registering with the poller fails (previously the daemon thread just exited with a debug log). If only one socket fails (e.g. a host without IPv6), the daemon still runs.

  • DaemonStatus::Running(RunningState). RunningState is a snapshot of the daemon's local setup, as of when it handled the status() request. It does not say whether packets get delivered or whether services can be found.

    • ipv4_socket() / ipv6_socket() return a SocketState, with:
      • is_bound(): whether that multicast socket was bound;
      • bind_error(): why it failed, if it did, so callers can tell "no IPv6 here" from "port in use".
    • enabled_intfs() returns the enabled interfaces the daemon uses, ordered by index, as EnabledIntf: name(), index(), and ipv4() / ipv6(), each an Option<Membership> (None if the daemon has no address of that version there). Membership has:
      • addrs(): the addresses of that version on the interface;
      • is_joined() / join_error(): whether the multicast join worked, or the error from the last failed attempt, which is retried at the next IP check.

    All four public types are #[non_exhaustive] with private fields, so more state can be added later without breaking anyone.

  • Join failures are tracked. A failed join records nothing in my_intfs (since fix: do not record an interface address whose multicast join failed #523), so failures are kept in a separate map. An entry is cleared when a later join on that interface and IP version succeeds, when the address is disabled or invalid, or when the IP check no longer finds it. The status is now built on request, so the stored status field is gone.

  • Docs. new() / new_with_port() said an unusable port is reported through monitor(), which was never the case. They now describe the new behavior, and status() says its result is a snapshot.

Breaking change

DaemonStatus::Running is now DaemonStatus::Running(RunningState). Code matching or comparing it needs DaemonStatus::Running(_). That's a compile error rather than a silent behavior change, but it needs a minor version bump (0.22).

Part of #514. The multicast sockets are only set up once, when the daemon
starts, and their failures were only logged at debug level. A daemon that
could bind neither socket still started, and `status()` said `Running`.

- `ServiceDaemon::new()` / `new_with_port()` now create both sockets before
  spawning the daemon thread, and return an error if neither can be bound.
- `DaemonStatus::Running` now carries a `RunningState`, whose `ipv4()` and
  `ipv6()` tell whether that socket is bound (`is_bound()`) and, if not,
  why (`bind_error()`). A host without IPv6 still runs on IPv4 alone.
- Fix the `new()` / `new_with_port()` docs, which said such failures are
  reported through `monitor()`.

BREAKING CHANGE: `DaemonStatus::Running` is now `DaemonStatus::Running(RunningState)`.
Match it with `DaemonStatus::Running(_)`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@keepsimple1 keepsimple1 changed the title feat!: report multicast socket setup in DaemonStatus::Running feat: report multicast socket setup in DaemonStatus::Running Oct 17, 2026
keepsimple1 and others added 4 commits October 18, 2026 16:24
…gState

`RunningState` now also lists the interfaces the daemon selected, with the
multicast membership of each IP version on them: joined, or the error from
the last failed attempt, or none if there is no address of that version.

A failed join records nothing in `my_intfs`, so failures are kept in a
separate `join_failures` map. An entry is cleared when a later join on that
interface and IP version succeeds, when the address is disabled or invalid,
or when the IP check no longer finds it.

Also:
- `Ipv4State` and `Ipv6State` are merged into one public `SocketState`,
  returned by `ipv4_socket()` / `ipv6_socket()`.
- The sockets are registered with the poller in `new()`, which now fails
  if that does, instead of the daemon thread exiting with only a debug log.
- The status is built on request, so the stored `status` field is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@keepsimple1 keepsimple1 changed the title feat: report multicast socket setup in DaemonStatus::Running feat: report daemon readiness in DaemonStatus::Running Nov 11, 2026
With IP checks disabled, a failed join is only retried when the interface
selection changes, not at a periodic check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@keepsimple1 keepsimple1 changed the title feat: report daemon readiness in DaemonStatus::Running feat: report sockets and interfaces state in DaemonStatus::Running Nov 14, 2026
@keepsimple1 keepsimple1 changed the title feat: report sockets and interfaces state in DaemonStatus::Running feat: report detailed state in DaemonStatus::Running Nov 14, 2026
Match the public vocabulary of `enable_interface()` / `disable_interface()`:
`SelectedIntf` becomes `EnabledIntf`, and `RunningState::selected_intfs()`
becomes `enabled_intfs()`. The public docs no longer mention interface
"selection", which is internal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@keepsimple1
keepsimple1 merged commit 4774fb9 into main Nov 14, 2026
6 checks passed
@keepsimple1
keepsimple1 deleted the feat/running-state branch November 14, 2026 04:47
keepsimple1 added a commit to WillBux/mdns-sd that referenced this pull request Nov 22, 2026
…hed-addr

Pass the address snapshot to the new del_interface_addr() call in
test_running_state_reports_join_per_ip_version, added on main by keepsimple1#524.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant