mongodb/client/options/
resolver_config.rs

1#[cfg(feature = "dns-resolver")]
2use hickory_resolver::config::ResolverConfig as HickoryResolverConfig;
3
4/// Configuration for the upstream nameservers to use for resolution.
5///
6/// This is a thin wrapper around a `hickory_resolver::config::ResolverConfig` provided to ensure
7/// API stability.
8#[derive(Clone, Debug)]
9#[cfg_attr(not(feature = "dns-resolver"), derive(PartialEq))]
10pub struct ResolverConfig {
11    #[cfg(feature = "dns-resolver")]
12    pub(crate) inner: HickoryResolverConfig,
13}
14
15#[cfg(feature = "dns-resolver")]
16impl PartialEq for ResolverConfig {
17    fn eq(&self, other: &Self) -> bool {
18        let (left, right) = (&self.inner, &other.inner);
19
20        if !(left.domain() == right.domain()
21            && left.search() == right.search()
22            && left.name_servers().len() == right.name_servers().len())
23        {
24            return false;
25        }
26
27        for (a, b) in std::iter::zip(left.name_servers(), right.name_servers()) {
28            if !(a.socket_addr == b.socket_addr
29                && a.protocol == b.protocol
30                && a.tls_dns_name == b.tls_dns_name
31                && a.http_endpoint == b.http_endpoint
32                && a.trust_negative_responses == b.trust_negative_responses
33                && a.bind_addr == b.bind_addr)
34            {
35                return false;
36            }
37        }
38
39        true
40    }
41}
42
43#[cfg(feature = "dns-resolver")]
44impl ResolverConfig {
45    /// Creates a default configuration, using 1.1.1.1, 1.0.0.1 and 2606:4700:4700::1111,
46    /// 2606:4700:4700::1001 (thank you, Cloudflare).
47    ///
48    /// Please see: <https://www.cloudflare.com/dns/>
49    pub fn cloudflare() -> Self {
50        ResolverConfig {
51            inner: HickoryResolverConfig::cloudflare(),
52        }
53    }
54
55    /// Creates a default configuration, using 8.8.8.8, 8.8.4.4 and 2001:4860:4860::8888,
56    /// 2001:4860:4860::8844 (thank you, Google).
57    ///
58    /// Please see Google’s privacy statement for important information about what they track, many
59    /// ISP’s track similar information in DNS.
60    pub fn google() -> Self {
61        ResolverConfig {
62            inner: HickoryResolverConfig::google(),
63        }
64    }
65
66    /// Creates a configuration, using 9.9.9.9, 149.112.112.112 and 2620:fe::fe, 2620:fe::fe:9, the
67    /// “secure” variants of the quad9 settings (thank you, Quad9).
68    ///
69    /// Please see: <https://www.quad9.net/faq/>
70    pub fn quad9() -> Self {
71        ResolverConfig {
72            inner: HickoryResolverConfig::quad9(),
73        }
74    }
75}