Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(udp): move udp mod from neqo-common to neqo-bin #1736

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" }
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
8 changes: 4 additions & 4 deletions neqo-common/src/udp.rs → neqo-bin/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -61,7 +60,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(),
Comment on lines -64 to +63
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part of the move or another change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datagram::into_data is changed to a From<Datagram> for Vec<u8> (see comment below). Instead of calling into_data, this line first leverages the new From implementation and then, as before, converts it into a Bytes (into at the end).

None of these methods allocate.

segment_size: None,
src_ip: None,
};
Expand Down Expand Up @@ -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> {
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
}
}

Comment on lines +80 to +85
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part of the move or another change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The udp module needs to convert a Datagram to a Vec. Previously this would have been done via the pub(crate) Datagram::into_data.

Given that udp module is moved outside of neqo-common crate now, pub(crate) into_data is changed into a pub From<Datagram> for Vec<u8> implementation. See also #1695 (comment).

Long story short, this just exposes into_data beyond the crate and implements it as a From instead.

#[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
Loading