#[cfg(feature = "dns-resolver")]
use hickory_resolver::config::ResolverConfig as HickoryResolverConfig;
#[derive(Clone, Debug)]
#[cfg_attr(not(feature = "dns-resolver"), derive(PartialEq))]
pub struct ResolverConfig {
#[cfg(feature = "dns-resolver")]
pub(crate) inner: HickoryResolverConfig,
}
#[cfg(feature = "dns-resolver")]
impl PartialEq for ResolverConfig {
fn eq(&self, other: &Self) -> bool {
let (left, right) = (&self.inner, &other.inner);
if !(left.domain() == right.domain()
&& left.search() == right.search()
&& left.name_servers().len() == right.name_servers().len())
{
return false;
}
for (a, b) in std::iter::zip(left.name_servers(), right.name_servers()) {
if !(a.ip == b.ip
&& a.trust_negative_responses == b.trust_negative_responses
&& a.connections.len() == b.connections.len()
&& std::iter::zip(&a.connections, &b.connections).all(|(ca, cb)| {
ca.port == cb.port && ca.protocol == cb.protocol && ca.bind_addr == cb.bind_addr
}))
{
return false;
}
}
true
}
}
#[cfg(feature = "dns-resolver")]
impl ResolverConfig {
pub fn cloudflare() -> Self {
ResolverConfig {
inner: HickoryResolverConfig::udp_and_tcp(&hickory_resolver::config::CLOUDFLARE),
}
}
pub fn google() -> Self {
ResolverConfig {
inner: HickoryResolverConfig::udp_and_tcp(&hickory_resolver::config::GOOGLE),
}
}
pub fn quad9() -> Self {
ResolverConfig {
inner: HickoryResolverConfig::udp_and_tcp(&hickory_resolver::config::QUAD9),
}
}
}