introduce shortlived in-memory dns cache and prefill ip addresses into

it during configuration.
This commit is contained in:
Simon Laux
2026-01-19 19:51:41 +01:00
parent 252fc8480e
commit 420b36fcde
3 changed files with 34 additions and 0 deletions

View File

@@ -13,6 +13,8 @@ mod auto_mozilla;
mod auto_outlook;
pub(crate) mod server_params;
use std::net::IpAddr;
use anyhow::{Context as _, Result, bail, ensure, format_err};
use auto_mozilla::moz_autoconfigure;
use auto_outlook::outlk_autodiscover;
@@ -557,6 +559,25 @@ async fn configure(ctx: &Context, param: &EnteredLoginParam) -> Result<Option<&'
let ctx2 = ctx.clone();
let update_device_chats_handle = task::spawn(async move { ctx2.update_device_chats().await });
if !param.dns_prefill.is_empty() {
let mut ips: Vec<IpAddr> = Vec::new();
for ip in &param.dns_prefill {
match ip.parse::<IpAddr>() {
Ok(ip) => ips.push(ip),
Err(err) => {
error!(
ctx,
"IP address prefill failed: parsing of address '{ip}' failed: {err}"
);
}
}
}
ctx.dns_memory_cache
.write()
.await
.insert(param.imap.server.clone(), ips);
}
let configured_param = get_configured_param(ctx, param).await?;
let proxy_config = ProxyConfig::load(ctx).await?;
let strict_tls = configured_param.strict_tls(proxy_config.is_some());

View File

@@ -318,6 +318,11 @@ pub struct InnerContext {
) -> mail_builder::mime::MimePart<'a>,
>,
>,
/// Short lived DNS cache which only lives in memory.
/// Used for configuration from `dcaccount` links with ip address.
/// Like `dcaccount:example.org?a=127.0.0.1,[::1]`
pub(crate) dns_memory_cache: Arc<RwLock<HashMap<String, Vec<std::net::IpAddr>>>>,
}
/// The state of ongoing process.

View File

@@ -860,6 +860,14 @@ pub(crate) async fn lookup_host_with_cache(
}
}
}
if let Some(ips) = context.dns_memory_cache.read().await.get(hostname) {
for ip in ips {
let addr = SocketAddr::new(*ip, port);
if !cache.contains(&addr) {
cache.push(addr);
}
}
}
merge_with_cache(resolved_addrs, cache)
} else {