mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-08 04:20:01 +03:00
- manual eventloop now replaced by asycn-await using the tokio runtime - dns no longer blocks the event loop - simplifies logic - makes xdg-desktop-portal easier to integrate
24 lines
685 B
Rust
24 lines
685 B
Rust
use anyhow::Result;
|
|
use std::{error::Error, net::IpAddr};
|
|
|
|
use trust_dns_resolver::TokioAsyncResolver;
|
|
|
|
pub(crate) struct DnsResolver {
|
|
resolver: TokioAsyncResolver,
|
|
}
|
|
impl DnsResolver {
|
|
pub(crate) async fn new() -> Result<Self> {
|
|
let resolver = TokioAsyncResolver::tokio_from_system_conf()?;
|
|
Ok(Self { resolver })
|
|
}
|
|
|
|
pub(crate) async fn resolve(&self, host: &str) -> Result<Vec<IpAddr>, Box<dyn Error>> {
|
|
log::info!("resolving {host} ...");
|
|
let response = self.resolver.lookup_ip(host).await?;
|
|
for ip in response.iter() {
|
|
log::info!("{host}: adding ip {ip}");
|
|
}
|
|
Ok(response.iter().collect())
|
|
}
|
|
}
|