diff --git a/pr/4199/docs/iroh/dns/struct.Builder.html b/pr/4199/docs/iroh/dns/struct.Builder.html index 57f08081aa..d4ad4d4aba 100644 --- a/pr/4199/docs/iroh/dns/struct.Builder.html +++ b/pr/4199/docs/iroh/dns/struct.Builder.html @@ -1,5 +1,5 @@ Builder in iroh::dns - Rust

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Available on non-wasm_browser only.
Expand description

Builder for DnsResolver.

-

Implementations§

Source§

impl Builder

Source

pub fn with_system_defaults(self) -> Builder

Reads the host system’s DNS configuration when the resolver builds.

+

Implementations§

Source§

impl Builder

Source

pub fn with_system_defaults(self) -> Builder

Reads the host system’s DNS configuration when the resolver builds.

On Linux, macOS, and Windows this picks up the operating system’s nameserver list. On Android the system reader is opt-in: by default the builder uses a built-in public DNS @@ -7,19 +7,17 @@ fallback, and callers that need the device’s per-network DNS supply the necessary JNI handles up front by calling install_android_jni_context (exported at the crate root, Android only).

-

The same public fallback (Cloudflare and Google over UDP and -TCP, plus DNS-over-HTTPS when the tls-ring or -tls-aws-lc-rs feature is enabled) is used on any platform -where the system reader returns nothing.

-
Source

pub fn with_nameserver(self, addr: SocketAddr, protocol: DnsProtocol) -> Builder

Adds a single nameserver.

-
Source

