diff --git a/Cargo.toml b/Cargo.toml index ce8ca5b..5f57fba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ categories = ["asynchronous", "network-programming","command-line-utilities"] readme = "README.md" [dependencies] +anyhow = "1.0" byteorder = "1.3.2" clap = { version="2.33.0", default-features = false, features=["wrap_help", "nightly"] } clockpro-cache = "0.1.8" @@ -20,7 +21,6 @@ daemonize-simple = "0.1.2" derivative = "1.0.3" dnsstamps = "0.1.2" env_logger = { version="0.7.1", default-features = false, features = ["humantime"] } -failure = "0.1.6" futures-preview = { version = "=0.3.0-alpha.19", features = ["async-await"] } jemallocator = "0.3.2" libsodium-sys-stable="1.18.2" @@ -29,12 +29,12 @@ net2 = "0.2.33" parking_lot = "0.9.0" privdrop = "0.3.3" rand = "0.7.2" -serde = "1.0.101" -serde_derive = "1.0.101" +serde = "1.0.102" +serde_derive = "1.0.102" serde-big-array = "0.2.0" siphasher = "0.3.1" tokio = "=0.2.0-alpha.6" -toml = "0.5.3" +toml = "0.5.5" [dependencies.hyper] optional = true diff --git a/src/anonymized_dns.rs b/src/anonymized_dns.rs index f3c1a27..11612bb 100644 --- a/src/anonymized_dns.rs +++ b/src/anonymized_dns.rs @@ -1,7 +1,7 @@ use crate::*; +use crate::errors::*; use byteorder::{BigEndian, ByteOrder}; -use failure::ensure; use siphasher::sip128::Hasher128; use std::hash::Hasher; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; diff --git a/src/blacklist.rs b/src/blacklist.rs index 4b1669c..ad644b1 100644 --- a/src/blacklist.rs +++ b/src/blacklist.rs @@ -45,7 +45,7 @@ impl BlackList { } let qname = line.as_bytes().to_vec().to_ascii_lowercase(); if qname.is_empty() { - bail!(format_err!("Unexpected blacklist rule at line {}", line_nb)) + bail!("Unexpected blacklist rule at line {}", line_nb) } map.insert(qname, ()); } diff --git a/src/config.rs b/src/config.rs index e3c5a5b..49c36d3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -82,7 +82,7 @@ impl Config { pub fn from_string(toml: &str) -> Result { let config: Config = match toml::from_str(toml) { Ok(config) => config, - Err(e) => bail!(format_err!("Parse error in the configuration file: {}", e)), + Err(e) => bail!("Parse error in the configuration file: {}", e), }; Ok(config) } diff --git a/src/crypto.rs b/src/crypto.rs index 34159e1..2a347cd 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -178,7 +178,7 @@ impl SharedKey { let idx = decrypted .iter() .rposition(|x| *x != 0x00) - .ok_or_else(|| format_err!("Padding error"))?; + .ok_or_else(|| anyhow!("Padding error"))?; ensure!(decrypted[idx] == 0x80, "Padding error"); decrypted.truncate(idx); Ok(decrypted) diff --git a/src/dns.rs b/src/dns.rs index 2e7d41a..3df2722 100644 --- a/src/dns.rs +++ b/src/dns.rs @@ -430,7 +430,7 @@ pub fn serve_certificates<'t>( let dnscrypt_encryption_params = dnscrypt_encryption_params_set .into_iter() .max_by_key(|x| x.dnscrypt_cert().ts_end()) - .ok_or_else(|| format_err!("No certificates"))?; + .ok_or_else(|| anyhow!("No certificates"))?; let cert_bin = dnscrypt_encryption_params.dnscrypt_cert().as_bytes(); ensure!(cert_bin.len() <= 0xff, "Certificate too long"); ancount_inc(&mut packet)?; diff --git a/src/dnscrypt.rs b/src/dnscrypt.rs index 9632837..f865f7a 100644 --- a/src/dnscrypt.rs +++ b/src/dnscrypt.rs @@ -64,7 +64,7 @@ pub fn decrypt( let dnscrypt_encryption_params = dnscrypt_encryption_params_set .iter() .find(|p| p.client_magic() == client_magic) - .ok_or_else(|| format_err!("Client magic not found"))?; + .ok_or_else(|| anyhow!("Client magic not found"))?; let mut nonce = [0u8; DNSCRYPT_FULL_NONCE_SIZE as usize]; nonce[..DNSCRYPT_QUERY_NONCE_SIZE].copy_from_slice(client_nonce); diff --git a/src/errors.rs b/src/errors.rs index 79cf66c..3441e7b 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1 +1 @@ -pub use failure::{bail, ensure, Error}; +pub use anyhow::{anyhow, bail, ensure, Error}; diff --git a/src/main.rs b/src/main.rs index e4a2c88..ce95906 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,8 +12,6 @@ extern crate clap; #[macro_use] extern crate derivative; #[macro_use] -extern crate failure; -#[macro_use] extern crate log; #[macro_use] extern crate serde_derive; @@ -56,7 +54,6 @@ use byteorder::{BigEndian, ByteOrder}; use clap::Arg; use clockpro_cache::ClockProCache; use dnsstamps::{InformalProperty, WithInformalProperty}; -use failure::{bail, ensure}; use futures::join; use futures::prelude::*; use parking_lot::Mutex; @@ -252,7 +249,7 @@ async fn tls_proxy( let fut_proxy_2 = erh.copy(&mut wh); match join!(fut_proxy_1, fut_proxy_2) { (Ok(_), Ok(_)) => Ok(()), - _ => Err(format_err!("TLS proxy error")), + _ => bail!("TLS proxy error"), } } @@ -401,7 +398,7 @@ fn bind_listeners( }; let tcp_listener = match TcpListener::from_std(std_socket, &Default::default()) { Ok(tcp_listener) => tcp_listener, - Err(e) => bail!(format_err!("{}/TCP: {}", listen_addr, e)), + Err(e) => bail!("{}/TCP: {}", listen_addr, e), }; let std_socket = match listen_addr { SocketAddr::V4(_) => net2::UdpBuilder::new_v4()? @@ -414,7 +411,7 @@ fn bind_listeners( }; let udp_socket = match std_socket { Ok(udp_socket) => udp_socket, - Err(e) => bail!(format_err!("{}/UDP: {}", listen_addr, e)), + Err(e) => bail!("{}/UDP: {}", listen_addr, e), }; sockets.push((tcp_listener, udp_socket)) } @@ -449,7 +446,7 @@ fn privdrop(config: &Config) -> Result<(), Error> { } daemon .doit() - .map_err(|e| format_err!("Unable to daemonize: [{}]", e))?; + .map_err(|e| anyhow!("Unable to daemonize: [{}]", e))?; } Ok(()) } @@ -601,14 +598,14 @@ fn main() -> Result<(), Error> { let cache = Cache::new( ClockProCache::new(cache_capacity) - .map_err(|e| format_err!("Unable to create the DNS cache: [{}]", e))?, + .map_err(|e| anyhow!("Unable to create the DNS cache: [{}]", e))?, config.cache_ttl_min, config.cache_ttl_max, config.cache_ttl_error, ); let cert_cache = Cache::new( ClockProCache::new(RELAYED_CERT_CACHE_SIZE) - .map_err(|e| format_err!("Unable to create the relay cert cache: [{}]", e))?, + .map_err(|e| anyhow!("Unable to create the relay cert cache: [{}]", e))?, RELAYED_CERT_CACHE_TTL, RELAYED_CERT_CACHE_TTL, RELAYED_CERT_CACHE_TTL, @@ -617,7 +614,7 @@ fn main() -> Result<(), Error> { None => None, Some(path) => Some( BlackList::load(&path) - .map_err(|e| format_err!("Unable to load the blacklist [{:?}]: [{}]", path, e))?, + .map_err(|e| anyhow!("Unable to load the blacklist [{:?}]: [{}]", path, e))?, ), }; let (