mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2025-01-15 04:57:08 +01:00
Use tokio concurrency knowlege to speed up DNS queries
This commit is contained in:
parent
2a530b6f11
commit
3bcf8fde39
@ -18,6 +18,8 @@ use trust_dns_resolver::{
|
|||||||
TokioAsyncResolver,
|
TokioAsyncResolver,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use tokio::join;
|
||||||
|
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
|
||||||
|
|
||||||
@ -211,34 +213,50 @@ pub async fn lookup(
|
|||||||
name: &String,
|
name: &String,
|
||||||
do_full_lookup: bool,
|
do_full_lookup: bool,
|
||||||
) -> DnsLookupResult {
|
) -> DnsLookupResult {
|
||||||
let ipv4_lookup_res = resolver.lookup(name, RecordType::A);
|
let (
|
||||||
let ipv6_lookup_res = resolver.lookup(name, RecordType::AAAA);
|
ipv4_lookup_res,
|
||||||
let cname_lookup_res = resolver.lookup(name, RecordType::CNAME);
|
ipv6_lookup_res,
|
||||||
let aname_lookup_res = resolver.lookup(name, RecordType::ANAME);
|
cname_lookup_res,
|
||||||
|
aname_lookup_res
|
||||||
|
) = join!(
|
||||||
|
resolver.lookup(name, RecordType::A),
|
||||||
|
resolver.lookup(name, RecordType::AAAA),
|
||||||
|
resolver.lookup(name, RecordType::CNAME),
|
||||||
|
resolver.lookup(name, RecordType::ANAME),
|
||||||
|
);
|
||||||
|
|
||||||
// initlize an empty lookup result
|
// initlize an empty lookup result
|
||||||
let mut dig_result: DnsLookupResult = Default::default();
|
let mut dig_result: DnsLookupResult = Default::default();
|
||||||
|
|
||||||
integrate_lookup_result(&mut dig_result, ipv4_lookup_res.await);
|
integrate_lookup_result(&mut dig_result, ipv4_lookup_res);
|
||||||
integrate_lookup_result(&mut dig_result, ipv6_lookup_res.await);
|
integrate_lookup_result(&mut dig_result, ipv6_lookup_res);
|
||||||
integrate_lookup_result(&mut dig_result, cname_lookup_res.await);
|
integrate_lookup_result(&mut dig_result, cname_lookup_res);
|
||||||
integrate_lookup_result(&mut dig_result, aname_lookup_res.await);
|
integrate_lookup_result(&mut dig_result, aname_lookup_res);
|
||||||
|
|
||||||
//Don't do an extented lookup if the domain seemingly doesn't exist
|
//Don't do an extented lookup if the domain seemingly doesn't exist
|
||||||
if do_full_lookup && !dig_result.nxdomain {
|
if do_full_lookup && !dig_result.nxdomain {
|
||||||
let mx_lookup_res = resolver.lookup(name, RecordType::MX);
|
let (
|
||||||
let ns_lookup_res = resolver.lookup(name, RecordType::NS);
|
mx_lookup_res,
|
||||||
let soa_lookup_res = resolver.lookup(name, RecordType::SOA);
|
ns_lookup_res,
|
||||||
let caa_lookup_res = resolver.lookup(name, RecordType::CAA);
|
soa_lookup_res,
|
||||||
let srv_lookup_res = resolver.lookup(name, RecordType::SRV);
|
caa_lookup_res,
|
||||||
let txt_lookup_res = resolver.lookup(name, RecordType::TXT);
|
srv_lookup_res,
|
||||||
|
txt_lookup_res
|
||||||
|
) = join!(
|
||||||
|
resolver.lookup(name, RecordType::MX),
|
||||||
|
resolver.lookup(name, RecordType::NS),
|
||||||
|
resolver.lookup(name, RecordType::SOA),
|
||||||
|
resolver.lookup(name, RecordType::CAA),
|
||||||
|
resolver.lookup(name, RecordType::SRV),
|
||||||
|
resolver.lookup(name, RecordType::TXT),
|
||||||
|
);
|
||||||
|
|
||||||
integrate_lookup_result(&mut dig_result, mx_lookup_res.await);
|
integrate_lookup_result(&mut dig_result, mx_lookup_res);
|
||||||
integrate_lookup_result(&mut dig_result, ns_lookup_res.await);
|
integrate_lookup_result(&mut dig_result, ns_lookup_res);
|
||||||
integrate_lookup_result(&mut dig_result, soa_lookup_res.await);
|
integrate_lookup_result(&mut dig_result, soa_lookup_res);
|
||||||
integrate_lookup_result(&mut dig_result, caa_lookup_res.await);
|
integrate_lookup_result(&mut dig_result, caa_lookup_res);
|
||||||
integrate_lookup_result(&mut dig_result, srv_lookup_res.await);
|
integrate_lookup_result(&mut dig_result, srv_lookup_res);
|
||||||
integrate_lookup_result(&mut dig_result, txt_lookup_res.await);
|
integrate_lookup_result(&mut dig_result, txt_lookup_res);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user