From 996543cecc016893e0638649289bc32398591e9e Mon Sep 17 00:00:00 2001 From: "(on company time)" <_@_> Date: Fri, 16 Dec 2022 13:49:34 -0600 Subject: [PATCH] :construction: wip: PTTH_QUIC to quinn 0.9.x --- Cargo.lock | 51 +++++++------------ crates/ptth_quic/Cargo.toml | 2 +- crates/ptth_quic/src/bin/ptth_quic_client.rs | 5 +- crates/ptth_quic/src/executable_end_server.rs | 9 ++-- .../ptth_quic/src/executable_relay_server.rs | 24 +++------ crates/ptth_quic/src/protocol.rs | 8 +-- crates/ptth_quic/src/quinn_utils.rs | 10 ++-- crates/ptth_quic_client_gui/Cargo.toml | 2 +- crates/ptth_quic_client_gui/src/main.rs | 5 +- 9 files changed, 41 insertions(+), 75 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bfc5688..727b9e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -553,15 +553,6 @@ dependencies = [ "slab", ] -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "generic-array" version = "0.14.6" @@ -1516,16 +1507,15 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quinn" -version = "0.8.5" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b435e71d9bfa0d8889927231970c51fb89c58fa63bffcab117c9c7a41e5ef8f" +checksum = "445cbfe2382fa023c4f2f3c7e1c95c03dcc1df2bf23cebcb2b13e1402c4394d1" dependencies = [ "bytes", - "futures-channel", - "futures-util", - "fxhash", + "pin-project-lite", "quinn-proto", "quinn-udp", + "rustc-hash", "rustls", "thiserror", "tokio", @@ -1535,17 +1525,16 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.8.4" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fce546b9688f767a57530652488420d419a8b1f44a478b451c3d1ab6d992a55" +checksum = "72ef4ced82a24bb281af338b9e8f94429b6eca01b4e66d899f40031f074e74c9" dependencies = [ "bytes", - "fxhash", "rand", "ring", + "rustc-hash", "rustls", "rustls-native-certs", - "rustls-pemfile 0.2.1", "slab", "thiserror", "tinyvec", @@ -1555,16 +1544,15 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.1.4" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07946277141531aea269befd949ed16b2c85a780ba1043244eda0969e538e54" +checksum = "641538578b21f5e5c8ea733b736895576d0fe329bb883b937db6f4d163dbaaf4" dependencies = [ - "futures-util", "libc", "quinn-proto", "socket2", - "tokio", "tracing", + "windows-sys 0.42.0", ] [[package]] @@ -1688,7 +1676,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "rustls", - "rustls-pemfile 1.0.1", + "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", @@ -1787,6 +1775,12 @@ dependencies = [ "walkdir", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustls" version = "0.20.7" @@ -1806,20 +1800,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" dependencies = [ "openssl-probe", - "rustls-pemfile 1.0.1", + "rustls-pemfile", "schannel", "security-framework", ] -[[package]] -name = "rustls-pemfile" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" -dependencies = [ - "base64 0.13.1", -] - [[package]] name = "rustls-pemfile" version = "1.0.1" diff --git a/crates/ptth_quic/Cargo.toml b/crates/ptth_quic/Cargo.toml index fa27582..30f9d16 100644 --- a/crates/ptth_quic/Cargo.toml +++ b/crates/ptth_quic/Cargo.toml @@ -13,7 +13,7 @@ base64 = "0.20.0" ctrlc = "3.2.4" futures-util = "0.3.25" hyper = { version = "0.14.23", features = ["http1", "server", "stream", "tcp"] } -quinn = "0.8.5" +quinn = "0.9.3" rand = "0.8.5" rcgen = "0.10.0" rmp-serde = "1.1.1" diff --git a/crates/ptth_quic/src/bin/ptth_quic_client.rs b/crates/ptth_quic/src/bin/ptth_quic_client.rs index 7a9dd13..d0bba4f 100644 --- a/crates/ptth_quic/src/bin/ptth_quic_client.rs +++ b/crates/ptth_quic/src/bin/ptth_quic_client.rs @@ -61,10 +61,7 @@ impl P2Client { let conf = Arc::clone (&self.conf); - let quinn::NewConnection { - connection, - .. - } = protocol::p2_connect_to_p3 (&self.endpoint, conf.relay_addr, &conf.client_id).await?; + let connection = protocol::p2_connect_to_p3 (&self.endpoint, conf.relay_addr, &conf.client_id).await?; let client_tcp_port = conf.client_tcp_port; diff --git a/crates/ptth_quic/src/executable_end_server.rs b/crates/ptth_quic/src/executable_end_server.rs index 7d6ea0e..374b295 100644 --- a/crates/ptth_quic/src/executable_end_server.rs +++ b/crates/ptth_quic/src/executable_end_server.rs @@ -140,10 +140,7 @@ impl P4EndServer { let conf = Arc::new (conf); trace! ("P4 end server connecting to P3 relay server"); - let quinn::NewConnection { - mut bi_streams, - .. - } = protocol::p4_connect_to_p3 ( + let conn = protocol::p4_connect_to_p3 ( &self.endpoint, conf.relay_addr, &conf.id @@ -163,8 +160,8 @@ impl P4EndServer { break; } } - stream_opt = bi_streams.next () => { - let (relay_send, relay_recv) = stream_opt.ok_or_else (|| anyhow::anyhow! ("P4 ran out of incoming streams. Maybe P3 shut down or disconnected?"))??; + stream_opt = conn.accept_bi () => { + let (relay_send, relay_recv) = stream_opt?; tokio::spawn (handle_bi_stream (Arc::clone (&conf), relay_send, relay_recv)); } diff --git a/crates/ptth_quic/src/executable_relay_server.rs b/crates/ptth_quic/src/executable_relay_server.rs index b796cf0..e5de31d 100644 --- a/crates/ptth_quic/src/executable_relay_server.rs +++ b/crates/ptth_quic/src/executable_relay_server.rs @@ -28,7 +28,7 @@ pub struct Opt { pub async fn main (opt: Opt) -> anyhow::Result <()> { let listen_addr = opt.listen_addr.unwrap_or_else (|| String::from ("0.0.0.0:30380")).parse ()?; - let (mut incoming, server_cert) = make_server_endpoint (listen_addr)?; + let (endpoint, server_cert) = make_server_endpoint (listen_addr)?; println! ("Base64 cert: {}", base64::encode (&server_cert)); tokio::fs::create_dir_all ("ptth_quic_output").await?; @@ -57,7 +57,7 @@ pub async fn main (opt: Opt) -> anyhow::Result <()> let task_quic_server = { let relay_state = Arc::clone (&relay_state); tokio::spawn (async move { - while let Some (conn) = incoming.next ().await { + while let Some (conn) = endpoint.accept ().await { let relay_state = Arc::clone (&relay_state); // Each new peer QUIC connection gets its own task @@ -286,13 +286,13 @@ async fn handle_quic_connection ( conn: quinn::Connecting, ) -> anyhow::Result <()> { - let mut conn = conn.await?; + let conn = conn.await?; // Everyone who connects must identify themselves with the first // bi stream // TODO: Timeout - let (mut send, mut recv) = conn.bi_streams.next ().await.ok_or_else (|| anyhow::anyhow! ("QUIC client didn't identify itself"))??; + let (mut send, mut recv) = conn.accept_bi ().await?; let peer = protocol::p3_accept_peer (&mut recv).await?; @@ -318,19 +318,13 @@ async fn handle_quic_connection ( async fn handle_p2_connection ( relay_state: Arc , - conn: quinn::NewConnection, + conn: quinn::Connection, peer: protocol::P2ClientProxy, ) -> anyhow::Result <()> { let client_id = peer.id; - let quinn::NewConnection { - mut bi_streams, - .. - } = conn; - - while let Some (bi_stream) = bi_streams.next ().await { - let (send, mut recv) = bi_stream?; + while let Ok ((send, mut recv)) = conn.accept_bi ().await { let relay_state = Arc::clone (&relay_state); let client_id = client_id.clone (); @@ -442,15 +436,11 @@ async fn handle_direc_p2_to_p4 ( async fn handle_p4_connection ( relay_state: Arc , - conn: quinn::NewConnection, + connection: quinn::Connection, peer: protocol::P4ServerProxy, ) -> anyhow::Result <()> { let server_id = peer.id; - let quinn::NewConnection { - connection, - .. - } = conn; let (tx, mut rx) = mpsc::channel (2); let p4_state = P4State { diff --git a/crates/ptth_quic/src/protocol.rs b/crates/ptth_quic/src/protocol.rs index c0cd600..3c42682 100644 --- a/crates/ptth_quic/src/protocol.rs +++ b/crates/ptth_quic/src/protocol.rs @@ -33,14 +33,14 @@ pub async fn p2_connect_to_p3 ( endpoint: &quinn::Endpoint, relay_addr: std::net::SocketAddr, client_id: &str, -) -> Result +) -> Result { if client_id.as_bytes ().len () > MAX_ID_LENGTH { bail! ("Client ID is longer than MAX_ID_LENGTH"); } let new_conn = endpoint.connect (relay_addr, "localhost")?.await?; - let (mut send, mut recv) = new_conn.connection.open_bi ().await?; + let (mut send, mut recv) = new_conn.open_bi ().await?; let cmd_type = Command::CONNECT_P2_TO_P3.0; send.write_all (&[cmd_type, 0, 0, 0]).await?; @@ -251,14 +251,14 @@ pub async fn p4_connect_to_p3 ( endpoint: &quinn::Endpoint, relay_addr: std::net::SocketAddr, server_id: &str, -) -> Result +) -> Result { if server_id.as_bytes ().len () > MAX_ID_LENGTH { bail! ("Server ID is longer than MAX_ID_LENGTH"); } let new_conn = endpoint.connect (relay_addr, "localhost")?.await?; - let (mut send, mut recv) = new_conn.connection.open_bi ().await?; + let (mut send, mut recv) = new_conn.open_bi ().await?; let cmd_type = Command::CONNECT_P4_TO_P3.0; send.write_all (&[cmd_type, 0, 0, 0]).await?; diff --git a/crates/ptth_quic/src/quinn_utils.rs b/crates/ptth_quic/src/quinn_utils.rs index b87f74d..56df875 100644 --- a/crates/ptth_quic/src/quinn_utils.rs +++ b/crates/ptth_quic/src/quinn_utils.rs @@ -8,7 +8,7 @@ use std::{ }; use quinn::{ - ClientConfig, Endpoint, Incoming, + ClientConfig, Endpoint, ServerConfig, TransportConfig, }; @@ -26,7 +26,7 @@ pub fn make_client_endpoint( let mut transport = quinn::TransportConfig::default (); transport.keep_alive_interval (Some (Duration::from_millis (5_000))); - client_cfg.transport = Arc::new (transport); + client_cfg.transport_config (Arc::new (transport)); let mut endpoint = Endpoint::client (bind_addr)?; endpoint.set_default_client_config (client_cfg); @@ -41,10 +41,10 @@ pub fn make_client_endpoint( /// - a stream of incoming QUIC connections /// - server certificate serialized into DER format #[allow(unused)] -pub fn make_server_endpoint(bind_addr: SocketAddr) -> anyhow::Result<(Incoming, Vec)> { +pub fn make_server_endpoint(bind_addr: SocketAddr) -> anyhow::Result<(Endpoint, Vec)> { let (server_config, server_cert) = configure_server()?; - let (_endpoint, incoming) = Endpoint::server (server_config, bind_addr)?; - Ok((incoming, server_cert)) + let endpoint = Endpoint::server (server_config, bind_addr)?; + Ok((endpoint, server_cert)) } /// Builds default quinn client config and trusts given certificates. diff --git a/crates/ptth_quic_client_gui/Cargo.toml b/crates/ptth_quic_client_gui/Cargo.toml index e04bcbd..2d73e6a 100644 --- a/crates/ptth_quic_client_gui/Cargo.toml +++ b/crates/ptth_quic_client_gui/Cargo.toml @@ -12,7 +12,7 @@ anyhow = "1.0.38" blake3 = "1.0.0" fltk = "1.2.8" ptth_quic = { path = "../ptth_quic" } -quinn = "0.8.5" +quinn = "0.9.3" rand = "0.8.4" rand_chacha = "0.3.1" reqwest = "0.11.4" diff --git a/crates/ptth_quic_client_gui/src/main.rs b/crates/ptth_quic_client_gui/src/main.rs index fa58aa8..d631eec 100644 --- a/crates/ptth_quic_client_gui/src/main.rs +++ b/crates/ptth_quic_client_gui/src/main.rs @@ -235,10 +235,7 @@ fn main () -> anyhow::Result <()> { let client_id = opt.client_id.unwrap_or_else (|| "bogus_client".to_string ()); - let quinn::NewConnection { - connection, - .. - } = protocol::p2_connect_to_p3 (&endpoint, relay_addr, &client_id).await + let connection = protocol::p2_connect_to_p3 (&endpoint, relay_addr, &client_id).await .context ("P2 can't connect to P3")?; Ok::<_, anyhow::Error> (connection)