Skip to content

Commit

Permalink
Fix tls bit of httpwg-loona
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Aug 30, 2024
1 parent 49078b1 commit 63d2961
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ httpwg-over-tcp *args='':
cargo build --release \
--package httpwg-loona \
--package httpwg-cli
export PROTO=h2
export PROTO=h2c
export PORT=8001
export RUST_LOG=${RUST_LOG:-info}
./target/release/httpwg --frame-timeout 2000 --connect-timeout 2000 --address localhost:8001 "$@" -- ./target/release/httpwg-loona
Expand All @@ -84,7 +84,7 @@ samply:
--package httpwg-loona \
--profile profiling \
--features tracing/release_max_level_info
export PROTO=h2
export PROTO=h2c
export PORT=8002
target/profiling/httpwg-loona

Expand Down
2 changes: 1 addition & 1 deletion crates/httpwg-loona/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ rcgen = { version = "0.13.1", default-features = false, features = [
httpwg-harness = { version = "0.1.0", path = "../httpwg-harness" }
socket2 = "0.5.7"

[target.'cfg(target_os = "linux")'.dev-dependencies]
[target.'cfg(target_os = "linux")'.dependencies]
ktls = "6.0.0"
tokio-rustls = "0.26.0"
4 changes: 3 additions & 1 deletion crates/httpwg-loona/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ async fn real_main() {

#[cfg(target_os = "linux")]
Proto::TLS => {
tls::handle_tls_conn(stream).await?;
tls::handle_tls_conn(stream)
.await
.map_err(|e| eyre::eyre!("tls error: {e:?}"))?;
}
}
Ok::<_, eyre::Report>(())
Expand Down
36 changes: 18 additions & 18 deletions crates/httpwg-loona/src/tls.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
use b_x::BxForResults;
use buffet::net::TcpStream;
use buffet::IntoHalves;
use buffet::RollMut;
use httpwg_harness::Settings;
use ktls::CorkStream;
use loona::h1;
use loona::h2;
use std::mem::ManuallyDrop;
use std::os::fd::AsRawFd;
use std::os::fd::FromRawFd;
use std::os::fd::IntoRawFd;
use std::rc::Rc;
use std::sync::Arc;
use tokio_rustls::TlsAcceptor;

async fn handle_tls_conn(
acceptor: Rc<tokio_rustls::TlsAcceptor>,
stream: tokio::net::TcpStream,
remote_addr: std::net::SocketAddr,
h1_conf: Rc<h1::ServerConf>,
h2_conf: Rc<h2::ServerConf>,
) -> b_x::Result<()> {
use ktls::CorkStream;
use std::os::fd::IntoRawFd;
use std::sync::Arc;
use tokio_rustls::TlsAcceptor;
use crate::driver::TestDriver;

pub(super) async fn handle_tls_conn(stream: TcpStream) -> b_x::Result<()> {
let mut server_config = Settings::gen_rustls_server_config().unwrap();
server_config.enable_secret_extraction = true;
let driver = TestDriver;
Expand All @@ -32,7 +35,7 @@ async fn handle_tls_conn(
let is_h2 = matches!(stream.get_ref().1.alpn_protocol(), Some(b"h2"));
tracing::debug!(%is_h2, "Performed TLS handshake");

let stream = ktls::config_ktls_server(stream).await?;
let stream = ktls::config_ktls_server(stream).await.bx()?;

tracing::debug!("Set up kTLS");
let (drained, stream) = stream.into_raw();
Expand All @@ -47,15 +50,12 @@ async fn handle_tls_conn(

if is_h2 {
tracing::info!("Using HTTP/2");
h2::serve(stream.into_halves(), h2_conf, client_buf, Rc::new(driver))
.await
.map_err(|e| eyre::eyre!("h2 server error: {e:?}"))?;
h2::serve(stream.into_halves(), h2_conf, client_buf, Rc::new(driver)).await?;
} else {
tracing::info!("Using HTTP/1.1");
h1::serve(stream.into_halves(), h1_conf, client_buf, driver)
.await
.map_err(|e| eyre::eyre!("h1 server error: {e:?}"))?;
h1::serve(stream.into_halves(), h1_conf, client_buf, driver).await?;
}
Ok(())
}

pub trait ToUringTcpStream {
Expand Down

0 comments on commit 63d2961

Please sign in to comment.