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:
Ferdinand Schober
2023-09-25 11:55:22 +02:00
committed by Ferdinand Schober
parent 603646c799
commit 06725f4b14
17 changed files with 908 additions and 432 deletions

View File

@@ -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())
}
}