From 09c6b23f349229f7b6a1a91c35fce4c104d876fd Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Sat, 23 Sep 2023 15:25:47 +0800 Subject: [PATCH] feat(local): local-dns client_cache_size set default when creating server instance --- README.md | 4 +++- crates/shadowsocks-service/src/config.rs | 9 ++++++++- crates/shadowsocks-service/src/local/mod.rs | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cb3efeeca4a6..bba9c00761c4 100644 --- a/README.md +++ b/README.md @@ -596,7 +596,9 @@ Example configuration: // Remote DNS address, DNS queries will be sent through ssserver to this address "remote_dns_address": "8.8.8.8", // OPTIONAL. Remote DNS's port, 53 by default - "remote_dns_port": 53 + "remote_dns_port": 53, + // OPTIONAL. DNS Client Cache (TCP & UDP sockets) + "client_cache_size": 5 }, { // Tun local server (feature = "local-tun") diff --git a/crates/shadowsocks-service/src/config.rs b/crates/shadowsocks-service/src/config.rs index 577ff96c339a..867c7eac0dbf 100644 --- a/crates/shadowsocks-service/src/config.rs +++ b/crates/shadowsocks-service/src/config.rs @@ -925,7 +925,7 @@ impl LocalConfig { #[cfg(feature = "local-dns")] remote_dns_addr: None, #[cfg(feature = "local-dns")] - client_cache_size: Some(5), + client_cache_size: None, #[cfg(feature = "local-tun")] tun_interface_name: None, @@ -1553,6 +1553,11 @@ impl Config { }); } + #[cfg(feature = "local-dns")] + { + local_config.client_cache_size = local.client_cache_size; + } + #[cfg(feature = "local-tun")] if let Some(tun_interface_address) = local.tun_interface_address { match tun_interface_address.parse::() { @@ -2464,6 +2469,8 @@ impl fmt::Display for Config { Address::DomainNameAddress(.., port) => Some(*port), }, }, + #[cfg(feature = "local-dns")] + client_cache_size: local.client_cache_size.clone(), #[cfg(feature = "local-tun")] tun_interface_name: local.tun_interface_name.clone(), #[cfg(feature = "local-tun")] diff --git a/crates/shadowsocks-service/src/local/mod.rs b/crates/shadowsocks-service/src/local/mod.rs index c2d0fb6455aa..dc99074c266d 100644 --- a/crates/shadowsocks-service/src/local/mod.rs +++ b/crates/shadowsocks-service/src/local/mod.rs @@ -353,7 +353,7 @@ impl Server { let mut server_builder = { let local_addr = local_config.local_dns_addr.expect("missing local_dns_addr"); let remote_addr = local_config.remote_dns_addr.expect("missing remote_dns_addr"); - let client_cache_size = local_config.client_cache_size.unwrap(); + let client_cache_size = local_config.client_cache_size.unwrap_or_else(5); DnsBuilder::with_context( context.clone(),