upgrade hickory and hyper-util dependencies
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
5d1404e9df
commit
58adb6fead
4 changed files with 229 additions and 39 deletions
|
@ -5,7 +5,7 @@ use std::{
|
|||
|
||||
use conduwuit::{Err, Result, debug, debug_info, err, error, trace};
|
||||
use futures::{FutureExt, TryFutureExt};
|
||||
use hickory_resolver::error::ResolveError;
|
||||
use hickory_resolver::ResolveError;
|
||||
use ipaddress::IPAddress;
|
||||
use ruma::ServerName;
|
||||
|
||||
|
@ -334,25 +334,28 @@ impl super::Service {
|
|||
}
|
||||
|
||||
fn handle_resolve_error(e: &ResolveError, host: &'_ str) -> Result<()> {
|
||||
use hickory_resolver::error::ResolveErrorKind;
|
||||
use hickory_resolver::{ResolveErrorKind::Proto, proto::ProtoErrorKind};
|
||||
|
||||
match *e.kind() {
|
||||
| ResolveErrorKind::NoRecordsFound { .. } => {
|
||||
// Raise to debug_warn if we can find out the result wasn't from cache
|
||||
debug!(%host, "No DNS records found: {e}");
|
||||
Ok(())
|
||||
},
|
||||
| ResolveErrorKind::Timeout => {
|
||||
Err!(warn!(%host, "DNS {e}"))
|
||||
},
|
||||
| ResolveErrorKind::NoConnections => {
|
||||
error!(
|
||||
"Your DNS server is overloaded and has ran out of connections. It is \
|
||||
strongly recommended you remediate this issue to ensure proper federation \
|
||||
connectivity."
|
||||
);
|
||||
match e.kind() {
|
||||
| Proto(e) => match e.kind() {
|
||||
| ProtoErrorKind::NoRecordsFound { .. } => {
|
||||
// Raise to debug_warn if we can find out the result wasn't from cache
|
||||
debug!(%host, "No DNS records found: {e}");
|
||||
Ok(())
|
||||
},
|
||||
| ProtoErrorKind::Timeout => {
|
||||
Err!(warn!(%host, "DNS {e}"))
|
||||
},
|
||||
| ProtoErrorKind::NoConnections => {
|
||||
error!(
|
||||
"Your DNS server is overloaded and has ran out of connections. It is \
|
||||
strongly recommended you remediate this issue to ensure proper \
|
||||
federation connectivity."
|
||||
);
|
||||
|
||||
Err!(error!(%host, "DNS error: {e}"))
|
||||
Err!(error!(%host, "DNS error: {e}"))
|
||||
},
|
||||
| _ => Err!(error!(%host, "DNS error: {e}")),
|
||||
},
|
||||
| _ => Err!(error!(%host, "DNS error: {e}")),
|
||||
}
|
||||
|
|
|
@ -2,19 +2,19 @@ use std::{net::SocketAddr, sync::Arc, time::Duration};
|
|||
|
||||
use conduwuit::{Result, Server, err};
|
||||
use futures::FutureExt;
|
||||
use hickory_resolver::{TokioAsyncResolver, lookup_ip::LookupIp};
|
||||
use hickory_resolver::{TokioResolver, lookup_ip::LookupIp};
|
||||
use reqwest::dns::{Addrs, Name, Resolve, Resolving};
|
||||
|
||||
use super::cache::{Cache, CachedOverride};
|
||||
|
||||
pub struct Resolver {
|
||||
pub(crate) resolver: Arc<TokioAsyncResolver>,
|
||||
pub(crate) resolver: Arc<TokioResolver>,
|
||||
pub(crate) hooked: Arc<Hooked>,
|
||||
server: Arc<Server>,
|
||||
}
|
||||
|
||||
pub(crate) struct Hooked {
|
||||
resolver: Arc<TokioAsyncResolver>,
|
||||
resolver: Arc<TokioResolver>,
|
||||
cache: Arc<Cache>,
|
||||
server: Arc<Server>,
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ impl Resolver {
|
|||
let mut ns = sys_conf.clone();
|
||||
|
||||
if config.query_over_tcp_only {
|
||||
ns.protocol = hickory_resolver::config::Protocol::Tcp;
|
||||
ns.protocol = hickory_resolver::proto::xfer::Protocol::Tcp;
|
||||
}
|
||||
|
||||
ns.trust_negative_responses = !config.query_all_nameservers;
|
||||
|
@ -51,6 +51,7 @@ impl Resolver {
|
|||
}
|
||||
|
||||
opts.cache_size = config.dns_cache_entries as usize;
|
||||
opts.preserve_intermediates = true;
|
||||
opts.negative_min_ttl = Some(Duration::from_secs(config.dns_min_ttl_nxdomain));
|
||||
opts.negative_max_ttl = Some(Duration::from_secs(60 * 60 * 24 * 30));
|
||||
opts.positive_min_ttl = Some(Duration::from_secs(config.dns_min_ttl));
|
||||
|
@ -60,8 +61,7 @@ impl Resolver {
|
|||
opts.try_tcp_on_error = config.dns_tcp_fallback;
|
||||
opts.num_concurrent_reqs = 1;
|
||||
opts.edns0 = true;
|
||||
opts.shuffle_dns_servers = true;
|
||||
opts.rotate = true;
|
||||
opts.case_randomization = true;
|
||||
opts.ip_strategy = match config.ip_lookup_strategy {
|
||||
| 1 => hickory_resolver::config::LookupIpStrategy::Ipv4Only,
|
||||
| 2 => hickory_resolver::config::LookupIpStrategy::Ipv6Only,
|
||||
|
@ -69,9 +69,13 @@ impl Resolver {
|
|||
| 4 => hickory_resolver::config::LookupIpStrategy::Ipv6thenIpv4,
|
||||
| _ => hickory_resolver::config::LookupIpStrategy::Ipv4thenIpv6,
|
||||
};
|
||||
opts.authentic_data = false;
|
||||
|
||||
let resolver = Arc::new(TokioAsyncResolver::tokio(conf, opts));
|
||||
let rt_prov = hickory_resolver::proto::runtime::TokioRuntimeProvider::new();
|
||||
let conn_prov = hickory_resolver::name_server::TokioConnectionProvider::new(rt_prov);
|
||||
let mut builder = TokioResolver::builder_with_config(conf, conn_prov);
|
||||
*builder.options_mut() = opts;
|
||||
let resolver = Arc::new(builder.build());
|
||||
|
||||
Ok(Arc::new(Self {
|
||||
resolver: resolver.clone(),
|
||||
hooked: Arc::new(Hooked { resolver, cache, server: server.clone() }),
|
||||
|
@ -105,7 +109,7 @@ impl Resolve for Hooked {
|
|||
async fn hooked_resolve(
|
||||
cache: Arc<Cache>,
|
||||
server: Arc<Server>,
|
||||
resolver: Arc<TokioAsyncResolver>,
|
||||
resolver: Arc<TokioResolver>,
|
||||
name: Name,
|
||||
) -> Result<Addrs, Box<dyn std::error::Error + Send + Sync>> {
|
||||
match cache.get_override(name.as_str()).await {
|
||||
|
@ -129,7 +133,7 @@ async fn hooked_resolve(
|
|||
|
||||
async fn resolve_to_reqwest(
|
||||
server: Arc<Server>,
|
||||
resolver: Arc<TokioAsyncResolver>,
|
||||
resolver: Arc<TokioResolver>,
|
||||
name: Name,
|
||||
) -> ResolvingResult {
|
||||
use std::{io, io::ErrorKind::Interrupted};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue