From 51d4ed439442046223405bf0e6d3fb707855b0bf Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Fri, 16 Aug 2024 16:09:54 -0700 Subject: [PATCH] Update 'h3' and 's2n_quic' dependencies. --- core/lib/Cargo.toml | 4 ++-- core/lib/src/listener/quic.rs | 14 +++++++------- examples/tls/Rocket.toml | 3 +++ examples/tls/src/redirector.rs | 33 ++++++++++----------------------- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/core/lib/Cargo.toml b/core/lib/Cargo.toml index 1dec9187..10eb5f17 100644 --- a/core/lib/Cargo.toml +++ b/core/lib/Cargo.toml @@ -33,7 +33,7 @@ uuid = ["uuid_", "rocket_http/uuid"] tls = ["rustls", "tokio-rustls", "rustls-pemfile"] mtls = ["tls", "x509-parser"] tokio-macros = ["tokio/macros"] -trace = ["tracing-subscriber", "tinyvec", "thread_local", "rustls?/logging", "tokio-rustls?/logging", "multer/log"] +trace = ["tracing-subscriber", "tinyvec", "thread_local", "rustls?/logging", "tokio-rustls?/logging", "multer/log", "s2n-quic-h3?/tracing"] [dependencies] # Optional serialization dependencies. @@ -128,7 +128,7 @@ optional = true [dependencies.s2n-quic-h3] git = "https://github.com/SergioBenitez/s2n-quic-h3.git" -rev = "865fd25" +rev = "7aa3be0" optional = true [target.'cfg(unix)'.dependencies] diff --git a/core/lib/src/listener/quic.rs b/core/lib/src/listener/quic.rs index dd94fd05..a51ae13e 100644 --- a/core/lib/src/listener/quic.rs +++ b/core/lib/src/listener/quic.rs @@ -48,10 +48,10 @@ pub struct QuicListener { tls: TlsConfig, } -pub struct H3Stream(H3Conn); +pub struct H3Stream(H3Conn, quic::connection::Result); pub struct H3Connection { - pub(crate) handle: quic::connection::Handle, + pub(crate) remote: quic::connection::Result, pub(crate) parts: http::request::Parts, pub(crate) tx: QuicTx, pub(crate) rx: QuicRx, @@ -104,9 +104,10 @@ impl QuicListener { } pub async fn connect(&self, accept: quic::Connection) -> io::Result { + let remote = accept.remote_addr(); let quic_conn = quic_h3::Connection::new(accept); let conn = H3Conn::new(quic_conn).await.map_err(io::Error::other)?; - Ok(H3Stream(conn)) + Ok(H3Stream(conn, remote)) } pub fn endpoint(&self) -> io::Result { @@ -116,7 +117,7 @@ impl QuicListener { impl H3Stream { pub async fn accept(&mut self) -> io::Result> { - let handle = self.0.inner.conn.handle().clone(); + let remote = self.1.clone(); let ((parts, _), (tx, rx)) = match self.0.accept().await { Ok(Some((req, stream))) => (req.into_parts(), stream.split()), Ok(None) => return Ok(None), @@ -129,7 +130,7 @@ impl H3Stream { } }; - Ok(Some(H3Connection { handle, parts, tx: QuicTx(tx), rx: QuicRx(rx) })) + Ok(Some(H3Connection { remote, parts, tx: QuicTx(tx), rx: QuicRx(rx) })) } } @@ -158,8 +159,7 @@ impl QuicTx { // FIXME: Expose certificates when possible. impl H3Connection { pub fn endpoint(&self) -> io::Result { - let addr = self.handle.remote_addr()?; - Ok(Endpoint::Quic(addr).assume_tls()) + Ok(Endpoint::Quic(self.remote?).assume_tls()) } } diff --git a/examples/tls/Rocket.toml b/examples/tls/Rocket.toml index 36f2f158..4b94b79d 100644 --- a/examples/tls/Rocket.toml +++ b/examples/tls/Rocket.toml @@ -5,6 +5,9 @@ # directly for your browser to show connections as secure. You should NEVER use # these certificate/key pairs. They are here for DEMONSTRATION PURPOSES ONLY. +[default] +log_format = "compact" + [default.tls] certs = "private/rsa_sha256_cert.pem" key = "private/rsa_sha256_key.pem" diff --git a/examples/tls/src/redirector.rs b/examples/tls/src/redirector.rs index 2e4a5ce3..ae08185a 100644 --- a/examples/tls/src/redirector.rs +++ b/examples/tls/src/redirector.rs @@ -3,7 +3,7 @@ use std::net::SocketAddr; use rocket::http::Status; -use rocket::tracing::Level; +use rocket::tracing::{self, Instrument}; use rocket::{route, Error, Request, Data, Route, Orbit, Rocket, Ignite}; use rocket::fairing::{Fairing, Info, Kind}; use rocket::response::Redirect; @@ -45,16 +45,13 @@ impl Redirector { pub async fn try_launch(self, config: Config) -> Result, Error> { use rocket::http::Method::*; - rocket::span_info!("HTTP -> HTTPS Redirector" => { - info!(from = self.0, to = config.tls_addr.port(), "redirecting"); - }); - // Build a vector of routes to `redirect` on `` for each method. let redirects = [Get, Put, Post, Delete, Options, Head, Trace, Connect, Patch] .into_iter() .map(|m| Route::new(m, "/", Self::redirect)) .collect::>(); + info!(from = self.0, to = config.tls_addr.port(), "redirecting"); let addr = SocketAddr::new(config.tls_addr.ip(), self.0); rocket::custom(&config.server) .manage(config) @@ -73,35 +70,25 @@ impl Fairing for Redirector { } } + #[tracing::instrument(name = "HTTP -> HTTPS Redirector", skip_all)] async fn on_liftoff(&self, rocket: &Rocket) { let Some(tls_addr) = rocket.endpoints().find_map(|e| e.tls()?.tcp()) else { - rocket::span_warn!("HTTP -> HTTPS Redirector" => { - warn!("Main instance is not being served over TLS/TCP.\n\ - Redirector refusing to start."); - }); + warn!("Main instance is not being served over TLS/TCP.\n\ + Redirector refusing to start."); return; }; - let config = Config { - tls_addr, - server: rocket::Config { - log_level: Some(Level::ERROR), - ..rocket.config().clone() - }, - }; - let this = *self; let shutdown = rocket.shutdown(); + let span = tracing::info_span!("HTTP -> HTTPS Redirector"); + let config = Config { tls_addr, server: rocket.config().clone() }; rocket::tokio::spawn(async move { if let Err(e) = this.try_launch(config).await { - span_error!("HTTP -> HTTPS Redirector", "failed to start" => { - e.trace_error(); - info!("shutting down main instance"); - }); - + e.trace_error(); + info!("shutting down main instance"); shutdown.notify(); } - }); + }.instrument(span)); } }