Prepare a new configuration section for Anonymized DNS

pull/12/head
Frank Denis 5 years ago
parent 5437f80bfc
commit 72dfb0628c

@ -180,3 +180,13 @@ key_cache_capacity = 10000
# type = "prometheus" # type = "prometheus"
# listen_addr = "0.0.0.0:9100" # listen_addr = "0.0.0.0:9100"
# path = "/metrics" # path = "/metrics"
################################
# Anonymized DNS #
################################
[anonymized_dns]
enabled = false

@ -9,6 +9,11 @@ use std::net::{IpAddr, SocketAddr};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use tokio::prelude::*; use tokio::prelude::*;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AnonymizedDNSConfig {
pub enabled: bool,
}
#[cfg(feature = "metrics")] #[cfg(feature = "metrics")]
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MetricsConfig { pub struct MetricsConfig {
@ -67,6 +72,7 @@ pub struct Config {
pub log_file: Option<PathBuf>, pub log_file: Option<PathBuf>,
#[cfg(feature = "metrics")] #[cfg(feature = "metrics")]
pub metrics: Option<MetricsConfig>, pub metrics: Option<MetricsConfig>,
pub anonymized_dns: Option<AnonymizedDNSConfig>,
} }
impl Config { impl Config {

@ -43,4 +43,5 @@ pub struct Globals {
#[cfg(feature = "metrics")] #[cfg(feature = "metrics")]
#[derivative(Debug = "ignore")] #[derivative(Debug = "ignore")]
pub varz: Varz, pub varz: Varz,
pub anonymized_dns_enabled: bool,
} }

@ -172,7 +172,9 @@ async fn handle_client_query(
"Short packet" "Short packet"
); );
debug_assert!(DNSCRYPT_QUERY_MIN_OVERHEAD > ANONYMIZED_DNSCRYPT_QUERY_MAGIC.len()); debug_assert!(DNSCRYPT_QUERY_MIN_OVERHEAD > ANONYMIZED_DNSCRYPT_QUERY_MAGIC.len());
if encrypted_packet[..ANONYMIZED_DNSCRYPT_QUERY_MAGIC.len()] == ANONYMIZED_DNSCRYPT_QUERY_MAGIC if globals.anonymized_dns_enabled
&& encrypted_packet[..ANONYMIZED_DNSCRYPT_QUERY_MAGIC.len()]
== ANONYMIZED_DNSCRYPT_QUERY_MAGIC
{ {
return handle_anonymized_dns( return handle_anonymized_dns(
globals, globals,
@ -582,6 +584,10 @@ fn main() -> Result<(), Error> {
.map_err(|e| format_err!("Unable to load the blacklist [{:?}]: [{}]", path, e))?, .map_err(|e| format_err!("Unable to load the blacklist [{:?}]: [{}]", path, e))?,
), ),
}; };
let anonymized_dns_enabled = match config.anonymized_dns {
None => false,
Some(anonymized_dns) => anonymized_dns.enabled,
};
let globals = Arc::new(Globals { let globals = Arc::new(Globals {
runtime: runtime.clone(), runtime: runtime.clone(),
state_file: state_file.to_path_buf(), state_file: state_file.to_path_buf(),
@ -612,6 +618,7 @@ fn main() -> Result<(), Error> {
blacklist, blacklist,
#[cfg(feature = "metrics")] #[cfg(feature = "metrics")]
varz: Varz::default(), varz: Varz::default(),
anonymized_dns_enabled,
}); });
let updater = DNSCryptEncryptionParamsUpdater::new(globals.clone()); let updater = DNSCryptEncryptionParamsUpdater::new(globals.clone());
if !state_is_new { if !state_is_new {

Loading…
Cancel
Save