From 2126982291489f9ec715fc221af448e70fb0d254 Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Fri, 8 Mar 2024 18:34:57 +0100 Subject: [PATCH] Update axum dependency to v0.7.4 Signed-off-by: Lee Smet --- Cargo.lock | 135 ++++++++++++++++++++++++++++++++++++++++++++--------- Cargo.toml | 2 +- src/api.rs | 23 ++++++--- src/lib.rs | 2 +- 4 files changed, 132 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 262edc8..837dbe5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -146,18 +146,19 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.6.20" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" dependencies = [ "async-trait", "axum-core", - "bitflags 1.3.2", "bytes", "futures-util", - "http", - "http-body", - "hyper", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.2.0", + "hyper-util", "itoa", "matchit", "memchr", @@ -178,17 +179,20 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.3.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", "mime", + "pin-project-lite", "rustversion", + "sync_wrapper", "tower-layer", "tower-service", ] @@ -691,7 +695,26 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.11", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.1.0", "indexmap", "slab", "tokio", @@ -728,6 +751,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -735,7 +769,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.11", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -767,9 +824,9 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.3.24", + "http 0.2.11", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -781,6 +838,26 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.2", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -788,13 +865,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", - "hyper", + "http 0.2.11", + "hyper 0.14.28", "rustls", "tokio", "tokio-rustls", ] +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.2.0", + "pin-project-lite", + "socket2", + "tokio", +] + [[package]] name = "idna" version = "0.5.0" @@ -1425,10 +1518,10 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", - "hyper", + "h2 0.3.24", + "http 0.2.11", + "http-body 0.4.6", + "hyper 0.14.28", "hyper-rustls", "ipnet", "js-sys", diff --git a/Cargo.toml b/Cargo.toml index a8e1017..a9c7c34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ left-right = "0.11.5" ipnet = "2.8.0" ip_network_table-deps-treebitmap = "0.5.0" blake3 = "1.5.0" -axum = { version = "0.6.20", default-features = false, features = [ +axum = { version = "0.7.4", default-features = false, features = [ "http1", "http2", "json", diff --git a/src/api.rs b/src/api.rs index c986591..569c886 100644 --- a/src/api.rs +++ b/src/api.rs @@ -51,7 +51,7 @@ impl Http { router: crate::router::Router, peer_manager: PeerManager, #[cfg(feature = "message")] message_stack: MessageStack, - listen_addr: &SocketAddr, + listen_addr: SocketAddr, ) -> Self { let server_state = HttpServerState { router: Arc::new(Mutex::new(router)), @@ -74,13 +74,22 @@ impl Http { } let (_cancel_tx, cancel_rx) = tokio::sync::oneshot::channel(); - let server = axum::Server::bind(listen_addr) - .serve(app.into_make_service()) - .with_graceful_shutdown(async { - cancel_rx.await.ok(); - }); - tokio::spawn(async { + tokio::spawn(async move { + let listener = match tokio::net::TcpListener::bind(listen_addr).await { + Ok(listener) => listener, + Err(e) => { + error!("Failed to bind listener for Http Api server: {e}"); + error!("API disabled"); + return; + } + }; + + let server = + axum::serve(listener, app.into_make_service()).with_graceful_shutdown(async { + cancel_rx.await.ok(); + }); + if let Err(e) = server.await { error!("Http API server error: {e}"); } diff --git a/src/lib.rs b/src/lib.rs index 6ee8291..e84b31d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -178,7 +178,7 @@ impl Stack { pm.clone(), #[cfg(feature = "message")] ms.clone(), - &config.api_addr, + config.api_addr, ); Ok(Stack {