From 2bea19568e332138c08f105192166ffcb16f37c9 Mon Sep 17 00:00:00 2001 From: Ross Younger Date: Sat, 2 Nov 2024 17:05:23 +1300 Subject: [PATCH] refactor: Combine the capnp invocations --- .vscode/tasks.json | 3 ++- build.rs | 10 ++-------- src/client/main_loop.rs | 2 +- src/protocol/control.rs | 35 +++-------------------------------- src/protocol/control_capnp.rs | 30 ++++++++++++++++++++++++++++++ src/protocol/mod.rs | 2 ++ src/protocol/session.rs | 24 +++--------------------- src/protocol/session_capnp.rs | 19 +++++++++++++++++++ src/server.rs | 2 +- src/util/io.rs | 2 +- 10 files changed, 64 insertions(+), 65 deletions(-) create mode 100644 src/protocol/control_capnp.rs create mode 100644 src/protocol/session_capnp.rs diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 2049b01..9a6a5f7 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,6 +4,7 @@ { "type": "cargo", "command": "doc", + "args": ["--no-deps"], "problemMatcher": [ "$rustc" ], @@ -14,4 +15,4 @@ "label": "rust: cargo doc" } ] -} \ No newline at end of file +} diff --git a/build.rs b/build.rs index 6752e63..381ee2d 100644 --- a/build.rs +++ b/build.rs @@ -6,16 +6,10 @@ fn main() { capnpc::CompilerCommand::new() .src_prefix("schema") .file("schema/session.capnp") - .default_parent_module(vec!["protocol::session".into()]) - .run() - .expect("session protocol compiler command"); - - capnpc::CompilerCommand::new() - .src_prefix("schema") .file("schema/control.capnp") - .default_parent_module(vec!["protocol::control".into()]) + .default_parent_module(vec!["protocol".into()]) .run() - .expect("control protocol compiler command"); + .expect("capnpc invocation failed"); } fn process_version_string() { diff --git a/src/client/main_loop.rs b/src/client/main_loop.rs index 0e94b6f..8fa2534 100644 --- a/src/client/main_loop.rs +++ b/src/client/main_loop.rs @@ -2,7 +2,7 @@ // (c) 2024 Ross Younger use crate::client::control::Channel; -use crate::protocol::session::session_capnp::Status; +use crate::protocol::session::Status; use crate::protocol::session::{FileHeader, FileTrailer, Response}; use crate::protocol::{RawStreamPair, StreamPair}; use crate::transport::{BandwidthParams, QuicParams, ThroughputMode}; diff --git a/src/protocol/control.rs b/src/protocol/control.rs index 088d3b8..920731d 100644 --- a/src/protocol/control.rs +++ b/src/protocol/control.rs @@ -22,43 +22,14 @@ //! [quic]: https://quicwg.github.io/ //! [capnproto]: https://capnproto.org/ +pub use super::control_capnp::client_message::ConnectionType; + +use super::control_capnp; use anyhow::Result; use capnp::message::ReaderOptions; -pub use control_capnp::client_message::ConnectionType; use quinn::ConnectionStats; use tokio_util::compat::{TokioAsyncReadCompatExt as _, TokioAsyncWriteCompatExt as _}; -/// Low-level protocol structures and serialisation, autogenerated from `session.capnp.` -#[allow( - missing_debug_implementations, - single_use_lifetimes, - unreachable_pub, - missing_docs, - clippy::expl_impl_clone_on_copy, - clippy::match_same_arms, - clippy::missing_panics_doc, - clippy::module_name_repetitions, - clippy::must_use_candidate, - clippy::semicolon_if_nothing_returned, - clippy::uninlined_format_args, - clippy::used_underscore_binding -)] -pub mod control_capnp { - use client_message::ConnectionType; - use std::net::IpAddr; - - include!(concat!(env!("OUT_DIR"), "/control_capnp.rs")); - - impl From for ConnectionType { - fn from(value: std::net::IpAddr) -> Self { - match value { - IpAddr::V4(_) => ConnectionType::Ipv4, - IpAddr::V6(_) => ConnectionType::Ipv6, - } - } - } -} - /// Server banner message, sent on stdout and checked by the client pub const BANNER: &str = "qcp-server-1\n"; diff --git a/src/protocol/control_capnp.rs b/src/protocol/control_capnp.rs new file mode 100644 index 0000000..1d6b12d --- /dev/null +++ b/src/protocol/control_capnp.rs @@ -0,0 +1,30 @@ +//! Low-level protocol structures and serialisation, autogenerated from `control.capnp` +// (c) 2024 Ross Younger +#![allow( + missing_debug_implementations, + single_use_lifetimes, + unreachable_pub, + missing_docs, + clippy::expl_impl_clone_on_copy, + clippy::match_same_arms, + clippy::missing_panics_doc, + clippy::module_name_repetitions, + clippy::must_use_candidate, + clippy::semicolon_if_nothing_returned, + clippy::uninlined_format_args, + clippy::used_underscore_binding +)] + +include!(concat!(env!("OUT_DIR"), "/control_capnp.rs")); + +use client_message::ConnectionType; +use std::net::IpAddr; + +impl From for ConnectionType { + fn from(value: IpAddr) -> Self { + match value { + IpAddr::V4(_) => ConnectionType::Ipv4, + IpAddr::V6(_) => ConnectionType::Ipv6, + } + } +} diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 8e91ce7..509ae88 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -109,7 +109,9 @@ //! [LetsEncrypt]: pub mod control; +pub mod control_capnp; pub mod session; +pub mod session_capnp; /// Helper type definition (syntactic sugar) pub(crate) type RawStreamPair = (quinn::SendStream, quinn::RecvStream); diff --git a/src/protocol/session.rs b/src/protocol/session.rs index 395d965..4d99c49 100644 --- a/src/protocol/session.rs +++ b/src/protocol/session.rs @@ -38,30 +38,12 @@ //! [quic]: https://quicwg.github.io/ //! [capnproto]: https://capnproto.org/ -/// Low-level protocol structures and serialisation, autogenerated from session.capnp -#[allow( - missing_debug_implementations, - single_use_lifetimes, - unreachable_pub, - missing_docs, - clippy::expl_impl_clone_on_copy, - clippy::match_same_arms, - clippy::missing_panics_doc, - clippy::module_name_repetitions, - clippy::must_use_candidate, - clippy::semicolon_if_nothing_returned, - clippy::uninlined_format_args, - clippy::used_underscore_binding -)] -pub mod session_capnp { - include!(concat!(env!("OUT_DIR"), "/session_capnp.rs")); -} - -use std::fmt::Display; +pub use super::session_capnp::Status; +use super::session_capnp; use anyhow::Result; use capnp::message::ReaderOptions; -use session_capnp::Status; +use std::fmt::Display; use tokio_util::compat::TokioAsyncReadCompatExt as _; /// Command packet diff --git a/src/protocol/session_capnp.rs b/src/protocol/session_capnp.rs new file mode 100644 index 0000000..f897e75 --- /dev/null +++ b/src/protocol/session_capnp.rs @@ -0,0 +1,19 @@ +//! Low-level protocol structures and serialisation, autogenerated from `session.capnp` +// (c) 2024 Ross Younger + +#![allow( + missing_debug_implementations, + single_use_lifetimes, + unreachable_pub, + missing_docs, + clippy::expl_impl_clone_on_copy, + clippy::match_same_arms, + clippy::missing_panics_doc, + clippy::module_name_repetitions, + clippy::must_use_candidate, + clippy::semicolon_if_nothing_returned, + clippy::uninlined_format_args, + clippy::used_underscore_binding +)] + +include!(concat!(env!("OUT_DIR"), "/session_capnp.rs")); diff --git a/src/server.rs b/src/server.rs index 92cdd16..3418a4b 100644 --- a/src/server.rs +++ b/src/server.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use std::sync::Arc; use crate::protocol::control::{ClientMessage, ClosedownReport, ServerMessage}; -use crate::protocol::session::{session_capnp::Status, Command, FileHeader, FileTrailer, Response}; +use crate::protocol::session::{Command, FileHeader, FileTrailer, Response, Status}; use crate::protocol::{self, StreamPair}; use crate::transport::BandwidthParams; use crate::util::socket::bind_range_for_family; diff --git a/src/util/io.rs b/src/util/io.rs index 759f2b9..3283640 100644 --- a/src/util/io.rs +++ b/src/util/io.rs @@ -1,7 +1,7 @@ //! File I/O helpers // (c) 2024 Ross Younger -use crate::protocol::session::session_capnp::Status; +use crate::protocol::session::Status; use futures_util::TryFutureExt as _; use std::{fs::Metadata, io::ErrorKind, path::Path, path::PathBuf, str::FromStr as _};