diff --git a/Cargo.toml b/Cargo.toml index 0d2d343..8c03da9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,5 @@ futures = "~0.1" hyper = "~0.11" tokio = "~0.1" tokio-io = "~0.1" -tokio-timer = "~0.1" +tokio-timer = "~0.2" clippy = {version = ">=0", optional = true} diff --git a/src/main.rs b/src/main.rs index ee3e7d5..14d9600 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,10 +20,10 @@ use hyper::{Body, Method, StatusCode}; use std::cell::RefCell; use std::net::SocketAddr; use std::rc::Rc; -use std::time::Duration; +use std::time::{Duration, Instant}; use tokio::executor::current_thread; use tokio::net::{TcpListener, UdpSocket}; -use tokio_timer::Timer; +use tokio_timer::{timer, Timer}; const DNS_QUERY_PARAM: &str = "dns"; const LISTEN_ADDRESS: &str = "127.0.0.1:3000"; @@ -47,7 +47,7 @@ struct DoH { path: String, max_clients: u32, timeout: Duration, - timers: Timer, + timer_handle: timer::Handle, clients_count: Rc>, } @@ -79,8 +79,8 @@ impl Service for DoH { err }); let timed = self - .timers - .timeout(fut.map_err(|_| {}), self.timeout) + .timer_handle + .deadline(fut.map_err(|_| {}), Instant::now() + self.timeout) .map_err(|_| hyper::Error::Timeout); Box::new(timed) } @@ -152,9 +152,7 @@ impl DoH { response.set_body(packet); let response = response .with_header(ContentLength(packet_len as u64)) - .with_header(ContentType( - "application/dns-message".parse().unwrap(), - )) + .with_header(ContentType("application/dns-message".parse().unwrap())) .with_header(CacheControl(vec![CacheDirective::MaxAge(ttl)])); future::ok(response) }); @@ -194,7 +192,7 @@ fn main() { max_clients: MAX_CLIENTS, timeout: Duration::from_secs(TIMEOUT_SEC), clients_count: Rc::new(RefCell::new(0u32)), - timers: tokio_timer::wheel().build(), + timer_handle: Timer::default().handle(), }; parse_opts(&mut doh); let listen_address = doh.listen_address;