#![cfg_attr(docsrs, feature(doc_cfg))]
mod dot;
mod error;
use std::net::{IpAddr, Ipv4Addr};
pub use dot::Dot;
pub use error::{Error, Result};
use idns::Answer;
pub use idns::QType;
use hipstr::HipStr;
#[derive(Debug, Clone)]
pub struct HostIp {
pub host: HipStr<'static>,
pub ip: IpAddr,
}
impl idns::Query for Dot {
type Error = Error;
async fn answer_li(&self, qtype: QType, name: &str) -> Result<Option<Vec<Answer>>> {
self.query(name, qtype).await
}
}
pub const fn host_ip(host: &'static str, a: u8, b: u8, c: u8, d: u8) -> HostIp {
HostIp {
host: HipStr::borrowed(host),
ip: IpAddr::V4(Ipv4Addr::new(a, b, c, d)),
}
}
pub mod dns {
pub const CLOUDFLARE: &str = "cloudflare-dns.com";
pub const GOOGLE: &str = "dns.google";
pub const QUAD9: &str = "dns.quad9.net";
pub const DNS360: &str = "dot.360.cn";
pub const TWNIC: &str = "101.101.101.101";
pub const IIJ: &str = "public.dns.iij.jp";
pub const ALIDNS: &str = "dns.alidns.com";
pub const DNSPOD: &str = "dot.pub";
}
pub fn dot_li(li: &[HostIp]) -> Vec<Dot> {
li.iter().map(|s| Dot::new(s.clone())).collect()
}
pub const DOT_LI: &[HostIp] = &[
host_ip(dns::CLOUDFLARE, 1, 1, 1, 1),
host_ip(dns::CLOUDFLARE, 1, 0, 0, 1),
host_ip(dns::GOOGLE, 8, 8, 8, 8),
host_ip(dns::GOOGLE, 8, 8, 4, 4),
host_ip(dns::QUAD9, 9, 9, 9, 9),
host_ip(dns::DNS360, 101, 226, 4, 6),
host_ip(dns::DNS360, 218, 30, 118, 6),
host_ip(dns::TWNIC, 101, 101, 101, 101),
host_ip(dns::IIJ, 103, 2, 57, 5),
];
#[cfg(feature = "static")]
#[static_init::dynamic(lazy)]
pub static DOT: idns::DnsRace<Dot> = idns::DnsRace::new(dot_li(DOT_LI));