Skip to content

Commit cdada50

Browse files
committed
RUST-739 Define ResolverConfig wrapper type
1 parent 2e8931a commit cdada50

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

src/client/options/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#[cfg(all(test, not(feature = "sync")))]
22
mod test;
33

4+
mod resolver_config;
5+
46
use std::{
57
collections::HashSet,
68
fmt::{self, Display, Formatter},
@@ -28,7 +30,6 @@ use serde::{
2830
Deserializer,
2931
};
3032
use strsim::jaro_winkler;
31-
pub use trust_dns_resolver::config::ResolverConfig;
3233
use typed_builder::TypedBuilder;
3334
use webpki_roots::TLS_SERVER_ROOTS;
3435

@@ -44,6 +45,8 @@ use crate::{
4445
srv::SrvResolver,
4546
};
4647

48+
pub use resolver_config::ResolverConfig;
49+
4750
const DEFAULT_PORT: u16 = 27017;
4851

4952
const URI_OPTIONS: &[&str] = &[
@@ -820,7 +823,7 @@ impl ClientOptions {
820823
options.resolver_config = resolver_config.clone();
821824

822825
if srv {
823-
let mut resolver = SrvResolver::new(resolver_config).await?;
826+
let mut resolver = SrvResolver::new(resolver_config.map(|config| config.inner)).await?;
824827
let mut config = resolver
825828
.resolve_client_options(&options.hosts[0].hostname)
826829
.await?;

src/client/options/resolver_config.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use trust_dns_resolver::config::ResolverConfig as TrustDnsResolverConfig;
2+
3+
/// Configuration for the upstream nameservers to use for resolution.
4+
///
5+
/// This is a thin wrapper around a `trust_dns_resolver::config::ResolverConfig` provided to ensure
6+
/// API stability.
7+
#[derive(Clone, Debug, PartialEq)]
8+
pub struct ResolverConfig {
9+
pub(crate) inner: TrustDnsResolverConfig,
10+
}
11+
12+
impl ResolverConfig {
13+
/// Creates a default configuration, using 1.1.1.1, 1.0.0.1 and 2606:4700:4700::1111,
14+
/// 2606:4700:4700::1001 (thank you, Cloudflare).
15+
///
16+
/// Please see: https://www.cloudflare.com/dns/
17+
pub fn cloudflare() -> Self {
18+
ResolverConfig {
19+
inner: TrustDnsResolverConfig::cloudflare(),
20+
}
21+
}
22+
23+
/// Creates a default configuration, using 8.8.8.8, 8.8.4.4 and 2001:4860:4860::8888,
24+
/// 2001:4860:4860::8844 (thank you, Google).
25+
///
26+
/// Please see Google’s privacy statement for important information about what they track, many
27+
/// ISP’s track similar information in DNS.
28+
pub fn google() -> Self {
29+
ResolverConfig {
30+
inner: TrustDnsResolverConfig::google(),
31+
}
32+
}
33+
34+
/// Creates a configuration, using 9.9.9.9, 149.112.112.112 and 2620:fe::fe, 2620:fe::fe:9, the
35+
/// “secure” variants of the quad9 settings (thank you, Quad9).
36+
///
37+
/// Please see: https://www.quad9.net/faq/
38+
pub fn quad9() -> Self {
39+
ResolverConfig {
40+
inner: TrustDnsResolverConfig::quad9(),
41+
}
42+
}
43+
}

src/sdam/srv_polling/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ impl SrvPollingMonitor {
128128
return Ok(resolver);
129129
}
130130

131-
let resolver = SrvResolver::new(self.client_options.resolver_config.clone()).await?;
131+
let resolver =
132+
SrvResolver::new(self.client_options.resolver_config.clone().map(|c| c.inner)).await?;
132133

133134
// Since the connection was not `Some` above, this will always insert the new connection and
134135
// return a reference to it.

src/test/atlas_connectivity.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::{bson::doc, options::ClientOptions, Client};
1+
use crate::{bson::doc, client::options::ResolverConfig, options::ClientOptions, Client};
22
use bson::Document;
3-
use trust_dns_resolver::config::ResolverConfig;
43

54
async fn run_test(uri_env_var: &str, resolver_config: Option<ResolverConfig>) {
65
if std::env::var_os("MONGO_ATLAS_TESTS").is_none() {

0 commit comments

Comments
 (0)