mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-05 23:41:27 +03:00
Frontend improvement (#27)
* removed redundant dns lookups * frontend now correctly reflects the state of the backend * config.toml is loaded when starting gtk frontend
This commit is contained in:
committed by
Ferdinand Schober
parent
603646c799
commit
06725f4b14
19
src/dns.rs
19
src/dns.rs
@@ -1,9 +1,20 @@
|
||||
use anyhow::Result;
|
||||
use std::{error::Error, net::IpAddr};
|
||||
|
||||
use trust_dns_resolver::Resolver;
|
||||
|
||||
pub fn resolve(host: &str) -> Result<Vec<IpAddr>, Box<dyn Error>> {
|
||||
log::info!("resolving {host} ...");
|
||||
let response = Resolver::from_system_conf()?.lookup_ip(host)?;
|
||||
Ok(response.iter().collect())
|
||||
pub(crate) struct DnsResolver {
|
||||
resolver: Resolver,
|
||||
}
|
||||
impl DnsResolver {
|
||||
pub(crate) fn new() -> Result<Self> {
|
||||
let resolver = Resolver::from_system_conf()?;
|
||||
Ok(Self { resolver })
|
||||
}
|
||||
|
||||
pub(crate) fn resolve(&self, host: &str) -> Result<Vec<IpAddr>, Box<dyn Error>> {
|
||||
log::info!("resolving {host} ...");
|
||||
let response = self.resolver.lookup_ip(host)?;
|
||||
Ok(response.iter().collect())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user