Skip to content

feat: make ServiceInfo TTL setters public - #556

Merged
keepsimple1 merged 6 commits into
keepsimple1:mainfrom
PoHsuanLai:feat/public-ttl-setters
Nov 27, 2026
Merged

keepsimple1 merged 6 commits into
keepsimple1:mainfrom
PoHsuanLai:feat/public-ttl-setters

Conversation

@PoHsuanLai

Copy link
Copy Markdown
Contributor

Summary

Make ServiceInfo::set_host_ttl and ServiceInfo::set_other_ttl public. Until now they were the crate-private _set_host_ttl and _set_other_ttl, used only by tests. The defaults are unchanged.

Why

Some protocols advertised over DNS-SD recommend a shorter TTL than the RFC 6762 defaults. For example, Network MIDI 2.0 (M2-124 §4.6) recommends a Host keep its TTL to one minute or less, so a Host that leaves without a goodbye drops out of browsers quickly. The getters are already public; this adds the matching setters.

Testing

The four tests that used the old names now call the public setters: test_expired_srv, test_hostname_resolution_address_removed, test_refresh_ptr and test_cache_only. All pass.

@keepsimple1 keepsimple1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! Please see inline comment.

Comment thread src/service_info.rs Resolved
… seconds

set_host_ttl and set_other_ttl refuse a TTL outside 10..=2^31-1 and
leave the TTL unchanged: 0 would make the records goodbyes, a TTL of a
few seconds means constant query traffic, and RFC 2181 section 8 caps a
TTL at 2^31-1. The crate-private setters the tests use stay as they are.
@PoHsuanLai
PoHsuanLai force-pushed the feat/public-ttl-setters branch from e943cbc to 4d9b5e1 Compare November 25, 2026 10:40
…setters

- Make the TTL bounds public associated constants on ServiceInfo and
  link them from the set_host_ttl/set_other_ttl docs.
- Remove the crate-private _set_host_ttl/_set_other_ttl, so every TTL
  goes through the range check. The daemon tests now use the public
  setters with ServiceInfo::MIN_TTL.
- Point browsing apps to ServiceDaemon::verify() for faster detection
  of a vanished service.

@keepsimple1 keepsimple1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! I've also made minor changes on top of it, mainly to export the MIN_TTL and MAX_TTL.

recv_timeout() restarts its timer on every event, and the browse sends
SearchStarted at doubling intervals. With the 10 s TTL the 9 s wait kept
being extended until a second PTR refresh had gone out, so the refresh
counter was 2 instead of 1. Wait with recv_deadline() instead.
The second announcement, about 1 s after the first, restarts the TTL of
the cached PTR, so the 80% refresh comes about 9.2 s after resolution:
just after the 9 s deadline, which made the counter 0 on all platforms.
The next refresh comes about 8 s after the first, so check at 12 s.
The browse's own PTR queries (1, 2, 4, 8, 16 s apart) get answered once
the cached PTR is past half of its TTL, and each answer restarts the TTL
and pushes the 80% refresh back. With a 10 s TTL that makes the refresh
time depend on jitter, so no fixed check time works. Poll the metrics
until both the PTR and SRV/TXT refreshes are seen, up to 3 TTLs, then
check each was sent exactly once.
@keepsimple1
keepsimple1 merged commit 534eeb8 into keepsimple1:main Nov 27, 2026
6 checks passed
@PoHsuanLai
PoHsuanLai deleted the feat/public-ttl-setters branch November 27, 2026 22:26
@keepsimple1

Copy link
Copy Markdown
Owner

FYI, 0.22.1 is released and includes this fix.

@PoHsuanLai

Copy link
Copy Markdown
Contributor Author

FYI, 0.22.1 is released and includes this fix.

Thanks for the heads up and for getting the release out so quickly! Really appreciate the review and merge.

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.

2 participants