mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Do not cache IP addresses which resolve into themselves
This commit is contained in:
13
src/net.rs
13
src/net.rs
@@ -55,8 +55,13 @@ async fn lookup_host_with_cache(
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (i, addr) in resolved_addrs.iter().enumerate() {
|
for (i, addr) in resolved_addrs.iter().enumerate() {
|
||||||
info!(context, "Resolved {}:{} into {}.", hostname, port, &addr);
|
let ip_string = addr.ip().to_string();
|
||||||
|
if ip_string == hostname {
|
||||||
|
// IP address resolved into itself, not interesting to cache.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
info!(context, "Resolved {}:{} into {}.", hostname, port, &addr);
|
||||||
let i = i64::try_from(i).unwrap_or_default();
|
let i = i64::try_from(i).unwrap_or_default();
|
||||||
|
|
||||||
// Update the cache.
|
// Update the cache.
|
||||||
@@ -71,11 +76,7 @@ async fn lookup_host_with_cache(
|
|||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
ON CONFLICT (hostname, address)
|
ON CONFLICT (hostname, address)
|
||||||
DO UPDATE SET timestamp=excluded.timestamp",
|
DO UPDATE SET timestamp=excluded.timestamp",
|
||||||
paramsv![
|
paramsv![hostname, ip_string, now.saturating_add(i).saturating_add(1)],
|
||||||
hostname,
|
|
||||||
addr.ip().to_string(),
|
|
||||||
now.saturating_add(i).saturating_add(1)
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user