diff --git a/Cargo.lock b/Cargo.lock index a059e6a..d7a762e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,15 +18,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "arrayvec" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" -dependencies = [ - "nodrop", -] - [[package]] name = "async-trait" version = "0.1.50" @@ -202,39 +193,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "crossbeam-deque" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04c9e3102cc2d69cd681412141b390abd55a362afc1540965dad0ad4d34280b4" -dependencies = [ - "arrayvec", - "cfg-if 0.1.7", - "crossbeam-utils", - "lazy_static 1.3.0", - "memoffset", - "scopeguard 0.3.3", -] - -[[package]] -name = "crossbeam-queue" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.6.5" @@ -398,16 +356,6 @@ version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815" -[[package]] -name = "futures-cpupool" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" -dependencies = [ - "futures 0.1.26", - "num_cpus", -] - [[package]] name = "futures-executor" version = "0.3.14" @@ -482,20 +430,22 @@ dependencies = [ [[package]] name = "h2" -version = "0.1.18" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85ab6286db06040ddefb71641b50017c06874614001a134b423783e2db2920bd" +checksum = "6b67e66362108efccd8ac053abafc8b7a8d86a37e6e48fc4f6f7485eb5e9e6a5" dependencies = [ - "byteorder", - "bytes 0.4.12", + "bytes 1.0.1", "fnv", - "futures 0.1.26", + "futures-core", + "futures-sink", + "futures-util", "http", "indexmap", - "log", "slab", - "string", - "tokio-io", + "tokio", + "tokio-util", + "tracing", + "tracing-futures", ] [[package]] @@ -509,20 +459,37 @@ dependencies = [ [[package]] name = "http" -version = "0.1.17" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eed324f0f0daf6ec10c474f150505af2c143f251722bf9dbd1261bd1f2ee2c1a" +checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" dependencies = [ - "bytes 0.4.12", + "bytes 1.0.1", "fnv", "itoa", ] [[package]] -name = "httparse" -version = "1.3.3" +name = "http-body" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" +checksum = "5dfb77c123b4e2f72a2069aeae0b4b4949cc7e966df277813fc16347e7549737" +dependencies = [ + "bytes 1.0.1", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a1ce40d6fc9764887c2fdc7305c3dcc429ba11ff981c1509416afd5697e4437" + +[[package]] +name = "httpdate" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05842d0d43232b23ccb7060ecb0f0626922c21f30012e97b767b30afd4a5d4b9" [[package]] name = "humantime" @@ -541,29 +508,25 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.12.28" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8e4606fed1c162e3a63d408c07584429f49a4f34c7176cb6cbee60e78f2372c" +checksum = "1e5f105c494081baa3bf9e200b279e27ec1623895cd504c7dbef8d0b080fcf54" dependencies = [ - "bytes 0.4.12", - "futures 0.1.26", - "futures-cpupool", + "bytes 1.0.1", + "futures-channel", + "futures-core", + "futures-util", "h2", "http", + "http-body", "httparse", - "iovec", + "httpdate", "itoa", - "log", - "net2", - "rustc_version", - "time", - "tokio 0.1.18", - "tokio-executor", - "tokio-io", - "tokio-reactor", - "tokio-tcp", - "tokio-threadpool", - "tokio-timer", + "pin-project", + "socket2", + "tokio", + "tower-service", + "tracing", "want", ] @@ -705,12 +668,6 @@ version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" -[[package]] -name = "memoffset" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" - [[package]] name = "mio" version = "0.6.16" @@ -822,12 +779,6 @@ dependencies = [ "void", ] -[[package]] -name = "nodrop" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" - [[package]] name = "ntapi" version = "0.3.6" @@ -950,7 +901,7 @@ dependencies = [ "log", "nest", "structopt", - "tokio 1.5.0", + "tokio", "tokio-executor", "tokio-tcp", "tokio-udp", @@ -964,6 +915,26 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pin-project" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" +dependencies = [ + "proc-macro2 1.0.26", + "quote 1.0.9", + "syn 1.0.70", +] + [[package]] name = "pin-project-lite" version = "0.2.6" @@ -1444,18 +1415,22 @@ dependencies = [ "syn 0.15.32", ] +[[package]] +name = "socket2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "stable_deref_trait" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" -[[package]] -name = "string" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b639411d0b9c738748b5397d5ceba08e648f4f1992231aa859af1a017f31f60b" - [[package]] name = "strsim" version = "0.8.0" @@ -1603,25 +1578,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65641e515a437b308ab131a82ce3042ff9795bef5d6c5a9be4eb24195c417fd9" -dependencies = [ - "bytes 0.4.12", - "futures 0.1.26", - "mio 0.6.16", - "num_cpus", - "tokio-current-thread", - "tokio-executor", - "tokio-io", - "tokio-reactor", - "tokio-threadpool", - "tokio-timer", - "tokio-trace-core", -] - [[package]] name = "tokio" version = "1.5.0" @@ -1653,16 +1609,6 @@ dependencies = [ "tokio-io", ] -[[package]] -name = "tokio-current-thread" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" -dependencies = [ - "futures 0.1.26", - "tokio-executor", -] - [[package]] name = "tokio-executor" version = "0.1.7" @@ -1738,44 +1684,6 @@ dependencies = [ "tokio-reactor", ] -[[package]] -name = "tokio-threadpool" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec5759cf26cf9659555f36c431b515e3d05f66831741c85b4b5d5dfb9cf1323c" -dependencies = [ - "crossbeam-deque", - "crossbeam-queue", - "crossbeam-utils", - "futures 0.1.26", - "log", - "num_cpus", - "rand 0.6.5", - "slab", - "tokio-executor", -] - -[[package]] -name = "tokio-timer" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2910970404ba6fa78c5539126a9ae2045d62e3713041e447f695f41405a120c6" -dependencies = [ - "crossbeam-utils", - "futures 0.1.26", - "slab", - "tokio-executor", -] - -[[package]] -name = "tokio-trace-core" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "350c9edade9830dc185ae48ba45667a445ab59f6167ef6d0254ec9d2430d9dd3" -dependencies = [ - "lazy_static 1.3.0", -] - [[package]] name = "tokio-udp" version = "0.1.6" @@ -1791,6 +1699,20 @@ dependencies = [ "tokio-reactor", ] +[[package]] +name = "tokio-util" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940a12c99365c31ea8dd9ba04ec1be183ffe4920102bb7122c2f515437601e8e" +dependencies = [ + "bytes 1.0.1", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.5.0" @@ -1801,6 +1723,42 @@ dependencies = [ "serde 1.0.125", ] +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +dependencies = [ + "lazy_static 1.3.0", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "trust-dns-client" version = "0.20.2" @@ -1817,7 +1775,7 @@ dependencies = [ "radix_trie", "rand 0.8.3", "thiserror", - "tokio 1.5.0", + "tokio", "trust-dns-proto", ] @@ -1842,7 +1800,7 @@ dependencies = [ "smallvec 1.6.1", "thiserror", "tinyvec", - "tokio 1.5.0", + "tokio", "url", ] @@ -1863,7 +1821,7 @@ dependencies = [ "log", "serde 1.0.125", "thiserror", - "tokio 1.5.0", + "tokio", "toml", "trust-dns-client", "trust-dns-proto", @@ -1943,11 +1901,10 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "want" -version = "0.0.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "futures 0.1.26", "log", "try-lock", ] diff --git a/Cargo.toml b/Cargo.toml index 8ef54d8..3b859a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ clap-log-flag = "0.2" clap-verbosity-flag = "0.2" log = "0.4" futures = "0.3.1" -hyper = "0.12" +hyper = { version = "0.14", features = ["full"] } nest = "1" structopt = "0.2" tokio = { version = "1.5.0", features = ["full"] } diff --git a/src/dns.rs b/src/dns.rs index 83f267d..68caea4 100644 --- a/src/dns.rs +++ b/src/dns.rs @@ -2,9 +2,9 @@ use std::collections::BTreeMap; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::str::FromStr; use std::time::Duration; - - +use std::sync::{Arc, RwLock}; use futures::{future, Future}; +use futures::future::join_all; use tokio::net::TcpListener; use tokio::net::UdpSocket; use trust_dns_client::rr::rdata::soa::SOA; @@ -14,14 +14,14 @@ use trust_dns_server::authority::{Catalog, ZoneType}; use trust_dns_server::server::ServerFuture; use trust_dns_server::store::in_memory::InMemoryAuthority; -use std::sync::{Arc, RwLock}; + static DEFAULT_TCP_REQUEST_TIMEOUT: u64 = 5; -pub async fn server() { +pub async fn server() -> ServerFuture { info!("Trust-DNS {} starting", trust_dns_server::version()); let ip_addr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)); @@ -86,10 +86,12 @@ pub async fn server() { // load all the listeners info!("DNS server listening for UDP on {:?}", udp_socket); - server.register_socket(udp_socket); + let udp_future = server.register_socket(udp_socket); info!("DNS server listening for TCP on {:?}", tcp_listener); - server + let tcp_future = server .register_listener(tcp_listener, tcp_request_timeout); info!("awaiting DNS connections..."); + + server } diff --git a/src/http.rs b/src/http.rs index 2eacfe7..20a984c 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,18 +1,22 @@ use futures::Future; -use hyper::service::service_fn_ok; use hyper::{Body, Request, Response, Server}; +use std::convert::Infallible; +use hyper::service::{make_service_fn, service_fn}; -fn handle_request(_req: Request) -> Response { - Response::new(Body::from("Hello, World!")) + +async fn handle_request(_req: Request) -> Result, Infallible>{ + Ok(Response::new(Body::from("Hello, World!"))) } pub async fn server() { let address = ([127, 0, 0, 1], 3000).into(); - let handle_connection = || service_fn_ok(handle_request); + let make_svc = make_service_fn(|_conn| async { + // service_fn converts our function into a `Service` + Ok::<_, Infallible>(service_fn(handle_request)) + }); info!("HTTP server listening for TCP on {:?}", address); - let server = Server::bind(&address) - .serve(handle_connection); + Server::bind(&address).serve(make_svc).await; } diff --git a/src/main.rs b/src/main.rs index fc1367b..21978f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,20 +12,27 @@ mod http; #[tokio::main] async fn main() { + let args = cli::args().expect("error parsing args"); + // create future for dns and http servers let dns_future = task::spawn(dns::server()); let http_future = task::spawn(http::server()); + // join futures let result = try_join!(dns_future, http_future); - if let Err(e) = result { + match result { + Err(e) => { io::Error::new( io::ErrorKind::Interrupted, "Server stopping due to interruption", ); error!("server failure: {}", e); } - - println!("were stopping for some reason"); + Ok(val) => { + info!("we're stopping for some unexpected reason"); + } + } + info!("we're stopping for some unexpected reason"); }