Switch a lot of Strings to Arc<str>

This commit is contained in:
Slatian
2023-10-08 09:12:06 +02:00
parent 223abdd804
commit 5c74de5685
5 changed files with 47 additions and 38 deletions

View File

@ -1,6 +1,7 @@
use serde::{Deserialize,Serialize};
use trust_dns_resolver::config::Protocol;
use std::sync::Arc;
use std::collections::HashMap;
use std::net::SocketAddr;
@ -10,12 +11,12 @@ pub struct DnsConfig {
pub allow_forward_lookup: bool,
pub allow_reverse_lookup: bool,
pub hidden_suffixes: Vec<String>,
pub resolver: HashMap<String,DnsResolverConfig>,
pub resolver: HashMap<Arc<str>,DnsResolverConfig>,
pub enable_system_resolver: bool,
pub system_resolver_name: String,
pub system_resolver_name: Arc<str>,
pub system_resolver_weight: i32,
pub system_resolver_id: String,
pub system_resolver_id: Arc<str>,
}
#[derive(Deserialize, Serialize, Clone)]
@ -30,16 +31,16 @@ pub enum DnsProtocol {
#[derive(Deserialize, Serialize, Clone)]
pub struct DnsResolverConfig {
pub display_name: String,
pub display_name: Arc<str>,
#[serde(default)]
pub info_url: Option<String>,
pub info_url: Option<Arc<str>>,
#[serde(default)]
pub aliases: Vec<String>,
pub aliases: Vec<Arc<str>>,
#[serde(default="zero")]
pub weight: i32,
pub servers: Vec<SocketAddr>,
pub protocol: DnsProtocol,
pub tls_dns_name: Option<String>,
pub tls_dns_name: Option<Arc<str>>,
#[serde(skip_serializing)] //Don't leak our bind address to the outside
pub bind_address: Option<SocketAddr>,
#[serde(default="default_true")]
@ -63,9 +64,9 @@ impl Default for DnsConfig {
resolver: Default::default(),
enable_system_resolver: true,
system_resolver_name: "System".to_string(),
system_resolver_name: "System".into(),
system_resolver_weight: 1000,
system_resolver_id: "system".to_string(),
system_resolver_id: "system".into(),
}
}
}
@ -91,7 +92,7 @@ impl DnsResolverConfig {
resolver.add_name_server(trust_dns_resolver::config::NameServerConfig{
socket_addr: *server,
protocol: self.protocol.clone().into(),
tls_dns_name: self.tls_dns_name.clone(),
tls_dns_name: self.tls_dns_name.clone().map(|s| s.to_string()),
trust_nx_responses: self.trust_nx_responses,
tls_config: None,
bind_addr: self.bind_address,