replace ConnProvider with RuntimeProvider

This commit is contained in:
XOR-op
2023-01-16 00:15:40 +08:00
committed by Benjamin Fry
parent 3c3f14ddc5
commit 74bdef0d9a
18 changed files with 305 additions and 295 deletions

View File

@@ -96,9 +96,7 @@
use trust_dns_resolver::AsyncResolver;
pub use crate::runtime::AsyncStdConnection;
pub use crate::runtime::AsyncStdConnectionProvider;
use crate::runtime::AsyncStdRuntimeHandle;
use crate::runtime::AsyncStdRuntimeProvider;
mod net;
mod runtime;
@@ -106,6 +104,7 @@ mod runtime;
mod tests;
mod time;
use crate::proto::Executor;
pub use trust_dns_resolver::config;
pub use trust_dns_resolver::error::ResolveError;
pub use trust_dns_resolver::lookup;
@@ -113,7 +112,7 @@ pub use trust_dns_resolver::lookup_ip;
pub use trust_dns_resolver::proto;
/// An AsyncResolver used with async_std
pub type AsyncStdResolver = AsyncResolver<AsyncStdConnection, AsyncStdConnectionProvider>;
pub type AsyncStdResolver = AsyncResolver<AsyncStdRuntimeProvider>;
/// Construct a new async-std based `AsyncResolver` with the provided configuration.
///
@@ -132,7 +131,7 @@ pub async fn resolver(
config: config::ResolverConfig,
options: config::ResolverOpts,
) -> Result<AsyncStdResolver, ResolveError> {
AsyncStdResolver::new(config, options, AsyncStdRuntimeHandle)
AsyncStdResolver::new(config, options, AsyncStdRuntimeProvider::new())
}
/// Constructs a new async-std based Resolver with the system configuration.
@@ -141,5 +140,5 @@ pub async fn resolver(
#[cfg(any(unix, target_os = "windows"))]
#[cfg(feature = "system-config")]
pub async fn resolver_from_system_conf() -> Result<AsyncStdResolver, ResolveError> {
AsyncStdResolver::from_system_conf(AsyncStdRuntimeHandle)
AsyncStdResolver::from_system_conf(AsyncStdRuntimeProvider::new())
}

View File

@@ -6,15 +6,17 @@
// copied, modified, or distributed except according to those terms.
use std::future::Future;
use std::net::SocketAddr;
use std::pin::Pin;
use trust_dns_resolver::proto::error::ProtoError;
use trust_dns_resolver::proto::Executor;
use trust_dns_resolver::name_server::{
GenericConnection, GenericConnectionProvider, RuntimeProvider, Spawn,
};
use trust_dns_resolver::name_server::{RuntimeProvider, Spawn};
use crate::net::{AsyncStdTcpStream, AsyncStdUdpSocket};
use crate::proto::tcp::Connect;
use crate::proto::udp::UdpSocket;
use crate::time::AsyncStdTime;
/// The async_std runtime.
@@ -45,9 +47,9 @@ use crate::time::AsyncStdTime;
/// [mod]: index.html
/// [`new`]: #method.new
#[derive(Clone, Copy)]
pub struct AsyncStdRuntime;
pub struct AsyncStdRuntimeProvider;
impl Executor for AsyncStdRuntime {
impl Executor for AsyncStdRuntimeProvider {
fn new() -> Self {
Self {}
}
@@ -68,22 +70,34 @@ impl Spawn for AsyncStdRuntimeHandle {
}
}
impl RuntimeProvider for AsyncStdRuntime {
impl RuntimeProvider for AsyncStdRuntimeProvider {
type Handle = AsyncStdRuntimeHandle;
type Tcp = AsyncStdTcpStream;
type Timer = AsyncStdTime;
type Udp = AsyncStdUdpSocket;
type Tcp = AsyncStdTcpStream;
fn create_handle(&self) -> Self::Handle {
AsyncStdRuntimeHandle {}
}
fn connect_tcp(
&self,
server_addr: SocketAddr,
) -> Pin<Box<dyn Send + Future<Output = std::io::Result<Self::Tcp>>>> {
Box::pin(AsyncStdTcpStream::connect(server_addr))
}
fn bind_udp(
&self,
local_addr: SocketAddr,
) -> Pin<Box<dyn Send + Future<Output = std::io::Result<Self::Udp>>>> {
Box::pin(AsyncStdUdpSocket::bind(local_addr))
}
}
impl AsyncStdRuntime {
impl AsyncStdRuntimeProvider {
#[cfg(test)]
pub(crate) fn handle(&self) -> AsyncStdRuntimeHandle {
AsyncStdRuntimeHandle
}
}
/// AsyncStd default connection
pub type AsyncStdConnection = GenericConnection;
/// AsyncStd default connection provider
pub type AsyncStdConnectionProvider = GenericConnectionProvider<AsyncStdRuntime>;

View File

@@ -5,7 +5,7 @@ use crate::lookup::LookupFuture;
use crate::lookup_ip::LookupIpFuture;
use crate::proto::xfer::DnsRequest;
use crate::proto::Executor;
use crate::runtime::{AsyncStdConnection, AsyncStdRuntime};
use crate::runtime::{AsyncStdConnection, AsyncStdRuntimeProvider};
use crate::AsyncStdResolver;
use crate::ResolveError;
@@ -35,59 +35,71 @@ fn test_send_sync() {
#[test]
fn test_lookup_google() {
use testing::lookup_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
lookup_test::<AsyncStdRuntime, AsyncStdRuntime>(ResolverConfig::google(), io_loop, handle)
lookup_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(
ResolverConfig::google(),
io_loop,
handle,
)
}
#[test]
fn test_lookup_cloudflare() {
use testing::lookup_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
lookup_test::<AsyncStdRuntime, AsyncStdRuntime>(ResolverConfig::cloudflare(), io_loop, handle)
lookup_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(
ResolverConfig::cloudflare(),
io_loop,
handle,
)
}
#[test]
fn test_lookup_quad9() {
use testing::lookup_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
lookup_test::<AsyncStdRuntime, AsyncStdRuntime>(ResolverConfig::quad9(), io_loop, handle)
lookup_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(
ResolverConfig::quad9(),
io_loop,
handle,
)
}
#[test]
fn test_ip_lookup() {
use testing::ip_lookup_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
ip_lookup_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle)
ip_lookup_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle)
}
#[test]
fn test_ip_lookup_across_threads() {
use testing::ip_lookup_across_threads_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
ip_lookup_across_threads_test::<AsyncStdRuntime, AsyncStdRuntime>(handle)
ip_lookup_across_threads_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(handle)
}
#[test]
#[cfg(feature = "dnssec")]
fn test_sec_lookup() {
use testing::sec_lookup_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
sec_lookup_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
sec_lookup_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
#[cfg(feature = "dnssec")]
fn test_sec_lookup_fails() {
use testing::sec_lookup_fails_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
sec_lookup_fails_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
sec_lookup_fails_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
@@ -96,9 +108,9 @@ fn test_sec_lookup_fails() {
#[cfg(feature = "system-config")]
fn test_system_lookup() {
use testing::system_lookup_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
system_lookup_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
system_lookup_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
@@ -108,95 +120,101 @@ fn test_system_lookup() {
#[cfg(unix)]
fn test_hosts_lookup() {
use testing::hosts_lookup_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
hosts_lookup_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
hosts_lookup_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
fn test_fqdn() {
use testing::fqdn_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
fqdn_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
fqdn_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
fn test_ndots() {
use testing::ndots_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
ndots_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
ndots_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
fn test_large_ndots() {
use testing::large_ndots_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
large_ndots_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
large_ndots_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
fn test_domain_search() {
use testing::domain_search_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
domain_search_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
domain_search_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
fn test_search_list() {
use testing::search_list_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
search_list_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
search_list_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
fn test_idna() {
use testing::idna_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
idna_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
idna_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
fn test_localhost_ipv4() {
use testing::localhost_ipv4_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
localhost_ipv4_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
localhost_ipv4_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
fn test_localhost_ipv6() {
use testing::localhost_ipv6_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
localhost_ipv6_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
localhost_ipv6_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(io_loop, handle);
}
#[test]
fn test_search_ipv4_large_ndots() {
use testing::search_ipv4_large_ndots_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
search_ipv4_large_ndots_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
search_ipv4_large_ndots_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(
io_loop, handle,
);
}
#[test]
fn test_search_ipv6_large_ndots() {
use testing::search_ipv6_large_ndots_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
search_ipv6_large_ndots_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
search_ipv6_large_ndots_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(
io_loop, handle,
);
}
#[test]
fn test_search_ipv6_name_parse_fails() {
use testing::search_ipv6_name_parse_fails_test;
let io_loop = AsyncStdRuntime::new();
let io_loop = AsyncStdRuntimeProvider::new();
let handle = io_loop.handle();
search_ipv6_name_parse_fails_test::<AsyncStdRuntime, AsyncStdRuntime>(io_loop, handle);
search_ipv6_name_parse_fails_test::<AsyncStdRuntimeProvider, AsyncStdRuntimeProvider>(
io_loop, handle,
);
}