Skip to content

Commit

Permalink
refactor: Combine the capnp invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyscot committed Nov 2, 2024
1 parent 64dfcea commit 2bea195
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 65 deletions.
3 changes: 2 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"type": "cargo",
"command": "doc",
"args": ["--no-deps"],
"problemMatcher": [
"$rustc"
],
Expand All @@ -14,4 +15,4 @@
"label": "rust: cargo doc"
}
]
}
}
10 changes: 2 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/client/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
35 changes: 3 additions & 32 deletions src/protocol/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IpAddr> 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";

Expand Down
30 changes: 30 additions & 0 deletions src/protocol/control_capnp.rs
Original file line number Diff line number Diff line change
@@ -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<IpAddr> for ConnectionType {
fn from(value: IpAddr) -> Self {
match value {
IpAddr::V4(_) => ConnectionType::Ipv4,
IpAddr::V6(_) => ConnectionType::Ipv6,
}
}
}
2 changes: 2 additions & 0 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@
//! [LetsEncrypt]: <https://letsencrypt.org/>
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);
Expand Down
24 changes: 3 additions & 21 deletions src/protocol/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/protocol/session_capnp.rs
Original file line number Diff line number Diff line change
@@ -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"));
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/util/io.rs
Original file line number Diff line number Diff line change
@@ -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 _};

Expand Down

0 comments on commit 2bea195

Please sign in to comment.