From 5d0443a678735141003ad1e106f11f2d92bbc11d Mon Sep 17 00:00:00 2001 From: Edu4rdSHL Date: Wed, 20 Oct 2021 05:51:47 -0500 Subject: [PATCH] Performance improvement. DNS queries with a dot [.] at the end of the domain are cheaper, this small but significant change results in an important performance improvement. Signed-off-by: Edu4rdSHL --- src/main.rs | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index c2361b0..1666e61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -158,23 +158,26 @@ async fn main() -> Result<(), Box> { buffer.lines().map(str::to_owned).collect() }; - futures::stream::iter(hosts.into_iter().map(|host| { - let resolver_fut = resolvers.ipv4_lookup(host.clone()); - let trustable_resolver_fut = trustable_resolver.ipv4_lookup(host.clone()); - let wildcard_ips = wildcard_ips.clone(); - async move { - if let Ok(ip) = resolver_fut.await { + stream::iter(hosts) + .map(|host| { + let resolver_fut = resolvers.ipv4_lookup(host.clone() + "."); + let trustable_resolver_fut = trustable_resolver.ipv4_lookup(host.clone() + "."); + let wildcard_ips = wildcard_ips.clone(); + + async move { let mut ips = HashSet::new(); - if disable_double_check { - ips = ip - .into_iter() - .map(|x| x.to_string()) - .collect::>(); - } else if let Ok(ip) = trustable_resolver_fut.await { - ips = ip - .into_iter() - .map(|x| x.to_string()) - .collect::>(); + if let Ok(ip) = resolver_fut.await { + if disable_double_check { + ips = ip + .into_iter() + .map(|x| x.to_string()) + .collect::>(); + } else if let Ok(ip) = trustable_resolver_fut.await { + ips = ip + .into_iter() + .map(|x| x.to_string()) + .collect::>(); + } } if show_ip_adress && !ips.iter().all(|ip| wildcard_ips.contains(ip)) { println!("{};{:?}", host, ips) @@ -182,11 +185,11 @@ async fn main() -> Result<(), Box> { println!("{}", host) } } - } - })) - .buffer_unordered(threads) - .collect::>() - .await; + }) + .buffer_unordered(threads) + .collect::>() + .await; + Ok(()) }