| Crates.io | dnsaur |
| lib.rs | dnsaur |
| version | 0.1.0-alpha.0 |
| created_at | 2024-12-22 13:35:47.188733+00 |
| updated_at | 2024-12-22 13:35:47.188733+00 |
| description | An asynchronous DNS stub resolver |
| homepage | |
| repository | https://github.com/mselee/dnsaur |
| max_upload_size | |
| id | 1491949 |
| size | 40,139 |
An asynchronous DNS stub resolver.
The monoio async runtime does not ship with an asynchronous DNS resolver, and rather relies
on a threadpool to handle the blocking calls (like most other runtimes). This library aims to do the resolution in an async manner, including the file system access (using io_uring).
use std::net::IpAddr;
use std::time::Duration;
use std::collections::BTreeSet;
use dnsaur::{StubResolver, Error};
#[monoio::main(driver = "iouring", enable_timer = true)]
async fn main() -> Result<(), Error> {
let mut dns = dnsaur::StubResolver::load().await?;
// pairs of (ip, ttl)
let ips: Vec<(IpAddr, Duration)> = dns.lookup("example.com").await?;
let ips = dns.lookup::<BTreeSet<_>>("example.com").await?;
// reload
let _ = dns.reload().await?;
Ok(())
}
or if you want a global client instance, enable the feature global:
use std::net::IpAddr;
use std::time::Duration;
use std::collections::BTreeSet;
use dnsaur::Error;
#[monoio::main(driver = "iouring", enable_timer = true)]
async fn main() -> Result<(), Error> {
// pairs of (ip, ttl)
let ips: Vec<(IpAddr, Duration)> = dnsaur::lookup("example.com").await?;
let ips = dnsaur::lookup::<BTreeSet<_>>("example.com").await?;
// reload
let _ = dnsaur::reload().await?;
// autoreload
monoio::spawn(async {
loop {
monoio::time::sleep(Duration::from_secs(5 * 60)).await;
let _ = dnsaur::reload().await?;
}
Ok::<(), Error>(())
});
Ok(())
}
/etc/hosts and /etc/resolv.conf are parsed to build the configuration.hosts are tried first, and if not present, the nameservers from resolv.conf will be queried.| limitation | glibc | dnsaur |
|---|---|---|
nameserver |
3 | unlimited |
timeout |
30 | u8::MAX |
ndots |
15 | u8::MAX |
attempts |
5 | u8::MAX |
rotateHic Sunt Dracones
Mozilla Public License Version 2.0. See the LICENSE file for details.
This library is inspired by async-dns