mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 13:26:28 +03:00
introduce shortlived in-memory dns cache and prefill ip addresses into
it during configuration.
This commit is contained in:
@@ -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 ¶m.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());
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user