Skip to content

Commit f053971

Browse files
committed
fix(discovery,service): drop unused method, add MissedTickBehavior::Skip
- discovery.rs: drop the unused `peer_primary_ip` method. It was kept as a "canonical lookup entry point" with `#[allow(dead_code)]`, but the dialer reads `primary_cache` directly via the shared `Rc<RefCell>` in `connect.rs` and nothing else calls it. - discovery.rs: fix the `refresh()` doc — said "call from the if-watch supervisor" but it's actually driven by the service's periodic tick. - service.rs: set `MissedTickBehavior::Skip` on `discovery_refresh_tick` (30s). The default `Burst` would replay backlog ticks back-to-back when resuming from a long suspend, each triggering a redundant interface enumeration and TXT republish.
1 parent 66c006d commit f053971

2 files changed

Lines changed: 7 additions & 24 deletions

File tree

src/discovery.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ impl Discovery {
217217
}
218218
}
219219

220-
/// Re-register with the current primary IP. Call from the
221-
/// `if-watch` supervisor when interfaces come/go so the TXT
222-
/// record stays accurate.
220+
/// Re-register with the current primary IP. Called periodically
221+
/// by the service's main loop so the TXT record reflects the
222+
/// active default-route interface even when interface changes
223+
/// don't arrive through if-watch.
223224
pub(crate) fn refresh(&mut self) {
224225
if self.daemon.is_some() {
225226
self.register();
@@ -264,26 +265,6 @@ impl Discovery {
264265
// from the last-known hints, and a re-enable would otherwise
265266
// lose them until each peer's next announcement.
266267
}
267-
268-
/// Look up a peer's advertised primary IP by configured hostname
269-
/// (e.g. "JKMBP-M4-Max.local"). Returns `None` if discovery is
270-
/// disabled, the peer isn't advertising, or the peer's
271-
/// advertisement hasn't been resolved yet (mDNS browse is
272-
/// asynchronous; the cache populates as ServiceResolved events
273-
/// arrive). Callers should treat None as "no hint, fall through
274-
/// to whatever the dialer would have done anyway."
275-
///
276-
/// Currently unused by the in-tree dialer (which reads
277-
/// `primary_cache` directly via the shared Rc<RefCell> for
278-
/// inline use in `connect_to_handle`); kept as the canonical
279-
/// lookup entry point so callers outside `connect.rs` don't
280-
/// need to take the same Rc reference.
281-
#[allow(dead_code)]
282-
pub(crate) fn peer_primary_ip(&self, hostname: &str) -> Option<IpAddr> {
283-
self.daemon.as_ref()?;
284-
let key = normalize_mdns_name(hostname);
285-
self.primary_cache.borrow().get(&key).copied()
286-
}
287268
}
288269

289270
impl Drop for Discovery {

src/service.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ impl Service {
164164
// interface (default route) changes — e.g. user switches
165165
// off Wi-Fi and Mac falls back to Ethernet. Cheap: at most
166166
// one re-publish every 30s, and a no-op when the primary
167-
// hasn't moved.
167+
// hasn't moved. `Skip` so a long suspend doesn't backlog-
168+
// burst on resume.
168169
let mut discovery_refresh_tick = tokio::time::interval(Duration::from_secs(30));
170+
discovery_refresh_tick.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
169171
// skip the immediate-fire of the first tick — Discovery
170172
// already published once at startup
171173
discovery_refresh_tick.tick().await;

0 commit comments

Comments
 (0)