recursor: define the bare minimum integration test
This commit is contained in:
@@ -28,7 +28,7 @@ use crate::{
|
||||
dns_lru::{DnsLru, TtlConfig},
|
||||
error::ResolveError,
|
||||
lookup::Lookup,
|
||||
name_server::{GenericNameServerPool, TokioRuntimeProvider},
|
||||
name_server::{ConnectionProvider, GenericConnector, GenericNameServerPool, NameServerPool, TokioRuntimeProvider},
|
||||
Name,
|
||||
},
|
||||
Error, ErrorKind,
|
||||
@@ -40,13 +40,13 @@ type NameServerCache<P> = LruCache<Name, RecursorPool<P>>;
|
||||
/// A top down recursive resolver which operates off a list of roots for initial recursive requests.
|
||||
///
|
||||
/// This is the well known root nodes, referred to as hints in RFCs. See the IANA [Root Servers](https://www.iana.org/domains/root/servers) list.
|
||||
pub struct Recursor {
|
||||
roots: RecursorPool<TokioRuntimeProvider>,
|
||||
name_server_cache: Mutex<NameServerCache<TokioRuntimeProvider>>,
|
||||
pub struct Recursor<P: ConnectionProvider> {
|
||||
roots: RecursorPool<P>,
|
||||
name_server_cache: Mutex<NameServerCache<P>>,
|
||||
record_cache: DnsLru,
|
||||
}
|
||||
|
||||
impl Recursor {
|
||||
impl Recursor<GenericConnector<TokioRuntimeProvider>> {
|
||||
/// Construct a new recursor using the list of NameServerConfigs for the root node list
|
||||
///
|
||||
/// # Panics
|
||||
@@ -62,11 +62,24 @@ impl Recursor {
|
||||
|
||||
assert!(!roots.is_empty(), "roots must not be empty");
|
||||
|
||||
debug!("Using cache sizes {}/{}", ns_cache_size, record_cache_size);
|
||||
let opts = recursor_opts();
|
||||
let roots =
|
||||
GenericNameServerPool::from_config(roots, opts, TokioConnectionProvider::default());
|
||||
|
||||
Self::new_with_pool(roots, ns_cache_size, record_cache_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: ConnectionProvider> Recursor<P> {
|
||||
/// Construct a new recursor using a custom name server pool.
|
||||
/// You likely want to use `new` instead.
|
||||
pub fn new_with_pool(
|
||||
roots: NameServerPool<P>,
|
||||
ns_cache_size: usize,
|
||||
record_cache_size: usize,
|
||||
) -> Result<Self, ResolveError> {
|
||||
let roots = RecursorPool::from(Name::root(), roots);
|
||||
debug!("Using cache sizes {}/{}", ns_cache_size, record_cache_size);
|
||||
let name_server_cache = Mutex::new(NameServerCache::new(ns_cache_size));
|
||||
let record_cache = DnsLru::new(record_cache_size, TtlConfig::default());
|
||||
|
||||
@@ -76,7 +89,9 @@ impl Recursor {
|
||||
record_cache,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: ConnectionProvider + Default> Recursor<P> {
|
||||
/// Perform a recursive resolution
|
||||
///
|
||||
/// [RFC 1034](https://datatracker.ietf.org/doc/html/rfc1034#section-5.3.3), Domain Concepts and Facilities, November 1987
|
||||
@@ -287,7 +302,7 @@ impl Recursor {
|
||||
async fn lookup(
|
||||
&self,
|
||||
query: Query,
|
||||
ns: RecursorPool<TokioRuntimeProvider>,
|
||||
ns: RecursorPool<P>,
|
||||
now: Instant,
|
||||
) -> Result<Lookup, Error> {
|
||||
if let Some(lookup) = self.record_cache.get(&query, now) {
|
||||
@@ -337,7 +352,7 @@ impl Recursor {
|
||||
&self,
|
||||
zone: Name,
|
||||
request_time: Instant,
|
||||
) -> Result<RecursorPool<TokioRuntimeProvider>, Error> {
|
||||
) -> Result<RecursorPool<P>, Error> {
|
||||
// TODO: need to check TTLs here.
|
||||
if let Some(ns) = self.name_server_cache.lock().get_mut(&zone) {
|
||||
return Ok(ns.clone());
|
||||
@@ -465,10 +480,10 @@ impl Recursor {
|
||||
}
|
||||
|
||||
// now construct a namesever pool based off the NS and glue records
|
||||
let ns = GenericNameServerPool::from_config(
|
||||
let ns = NameServerPool::from_config(
|
||||
config_group,
|
||||
recursor_opts(),
|
||||
TokioConnectionProvider::default(),
|
||||
Default::default(),
|
||||
);
|
||||
let ns = RecursorPool::from(zone.clone(), ns);
|
||||
|
||||
|
@@ -18,10 +18,9 @@ use hickory_proto::{
|
||||
xfer::{DnsRequestOptions, DnsResponse},
|
||||
DnsHandle,
|
||||
};
|
||||
use hickory_resolver::name_server::{RuntimeProvider, TokioRuntimeProvider};
|
||||
use hickory_resolver::{
|
||||
error::{ResolveError, ResolveErrorKind},
|
||||
name_server::GenericNameServerPool,
|
||||
name_server::{ConnectionProvider, NameServerPool},
|
||||
Name,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
@@ -50,14 +49,14 @@ impl Future for SharedLookup {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct RecursorPool<P: RuntimeProvider + Send + 'static> {
|
||||
pub(crate) struct RecursorPool<P: ConnectionProvider> {
|
||||
zone: Name,
|
||||
ns: GenericNameServerPool<P>,
|
||||
ns: NameServerPool<P>,
|
||||
active_requests: Arc<Mutex<ActiveRequests>>,
|
||||
}
|
||||
|
||||
impl RecursorPool<TokioRuntimeProvider> {
|
||||
pub(crate) fn from(zone: Name, ns: GenericNameServerPool<TokioRuntimeProvider>) -> Self {
|
||||
impl<P: ConnectionProvider> RecursorPool<P> {
|
||||
pub(crate) fn from(zone: Name, ns: NameServerPool<P>) -> Self {
|
||||
let active_requests = Arc::new(Mutex::new(ActiveRequests::default()));
|
||||
|
||||
Self {
|
||||
@@ -68,10 +67,7 @@ impl RecursorPool<TokioRuntimeProvider> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> RecursorPool<P>
|
||||
where
|
||||
P: RuntimeProvider + Send + 'static,
|
||||
{
|
||||
impl<P: ConnectionProvider> RecursorPool<P> {
|
||||
pub(crate) fn zone(&self) -> &Name {
|
||||
&self.zone
|
||||
}
|
||||
|
Reference in New Issue
Block a user