From 78b6b7d90a05b5fb3c0efabb40f53cb49b27a819 Mon Sep 17 00:00:00 2001 From: wyhaya Date: Mon, 2 Sep 2019 16:37:12 +0800 Subject: [PATCH] change default dns server --- src/main.rs | 12 +++++------- src/watch.rs | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4a278f1..36047e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ use watch::Watch; const CONFIG_NAME: &str = ".updns/config"; const DEFAULT_BIND: &str = "0.0.0.0:53"; -const DEFAULT_PROXY: [&str; 2] = ["8.8.8.8:53", "114.114.114.114:53"]; +const DEFAULT_PROXY: [&str; 2] = ["8.8.8.8:53", "1.1.1.1:53"]; const PROXY_TIMEOUT: u64 = 2000; const WATCH_INTERVAL: u64 = 3000; static mut PROXY: Vec = Vec::new(); @@ -117,9 +117,7 @@ fn main() { exit!("'rm' value: [DOMAIN | IP]"); } match ask("Confirm delete? Y/N\n") { - Ok(d) => { - log!("todo"); - } + Ok(_) => log!("todo"), Err(err) => exit!("{:?}", err), } } @@ -204,11 +202,11 @@ fn ask(tips: &str) -> io::Result { let mut s = String::new(); io::stdin().read_line(&mut s)?; - return match s.to_uppercase().as_str() { + match s.to_uppercase().as_str() { "Y\n" => Ok(true), "N\n" => Ok(false), _ => Ok(ask(&tips)?), - }; + } } fn update_config(mut proxy: Vec, hosts: Hosts) { @@ -257,7 +255,7 @@ fn output_invalid(errors: Vec) { async fn watch_config(p: PathBuf) { let mut watch = Watch::new(p, WATCH_INTERVAL); watch - .change(|c| { + .for_each(|c| { log!("Reload the configuration file: {:?}", &c); if let Ok(mut config) = Config::new(c) { if let Ok((_, proxy, hosts, errors)) = config.parse() { diff --git a/src/watch.rs b/src/watch.rs index ed9d463..c1537d3 100644 --- a/src/watch.rs +++ b/src/watch.rs @@ -22,7 +22,7 @@ impl Watch { Ok(modified) } - pub async fn change(&mut self, func: fn(path: &PathBuf)) { + pub async fn for_each(&mut self, func: fn(path: &PathBuf)) { let mut repeat = stream::repeat(0); let mut before = match self.modified().await { Ok(time) => Some(time),