Skip to content

Commit

Permalink
Refactoring DnsCache and how to resolve Service Instance (#108)
Browse files Browse the repository at this point in the history
Simplify the logic of resolving an instance: always resolve from the cache.
For any incoming updates, we update the cache first, then try to resolve.
  • Loading branch information
keepsimple1 committed Apr 26, 2023
1 parent 41b01a0 commit 3fe9b56
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 288 deletions.
9 changes: 9 additions & 0 deletions src/dns_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub(crate) struct DnsRecord {
pub(crate) entry: DnsEntry,
ttl: u32, // in seconds, 0 means this record should not be cached
created: u64, // UNIX time in millis

/// Support re-query an instance before its PTR record expires.
/// See https://datatracker.ietf.org/doc/html/rfc6762#section-5.2
refresh: u64, // UNIX time in millis
}

Expand All @@ -88,6 +91,10 @@ impl DnsRecord {
}
}

pub(crate) fn get_created(&self) -> u64 {
self.created
}

pub(crate) fn is_expired(&self, now: u64) -> bool {
get_expiration_time(self.created, self.ttl, 100) <= now
}
Expand Down Expand Up @@ -796,6 +803,8 @@ pub(crate) struct DnsIncoming {
offset: usize,
data: Vec<u8>,
pub(crate) questions: Vec<DnsQuestion>,
/// This field includes records in the `answers` section
/// and in the `additionals` section.
pub(crate) answers: Vec<DnsRecordBox>,
pub(crate) id: u16,
flags: u16,
Expand Down
Loading

0 comments on commit 3fe9b56

Please sign in to comment.