mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
feat: always use preloaded DNS results
Otherwise if DNS server returns incorrect results, we may never try preloaded DNS results. For example, we may get our first results from a captive portal. To test, add `127.0.0.1 example.org` and try to create an account. Without this change we only try 127.0.0.1 and fail. With this change preloaded DNS results are tried as well.
This commit is contained in:
@@ -108,6 +108,10 @@ pub(crate) async fn update_connect_timestamp(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Preloaded DNS results that can be used in case of DNS server failures.
|
||||||
|
///
|
||||||
|
/// See <https://support.delta.chat/t/no-dns-resolution-result/2778> and
|
||||||
|
/// <https://github.com/deltachat/deltachat-core-rust/issues/4920> for reasons.
|
||||||
static DNS_PRELOAD: Lazy<HashMap<&'static str, Vec<IpAddr>>> = Lazy::new(|| {
|
static DNS_PRELOAD: Lazy<HashMap<&'static str, Vec<IpAddr>>> = Lazy::new(|| {
|
||||||
HashMap::from([
|
HashMap::from([
|
||||||
(
|
(
|
||||||
@@ -501,21 +505,6 @@ static DNS_PRELOAD: Lazy<HashMap<&'static str, Vec<IpAddr>>> = Lazy::new(|| {
|
|||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Load hardcoded cache if everything else fails.
|
|
||||||
///
|
|
||||||
/// See <https://support.delta.chat/t/no-dns-resolution-result/2778> and
|
|
||||||
/// <https://github.com/deltachat/deltachat-core-rust/issues/4920> for reasons.
|
|
||||||
///
|
|
||||||
/// In the future we may pre-resolve all provider database addresses
|
|
||||||
/// and build them in.
|
|
||||||
fn load_hardcoded_cache(hostname: &str, port: u16) -> Vec<SocketAddr> {
|
|
||||||
if let Some(ips) = DNS_PRELOAD.get(hostname) {
|
|
||||||
ips.iter().map(|ip| SocketAddr::new(*ip, port)).collect()
|
|
||||||
} else {
|
|
||||||
Vec::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn lookup_cache(
|
async fn lookup_cache(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
host: &str,
|
host: &str,
|
||||||
@@ -631,8 +620,13 @@ pub(crate) async fn lookup_host_with_cache(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if resolved_addrs.is_empty() {
|
if let Some(ips) = DNS_PRELOAD.get(hostname) {
|
||||||
return Ok(load_hardcoded_cache(hostname, port));
|
for ip in ips {
|
||||||
|
let addr = SocketAddr::new(*ip, port);
|
||||||
|
if !resolved_addrs.contains(&addr) {
|
||||||
|
resolved_addrs.push(addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user