mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-15 20:31:19 +00:00
parent
6715281d92
commit
c0bccf724e
124
Cargo.lock
generated
124
Cargo.lock
generated
@ -463,16 +463,16 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-std-resolver"
|
name = "async-std-resolver"
|
||||||
version = "0.22.0"
|
version = "0.23.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6ba50e24d9ee0a8950d3d03fc6d0dd10aa14b5de3b101949b4e160f7fee7c723"
|
checksum = "0354a68a52265a3bde76005ddd2726624ef8624614f7f58871301de205a58a59"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"futures-io",
|
"futures-io",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
"socket2 0.4.9",
|
"socket2 0.5.3",
|
||||||
"trust-dns-resolver",
|
"trust-dns-resolver",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1562,18 +1562,6 @@ dependencies = [
|
|||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "enum-as-inner"
|
|
||||||
version = "0.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116"
|
|
||||||
dependencies = [
|
|
||||||
"heck",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "enum-as-inner"
|
name = "enum-as-inner"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
@ -2211,7 +2199,7 @@ dependencies = [
|
|||||||
"rustls 0.20.8",
|
"rustls 0.20.8",
|
||||||
"rustls-native-certs",
|
"rustls-native-certs",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-rustls",
|
"tokio-rustls 0.23.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2243,17 +2231,6 @@ dependencies = [
|
|||||||
"libp2p",
|
"libp2p",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "idna"
|
|
||||||
version = "0.2.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8"
|
|
||||||
dependencies = [
|
|
||||||
"matches",
|
|
||||||
"unicode-bidi",
|
|
||||||
"unicode-normalization",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "idna"
|
name = "idna"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@ -2700,6 +2677,7 @@ version = "0.40.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-std-resolver",
|
"async-std-resolver",
|
||||||
|
"async-trait",
|
||||||
"env_logger 0.10.0",
|
"env_logger 0.10.0",
|
||||||
"futures",
|
"futures",
|
||||||
"libp2p-core",
|
"libp2p-core",
|
||||||
@ -2875,7 +2853,7 @@ dependencies = [
|
|||||||
"smallvec",
|
"smallvec",
|
||||||
"socket2 0.5.3",
|
"socket2 0.5.3",
|
||||||
"tokio",
|
"tokio",
|
||||||
"trust-dns-proto 0.23.0",
|
"trust-dns-proto",
|
||||||
"void",
|
"void",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -3377,7 +3355,7 @@ dependencies = [
|
|||||||
"rw-stream-sink",
|
"rw-stream-sink",
|
||||||
"soketto",
|
"soketto",
|
||||||
"url",
|
"url",
|
||||||
"webpki-roots 0.25.2",
|
"webpki-roots",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3531,12 +3509,6 @@ dependencies = [
|
|||||||
"regex-automata 0.1.10",
|
"regex-automata 0.1.10",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "matches"
|
|
||||||
version = "0.1.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matchit"
|
name = "matchit"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
@ -5735,6 +5707,16 @@ dependencies = [
|
|||||||
"webpki 0.22.0",
|
"webpki 0.22.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-rustls"
|
||||||
|
version = "0.24.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081"
|
||||||
|
dependencies = [
|
||||||
|
"rustls 0.21.7",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-util"
|
name = "tokio-util"
|
||||||
version = "0.7.8"
|
version = "0.7.8"
|
||||||
@ -5866,39 +5848,6 @@ dependencies = [
|
|||||||
"tracing-log",
|
"tracing-log",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "trust-dns-proto"
|
|
||||||
version = "0.22.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4f7f83d1e4a0e4358ac54c5c3681e5d7da5efc5a7a632c90bb6d6669ddd9bc26"
|
|
||||||
dependencies = [
|
|
||||||
"async-trait",
|
|
||||||
"bytes",
|
|
||||||
"cfg-if 1.0.0",
|
|
||||||
"data-encoding",
|
|
||||||
"enum-as-inner 0.5.1",
|
|
||||||
"futures-channel",
|
|
||||||
"futures-io",
|
|
||||||
"futures-util",
|
|
||||||
"h2",
|
|
||||||
"http",
|
|
||||||
"idna 0.2.3",
|
|
||||||
"ipnet",
|
|
||||||
"lazy_static",
|
|
||||||
"rand 0.8.5",
|
|
||||||
"rustls 0.20.8",
|
|
||||||
"rustls-pemfile",
|
|
||||||
"smallvec",
|
|
||||||
"thiserror",
|
|
||||||
"tinyvec",
|
|
||||||
"tokio",
|
|
||||||
"tokio-rustls",
|
|
||||||
"tracing",
|
|
||||||
"url",
|
|
||||||
"webpki 0.22.0",
|
|
||||||
"webpki-roots 0.22.6",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "trust-dns-proto"
|
name = "trust-dns-proto"
|
||||||
version = "0.23.0"
|
version = "0.23.0"
|
||||||
@ -5906,45 +5855,55 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "0dc775440033cb114085f6f2437682b194fa7546466024b1037e82a48a052a69"
|
checksum = "0dc775440033cb114085f6f2437682b194fa7546466024b1037e82a48a052a69"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
"bytes",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
"enum-as-inner 0.6.0",
|
"enum-as-inner",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-io",
|
"futures-io",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"idna 0.4.0",
|
"h2",
|
||||||
|
"http",
|
||||||
|
"idna",
|
||||||
"ipnet",
|
"ipnet",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
|
"rustls 0.21.7",
|
||||||
|
"rustls-pemfile",
|
||||||
|
"rustls-webpki",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"socket2 0.5.3",
|
"socket2 0.5.3",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tinyvec",
|
"tinyvec",
|
||||||
|
"tokio",
|
||||||
|
"tokio-rustls 0.24.1",
|
||||||
"tracing",
|
"tracing",
|
||||||
"url",
|
"url",
|
||||||
|
"webpki-roots",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "trust-dns-resolver"
|
name = "trust-dns-resolver"
|
||||||
version = "0.22.0"
|
version = "0.23.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "aff21aa4dcefb0a1afbfac26deb0adc93888c7d295fb63ab273ef276ba2b7cfe"
|
checksum = "2dff7aed33ef3e8bf2c9966fccdfed93f93d46f432282ea875cd66faabc6ef2f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"ipconfig",
|
"ipconfig",
|
||||||
"lazy_static",
|
|
||||||
"lru-cache",
|
"lru-cache",
|
||||||
|
"once_cell",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
"rand 0.8.5",
|
||||||
"resolv-conf",
|
"resolv-conf",
|
||||||
"rustls 0.20.8",
|
"rustls 0.21.7",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-rustls",
|
"tokio-rustls 0.24.1",
|
||||||
"tracing",
|
"tracing",
|
||||||
"trust-dns-proto 0.22.0",
|
"trust-dns-proto",
|
||||||
"webpki-roots 0.22.6",
|
"webpki-roots",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -6090,7 +6049,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5"
|
checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"form_urlencoded",
|
"form_urlencoded",
|
||||||
"idna 0.4.0",
|
"idna",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -6335,15 +6294,6 @@ dependencies = [
|
|||||||
"untrusted",
|
"untrusted",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "webpki-roots"
|
|
||||||
version = "0.22.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87"
|
|
||||||
dependencies = [
|
|
||||||
"webpki 0.22.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webpki-roots"
|
name = "webpki-roots"
|
||||||
version = "0.25.2"
|
version = "0.25.2"
|
||||||
|
@ -11,13 +11,14 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
|
|||||||
categories = ["network-programming", "asynchronous"]
|
categories = ["network-programming", "asynchronous"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
async-trait = "0.1.72"
|
||||||
libp2p-core = { workspace = true }
|
libp2p-core = { workspace = true }
|
||||||
libp2p-identity = { workspace = true }
|
libp2p-identity = { workspace = true }
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
async-std-resolver = { version = "0.22", optional = true }
|
async-std-resolver = { version = "0.23", optional = true }
|
||||||
parking_lot = "0.12.0"
|
parking_lot = "0.12.0"
|
||||||
trust-dns-resolver = { version = "0.22", default-features = false, features = ["system-config"] }
|
trust-dns-resolver = { version = "0.23", default-features = false, features = ["system-config"] }
|
||||||
smallvec = "1.11.0"
|
smallvec = "1.11.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@ -58,7 +58,8 @@
|
|||||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||||
|
|
||||||
#[cfg(feature = "async-std")]
|
#[cfg(feature = "async-std")]
|
||||||
use async_std_resolver::{AsyncStdConnection, AsyncStdConnectionProvider};
|
use async_std_resolver::AsyncStdResolver;
|
||||||
|
use async_trait::async_trait;
|
||||||
use futures::{future::BoxFuture, prelude::*};
|
use futures::{future::BoxFuture, prelude::*};
|
||||||
use libp2p_core::{
|
use libp2p_core::{
|
||||||
connection::Endpoint,
|
connection::Endpoint,
|
||||||
@ -69,10 +70,10 @@ use libp2p_core::{
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
error, fmt, iter,
|
error, fmt, iter,
|
||||||
net::IpAddr,
|
|
||||||
ops::DerefMut,
|
ops::DerefMut,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
str,
|
str,
|
||||||
@ -81,12 +82,15 @@ use std::{
|
|||||||
};
|
};
|
||||||
#[cfg(any(feature = "async-std", feature = "tokio"))]
|
#[cfg(any(feature = "async-std", feature = "tokio"))]
|
||||||
use trust_dns_resolver::system_conf;
|
use trust_dns_resolver::system_conf;
|
||||||
use trust_dns_resolver::{proto::xfer::dns_handle::DnsHandle, AsyncResolver, ConnectionProvider};
|
|
||||||
#[cfg(feature = "tokio")]
|
#[cfg(feature = "tokio")]
|
||||||
use trust_dns_resolver::{TokioAsyncResolver, TokioConnection, TokioConnectionProvider};
|
use trust_dns_resolver::TokioAsyncResolver;
|
||||||
|
|
||||||
pub use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
pub use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
||||||
pub use trust_dns_resolver::error::{ResolveError, ResolveErrorKind};
|
pub use trust_dns_resolver::error::{ResolveError, ResolveErrorKind};
|
||||||
|
use trust_dns_resolver::lookup::{Ipv4Lookup, Ipv6Lookup, TxtLookup};
|
||||||
|
use trust_dns_resolver::lookup_ip::LookupIp;
|
||||||
|
use trust_dns_resolver::name_server::ConnectionProvider;
|
||||||
|
use trust_dns_resolver::AsyncResolver;
|
||||||
|
|
||||||
/// The prefix for `dnsaddr` protocol TXT record lookups.
|
/// The prefix for `dnsaddr` protocol TXT record lookups.
|
||||||
const DNSADDR_PREFIX: &str = "_dnsaddr.";
|
const DNSADDR_PREFIX: &str = "_dnsaddr.";
|
||||||
@ -109,23 +113,20 @@ const MAX_TXT_RECORDS: usize = 16;
|
|||||||
/// A `Transport` wrapper for performing DNS lookups when dialing `Multiaddr`esses
|
/// A `Transport` wrapper for performing DNS lookups when dialing `Multiaddr`esses
|
||||||
/// using `async-std` for all async I/O.
|
/// using `async-std` for all async I/O.
|
||||||
#[cfg(feature = "async-std")]
|
#[cfg(feature = "async-std")]
|
||||||
pub type DnsConfig<T> = GenDnsConfig<T, AsyncStdConnection, AsyncStdConnectionProvider>;
|
pub type DnsConfig<T> = GenDnsConfig<T, AsyncStdResolver>;
|
||||||
|
|
||||||
/// A `Transport` wrapper for performing DNS lookups when dialing `Multiaddr`esses
|
/// A `Transport` wrapper for performing DNS lookups when dialing `Multiaddr`esses
|
||||||
/// using `tokio` for all async I/O.
|
/// using `tokio` for all async I/O.
|
||||||
#[cfg(feature = "tokio")]
|
#[cfg(feature = "tokio")]
|
||||||
pub type TokioDnsConfig<T> = GenDnsConfig<T, TokioConnection, TokioConnectionProvider>;
|
pub type TokioDnsConfig<T> = GenDnsConfig<T, TokioAsyncResolver>;
|
||||||
|
|
||||||
/// A `Transport` wrapper for performing DNS lookups when dialing `Multiaddr`esses.
|
/// A `Transport` wrapper for performing DNS lookups when dialing `Multiaddr`esses.
|
||||||
pub struct GenDnsConfig<T, C, P>
|
#[derive(Debug)]
|
||||||
where
|
pub struct GenDnsConfig<T, R> {
|
||||||
C: DnsHandle<Error = ResolveError>,
|
|
||||||
P: ConnectionProvider<Conn = C>,
|
|
||||||
{
|
|
||||||
/// The underlying transport.
|
/// The underlying transport.
|
||||||
inner: Arc<Mutex<T>>,
|
inner: Arc<Mutex<T>>,
|
||||||
/// The DNS resolver used when dialing addresses with DNS components.
|
/// The DNS resolver used when dialing addresses with DNS components.
|
||||||
resolver: AsyncResolver<C, P>,
|
resolver: R,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "async-std")]
|
#[cfg(feature = "async-std")]
|
||||||
@ -145,9 +146,10 @@ where
|
|||||||
cfg: ResolverConfig,
|
cfg: ResolverConfig,
|
||||||
opts: ResolverOpts,
|
opts: ResolverOpts,
|
||||||
) -> Result<DnsConfig<T>, io::Error> {
|
) -> Result<DnsConfig<T>, io::Error> {
|
||||||
|
// TODO: Make infallible in next breaking release. Or deprecation?
|
||||||
Ok(DnsConfig {
|
Ok(DnsConfig {
|
||||||
inner: Arc::new(Mutex::new(inner)),
|
inner: Arc::new(Mutex::new(inner)),
|
||||||
resolver: async_std_resolver::resolver(cfg, opts).await?,
|
resolver: async_std_resolver::resolver(cfg, opts).await,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,31 +172,20 @@ where
|
|||||||
cfg: ResolverConfig,
|
cfg: ResolverConfig,
|
||||||
opts: ResolverOpts,
|
opts: ResolverOpts,
|
||||||
) -> Result<TokioDnsConfig<T>, io::Error> {
|
) -> Result<TokioDnsConfig<T>, io::Error> {
|
||||||
|
// TODO: Make infallible in next breaking release. Or deprecation?
|
||||||
Ok(TokioDnsConfig {
|
Ok(TokioDnsConfig {
|
||||||
inner: Arc::new(Mutex::new(inner)),
|
inner: Arc::new(Mutex::new(inner)),
|
||||||
resolver: TokioAsyncResolver::tokio(cfg, opts)?,
|
resolver: TokioAsyncResolver::tokio(cfg, opts),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, C, P> fmt::Debug for GenDnsConfig<T, C, P>
|
impl<T, R> Transport for GenDnsConfig<T, R>
|
||||||
where
|
|
||||||
C: DnsHandle<Error = ResolveError>,
|
|
||||||
P: ConnectionProvider<Conn = C>,
|
|
||||||
T: fmt::Debug,
|
|
||||||
{
|
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
fmt.debug_tuple("GenDnsConfig").field(&self.inner).finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, C, P> Transport for GenDnsConfig<T, C, P>
|
|
||||||
where
|
where
|
||||||
T: Transport + Send + Unpin + 'static,
|
T: Transport + Send + Unpin + 'static,
|
||||||
T::Error: Send,
|
T::Error: Send,
|
||||||
T::Dial: Send,
|
T::Dial: Send,
|
||||||
C: DnsHandle<Error = ResolveError>,
|
R: Clone + Send + Sync + Resolver + 'static,
|
||||||
P: ConnectionProvider<Conn = C>,
|
|
||||||
{
|
{
|
||||||
type Output = T::Output;
|
type Output = T::Output;
|
||||||
type Error = DnsErr<T::Error>;
|
type Error = DnsErr<T::Error>;
|
||||||
@ -247,13 +238,12 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, C, P> GenDnsConfig<T, C, P>
|
impl<T, R> GenDnsConfig<T, R>
|
||||||
where
|
where
|
||||||
T: Transport + Send + Unpin + 'static,
|
T: Transport + Send + Unpin + 'static,
|
||||||
T::Error: Send,
|
T::Error: Send,
|
||||||
T::Dial: Send,
|
T::Dial: Send,
|
||||||
C: DnsHandle<Error = ResolveError>,
|
R: Clone + Send + Sync + Resolver + 'static,
|
||||||
P: ConnectionProvider<Conn = C>,
|
|
||||||
{
|
{
|
||||||
fn do_dial(
|
fn do_dial(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -460,14 +450,10 @@ enum Resolved<'a> {
|
|||||||
/// Asynchronously resolves the domain name of a `Dns`, `Dns4`, `Dns6` or `Dnsaddr` protocol
|
/// Asynchronously resolves the domain name of a `Dns`, `Dns4`, `Dns6` or `Dnsaddr` protocol
|
||||||
/// component. If the given protocol is of a different type, it is returned unchanged as a
|
/// component. If the given protocol is of a different type, it is returned unchanged as a
|
||||||
/// [`Resolved::One`].
|
/// [`Resolved::One`].
|
||||||
fn resolve<'a, E: 'a + Send, C, P>(
|
fn resolve<'a, E: 'a + Send, R: Resolver>(
|
||||||
proto: &Protocol<'a>,
|
proto: &Protocol<'a>,
|
||||||
resolver: &'a AsyncResolver<C, P>,
|
resolver: &'a R,
|
||||||
) -> BoxFuture<'a, Result<Resolved<'a>, DnsErr<E>>>
|
) -> BoxFuture<'a, Result<Resolved<'a>, DnsErr<E>>> {
|
||||||
where
|
|
||||||
C: DnsHandle<Error = ResolveError>,
|
|
||||||
P: ConnectionProvider<Conn = C>,
|
|
||||||
{
|
|
||||||
match proto {
|
match proto {
|
||||||
Protocol::Dns(ref name) => resolver
|
Protocol::Dns(ref name) => resolver
|
||||||
.lookup_ip(name.clone().into_owned())
|
.lookup_ip(name.clone().into_owned())
|
||||||
@ -505,12 +491,12 @@ where
|
|||||||
iter::once(one)
|
iter::once(one)
|
||||||
.chain(iter::once(two))
|
.chain(iter::once(two))
|
||||||
.chain(ips)
|
.chain(ips)
|
||||||
.map(IpAddr::from)
|
.map(Ipv4Addr::from)
|
||||||
.map(Protocol::from)
|
.map(Protocol::from)
|
||||||
.collect(),
|
.collect(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(Resolved::One(Protocol::from(IpAddr::from(one))))
|
Ok(Resolved::One(Protocol::from(Ipv4Addr::from(one))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => Err(DnsErr::ResolveError(e)),
|
Err(e) => Err(DnsErr::ResolveError(e)),
|
||||||
@ -529,12 +515,12 @@ where
|
|||||||
iter::once(one)
|
iter::once(one)
|
||||||
.chain(iter::once(two))
|
.chain(iter::once(two))
|
||||||
.chain(ips)
|
.chain(ips)
|
||||||
.map(IpAddr::from)
|
.map(Ipv6Addr::from)
|
||||||
.map(Protocol::from)
|
.map(Protocol::from)
|
||||||
.collect(),
|
.collect(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(Resolved::One(Protocol::from(IpAddr::from(one))))
|
Ok(Resolved::One(Protocol::from(Ipv6Addr::from(one))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => Err(DnsErr::ResolveError(e)),
|
Err(e) => Err(DnsErr::ResolveError(e)),
|
||||||
@ -583,6 +569,37 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub trait Resolver {
|
||||||
|
async fn lookup_ip(&self, name: String) -> Result<LookupIp, ResolveError>;
|
||||||
|
async fn ipv4_lookup(&self, name: String) -> Result<Ipv4Lookup, ResolveError>;
|
||||||
|
async fn ipv6_lookup(&self, name: String) -> Result<Ipv6Lookup, ResolveError>;
|
||||||
|
async fn txt_lookup(&self, name: String) -> Result<TxtLookup, ResolveError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<C> Resolver for AsyncResolver<C>
|
||||||
|
where
|
||||||
|
C: ConnectionProvider,
|
||||||
|
{
|
||||||
|
async fn lookup_ip(&self, name: String) -> Result<LookupIp, ResolveError> {
|
||||||
|
self.lookup_ip(name).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn ipv4_lookup(&self, name: String) -> Result<Ipv4Lookup, ResolveError> {
|
||||||
|
self.ipv4_lookup(name).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn ipv6_lookup(&self, name: String) -> Result<Ipv6Lookup, ResolveError> {
|
||||||
|
self.ipv6_lookup(name).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn txt_lookup(&self, name: String) -> Result<TxtLookup, ResolveError> {
|
||||||
|
self.txt_lookup(name).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(test, any(feature = "tokio", feature = "async-std")))]
|
#[cfg(all(test, any(feature = "tokio", feature = "async-std")))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -647,13 +664,12 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run<T, C, P>(mut transport: GenDnsConfig<T, C, P>)
|
async fn run<T, R>(mut transport: GenDnsConfig<T, R>)
|
||||||
where
|
where
|
||||||
C: DnsHandle<Error = ResolveError>,
|
|
||||||
P: ConnectionProvider<Conn = C>,
|
|
||||||
T: Transport + Clone + Send + Unpin + 'static,
|
T: Transport + Clone + Send + Unpin + 'static,
|
||||||
T::Error: Send,
|
T::Error: Send,
|
||||||
T::Dial: Send,
|
T::Dial: Send,
|
||||||
|
R: Clone + Send + Sync + Resolver + 'static,
|
||||||
{
|
{
|
||||||
// Success due to existing A record for example.com.
|
// Success due to existing A record for example.com.
|
||||||
let _ = transport
|
let _ = transport
|
||||||
|
Loading…
x
Reference in New Issue
Block a user