mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 12:38:43 +00:00
Enable happy eyeballs when using hickory-dns (#1877)
* Enable happy eyeballs when using hickory-dns Ported from seanmonstar/reqwest#2378 Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix imports in resolver.rs Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix fmt in resolver.rs Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix fmt in resolver.rs Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix resolver.rs Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix import on windows in resolver.rs Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> --------- Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
This commit is contained in:
parent
43012ceb2c
commit
a8eea5bc72
1 changed files with 40 additions and 31 deletions
|
@ -1,12 +1,15 @@
|
||||||
use std::{net::SocketAddr, sync::Arc};
|
use std::{net::SocketAddr, sync::Arc};
|
||||||
|
|
||||||
use hickory_resolver::TokioAsyncResolver;
|
use hickory_resolver::{
|
||||||
|
config::{LookupIpStrategy, ResolverConfig, ResolverOpts},
|
||||||
|
system_conf, TokioAsyncResolver,
|
||||||
|
};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use reqwest::dns::{Addrs, Name, Resolve, Resolving};
|
use reqwest::dns::{Addrs, Name, Resolve, Resolving};
|
||||||
use tracing::{debug, instrument, warn};
|
use tracing::{debug, instrument, warn};
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use hickory_resolver::config::{NameServerConfig, Protocol, ResolverConfig, ResolverOpts};
|
use hickory_resolver::config::{NameServerConfig, Protocol};
|
||||||
|
|
||||||
type BoxError = Box<dyn std::error::Error + Send + Sync>;
|
type BoxError = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
|
||||||
|
@ -26,15 +29,14 @@ impl Resolve for TrustDnsResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
|
||||||
fn new_resolver() -> Result<TokioAsyncResolver, BoxError> {
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
fn get_configs() -> Result<(ResolverConfig, ResolverOpts), BoxError> {
|
||||||
debug!("Using system DNS resolver configuration");
|
debug!("Using system DNS resolver configuration");
|
||||||
Ok(TokioAsyncResolver::tokio_from_system_conf()?)
|
system_conf::read_system_conf().map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
fn get_configs() -> Result<(ResolverConfig, ResolverOpts), BoxError> {
|
||||||
debug!("Using custom DNS resolver configuration");
|
debug!("Using custom DNS resolver configuration");
|
||||||
let mut config = ResolverConfig::new();
|
let mut config = ResolverConfig::new();
|
||||||
let opts = ResolverOpts::default();
|
let opts = ResolverOpts::default();
|
||||||
|
@ -55,9 +57,16 @@ fn new_resolver() -> Result<TokioAsyncResolver, BoxError> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
debug!("Resolver configuration complete");
|
Ok((config, opts))
|
||||||
Ok(TokioAsyncResolver::tokio(config, opts))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
|
fn new_resolver() -> Result<TokioAsyncResolver, BoxError> {
|
||||||
|
let (config, mut opts) = get_configs()?;
|
||||||
|
|
||||||
|
debug!("Resolver configuration complete");
|
||||||
|
opts.ip_strategy = LookupIpStrategy::Ipv4AndIpv6;
|
||||||
|
Ok(TokioAsyncResolver::tokio(config, opts))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue