summaryrefslogtreecommitdiff
path: root/resolver/src/lib.rs
blob: 98df31758ff8c9803a47b756585e8e6cf769367e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::net::SocketAddr;
use server::handle_query;
use tokio::net::UdpSocket;
use packet::Result;

mod server;
mod config;

pub use config::Config as Config;

pub struct DnsResolver {
    config: Config
}

impl DnsResolver {

    pub fn new(config: Config) -> Self {
        Self { config }
    }

    pub async fn bind(self, addr: SocketAddr) -> Result<()> {

        let socket = UdpSocket::bind(addr).await?;

        loop {
            match handle_query(&socket, &self.config).await {
                Ok(_) => {}
                Err(e) => eprintln!("An error occurred: {e}"),
            }
        }
    }

}