Skip to content

Commit

Permalink
cache flush: add the missing timer for updated expires
Browse files Browse the repository at this point in the history
  • Loading branch information
keepsimple1 committed Aug 20, 2024
1 parent c1d7efa commit fe3e9c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/dns_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ impl DnsCache {
///
/// Returns `None` if `incoming` is invalid / unrecognized, otherwise returns
/// (a new record, true) or (existing record with TTL updated, false).
///
/// If need to add new timers for related records, push into `timers`.
pub(crate) fn add_or_update(
&mut self,
incoming: DnsRecordBox,
timers: &mut Vec<u64>,
) -> Option<(&DnsRecordBox, bool)> {
let entry_name = incoming.get_name().to_string();

Expand Down Expand Up @@ -156,7 +159,11 @@ impl DnsCache {
&& r.get_expire() > now + 1000
{
debug!("FLUSH one record: {:?}", &r);
r.set_expire(now + 1000);
let new_expire = now + 1000;
r.set_expire(new_expire);

// Add a timer so the run loop will handle this expire.
timers.push(new_expire);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/service_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ impl Zeroconf {
let mut changes = Vec::new();
let mut timers = Vec::new();
for record in msg.answers {
match self.cache.add_or_update(record) {
match self.cache.add_or_update(record, &mut timers) {
Some((dns_record, true)) => {
timers.push(dns_record.get_record().get_expire_time());
timers.push(dns_record.get_record().get_refresh_time());
Expand Down

0 comments on commit fe3e9c1

Please sign in to comment.