Skip to main content

Resolver

Struct Resolver 

Source
pub struct Resolver { /* private fields */ }
Expand description

An in-process DNS query orchestrator.

Construct it from a split-DNS policy and one or more upstream backends per group, then resolve decoded queries against it. It owns policy selection, caching, and upstream failover, but not server lifecycle or transport protocol implementation; see the module documentation.

§Lifecycle

Construct via Resolver::builder, call Resolver::resolve as many times as needed, then drop. This stage holds no background threads, so there is no explicit shutdown method — Rust’s ordinary drop semantics fully release any resources the resolver owns (including any sockets a registered crate::upstream::UdpBackend/crate::upstream::TcpBackend opens per call).

Implementations§

Source§

impl Resolver

Source

pub fn builder(policy: SplitDnsPolicy) -> ResolverBuilder

Starts building a resolver from a split-DNS policy.

Source

pub async fn resolve(&self, query: &Message) -> Result<Message>

Resolves one query.

Extracts the queried name from query’s first question. Locally handled Fake IP questions return before the hook, cache, and upstream stages. For every other question, static SplitDnsPolicy routing supplies a tentative group and an optional crate::hooks::RouteHook can authoritatively replace it. The selected registered group scopes the in-memory answer cache; on a miss its backends are tried in registration order: the first backend to return Ok wins and its answer is cached (per the existing TTL rules) and returned immediately. A backend failing with Error::Timeout, Error::Transport, or Error::Tls is treated as retryable — resolution moves on to the next backend in the group rather than failing the whole call. Once every backend in the group has been tried and failed, the last attempted backend’s error is propagated as-is; this exhausted-group failure is never cached. A group with exactly one backend behaves exactly as before: success or that one backend’s own error.

§Errors

Returns Error::NoRoute when no split-DNS rule matches the queried name and no default upstream group is configured, when no question is present in query, or when the selected group has no backend registered. A hook-selected unknown or empty group never falls back to static policy. A hook failure returns Error::Hook and is neither retried nor cached. Returns the last attempted backend’s error, propagated as-is (not cached), once every backend in the matched group has failed.

§Runtime requirement

Must be called from inside a tokio runtime context if the selected backend performs real socket I/O (e.g. crate::upstream::UdpBackend/ crate::upstream::TcpBackend) — see crate::upstream’s module-level docs.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.