From 177385e02466115755a815edb334bbe5fee144a4 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 15 Mar 2024 13:21:32 +0100 Subject: [PATCH] refactor(udp): move udp mod from neqo-common to neqo-bin (#1736) The `udp` module is only used in the `neqo_bin` crate, more specifically by the Neqo client and server implementation. This commit moves the `udp` module to `neqo-bin`. Co-authored-by: Lars Eggert --- neqo-bin/Cargo.toml | 3 ++- neqo-bin/src/bin/client/main.rs | 3 ++- neqo-bin/src/bin/server/main.rs | 3 ++- neqo-bin/src/lib.rs | 2 ++ {neqo-common => neqo-bin}/src/udp.rs | 8 ++++---- neqo-common/Cargo.toml | 3 --- neqo-common/src/datagram.rs | 12 ++++++------ neqo-common/src/lib.rs | 2 -- 8 files changed, 18 insertions(+), 18 deletions(-) rename {neqo-common => neqo-bin}/src/udp.rs (98%) diff --git a/neqo-bin/Cargo.toml b/neqo-bin/Cargo.toml index 2beafa7e42..d36d2ecdca 100644 --- a/neqo-bin/Cargo.toml +++ b/neqo-bin/Cargo.toml @@ -28,12 +28,13 @@ clap = { version = "4.4", default-features = false, features = ["std", "color", futures = { version = "0.3", default-features = false, features = ["alloc"] } hex = { version = "0.4", default-features = false, features = ["std"] } log = { version = "0.4", default-features = false } -neqo-common = { path = "./../neqo-common", features = ["udp"] } +neqo-common = { path = "./../neqo-common" } neqo-crypto = { path = "./../neqo-crypto" } neqo-http3 = { path = "./../neqo-http3" } neqo-qpack = { path = "./../neqo-qpack" } neqo-transport = { path = "./../neqo-transport" } qlog = { version = "0.12", default-features = false } +quinn-udp = { git = "https://github.com/quinn-rs/quinn/", rev = "a947962131aba8a6521253d03cc948b20098a2d6" } regex = { version = "1.9", default-features = false, features = ["unicode-perl"] } tokio = { version = "1", default-features = false, features = ["net", "time", "macros", "rt", "rt-multi-thread"] } url = { version = "2.5", default-features = false } diff --git a/neqo-bin/src/bin/client/main.rs b/neqo-bin/src/bin/client/main.rs index 4710f8b222..d472dfb2bc 100644 --- a/neqo-bin/src/bin/client/main.rs +++ b/neqo-bin/src/bin/client/main.rs @@ -21,7 +21,8 @@ use futures::{ future::{select, Either}, FutureExt, TryFutureExt, }; -use neqo_common::{self as common, qdebug, qinfo, qlog::NeqoQlog, udp, Datagram, Role}; +use neqo_bin::udp; +use neqo_common::{self as common, qdebug, qinfo, qlog::NeqoQlog, Datagram, Role}; use neqo_crypto::{ constants::{TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256}, init, Cipher, ResumptionToken, diff --git a/neqo-bin/src/bin/server/main.rs b/neqo-bin/src/bin/server/main.rs index da8de3831c..f694cf98c1 100644 --- a/neqo-bin/src/bin/server/main.rs +++ b/neqo-bin/src/bin/server/main.rs @@ -24,7 +24,8 @@ use futures::{ future::{select, select_all, Either}, FutureExt, }; -use neqo_common::{hex, qinfo, qwarn, udp, Datagram, Header}; +use neqo_bin::udp; +use neqo_common::{hex, qinfo, qwarn, Datagram, Header}; use neqo_crypto::{ constants::{TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256}, generate_ech_keys, init_db, random, AntiReplay, Cipher, diff --git a/neqo-bin/src/lib.rs b/neqo-bin/src/lib.rs index 4fe47d5cbf..8a7ff69b69 100644 --- a/neqo-bin/src/lib.rs +++ b/neqo-bin/src/lib.rs @@ -17,6 +17,8 @@ use neqo_transport::{ Version, }; +pub mod udp; + #[derive(Debug, Parser)] pub struct SharedArgs { #[arg(short = 'a', long, default_value = "h3")] diff --git a/neqo-common/src/udp.rs b/neqo-bin/src/udp.rs similarity index 98% rename from neqo-common/src/udp.rs rename to neqo-bin/src/udp.rs index c27b0632ff..632a1293d7 100644 --- a/neqo-common/src/udp.rs +++ b/neqo-bin/src/udp.rs @@ -13,11 +13,10 @@ use std::{ slice, }; +use neqo_common::{Datagram, IpTos}; use quinn_udp::{EcnCodepoint, RecvMeta, Transmit, UdpSocketState}; use tokio::io::Interest; -use crate::{Datagram, IpTos}; - /// Socket receive buffer size. /// /// Allows reading multiple datagrams in a single [`Socket::recv`] call. @@ -61,7 +60,7 @@ impl Socket { let transmit = Transmit { destination: d.destination(), ecn: EcnCodepoint::from_bits(Into::::into(d.tos())), - contents: d.into_data().into(), + contents: Vec::from(d).into(), segment_size: None, src_ip: None, }; @@ -129,8 +128,9 @@ impl Socket { #[cfg(test)] mod tests { + use neqo_common::{IpTosDscp, IpTosEcn}; + use super::*; - use crate::{IpTosDscp, IpTosEcn}; #[tokio::test] async fn datagram_tos() -> Result<(), io::Error> { diff --git a/neqo-common/Cargo.toml b/neqo-common/Cargo.toml index dae8362bfd..89eaa53890 100644 --- a/neqo-common/Cargo.toml +++ b/neqo-common/Cargo.toml @@ -18,16 +18,13 @@ enum-map = { version = "2.7", default-features = false } env_logger = { version = "0.10", default-features = false } log = { version = "0.4", default-features = false } qlog = { version = "0.12", default-features = false } -quinn-udp = { git = "https://github.com/quinn-rs/quinn/", rev = "a947962131aba8a6521253d03cc948b20098a2d6", optional = true } time = { version = "0.3", default-features = false, features = ["formatting"] } -tokio = { version = "1", default-features = false, features = ["net", "time", "macros", "rt", "rt-multi-thread"], optional = true } [dev-dependencies] test-fixture = { path = "../test-fixture" } [features] ci = [] -udp = ["dep:quinn-udp", "dep:tokio"] [target."cfg(windows)".dependencies.winapi] version = "0.3" diff --git a/neqo-common/src/datagram.rs b/neqo-common/src/datagram.rs index 04ba1a45a1..9cebb64ea5 100644 --- a/neqo-common/src/datagram.rs +++ b/neqo-common/src/datagram.rs @@ -53,12 +53,6 @@ impl Datagram { pub fn ttl(&self) -> Option { self.ttl } - - #[cfg(feature = "udp")] - #[must_use] - pub(crate) fn into_data(self) -> Vec { - self.d - } } impl Deref for Datagram { @@ -83,6 +77,12 @@ impl std::fmt::Debug for Datagram { } } +impl From for Vec { + fn from(datagram: Datagram) -> Self { + datagram.d + } +} + #[cfg(test)] use test_fixture::datagram; diff --git a/neqo-common/src/lib.rs b/neqo-common/src/lib.rs index fe88097983..e988c6071d 100644 --- a/neqo-common/src/lib.rs +++ b/neqo-common/src/lib.rs @@ -16,8 +16,6 @@ pub mod log; pub mod qlog; pub mod timer; pub mod tos; -#[cfg(feature = "udp")] -pub mod udp; use std::fmt::Write;