From 8805ef7c38d9f54f4536da7acbb9b32ecf45f631 Mon Sep 17 00:00:00 2001 From: David Niehues Date: Thu, 12 Dec 2024 17:27:01 +0100 Subject: [PATCH] style: Ensure inline comments start upper case and end with a dot, and fix some overlong lines. --- rp/src/cli.rs | 4 ++-- rp/src/exchange.rs | 34 ++++++++++++++++++---------------- rp/src/key.rs | 4 ++-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/rp/src/cli.rs b/rp/src/cli.rs index 26742e9..97fce50 100644 --- a/rp/src/cli.rs +++ b/rp/src/cli.rs @@ -38,9 +38,9 @@ enum CommandType { /// A new [Cli] is created by calling [Cli::parse] with the appropriate arguments. #[derive(Default)] pub struct Cli { - /// whether the output should be verbose. + /// Whether the output should be verbose. pub verbose: bool, - /// the command specified by the given arguments. + /// The command specified by the given arguments. pub command: Option, } diff --git a/rp/src/exchange.rs b/rp/src/exchange.rs index 28e985d..6deb9ba 100644 --- a/rp/src/exchange.rs +++ b/rp/src/exchange.rs @@ -33,11 +33,13 @@ pub struct ExchangeOptions { pub verbose: bool, /// path to the directory where private keys are stored. pub private_keys_dir: PathBuf, - /// The link rosenpass should run as. If None is given [exchange] will use `"rosenpass0"` instead. + /// The link rosenpass should run as. If None is given [exchange] will use `"rosenpass0"` + /// instead. pub dev: Option, - /// The IP-address rosenpass should run under + /// The IP-address rosenpass should run under. pub ip: Option, - /// The IP-address and port that the rosenpass [AppServer](rosenpass::app_server::AppServer) should use. + /// The IP-address and port that the rosenpass [AppServer](rosenpass::app_server::AppServer) + /// should use. pub listen: Option, /// Other peers a connection should be initialized to pub peers: Vec, @@ -64,9 +66,9 @@ mod netlink { /// Creates a netlink named `link_name` and changes the state to up. It returns the index /// of the interface in the list of interfaces as the result or an error if any of the - ///operations of creating the link or changing its state to up fails. + /// operations of creating the link or changing its state to up fails. pub async fn link_create_and_up(rtnetlink: &Handle, link_name: String) -> Result { - // add the link, equivalent to `ip link add type wireguard` + // Add the link, equivalent to `ip link add type wireguard`. rtnetlink .link() .add() @@ -74,7 +76,7 @@ mod netlink { .execute() .await?; - // retrieve the link to be able to up it, equivalent to `ip link show` and then + // Retrieve the link to be able to up it, equivalent to `ip link show` and then // using the link shown that is identified by `link_name`. let link = rtnetlink .link() @@ -87,7 +89,7 @@ mod netlink { .0 .unwrap()?; - // up the link, equivalent to `ip link set dev up` + // Up the link, equivalent to `ip link set dev up`. rtnetlink .link() .set(link.header.index) @@ -133,7 +135,7 @@ mod netlink { use netlink_packet_generic::GenlMessage; use netlink_packet_wireguard::{Wireguard, WireguardCmd}; - // Scope our `set` command to only the device of the specified index + // Scope our `set` command to only the device of the specified index. attr.insert(0, WgDeviceAttrs::IfIndex(index)); // Construct the WireGuard-specific netlink packet @@ -142,12 +144,12 @@ mod netlink { nlas: attr, }; - // Construct final message + // Construct final message. let genl = GenlMessage::from_payload(wgc); let mut nlmsg = NetlinkMessage::from(genl); nlmsg.header.flags = NLM_F_REQUEST | NLM_F_ACK; - // Send and wait for the ACK or error + // Send and wait for the ACK or error. let (res, _) = genetlink.request(nlmsg).await?.into_future().await; if let Some(res) = res { let res = res?; @@ -215,7 +217,7 @@ pub async fn exchange(options: ExchangeOptions) -> Result<()> { let link_name = options.dev.clone().unwrap_or("rosenpass0".to_string()); let link_index = netlink::link_create_and_up(&rtnetlink, link_name.clone()).await?; - // set up a list of (initiallc empty) cleanup handlers that are to be run if + // Set up a list of (initiallc empty) cleanup handlers that are to be run if // ctrl-c is hit or generally a `SIGINT` signal is received and always in the end. let cleanup_handlers = CleanupHandlers::new(); let final_cleanup_handlers = (&cleanup_handlers).clone(); @@ -233,8 +235,7 @@ pub async fn exchange(options: ExchangeOptions) -> Result<()> { .expect("Failed to clean up"); })?; - // run `ip address add dev ` and enqueue - // `ip address del dev ` as a cleanup + // Run `ip address add dev ` and enqueue `ip address del dev ` as a cleanup. if let Some(ip) = options.ip { let dev = options.dev.clone().unwrap_or("rosenpass0".to_string()); Command::new("ip") @@ -260,7 +261,7 @@ pub async fn exchange(options: ExchangeOptions) -> Result<()> { .await; } - // Deploy the classic wireguard private key + // Deploy the classic wireguard private key. let (connection, mut genetlink, _) = genetlink::new_connection()?; tokio::spawn(connection); @@ -309,7 +310,7 @@ pub async fn exchange(options: ExchangeOptions) -> Result<()> { anyhow::Error::msg(format!("NativeUnixBrokerConfigBaseBuilderError: {:?}", e)) } - // configure everything per peer + // Configure everything per peer. for peer in options.peers { let wgpk = peer.public_keys_dir.join("wgpk"); let pqpk = peer.public_keys_dir.join("pqpk"); @@ -389,7 +390,8 @@ pub async fn exchange(options: ExchangeOptions) -> Result<()> { match out { Ok(_) => Ok(()), Err(e) => { - // Check if the returned error is actually EINTR, in which case, the run actually succeeded. + // Check if the returned error is actually EINTR, in which case, the run actually + // succeeded. let is_ok = if let Some(e) = e.root_cause().downcast_ref::() { matches!(e.kind(), std::io::ErrorKind::Interrupted) } else { diff --git a/rp/src/key.rs b/rp/src/key.rs index 4f98bb8..f061d05 100644 --- a/rp/src/key.rs +++ b/rp/src/key.rs @@ -104,11 +104,11 @@ pub fn pubkey(private_keys_dir: &Path, public_keys_dir: &Path) -> Result<()> { Public::from_slice(public.as_bytes()) }; - // store the wireguard public key + // Store the wireguard public key. wgpk.store_b64::(public_wgpk)?; wgpk.zeroize(); - // copy the pq-public key to the public directory + // Copy the pq-public key to the public directory. fs::copy(private_pqpk, public_pqpk)?; Ok(())