recursor: make the test helpers more capable
they did not previously allow any way to mock DNS query sequences in a manner compatible with the RecursorPool, which prefers to create new NameServers itself, rather than via anything injectable by the test.
This commit is contained in:
@@ -40,35 +40,12 @@ 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<P: ConnectionProvider> {
|
||||
pub struct Recursor<P: ConnectionProvider=TokioConnectionProvider> {
|
||||
roots: RecursorPool<P>,
|
||||
name_server_cache: Mutex<NameServerCache<P>>,
|
||||
record_cache: DnsLru,
|
||||
}
|
||||
|
||||
impl Recursor<GenericConnector<TokioRuntimeProvider>> {
|
||||
/// Construct a new recursor using the list of NameServerConfigs for the root node list
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This will panic if the roots are empty.
|
||||
pub fn new(
|
||||
roots: impl Into<NameServerConfigGroup>,
|
||||
ns_cache_size: usize,
|
||||
record_cache_size: usize,
|
||||
) -> Result<Self, ResolveError> {
|
||||
// configure the hickory-resolver
|
||||
let roots: NameServerConfigGroup = roots.into();
|
||||
|
||||
assert!(!roots.is_empty(), "roots must not be empty");
|
||||
|
||||
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.
|
||||
@@ -92,6 +69,27 @@ impl<P: ConnectionProvider> Recursor<P> {
|
||||
}
|
||||
|
||||
impl<P: ConnectionProvider + Default> Recursor<P> {
|
||||
/// Construct a new recursor using the list of NameServerConfigs for the root node list
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This will panic if the roots are empty.
|
||||
pub fn new(
|
||||
roots: impl Into<NameServerConfigGroup>,
|
||||
ns_cache_size: usize,
|
||||
record_cache_size: usize,
|
||||
) -> Result<Self, ResolveError> {
|
||||
// configure the hickory-resolver
|
||||
let roots: NameServerConfigGroup = roots.into();
|
||||
|
||||
assert!(!roots.is_empty(), "roots must not be empty");
|
||||
|
||||
let opts = recursor_opts();
|
||||
let roots = NameServerPool::from_config(roots, opts, P::default());
|
||||
|
||||
Self::new_with_pool(roots, ns_cache_size, record_cache_size)
|
||||
}
|
||||
|
||||
/// Perform a recursive resolution
|
||||
///
|
||||
/// [RFC 1034](https://datatracker.ietf.org/doc/html/rfc1034#section-5.3.3), Domain Concepts and Facilities, November 1987
|
||||
|
Reference in New Issue
Block a user