refactor: unify warm_stale/warm_domain, remove raw_wire alloc, add Freshness enum
- Extract refresh_entry in ctx.rs — warm_domain in main.rs now delegates to it instead of duplicating the resolve+cache logic (~40 lines removed) - Eliminate unconditional .to_vec() of raw wire on every UDP/DoT query — pass &buffer.buf[..len] directly (zero-cost for cache hits) - Replace bare bool stale flag with Freshness enum (Fresh/NearExpiry/Stale) making the three states self-documenting at every call site
This commit is contained in:
54
src/main.rs
54
src/main.rs
@@ -758,55 +758,11 @@ async fn load_blocklists(ctx: &ServerCtx, lists: &[String]) {
|
||||
}
|
||||
|
||||
async fn warm_domain(ctx: &ServerCtx, domain: &str) {
|
||||
use numa::question::QueryType;
|
||||
|
||||
for qtype in [QueryType::A, QueryType::AAAA] {
|
||||
if ctx.upstream_mode == numa::config::UpstreamMode::Recursive {
|
||||
let query = numa::packet::DnsPacket::query(0, domain, qtype);
|
||||
match numa::recursive::resolve_recursive(
|
||||
domain,
|
||||
qtype,
|
||||
&ctx.cache,
|
||||
&query,
|
||||
&ctx.root_hints,
|
||||
&ctx.srtt,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(resp) => {
|
||||
ctx.cache.write().unwrap().insert(domain, qtype, &resp);
|
||||
log::debug!("cache warm: {} {:?}", domain, qtype);
|
||||
}
|
||||
Err(e) => log::warn!("cache warm: {} {:?} failed: {}", domain, qtype, e),
|
||||
}
|
||||
} else {
|
||||
let query = numa::packet::DnsPacket::query(0, domain, qtype);
|
||||
let mut buf = numa::buffer::BytePacketBuffer::new();
|
||||
if query.write(&mut buf).is_err() {
|
||||
continue;
|
||||
}
|
||||
let pool = ctx.upstream_pool.lock().unwrap().clone();
|
||||
match numa::forward::forward_with_failover_raw(
|
||||
buf.filled(),
|
||||
&pool,
|
||||
&ctx.srtt,
|
||||
ctx.timeout,
|
||||
ctx.hedge_delay,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(wire) => {
|
||||
ctx.cache.write().unwrap().insert_wire(
|
||||
domain,
|
||||
qtype,
|
||||
&wire,
|
||||
numa::cache::DnssecStatus::Indeterminate,
|
||||
);
|
||||
log::debug!("cache warm: {} {:?}", domain, qtype);
|
||||
}
|
||||
Err(e) => log::warn!("cache warm: {} {:?} failed: {}", domain, qtype, e),
|
||||
}
|
||||
}
|
||||
for qtype in [
|
||||
numa::question::QueryType::A,
|
||||
numa::question::QueryType::AAAA,
|
||||
] {
|
||||
numa::ctx::refresh_entry(ctx, domain, qtype).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user