diff --git a/Cargo.lock b/Cargo.lock index 3804e8c..f7e497a 100644 Binary files a/Cargo.lock and b/Cargo.lock differ diff --git a/querying/Cargo.toml b/querying/Cargo.toml index 33de5d0..fd69520 100644 --- a/querying/Cargo.toml +++ b/querying/Cargo.toml @@ -13,7 +13,7 @@ reqwest = { workspace = true } csv = "1.4.0" maxminddb = "0.27.3" log = { workspace = true } -hickory-resolver = { version = "0.26.0-beta.3", features = ["tokio", "webpki-roots", "https-ring"] } +hickory-resolver = { version = "0.26.0", features = ["tokio", "webpki-roots", "https-ring"] } thiserror = "2.0.18" url = "2.5.8" indicatif = "0.18.4" diff --git a/querying/src/lists.rs b/querying/src/lists.rs index a925f62..e171baa 100644 --- a/querying/src/lists.rs +++ b/querying/src/lists.rs @@ -64,14 +64,14 @@ impl CdnList { let record: NetworkRecord = result?; trie.insert(record.cidr, record); } - let (v4, v6) = trie.ip_count(); - info!("ip count: v4={}, v6={}", v4, v6); + let count = trie.ip_count(); + info!("ip count: v4={}, v6={:?}", count.ipv4, count.ipv6); self.trie = trie; Ok(()) } - pub fn v4_count(&self) -> u32 { - self.trie.ip_count().0 + pub fn v4_count(&self) -> u64 { + self.trie.ip_count().ipv4 } pub fn contains(&self, ip: &IpAddr) -> Option { @@ -141,8 +141,8 @@ impl RuBlacklist { IpNet::from_str(&net).map_err(|e| Error::new(io::ErrorKind::InvalidData, e))?; ip_trie.insert(net, ()); } - let (v4, v6) = ip_trie.ip_count(); - info!("ip count: v4={}, v6={}", v4, v6); + let count = ip_trie.ip_count(); + info!("ip count: v4={}, v6={:?}", count.ipv4, count.ipv6); self.ip_trie = ip_trie; let mut blocked_domains = Vec::new(); @@ -160,8 +160,8 @@ impl RuBlacklist { Ok(()) } - pub fn v4_count(&self) -> u32 { - self.ip_trie.ip_count().0 + pub fn v4_count(&self) -> u64 { + self.ip_trie.ip_count().ipv4 } pub fn contains_ip(&self, ip: &IpAddr) -> Option { @@ -219,9 +219,20 @@ impl Updatable for RuBlacklist { #[cfg(test)] mod tests { - use super::RuBlacklist; + use super::{CdnList, RuBlacklist}; use std::io::Cursor; + #[test] + fn ipv4_counts_can_represent_the_entire_address_space() { + let cdn = CdnList::load(Cursor::new("provider,cidr,region\nexample,0.0.0.0/0,\n")).unwrap(); + let blacklist = + RuBlacklist::load(Cursor::new("0.0.0.0/0\n"), Cursor::new(""), Cursor::new("")) + .unwrap(); + + assert_eq!(cdn.v4_count(), 1_u64 << 32); + assert_eq!(blacklist.v4_count(), 1_u64 << 32); + } + #[test] fn domain_lookup_matches_subdomains_on_label_boundaries() { let list = RuBlacklist::load( diff --git a/querying/src/resolver.rs b/querying/src/resolver.rs index 9887b99..8b9284a 100644 --- a/querying/src/resolver.rs +++ b/querying/src/resolver.rs @@ -77,7 +77,7 @@ impl Resolver { .map_err(map_resolve_error)? .answers() .iter() - .filter_map(|record| match record.data() { + .filter_map(|record| match &record.data { RData::PTR(ptr) => Some(ptr.to_string().trim_end_matches('.').to_string()), _ => None, })