Skip to content

Commit

Permalink
feat(iroh-net): DNS queries: lookup ipv6 & ipv4 in parallel
Browse files Browse the repository at this point in the history
Closes #2006
  • Loading branch information
dignifiedquire committed Feb 12, 2024
1 parent df1efb3 commit 667408f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions iroh-net/src/dns.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use once_cell::sync::Lazy;
use trust_dns_resolver::{config, AsyncResolver, TokioAsyncResolver};
use trust_dns_resolver::{AsyncResolver, TokioAsyncResolver};

pub static DNS_RESOLVER: Lazy<TokioAsyncResolver> =
Lazy::new(|| get_resolver().expect("unable to create DNS resolver"));
Expand All @@ -11,13 +11,11 @@ pub static DNS_RESOLVER: Lazy<TokioAsyncResolver> =
/// This does not work at least on some Androids, therefore we fallback
/// to the default `ResolverConfig` which uses eg. to google's `8.8.8.8` or `8.8.4.4`.
fn get_resolver() -> Result<TokioAsyncResolver> {
if let Ok(resolver) = AsyncResolver::tokio_from_system_conf() {
return Ok(resolver);
}
let resolver = AsyncResolver::tokio(
config::ResolverConfig::default(),
config::ResolverOpts::default(),
);
let (config, mut options) = trust_dns_resolver::system_conf::read_system_conf().unwrap_or_default();
// lookup IPv4 and IPv6 in parallel
options.ip_strategy = trust_dns_resolver::config::LookupIpStrategy::Ipv4AndIpv6;

let resolver = AsyncResolver::tokio(config, options);
Ok(resolver)
}

Expand Down

0 comments on commit 667408f

Please sign in to comment.