
* update all READMEs with notices about the name change * update changelog for 0.24 * bump crate versions to 0.24 * update version notice information * update readmes to back reference trust-dns * rename all crates to hickory counterparts * replace all Trust-DNS references in code and comments with Hickory DNS * rename all Trust-DNS references to Hickory DNS in non-code * rename all trust-dns-resolver references to hickory-resolver * rename all trust-dns-client references to hickory-client * rename all trust-dns-proto references to hickory-proto * rename all trust-dns-server references to hickory-server * rename all trust-dns-compatibility references to hickory-compatability * rename all trust-dns-integration references to hickory-integration * rename all trust-dns-util references to hickory-util * Update MIT licenses to reference Hickory DNS * update all trust-dns references to hickory-dns * update all bluejekyll github references to hickorydns org * Update name in Changelog * make sure hickory-dns logs during tests * add changelogs for recent main additions * fix references to trust-dns and hickory in architecture * update a few trust-dns references in READMEs * fixup some dangling trust_dns references * replace fka with formerly in change log * replace all hickoydns org references to hickory-dns * replace all http links with https * update logos * update hickorydns to hickory-dns for all other org references * fix Notices of Trust-DNS to Hickory in each Readme
96 lines
3.0 KiB
Rust
96 lines
3.0 KiB
Rust
#![recursion_limit = "128"]
|
|
|
|
fn main() {
|
|
tokio::runtime::Builder::new_multi_thread()
|
|
.enable_all()
|
|
.build()
|
|
.unwrap()
|
|
.block_on(async {
|
|
tokio_main().await;
|
|
});
|
|
}
|
|
|
|
async fn tokio_main() {
|
|
use hickory_resolver::{name_server::TokioConnectionProvider, TokioAsyncResolver};
|
|
|
|
let resolver = {
|
|
// To make this independent, if targeting macOS, BSD, Linux, or Windows, we can use the system's configuration:
|
|
#[cfg(any(unix, windows))]
|
|
{
|
|
// use the system resolver configuration
|
|
TokioAsyncResolver::from_system_conf(TokioConnectionProvider::default())
|
|
}
|
|
|
|
// For other operating systems, we can use one of the preconfigured definitions
|
|
#[cfg(not(any(unix, windows)))]
|
|
{
|
|
// Directly reference the config types
|
|
use hickory_resolver::config::{ResolverConfig, ResolverOpts};
|
|
|
|
// Get a new resolver with the google nameservers as the upstream recursive resolvers
|
|
AsyncResolver::tokio(
|
|
ResolverConfig::quad9(),
|
|
ResolverOpts::default(),
|
|
//runtime.handle().clone(),
|
|
)
|
|
}
|
|
}
|
|
.map(std::sync::Arc::new)
|
|
.expect("failed to create resolver");
|
|
|
|
// Create some futures representing name lookups.
|
|
let names = ["hickory-dns.org.", "estada.ch.", "wikipedia.org."];
|
|
|
|
let first_resolve = resolve_list(&names, &*resolver).await;
|
|
let cached_resolve = resolve_list(&names, &*resolver).await;
|
|
|
|
resolver.clear_cache();
|
|
let second_resolve = resolve_list(&names, &*resolver).await;
|
|
|
|
println!("first_resolve: {first_resolve:?}");
|
|
println!("cached_resolve: {cached_resolve:?}");
|
|
println!("second_resolve: {second_resolve:?}");
|
|
|
|
// Drop the resolver, which means that the runtime will become idle.
|
|
drop(resolver);
|
|
}
|
|
|
|
async fn resolve_list<P: hickory_resolver::name_server::ConnectionProvider>(
|
|
names: &[&str],
|
|
resolver: &hickory_resolver::AsyncResolver<P>,
|
|
) -> tokio::time::Duration {
|
|
use tokio::time::Instant;
|
|
let start_time = Instant::now();
|
|
|
|
// Create the resolve requests first
|
|
let futures = names
|
|
.iter()
|
|
.map(|name: &&str| {
|
|
let name: String = name.to_string();
|
|
let resolver = resolver.clone();
|
|
let future = {
|
|
let name = name.clone();
|
|
tokio::spawn(async move { resolver.txt_lookup(name).await })
|
|
};
|
|
(name, future)
|
|
})
|
|
.collect::<Vec<_>>();
|
|
|
|
// Go through the list of resolution operations in parallel and wait for them to complete.
|
|
for (name, lookup) in futures {
|
|
let txts = lookup.await.expect("unable to spawn resolver").map(|txt| {
|
|
txt.iter()
|
|
.map(|rdata| rdata.to_string())
|
|
.collect::<Vec<_>>()
|
|
});
|
|
println!(" {name} returned to {txts:?}");
|
|
}
|
|
println!();
|
|
start_time.elapsed()
|
|
}
|
|
|
|
#[test]
|
|
fn test_flush_cache() {
|
|
main()
|
|
}
|