mirror of
https://github.com/DNSCrypt/encrypted-dns-server.git
synced 2024-05-07 06:36:06 +02:00
Move from failure to anyhow
This commit is contained in:
parent
32758edc74
commit
4d584d95e6
|
@ -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
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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, ());
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ impl Config {
|
|||
pub fn from_string(toml: &str) -> Result<Config, Error> {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)?;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1 +1 @@
|
|||
pub use failure::{bail, ensure, Error};
|
||||
pub use anyhow::{anyhow, bail, ensure, Error};
|
||||
|
|
17
src/main.rs
17
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 (
|
||||
|
|
Loading…
Reference in New Issue