pub struct DnsResolver { /* private fields */ }Expand description
Per-client DNS and SRV cache.
Cheaply Clone-able — all clones share the same underlying Arc caches.
Constructed by McClientBuilder via
DnsResolver::new() or DnsResolver::with_cache_size(n).
Implementations§
Source§impl DnsResolver
impl DnsResolver
Sourcepub fn with_cache_size(size: usize) -> Self
pub fn with_cache_size(size: usize) -> Self
Create a resolver with a custom LRU capacity.
The same capacity is applied to both the DNS and SRV caches.
§Panics
Panics if size is 0.
Sourcepub async fn dns_len(&self) -> usize
pub async fn dns_len(&self) -> usize
Number of entries currently in the DNS cache (including expired ones).
Sourcepub async fn srv_len(&self) -> usize
pub async fn srv_len(&self) -> usize
Number of entries currently in the SRV cache (including expired ones).
Sourcepub async fn lookup_srv(
&self,
host: &str,
tout: Duration,
) -> Option<(String, u16)>
pub async fn lookup_srv( &self, host: &str, tout: Duration, ) -> Option<(String, u16)>
Look up the _minecraft._tcp.<host> SRV record.
Returns Some((target_host, port)) on success, None on any failure
(DNS error, no SRV record, timeout) so callers can transparently fall
back to a plain A/AAAA lookup.
Results are cached for [DNS_CACHE_TTL] (5 minutes).
Sourcepub async fn resolve(
&self,
host: &str,
port: u16,
) -> Result<(SocketAddr, DnsInfo), McError>
pub async fn resolve( &self, host: &str, port: u16, ) -> Result<(SocketAddr, DnsInfo), McError>
Resolve host:port to a SocketAddr.
Prefers IPv4 addresses when both A and AAAA records are returned.
Results are cached for [DNS_CACHE_TTL] (5 minutes).
Resolution is performed in a spawn_blocking task because
std::net::ToSocketAddrs is a blocking call.
§Errors
Returns McError::Network(Dns) on
resolution failure or when no addresses are returned.
Trait Implementations§
Source§impl Clone for DnsResolver
impl Clone for DnsResolver
Source§fn clone(&self) -> DnsResolver
fn clone(&self) -> DnsResolver
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for DnsResolver
impl !UnwindSafe for DnsResolver
impl Freeze for DnsResolver
impl Send for DnsResolver
impl Sync for DnsResolver
impl Unpin for DnsResolver
impl UnsafeUnpin for DnsResolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more