Skip to content

Commit 7d4fcd8

Browse files
committed
Update 'h3' and 's2n_quic' dependencies.
1 parent 61970a9 commit 7d4fcd8

File tree

4 files changed

+22
-32
lines changed

4 files changed

+22
-32
lines changed

core/lib/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ uuid = ["uuid_", "rocket_http/uuid"]
3333
tls = ["rustls", "tokio-rustls", "rustls-pemfile"]
3434
mtls = ["tls", "x509-parser"]
3535
tokio-macros = ["tokio/macros"]
36-
trace = ["tracing-subscriber", "tinyvec", "thread_local", "rustls?/logging", "tokio-rustls?/logging", "multer/log"]
36+
trace = ["tracing-subscriber", "tinyvec", "thread_local", "rustls?/logging", "tokio-rustls?/logging", "multer/log", "s2n-quic-h3?/tracing"]
3737

3838
[dependencies]
3939
# Optional serialization dependencies.
@@ -128,7 +128,7 @@ optional = true
128128

129129
[dependencies.s2n-quic-h3]
130130
git = "https://github.com/SergioBenitez/s2n-quic-h3.git"
131-
rev = "865fd25"
131+
rev = "7aa3be0"
132132
optional = true
133133

134134
[target.'cfg(unix)'.dependencies]

core/lib/src/listener/quic.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ pub struct QuicListener {
4848
tls: TlsConfig,
4949
}
5050

51-
pub struct H3Stream(H3Conn);
51+
pub struct H3Stream(H3Conn, quic::connection::Result<SocketAddr>);
5252

5353
pub struct H3Connection {
54-
pub(crate) handle: quic::connection::Handle,
54+
pub(crate) remote: quic::connection::Result<SocketAddr>,
5555
pub(crate) parts: http::request::Parts,
5656
pub(crate) tx: QuicTx,
5757
pub(crate) rx: QuicRx,
@@ -104,9 +104,10 @@ impl QuicListener {
104104
}
105105

106106
pub async fn connect(&self, accept: quic::Connection) -> io::Result<H3Stream> {
107+
let remote = accept.remote_addr();
107108
let quic_conn = quic_h3::Connection::new(accept);
108109
let conn = H3Conn::new(quic_conn).await.map_err(io::Error::other)?;
109-
Ok(H3Stream(conn))
110+
Ok(H3Stream(conn, remote))
110111
}
111112

112113
pub fn endpoint(&self) -> io::Result<Endpoint> {
@@ -116,7 +117,7 @@ impl QuicListener {
116117

117118
impl H3Stream {
118119
pub async fn accept(&mut self) -> io::Result<Option<H3Connection>> {
119-
let handle = self.0.inner.conn.handle().clone();
120+
let remote = self.1.clone();
120121
let ((parts, _), (tx, rx)) = match self.0.accept().await {
121122
Ok(Some((req, stream))) => (req.into_parts(), stream.split()),
122123
Ok(None) => return Ok(None),
@@ -129,7 +130,7 @@ impl H3Stream {
129130
}
130131
};
131132

132-
Ok(Some(H3Connection { handle, parts, tx: QuicTx(tx), rx: QuicRx(rx) }))
133+
Ok(Some(H3Connection { remote, parts, tx: QuicTx(tx), rx: QuicRx(rx) }))
133134
}
134135
}
135136

@@ -158,8 +159,7 @@ impl QuicTx {
158159
// FIXME: Expose certificates when possible.
159160
impl H3Connection {
160161
pub fn endpoint(&self) -> io::Result<Endpoint> {
161-
let addr = self.handle.remote_addr()?;
162-
Ok(Endpoint::Quic(addr).assume_tls())
162+
Ok(Endpoint::Quic(self.remote?).assume_tls())
163163
}
164164
}
165165

examples/tls/Rocket.toml

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# directly for your browser to show connections as secure. You should NEVER use
66
# these certificate/key pairs. They are here for DEMONSTRATION PURPOSES ONLY.
77

8+
[default]
9+
log_format = "compact"
10+
811
[default.tls]
912
certs = "private/rsa_sha256_cert.pem"
1013
key = "private/rsa_sha256_key.pem"

examples/tls/src/redirector.rs

+10-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::net::SocketAddr;
44

55
use rocket::http::Status;
6-
use rocket::tracing::Level;
6+
use rocket::tracing::{self, Instrument};
77
use rocket::{route, Error, Request, Data, Route, Orbit, Rocket, Ignite};
88
use rocket::fairing::{Fairing, Info, Kind};
99
use rocket::response::Redirect;
@@ -45,16 +45,13 @@ impl Redirector {
4545
pub async fn try_launch(self, config: Config) -> Result<Rocket<Ignite>, Error> {
4646
use rocket::http::Method::*;
4747

48-
rocket::span_info!("HTTP -> HTTPS Redirector" => {
49-
info!(from = self.0, to = config.tls_addr.port(), "redirecting");
50-
});
51-
5248
// Build a vector of routes to `redirect` on `<path..>` for each method.
5349
let redirects = [Get, Put, Post, Delete, Options, Head, Trace, Connect, Patch]
5450
.into_iter()
5551
.map(|m| Route::new(m, "/<path..>", Self::redirect))
5652
.collect::<Vec<_>>();
5753

54+
info!(from = self.0, to = config.tls_addr.port(), "redirecting");
5855
let addr = SocketAddr::new(config.tls_addr.ip(), self.0);
5956
rocket::custom(&config.server)
6057
.manage(config)
@@ -73,35 +70,25 @@ impl Fairing for Redirector {
7370
}
7471
}
7572

73+
#[tracing::instrument(name = "HTTP -> HTTPS Redirector", skip_all)]
7674
async fn on_liftoff(&self, rocket: &Rocket<Orbit>) {
7775
let Some(tls_addr) = rocket.endpoints().find_map(|e| e.tls()?.tcp()) else {
78-
rocket::span_warn!("HTTP -> HTTPS Redirector" => {
79-
warn!("Main instance is not being served over TLS/TCP.\n\
80-
Redirector refusing to start.");
81-
});
76+
warn!("Main instance is not being served over TLS/TCP.\n\
77+
Redirector refusing to start.");
8278

8379
return;
8480
};
8581

86-
let config = Config {
87-
tls_addr,
88-
server: rocket::Config {
89-
log_level: Some(Level::ERROR),
90-
..rocket.config().clone()
91-
},
92-
};
93-
9482
let this = *self;
9583
let shutdown = rocket.shutdown();
84+
let span = tracing::info_span!("HTTP -> HTTPS Redirector");
85+
let config = Config { tls_addr, server: rocket.config().clone() };
9686
rocket::tokio::spawn(async move {
9787
if let Err(e) = this.try_launch(config).await {
98-
span_error!("HTTP -> HTTPS Redirector", "failed to start" => {
99-
e.trace_error();
100-
info!("shutting down main instance");
101-
});
102-
88+
e.trace_error();
89+
info!("shutting down main instance");
10390
shutdown.notify();
10491
}
105-
});
92+
}.instrument(span));
10693
}
10794
}

0 commit comments

Comments
 (0)