use trillium_client::Client;
use trillium_quinn::ClientQuicConfig;
use trillium_rustls::RustlsConfig;
use trillium_tokio::{ClientConfig, TokioRuntime};
fn main() {
env_logger::init();
let mut args = std::env::args().skip(1);
let resolvers: Vec<String> = match args.next() {
Some(resolver) => vec![resolver],
None => vec!["1.1.1.1".into(), "8.8.8.8".into()],
};
let urls: Vec<String> = {
let rest: Vec<String> = args.collect();
if rest.is_empty() {
[
"https://www.cloudflare.com/",
"https://blog.cloudflare.com/",
"https://example.com/",
]
.into_iter()
.map(String::from)
.collect()
} else {
rest
}
};
TokioRuntime::default().block_on(async move {
for resolver in &resolvers {
println!("\n=== routing all DNS through {resolver} ===");
let client = Client::new_with_quic(
RustlsConfig::<ClientConfig>::default(),
ClientQuicConfig::with_webpki_roots(),
);
let client = if std::env::var("DOH_HTTP3").is_ok() {
client.with_doh3(resolver)
} else {
client.with_doh(resolver)
};
for url in &urls {
match client.get(url.as_str()).await {
Ok(conn) => {
let version = conn.http_version();
let status = conn.status().map(|s| s.to_string()).unwrap_or_default();
println!(" {status} via {version:?} {url}");
}
Err(e) => println!(" error — {e} {url}"),
}
}
}
});
}