Skip to content

Commit

Permalink
style: Ensure inline comments start upper case and end with a dot, an…
Browse files Browse the repository at this point in the history
…d fix some overlong lines.
  • Loading branch information
DavidNiehues committed Dec 12, 2024
1 parent cca02dc commit 8805ef7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions rp/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Command>,
}

Expand Down
34 changes: 18 additions & 16 deletions rp/src/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// The IP-address rosenpass should run under
/// The IP-address rosenpass should run under.
pub ip: Option<String>,
/// 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<SocketAddr>,
/// Other peers a connection should be initialized to
pub peers: Vec<ExchangePeer>,
Expand All @@ -64,17 +66,17 @@ 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<u32> {
// add the link, equivalent to `ip link add <link_name> type wireguard`
// Add the link, equivalent to `ip link add <link_name> type wireguard`.
rtnetlink
.link()
.add()
.wireguard(link_name.clone())
.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()
Expand All @@ -87,7 +89,7 @@ mod netlink {
.0
.unwrap()?;

// up the link, equivalent to `ip link set dev <DEV> up`
// Up the link, equivalent to `ip link set dev <DEV> up`.
rtnetlink
.link()
.set(link.header.index)
Expand Down Expand Up @@ -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
Expand All @@ -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?;
Expand Down Expand Up @@ -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();
Expand All @@ -233,8 +235,7 @@ pub async fn exchange(options: ExchangeOptions) -> Result<()> {
.expect("Failed to clean up");
})?;

// run `ip address add <ip> dev <dev>` and enqueue
// `ip address del <ip> dev <dev>` as a cleanup
// Run `ip address add <ip> dev <dev>` and enqueue `ip address del <ip> dev <dev>` as a cleanup.
if let Some(ip) = options.ip {
let dev = options.dev.clone().unwrap_or("rosenpass0".to_string());
Command::new("ip")
Expand All @@ -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);

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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::<std::io::Error>() {
matches!(e.kind(), std::io::ErrorKind::Interrupted)
} else {
Expand Down
4 changes: 2 additions & 2 deletions rp/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<WG_B64_LEN, _>(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(())
Expand Down

0 comments on commit 8805ef7

Please sign in to comment.