pub fn with_nameservers( +

The same public fallback (Google over UDP and TCP) is used on +any platform where the system reader returns nothing.

+

Source

pub fn with_nameserver(self, addr: SocketAddr, protocol: DnsProtocol) -> Builder

Adds a single nameserver.

+
Source

pub fn with_nameservers( self, nameservers: impl IntoIterator<Item = (SocketAddr, DnsProtocol)>, ) -> Builder

Adds a list of nameservers.

-
Source

pub fn tls_client_config(self, client_config: ClientConfig) -> Builder

Sets a custom TLS verification config.

+
Source

pub fn tls_client_config(self, client_config: ClientConfig) -> Builder

Sets a custom TLS verification config.

This is only used with DNS-over-TLS and DNS-over-HTTPS, and requires enabling either the ring or aws-lc-rs feature.

-
Source

pub fn build(self) -> DnsResolver

Builds the DNS resolver.

+
Source

pub fn build(self) -> DnsResolver

Builds the DNS resolver.

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Builder

Source§

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

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

impl Default for Builder

Source§

fn default() -> Builder

Returns the “default value” for a type. 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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where diff --git a/pr/4199/docs/iroh/dns/struct.DnsResolver.html b/pr/4199/docs/iroh/dns/struct.DnsResolver.html index 25ffda972c..37342324cd 100644 --- a/pr/4199/docs/iroh/dns/struct.DnsResolver.html +++ b/pr/4199/docs/iroh/dns/struct.DnsResolver.html @@ -1,47 +1,46 @@ -DnsResolver in iroh::dns - Rust

DnsResolver

Struct DnsResolver 

Source
pub struct DnsResolver { /* private fields */ }
Available on non-wasm_browser only.
Expand description

The DNS resolver used throughout iroh.

+DnsResolver in iroh::dns - Rust

DnsResolver

Struct DnsResolver 

Source
pub struct DnsResolver { /* private fields */ }
Available on non-wasm_browser only.
Expand description

The DNS resolver used throughout iroh.

By default, we use a built-in resolver that reads the system’s DNS configuration. The nameservers can be customized by constructing the resolver with Self::builder. Alternatively, you can create a fully custom DNS resolver by implementing the Resolver trait and creating the resolver with Self::custom.

-

Implementations§

Source§

impl DnsResolver

Source

pub fn new() -> DnsResolver

Creates a new resolver with sensible cross-platform defaults.

+

Implementations§

Source§

impl DnsResolver

Source

pub fn new() -> DnsResolver

Creates a new resolver with sensible cross-platform defaults.

Equivalent to Builder::default().with_system_defaults().build(). See Builder::with_system_defaults for the per-platform behavior, including the public DNS fallback that takes over when the system reader returns nothing.

-

The fallback can route queries through public providers -(Cloudflare and Google). To keep DNS traffic on caller-supplied -servers only, build the resolver through Self::builder -with explicit nameservers.

-
Source

pub fn with_nameserver(nameserver: SocketAddr) -> DnsResolver

Creates a new DNS resolver configured with a single UDP DNS nameserver.

-
Source

pub fn builder() -> Builder

Creates a builder to construct a DNS resolver with custom options.

-
Source

pub fn custom(resolver: impl Resolver) -> DnsResolver

Creates a new DnsResolver from a struct that implements Resolver.

+

The fallback routes queries through Google’s public DNS. To +keep DNS traffic on caller-supplied servers only, build the +resolver through Self::builder with explicit nameservers.

+
Source

pub fn with_nameserver(nameserver: SocketAddr) -> DnsResolver

Creates a new DNS resolver configured with a single UDP DNS nameserver.

+
Source

pub fn builder() -> Builder

Creates a builder to construct a DNS resolver with custom options.

+
Source

pub fn custom(resolver: impl Resolver) -> DnsResolver

Creates a new DnsResolver from a struct that implements Resolver.

If you need more customization for DNS resolving than the Builder allows, you can implement the Resolver trait on a struct and implement DNS resolution however you see fit.

-
Source

pub fn clear_cache(&self)

Removes all entries from the cache.

-
Source

pub fn reset(&self)

Replaces the inner resolver with a freshly-built one.

+
Source

pub fn clear_cache(&self)

Removes all entries from the cache.

+
Source

pub fn reset(&self)

Replaces the inner resolver with a freshly-built one.

Call this on a major host network change to pick up the new system DNS configuration and rebind sockets. The swap is atomic and non-blocking; in-flight lookups retry against the new resolver. See Resolver::reset.

-
Source

pub async fn lookup_txt<T>( +

Source

pub async fn lookup_txt<T>( &self, host: T, timeout: Duration, ) -> Result<impl Iterator<Item = TxtRecordData>, DnsError>
where T: ToString,

Looks up a TXT record.

-
Source

pub async fn lookup_ipv4<T>( +

Source

pub async fn lookup_ipv4<T>( &self, host: T, timeout: Duration, ) -> Result<impl Iterator<Item = IpAddr> + use<T>, DnsError>
where T: ToString,

Performs an IPv4 lookup with a timeout.

-
Source

pub async fn lookup_ipv6<T>( +

Source

pub async fn lookup_ipv6<T>( &self, host: T, timeout: Duration, ) -> Result<impl Iterator<Item = IpAddr> + use<T>, DnsError>
where T: ToString,

Performs an IPv6 lookup with a timeout.

-
Source

pub async fn lookup_ipv4_ipv6<T>( +

Source

pub async fn lookup_ipv4_ipv6<T>( &self, host: T, timeout: Duration, @@ -50,13 +49,13 @@ in-flight lookups retry against the new resolver. See
Source

pub async fn resolve_host( +

Source

pub async fn resolve_host( &self, url: &Url, prefer_ipv6: bool, timeout: Duration, ) -> Result<IpAddr, DnsError>

Resolves a hostname from a URL to an IP address.

-
Source

pub async fn lookup_ipv4_staggered( +

Source

pub async fn lookup_ipv4_staggered( &self, host: impl ToString, timeout: Duration, @@ -66,7 +65,7 @@ individually.

delays_ms with the first call being done immediately. [200ms, 300ms] results in calls at T+0ms, T+200ms and T+300ms. The timeout is applied to each call individually. The result of the first successful call is returned, or a summary of all errors otherwise.

-

Source

pub async fn lookup_ipv6_staggered( +

Source

pub async fn lookup_ipv6_staggered( &self, host: impl ToString, timeout: Duration, @@ -76,7 +75,7 @@ result of the first successful call is returned, or a summary of all errors othe delays_ms with the first call being done immediately. [200ms, 300ms] results in calls at T+0ms, T+200ms and T+300ms. The timeout is applied to each call individually. The result of the first successful call is returned, or a summary of all errors otherwise.

-

Source

pub async fn lookup_ipv4_ipv6_staggered( +

Source

pub async fn lookup_ipv4_ipv6_staggered( &self, host: impl ToString, timeout: Duration, @@ -87,18 +86,18 @@ result of the first successful call is returned, or a summary of all errors othe at T+0ms, T+200ms and T+300ms. The timeout is applied as stated in Self::lookup_ipv4_ipv6. The result of the first successful call is returned, or a summary of all errors otherwise.

-

Source

pub async fn lookup_endpoint_by_id( +

Source

pub async fn lookup_endpoint_by_id( &self, endpoint_id: &PublicKey, origin: &str, ) -> Result<EndpointInfo, LookupError>

Looks up endpoint info by EndpointId and origin domain name.

To lookup endpoints that published their endpoint info to the DNS servers run by n0, pass N0_DNS_ENDPOINT_ORIGIN_PROD as origin.

-
Source

pub async fn lookup_endpoint_by_domain_name( +

Source

pub async fn lookup_endpoint_by_domain_name( &self, name: &str, ) -> Result<EndpointInfo, LookupError>

Looks up endpoint info by DNS name.

-
Source

pub async fn lookup_endpoint_by_domain_name_staggered( +

Source

pub async fn lookup_endpoint_by_domain_name_staggered( &self, name: &str, delays_ms: &[u64], @@ -107,7 +106,7 @@ pass
Source

pub async fn lookup_endpoint_by_id_staggered( +

Source

pub async fn lookup_endpoint_by_id_staggered( &self, endpoint_id: &PublicKey, origin: &str, @@ -117,7 +116,7 @@ summary of all errors otherwise.

delays_ms with the first call being done immediately. [200ms, 300ms] results in calls at T+0ms, T+200ms and T+300ms. The result of the first successful call is returned, or a summary of all errors otherwise.

-

Trait Implementations§

Source§

impl Clone for DnsResolver

Source§

fn clone(&self) -> DnsResolver

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DnsResolver

Source§

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

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

impl Default for DnsResolver

Source§

fn default() -> DnsResolver

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

Auto Trait Implementations§

§

impl Freeze for DnsResolver

§

impl !RefUnwindSafe for DnsResolver

§

impl Send for DnsResolver

§

impl Sync for DnsResolver

§

impl Unpin for DnsResolver

§

impl !UnwindSafe for DnsResolver

Blanket Implementations§

Source§

impl<T> Any for T
where +

Trait Implementations§

Source§

impl Clone for DnsResolver

Source§

fn clone(&self) -> DnsResolver

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DnsResolver

Source§

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

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

impl Default for DnsResolver

Source§

fn default() -> DnsResolver

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

Auto Trait Implementations§

§

impl Freeze for DnsResolver

§

impl !RefUnwindSafe for DnsResolver

§

impl Send for DnsResolver

§

impl Sync for DnsResolver

§

impl Unpin for DnsResolver

§

impl !UnwindSafe for DnsResolver

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( diff --git a/pr/4199/docs/iroh/dns/struct.TxtRecordData.html b/pr/4199/docs/iroh/dns/struct.TxtRecordData.html index 62b48ed132..e2f63308e8 100644 --- a/pr/4199/docs/iroh/dns/struct.TxtRecordData.html +++ b/pr/4199/docs/iroh/dns/struct.TxtRecordData.html @@ -1,11 +1,11 @@ -TxtRecordData in iroh::dns - Rust

TxtRecordData

Struct TxtRecordData 

Source
pub struct TxtRecordData(/* private fields */);
Available on non-wasm_browser only.
Expand description

Record data for a TXT record.

+TxtRecordData in iroh::dns - Rust

TxtRecordData

Struct TxtRecordData 

Source
pub struct TxtRecordData(/* private fields */);
Available on non-wasm_browser only.
Expand description

Record data for a TXT record.

This contains a list of character strings, as defined in RFC 1035 Section 3.3.14.

TxtRecordData implements fmt::Display, so you can call ToString::to_string to convert the record data into a string. This will parse each character string with String::from_utf8_lossy and then concatenate all strings without a separator.

If you want to process each character string individually, use Self::iter.

-

Implementations§

Source§

impl TxtRecordData

Source

pub fn iter(&self) -> impl Iterator<Item = &[u8]>

Returns an iterator over the character strings contained in this TXT record.

-

Trait Implementations§

Source§

impl Clone for TxtRecordData

Source§

fn clone(&self) -> TxtRecordData

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TxtRecordData

Source§

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

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

impl Display for TxtRecordData

Source§

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

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

impl From<Vec<Box<[u8]>>> for TxtRecordData

Source§

fn from(value: Vec<Box<[u8]>>) -> TxtRecordData

Converts to this type from the input type.
Source§

impl FromIterator<Box<[u8]>> for TxtRecordData

Source§

fn from_iter<T>(iter: T) -> TxtRecordData
where +

Implementations§

Source§

impl TxtRecordData

Source

pub fn iter(&self) -> impl Iterator<Item = &[u8]>

Returns an iterator over the character strings contained in this TXT record.

+

Trait Implementations§

Source§

impl Clone for TxtRecordData

Source§

fn clone(&self) -> TxtRecordData

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TxtRecordData

Source§

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

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

impl Display for TxtRecordData

Source§

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

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

impl From<Vec<Box<[u8]>>> for TxtRecordData

Source§

fn from(value: Vec<Box<[u8]>>) -> TxtRecordData

Converts to this type from the input type.
Source§

impl FromIterator<Box<[u8]>> for TxtRecordData

Source§

fn from_iter<T>(iter: T) -> TxtRecordData
where T: IntoIterator<Item = Box<[u8]>>,

Creates a value from an iterator. 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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where diff --git a/pr/4199/docs/iroh_dns/dns/index.html b/pr/4199/docs/iroh_dns/dns/index.html index 72c43a3a59..aa43fad7df 100644 --- a/pr/4199/docs/iroh_dns/dns/index.html +++ b/pr/4199/docs/iroh_dns/dns/index.html @@ -1,4 +1,4 @@ -iroh_dns::dns - Rust

Module dns

Module dns 

Source
Expand description

Configurable DNS resolver.

+iroh_dns::dns - Rust

Module dns

Module dns 

Source
Expand description

Configurable DNS resolver.

The main export is the DnsResolver struct. It provides methods to resolve domain names to IPv4 and IPv6 addresses, and to look up TXT records. Additionally, the resolver features methods to resolve the EndpointInfo for an iroh EndpointId from _iroh TXT records. diff --git a/pr/4199/docs/iroh_dns/dns/struct.Builder.html b/pr/4199/docs/iroh_dns/dns/struct.Builder.html index 2f3bc90b44..463e3cd292 100644 --- a/pr/4199/docs/iroh_dns/dns/struct.Builder.html +++ b/pr/4199/docs/iroh_dns/dns/struct.Builder.html @@ -1,5 +1,5 @@ Builder in iroh_dns::dns - Rust

Builder

Struct Builder 

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

Builder for DnsResolver.

-

Implementations§

Source§

impl Builder

Source

pub fn with_system_defaults(self) -> Self

Reads the host system’s DNS configuration when the resolver builds.

+

Implementations§

Source§

impl Builder

Source

pub fn with_system_defaults(self) -> Self

Reads the host system’s DNS configuration when the resolver builds.

On Linux, macOS, and Windows this picks up the operating system’s nameserver list. On Android the system reader is opt-in: by default the builder uses a built-in public DNS @@ -7,19 +7,17 @@ fallback, and callers that need the device’s per-network DNS supply the necessary JNI handles up front by calling install_android_jni_context (exported at the crate root, Android only).

-

The same public fallback (Cloudflare and Google over UDP and -TCP, plus DNS-over-HTTPS when the tls-ring or -tls-aws-lc-rs feature is enabled) is used on any platform -where the system reader returns nothing.

-
Source

pub fn with_nameserver(self, addr: SocketAddr, protocol: DnsProtocol) -> Self

Adds a single nameserver.

-
Source

pub fn with_nameservers( +

The same public fallback (Google over UDP and TCP) is used on +any platform where the system reader returns nothing.

+

Source

pub fn with_nameserver(self, addr: SocketAddr, protocol: DnsProtocol) -> Self

Adds a single nameserver.

+
Source

pub fn with_nameservers( self, nameservers: impl IntoIterator<Item = (SocketAddr, DnsProtocol)>, ) -> Self

Adds a list of nameservers.

-
Source

pub fn tls_client_config(self, client_config: ClientConfig) -> Self

Sets a custom TLS verification config.

+
Source

pub fn tls_client_config(self, client_config: ClientConfig) -> Self

Sets a custom TLS verification config.

This is only used with DNS-over-TLS and DNS-over-HTTPS, and requires enabling either the ring or aws-lc-rs feature.

-
Source

pub fn build(self) -> DnsResolver

Builds the DNS resolver.

+
Source

pub fn build(self) -> DnsResolver

Builds the DNS resolver.

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Builder

Source§

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

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

impl Default for Builder

Source§

fn default() -> Builder

Returns the “default value” for a type. 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 diff --git a/pr/4199/docs/iroh_dns/dns/struct.DnsResolver.html b/pr/4199/docs/iroh_dns/dns/struct.DnsResolver.html index 5e59ef7128..7b36371e72 100644 --- a/pr/4199/docs/iroh_dns/dns/struct.DnsResolver.html +++ b/pr/4199/docs/iroh_dns/dns/struct.DnsResolver.html @@ -1,44 +1,43 @@ -DnsResolver in iroh_dns::dns - Rust

DnsResolver

Struct DnsResolver 

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

The DNS resolver used throughout iroh.

+DnsResolver in iroh_dns::dns - Rust

DnsResolver

Struct DnsResolver 

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

The DNS resolver used throughout iroh.

By default, we use a built-in resolver that reads the system’s DNS configuration. The nameservers can be customized by constructing the resolver with Self::builder. Alternatively, you can create a fully custom DNS resolver by implementing the Resolver trait and creating the resolver with Self::custom.

-

Implementations§

Source§

impl DnsResolver

Source

pub fn new() -> Self

Creates a new resolver with sensible cross-platform defaults.

+

Implementations§

Source§

impl DnsResolver

Source

pub fn new() -> Self

Creates a new resolver with sensible cross-platform defaults.

Equivalent to Builder::default().with_system_defaults().build(). See Builder::with_system_defaults for the per-platform behavior, including the public DNS fallback that takes over when the system reader returns nothing.

-

The fallback can route queries through public providers -(Cloudflare and Google). To keep DNS traffic on caller-supplied -servers only, build the resolver through Self::builder -with explicit nameservers.

-
Source

pub fn with_nameserver(nameserver: SocketAddr) -> Self

Creates a new DNS resolver configured with a single UDP DNS nameserver.

-
Source

pub fn builder() -> Builder

Creates a builder to construct a DNS resolver with custom options.

-
Source

pub fn custom(resolver: impl Resolver) -> Self

Creates a new DnsResolver from a struct that implements Resolver.

+

The fallback routes queries through Google’s public DNS. To +keep DNS traffic on caller-supplied servers only, build the +resolver through Self::builder with explicit nameservers.

+
Source

pub fn with_nameserver(nameserver: SocketAddr) -> Self

Creates a new DNS resolver configured with a single UDP DNS nameserver.

+
Source

pub fn builder() -> Builder

Creates a builder to construct a DNS resolver with custom options.

+
Source

pub fn custom(resolver: impl Resolver) -> Self

Creates a new DnsResolver from a struct that implements Resolver.

If you need more customization for DNS resolving than the Builder allows, you can implement the Resolver trait on a struct and implement DNS resolution however you see fit.

-
Source

pub fn clear_cache(&self)

Removes all entries from the cache.

-
Source

pub fn reset(&self)

Replaces the inner resolver with a freshly-built one.

+
Source

pub fn clear_cache(&self)

Removes all entries from the cache.

+
Source

pub fn reset(&self)

Replaces the inner resolver with a freshly-built one.

Call this on a major host network change to pick up the new system DNS configuration and rebind sockets. The swap is atomic and non-blocking; in-flight lookups retry against the new resolver. See Resolver::reset.

-
Source

pub async fn lookup_txt<T: ToString>( +

Source

pub async fn lookup_txt<T: ToString>( &self, host: T, timeout: Duration, ) -> Result<impl Iterator<Item = TxtRecordData>, DnsError>

Looks up a TXT record.

-
Source

pub async fn lookup_ipv4<T: ToString>( +

Source

pub async fn lookup_ipv4<T: ToString>( &self, host: T, timeout: Duration, ) -> Result<impl Iterator<Item = IpAddr> + use<T>, DnsError>

Performs an IPv4 lookup with a timeout.

-
Source

pub async fn lookup_ipv6<T: ToString>( +

Source

pub async fn lookup_ipv6<T: ToString>( &self, host: T, timeout: Duration, ) -> Result<impl Iterator<Item = IpAddr> + use<T>, DnsError>

Performs an IPv6 lookup with a timeout.

-
Source

pub async fn lookup_ipv4_ipv6<T: ToString>( +

Source

pub async fn lookup_ipv4_ipv6<T: ToString>( &self, host: T, timeout: Duration, @@ -46,13 +45,13 @@ in-flight lookups retry against the new resolver. See
Source

pub async fn resolve_host( +

Source

pub async fn resolve_host( &self, url: &Url, prefer_ipv6: bool, timeout: Duration, ) -> Result<IpAddr, DnsError>

Resolves a hostname from a URL to an IP address.

-
Source

pub async fn lookup_ipv4_staggered( +

Source

pub async fn lookup_ipv4_staggered( &self, host: impl ToString, timeout: Duration, @@ -62,7 +61,7 @@ individually.

delays_ms with the first call being done immediately. [200ms, 300ms] results in calls at T+0ms, T+200ms and T+300ms. The timeout is applied to each call individually. The result of the first successful call is returned, or a summary of all errors otherwise.

-

Source

pub async fn lookup_ipv6_staggered( +

Source

pub async fn lookup_ipv6_staggered( &self, host: impl ToString, timeout: Duration, @@ -72,7 +71,7 @@ result of the first successful call is returned, or a summary of all errors othe delays_ms with the first call being done immediately. [200ms, 300ms] results in calls at T+0ms, T+200ms and T+300ms. The timeout is applied to each call individually. The result of the first successful call is returned, or a summary of all errors otherwise.

-

Source

pub async fn lookup_ipv4_ipv6_staggered( +

Source

pub async fn lookup_ipv4_ipv6_staggered( &self, host: impl ToString, timeout: Duration, @@ -83,18 +82,18 @@ result of the first successful call is returned, or a summary of all errors othe at T+0ms, T+200ms and T+300ms. The timeout is applied as stated in Self::lookup_ipv4_ipv6. The result of the first successful call is returned, or a summary of all errors otherwise.

-

Source

pub async fn lookup_endpoint_by_id( +

Source

pub async fn lookup_endpoint_by_id( &self, endpoint_id: &EndpointId, origin: &str, ) -> Result<EndpointInfo, LookupError>

Looks up endpoint info by EndpointId and origin domain name.

To lookup endpoints that published their endpoint info to the DNS servers run by n0, pass N0_DNS_ENDPOINT_ORIGIN_PROD as origin.

-
Source

pub async fn lookup_endpoint_by_domain_name( +

Source

pub async fn lookup_endpoint_by_domain_name( &self, name: &str, ) -> Result<EndpointInfo, LookupError>

Looks up endpoint info by DNS name.

-
Source

pub async fn lookup_endpoint_by_domain_name_staggered( +

Source

pub async fn lookup_endpoint_by_domain_name_staggered( &self, name: &str, delays_ms: &[u64], @@ -103,7 +102,7 @@ pass
Source

pub async fn lookup_endpoint_by_id_staggered( +

Source

pub async fn lookup_endpoint_by_id_staggered( &self, endpoint_id: &EndpointId, origin: &str, @@ -113,7 +112,7 @@ summary of all errors otherwise.

delays_ms with the first call being done immediately. [200ms, 300ms] results in calls at T+0ms, T+200ms and T+300ms. The result of the first successful call is returned, or a summary of all errors otherwise.

-

Trait Implementations§

Source§

impl Clone for DnsResolver

Source§

fn clone(&self) -> DnsResolver

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DnsResolver

Source§

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

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

impl Default for DnsResolver

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for DnsResolver

§

impl !RefUnwindSafe for DnsResolver

§

impl Send for DnsResolver

§

impl Sync for DnsResolver

§

impl Unpin for DnsResolver

§

impl !UnwindSafe for DnsResolver

Blanket Implementations§

Source§

impl<T> Any for T
where +

Trait Implementations§

Source§

impl Clone for DnsResolver

Source§

fn clone(&self) -> DnsResolver

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DnsResolver

Source§

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

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

impl Default for DnsResolver

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for DnsResolver

§

impl !RefUnwindSafe for DnsResolver

§

impl Send for DnsResolver

§

impl Sync for DnsResolver

§

impl Unpin for DnsResolver

§

impl !UnwindSafe for DnsResolver

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 diff --git a/pr/4199/docs/iroh_dns/dns/struct.TxtRecordData.html b/pr/4199/docs/iroh_dns/dns/struct.TxtRecordData.html index 3789f6d95b..fb698f0ae8 100644 --- a/pr/4199/docs/iroh_dns/dns/struct.TxtRecordData.html +++ b/pr/4199/docs/iroh_dns/dns/struct.TxtRecordData.html @@ -1,11 +1,11 @@ -TxtRecordData in iroh_dns::dns - Rust

TxtRecordData

Struct TxtRecordData 

Source
pub struct TxtRecordData(/* private fields */);
Expand description

Record data for a TXT record.

+TxtRecordData in iroh_dns::dns - Rust

TxtRecordData

Struct TxtRecordData 

Source
pub struct TxtRecordData(/* private fields */);
Expand description

Record data for a TXT record.

This contains a list of character strings, as defined in RFC 1035 Section 3.3.14.

TxtRecordData implements fmt::Display, so you can call ToString::to_string to convert the record data into a string. This will parse each character string with String::from_utf8_lossy and then concatenate all strings without a separator.

If you want to process each character string individually, use Self::iter.

-

Implementations§

Source§

impl TxtRecordData

Source

pub fn iter(&self) -> impl Iterator<Item = &[u8]>

Returns an iterator over the character strings contained in this TXT record.

-

Trait Implementations§

Source§

impl Clone for TxtRecordData

Source§

fn clone(&self) -> TxtRecordData

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TxtRecordData

Source§

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

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

impl Display for TxtRecordData

Source§

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

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

impl From<Vec<Box<[u8]>>> for TxtRecordData

Source§

fn from(value: Vec<Box<[u8]>>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Box<[u8]>> for TxtRecordData

Source§

fn from_iter<T: IntoIterator<Item = Box<[u8]>>>(iter: T) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where +

Implementations§

Source§

impl TxtRecordData

Source

pub fn iter(&self) -> impl Iterator<Item = &[u8]>

Returns an iterator over the character strings contained in this TXT record.

+

Trait Implementations§

Source§

impl Clone for TxtRecordData

Source§

fn clone(&self) -> TxtRecordData

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TxtRecordData

Source§

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

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

impl Display for TxtRecordData

Source§

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

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

impl From<Vec<Box<[u8]>>> for TxtRecordData

Source§

fn from(value: Vec<Box<[u8]>>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Box<[u8]>> for TxtRecordData

Source§

fn from_iter<T: IntoIterator<Item = Box<[u8]>>>(iter: T) -> Self

Creates a value from an iterator. 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 diff --git a/pr/4199/docs/src/iroh_dns/dns.rs.html b/pr/4199/docs/src/iroh_dns/dns.rs.html index 0eec2d2ddc..36cb357b4e 100644 --- a/pr/4199/docs/src/iroh_dns/dns.rs.html +++ b/pr/4199/docs/src/iroh_dns/dns.rs.html @@ -1,4 +1,4 @@ -dns.rs - source

iroh_dns/
dns.rs

1//! Configurable DNS resolver.
+dns.rs - source

iroh_dns/
dns.rs

1//! Configurable DNS resolver.
 2//!
 3//! The main export is the [`DnsResolver`] struct. It provides methods to resolve domain names
 4//! to IPv4 and IPv6 addresses, and to look up TXT records. Additionally, the resolver features
@@ -187,829 +187,762 @@
 187    /// `install_android_jni_context` (exported at the crate root,
 188    /// Android only).
 189    ///
-190    /// The same public fallback (Cloudflare and Google over UDP and
-191    /// TCP, plus DNS-over-HTTPS when the `tls-ring` or
-192    /// `tls-aws-lc-rs` feature is enabled) is used on any platform
-193    /// where the system reader returns nothing.
-194    pub fn with_system_defaults(mut self) -> Self {
-195        self.use_system_defaults = true;
-196        self
-197    }
-198
-199    /// Adds a single nameserver.
-200    pub fn with_nameserver(mut self, addr: SocketAddr, protocol: DnsProtocol) -> Self {
-201        self.nameservers.push((addr, protocol));
-202        self
-203    }
-204
-205    /// Adds a list of nameservers.
-206    pub fn with_nameservers(
-207        mut self,
-208        nameservers: impl IntoIterator<Item = (SocketAddr, DnsProtocol)>,
-209    ) -> Self {
-210        self.nameservers.extend(nameservers);
-211        self
-212    }
-213
-214    /// Sets a custom TLS verification config.
-215    ///
-216    /// This is only used with DNS-over-TLS and DNS-over-HTTPS, and requires
-217    /// enabling either the ring or aws-lc-rs feature.
-218    #[cfg(with_crypto_provider)]
-219    pub fn tls_client_config(mut self, client_config: rustls::ClientConfig) -> Self {
-220        self.tls_client_config = Some(client_config);
-221        self
-222    }
-223
-224    /// Builds the DNS resolver.
-225    pub fn build(self) -> DnsResolver {
-226        DnsResolver::custom(HickoryResolver::new(self))
-227    }
-228}
-229
-230/// The DNS resolver used throughout `iroh`.
-231///
-232/// By default, we use a built-in resolver that reads the system's DNS configuration.
-233/// The nameservers can be customized by constructing the resolver with [`Self::builder`].
-234/// Alternatively, you can create a fully custom DNS resolver by implementing the [`Resolver`]
-235/// trait and creating the resolver with [`Self::custom`].
-236#[derive(Debug, Clone)]
-237pub struct DnsResolver {
-238    inner: Arc<Inner>,
-239}
-240
-241/// Shared state behind [`DnsResolver`].
-242#[derive(Debug)]
-243struct Inner {
-244    /// Wakes in-flight [`Self::op`] calls when the resolver is swapped.
-245    notify_reset: Notify,
-246    resolver: ArcSwap<Box<dyn Resolver>>,
-247}
-248
-249impl Inner {
-250    fn new(inner: Box<dyn Resolver>) -> Self {
-251        Self {
-252            notify_reset: Notify::new(),
-253            resolver: ArcSwap::from_pointee(inner),
-254        }
-255    }
-256
-257    /// Atomically swaps the resolver and wakes in-flight [`Self::op`] calls.
-258    ///
-259    /// The swap happens before the wake. An op that observes or misses the wake is
-260    /// then guaranteed to load the new resolver. Non-blocking.
-261    ///
-262    /// Under contention only the first concurrent caller's swap lands; the others
-263    /// drop their freshly-built resolver. The winner's notification is enough since
-264    /// every in-flight op will pick up the new resolver on its next iteration.
-265    fn reset(&self) {
-266        let current = self.resolver.load();
-267        let new = Arc::new(current.reset());
-268        let prev = self.resolver.compare_and_swap(&current, new);
-269        if Arc::ptr_eq(&current, &prev) {
-270            self.notify_reset.notify_waiters();
-271        }
-272    }
-273
-274    fn clear_cache(&self) {
-275        self.resolver.load().clear_cache();
-276    }
-277
-278    /// Runs `f(resolver)` with a timeout, restarting against the new resolver if
-279    /// [`Self::reset`] fires.
-280    ///
-281    /// Three things race in `biased` order: the lookup completes (returned even if a
-282    /// reset happened concurrently, since a successful result is still valid), a reset
-283    /// is observed (drop the in-flight future and re-run `f`), or the timeout elapses.
-284    ///
-285    /// `timeout` is per-attempt. Each retry starts a fresh sleep, so the wall-clock
-286    /// total can exceed it if many resets fire. This is intentional: a fresh attempt
-287    /// against a just-changed network should not inherit the previous attempt's
-288    /// remaining budget.
-289    ///
-290    /// `f` may be invoked more than once and so must be `Fn`. Captured state must be
-291    /// reusable across calls, typically by cloning inside the closure body.
-292    ///
-293    /// `notified` is enabled before `load_full`. Combined with [`Self::reset`]'s
-294    /// swap-then-notify ordering: a wake missed before `enable()` had already been
-295    /// preceded by the swap, so the following `load_full` returns the new resolver.
-296    async fn op<F, Fut, R, E>(&self, timeout: Duration, f: F) -> Result<R, DnsError>
-297    where
-298        E: 'static + Send + Into<DnsError>,
-299        R: 'static + Send,
-300        F: 'static + Send + Fn(Arc<Box<dyn Resolver>>) -> Fut,
-301        Fut: 'static + Send + Future<Output = Result<R, E>>,
-302    {
-303        loop {
-304            let notified = self.notify_reset.notified();
-305            tokio::pin!(notified);
-306            notified.as_mut().enable();
-307
-308            let timeout = n0_future::time::sleep(timeout);
-309            tokio::pin!(timeout);
-310
-311            let resolver = self.resolver.load_full();
-312            let fut = f(resolver);
-313            tokio::pin!(fut);
-314
-315            tokio::select! {
-316                biased;
-317                res = fut => return res.map_err(Into::into),
-318                _ = notified => continue,
-319                _ = timeout => return Err(e!(DnsError::Timeout)),
-320            }
-321        }
-322    }
-323}
-324
-325impl DnsResolver {
-326    /// Creates a new resolver with sensible cross-platform defaults.
-327    ///
-328    /// Equivalent to `Builder::default().with_system_defaults().build()`.
-329    /// See [`Builder::with_system_defaults`] for the per-platform
-330    /// behavior, including the public DNS fallback that takes over
-331    /// when the system reader returns nothing.
-332    ///
-333    /// The fallback can route queries through public providers
-334    /// (Cloudflare and Google). To keep DNS traffic on caller-supplied
-335    /// servers only, build the resolver through [`Self::builder`]
-336    /// with explicit nameservers.
-337    pub fn new() -> Self {
-338        Builder::default().with_system_defaults().build()
-339    }
-340
-341    /// Creates a new DNS resolver configured with a single UDP DNS nameserver.
-342    pub fn with_nameserver(nameserver: SocketAddr) -> Self {
-343        Builder::default()
-344            .with_nameserver(nameserver, DnsProtocol::Udp)
-345            .build()
-346    }
-347
-348    /// Creates a builder to construct a DNS resolver with custom options.
-349    pub fn builder() -> Builder {
-350        Builder::default()
-351    }
-352
-353    /// Creates a new [`DnsResolver`] from a struct that implements [`Resolver`].
-354    ///
-355    /// If you need more customization for DNS resolving than the [`Builder`] allows, you can
-356    /// implement the [`Resolver`] trait on a struct and implement DNS resolution
-357    /// however you see fit.
-358    pub fn custom(resolver: impl Resolver) -> Self {
-359        Self {
-360            inner: Arc::new(Inner::new(Box::new(resolver))),
-361        }
-362    }
-363
-364    /// Removes all entries from the cache.
-365    pub fn clear_cache(&self) {
-366        self.inner.clear_cache();
-367    }
-368
-369    /// Replaces the inner resolver with a freshly-built one.
-370    ///
-371    /// Call this on a major host network change to pick up the new system DNS
-372    /// configuration and rebind sockets. The swap is atomic and non-blocking;
-373    /// in-flight lookups retry against the new resolver. See [`Resolver::reset`].
-374    pub fn reset(&self) {
-375        self.inner.reset();
-376    }
-377
-378    /// Looks up a TXT record.
-379    pub async fn lookup_txt<T: ToString>(
-380        &self,
-381        host: T,
-382        timeout: Duration,
-383    ) -> Result<impl Iterator<Item = TxtRecordData>, DnsError> {
-384        let host = host.to_string();
-385        let res = self
-386            .inner
-387            .op(timeout, move |resolver| resolver.lookup_txt(host.clone()))
-388            .await?;
-389        Ok(res)
-390    }
-391
-392    /// Performs an IPv4 lookup with a timeout.
-393    pub async fn lookup_ipv4<T: ToString>(
-394        &self,
-395        host: T,
-396        timeout: Duration,
-397    ) -> Result<impl Iterator<Item = IpAddr> + use<T>, DnsError> {
-398        let host = host.to_string();
-399        let addrs = self
-400            .inner
-401            .op(timeout, move |resolver| resolver.lookup_ipv4(host.clone()))
-402            .await?;
-403        Ok(addrs.into_iter().map(IpAddr::V4))
-404    }
-405
-406    /// Performs an IPv6 lookup with a timeout.
-407    pub async fn lookup_ipv6<T: ToString>(
-408        &self,
-409        host: T,
-410        timeout: Duration,
-411    ) -> Result<impl Iterator<Item = IpAddr> + use<T>, DnsError> {
-412        let host = host.to_string();
-413        let addrs = self
-414            .inner
-415            .op(timeout, move |resolver| resolver.lookup_ipv6(host.clone()))
-416            .await?;
-417        Ok(addrs.into_iter().map(IpAddr::V6))
-418    }
-419
-420    /// Resolves IPv4 and IPv6 in parallel with a timeout.
-421    ///
-422    /// `LookupIpStrategy::Ipv4AndIpv6` will wait for ipv6 resolution timeout, even if it is
-423    /// not usable on the stack, so we manually query both lookups concurrently and time them out
-424    /// individually.
-425    pub async fn lookup_ipv4_ipv6<T: ToString>(
-426        &self,
-427        host: T,
-428        timeout: Duration,
-429    ) -> Result<impl Iterator<Item = IpAddr> + use<T>, DnsError> {
-430        let host = host.to_string();
-431        let res = tokio::join!(
-432            self.lookup_ipv4(host.clone(), timeout),
-433            self.lookup_ipv6(host, timeout)
-434        );
-435
-436        match res {
-437            (Ok(ipv4), Ok(ipv6)) => Ok(LookupIter::Both(ipv4.chain(ipv6))),
-438            (Ok(ipv4), Err(_)) => Ok(LookupIter::Ipv4(ipv4)),
-439            (Err(_), Ok(ipv6)) => Ok(LookupIter::Ipv6(ipv6)),
-440            (Err(ipv4_err), Err(ipv6_err)) => Err(e!(DnsError::ResolveBoth {
-441                ipv4: Box::new(ipv4_err),
-442                ipv6: Box::new(ipv6_err)
-443            })),
-444        }
-445    }
-446
-447    /// Resolves a hostname from a URL to an IP address.
-448    pub async fn resolve_host(
-449        &self,
-450        url: &Url,
-451        prefer_ipv6: bool,
-452        timeout: Duration,
-453    ) -> Result<IpAddr, DnsError> {
-454        let host = url.host().ok_or_else(|| e!(DnsError::MissingHost))?;
-455        match host {
-456            url::Host::Domain(domain) => {
-457                // Need to do a DNS lookup
-458                let lookup = tokio::join!(
-459                    self.lookup_ipv4(domain, timeout),
-460                    self.lookup_ipv6(domain, timeout)
-461                );
-462                let (v4, v6) = match lookup {
-463                    (Err(ipv4_err), Err(ipv6_err)) => {
-464                        return Err(e!(DnsError::ResolveBoth {
-465                            ipv4: Box::new(ipv4_err),
-466                            ipv6: Box::new(ipv6_err)
-467                        }));
-468                    }
-469                    (Err(_), Ok(mut v6)) => (None, v6.next()),
-470                    (Ok(mut v4), Err(_)) => (v4.next(), None),
-471                    (Ok(mut v4), Ok(mut v6)) => (v4.next(), v6.next()),
-472                };
-473                if prefer_ipv6 {
-474                    v6.or(v4).ok_or_else(|| e!(DnsError::NoResponse))
-475                } else {
-476                    v4.or(v6).ok_or_else(|| e!(DnsError::NoResponse))
-477                }
-478            }
-479            url::Host::Ipv4(ip) => Ok(IpAddr::V4(ip)),
-480            url::Host::Ipv6(ip) => Ok(IpAddr::V6(ip)),
-481        }
-482    }
-483
-484    /// Performs an IPv4 lookup with a timeout in a staggered fashion.
-485    ///
-486    /// From the moment this function is called, each lookup is scheduled after the delays in
-487    /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls
-488    /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The
-489    /// result of the first successful call is returned, or a summary of all errors otherwise.
-490    pub async fn lookup_ipv4_staggered(
-491        &self,
-492        host: impl ToString,
-493        timeout: Duration,
-494        delays_ms: &[u64],
-495    ) -> Result<impl Iterator<Item = IpAddr>, StaggeredError<DnsError>> {
-496        let host = host.to_string();
-497        let f = || self.lookup_ipv4(host.clone(), timeout);
-498        stagger_call(f, delays_ms).await
-499    }
-500
-501    /// Performs an IPv6 lookup with a timeout in a staggered fashion.
-502    ///
-503    /// From the moment this function is called, each lookup is scheduled after the delays in
-504    /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls
-505    /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The
-506    /// result of the first successful call is returned, or a summary of all errors otherwise.
-507    pub async fn lookup_ipv6_staggered(
-508        &self,
-509        host: impl ToString,
-510        timeout: Duration,
-511        delays_ms: &[u64],
-512    ) -> Result<impl Iterator<Item = IpAddr>, StaggeredError<DnsError>> {
-513        let host = host.to_string();
-514        let f = || self.lookup_ipv6(host.clone(), timeout);
-515        stagger_call(f, delays_ms).await
-516    }
-517
-518    /// Races an IPv4 and IPv6 lookup with a timeout in a staggered fashion.
-519    ///
-520    /// From the moment this function is called, each lookup is scheduled after the delays in
-521    /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls
-522    /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied as stated in
-523    /// [`Self::lookup_ipv4_ipv6`]. The result of the first successful call is returned, or a
-524    /// summary of all errors otherwise.
-525    pub async fn lookup_ipv4_ipv6_staggered(
-526        &self,
-527        host: impl ToString,
-528        timeout: Duration,
-529        delays_ms: &[u64],
-530    ) -> Result<impl Iterator<Item = IpAddr>, StaggeredError<DnsError>> {
-531        let host = host.to_string();
-532        let f = || self.lookup_ipv4_ipv6(host.clone(), timeout);
-533        stagger_call(f, delays_ms).await
-534    }
-535
-536    /// Looks up endpoint info by [`EndpointId`] and origin domain name.
-537    ///
-538    /// To lookup endpoints that published their endpoint info to the DNS servers run by n0,
-539    /// pass [`N0_DNS_ENDPOINT_ORIGIN_PROD`] as `origin`.
-540    pub async fn lookup_endpoint_by_id(
-541        &self,
-542        endpoint_id: &EndpointId,
-543        origin: &str,
-544    ) -> Result<EndpointInfo, LookupError> {
-545        let name = format!("_iroh.{}.{}", endpoint_id.to_z32(), origin);
-546        let lookup = self.lookup_txt(name.clone(), DNS_TIMEOUT).await?;
-547        let info = EndpointInfo::from_txt_lookup(name, lookup)?;
-548        Ok(info)
-549    }
-550
-551    /// Looks up endpoint info by DNS name.
-552    pub async fn lookup_endpoint_by_domain_name(
-553        &self,
-554        name: &str,
-555    ) -> Result<EndpointInfo, LookupError> {
-556        let name = if name.starts_with("_iroh.") {
-557            name.to_string()
-558        } else {
-559            format!("_iroh.{name}")
-560        };
-561        let lookup = self.lookup_txt(name.clone(), DNS_TIMEOUT).await?;
-562        let info = EndpointInfo::from_txt_lookup(name, lookup)?;
-563        Ok(info)
-564    }
-565
-566    /// Looks up endpoint info by DNS name in a staggered fashion.
-567    ///
-568    /// From the moment this function is called, each lookup is scheduled after the delays in
-569    /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls
-570    /// at T+0ms, T+200ms and T+300ms. The result of the first successful call is returned, or a
-571    /// summary of all errors otherwise.
-572    pub async fn lookup_endpoint_by_domain_name_staggered(
-573        &self,
-574        name: &str,
-575        delays_ms: &[u64],
-576    ) -> Result<EndpointInfo, StaggeredError<LookupError>> {
-577        let f = || self.lookup_endpoint_by_domain_name(name);
-578        stagger_call(f, delays_ms).await
-579    }
-580
-581    /// Looks up endpoint info by [`EndpointId`] and origin domain name.
-582    ///
-583    /// From the moment this function is called, each lookup is scheduled after the delays in
-584    /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls
-585    /// at T+0ms, T+200ms and T+300ms. The result of the first successful call is returned, or a
-586    /// summary of all errors otherwise.
-587    pub async fn lookup_endpoint_by_id_staggered(
-588        &self,
-589        endpoint_id: &EndpointId,
-590        origin: &str,
-591        delays_ms: &[u64],
-592    ) -> Result<EndpointInfo, StaggeredError<LookupError>> {
-593        let f = || self.lookup_endpoint_by_id(endpoint_id, origin);
-594        stagger_call(f, delays_ms).await
-595    }
-596}
-597
-598impl Default for DnsResolver {
-599    fn default() -> Self {
-600        Self::new()
-601    }
-602}
-603
-604#[derive(Debug)]
-605struct HickoryResolver {
-606    resolver: TokioResolver,
-607    builder: Builder,
-608}
-609
-610impl HickoryResolver {
-611    fn new(builder: Builder) -> Self {
-612        let resolver = Self::build_resolver(&builder);
-613        Self { resolver, builder }
-614    }
-615
-616    fn build_resolver(builder: &Builder) -> TokioResolver {
-617        let (mut config, mut options) = if builder.use_system_defaults {
-618            match crate::system_config::read_system_conf() {
-619                Ok((config, options)) => (config, options),
-620                Err(error) => {
-621                    debug!(
-622                        %error,
-623                        "Falling back to public DNS resolvers: \
-624                         system DNS unavailable.",
-625                    );
-626                    (public_fallback_config(), ResolverOpts::default())
-627                }
-628            }
-629        } else {
-630            (ResolverConfig::default(), ResolverOpts::default())
-631        };
-632
-633        for (addr, proto) in builder.nameservers.iter() {
-634            let mut transport = proto.to_hickory(addr.ip());
-635            transport.port = addr.port();
-636            let nameserver =
-637                hickory_resolver::config::NameServerConfig::new(addr.ip(), false, vec![transport]);
-638
-639            config.add_name_server(nameserver);
-640        }
-641
-642        // see [`DnsResolver::lookup_ipv4_ipv6`] for info on why we avoid `LookupIpStrategy::Ipv4AndIpv6`
-643        options.ip_strategy = hickory_resolver::config::LookupIpStrategy::Ipv4thenIpv6;
-644        options.negative_max_ttl = Some(Duration::ZERO);
-645
-646        let mut hickory_builder =
-647            TokioResolver::builder_with_config(config, TokioRuntimeProvider::default());
-648        *hickory_builder.options_mut() = options;
-649
-650        #[cfg(with_crypto_provider)]
-651        if let Some(client_config) = builder.tls_client_config.clone() {
-652            hickory_builder = hickory_builder.with_tls_config(client_config);
-653        }
-654
-655        hickory_builder.build().expect("config works")
-656    }
-657}
-658
-659/// Returns the public DNS fallback used when the system reader is
-660/// unavailable.
-661///
-662/// Lists Cloudflare and Google over UDP and TCP in that order: both
-663/// providers are anycasted on disjoint networks, so a single
-664/// provider outage still leaves a working resolver. With a TLS
-665/// feature enabled the same providers are appended again over DoH,
-666/// which keeps the resolver functional on networks that filter
-667/// plain UDP/53.
-668fn public_fallback_config() -> ResolverConfig {
-669    use hickory_resolver::config::{CLOUDFLARE, GOOGLE};
-670
-671    let mut config = ResolverConfig::default();
-672    for ns in CLOUDFLARE.udp_and_tcp() {
-673        config.add_name_server(ns);
-674    }
-675    for ns in GOOGLE.udp_and_tcp() {
-676        config.add_name_server(ns);
-677    }
-678    #[cfg(with_crypto_provider)]
-679    {
-680        for ns in CLOUDFLARE.https() {
-681            config.add_name_server(ns);
-682        }
-683        for ns in GOOGLE.https() {
-684            config.add_name_server(ns);
-685        }
-686    }
-687    config
-688}
-689
-690impl Resolver for HickoryResolver {
-691    fn lookup_ipv4(&self, host: String) -> BoxFuture<Result<BoxIter<Ipv4Addr>, DnsError>> {
-692        let resolver = self.resolver.clone();
-693        Box::pin(async move {
-694            let lookup = resolver.ipv4_lookup(host).await.anyerr()?;
-695            let iter: BoxIter<Ipv4Addr> =
-696                Box::new(lookup.answers().to_vec().into_iter().filter_map(|record| {
-697                    match &record.data {
-698                        RData::A(addr) => Some(addr.0),
-699                        _ => None,
-700                    }
-701                }));
-702            Ok(iter)
-703        })
-704    }
-705
-706    fn lookup_ipv6(&self, host: String) -> BoxFuture<Result<BoxIter<Ipv6Addr>, DnsError>> {
-707        let resolver = self.resolver.clone();
-708        Box::pin(async move {
-709            let lookup = resolver.ipv6_lookup(host).await.anyerr()?;
-710            let iter: BoxIter<Ipv6Addr> =
-711                Box::new(lookup.answers().to_vec().into_iter().filter_map(|record| {
-712                    match &record.data {
-713                        RData::AAAA(addr) => Some(addr.0),
-714                        _ => None,
-715                    }
-716                }));
-717            Ok(iter)
+190    /// The same public fallback (Google over UDP and TCP) is used on
+191    /// any platform where the system reader returns nothing.
+192    pub fn with_system_defaults(mut self) -> Self {
+193        self.use_system_defaults = true;
+194        self
+195    }
+196
+197    /// Adds a single nameserver.
+198    pub fn with_nameserver(mut self, addr: SocketAddr, protocol: DnsProtocol) -> Self {
+199        self.nameservers.push((addr, protocol));
+200        self
+201    }
+202
+203    /// Adds a list of nameservers.
+204    pub fn with_nameservers(
+205        mut self,
+206        nameservers: impl IntoIterator<Item = (SocketAddr, DnsProtocol)>,
+207    ) -> Self {
+208        self.nameservers.extend(nameservers);
+209        self
+210    }
+211
+212    /// Sets a custom TLS verification config.
+213    ///
+214    /// This is only used with DNS-over-TLS and DNS-over-HTTPS, and requires
+215    /// enabling either the ring or aws-lc-rs feature.
+216    #[cfg(with_crypto_provider)]
+217    pub fn tls_client_config(mut self, client_config: rustls::ClientConfig) -> Self {
+218        self.tls_client_config = Some(client_config);
+219        self
+220    }
+221
+222    /// Builds the DNS resolver.
+223    pub fn build(self) -> DnsResolver {
+224        DnsResolver::custom(HickoryResolver::new(self))
+225    }
+226}
+227
+228/// The DNS resolver used throughout `iroh`.
+229///
+230/// By default, we use a built-in resolver that reads the system's DNS configuration.
+231/// The nameservers can be customized by constructing the resolver with [`Self::builder`].
+232/// Alternatively, you can create a fully custom DNS resolver by implementing the [`Resolver`]
+233/// trait and creating the resolver with [`Self::custom`].
+234#[derive(Debug, Clone)]
+235pub struct DnsResolver {
+236    inner: Arc<Inner>,
+237}
+238
+239/// Shared state behind [`DnsResolver`].
+240#[derive(Debug)]
+241struct Inner {
+242    /// Wakes in-flight [`Self::op`] calls when the resolver is swapped.
+243    notify_reset: Notify,
+244    resolver: ArcSwap<Box<dyn Resolver>>,
+245}
+246
+247impl Inner {
+248    fn new(inner: Box<dyn Resolver>) -> Self {
+249        Self {
+250            notify_reset: Notify::new(),
+251            resolver: ArcSwap::from_pointee(inner),
+252        }
+253    }
+254
+255    /// Atomically swaps the resolver and wakes in-flight [`Self::op`] calls.
+256    ///
+257    /// The swap happens before the wake. An op that observes or misses the wake is
+258    /// then guaranteed to load the new resolver. Non-blocking.
+259    ///
+260    /// Under contention only the first concurrent caller's swap lands; the others
+261    /// drop their freshly-built resolver. The winner's notification is enough since
+262    /// every in-flight op will pick up the new resolver on its next iteration.
+263    fn reset(&self) {
+264        let current = self.resolver.load();
+265        let new = Arc::new(current.reset());
+266        let prev = self.resolver.compare_and_swap(&current, new);
+267        if Arc::ptr_eq(&current, &prev) {
+268            self.notify_reset.notify_waiters();
+269        }
+270    }
+271
+272    fn clear_cache(&self) {
+273        self.resolver.load().clear_cache();
+274    }
+275
+276    /// Runs `f(resolver)` with a timeout, restarting against the new resolver if
+277    /// [`Self::reset`] fires.
+278    ///
+279    /// Three things race in `biased` order: the lookup completes (returned even if a
+280    /// reset happened concurrently, since a successful result is still valid), a reset
+281    /// is observed (drop the in-flight future and re-run `f`), or the timeout elapses.
+282    ///
+283    /// `timeout` is per-attempt. Each retry starts a fresh sleep, so the wall-clock
+284    /// total can exceed it if many resets fire. This is intentional: a fresh attempt
+285    /// against a just-changed network should not inherit the previous attempt's
+286    /// remaining budget.
+287    ///
+288    /// `f` may be invoked more than once and so must be `Fn`. Captured state must be
+289    /// reusable across calls, typically by cloning inside the closure body.
+290    ///
+291    /// `notified` is enabled before `load_full`. Combined with [`Self::reset`]'s
+292    /// swap-then-notify ordering: a wake missed before `enable()` had already been
+293    /// preceded by the swap, so the following `load_full` returns the new resolver.
+294    async fn op<F, Fut, R, E>(&self, timeout: Duration, f: F) -> Result<R, DnsError>
+295    where
+296        E: 'static + Send + Into<DnsError>,
+297        R: 'static + Send,
+298        F: 'static + Send + Fn(Arc<Box<dyn Resolver>>) -> Fut,
+299        Fut: 'static + Send + Future<Output = Result<R, E>>,
+300    {
+301        loop {
+302            let notified = self.notify_reset.notified();
+303            tokio::pin!(notified);
+304            notified.as_mut().enable();
+305
+306            let timeout = n0_future::time::sleep(timeout);
+307            tokio::pin!(timeout);
+308
+309            let resolver = self.resolver.load_full();
+310            let fut = f(resolver);
+311            tokio::pin!(fut);
+312
+313            tokio::select! {
+314                biased;
+315                res = fut => return res.map_err(Into::into),
+316                _ = notified => continue,
+317                _ = timeout => return Err(e!(DnsError::Timeout)),
+318            }
+319        }
+320    }
+321}
+322
+323impl DnsResolver {
+324    /// Creates a new resolver with sensible cross-platform defaults.
+325    ///
+326    /// Equivalent to `Builder::default().with_system_defaults().build()`.
+327    /// See [`Builder::with_system_defaults`] for the per-platform
+328    /// behavior, including the public DNS fallback that takes over
+329    /// when the system reader returns nothing.
+330    ///
+331    /// The fallback routes queries through Google's public DNS. To
+332    /// keep DNS traffic on caller-supplied servers only, build the
+333    /// resolver through [`Self::builder`] with explicit nameservers.
+334    pub fn new() -> Self {
+335        Builder::default().with_system_defaults().build()
+336    }
+337
+338    /// Creates a new DNS resolver configured with a single UDP DNS nameserver.
+339    pub fn with_nameserver(nameserver: SocketAddr) -> Self {
+340        Builder::default()
+341            .with_nameserver(nameserver, DnsProtocol::Udp)
+342            .build()
+343    }
+344
+345    /// Creates a builder to construct a DNS resolver with custom options.
+346    pub fn builder() -> Builder {
+347        Builder::default()
+348    }
+349
+350    /// Creates a new [`DnsResolver`] from a struct that implements [`Resolver`].
+351    ///
+352    /// If you need more customization for DNS resolving than the [`Builder`] allows, you can
+353    /// implement the [`Resolver`] trait on a struct and implement DNS resolution
+354    /// however you see fit.
+355    pub fn custom(resolver: impl Resolver) -> Self {
+356        Self {
+357            inner: Arc::new(Inner::new(Box::new(resolver))),
+358        }
+359    }
+360
+361    /// Removes all entries from the cache.
+362    pub fn clear_cache(&self) {
+363        self.inner.clear_cache();
+364    }
+365
+366    /// Replaces the inner resolver with a freshly-built one.
+367    ///
+368    /// Call this on a major host network change to pick up the new system DNS
+369    /// configuration and rebind sockets. The swap is atomic and non-blocking;
+370    /// in-flight lookups retry against the new resolver. See [`Resolver::reset`].
+371    pub fn reset(&self) {
+372        self.inner.reset();
+373    }
+374
+375    /// Looks up a TXT record.
+376    pub async fn lookup_txt<T: ToString>(
+377        &self,
+378        host: T,
+379        timeout: Duration,
+380    ) -> Result<impl Iterator<Item = TxtRecordData>, DnsError> {
+381        let host = host.to_string();
+382        let res = self
+383            .inner
+384            .op(timeout, move |resolver| resolver.lookup_txt(host.clone()))
+385            .await?;
+386        Ok(res)
+387    }
+388
+389    /// Performs an IPv4 lookup with a timeout.
+390    pub async fn lookup_ipv4<T: ToString>(
+391        &self,
+392        host: T,
+393        timeout: Duration,
+394    ) -> Result<impl Iterator<Item = IpAddr> + use<T>, DnsError> {
+395        let host = host.to_string();
+396        let addrs = self
+397            .inner
+398            .op(timeout, move |resolver| resolver.lookup_ipv4(host.clone()))
+399            .await?;
+400        Ok(addrs.into_iter().map(IpAddr::V4))
+401    }
+402
+403    /// Performs an IPv6 lookup with a timeout.
+404    pub async fn lookup_ipv6<T: ToString>(
+405        &self,
+406        host: T,
+407        timeout: Duration,
+408    ) -> Result<impl Iterator<Item = IpAddr> + use<T>, DnsError> {
+409        let host = host.to_string();
+410        let addrs = self
+411            .inner
+412            .op(timeout, move |resolver| resolver.lookup_ipv6(host.clone()))
+413            .await?;
+414        Ok(addrs.into_iter().map(IpAddr::V6))
+415    }
+416
+417    /// Resolves IPv4 and IPv6 in parallel with a timeout.
+418    ///
+419    /// `LookupIpStrategy::Ipv4AndIpv6` will wait for ipv6 resolution timeout, even if it is
+420    /// not usable on the stack, so we manually query both lookups concurrently and time them out
+421    /// individually.
+422    pub async fn lookup_ipv4_ipv6<T: ToString>(
+423        &self,
+424        host: T,
+425        timeout: Duration,
+426    ) -> Result<impl Iterator<Item = IpAddr> + use<T>, DnsError> {
+427        let host = host.to_string();
+428        let res = tokio::join!(
+429            self.lookup_ipv4(host.clone(), timeout),
+430            self.lookup_ipv6(host, timeout)
+431        );
+432
+433        match res {
+434            (Ok(ipv4), Ok(ipv6)) => Ok(LookupIter::Both(ipv4.chain(ipv6))),
+435            (Ok(ipv4), Err(_)) => Ok(LookupIter::Ipv4(ipv4)),
+436            (Err(_), Ok(ipv6)) => Ok(LookupIter::Ipv6(ipv6)),
+437            (Err(ipv4_err), Err(ipv6_err)) => Err(e!(DnsError::ResolveBoth {
+438                ipv4: Box::new(ipv4_err),
+439                ipv6: Box::new(ipv6_err)
+440            })),
+441        }
+442    }
+443
+444    /// Resolves a hostname from a URL to an IP address.
+445    pub async fn resolve_host(
+446        &self,
+447        url: &Url,
+448        prefer_ipv6: bool,
+449        timeout: Duration,
+450    ) -> Result<IpAddr, DnsError> {
+451        let host = url.host().ok_or_else(|| e!(DnsError::MissingHost))?;
+452        match host {
+453            url::Host::Domain(domain) => {
+454                // Need to do a DNS lookup
+455                let lookup = tokio::join!(
+456                    self.lookup_ipv4(domain, timeout),
+457                    self.lookup_ipv6(domain, timeout)
+458                );
+459                let (v4, v6) = match lookup {
+460                    (Err(ipv4_err), Err(ipv6_err)) => {
+461                        return Err(e!(DnsError::ResolveBoth {
+462                            ipv4: Box::new(ipv4_err),
+463                            ipv6: Box::new(ipv6_err)
+464                        }));
+465                    }
+466                    (Err(_), Ok(mut v6)) => (None, v6.next()),
+467                    (Ok(mut v4), Err(_)) => (v4.next(), None),
+468                    (Ok(mut v4), Ok(mut v6)) => (v4.next(), v6.next()),
+469                };
+470                if prefer_ipv6 {
+471                    v6.or(v4).ok_or_else(|| e!(DnsError::NoResponse))
+472                } else {
+473                    v4.or(v6).ok_or_else(|| e!(DnsError::NoResponse))
+474                }
+475            }
+476            url::Host::Ipv4(ip) => Ok(IpAddr::V4(ip)),
+477            url::Host::Ipv6(ip) => Ok(IpAddr::V6(ip)),
+478        }
+479    }
+480
+481    /// Performs an IPv4 lookup with a timeout in a staggered fashion.
+482    ///
+483    /// From the moment this function is called, each lookup is scheduled after the delays in
+484    /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls
+485    /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The
+486    /// result of the first successful call is returned, or a summary of all errors otherwise.
+487    pub async fn lookup_ipv4_staggered(
+488        &self,
+489        host: impl ToString,
+490        timeout: Duration,
+491        delays_ms: &[u64],
+492    ) -> Result<impl Iterator<Item = IpAddr>, StaggeredError<DnsError>> {
+493        let host = host.to_string();
+494        let f = || self.lookup_ipv4(host.clone(), timeout);
+495        stagger_call(f, delays_ms).await
+496    }
+497
+498    /// Performs an IPv6 lookup with a timeout in a staggered fashion.
+499    ///
+500    /// From the moment this function is called, each lookup is scheduled after the delays in
+501    /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls
+502    /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied to each call individually. The
+503    /// result of the first successful call is returned, or a summary of all errors otherwise.
+504    pub async fn lookup_ipv6_staggered(
+505        &self,
+506        host: impl ToString,
+507        timeout: Duration,
+508        delays_ms: &[u64],
+509    ) -> Result<impl Iterator<Item = IpAddr>, StaggeredError<DnsError>> {
+510        let host = host.to_string();
+511        let f = || self.lookup_ipv6(host.clone(), timeout);
+512        stagger_call(f, delays_ms).await
+513    }
+514
+515    /// Races an IPv4 and IPv6 lookup with a timeout in a staggered fashion.
+516    ///
+517    /// From the moment this function is called, each lookup is scheduled after the delays in
+518    /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls
+519    /// at T+0ms, T+200ms and T+300ms. The `timeout` is applied as stated in
+520    /// [`Self::lookup_ipv4_ipv6`]. The result of the first successful call is returned, or a
+521    /// summary of all errors otherwise.
+522    pub async fn lookup_ipv4_ipv6_staggered(
+523        &self,
+524        host: impl ToString,
+525        timeout: Duration,
+526        delays_ms: &[u64],
+527    ) -> Result<impl Iterator<Item = IpAddr>, StaggeredError<DnsError>> {
+528        let host = host.to_string();
+529        let f = || self.lookup_ipv4_ipv6(host.clone(), timeout);
+530        stagger_call(f, delays_ms).await
+531    }
+532
+533    /// Looks up endpoint info by [`EndpointId`] and origin domain name.
+534    ///
+535    /// To lookup endpoints that published their endpoint info to the DNS servers run by n0,
+536    /// pass [`N0_DNS_ENDPOINT_ORIGIN_PROD`] as `origin`.
+537    pub async fn lookup_endpoint_by_id(
+538        &self,
+539        endpoint_id: &EndpointId,
+540        origin: &str,
+541    ) -> Result<EndpointInfo, LookupError> {
+542        let name = format!("_iroh.{}.{}", endpoint_id.to_z32(), origin);
+543        let lookup = self.lookup_txt(name.clone(), DNS_TIMEOUT).await?;
+544        let info = EndpointInfo::from_txt_lookup(name, lookup)?;
+545        Ok(info)
+546    }
+547
+548    /// Looks up endpoint info by DNS name.
+549    pub async fn lookup_endpoint_by_domain_name(
+550        &self,
+551        name: &str,
+552    ) -> Result<EndpointInfo, LookupError> {
+553        let name = if name.starts_with("_iroh.") {
+554            name.to_string()
+555        } else {
+556            format!("_iroh.{name}")
+557        };
+558        let lookup = self.lookup_txt(name.clone(), DNS_TIMEOUT).await?;
+559        let info = EndpointInfo::from_txt_lookup(name, lookup)?;
+560        Ok(info)
+561    }
+562
+563    /// Looks up endpoint info by DNS name in a staggered fashion.
+564    ///
+565    /// From the moment this function is called, each lookup is scheduled after the delays in
+566    /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls
+567    /// at T+0ms, T+200ms and T+300ms. The result of the first successful call is returned, or a
+568    /// summary of all errors otherwise.
+569    pub async fn lookup_endpoint_by_domain_name_staggered(
+570        &self,
+571        name: &str,
+572        delays_ms: &[u64],
+573    ) -> Result<EndpointInfo, StaggeredError<LookupError>> {
+574        let f = || self.lookup_endpoint_by_domain_name(name);
+575        stagger_call(f, delays_ms).await
+576    }
+577
+578    /// Looks up endpoint info by [`EndpointId`] and origin domain name.
+579    ///
+580    /// From the moment this function is called, each lookup is scheduled after the delays in
+581    /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls
+582    /// at T+0ms, T+200ms and T+300ms. The result of the first successful call is returned, or a
+583    /// summary of all errors otherwise.
+584    pub async fn lookup_endpoint_by_id_staggered(
+585        &self,
+586        endpoint_id: &EndpointId,
+587        origin: &str,
+588        delays_ms: &[u64],
+589    ) -> Result<EndpointInfo, StaggeredError<LookupError>> {
+590        let f = || self.lookup_endpoint_by_id(endpoint_id, origin);
+591        stagger_call(f, delays_ms).await
+592    }
+593}
+594
+595impl Default for DnsResolver {
+596    fn default() -> Self {
+597        Self::new()
+598    }
+599}
+600
+601#[derive(Debug)]
+602struct HickoryResolver {
+603    resolver: TokioResolver,
+604    builder: Builder,
+605}
+606
+607impl HickoryResolver {
+608    fn new(builder: Builder) -> Self {
+609        let resolver = Self::build_resolver(&builder);
+610        Self { resolver, builder }
+611    }
+612
+613    fn build_resolver(builder: &Builder) -> TokioResolver {
+614        let (mut config, mut options) = if builder.use_system_defaults {
+615            match crate::system_config::read_system_conf() {
+616                Ok((config, options)) => (config, options),
+617                Err(error) => {
+618                    debug!(
+619                        %error,
+620                        "Failed to read the system's DNS config, using fallback DNS servers."
+621                    );
+622                    (
+623                        ResolverConfig::udp_and_tcp(&hickory_resolver::config::GOOGLE),
+624                        ResolverOpts::default(),
+625                    )
+626                }
+627            }
+628        } else {
+629            (ResolverConfig::default(), ResolverOpts::default())
+630        };
+631
+632        for (addr, proto) in builder.nameservers.iter() {
+633            let mut transport = proto.to_hickory(addr.ip());
+634            transport.port = addr.port();
+635            let nameserver =
+636                hickory_resolver::config::NameServerConfig::new(addr.ip(), false, vec![transport]);
+637
+638            config.add_name_server(nameserver);
+639        }
+640
+641        // see [`DnsResolver::lookup_ipv4_ipv6`] for info on why we avoid `LookupIpStrategy::Ipv4AndIpv6`
+642        options.ip_strategy = hickory_resolver::config::LookupIpStrategy::Ipv4thenIpv6;
+643        options.negative_max_ttl = Some(Duration::ZERO);
+644
+645        let mut hickory_builder =
+646            TokioResolver::builder_with_config(config, TokioRuntimeProvider::default());
+647        *hickory_builder.options_mut() = options;
+648
+649        #[cfg(with_crypto_provider)]
+650        if let Some(client_config) = builder.tls_client_config.clone() {
+651            hickory_builder = hickory_builder.with_tls_config(client_config);
+652        }
+653
+654        hickory_builder.build().expect("config works")
+655    }
+656}
+657
+658impl Resolver for HickoryResolver {
+659    fn lookup_ipv4(&self, host: String) -> BoxFuture<Result<BoxIter<Ipv4Addr>, DnsError>> {
+660        let resolver = self.resolver.clone();
+661        Box::pin(async move {
+662            let lookup = resolver.ipv4_lookup(host).await.anyerr()?;
+663            let iter: BoxIter<Ipv4Addr> =
+664                Box::new(lookup.answers().to_vec().into_iter().filter_map(|record| {
+665                    match &record.data {
+666                        RData::A(addr) => Some(addr.0),
+667                        _ => None,
+668                    }
+669                }));
+670            Ok(iter)
+671        })
+672    }
+673
+674    fn lookup_ipv6(&self, host: String) -> BoxFuture<Result<BoxIter<Ipv6Addr>, DnsError>> {
+675        let resolver = self.resolver.clone();
+676        Box::pin(async move {
+677            let lookup = resolver.ipv6_lookup(host).await.anyerr()?;
+678            let iter: BoxIter<Ipv6Addr> =
+679                Box::new(lookup.answers().to_vec().into_iter().filter_map(|record| {
+680                    match &record.data {
+681                        RData::AAAA(addr) => Some(addr.0),
+682                        _ => None,
+683                    }
+684                }));
+685            Ok(iter)
+686        })
+687    }
+688
+689    fn lookup_txt(&self, host: String) -> BoxFuture<Result<BoxIter<TxtRecordData>, DnsError>> {
+690        let resolver = self.resolver.clone();
+691        Box::pin(async move {
+692            let lookup = resolver.txt_lookup(host).await.anyerr()?;
+693            let iter: BoxIter<TxtRecordData> =
+694                Box::new(lookup.answers().to_vec().into_iter().filter_map(|record| {
+695                    match &record.data {
+696                        RData::TXT(txt) => {
+697                            // I don't know a way of avoiding this deep copy, even if it's agonizing.
+698                            // The representation of `TxtRecrodData` and `hickory_proto::rr::rdata::TXT`
+699                            // is identical.
+700                            Some(TxtRecordData::from(txt.txt_data.to_vec()))
+701                        }
+702                        _ => None,
+703                    }
+704                }));
+705            Ok(iter)
+706        })
+707    }
+708
+709    fn clear_cache(&self) {
+710        self.resolver.clear_cache()
+711    }
+712
+713    fn reset(&self) -> Box<dyn Resolver> {
+714        let resolver = Self::build_resolver(&self.builder);
+715        Box::new(Self {
+716            resolver,
+717            builder: self.builder.clone(),
 718        })
 719    }
-720
-721    fn lookup_txt(&self, host: String) -> BoxFuture<Result<BoxIter<TxtRecordData>, DnsError>> {
-722        let resolver = self.resolver.clone();
-723        Box::pin(async move {
-724            let lookup = resolver.txt_lookup(host).await.anyerr()?;
-725            let iter: BoxIter<TxtRecordData> =
-726                Box::new(lookup.answers().to_vec().into_iter().filter_map(|record| {
-727                    match &record.data {
-728                        RData::TXT(txt) => {
-729                            // I don't know a way of avoiding this deep copy, even if it's agonizing.
-730                            // The representation of `TxtRecrodData` and `hickory_proto::rr::rdata::TXT`
-731                            // is identical.
-732                            Some(TxtRecordData::from(txt.txt_data.to_vec()))
-733                        }
-734                        _ => None,
-735                    }
-736                }));
-737            Ok(iter)
-738        })
-739    }
-740
-741    fn clear_cache(&self) {
-742        self.resolver.clear_cache()
-743    }
-744
-745    fn reset(&self) -> Box<dyn Resolver> {
-746        let resolver = Self::build_resolver(&self.builder);
-747        Box::new(Self {
-748            resolver,
-749            builder: self.builder.clone(),
-750        })
-751    }
-752}
-753
-754/// Record data for a TXT record.
-755///
-756/// This contains a list of character strings, as defined in [RFC 1035 Section 3.3.14].
-757///
-758/// [`TxtRecordData`] implements [`fmt::Display`], so you can call [`ToString::to_string`] to
-759/// convert the record data into a string. This will parse each character string with
-760/// [`String::from_utf8_lossy`] and then concatenate all strings without a separator.
-761///
-762/// If you want to process each character string individually, use [`Self::iter`].
-763///
-764/// [RFC 1035 Section 3.3.14]: https://datatracker.ietf.org/doc/html/rfc1035#section-3.3.14
-765#[derive(Debug, Clone)]
-766pub struct TxtRecordData(Box<[Box<[u8]>]>);
-767
-768impl TxtRecordData {
-769    /// Returns an iterator over the character strings contained in this TXT record.
-770    pub fn iter(&self) -> impl Iterator<Item = &[u8]> {
-771        self.0.iter().map(|x| x.as_ref())
-772    }
-773}
-774
-775impl fmt::Display for TxtRecordData {
-776    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-777        for s in self.iter() {
-778            write!(f, "{}", &String::from_utf8_lossy(s))?
-779        }
-780        Ok(())
-781    }
-782}
-783
-784impl FromIterator<Box<[u8]>> for TxtRecordData {
-785    fn from_iter<T: IntoIterator<Item = Box<[u8]>>>(iter: T) -> Self {
-786        Self(iter.into_iter().collect())
-787    }
-788}
-789
-790impl From<Vec<Box<[u8]>>> for TxtRecordData {
-791    fn from(value: Vec<Box<[u8]>>) -> Self {
-792        Self(value.into_boxed_slice())
-793    }
-794}
-795
-796/// Helper enum to give a unified type to the iterators of [`DnsResolver::lookup_ipv4_ipv6`].
-797enum LookupIter<A, B> {
-798    Ipv4(A),
-799    Ipv6(B),
-800    Both(std::iter::Chain<A, B>),
-801}
-802
-803impl<A: Iterator<Item = IpAddr>, B: Iterator<Item = IpAddr>> Iterator for LookupIter<A, B> {
-804    type Item = IpAddr;
-805
-806    fn next(&mut self) -> Option<Self::Item> {
-807        match self {
-808            LookupIter::Ipv4(iter) => iter.next(),
-809            LookupIter::Ipv6(iter) => iter.next(),
-810            LookupIter::Both(iter) => iter.next(),
-811        }
-812    }
-813}
-814
-815/// Staggers calls to the future F with the given delays.
-816///
-817/// The first call is performed immediately. The first call to succeed generates an Ok result
-818/// ignoring any previous error. If all calls fail, an error summarizing all errors is returned.
-819async fn stagger_call<
-820    T,
-821    E: StackError + 'static,
-822    F: Fn() -> Fut,
-823    Fut: Future<Output = Result<T, E>>,
-824>(
-825    f: F,
-826    delays_ms: &[u64],
-827) -> Result<T, StaggeredError<E>> {
-828    let mut calls = n0_future::FuturesUnorderedBounded::new(delays_ms.len() + 1);
-829    // NOTE: we add the 0 delay here to have a uniform set of futures. This is more performant than
-830    // using alternatives that allow futures of different types.
-831    for delay in std::iter::once(&0u64).chain(delays_ms) {
-832        let delay = add_jitter(delay);
-833        let fut = f();
-834        let staggered_fut = async move {
-835            time::sleep(delay).await;
-836            fut.await
-837        };
-838        calls.push(staggered_fut)
-839    }
+720}
+721
+722/// Record data for a TXT record.
+723///
+724/// This contains a list of character strings, as defined in [RFC 1035 Section 3.3.14].
+725///
+726/// [`TxtRecordData`] implements [`fmt::Display`], so you can call [`ToString::to_string`] to
+727/// convert the record data into a string. This will parse each character string with
+728/// [`String::from_utf8_lossy`] and then concatenate all strings without a separator.
+729///
+730/// If you want to process each character string individually, use [`Self::iter`].
+731///
+732/// [RFC 1035 Section 3.3.14]: https://datatracker.ietf.org/doc/html/rfc1035#section-3.3.14
+733#[derive(Debug, Clone)]
+734pub struct TxtRecordData(Box<[Box<[u8]>]>);
+735
+736impl TxtRecordData {
+737    /// Returns an iterator over the character strings contained in this TXT record.
+738    pub fn iter(&self) -> impl Iterator<Item = &[u8]> {
+739        self.0.iter().map(|x| x.as_ref())
+740    }
+741}
+742
+743impl fmt::Display for TxtRecordData {
+744    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+745        for s in self.iter() {
+746            write!(f, "{}", &String::from_utf8_lossy(s))?
+747        }
+748        Ok(())
+749    }
+750}
+751
+752impl FromIterator<Box<[u8]>> for TxtRecordData {
+753    fn from_iter<T: IntoIterator<Item = Box<[u8]>>>(iter: T) -> Self {
+754        Self(iter.into_iter().collect())
+755    }
+756}
+757
+758impl From<Vec<Box<[u8]>>> for TxtRecordData {
+759    fn from(value: Vec<Box<[u8]>>) -> Self {
+760        Self(value.into_boxed_slice())
+761    }
+762}
+763
+764/// Helper enum to give a unified type to the iterators of [`DnsResolver::lookup_ipv4_ipv6`].
+765enum LookupIter<A, B> {
+766    Ipv4(A),
+767    Ipv6(B),
+768    Both(std::iter::Chain<A, B>),
+769}
+770
+771impl<A: Iterator<Item = IpAddr>, B: Iterator<Item = IpAddr>> Iterator for LookupIter<A, B> {
+772    type Item = IpAddr;
+773
+774    fn next(&mut self) -> Option<Self::Item> {
+775        match self {
+776            LookupIter::Ipv4(iter) => iter.next(),
+777            LookupIter::Ipv6(iter) => iter.next(),
+778            LookupIter::Both(iter) => iter.next(),
+779        }
+780    }
+781}
+782
+783/// Staggers calls to the future F with the given delays.
+784///
+785/// The first call is performed immediately. The first call to succeed generates an Ok result
+786/// ignoring any previous error. If all calls fail, an error summarizing all errors is returned.
+787async fn stagger_call<
+788    T,
+789    E: StackError + 'static,
+790    F: Fn() -> Fut,
+791    Fut: Future<Output = Result<T, E>>,
+792>(
+793    f: F,
+794    delays_ms: &[u64],
+795) -> Result<T, StaggeredError<E>> {
+796    let mut calls = n0_future::FuturesUnorderedBounded::new(delays_ms.len() + 1);
+797    // NOTE: we add the 0 delay here to have a uniform set of futures. This is more performant than
+798    // using alternatives that allow futures of different types.
+799    for delay in std::iter::once(&0u64).chain(delays_ms) {
+800        let delay = add_jitter(delay);
+801        let fut = f();
+802        let staggered_fut = async move {
+803            time::sleep(delay).await;
+804            fut.await
+805        };
+806        calls.push(staggered_fut)
+807    }
+808
+809    let mut errors = vec![];
+810    while let Some(call_result) = calls.next().await {
+811        match call_result {
+812            Ok(t) => return Ok(t),
+813            Err(e) => errors.push(e),
+814        }
+815    }
+816
+817    Err(e!(StaggeredError { errors }))
+818}
+819
+820fn add_jitter(delay: &u64) -> Duration {
+821    // If delay is 0, return 0 immediately.
+822    if *delay == 0 {
+823        return Duration::ZERO;
+824    }
+825
+826    // Calculate jitter as a random value in the range of +/- MAX_JITTER_PERCENT of the delay.
+827    let max_jitter = delay.saturating_mul(MAX_JITTER_PERCENT * 2) / 100;
+828    let jitter = rand::random::<u64>() % max_jitter;
+829
+830    Duration::from_millis(delay.saturating_sub(max_jitter / 2).saturating_add(jitter))
+831}
+832
+833#[cfg(test)]
+834pub(crate) mod tests {
+835    use std::sync::atomic::AtomicUsize;
+836
+837    use n0_tracing_test::traced_test;
+838
+839    use super::*;
 840
-841    let mut errors = vec![];
-842    while let Some(call_result) = calls.next().await {
-843        match call_result {
-844            Ok(t) => return Ok(t),
-845            Err(e) => errors.push(e),
-846        }
-847    }
-848
-849    Err(e!(StaggeredError { errors }))
-850}
-851
-852fn add_jitter(delay: &u64) -> Duration {
-853    // If delay is 0, return 0 immediately.
-854    if *delay == 0 {
-855        return Duration::ZERO;
-856    }
-857
-858    // Calculate jitter as a random value in the range of +/- MAX_JITTER_PERCENT of the delay.
-859    let max_jitter = delay.saturating_mul(MAX_JITTER_PERCENT * 2) / 100;
-860    let jitter = rand::random::<u64>() % max_jitter;
-861
-862    Duration::from_millis(delay.saturating_sub(max_jitter / 2).saturating_add(jitter))
-863}
-864
-865#[cfg(test)]
-866pub(crate) mod tests {
-867    use std::sync::atomic::AtomicUsize;
-868
-869    use n0_tracing_test::traced_test;
+841    #[cfg(target_os = "android")]
+842    #[test]
+843    fn android_system_conf_unsupported_without_jni_context() {
+844        // Without `install_android_jni_context`, the platform reader
+845        // must report PlatformUnsupported so the resolver picks up the
+846        // public fallback instead of trying to query nothing.
+847        match crate::system_config::read_system_conf() {
+848            Err(crate::system_config::SystemConfigError::PlatformUnsupported { .. }) => {}
+849            other => panic!("expected PlatformUnsupported, got {other:?}"),
+850        }
+851    }
+852
+853    #[tokio::test]
+854    #[traced_test]
+855    async fn stagger_basic() {
+856        const CALL_RESULTS: &[Result<u8, u8>] = &[Err(2), Ok(3), Ok(5), Ok(7)];
+857        static DONE_CALL: AtomicUsize = AtomicUsize::new(0);
+858        let f = || {
+859            let r_pos = DONE_CALL.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
+860            async move {
+861                tracing::info!(r_pos, "call");
+862                CALL_RESULTS[r_pos].map_err(|_| e!(DnsError::InvalidResponse))
+863            }
+864        };
+865
+866        let delays = [1000, 15];
+867        let result = stagger_call(f, &delays).await.unwrap();
+868        assert_eq!(result, 5)
+869    }
 870
-871    use super::*;
-872    use crate::system_config::is_usable_nameserver;
-873
-874    #[test]
-875    fn public_fallback_has_useful_servers() {
-876        let config = public_fallback_config();
-877        let servers: Vec<_> = config.name_servers().iter().map(|n| n.ip).collect();
-878        assert!(!servers.is_empty(), "fallback config must list servers");
-879        for ip in &servers {
-880            assert!(
-881                is_usable_nameserver(*ip),
-882                "fallback server {ip} must pass the link-local filter",
-883            );
-884        }
-885        // Both providers must be present so a single-provider outage does
-886        // not take iroh down.
-887        assert!(servers.contains(&"1.1.1.1".parse().unwrap()));
-888        assert!(servers.contains(&"8.8.8.8".parse().unwrap()));
-889    }
-890
-891    #[cfg(with_crypto_provider)]
-892    #[test]
-893    fn public_fallback_includes_doh_when_tls_enabled() {
-894        use hickory_resolver::config::ProtocolConfig;
-895
-896        let config = public_fallback_config();
-897        let has_https = config.name_servers().iter().any(|n| {
-898            n.connections
-899                .iter()
-900                .any(|c| matches!(c.protocol, ProtocolConfig::Https { .. }))
-901        });
-902        assert!(
-903            has_https,
-904            "fallback config must include DoH when tls feature is enabled",
-905        );
-906    }
-907
-908    #[cfg(target_os = "android")]
-909    #[test]
-910    fn android_system_conf_unsupported_without_jni_context() {
-911        // Without `install_android_jni_context`, the platform reader
-912        // must report PlatformUnsupported so the resolver picks up the
-913        // public fallback instead of trying to query nothing.
-914        match crate::system_config::read_system_conf() {
-915            Err(crate::system_config::SystemConfigError::PlatformUnsupported { .. }) => {}
-916            other => panic!("expected PlatformUnsupported, got {other:?}"),
-917        }
-918    }
-919
-920    #[tokio::test]
-921    #[traced_test]
-922    async fn stagger_basic() {
-923        const CALL_RESULTS: &[Result<u8, u8>] = &[Err(2), Ok(3), Ok(5), Ok(7)];
-924        static DONE_CALL: AtomicUsize = AtomicUsize::new(0);
-925        let f = || {
-926            let r_pos = DONE_CALL.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
-927            async move {
-928                tracing::info!(r_pos, "call");
-929                CALL_RESULTS[r_pos].map_err(|_| e!(DnsError::InvalidResponse))
-930            }
-931        };
-932
-933        let delays = [1000, 15];
-934        let result = stagger_call(f, &delays).await.unwrap();
-935        assert_eq!(result, 5)
-936    }
-937
-938    #[test]
-939    #[traced_test]
-940    fn jitter_test_zero() {
-941        let jittered_delay = add_jitter(&0);
-942        assert_eq!(jittered_delay, Duration::from_secs(0));
-943    }
-944
-945    //Sanity checks that I did the math right
-946    #[test]
-947    #[traced_test]
-948    fn jitter_test_nonzero_lower_bound() {
-949        let delay: u64 = 300;
-950        for _ in 0..100 {
-951            assert!(add_jitter(&delay) >= Duration::from_millis(delay * 8 / 10));
-952        }
-953    }
-954
-955    #[test]
-956    #[traced_test]
-957    fn jitter_test_nonzero_upper_bound() {
-958        let delay: u64 = 300;
-959        for _ in 0..100 {
-960            assert!(add_jitter(&delay) < Duration::from_millis(delay * 12 / 10));
-961        }
-962    }
-963
-964    #[tokio::test]
-965    #[traced_test]
-966    async fn custom_resolver() {
-967        #[derive(Debug)]
-968        struct MyResolver;
-969        impl Resolver for MyResolver {
-970            fn lookup_ipv4(&self, host: String) -> BoxFuture<Result<BoxIter<Ipv4Addr>, DnsError>> {
-971                Box::pin(async move {
-972                    let addr = if host == "foo.example" {
-973                        Ipv4Addr::new(1, 1, 1, 1)
-974                    } else {
-975                        return Err(e!(DnsError::NoResponse));
-976                    };
-977                    let iter: BoxIter<Ipv4Addr> = Box::new(vec![addr].into_iter());
-978                    Ok(iter)
-979                })
-980            }
-981
-982            fn lookup_ipv6(&self, _host: String) -> BoxFuture<Result<BoxIter<Ipv6Addr>, DnsError>> {
-983                todo!()
-984            }
-985
-986            fn lookup_txt(
-987                &self,
-988                _host: String,
-989            ) -> BoxFuture<Result<BoxIter<TxtRecordData>, DnsError>> {
-990                todo!()
-991            }
-992
-993            fn clear_cache(&self) {
-994                todo!()
-995            }
-996
-997            fn reset(&self) -> Box<dyn Resolver> {
-998                todo!()
-999            }
-1000        }
-1001
-1002        let resolver = DnsResolver::custom(MyResolver);
-1003        let mut iter = resolver
-1004            .lookup_ipv4("foo.example", Duration::from_secs(1))
-1005            .await
-1006            .expect("not to fail");
-1007        let addr = iter.next().expect("one result");
-1008        assert_eq!(addr, "1.1.1.1".parse::<IpAddr>().unwrap());
-1009
-1010        let res = resolver
-1011            .lookup_ipv4("bar.example", Duration::from_secs(1))
-1012            .await;
-1013        assert!(matches!(res, Err(DnsError::NoResponse { .. })))
-1014    }
-1015}
\ No newline at end of file +871 #[test] +872 #[traced_test] +873 fn jitter_test_zero() { +874 let jittered_delay = add_jitter(&0); +875 assert_eq!(jittered_delay, Duration::from_secs(0)); +876 } +877 +878 //Sanity checks that I did the math right +879 #[test] +880 #[traced_test] +881 fn jitter_test_nonzero_lower_bound() { +882 let delay: u64 = 300; +883 for _ in 0..100 { +884 assert!(add_jitter(&delay) >= Duration::from_millis(delay * 8 / 10)); +885 } +886 } +887 +888 #[test] +889 #[traced_test] +890 fn jitter_test_nonzero_upper_bound() { +891 let delay: u64 = 300; +892 for _ in 0..100 { +893 assert!(add_jitter(&delay) < Duration::from_millis(delay * 12 / 10)); +894 } +895 } +896 +897 #[tokio::test] +898 #[traced_test] +899 async fn custom_resolver() { +900 #[derive(Debug)] +901 struct MyResolver; +902 impl Resolver for MyResolver { +903 fn lookup_ipv4(&self, host: String) -> BoxFuture<Result<BoxIter<Ipv4Addr>, DnsError>> { +904 Box::pin(async move { +905 let addr = if host == "foo.example" { +906 Ipv4Addr::new(1, 1, 1, 1) +907 } else { +908 return Err(e!(DnsError::NoResponse)); +909 }; +910 let iter: BoxIter<Ipv4Addr> = Box::new(vec![addr].into_iter()); +911 Ok(iter) +912 }) +913 } +914 +915 fn lookup_ipv6(&self, _host: String) -> BoxFuture<Result<BoxIter<Ipv6Addr>, DnsError>> { +916 todo!() +917 } +918 +919 fn lookup_txt( +920 &self, +921 _host: String, +922 ) -> BoxFuture<Result<BoxIter<TxtRecordData>, DnsError>> { +923 todo!() +924 } +925 +926 fn clear_cache(&self) { +927 todo!() +928 } +929 +930 fn reset(&self) -> Box<dyn Resolver> { +931 todo!() +932 } +933 } +934 +935 let resolver = DnsResolver::custom(MyResolver); +936 let mut iter = resolver +937 .lookup_ipv4("foo.example", Duration::from_secs(1)) +938 .await +939 .expect("not to fail"); +940 let addr = iter.next().expect("one result"); +941 assert_eq!(addr, "1.1.1.1".parse::<IpAddr>().unwrap()); +942 +943 let res = resolver +944 .lookup_ipv4("bar.example", Duration::from_secs(1)) +945 .await; +946 assert!(matches!(res, Err(DnsError::NoResponse { .. }))) +947 } +948}
\ No newline at end of file