Remove port number from DNS cache table

This commit is contained in:
link2xt
2023-01-19 20:26:11 +00:00
parent 7a47c9e38b
commit 7935085e74
2 changed files with 11 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
///! # Common network utilities. ///! # Common network utilities.
use std::net::SocketAddr; use std::net::{IpAddr, SocketAddr};
use std::pin::Pin; use std::pin::Pin;
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
@@ -67,14 +67,13 @@ async fn lookup_host_with_cache(
.sql .sql
.execute( .execute(
"INSERT INTO dns_cache "INSERT INTO dns_cache
(hostname, port, address, timestamp) (hostname, address, timestamp)
VALUES (?, ?, ?, ?) VALUES (?, ?, ?)
ON CONFLICT (hostname, port, address) ON CONFLICT (hostname, address)
DO UPDATE SET timestamp=excluded.timestamp", DO UPDATE SET timestamp=excluded.timestamp",
paramsv![ paramsv![
hostname, hostname,
port, addr.ip().to_string(),
addr.to_string(),
now.saturating_add(i).saturating_add(1) now.saturating_add(i).saturating_add(1)
], ],
) )
@@ -102,8 +101,9 @@ async fn lookup_host_with_cache(
) )
.await? .await?
{ {
match SocketAddr::from_str(&cached_address) { match IpAddr::from_str(&cached_address) {
Ok(addr) => { Ok(ip_addr) => {
let addr = SocketAddr::new(ip_addr, port);
if !resolved_addrs.contains(&addr) { if !resolved_addrs.contains(&addr) {
resolved_addrs.push(addr); resolved_addrs.push(addr);
} }
@@ -153,7 +153,7 @@ pub(crate) async fn connect_tcp(
"UPDATE dns_cache "UPDATE dns_cache
SET timestamp = ? SET timestamp = ?
WHERE address = ?", WHERE address = ?",
paramsv![time(), resolved_addr.to_string()], paramsv![time(), resolved_addr.ip().to_string()],
) )
.await?; .await?;
break; break;

View File

@@ -675,10 +675,9 @@ CREATE INDEX smtp_messageid ON imap(rfc724_mid);
sql.execute_migration( sql.execute_migration(
"CREATE TABLE dns_cache ( "CREATE TABLE dns_cache (
hostname TEXT NOT NULL, hostname TEXT NOT NULL,
port INTEGER NOT NULL, address TEXT NOT NULL, -- IPv4 or IPv6 address
address TEXT NOT NULL,
timestamp INTEGER NOT NULL, timestamp INTEGER NOT NULL,
UNIQUE (hostname, port, address) UNIQUE (hostname, address)
)", )",
97, 97,
) )