pub struct DnsResolver { /* private fields */ }Expand description
Async DNS resolver for crawler verification with rate limiting.
Implementations§
Source§impl DnsResolver
impl DnsResolver
Sourcepub async fn new(
timeout_ms: u64,
max_concurrent: usize,
) -> Result<Self, DnsError>
pub async fn new( timeout_ms: u64, max_concurrent: usize, ) -> Result<Self, DnsError>
Create a new DNS resolver with rate limiting.
§Arguments
timeout_ms- DNS lookup timeout in millisecondsmax_concurrent- Maximum concurrent DNS lookups (semaphore permits)
Sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Get current number of available permits (for metrics)
Sourcepub fn max_concurrent(&self) -> usize
pub fn max_concurrent(&self) -> usize
Get maximum concurrent lookups configured
Sourcepub async fn reverse_lookup(
&self,
ip: IpAddr,
) -> Result<Option<String>, DnsError>
pub async fn reverse_lookup( &self, ip: IpAddr, ) -> Result<Option<String>, DnsError>
Reverse DNS lookup: IP -> hostname.
Rate-limited via semaphore to prevent resource exhaustion.
Sourcepub async fn forward_lookup(
&self,
hostname: &str,
) -> Result<Vec<IpAddr>, DnsError>
pub async fn forward_lookup( &self, hostname: &str, ) -> Result<Vec<IpAddr>, DnsError>
Forward DNS lookup: hostname -> IPs.
Rate-limited via semaphore to prevent resource exhaustion.
Sourcepub async fn verify_ip(
&self,
ip: IpAddr,
) -> Result<(bool, Option<String>), DnsError>
pub async fn verify_ip( &self, ip: IpAddr, ) -> Result<(bool, Option<String>), DnsError>
Verify IP via reverse+forward DNS lookup.
Returns (verified, hostname) where verified is true only if:
- Reverse lookup (IP -> hostname) succeeds
- Forward lookup (hostname -> IPs) succeeds
- Original IP is contained in the forward lookup results
This prevents DNS rebinding attacks where an attacker controls a domain that initially resolves to a legitimate IP, then changes after verification.
§Security
The IP round-trip check is critical: we verify that the hostname the IP claims to be actually resolves back to that IP.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DnsResolver
impl !RefUnwindSafe for DnsResolver
impl Send for DnsResolver
impl Sync for DnsResolver
impl Unpin for DnsResolver
impl UnsafeUnpin for DnsResolver
impl !UnwindSafe 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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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