Skip to main content

HickoryDnsResolver

Struct HickoryDnsResolver 

Source
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>

Source

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>

Source

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>

Source

pub fn shared() -> Self

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.

Source

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

Source

pub fn thread_resolver() -> Self

Create a (lazy-initialized) resolver that is not shared across threads.

Source

pub fn use_system_resolver(&self)

Swap the primary internal resolver to the system resolver rather than the configured custom resolver.

Source

pub fn use_configured_resolver(&self)

Swap the primary internal resolver to the configured custom resolver rather than the system resolver.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug + ConnectionProvider> Debug for HickoryDnsResolver<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: ConnectionProvider> Default for HickoryDnsResolver<C>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<C: SharedResolverState> Resolve for HickoryDnsResolver<C>

Source§

fn resolve(&self, name: Name) -> Resolving

Performs DNS resolution on a Name. The return type is a future containing an iterator of SocketAddr. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more