Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proxy-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ toml = { version = "0.9.8", default-features = false, features = [
"parse",
"serde",
] }
hot_reload = { version = "0.3.4", features = ["file-reloader"] }
hot_reload = { version = "0.3.5", features = ["file-reloader"] }

# logging
tracing = { version = "0.1.41" }
Expand Down
47 changes: 46 additions & 1 deletion proxy-bin/src/config/target_config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use super::{toml::ConfigToml, utils_dns_proto::parse_proto_sockaddr_str, utils_verifier::*};
use crate::{constants::*, error::*, log::*};
use async_trait::async_trait;
use doh_auth_proxy_lib::{
AuthenticationConfig, NextHopRelayConfig, ProxyConfig, QueryManipulationConfig, SubseqRelayConfig, TokenConfig,
};
use std::{env, path::PathBuf, sync::Arc};
use hot_reload::AsyncFileLoad;
use std::{
env,
path::{Path, PathBuf},
sync::Arc,
};
use tokio::time::Duration;

pub type ConfigReloader = hot_reload::file_reloader::FileReloader<TargetConfig>;
Expand All @@ -25,6 +31,45 @@ impl TryFrom<&PathBuf> for TargetConfig {
}
}

#[async_trait]
impl AsyncFileLoad for TargetConfig {
type Error = String;

async fn async_load_from<T>(path: T) -> Result<Self, Self::Error>
where
T: AsRef<Path> + Send,
{
let config_str = tokio::fs::read_to_string(path)
.await
.map_err(|e| format!("Failed to read config file: {}", e))?;
let config_toml: ConfigToml = toml::from_str(&config_str).map_err(|e| format!("Failed to parse toml: {}", e))?;
let query_manipulation_config: Option<QueryManipulationConfig> = (&config_toml)
.try_into()
.map_err(|e| format!("Failed to parse query manipulation config: {}", e))?;
Ok(Self {
config_toml,
query_manipulation_config: query_manipulation_config.map(Arc::new),
})
}

fn dependent_paths(&self) -> Vec<PathBuf> {
let mut paths = Vec::new();

let Some(plugins) = &self.config_toml.plugins else {
return paths;
};

if let Some(blocked_file) = &plugins.domains_blocked_file {
paths.push(PathBuf::from(blocked_file));
}
if let Some(overridden_file) = &plugins.domains_overridden_file {
paths.push(PathBuf::from(overridden_file));
}

paths
}
}

impl TargetConfig {
/// build new target config by loading query manipulation plugin configs
pub fn new(config_file: &PathBuf) -> anyhow::Result<Self> {
Expand Down
5 changes: 3 additions & 2 deletions proxy-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ fn main() {
std::process::exit(1);
}
} else {
let reloader_config = ReloaderConfig::polling(CONFIG_WATCH_DELAY_SECS);
// With config file watcher in hybrid mode
let reloader_config = ReloaderConfig::hybrid(CONFIG_WATCH_DELAY_SECS);
let (config_service, config_rx) =
ReloaderService::<ConfigReloader, TargetConfig, String>::new(&parsed_opts.config_file_path, reloader_config)
.await
.unwrap();

tokio::select! {
Err(e) = config_service.start() => {
Err(e) = config_service.start_with_realtime() => {
error!("config reloader service exited: {e}");
std::process::exit(1);
}
Expand Down