diff --git a/Cargo.lock b/Cargo.lock index a43c19f8..56069c01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -987,6 +987,64 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +[[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", + "futures-channel", + "futures-io", + "futures-util", + "h2", + "http", + "idna", + "ipnet", + "native-tls", + "once_cell", + "rand", + "rustls", + "rustls-pemfile", + "serde", + "thiserror", + "tinyvec", + "tokio", + "tokio-native-tls", + "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", + "rand", + "resolv-conf", + "rustls", + "serde", + "smallvec", + "thiserror", + "tokio", + "tokio-native-tls", + "tokio-rustls", + "tracing", +] + [[package]] name = "hkdf" version = "0.12.3" @@ -2317,7 +2375,7 @@ dependencies = [ [[package]] name = "shadowsocks" -version = "1.16.0" +version = "1.17.0" dependencies = [ "aes", "arc-swap", @@ -2330,6 +2388,7 @@ dependencies = [ "cfg-if", "env_logger", "futures", + "hickory-resolver", "libc", "log", "lru_time_cache", @@ -2348,7 +2407,6 @@ dependencies = [ "thiserror", "tokio", "tokio-tfo", - "trust-dns-resolver", "url", "windows-sys 0.48.0", ] @@ -2378,7 +2436,7 @@ dependencies = [ [[package]] name = "shadowsocks-rust" -version = "1.16.2" +version = "1.17.0" dependencies = [ "base64", "build-time", @@ -2416,7 +2474,7 @@ dependencies = [ [[package]] name = "shadowsocks-service" -version = "1.16.2" +version = "1.17.0" dependencies = [ "arc-swap", "async-trait", @@ -2427,6 +2485,7 @@ dependencies = [ "env_logger", "etherparse", "futures", + "hickory-resolver", "hyper", "idna", "ipnet", @@ -2452,7 +2511,6 @@ dependencies = [ "tokio-native-tls", "tokio-rustls", "tower", - "trust-dns-resolver", "tun", "webpki-roots", "windows-sys 0.48.0", @@ -2872,68 +2930,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "trust-dns-proto" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc775440033cb114085f6f2437682b194fa7546466024b1037e82a48a052a69" -dependencies = [ - "async-trait", - "bytes", - "cfg-if", - "data-encoding", - "enum-as-inner", - "futures-channel", - "futures-io", - "futures-util", - "h2", - "http", - "idna", - "ipnet", - "native-tls", - "once_cell", - "rand", - "rustls", - "rustls-pemfile", - "rustls-webpki", - "serde", - "smallvec", - "thiserror", - "tinyvec", - "tokio", - "tokio-native-tls", - "tokio-rustls", - "tracing", - "url", - "webpki-roots", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff7aed33ef3e8bf2c9966fccdfed93f93d46f432282ea875cd66faabc6ef2f" -dependencies = [ - "cfg-if", - "futures-util", - "ipconfig", - "lru-cache", - "once_cell", - "parking_lot", - "rand", - "resolv-conf", - "rustls", - "serde", - "smallvec", - "thiserror", - "tokio", - "tokio-native-tls", - "tokio-rustls", - "tracing", - "trust-dns-proto", - "webpki-roots", -] - [[package]] name = "try-lock" version = "0.2.4" diff --git a/Cargo.toml b/Cargo.toml index 33eda6e2..fde902b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shadowsocks-rust" -version = "1.16.2" +version = "1.17.0" authors = ["Shadowsocks Contributors"] description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls." repository = "https://github.com/shadowsocks/shadowsocks-rust" @@ -57,7 +57,7 @@ strip = true [features] default = [ "logging", - "trust-dns", + "hickory-dns", "local", "server", "manager", @@ -83,8 +83,10 @@ service = ["local", "server", "manager"] # Enable Windows Service winservice = ["service", "windows-service"] -# Enables trust-dns for replacing tokio's builtin DNS resolver -trust-dns = ["shadowsocks-service/trust-dns"] +# Enables Hickory-DNS for replacing tokio's builtin DNS resolver +hickory-dns = ["shadowsocks-service/hickory-dns"] +# Hickory-DNS was renamed from Trust-DNS, keep compatibility. +trust-dns = ["hickory-dns"] dns-over-tls = ["shadowsocks-service/dns-over-tls"] dns-over-native-tls = ["shadowsocks-service/dns-over-native-tls"] dns-over-native-tls-vendored = [ @@ -189,7 +191,7 @@ jemallocator = { version = "0.5", optional = true } snmalloc-rs = { version = "0.3", optional = true } rpmalloc = { version = "0.2", optional = true } -shadowsocks-service = { version = "1.16.2", path = "./crates/shadowsocks-service" } +shadowsocks-service = { version = "1.17.0", path = "./crates/shadowsocks-service" } windows-service = { version = "0.6", optional = true } diff --git a/crates/shadowsocks-service/Cargo.toml b/crates/shadowsocks-service/Cargo.toml index c9abd4aa..1a865b3f 100644 --- a/crates/shadowsocks-service/Cargo.toml +++ b/crates/shadowsocks-service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shadowsocks-service" -version = "1.16.2" +version = "1.17.0" authors = ["Shadowsocks Contributors"] description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls." repository = "https://github.com/shadowsocks/shadowsocks-rust" @@ -18,7 +18,7 @@ full = [ "local", "server", "manager", - "trust-dns", + "hickory-dns", "local-http", "local-redir", "local-tunnel", @@ -32,32 +32,34 @@ server = [] # Enable manager server manager = ["server"] -# Enables trust-dns for replacing tokio's builtin DNS resolver -trust-dns = ["trust-dns-resolver", "shadowsocks/trust-dns"] +# Enables Hickory-DNS for replacing tokio's builtin DNS resolver +hickory-dns = ["hickory-resolver", "shadowsocks/trust-dns"] +# Hickory-DNS was renamed from Trust-DNS, keep compatibility. +trust-dns = ["hickory-dns"] dns-over-tls = [ - "trust-dns", - "trust-dns-resolver/dns-over-tls", - "trust-dns-resolver/dns-over-rustls", + "hickory-dns", + "hickory-resolver/dns-over-tls", + "hickory-resolver/dns-over-rustls", ] dns-over-native-tls = [ - "trust-dns", - "trust-dns-resolver/dns-over-tls", - "trust-dns-resolver/dns-over-native-tls", + "hickory-dns", + "hickory-resolver/dns-over-tls", + "hickory-resolver/dns-over-native-tls", ] dns-over-native-tls-vendored = [ - "trust-dns", - "trust-dns-resolver/dns-over-tls", - "trust-dns-resolver/dns-over-native-tls", + "hickory-dns", + "hickory-resolver/dns-over-tls", + "hickory-resolver/dns-over-native-tls", "native-tls/vendored", ] dns-over-https = [ - "trust-dns", - "trust-dns-resolver/dns-over-https", - "trust-dns-resolver/dns-over-https-rustls", + "hickory-dns", + "hickory-resolver/dns-over-https", + "hickory-resolver/dns-over-https-rustls", ] # Enable DNS-relay -local-dns = ["local", "trust-dns"] +local-dns = ["local", "hickory-dns"] # Backward compatibility, DO NOT USE local-dns-relay = ["local-dns"] # Enable client flow statistic report @@ -144,7 +146,7 @@ libc = "0.2.141" hyper = { version = "0.14.25", optional = true, features = ["full"] } tower = { version = "0.4", optional = true } -trust-dns-resolver = { version = "0.23.0-alpha", optional = true, features = [ +hickory-resolver = { version = "0.24", optional = true, features = [ "serde-config", ] } @@ -169,7 +171,7 @@ smoltcp = { version = "0.10", optional = true, default-features = false, feature serde = { version = "1.0", features = ["derive"] } json5 = "0.4" -shadowsocks = { version = "1.16.0", path = "../shadowsocks", default-features = false } +shadowsocks = { version = "1.17.0", path = "../shadowsocks", default-features = false } # Just for the ioctl call macro [target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies] diff --git a/crates/shadowsocks-service/src/config.rs b/crates/shadowsocks-service/src/config.rs index 3de4dfef..60a21d87 100644 --- a/crates/shadowsocks-service/src/config.rs +++ b/crates/shadowsocks-service/src/config.rs @@ -58,6 +58,8 @@ use std::{ }; use cfg_if::cfg_if; +#[cfg(feature = "hickory-dns")] +use hickory_resolver::config::{NameServerConfig, Protocol, ResolverConfig}; #[cfg(feature = "local-tun")] use ipnet::IpNet; use log::warn; @@ -78,8 +80,6 @@ use shadowsocks::{ crypto::CipherKind, plugin::PluginConfig, }; -#[cfg(feature = "trust-dns")] -use trust_dns_resolver::config::{NameServerConfig, Protocol, ResolverConfig}; use crate::acl::AccessControl; #[cfg(feature = "local-dns")] @@ -91,8 +91,8 @@ use crate::local::socks::config::Socks5AuthConfig; #[serde(untagged)] enum SSDnsConfig { Simple(String), - #[cfg(feature = "trust-dns")] - TrustDns(ResolverConfig), + #[cfg(feature = "hickory-dns")] + HickoryDns(ResolverConfig), } #[derive(Serialize, Deserialize, Debug, Default)] @@ -1031,8 +1031,8 @@ impl LocalConfig { pub enum DnsConfig { #[default] System, - #[cfg(feature = "trust-dns")] - TrustDns(ResolverConfig), + #[cfg(feature = "hickory-dns")] + HickoryDns(ResolverConfig), #[cfg(feature = "local-dns")] LocalDns(NameServerAddr), } @@ -1967,8 +1967,8 @@ impl Config { { match config.dns { Some(SSDnsConfig::Simple(ds)) => nconfig.set_dns_formatted(&ds)?, - #[cfg(feature = "trust-dns")] - Some(SSDnsConfig::TrustDns(c)) => nconfig.dns = DnsConfig::TrustDns(c), + #[cfg(feature = "hickory-dns")] + Some(SSDnsConfig::HickoryDns(c)) => nconfig.dns = DnsConfig::HickoryDns(c), None => nconfig.dns = DnsConfig::System, } nconfig.dns_cache_size = config.dns_cache_size; @@ -2091,22 +2091,22 @@ impl Config { self.dns = match dns { "system" => DnsConfig::System, - #[cfg(feature = "trust-dns")] - "google" => DnsConfig::TrustDns(ResolverConfig::google()), + #[cfg(feature = "hickory-dns")] + "google" => DnsConfig::HickoryDns(ResolverConfig::google()), - #[cfg(feature = "trust-dns")] - "cloudflare" => DnsConfig::TrustDns(ResolverConfig::cloudflare()), - #[cfg(all(feature = "trust-dns", feature = "dns-over-tls"))] - "cloudflare_tls" => DnsConfig::TrustDns(ResolverConfig::cloudflare_tls()), - #[cfg(all(feature = "trust-dns", feature = "dns-over-https"))] - "cloudflare_https" => DnsConfig::TrustDns(ResolverConfig::cloudflare_https()), + #[cfg(feature = "hickory-dns")] + "cloudflare" => DnsConfig::HickoryDns(ResolverConfig::cloudflare()), + #[cfg(all(feature = "hickory-dns", feature = "dns-over-tls"))] + "cloudflare_tls" => DnsConfig::HickoryDns(ResolverConfig::cloudflare_tls()), + #[cfg(all(feature = "hickory-dns", feature = "dns-over-https"))] + "cloudflare_https" => DnsConfig::HickoryDns(ResolverConfig::cloudflare_https()), - #[cfg(feature = "trust-dns")] - "quad9" => DnsConfig::TrustDns(ResolverConfig::quad9()), - #[cfg(all(feature = "trust-dns", feature = "dns-over-tls"))] - "quad9_tls" => DnsConfig::TrustDns(ResolverConfig::quad9_tls()), - #[cfg(all(feature = "trust-dns", feature = "dns-over-https"))] - "quad9_https" => DnsConfig::TrustDns(ResolverConfig::quad9_https()), + #[cfg(feature = "hickory-dns")] + "quad9" => DnsConfig::HickoryDns(ResolverConfig::quad9()), + #[cfg(all(feature = "hickory-dns", feature = "dns-over-tls"))] + "quad9_tls" => DnsConfig::HickoryDns(ResolverConfig::quad9_tls()), + #[cfg(all(feature = "hickory-dns", feature = "dns-over-https"))] + "quad9_https" => DnsConfig::HickoryDns(ResolverConfig::quad9_https()), nameservers => self.parse_dns_nameservers(nameservers)?, }; @@ -2114,7 +2114,7 @@ impl Config { Ok(()) } - #[cfg(any(feature = "trust-dns", feature = "local-dns"))] + #[cfg(any(feature = "hickory-dns", feature = "local-dns"))] fn parse_dns_nameservers(&mut self, nameservers: &str) -> Result { #[cfg(all(unix, feature = "local-dns"))] if let Some(nameservers) = nameservers.strip_prefix("unix://") { @@ -2192,11 +2192,11 @@ impl Config { Ok(if c.name_servers().is_empty() { DnsConfig::System } else { - DnsConfig::TrustDns(c) + DnsConfig::HickoryDns(c) }) } - #[cfg(not(any(feature = "trust-dns", feature = "local-dns")))] + #[cfg(not(any(feature = "hickory-dns", feature = "local-dns")))] fn parse_dns_nameservers(&mut self, _nameservers: &str) -> Result { Ok(DnsConfig::System) } @@ -2675,9 +2675,9 @@ impl fmt::Display for Config { match self.dns { DnsConfig::System => {} - #[cfg(feature = "trust-dns")] - DnsConfig::TrustDns(ref dns) => { - jconf.dns = Some(SSDnsConfig::TrustDns(dns.clone())); + #[cfg(feature = "hickory-dns")] + DnsConfig::HickoryDns(ref dns) => { + jconf.dns = Some(SSDnsConfig::HickoryDns(dns.clone())); } #[cfg(feature = "local-dns")] DnsConfig::LocalDns(ref ns) => { diff --git a/crates/shadowsocks-service/src/dns/mod.rs b/crates/shadowsocks-service/src/dns/mod.rs index 07bc5522..32da44d2 100644 --- a/crates/shadowsocks-service/src/dns/mod.rs +++ b/crates/shadowsocks-service/src/dns/mod.rs @@ -1,9 +1,9 @@ //! DNS resolvers +#[cfg(feature = "hickory-dns")] +use hickory_resolver::config::ResolverOpts; use log::trace; use shadowsocks::{dns_resolver::DnsResolver, net::ConnectOpts}; -#[cfg(feature = "trust-dns")] -use trust_dns_resolver::config::ResolverOpts; use crate::config::DnsConfig; @@ -16,7 +16,7 @@ pub async fn build_dns_resolver( ) -> Option { match dns { DnsConfig::System => { - #[cfg(feature = "trust-dns")] + #[cfg(feature = "hickory-dns")] if crate::hint_support_default_system_resolver() { use log::warn; use std::env; @@ -37,11 +37,11 @@ pub async fn build_dns_resolver( opts_opt = Some(opts); } - return match DnsResolver::trust_dns_system_resolver(opts_opt, connect_opts.clone()).await { + return match DnsResolver::hickory_dns_system_resolver(opts_opt, connect_opts.clone()).await { Ok(r) => Some(r), Err(err) => { warn!( - "initialize trust-dns DNS system resolver failed, fallback to default system resolver, error: {}", + "initialize hickory-dns DNS system resolver failed, fallback to default system resolver, error: {}", err ); None @@ -54,8 +54,8 @@ pub async fn build_dns_resolver( None } - #[cfg(feature = "trust-dns")] - DnsConfig::TrustDns(dns) => { + #[cfg(feature = "hickory-dns")] + DnsConfig::HickoryDns(dns) => { let mut opts_opt = None; if let Some(dns_cache_size) = dns_cache_size { let mut opts = ResolverOpts::default(); @@ -63,13 +63,13 @@ pub async fn build_dns_resolver( opts_opt = Some(opts); } - match DnsResolver::trust_dns_resolver(dns, opts_opt, connect_opts.clone()).await { + match DnsResolver::hickory_resolver(dns, opts_opt, connect_opts.clone()).await { Ok(r) => Some(r), Err(err) => { use log::warn; warn!( - "initialize trust-dns DNS resolver failed, fallback to default system resolver, error: {}", + "initialize hickory-dns DNS resolver failed, fallback to default system resolver, error: {}", err ); None diff --git a/crates/shadowsocks-service/src/lib.rs b/crates/shadowsocks-service/src/lib.rs index a4b53296..13116b10 100644 --- a/crates/shadowsocks-service/src/lib.rs +++ b/crates/shadowsocks-service/src/lib.rs @@ -75,7 +75,7 @@ mod sys; #[allow(dead_code)] const DEFAULT_UDP_EXPIRY_DURATION: Duration = Duration::from_secs(5 * 60); -#[cfg(feature = "trust-dns")] +#[cfg(feature = "hickory-dns")] fn hint_support_default_system_resolver() -> bool { // Nearly all *nix system have /etc/resolv.conf, except Android. // macOS have to use system provided resolver. diff --git a/crates/shadowsocks-service/src/local/dns/client_cache.rs b/crates/shadowsocks-service/src/local/dns/client_cache.rs index 4e919a19..d4b2694f 100644 --- a/crates/shadowsocks-service/src/local/dns/client_cache.rs +++ b/crates/shadowsocks-service/src/local/dns/client_cache.rs @@ -10,9 +10,9 @@ use std::{ time::Duration, }; +use hickory_resolver::proto::{error::ProtoError, op::Message}; use log::{debug, trace}; use tokio::sync::Mutex; -use trust_dns_resolver::proto::{error::ProtoError, op::Message}; use shadowsocks::{config::ServerConfig, net::ConnectOpts, relay::socks5::Address}; diff --git a/crates/shadowsocks-service/src/local/dns/dns_resolver.rs b/crates/shadowsocks-service/src/local/dns/dns_resolver.rs index 47ee56d8..b27b02a0 100644 --- a/crates/shadowsocks-service/src/local/dns/dns_resolver.rs +++ b/crates/shadowsocks-service/src/local/dns/dns_resolver.rs @@ -7,11 +7,11 @@ use std::{ use async_trait::async_trait; use futures::future; -use log::{debug, trace}; -use trust_dns_resolver::proto::{ +use hickory_resolver::proto::{ op::{Message, Query}, rr::{DNSClass, Name, RData, RecordType}, }; +use log::{debug, trace}; use shadowsocks::{config::Mode, dns_resolver::DnsResolve, net::ConnectOpts}; diff --git a/crates/shadowsocks-service/src/local/dns/server.rs b/crates/shadowsocks-service/src/local/dns/server.rs index 47870ebf..0026ea55 100644 --- a/crates/shadowsocks-service/src/local/dns/server.rs +++ b/crates/shadowsocks-service/src/local/dns/server.rs @@ -18,6 +18,10 @@ use futures::{ future::{self, Either}, FutureExt, }; +use hickory_resolver::proto::{ + op::{header::MessageType, response_code::ResponseCode, Message, OpCode, Query}, + rr::{DNSClass, Name, RData, RecordType}, +}; use log::{debug, error, info, trace, warn}; use rand::{thread_rng, Rng}; use tokio::{ @@ -25,10 +29,6 @@ use tokio::{ net::{TcpStream, UdpSocket}, time, }; -use trust_dns_resolver::proto::{ - op::{header::MessageType, response_code::ResponseCode, Message, OpCode, Query}, - rr::{DNSClass, Name, RData, RecordType}, -}; use shadowsocks::{ config::Mode, diff --git a/crates/shadowsocks-service/src/local/dns/upstream.rs b/crates/shadowsocks-service/src/local/dns/upstream.rs index ce21567b..a5e1efb3 100644 --- a/crates/shadowsocks-service/src/local/dns/upstream.rs +++ b/crates/shadowsocks-service/src/local/dns/upstream.rs @@ -12,6 +12,10 @@ use std::{ use byteorder::{BigEndian, ByteOrder}; use bytes::{BufMut, BytesMut}; +use hickory_resolver::proto::{ + error::{ProtoError, ProtoErrorKind}, + op::Message, +}; use log::trace; use rand::{thread_rng, Rng}; use shadowsocks::{ @@ -27,10 +31,6 @@ use tokio::{ net::UdpSocket, time, }; -use trust_dns_resolver::proto::{ - error::{ProtoError, ProtoErrorKind}, - op::Message, -}; use crate::net::{FlowStat, MonProxySocket, MonProxyStream}; diff --git a/crates/shadowsocks-service/src/local/socks/client/socks5/udp_client.rs b/crates/shadowsocks-service/src/local/socks/client/socks5/udp_client.rs index 17413903..48047075 100644 --- a/crates/shadowsocks-service/src/local/socks/client/socks5/udp_client.rs +++ b/crates/shadowsocks-service/src/local/socks/client/socks5/udp_client.rs @@ -47,7 +47,7 @@ impl Socks5UdpClient { match proxy_addr { Address::SocketAddress(sa) => self.socket.connect(sa).await?, // FIXME: `connect` will use tokio's builtin DNS resolver. - // But if we want to use `trust-dns`, we have to initialize a `Context` instance (for the global `AsyncResolver` instance) + // But if we want to use `hickory-dns`, we have to initialize a `Context` instance (for the global `AsyncResolver` instance) Address::DomainNameAddress(ref dname, port) => self.socket.connect((dname.as_str(), port)).await?, } diff --git a/crates/shadowsocks/Cargo.toml b/crates/shadowsocks/Cargo.toml index d84ecaff..b8218c0a 100644 --- a/crates/shadowsocks/Cargo.toml +++ b/crates/shadowsocks/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shadowsocks" -version = "1.16.0" +version = "1.17.0" authors = ["Shadowsocks Contributors"] description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls." repository = "https://github.com/shadowsocks/shadowsocks-rust" @@ -14,10 +14,12 @@ edition = "2021" maintenance = { status = "passively-maintained" } [features] -default = ["trust-dns"] +default = ["hickory-dns"] -# Uses trust-dns instead of tokio's builtin DNS resolver -trust-dns = ["trust-dns-resolver", "arc-swap", "notify"] +# Uses Hickory-DNS instead of tokio's builtin DNS resolver +hickory-dns = ["hickory-resolver", "arc-swap", "notify"] +# Hickory-DNS was renamed from Trust-DNS, keep compatibility. +trust-dns = ["hickory-dns"] # Enable Stream Cipher Protocol # WARN: Stream Cipher Protocol is proved to be insecure @@ -80,7 +82,7 @@ tokio = { version = "1.9.0", features = [ ] } tokio-tfo = "0.2.0" -trust-dns-resolver = { version = "0.23.0-alpha", optional = true } +hickory-resolver = { version = "0.24", optional = true } arc-swap = { version = "1.6", optional = true } notify = { version = "6.0", optional = true } diff --git a/crates/shadowsocks/src/context.rs b/crates/shadowsocks/src/context.rs index 12aa1c47..08cae470 100644 --- a/crates/shadowsocks/src/context.rs +++ b/crates/shadowsocks/src/context.rs @@ -20,7 +20,7 @@ pub struct Context { // Policy against replay attack replay_policy: ReplayAttackPolicy, - // trust-dns resolver, which supports REAL asynchronous resolving, and also customizable + // hickory-dns resolver, which supports REAL asynchronous resolving, and also customizable dns_resolver: Arc, // Connect IPv6 address first diff --git a/crates/shadowsocks/src/dns_resolver/trust_dns_resolver.rs b/crates/shadowsocks/src/dns_resolver/hickory_dns_resolver.rs similarity index 93% rename from crates/shadowsocks/src/dns_resolver/trust_dns_resolver.rs rename to crates/shadowsocks/src/dns_resolver/hickory_dns_resolver.rs index e5e5f5b9..bd417e2a 100644 --- a/crates/shadowsocks/src/dns_resolver/trust_dns_resolver.rs +++ b/crates/shadowsocks/src/dns_resolver/hickory_dns_resolver.rs @@ -11,9 +11,7 @@ use std::{ use cfg_if::cfg_if; use futures::ready; -use log::trace; -use tokio::{io::ReadBuf, net::UdpSocket}; -use trust_dns_resolver::{ +use hickory_resolver::{ config::{LookupIpStrategy, ResolverConfig, ResolverOpts}, error::ResolveResult, name_server::{GenericConnector, RuntimeProvider}, @@ -21,10 +19,12 @@ use trust_dns_resolver::{ AsyncResolver, TokioHandle, }; +use log::trace; +use tokio::{io::ReadBuf, net::UdpSocket}; use crate::net::{tcp::TcpStream as ShadowTcpStream, udp::UdpSocket as ShadowUdpSocket, ConnectOpts}; -/// Shadowsocks trust-dns Runtime Provider +/// Shadowsocks hickory-dns Runtime Provider #[derive(Clone)] pub struct ShadowDnsRuntimeProvider { handle: TokioHandle, @@ -95,10 +95,10 @@ pub type ShadowDnsConnectionProvider = GenericConnector; -/// Create a `trust-dns` asynchronous DNS resolver +/// Create a `hickory-dns` asynchronous DNS resolver pub async fn create_resolver( dns: Option, opts: Option, @@ -129,7 +129,7 @@ pub async fn create_resolver( None => { cfg_if! { if #[cfg(any(all(unix, not(target_os = "android")), windows))] { - use trust_dns_resolver::system_conf::read_system_conf; + use hickory_resolver::system_conf::read_system_conf; // use the system resolver configuration let (config, mut opts) = match read_system_conf() { @@ -158,9 +158,9 @@ pub async fn create_resolver( Ok(DnsResolver::new(config, opts, ShadowDnsConnectionProvider::new(ShadowDnsRuntimeProvider::new(connect_opts)))) } else { - use trust_dns_resolver::error::ResolveError; + use hickory_resolver::error::ResolveError; - Err(ResolveError::from("current platform doesn't support trust-dns resolver with system configured".to_owned())) + Err(ResolveError::from("current platform doesn't support hickory-dns resolver with system configured".to_owned())) } } } diff --git a/crates/shadowsocks/src/dns_resolver/mod.rs b/crates/shadowsocks/src/dns_resolver/mod.rs index 474944ec..1fba47fc 100644 --- a/crates/shadowsocks/src/dns_resolver/mod.rs +++ b/crates/shadowsocks/src/dns_resolver/mod.rs @@ -3,9 +3,9 @@ pub use self::resolver::{DnsResolve, DnsResolver}; +#[cfg(feature = "hickory-dns")] +mod hickory_dns_resolver; mod resolver; -#[cfg(feature = "trust-dns")] -mod trust_dns_resolver; /// Helper macro for resolving host and then process each addresses #[macro_export] diff --git a/crates/shadowsocks/src/dns_resolver/resolver.rs b/crates/shadowsocks/src/dns_resolver/resolver.rs index 6064d88f..5630d709 100644 --- a/crates/shadowsocks/src/dns_resolver/resolver.rs +++ b/crates/shadowsocks/src/dns_resolver/resolver.rs @@ -1,6 +1,6 @@ //! Resolver Alternatives -#[cfg(feature = "trust-dns")] +#[cfg(feature = "hickory-dns")] use std::sync::Arc; use std::{ fmt::{self, Debug}, @@ -9,26 +9,26 @@ use std::{ time::Instant, }; -#[cfg(feature = "trust-dns")] +#[cfg(feature = "hickory-dns")] use arc_swap::ArcSwap; use async_trait::async_trait; use cfg_if::cfg_if; -#[cfg(all(feature = "trust-dns", unix, not(target_os = "android")))] +#[cfg(feature = "hickory-dns")] +use hickory_resolver::config::ResolverConfig; +#[cfg(feature = "hickory-dns")] +use hickory_resolver::config::ResolverOpts; +#[cfg(all(feature = "hickory-dns", unix, not(target_os = "android")))] use log::error; use log::{log_enabled, trace, Level}; use tokio::net::lookup_host; -#[cfg(all(feature = "trust-dns", unix, not(target_os = "android")))] +#[cfg(all(feature = "hickory-dns", unix, not(target_os = "android")))] use tokio::task::JoinHandle; -#[cfg(feature = "trust-dns")] -use trust_dns_resolver::config::ResolverConfig; -#[cfg(feature = "trust-dns")] -use trust_dns_resolver::config::ResolverOpts; -#[cfg(feature = "trust-dns")] +#[cfg(feature = "hickory-dns")] use crate::net::ConnectOpts; -#[cfg(feature = "trust-dns")] -use super::trust_dns_resolver::DnsResolver as TrustDnsResolver; +#[cfg(feature = "hickory-dns")] +use super::hickory_dns_resolver::DnsResolver as HickoryDnsResolver; /// Abstract DNS resolver #[async_trait] @@ -37,9 +37,9 @@ pub trait DnsResolve { async fn resolve(&self, addr: &str, port: u16) -> io::Result>; } -#[cfg(feature = "trust-dns")] +#[cfg(feature = "hickory-dns")] pub struct TrustDnsSystemResolver { - resolver: ArcSwap, + resolver: ArcSwap, #[cfg_attr(windows, allow(dead_code))] connect_opts: ConnectOpts, #[cfg_attr(windows, allow(dead_code))] @@ -52,15 +52,15 @@ pub enum DnsResolver { /// System Resolver, which is tokio's builtin resolver System, /// Trust-DNS's system resolver - #[cfg(feature = "trust-dns")] + #[cfg(feature = "hickory-dns")] TrustDnsSystem { inner: Arc, - #[cfg(all(feature = "trust-dns", unix, not(target_os = "android")))] + #[cfg(all(feature = "hickory-dns", unix, not(target_os = "android")))] abortable: JoinHandle<()>, }, /// Trust-DNS resolver - #[cfg(feature = "trust-dns")] - TrustDns(TrustDnsResolver), + #[cfg(feature = "hickory-dns")] + TrustDns(HickoryDnsResolver), /// Customized Resolver Custom(Box), } @@ -75,19 +75,19 @@ impl Debug for DnsResolver { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { DnsResolver::System => f.write_str("System"), - #[cfg(feature = "trust-dns")] + #[cfg(feature = "hickory-dns")] DnsResolver::TrustDnsSystem { .. } => f.write_str("TrustDnsSystem(..)"), - #[cfg(feature = "trust-dns")] + #[cfg(feature = "hickory-dns")] DnsResolver::TrustDns(..) => f.write_str("TrustDns(..)"), DnsResolver::Custom(..) => f.write_str("Custom(..)"), } } } -#[cfg(feature = "trust-dns")] +#[cfg(feature = "hickory-dns")] impl Drop for DnsResolver { fn drop(&mut self) { - #[cfg(all(feature = "trust-dns", unix, not(target_os = "android")))] + #[cfg(all(feature = "hickory-dns", unix, not(target_os = "android")))] if let DnsResolver::TrustDnsSystem { ref abortable, .. } = *self { abortable.abort(); } @@ -95,7 +95,7 @@ impl Drop for DnsResolver { } cfg_if! { - if #[cfg(feature = "trust-dns")] { + if #[cfg(feature = "hickory-dns")] { /// Resolved result enum EitherResolved { Tokio(A), @@ -146,15 +146,15 @@ cfg_if! { } } -#[cfg(all(feature = "trust-dns", unix, not(target_os = "android")))] -async fn trust_dns_notify_update_dns(resolver: Arc) -> notify::Result<()> { +#[cfg(all(feature = "hickory-dns", unix, not(target_os = "android")))] +async fn hickory_dns_notify_update_dns(resolver: Arc) -> notify::Result<()> { use std::{path::Path, time::Duration}; use log::debug; use notify::{Event, EventKind, RecommendedWatcher, RecursiveMode, Result as NotifyResult, Watcher}; use tokio::{sync::watch, time}; - use super::trust_dns_resolver::create_resolver; + use super::hickory_dns_resolver::create_resolver; static DNS_RESOLV_FILE_PATH: &str = "/etc/resolv.conf"; @@ -200,7 +200,7 @@ async fn trust_dns_notify_update_dns(resolver: Arc) -> n // Update once for all those Modify events time::sleep(Duration::from_secs(1)).await; - match create_resolver(None, resolver.opts, resolver.connect_opts.clone()).await { + match create_resolver(None, resolver.opts.clone(), resolver.connect_opts.clone()).await { Ok(r) => { debug!("auto-reload {DNS_RESOLV_FILE_PATH}"); @@ -227,17 +227,17 @@ impl DnsResolver { DnsResolver::System } - /// Use trust-dns DNS system resolver (with DNS cache) + /// Use hickory-dns DNS system resolver (with DNS cache) /// /// On *nix system, it will try to read configurations from `/etc/resolv.conf`. - #[cfg(feature = "trust-dns")] - pub async fn trust_dns_system_resolver( + #[cfg(feature = "hickory-dns")] + pub async fn hickory_dns_system_resolver( opts: Option, connect_opts: ConnectOpts, ) -> io::Result { - use super::trust_dns_resolver::create_resolver; + use super::hickory_dns_resolver::create_resolver; - let resolver = create_resolver(None, opts, connect_opts.clone()).await?; + let resolver = create_resolver(None, opts.clone(), connect_opts.clone()).await?; let inner = Arc::new(TrustDnsSystemResolver { resolver: ArcSwap::from(Arc::new(resolver)), @@ -246,11 +246,11 @@ impl DnsResolver { }); cfg_if! { - if #[cfg(all(feature = "trust-dns", unix, not(target_os = "android")))] { + if #[cfg(all(feature = "hickory-dns", unix, not(target_os = "android")))] { let abortable = { let inner = inner.clone(); tokio::spawn(async { - if let Err(err) = trust_dns_notify_update_dns(inner).await { + if let Err(err) = hickory_dns_notify_update_dns(inner).await { error!("failed to watch DNS system configuration changes, error: {}", err); } }) @@ -263,14 +263,14 @@ impl DnsResolver { } } - /// Use trust-dns DNS resolver (with DNS cache) - #[cfg(feature = "trust-dns")] - pub async fn trust_dns_resolver( + /// Use hickory-dns DNS resolver (with DNS cache) + #[cfg(feature = "hickory-dns")] + pub async fn hickory_resolver( dns: ResolverConfig, opts: Option, connect_opts: ConnectOpts, ) -> io::Result { - use super::trust_dns_resolver::create_resolver; + use super::hickory_dns_resolver::create_resolver; Ok(DnsResolver::TrustDns( create_resolver(Some(dns), opts, connect_opts).await?, )) @@ -327,10 +327,10 @@ impl DnsResolver { elapsed.as_secs_f32() ); } - #[cfg(feature = "trust-dns")] + #[cfg(feature = "hickory-dns")] DnsResolver::TrustDnsSystem { .. } | DnsResolver::TrustDns(..) => { trace!( - "DNS resolved {}:{} with trust-dns {}s", + "DNS resolved {}:{} with hickory-dns {}s", self.addr, self.port, elapsed.as_secs_f32() @@ -350,9 +350,9 @@ impl DnsResolver { DnsResolver::System => { trace!("DNS resolved {}:{} with tokio", self.addr, self.port); } - #[cfg(feature = "trust-dns")] + #[cfg(feature = "hickory-dns")] DnsResolver::TrustDnsSystem { .. } | DnsResolver::TrustDns(..) => { - trace!("DNS resolved {}:{} with trust-dns", self.addr, self.port); + trace!("DNS resolved {}:{} with hickory-dns", self.addr, self.port); } DnsResolver::Custom(..) => { trace!("DNS resolved {}:{} with customized", self.addr, self.port); @@ -372,7 +372,7 @@ impl DnsResolver { Err(err) } }, - #[cfg(feature = "trust-dns")] + #[cfg(feature = "hickory-dns")] DnsResolver::TrustDnsSystem { ref inner, .. } => match inner.resolver.load().lookup_ip(addr).await { Ok(lookup_result) => Ok(EitherResolved::TrustDnsSystem( lookup_result.into_iter().map(move |ip| SocketAddr::new(ip, port)), @@ -382,7 +382,7 @@ impl DnsResolver { Err(err) } }, - #[cfg(feature = "trust-dns")] + #[cfg(feature = "hickory-dns")] DnsResolver::TrustDns(ref resolver) => match resolver.lookup_ip(addr).await { Ok(lookup_result) => Ok(EitherResolved::TrustDns( lookup_result.into_iter().map(move |ip| SocketAddr::new(ip, port)),