transports/dns: Remove fqdn function optimization (#2027)

Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
Pierre Krieger
2021-04-01 16:11:36 +02:00
committed by GitHub
parent a2e774992d
commit 2017c5c73a

View File

@ -45,7 +45,7 @@ use libp2p_core::{
transport::{TransportError, ListenerEvent} transport::{TransportError, ListenerEvent}
}; };
use smallvec::SmallVec; 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"))] #[cfg(any(feature = "async-std", feature = "tokio"))]
use std::io; use std::io;
#[cfg(any(feature = "async-std", feature = "tokio"))] #[cfg(any(feature = "async-std", feature = "tokio"))]
@ -384,7 +384,7 @@ where
{ {
match proto { match proto {
Protocol::Dns(ref name) => { 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) => { Ok(ips) => {
let mut ips = ips.into_iter(); let mut ips = ips.into_iter();
let one = ips.next() let one = ips.next()
@ -403,7 +403,7 @@ where
}).boxed() }).boxed()
} }
Protocol::Dns4(ref name) => { 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) => { Ok(ips) => {
let mut ips = ips.into_iter(); let mut ips = ips.into_iter();
let one = ips.next() let one = ips.next()
@ -423,7 +423,7 @@ where
}).boxed() }).boxed()
} }
Protocol::Dns6(ref name) => { 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) => { Ok(ips) => {
let mut ips = ips.into_iter(); let mut ips = ips.into_iter();
let one = ips.next() let one = ips.next()
@ -443,8 +443,8 @@ where
}).boxed() }).boxed()
}, },
Protocol::Dnsaddr(ref name) => { Protocol::Dnsaddr(ref name) => {
let name = Cow::Owned([DNSADDR_PREFIX, name].concat()); let name = [DNSADDR_PREFIX, name].concat();
resolver.txt_lookup(fqdn(&name)).map(move |res| match res { resolver.txt_lookup(name).map(move |res| match res {
Ok(txts) => { Ok(txts) => {
let mut addrs = Vec::new(); let mut addrs = Vec::new();
for txt in txts { for txt in txts {
@ -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) 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)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;