chore: Unify enable_wg_broker and enable_broker_api features

This commit is contained in:
Katherine Watson
2024-08-11 21:20:46 -07:00
parent 065b0fcc8a
commit 274d245bed
7 changed files with 20 additions and 22 deletions

View File

@@ -53,7 +53,7 @@ zeroize = { workspace = true }
hex-literal = { workspace = true, optional = true }
hex = { workspace = true, optional = true }
heck = { workspace = true, optional = true }
command-fds = { workspace = true }
command-fds = { workspace = true, optional = true }
rustix = { workspace = true }
[build-dependencies]
@@ -68,9 +68,8 @@ procspawn = {workspace = true}
tempfile = { workspace = true }
[features]
enable_wg_broker = ["enable_broker_api"]
enable_broker_api = ["rosenpass-wireguard-broker/enable_broker_api"]
experiment_memfd_secret = []
experiment_broker_api = ["rosenpass-wireguard-broker/experimental_broker_api", "command-fds"]
experiment_libcrux = ["rosenpass-ciphers/experiment_libcrux"]
experiment_api = ["hex-literal"]
internal_testing = []

View File

@@ -17,7 +17,7 @@ use crate::protocol::{SPk, SSk, SymKey};
use super::config;
#[cfg(feature = "enable_wg_broker")]
#[cfg(feature = "experiment_broker_api")]
use {
command_fds::{CommandFdExt, FdMapping},
log::{error, info},
@@ -60,7 +60,7 @@ pub struct CliArgs {
api: crate::api::cli::ApiCli,
/// path of the wireguard_psk broker socket to connect to
#[cfg(feature = "enable_wg_broker")]
#[cfg(feature = "experiment_broker_api")]
#[arg(long, group = "psk-broker-specs")]
psk_broker_path: Option<PathBuf>,
@@ -70,12 +70,12 @@ pub struct CliArgs {
/// Unix socket for the psk broker connection to use themselves, passing it to this process --
/// in Rust this can be achieved using the
/// [command-fds](https://docs.rs/command-fds/latest/command_fds/) crate
#[cfg(feature = "enable_wg_broker")]
#[cfg(feature = "experiment_broker_api")]
#[arg(long, group = "psk-broker-specs")]
psk_broker_fd: Option<i32>,
/// spawn a psk broker locally using a socket pair
#[cfg(feature = "enable_wg_broker")]
#[cfg(feature = "experiment_broker_api")]
#[arg(short, long, group = "psk-broker-specs")]
psk_broker_spawn: bool,
@@ -109,9 +109,9 @@ impl CliArgs {
None
}
#[cfg(feature = "enable_wg_broker")]
#[cfg(feature = "experiment_broker_api")]
/// returns the broker interface set by CLI args
/// returns `None` if the `enable_wg_broker` feature isn't enabled
/// returns `None` if the `experiment_broker_api` feature isn't enabled
pub fn get_broker_interface(&self) -> Option<BrokerInterface> {
if let Some(path_ref) = self.psk_broker_path.as_ref() {
Some(BrokerInterface::Socket(path_ref.to_path_buf()))
@@ -124,9 +124,9 @@ impl CliArgs {
}
}
#[cfg(not(feature = "enable_wg_broker"))]
#[cfg(not(feature = "experiment_broker_api"))]
/// returns the broker interface set by CLI args
/// returns `None` if the `enable_wg_broker` feature isn't enabled
/// returns `None` if the `experiment_broker_api` feature isn't enabled
pub fn get_broker_interface(&self) -> Option<BrokerInterface> {
None
}
@@ -445,7 +445,7 @@ impl CliArgs {
srv.event_loop()
}
#[cfg(feature = "enable_wg_broker")]
#[cfg(feature = "experiment_broker_api")]
fn create_broker(
broker_interface: Option<BrokerInterface>,
) -> Result<
@@ -460,7 +460,7 @@ impl CliArgs {
}
}
#[cfg(not(feature = "enable_wg_broker"))]
#[cfg(not(feature = "experiment_broker_api"))]
fn create_broker(
_broker_interface: Option<BrokerInterface>,
) -> Result<
@@ -470,7 +470,7 @@ impl CliArgs {
Ok(Box::new(NativeUnixBroker::new()))
}
#[cfg(feature = "enable_wg_broker")]
#[cfg(feature = "experiment_broker_api")]
fn get_broker_socket(broker_interface: BrokerInterface) -> Result<UnixStream, anyhow::Error> {
// Connect to the psk broker unix socket if one was specified
// OR OTHERWISE spawn the psk broker and use socketpair(2) to connect with them

View File

@@ -36,14 +36,14 @@ rand = {workspace = true}
procspawn = {workspace = true}
[features]
enable_broker_api=[]
experimental_broker_api = []
[[bin]]
name = "rosenpass-wireguard-broker-privileged"
path = "src/bin/priviledged.rs"
test = false
doc = false
required-features=["enable_broker_api"]
required-features = ["experimental_broker_api"]
cfg = { target_os = "linux" }
[[bin]]
@@ -51,5 +51,5 @@ name = "rosenpass-wireguard-broker-socket-handler"
test = false
path = "src/bin/socket_handler.rs"
doc = false
required-features=["enable_broker_api"]
required-features = ["experimental_broker_api"]
cfg = { target_os = "linux" }

View File

@@ -2,7 +2,6 @@ use anyhow::{bail, ensure};
use mio::Interest;
use rosenpass_util::ord::max_usize;
use std::collections::VecDeque;
use std::dbg;
use std::io::{ErrorKind, Read, Write};
use crate::{SerializedBrokerConfig, WireGuardBroker, WireguardBrokerMio};

View File

@@ -1,6 +1,6 @@
#[cfg(feature = "enable_broker_api")]
#[cfg(feature = "experimental_broker_api")]
pub mod mio_client;
#[cfg(all(feature = "enable_broker_api", target_os = "linux"))]
#[cfg(all(feature = "experimental_broker_api", target_os = "linux"))]
pub mod netlink;
pub mod native_unix;

View File

@@ -34,7 +34,7 @@ pub trait WireguardBrokerMio: WireGuardBroker {
fn unregister(&mut self, registry: &mio::Registry) -> Result<(), Self::MioError>;
}
#[cfg(feature = "enable_broker_api")]
#[cfg(feature = "experimental_broker_api")]
pub mod api;
pub mod brokers;

View File

@@ -1,4 +1,4 @@
#[cfg(feature = "enable_broker_api")]
#[cfg(feature = "experimental_broker_api")]
#[cfg(test)]
mod integration_tests {