Skip to content

Commit

Permalink
transports/dns: Remove fqdn function optimization (#2027)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Inden <[email protected]>
  • Loading branch information
tomaka and mxinden authored Apr 1, 2021
1 parent a2e7749 commit 2017c5c
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions transports/dns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use libp2p_core::{
transport::{TransportError, ListenerEvent}
};
use smallvec::SmallVec;
use std::{borrow::Cow, convert::TryFrom, error, fmt, iter, net::IpAddr, str};
use std::{convert::TryFrom, error, fmt, iter, net::IpAddr, str};
#[cfg(any(feature = "async-std", feature = "tokio"))]
use std::io;
#[cfg(any(feature = "async-std", feature = "tokio"))]
Expand Down Expand Up @@ -384,7 +384,7 @@ where
{
match proto {
Protocol::Dns(ref name) => {
resolver.lookup_ip(fqdn(name)).map(move |res| match res {
resolver.lookup_ip(name.clone().into_owned()).map(move |res| match res {
Ok(ips) => {
let mut ips = ips.into_iter();
let one = ips.next()
Expand All @@ -403,7 +403,7 @@ where
}).boxed()
}
Protocol::Dns4(ref name) => {
resolver.ipv4_lookup(fqdn(name)).map(move |res| match res {
resolver.ipv4_lookup(name.clone().into_owned()).map(move |res| match res {
Ok(ips) => {
let mut ips = ips.into_iter();
let one = ips.next()
Expand All @@ -423,7 +423,7 @@ where
}).boxed()
}
Protocol::Dns6(ref name) => {
resolver.ipv6_lookup(fqdn(name)).map(move |res| match res {
resolver.ipv6_lookup(name.clone().into_owned()).map(move |res| match res {
Ok(ips) => {
let mut ips = ips.into_iter();
let one = ips.next()
Expand All @@ -443,8 +443,8 @@ where
}).boxed()
},
Protocol::Dnsaddr(ref name) => {
let name = Cow::Owned([DNSADDR_PREFIX, name].concat());
resolver.txt_lookup(fqdn(&name)).map(move |res| match res {
let name = [DNSADDR_PREFIX, name].concat();
resolver.txt_lookup(name).map(move |res| match res {
Ok(txts) => {
let mut addrs = Vec::new();
for txt in txts {
Expand Down Expand Up @@ -482,14 +482,6 @@ fn invalid_data(e: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> io::E
io::Error::new(io::ErrorKind::InvalidData, e)
}

fn fqdn(name: &Cow<'_, str>) -> String {
if name.ends_with('.') {
name.to_string()
} else {
format!("{}.", name)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 2017c5c

Please sign in to comment.