diff --git a/Cargo.lock b/Cargo.lock index ac62ecb11..07655d177 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -746,6 +746,10 @@ dependencies = [ "foreign-types-shared", "futures", "h2", + "hickory-client", + "hickory-proto", + "hickory-resolver", + "hickory-server", "hmac", "http", "httparse", @@ -792,10 +796,6 @@ dependencies = [ "tracing-oslog", "tracing-subscriber", "tracing-timing", - "trust-dns-client", - "trust-dns-proto 0.23.0 (git+https://github.com/Watfaq/trust-dns.git?rev=a6a7b2c)", - "trust-dns-resolver 0.23.0 (git+https://github.com/Watfaq/trust-dns.git?rev=a6a7b2c)", - "trust-dns-server", "tun", "url", "uuid", @@ -1146,15 +1146,6 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" -[[package]] -name = "drain" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f1a0abf3fcefad9b4dd0e414207a7408e12b68414a01e6bb19b897d5bd7632d" -dependencies = [ - "tokio", -] - [[package]] name = "ecdsa" version = "0.14.8" @@ -1649,6 +1640,106 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hickory-client" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f3e08124cf0ddda93b1186d4af73599de401f3b52f14cd9aaa719049379462e" +dependencies = [ + "cfg-if", + "data-encoding", + "futures-channel", + "futures-util", + "hickory-proto", + "once_cell", + "radix_trie", + "rand", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "hickory-proto" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "091a6fbccf4860009355e3efc52ff4acf37a63489aad7435372d44ceeb6fbbcf" +dependencies = [ + "async-trait", + "bytes", + "cfg-if", + "data-encoding", + "enum-as-inner 0.6.0", + "futures-channel", + "futures-io", + "futures-util", + "h2", + "http", + "idna 0.4.0", + "ipnet", + "once_cell", + "rand", + "ring", + "rustls", + "rustls-pemfile", + "serde", + "thiserror", + "tinyvec", + "tokio", + "tokio-rustls", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35b8f021164e6a984c9030023544c57789c51760065cd510572fedcfb04164e8" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot 0.12.1", + "rand", + "resolv-conf", + "rustls", + "serde", + "smallvec", + "thiserror", + "tokio", + "tokio-rustls", + "tracing", +] + +[[package]] +name = "hickory-server" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fbbb45bc4dcb456445732c705e3cfdc7393b8bcae5c36ecec36b9d76bd67cb5" +dependencies = [ + "async-trait", + "bytes", + "cfg-if", + "enum-as-inner 0.6.0", + "futures-util", + "h2", + "hickory-proto", + "hickory-resolver", + "http", + "rustls", + "serde", + "thiserror", + "time", + "tokio", + "tokio-rustls", + "tokio-util 0.7.9", + "tracing", +] + [[package]] name = "hkdf" version = "0.12.3" @@ -3178,15 +3269,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_spanned" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" -dependencies = [ - "serde", -] - [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -3266,7 +3348,7 @@ dependencies = [ "thiserror", "tokio", "tokio-tfo", - "trust-dns-resolver 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "trust-dns-resolver", "url", "windows-sys", ] @@ -3711,40 +3793,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "toml" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.0.0", - "serde", - "serde_spanned", - "toml_datetime", - "winnow", -] - [[package]] name = "tonic" version = "0.10.2" @@ -3940,24 +3988,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "trust-dns-client" -version = "0.23.0" -source = "git+https://github.com/Watfaq/trust-dns.git?rev=a6a7b2c#a6a7b2c9ba9907cd63375aa6de44a45662072f4b" -dependencies = [ - "cfg-if", - "data-encoding", - "futures-channel", - "futures-util", - "once_cell", - "radix_trie", - "rand", - "thiserror", - "tokio", - "tracing", - "trust-dns-proto 0.23.0 (git+https://github.com/Watfaq/trust-dns.git?rev=a6a7b2c)", -] - [[package]] name = "trust-dns-proto" version = "0.22.0" @@ -4007,38 +4037,6 @@ dependencies = [ "url", ] -[[package]] -name = "trust-dns-proto" -version = "0.23.0" -source = "git+https://github.com/Watfaq/trust-dns.git?rev=a6a7b2c#a6a7b2c9ba9907cd63375aa6de44a45662072f4b" -dependencies = [ - "async-trait", - "bytes", - "cfg-if", - "data-encoding", - "enum-as-inner 0.6.0", - "futures-channel", - "futures-io", - "futures-util", - "h2", - "http", - "idna 0.4.0", - "ipnet", - "once_cell", - "rand", - "ring", - "rustls", - "rustls-pemfile", - "serde", - "smallvec", - "thiserror", - "tinyvec", - "tokio", - "tokio-rustls", - "tracing", - "url", -] - [[package]] name = "trust-dns-resolver" version = "0.23.0" @@ -4057,56 +4055,7 @@ dependencies = [ "thiserror", "tokio", "tracing", - "trust-dns-proto 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.23.0" -source = "git+https://github.com/Watfaq/trust-dns.git?rev=a6a7b2c#a6a7b2c9ba9907cd63375aa6de44a45662072f4b" -dependencies = [ - "cfg-if", - "futures-util", - "ipconfig", - "lru-cache", - "once_cell", - "parking_lot 0.12.1", - "rand", - "resolv-conf", - "rustls", - "serde", - "smallvec", - "thiserror", - "tokio", - "tokio-rustls", - "tracing", - "trust-dns-proto 0.23.0 (git+https://github.com/Watfaq/trust-dns.git?rev=a6a7b2c)", -] - -[[package]] -name = "trust-dns-server" -version = "0.23.0" -source = "git+https://github.com/Watfaq/trust-dns.git?rev=a6a7b2c#a6a7b2c9ba9907cd63375aa6de44a45662072f4b" -dependencies = [ - "async-trait", - "bytes", - "cfg-if", - "drain", - "enum-as-inner 0.6.0", - "futures-executor", - "futures-util", - "h2", - "http", - "rustls", - "serde", - "thiserror", - "time", - "tokio", - "tokio-rustls", - "toml", - "tracing", - "trust-dns-proto 0.23.0 (git+https://github.com/Watfaq/trust-dns.git?rev=a6a7b2c)", - "trust-dns-resolver 0.23.0 (git+https://github.com/Watfaq/trust-dns.git?rev=a6a7b2c)", + "trust-dns-proto 0.23.0", ] [[package]] @@ -4515,15 +4464,6 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" -[[package]] -name = "winnow" -version = "0.5.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" -dependencies = [ - "memchr", -] - [[package]] name = "winreg" version = "0.50.0" diff --git a/clash_lib/Cargo.toml b/clash_lib/Cargo.toml index 13a59d6f3..9123572a1 100644 --- a/clash_lib/Cargo.toml +++ b/clash_lib/Cargo.toml @@ -68,15 +68,10 @@ serde = { version = "1.0", features=["derive"] } serde_yaml = "0.9" erased-serde = "0.3.30" -trust-dns-client = { git = "https://github.com/Watfaq/trust-dns.git", rev = "a6a7b2c" } -trust-dns-resolver = { git = "https://github.com/Watfaq/trust-dns.git", rev = "a6a7b2c" } -trust-dns-server = { git = "https://github.com/Watfaq/trust-dns.git", rev = "a6a7b2c", features = ["dns-over-rustls", "dns-over-https-rustls"] } -trust-dns-proto = { git = "https://github.com/Watfaq/trust-dns.git", rev = "a6a7b2c", features = ["dns-over-rustls", "dns-over-https-rustls"] } - -#trust-dns-client = "0.23" -#trust-dns-resolver = "0.23" -#trust-dns-server = { version = "0.23", features = ["dns-over-rustls", "dns-over-https-rustls"] } -#trust-dns-proto = { version = "0.23", features = ["dns-over-rustls", "dns-over-https-rustls"]} +hickory-client = "0.24" +hickory-resolver = "0.24" +hickory-server = { version = "0.24", features = ["dns-over-rustls", "dns-over-https-rustls"] } +hickory-proto = { version = "0.24", features = ["dns-over-rustls", "dns-over-https-rustls"]} # DoH rustls = { version = "0.21", features=["dangerous_configuration"] } diff --git a/clash_lib/src/app/dns/dhcp.rs b/clash_lib/src/app/dns/dhcp.rs index 590f8ae57..fba36e1a4 100644 --- a/clash_lib/src/app/dns/dhcp.rs +++ b/clash_lib/src/app/dns/dhcp.rs @@ -17,8 +17,8 @@ use tokio::net::UdpSocket; use tokio::sync::Mutex; use tokio::task::yield_now; +use hickory_proto::op::Message; use tracing::{debug, warn}; -use trust_dns_proto::op::Message; use super::config::NameServer; diff --git a/clash_lib/src/app/dns/dns_client.rs b/clash_lib/src/app/dns/dns_client.rs index 87e9123af..688c7a17f 100644 --- a/clash_lib/src/app/dns/dns_client.rs +++ b/clash_lib/src/app/dns/dns_client.rs @@ -5,28 +5,28 @@ use std::{net, sync::Arc, time::Duration}; use async_trait::async_trait; +use hickory_client::client::AsyncClient; +use hickory_client::{ + client, proto::iocompat::AsyncIoTokioAsStd, tcp::TcpClientStream, udp::UdpClientStream, +}; +use hickory_proto::error::ProtoError; use rustls::ClientConfig; use tokio::sync::RwLock; use tokio::task::JoinHandle; use tracing::warn; -use trust_dns_client::client::AsyncClient; -use trust_dns_client::{ - client, proto::iocompat::AsyncIoTokioAsStd, tcp::TcpClientStream, udp::UdpClientStream, -}; -use trust_dns_proto::error::ProtoError; use crate::common::tls::{self, GLOBAL_ROOT_STORE}; use crate::dns::dhcp::DhcpClient; use crate::dns::ThreadSafeDNSClient; -use tokio::net::TcpStream as TokioTcpStream; -use tokio::net::UdpSocket as TokioUdpSocket; -use trust_dns_proto::https::HttpsClientStreamBuilder; -use trust_dns_proto::op::Message; -use trust_dns_proto::rustls::tls_client_connect_with_bind_addr; -use trust_dns_proto::{ +use hickory_proto::h2::HttpsClientStreamBuilder; +use hickory_proto::op::Message; +use hickory_proto::rustls::tls_client_connect_with_bind_addr; +use hickory_proto::{ xfer::{DnsRequest, DnsRequestOptions, FirstAnswer}, DnsHandle, }; +use tokio::net::TcpStream as TokioTcpStream; +use tokio::net::UdpSocket as TokioUdpSocket; use crate::proxy::utils::Interface; use crate::Error; diff --git a/clash_lib/src/app/dns/mod.rs b/clash_lib/src/app/dns/mod.rs index 12eb05b39..5f78bb49c 100644 --- a/clash_lib/src/app/dns/mod.rs +++ b/clash_lib/src/app/dns/mod.rs @@ -2,8 +2,8 @@ use async_trait::async_trait; use std::fmt::Debug; +use hickory_proto::op; use std::sync::Arc; -use trust_dns_proto::op; #[cfg(test)] use mockall::automock; diff --git a/clash_lib/src/app/dns/resolver.rs b/clash_lib/src/app/dns/resolver.rs index 6c5416f21..a5450d2d6 100644 --- a/clash_lib/src/app/dns/resolver.rs +++ b/clash_lib/src/app/dns/resolver.rs @@ -8,7 +8,7 @@ use std::{net, sync::Arc}; use tokio::sync::RwLock; use tracing::{debug, instrument, warn}; -use trust_dns_proto::{op, rr}; +use hickory_proto::{op, rr}; use crate::app::profile::ThreadSafeCacheFile; use crate::common::mmdb::MMDB; @@ -560,13 +560,13 @@ impl ClashResolver for Resolver { mod tests { use crate::dns::dns_client::{DNSNetMode, DnsClient, Opts}; use crate::dns::{Resolver, ThreadSafeDNSClient}; + use hickory_client::{client, op}; + use hickory_proto::rr; + use hickory_proto::udp::UdpClientStream; + use hickory_proto::xfer::{DnsHandle, DnsRequest, DnsRequestOptions, FirstAnswer}; use std::sync::Arc; use std::time::Duration; use tokio::net::UdpSocket; - use trust_dns_client::{client, op}; - use trust_dns_proto::rr; - use trust_dns_proto::udp::UdpClientStream; - use trust_dns_proto::xfer::{DnsHandle, DnsRequest, DnsRequestOptions, FirstAnswer}; #[tokio::test] async fn test_bad_labels_with_custom_resolver() { diff --git a/clash_lib/src/app/dns/server/mod.rs b/clash_lib/src/app/dns/server/mod.rs index 2d5d38a41..bfcc4cddf 100644 --- a/clash_lib/src/app/dns/server/mod.rs +++ b/clash_lib/src/app/dns/server/mod.rs @@ -2,18 +2,18 @@ use std::time::Duration; use async_trait::async_trait; -use thiserror::Error; -use tokio::net::{TcpListener, UdpSocket}; -use tracing::{debug, info, warn}; -use trust_dns_proto::{ +use hickory_proto::{ op::{Header, Message, MessageType, OpCode, ResponseCode}, rr::RecordType, }; -use trust_dns_server::{ +use hickory_server::{ authority::MessageResponseBuilder, server::{Request, RequestHandler, ResponseHandler, ResponseInfo}, ServerFuture, }; +use thiserror::Error; +use tokio::net::{TcpListener, UdpSocket}; +use tracing::{debug, info, warn}; use crate::Runner; @@ -189,7 +189,7 @@ pub async fn get_dns_listener(cfg: Config, resolver: ThreadSafeDNSResolver) -> O .ok()?; } - let l = DnsListener { server: s }; + let mut l = DnsListener { server: s }; Some(Box::pin(async move { match l.server.block_until_done().await { diff --git a/clash_lib/src/app/dns/system.rs b/clash_lib/src/app/dns/system.rs index a7b742bd5..0dc46e6a5 100644 --- a/clash_lib/src/app/dns/system.rs +++ b/clash_lib/src/app/dns/system.rs @@ -53,8 +53,8 @@ impl ClashResolver for SystemResolver { async fn exchange( &self, - _: trust_dns_proto::op::Message, - ) -> anyhow::Result { + _: hickory_proto::op::Message, + ) -> anyhow::Result { Err(anyhow::anyhow!("unsupported")) } @@ -89,7 +89,7 @@ impl ClashResolver for SystemResolver { #[cfg(test)] mod tests { - use trust_dns_resolver::TokioAsyncResolver; + use hickory_resolver::TokioAsyncResolver; use crate::app::dns::{ClashResolver, SystemResolver};