fn resolver_queue_processor(
        rx: Receiver<DnsResolveRequest>,
        provider: &DnsProvider,
        cache: &Cache,
    ) {
        for DnsResolveRequest { addr, with_asinfo } in rx {
            let entry = match &provider {
                DnsProvider::DnsLookup => {
                    // we can't distinguish between a failed lookup or a genuine error and so we just assume all
                    // failures are `DnsEntry::NotFound`.
                    match dns_lookup::lookup_addr(&addr) {
                        Ok(dns) => DnsEntry::Resolved(Resolved::Normal(addr, vec![dns])),
                        Err(_) => DnsEntry::NotFound(addr),
                    }
                }
                DnsProvider::TrustDns(resolver) => match resolver.reverse_lookup(addr) {
                    Ok(name) => {
                        let hostnames = name
                            .into_iter()
                            .map(|mut s| {
                                s.set_fqdn(false);
                                s
                            })
                            .map(|s| s.to_string())
                            .collect();
                        if with_asinfo {
                            let as_info = lookup_asinfo(resolver, addr).unwrap_or_default();
                            DnsEntry::Resolved(Resolved::WithAsInfo(addr, hostnames, as_info))
                        } else {
                            DnsEntry::Resolved(Resolved::Normal(addr, hostnames))
                        }
                    }
                    Err(err) => match err.kind() {
                        ResolveErrorKind::NoRecordsFound { .. } => DnsEntry::NotFound(addr),
                        ResolveErrorKind::Timeout => DnsEntry::Timeout(addr),
                        _ => DnsEntry::Failed(addr),
                    },
                },
            };
            cache.write().insert(addr, entry);
        }
    }
/// Process each `IpAddr` from the resolver queue and perform the reverse DNS lookup.
///
/// For each `IpAddr`, perform the reverse DNS lookup and update the cache with the result (`Resolved`, `NotFound`,
/// `Timeout` or `Failed`) for that addr.
Process each `IpAddr` from the resolver queue and perform the reverse DNS lookup.
Process each ` IpAddr ` from the resolver queue and perform the reverse DNS lookup .
fn resolver_queue_processor(
        rx: Receiver<DnsResolveRequest>,
        provider: &DnsProvider,
        cache: &Cache,
    ) {
        for DnsResolveRequest { addr, with_asinfo } in rx {
            let entry = match &provider {
                DnsProvider::DnsLookup => {
                    // we can't distinguish between a failed lookup or a genuine error and so we just assume all
                    // failures are `DnsEntry::NotFound`.
                    match dns_lookup::lookup_addr(&addr) {
                        Ok(dns) => DnsEntry::Resolved(Resolved::Normal(addr, vec![dns])),
                        Err(_) => DnsEntry::NotFound(addr),
                    }
                }
                DnsProvider::TrustDns(resolver) => match resolver.reverse_lookup(addr) {
                    Ok(name) => {
                        let hostnames = name
                            .into_iter()
                            .map(|mut s| {
                                s.set_fqdn(false);
                                s
                            })
                            .map(|s| s.to_string())
                            .collect();
                        if with_asinfo {
                            let as_info = lookup_asinfo(resolver, addr).unwrap_or_default();
                            DnsEntry::Resolved(Resolved::WithAsInfo(addr, hostnames, as_info))
                        } else {
                            DnsEntry::Resolved(Resolved::Normal(addr, hostnames))
                        }
                    }
                    Err(err) => match err.kind() {
                        ResolveErrorKind::NoRecordsFound { .. } => DnsEntry::NotFound(addr),
                        ResolveErrorKind::Timeout => DnsEntry::Timeout(addr),
                        _ => DnsEntry::Failed(addr),
                    },
                },
            };
            cache.write().insert(addr, entry);
        }
    }
fn resolver_queue_processor ( rx : Receiver < DnsResolveRequest > , provider : & DnsProvider , cache : & Cache , ) { for DnsResolveRequest { addr , with_asinfo } in rx { let entry = match & provider { DnsProvider :: DnsLookup => { // we can't distinguish between a failed lookup or a genuine error and so we just assume all // failures are `DnsEntry::NotFound`. match dns_lookup :: lookup_addr ( & addr ) { Ok ( dns ) => DnsEntry :: Resolved ( Resolved :: Normal ( addr , vec ! [ dns ] ) ) , Err ( _ ) => DnsEntry :: NotFound ( addr ) , } } DnsProvider :: TrustDns ( resolver ) => match resolver . reverse_lookup ( addr ) { Ok ( name ) => { let hostnames = name . into_iter ( ) . map ( | mut s | { s . set_fqdn ( false ) ; s } ) . map ( | s | s . to_string ( ) ) . collect ( ) ; if with_asinfo { let as_info = lookup_asinfo ( resolver , addr ) . unwrap_or_default ( ) ; DnsEntry :: Resolved ( Resolved :: WithAsInfo ( addr , hostnames , as_info ) ) } else { DnsEntry :: Resolved ( Resolved :: Normal ( addr , hostnames ) ) } } Err ( err ) => match err . kind ( ) { ResolveErrorKind :: NoRecordsFound { .. } => DnsEntry :: NotFound ( addr ) , ResolveErrorKind :: Timeout => DnsEntry :: Timeout ( addr ) , _ => DnsEntry :: Failed ( addr ) , } , } , } ; cache . write ( ) . insert ( addr , entry ) ; } }
Process each `IpAddr` from the resolver queue and perform the reverse DNS lookup.
Process each ` IpAddr ` from the resolver queue and perform the reverse DNS lookup .
rx
Receiver<DnsResolveRequest>
provider
&DnsProvider
cache
&Cache