feat(WIP): change relevant types

This commit is contained in:
XOR-op
2023-05-19 16:34:31 +08:00
committed by Benjamin Fry
parent 0901b1d591
commit 5ab85e297d
13 changed files with 198 additions and 194 deletions

View File

@@ -25,8 +25,7 @@ use crate::error::*;
use crate::lookup::{self, Lookup, LookupEither, LookupFuture};
use crate::lookup_ip::{LookupIp, LookupIpFuture};
#[cfg(feature = "tokio-runtime")]
use crate::name_server::TokioRuntimeProvider;
use crate::name_server::{NameServerPool, RuntimeProvider};
use crate::name_server::{ConnectionProvider, NameServerPool, TokioConnectionProvider};
use crate::Hosts;
@@ -57,7 +56,7 @@ use crate::Hosts;
/// linked to it. When all of its [`AsyncResolver`]s have been dropped, the
/// background future will finish.
#[derive(Clone)]
pub struct AsyncResolver<P: RuntimeProvider> {
pub struct AsyncResolver<P: ConnectionProvider> {
config: ResolverConfig,
options: ResolverOpts,
client_cache: CachingClient<LookupEither<P>, ResolveError>,
@@ -67,7 +66,7 @@ pub struct AsyncResolver<P: RuntimeProvider> {
/// An AsyncResolver used with Tokio
#[cfg(feature = "tokio-runtime")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio-runtime")))]
pub type TokioAsyncResolver = AsyncResolver<TokioRuntimeProvider>;
pub type TokioAsyncResolver = AsyncResolver<TokioConnectionProvider>;
macro_rules! lookup_fn {
($p:ident, $l:ty, $r:path) => {
@@ -119,7 +118,7 @@ impl TokioAsyncResolver {
/// documentation for `AsyncResolver` for more information on how to use
/// the background future.
pub fn tokio(config: ResolverConfig, options: ResolverOpts) -> Self {
Self::new(config, options, TokioRuntimeProvider::new())
Self::new(config, options, TokioConnectionProvider::default())
}
/// Constructs a new Tokio based Resolver with the system configuration.
@@ -132,11 +131,11 @@ impl TokioAsyncResolver {
doc(cfg(all(feature = "system-config", any(unix, target_os = "windows"))))
)]
pub fn tokio_from_system_conf() -> Result<Self, ResolveError> {
Self::from_system_conf(TokioRuntimeProvider::new())
Self::from_system_conf(TokioConnectionProvider::default())
}
}
impl<R: RuntimeProvider> AsyncResolver<R> {
impl<R: ConnectionProvider> AsyncResolver<R> {
/// Construct a new generic `AsyncResolver` with the provided configuration.
///
/// see [TokioAsyncResolver::tokio(..)] instead.
@@ -177,7 +176,7 @@ impl<R: RuntimeProvider> AsyncResolver<R> {
}
}
impl<P: RuntimeProvider> AsyncResolver<P> {
impl<P: ConnectionProvider> AsyncResolver<P> {
/// Construct a new `AsyncResolver` with the provided configuration.
///
/// # Arguments
@@ -441,7 +440,7 @@ impl<P: RuntimeProvider> AsyncResolver<P> {
lookup_fn!(txt_lookup, lookup::TxtLookup, RecordType::TXT);
}
impl<P: RuntimeProvider> fmt::Debug for AsyncResolver<P> {
impl<P: ConnectionProvider> fmt::Debug for AsyncResolver<P> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("AsyncResolver")
.field("request_tx", &"...")
@@ -457,12 +456,12 @@ pub mod testing {
use std::{net::*, str::FromStr};
use crate::config::{LookupIpStrategy, NameServerConfig, ResolverConfig, ResolverOpts};
use crate::name_server::RuntimeProvider;
use crate::name_server::ConnectionProvider;
use crate::AsyncResolver;
use proto::{rr::Name, Executor};
/// Test IP lookup from URLs.
pub fn lookup_test<E: Executor, R: RuntimeProvider>(
pub fn lookup_test<E: Executor, R: ConnectionProvider>(
config: ResolverConfig,
mut exec: E,
handle: R,
@@ -489,7 +488,7 @@ pub mod testing {
}
/// Test IP lookup from IP literals.
pub fn ip_lookup_test<E: Executor, R: RuntimeProvider>(mut exec: E, handle: R) {
pub fn ip_lookup_test<E: Executor, R: ConnectionProvider>(mut exec: E, handle: R) {
let resolver =
AsyncResolver::<R>::new(ResolverConfig::default(), ResolverOpts::default(), handle);
@@ -515,7 +514,7 @@ pub mod testing {
}
/// Test IP lookup from IP literals across threads.
pub fn ip_lookup_across_threads_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn ip_lookup_across_threads_test<E: Executor + Send + 'static, R: ConnectionProvider>(
handle: R,
) {
// Test ensuring that running the background task on a separate
@@ -567,7 +566,7 @@ pub mod testing {
/// Test IP lookup from URLs with DNSSEC validation.
#[cfg(feature = "dnssec")]
#[cfg_attr(docsrs, doc(cfg(feature = "dnssec")))]
pub fn sec_lookup_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn sec_lookup_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -607,7 +606,7 @@ pub mod testing {
#[allow(deprecated)]
#[cfg(feature = "dnssec")]
#[cfg_attr(docsrs, doc(cfg(feature = "dnssec")))]
pub fn sec_lookup_fails_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn sec_lookup_fails_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -650,7 +649,7 @@ pub mod testing {
/// Test AsyncResolver created from system configuration with IP lookup.
#[cfg(feature = "system-config")]
#[cfg_attr(docsrs, doc(cfg(feature = "system-config")))]
pub fn system_lookup_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn system_lookup_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -679,7 +678,7 @@ pub mod testing {
/// Test AsyncResolver created from system configuration with host lookups.
#[cfg(feature = "system-config")]
#[cfg_attr(docsrs, doc(cfg(feature = "system-config")))]
pub fn hosts_lookup_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn hosts_lookup_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -701,7 +700,7 @@ pub mod testing {
}
/// Test fqdn.
pub fn fqdn_test<E: Executor + Send + 'static, R: RuntimeProvider>(mut exec: E, handle: R) {
pub fn fqdn_test<E: Executor + Send + 'static, R: ConnectionProvider>(mut exec: E, handle: R) {
let domain = Name::from_str("incorrect.example.com.").unwrap();
let search = vec![
Name::from_str("bad.example.com.").unwrap(),
@@ -734,7 +733,7 @@ pub mod testing {
}
/// Test ndots with non-fqdn.
pub fn ndots_test<E: Executor + Send + 'static, R: RuntimeProvider>(mut exec: E, handle: R) {
pub fn ndots_test<E: Executor + Send + 'static, R: ConnectionProvider>(mut exec: E, handle: R) {
let domain = Name::from_str("incorrect.example.com.").unwrap();
let search = vec![
Name::from_str("bad.example.com.").unwrap(),
@@ -770,7 +769,7 @@ pub mod testing {
}
/// Test large ndots with non-fqdn.
pub fn large_ndots_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn large_ndots_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -809,7 +808,7 @@ pub mod testing {
}
/// Test domain search.
pub fn domain_search_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn domain_search_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -849,7 +848,7 @@ pub mod testing {
}
/// Test search lists.
pub fn search_list_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn search_list_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -888,7 +887,7 @@ pub mod testing {
}
/// Test idna.
pub fn idna_test<E: Executor + Send + 'static, R: RuntimeProvider>(mut exec: E, handle: R) {
pub fn idna_test<E: Executor + Send + 'static, R: ConnectionProvider>(mut exec: E, handle: R) {
let resolver =
AsyncResolver::<R>::new(ResolverConfig::default(), ResolverOpts::default(), handle);
@@ -902,7 +901,7 @@ pub mod testing {
}
/// Test ipv4 localhost.
pub fn localhost_ipv4_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn localhost_ipv4_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -927,7 +926,7 @@ pub mod testing {
}
/// Test ipv6 localhost.
pub fn localhost_ipv6_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn localhost_ipv6_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -952,7 +951,7 @@ pub mod testing {
}
/// Test ipv4 search with large ndots.
pub fn search_ipv4_large_ndots_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn search_ipv4_large_ndots_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -981,7 +980,7 @@ pub mod testing {
}
/// Test ipv6 search with large ndots.
pub fn search_ipv6_large_ndots_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn search_ipv6_large_ndots_test<E: Executor + Send + 'static, R: ConnectionProvider>(
mut exec: E,
handle: R,
) {
@@ -1010,7 +1009,10 @@ pub mod testing {
}
/// Test ipv6 name parse fails.
pub fn search_ipv6_name_parse_fails_test<E: Executor + Send + 'static, R: RuntimeProvider>(
pub fn search_ipv6_name_parse_fails_test<
E: Executor + Send + 'static,
R: ConnectionProvider,
>(
mut exec: E,
handle: R,
) {
@@ -1046,7 +1048,7 @@ mod tests {
use tokio::runtime::Runtime;
use crate::config::{ResolverConfig, ResolverOpts};
use crate::name_server::{GenericConnection, TokioRuntimeProvider};
use crate::name_server::GenericConnection;
use super::*;
@@ -1065,8 +1067,8 @@ mod tests {
assert!(is_send_t::<ResolverOpts>());
assert!(is_sync_t::<ResolverOpts>());
assert!(is_send_t::<AsyncResolver<TokioRuntimeProvider>>());
assert!(is_sync_t::<AsyncResolver<TokioRuntimeProvider>>());
assert!(is_send_t::<AsyncResolver<TokioConnectionProvider>>());
assert!(is_sync_t::<AsyncResolver<TokioConnectionProvider>>());
assert!(is_send_t::<DnsRequest>());
assert!(is_send_t::<LookupIpFuture<GenericConnection, ResolveError>>());
@@ -1077,40 +1079,44 @@ mod tests {
fn test_lookup_google() {
use super::testing::lookup_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime");
let handle = TokioRuntimeProvider::new();
lookup_test::<Runtime, TokioRuntimeProvider>(ResolverConfig::google(), io_loop, handle)
let handle = TokioConnectionProvider::default();
lookup_test::<Runtime, TokioConnectionProvider>(ResolverConfig::google(), io_loop, handle)
}
#[test]
fn test_lookup_cloudflare() {
use super::testing::lookup_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime");
let handle = TokioRuntimeProvider::new();
lookup_test::<Runtime, TokioRuntimeProvider>(ResolverConfig::cloudflare(), io_loop, handle)
let handle = TokioConnectionProvider::default();
lookup_test::<Runtime, TokioConnectionProvider>(
ResolverConfig::cloudflare(),
io_loop,
handle,
)
}
#[test]
fn test_lookup_quad9() {
use super::testing::lookup_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime");
let handle = TokioRuntimeProvider::new();
lookup_test::<Runtime, TokioRuntimeProvider>(ResolverConfig::quad9(), io_loop, handle)
let handle = TokioConnectionProvider::default();
lookup_test::<Runtime, TokioConnectionProvider>(ResolverConfig::quad9(), io_loop, handle)
}
#[test]
fn test_ip_lookup() {
use super::testing::ip_lookup_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime");
let handle = TokioRuntimeProvider::new();
ip_lookup_test::<Runtime, TokioRuntimeProvider>(io_loop, handle)
let handle = TokioConnectionProvider::default();
ip_lookup_test::<Runtime, TokioConnectionProvider>(io_loop, handle)
}
#[test]
fn test_ip_lookup_across_threads() {
use super::testing::ip_lookup_across_threads_test;
let _io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
ip_lookup_across_threads_test::<Runtime, TokioRuntimeProvider>(handle)
let handle = TokioConnectionProvider::default();
ip_lookup_across_threads_test::<Runtime, TokioConnectionProvider>(handle)
}
#[test]
@@ -1118,8 +1124,8 @@ mod tests {
fn test_sec_lookup() {
use super::testing::sec_lookup_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
sec_lookup_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
sec_lookup_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
@@ -1127,8 +1133,8 @@ mod tests {
fn test_sec_lookup_fails() {
use super::testing::sec_lookup_fails_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
sec_lookup_fails_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
sec_lookup_fails_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
@@ -1138,8 +1144,8 @@ mod tests {
fn test_system_lookup() {
use super::testing::system_lookup_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
system_lookup_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
system_lookup_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
@@ -1150,105 +1156,105 @@ mod tests {
fn test_hosts_lookup() {
use super::testing::hosts_lookup_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
hosts_lookup_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
hosts_lookup_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_fqdn() {
use super::testing::fqdn_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
fqdn_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
fqdn_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_ndots() {
use super::testing::ndots_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
ndots_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
ndots_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_large_ndots() {
use super::testing::large_ndots_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
large_ndots_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
large_ndots_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_domain_search() {
use super::testing::domain_search_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
domain_search_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
domain_search_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_search_list() {
use super::testing::search_list_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
search_list_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
search_list_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_idna() {
use super::testing::idna_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
idna_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
idna_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_localhost_ipv4() {
use super::testing::localhost_ipv4_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
localhost_ipv4_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
localhost_ipv4_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_localhost_ipv6() {
use super::testing::localhost_ipv6_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
localhost_ipv6_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
localhost_ipv6_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_search_ipv4_large_ndots() {
use super::testing::search_ipv4_large_ndots_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
search_ipv4_large_ndots_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
search_ipv4_large_ndots_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_search_ipv6_large_ndots() {
use super::testing::search_ipv6_large_ndots_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
search_ipv6_large_ndots_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
search_ipv6_large_ndots_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_search_ipv6_name_parse_fails() {
use super::testing::search_ipv6_name_parse_fails_test;
let io_loop = Runtime::new().expect("failed to create tokio runtime io_loop");
let handle = TokioRuntimeProvider::new();
search_ipv6_name_parse_fails_test::<Runtime, TokioRuntimeProvider>(io_loop, handle);
let handle = TokioConnectionProvider::default();
search_ipv6_name_parse_fails_test::<Runtime, TokioConnectionProvider>(io_loop, handle);
}
#[test]
fn test_build_names_onion() {
let handle = TokioRuntimeProvider::new();
let handle = TokioConnectionProvider::default();
let mut config = ResolverConfig::default();
config.add_search(Name::from_ascii("example.com.").unwrap());
let resolver =
AsyncResolver::<TokioRuntimeProvider>::new(config, ResolverOpts::default(), handle);
AsyncResolver::<TokioConnectionProvider>::new(config, ResolverOpts::default(), handle);
let tor_address = [
Name::from_ascii("2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid.onion")
.unwrap(),