Skip to content

Commit

Permalink
refactor(udp): move udp mod from neqo-common to neqo-bin
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
mxinden committed Mar 12, 2024
1 parent d091f16 commit df73dc1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
3 changes: 2 additions & 1 deletion neqo-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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", optional = true }
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 }
Expand Down
3 changes: 2 additions & 1 deletion neqo-bin/src/bin/client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion neqo-bin/src/bin/server/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions neqo-bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use neqo_transport::{
Version,
};

pub mod udp;

#[derive(Debug, Parser)]
pub struct SharedArgs {
#[arg(short = 'a', long, default_value = "h3")]
Expand Down
6 changes: 3 additions & 3 deletions neqo-common/src/udp.rs → neqo-bin/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
use quinn_udp::{EcnCodepoint, RecvMeta, Transmit, UdpSocketState};
use tokio::io::Interest;

use crate::{Datagram, IpTos};
use neqo_common::{Datagram, IpTos};

/// Socket receive buffer size.
///
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Socket {
let transmit = Transmit {
destination: d.destination(),
ecn: EcnCodepoint::from_bits(Into::<u8>::into(d.tos())),
contents: d.into_data().into(),
contents: Vec::from(d).into(),
segment_size: None,
src_ip: None,
};
Expand Down Expand Up @@ -130,7 +130,7 @@ impl Socket {
#[cfg(test)]
mod tests {
use super::*;
use crate::{IpTosDscp, IpTosEcn};
use neqo_common::{IpTosDscp, IpTosEcn};

#[tokio::test]
async fn datagram_tos() -> Result<(), io::Error> {
Expand Down
3 changes: 0 additions & 3 deletions neqo-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions neqo-common/src/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ impl Datagram {
pub fn ttl(&self) -> Option<u8> {
self.ttl
}

#[cfg(feature = "udp")]
#[must_use]
pub(crate) fn into_data(self) -> Vec<u8> {
self.d
}
}

impl Deref for Datagram {
Expand All @@ -83,6 +77,12 @@ impl std::fmt::Debug for Datagram {
}
}

impl From<Datagram> for Vec<u8> {
fn from(datagram: Datagram) -> Self {
datagram.d
}
}

#[cfg(test)]
use test_fixture::datagram;

Expand Down
2 changes: 0 additions & 2 deletions neqo-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit df73dc1

Please sign in to comment.