Skip to content

Commit

Permalink
🐛 Fix nameserver subnet not work
Browse files Browse the repository at this point in the history
  • Loading branch information
mokeyish authored Jun 14, 2024
1 parent 5b8b907 commit 5549319
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ tracing-subscriber = { version = "0.3", features = [
# tracing-appender = "0.2"

# hickory dns
hickory-proto = { git = "https://github.com/mokeyish/hickory-dns.git", rev = "5a41208", version = "0.24", features = ["serde-config"]}
hickory-resolver = { git = "https://github.com/mokeyish/hickory-dns.git", rev = "5a41208", version = "0.24", features = [
hickory-proto = { git = "https://github.com/mokeyish/hickory-dns.git", rev = "bbf1262", version = "0.24", features = ["serde-config"]}
hickory-resolver = { git = "https://github.com/mokeyish/hickory-dns.git", rev = "bbf1262", version = "0.24", features = [
"serde-config",
"system-config",
] }
hickory-server = { git = "https://github.com/mokeyish/hickory-dns.git", rev = "5a41208", version = "0.24", features = ["resolver"], optional = true }
hickory-server = { git = "https://github.com/mokeyish/hickory-dns.git", rev = "bbf1262", version = "0.24", features = ["resolver"], optional = true }

# ssl
webpki-roots = "0.25.2"
Expand Down
22 changes: 12 additions & 10 deletions src/dns_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
collections::{HashMap, HashSet},
hash::{DefaultHasher, Hash, Hasher},
net::{IpAddr, SocketAddr},
ops::Deref,
path::PathBuf,
Expand Down Expand Up @@ -434,7 +435,7 @@ impl GenericResolver for NameServerGroup {

pub struct NameServerFactory {
tls_client_config: TlsClientConfigBundle,
cache: RwLock<HashMap<String, Arc<NameServer>>>,
cache: RwLock<HashMap<u64, Arc<NameServer>>>,
}

impl NameServerFactory {
Expand All @@ -455,14 +456,15 @@ impl NameServerFactory {
) -> Arc<NameServer> {
use crate::libdns::resolver::name_server::NameServer as N;

let key = format!(
"{}: {}{:?}#{}@{}",
url.proto(),
**url,
proxy.as_ref().map(|s| s.to_string()),
so_mark.unwrap_or_default(),
device.as_deref().unwrap_or_default(),
);
let key = {
let mut hasher = DefaultHasher::new();
url.hash(&mut hasher);
proxy.hash(&mut hasher);
so_mark.hash(&mut hasher);
device.hash(&mut hasher);
resolver_opts.hash(&mut hasher);
hasher.finish()
};

if let Some(ns) = self.cache.read().await.get(&key) {
return ns.clone();
Expand Down Expand Up @@ -714,7 +716,7 @@ impl GenericResolver for NameServer {
}
}

#[derive(Clone)]
#[derive(Clone, Hash)]
pub struct NameServerOpts {
/// filter result with blacklist ip
pub blacklist_ip: bool,
Expand Down
4 changes: 2 additions & 2 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Deref for UdpSocket {
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ProxyConfig {
pub proto: ProxyProtocol,
pub server: SocketAddr,
Expand Down Expand Up @@ -210,7 +210,7 @@ impl FromStr for ProxyConfig {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ProxyProtocol {
Socks5,
Http,
Expand Down

0 comments on commit 5549319

Please sign in to comment.