pub struct HickoryDnsResolver<C: ConnectionProvider = TokioRuntimeProvider> { /* private fields */ }Expand description
Wrapper around a hickory-resolver Resolver, which implements the Resolve trait.
Generic over the ConnectionProvider used by the underlying resolver, defaulting to
TokioRuntimeProvider (i.e. a TokioResolver) so existing callers are unaffected. See the
module docs for details on using a different provider.
Typical use involves instantiating using the Default implementation and then resolving using
methods or trait implementations.
The default initialization uses a shared underlying resolver. If a thread local resolver is
required use thread_resolver() to build a resolver with an independently instantiated
internal resolver.
Implementations§
Source§impl<C: SharedResolverState> HickoryDnsResolver<C>
impl<C: SharedResolverState> HickoryDnsResolver<C>
Sourcepub async fn trial_nameservers(&self)
pub async fn trial_nameservers(&self)
Do a trial resolution using each nameserver individually to test which are working and which fail to complete a lookup. This will always try the full set of default configured resolvers.
This diagnostic always runs over Tokio (via TokioRuntimeProvider), independent of the
connection provider C this resolver is otherwise configured with.
Source§impl HickoryDnsResolver<TokioRuntimeProvider>
impl HickoryDnsResolver<TokioRuntimeProvider>
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct the default, Tokio-backed resolver.
Prefer this over Default::default() / HickoryDnsResolver::default(): since
HickoryDnsResolver is generic over its connection provider, Default is implemented for
every valid provider. Building a HickoryDnsResolver through the Default trait therefore
requires a type annotation, e.g. let resolver: HickoryDnsResolver<TokioRuntimeProvider> = HickoryDnsResolver::default();. new is inherent to TokioRuntimeProvider specifically,
so it resolves without an explicit type annotation.
Source§impl<C: SharedResolverState> HickoryDnsResolver<C>
impl<C: SharedResolverState> HickoryDnsResolver<C>
Returns an instance of the process-wide shared resolver for this connection provider, if
one exists (see SharedResolverState). Falls back to an independent instance (as if
built via Self::default) for connection providers without shared state.
Sourcepub async fn resolve_str(
&self,
name: &str,
) -> Result<impl Iterator<Item = IpAddr> + use<C>, ResolveError>
pub async fn resolve_str( &self, name: &str, ) -> Result<impl Iterator<Item = IpAddr> + use<C>, ResolveError>
Attempt to resolve a domain name to a set of IpAddrs
Sourcepub fn thread_resolver() -> Self
pub fn thread_resolver() -> Self
Create a (lazy-initialized) resolver that is not shared across threads.
Sourcepub fn use_system_resolver(&self)
pub fn use_system_resolver(&self)
Swap the primary internal resolver to the system resolver rather than the configured custom resolver.
Sourcepub fn use_configured_resolver(&self)
pub fn use_configured_resolver(&self)
Swap the primary internal resolver to the configured custom resolver rather than the system resolver.
Sourcepub fn clear_preresolve(&self)
pub fn clear_preresolve(&self)
Clear entries from the static table that would return entries during the pre-resolve stage. This means that all lookups will attempt to use the network resolver again before the static table is consulted.
Entries elevated to pre-resolve from fallback (added from default or using
Self::set_fallback_addrs) will have their cache timeout cleared. Entries added directly
to pre-resolve (using Self::set_static_preresolve) will be removed.
Sourcepub fn get_static_fallbacks(&self) -> Option<HashMap<String, Vec<IpAddr>>>
pub fn get_static_fallbacks(&self) -> Option<HashMap<String, Vec<IpAddr>>>
Get the current map of hostnames to addresses used in the fallback static lookup stage if one exists.
Sourcepub fn set_fallback_addrs(&self, addrs: HashMap<String, Vec<IpAddr>>)
pub fn set_fallback_addrs(&self, addrs: HashMap<String, Vec<IpAddr>>)
Set (or overwrite) the map of addresses used in the fallback static hostname lookup.
Sourcepub fn get_static_preresolve(&self) -> Option<HashMap<String, Vec<IpAddr>>>
pub fn get_static_preresolve(&self) -> Option<HashMap<String, Vec<IpAddr>>>
Get the current map of hostnames to addresses used in the preresolve static lookup stage if one exists.
Sourcepub fn set_static_preresolve(&self, addrs: HashMap<String, Vec<IpAddr>>)
pub fn set_static_preresolve(&self, addrs: HashMap<String, Vec<IpAddr>>)
Set (or overwrite) the map of addresses used in the preresolve static hostname lookup.
Sourcepub fn default_name_servers(&self) -> Vec<NameServerConfig>
pub fn default_name_servers(&self) -> Vec<NameServerConfig>
Get the full default set of known nameserver configs (Cloudflare and Quad9, DoT and DoH,
IPv4 and IPv6). Unlike Self::get_name_servers, this is independent of any override
applied via Self::set_name_servers.
Sourcepub fn get_name_servers(&self) -> Vec<NameServerConfig>
pub fn get_name_servers(&self) -> Vec<NameServerConfig>
Get the nameserver group currently configured for this resolver, reflecting any change
made via Self::set_name_servers.
Sourcepub fn set_name_servers(&self, name_servers: Vec<NameServerConfig>)
pub fn set_name_servers(&self, name_servers: Vec<NameServerConfig>)
Set (or overwrite) the nameserver group used by this resolver. Since the underlying resolver is immutable once built, this invalidates the internal (cached, lazily-built) resolver: the next lookup made with this resolver rebuilds it using the new nameservers.
If this resolver uses the shared underlying resolver, the shared nameserver group and cached resolver are reset as well, so that other instances backed by the shared resolver pick up the change the next time they need to (re)build it.
Trait Implementations§
Source§impl<C: Clone + ConnectionProvider> Clone for HickoryDnsResolver<C>
impl<C: Clone + ConnectionProvider> Clone for HickoryDnsResolver<C>
Source§impl<C: Debug + ConnectionProvider> Debug for HickoryDnsResolver<C>
impl<C: Debug + ConnectionProvider> Debug for HickoryDnsResolver<C>
Source§impl<C: ConnectionProvider> Default for HickoryDnsResolver<C>
impl<C: ConnectionProvider> Default for HickoryDnsResolver<C>
Auto Trait Implementations§
impl<C = TokioRuntimeProvider> !RefUnwindSafe for HickoryDnsResolver<C>
impl<C = TokioRuntimeProvider> !UnwindSafe for HickoryDnsResolver<C>
impl<C> Freeze for HickoryDnsResolver<C>
impl<C> Send for HickoryDnsResolver<C>
impl<C> Sync for HickoryDnsResolver<C>
impl<C> Unpin for HickoryDnsResolver<C>
impl<C> UnsafeUnpin for HickoryDnsResolver<C>where
Arc<ArcSwapAny<Arc<OnceCell<Resolver<C>>>>>: UnsafeUnpin,
Arc<OnceCell<Resolver<C>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more