Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRV TTL triggers timeout event #175

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions src/service_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,16 +513,31 @@ impl ServiceDaemon {
// check and evict expired records in our cache
let now = current_time_millis();
let map = zc.queriers.clone();
zc.cache.evict_expired(now, |expired| {
if let Some(dns_ptr) = expired.any().downcast_ref::<DnsPointer>() {
let ty_domain = dns_ptr.get_name();
call_listener(
&map,
ty_domain,
ServiceEvent::ServiceRemoved(ty_domain.to_string(), dns_ptr.alias.clone()),
);
}
});
for (ty_domain, _sender) in zc.queriers.iter() {
zc.cache.evict_expired(&ty_domain, now, |expired| {
if let Some(dns_ptr) = expired.any().downcast_ref::<DnsPointer>() {
// let ty_domain = dns_ptr.get_name();
call_listener(
&map,
ty_domain,
ServiceEvent::ServiceRemoved(
ty_domain.to_string(),
dns_ptr.alias.clone(),
),
);
} else if let Some(dns_srv) = expired.any().downcast_ref::<DnsSrv>() {
let fullname = dns_srv.get_name();
call_listener(
&map,
ty_domain,
ServiceEvent::ServiceInactive(
ty_domain.to_string(),
fullname.to_string(),
),
);
}
});
}

// check IP changes.
if now > next_ip_check {
Expand Down Expand Up @@ -1897,6 +1912,8 @@ pub enum ServiceEvent {
ServiceResolved(ServiceInfo),
/// A service instance (service_type, fullname) was removed.
ServiceRemoved(String, String),
/// A service instance (service_type, fullname) was offline.
ServiceInactive(String, String),
/// Stopped searching for a service type.
SearchStopped(String),
}
Expand Down Expand Up @@ -2094,13 +2111,14 @@ impl DnsCache {

/// Iterate all records and remove ones that expired, allowing
/// a function `f` to react with the expired ones.
fn evict_expired<F>(&mut self, now: u64, f: F)
fn evict_expired<F>(&mut self, ty_domain: &str, now: u64, f: F)
where
F: Fn(&DnsRecordBox), // Caller has a chance to do something with expired
{
let all_records = self
.ptr
.values_mut()
.get_mut(ty_domain)
.into_iter()
.chain(self.srv.values_mut())
.chain(self.txt.values_mut())
.chain(self.addr.values_mut());
Expand Down
Loading