Skip to content

Commit

Permalink
Fix nits for rust 1.49.0 clippy
Browse files Browse the repository at this point in the history
Some really cool new nits have been included, await over lock boundries
is going to really improve our lock based threading pattern for Rita.
  • Loading branch information
jkilpatr committed Aug 26, 2021
1 parent 8c4490a commit 91cd0f4
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 37 deletions.
2 changes: 1 addition & 1 deletion althea_kernel_interface/src/traffic_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl dyn KernelInterface {

// we need 1kbyte of burst cache per mbit of bandwidth to actually keep things
// moving
let burst = bw * 1000 as u32;
let burst = bw * 1000u32;
// amount of time a packet can spend in the burst cache, 40ms
let latency = 40u32;

Expand Down
13 changes: 3 additions & 10 deletions babel_monitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,9 @@ fn parse_neighs_sync(output: String) -> Result<Vec<Neighbor>, Error> {
Ok(entry) => entry,
Err(_) => continue,
},
rtt: match find_and_parse_babel_val("rtt", entry) {
Ok(entry) => entry,
// it's possible that our neigh does not have rtt enabled, handle
Err(_) => 0.0,
},
rttcost: match find_and_parse_babel_val("rttcost", entry) {
Ok(entry) => entry,
// it's possible that our neigh does not have rtt enabled, handle
Err(_) => 0,
},
// it's possible that the neighbor does not have rtt enabled
rtt: find_and_parse_babel_val("rtt", entry).unwrap_or(0.0),
rttcost: find_and_parse_babel_val("rttcost", entry).unwrap_or(0),
cost: match find_and_parse_babel_val("cost", entry) {
Ok(entry) => entry,
Err(_) => continue,
Expand Down
2 changes: 1 addition & 1 deletion rita/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<S> Middleware<S> for Headers {
*resp.status_mut() = StatusCode::OK;
}

if origin != "" {
if !origin.is_empty() {
#[cfg(not(feature = "dash_debug"))]
resp.headers_mut().insert(
header::HeaderName::try_from("Access-Control-Allow-Origin").unwrap(),
Expand Down
7 changes: 3 additions & 4 deletions rita/src/rita_client/dashboard/exits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ fn is_selected(exit: &ExitServer, current_exit: Option<&ExitServer>) -> bool {
fn is_tunnel_working(exit: &ExitServer, current_exit: Option<&ExitServer>) -> bool {
match (current_exit, is_selected(exit, current_exit)) {
(Some(exit), true) => match exit.info.general_details() {
Some(details) => match KI.ping_check(&details.server_internal_ip, EXIT_PING_TIMEOUT) {
Ok(ping_result) => ping_result,
Err(_) => false,
},
Some(details) => KI
.ping_check(&details.server_internal_ip, EXIT_PING_TIMEOUT)
.unwrap_or(false),
None => false,
},
(_, _) => false,
Expand Down
1 change: 1 addition & 0 deletions rita/src/rita_common/payment_validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ fn checked(msg: ToValidate, history: &mut PaymentValidator) {
}
}

#[allow(clippy::await_holding_lock)]
pub async fn validate() {
// we panic on a failed receive so it should always be longer than the minimum
// time we expect payments to take to enter the blockchain (the send timeout)
Expand Down
5 changes: 1 addition & 4 deletions rita/src/rita_common/peer_listener/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,7 @@ impl ListenInterface {
let link_ip = KI.get_link_local_device_ip(&ifname)?;

// Lookup interface index
let iface_index = match KI.get_iface_index(&ifname) {
Ok(idx) => idx,
Err(_) => 0,
};
let iface_index = KI.get_iface_index(&ifname).unwrap_or(0);
// Bond to multicast discovery address on each listen port
let multicast_socketaddr = SocketAddrV6::new(disc_ip, port, 0, iface_index);

Expand Down
5 changes: 1 addition & 4 deletions rita/src/rita_common/rita_loop/fast_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,7 @@ fn manage_gateway() {
// the is_up detection is mostly useless because these ports reside on switches which mark
// all ports as up all the time.
let gateway = match SETTING.get_network().external_nic {
Some(ref external_nic) => match KI.is_iface_up(external_nic) {
Some(val) => val,
None => false,
},
Some(ref external_nic) => KI.is_iface_up(external_nic).unwrap_or(false),
None => false,
};

Expand Down
6 changes: 2 additions & 4 deletions rita/src/rita_common/tunnel_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,8 @@ impl TunnelManager {
None => false,
};

let they_have_tunnel = match their_localid.have_tunnel {
Some(v) => v,
None => true, // when we don't know take the more conservative option
};
// when we don't know take the more conservative option and assume they do have a tunnel
let they_have_tunnel = their_localid.have_tunnel.unwrap_or(true);

let mut return_bool = false;
if we_have_tunnel {
Expand Down
2 changes: 1 addition & 1 deletion rita/src/rita_exit/traffic_watcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn watch(

// Setup the debts table
for (_, ident) in identities.clone() {
debts.insert(ident, 0 as i128);
debts.insert(ident, 0i128);
}

// accounting for 'input'
Expand Down
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
#![forbid(unsafe_code)]

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}

0 comments on commit 91cd0f4

Please sign in to comment.