Skip to main content

idot/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3mod dot;
4mod error;
5
6use std::net::{IpAddr, Ipv4Addr};
7
8pub use dot::Dot;
9pub use error::{Error, Result};
10use hipstr::HipStr;
11use idns::Answer;
12pub use idns::QType;
13
14/// Host with IP / 主机与 IP
15#[derive(Debug, Clone)]
16pub struct HostIp {
17  pub host: HipStr<'static>,
18  pub ip: IpAddr,
19}
20
21impl idns::Query for Dot {
22  type Error = Error;
23
24  async fn answer_li(&self, qtype: QType, name: &str) -> Result<Option<Vec<Answer>>> {
25    self.query(name, qtype).await
26  }
27}
28
29/// Create HostIp from host and IPv4 / 从主机名和 IPv4 创建 HostIp
30pub const fn host_ip(host: &'static str, a: u8, b: u8, c: u8, d: u8) -> HostIp {
31  HostIp {
32    host: HipStr::borrowed(host),
33    ip: IpAddr::V4(Ipv4Addr::new(a, b, c, d)),
34  }
35}
36
37/// DoT server hostnames / DoT 服务器域名
38pub mod dns {
39  pub const CLOUDFLARE: &str = "cloudflare-dns.com";
40  pub const GOOGLE: &str = "dns.google";
41  pub const QUAD9: &str = "dns.quad9.net";
42  /// 360 安全 DNS(中国)
43  pub const DNS360: &str = "dot.360.cn";
44  /// TWNIC(台湾)- 证书只对 IP 有效
45  pub const TWNIC: &str = "101.101.101.101";
46  /// IIJ DNS(日本)
47  pub const IIJ: &str = "public.dns.iij.jp";
48  /// 阿里 DNS(中国)
49  pub const ALIDNS: &str = "dns.alidns.com";
50  /// 腾讯 DNSPod(中国)
51  pub const DNSPOD: &str = "dot.pub";
52}
53
54/// Create Dot clients from HostIp list / 从 HostIp 列表创建 Dot 客户端
55pub fn dot_li(li: &[HostIp]) -> Vec<Dot> {
56  li.iter().map(|s| Dot::new(s.clone())).collect()
57}
58
59/// DoT server list / DoT 服务器列表
60pub const DOT_LI: &[HostIp] = &[
61  host_ip(dns::CLOUDFLARE, 1, 1, 1, 1),
62  host_ip(dns::CLOUDFLARE, 1, 0, 0, 1),
63  host_ip(dns::GOOGLE, 8, 8, 8, 8),
64  host_ip(dns::GOOGLE, 8, 8, 4, 4),
65  host_ip(dns::QUAD9, 9, 9, 9, 9),
66  // 360 安全 DNS(中国,无过滤)
67  host_ip(dns::DNS360, 101, 226, 4, 6),
68  host_ip(dns::DNS360, 218, 30, 118, 6),
69  // TWNIC(台湾)
70  host_ip(dns::TWNIC, 101, 101, 101, 101),
71  // IIJ DNS(日本)
72  host_ip(dns::IIJ, 103, 2, 57, 5),
73  // 阿里 DNS:对大量 TXT 记录(如 salesforce.com 34 条)返回 0 条或不完整
74  // host_ip(dns::ALIDNS, 223, 5, 5, 5),
75  // host_ip(dns::ALIDNS, 223, 6, 6, 6),
76  // 腾讯 DNSPod:1.12.12.12 返回 early eof,120.53.53.53 只返回 4 条 TXT
77  // host_ip(dns::DNSPOD, 1, 12, 12, 12),
78  // host_ip(dns::DNSPOD, 120, 53, 53, 53),
79];
80
81#[cfg(feature = "static")]
82#[static_init::dynamic(lazy)]
83pub static DOT: idns::DnsRace<Dot> = idns::DnsRace::new(dot_li(DOT_LI));