Fixed clippy warnings

This commit is contained in:
Jedrzej Stuczynski
2020-02-19 15:33:37 +00:00
parent a6c389b5a6
commit a62744a177
8 changed files with 15 additions and 23 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ pub fn encapsulate_message<T: NymTopology>(
average_delay: time::Duration,
) -> Result<(SocketAddr, SphinxPacket), SphinxPacketEncapsulationError> {
let mut providers = topology.providers();
if providers.len() == 0 {
if providers.is_empty() {
return Err(SphinxPacketEncapsulationError::NoValidProvidersError);
}
// unwrap is fine here as we asserted there is at least single provider
+4 -4
View File
@@ -73,7 +73,7 @@ impl PathChecker {
// iteration is used to distinguish packets sent through the same path (as the healthcheck
// may try to send say 10 packets through given path)
fn unique_path_key(path: &Vec<SphinxNode>, check_id: [u8; 16], iteration: u8) -> Vec<u8> {
fn unique_path_key(path: &[SphinxNode], check_id: [u8; 16], iteration: u8) -> Vec<u8> {
check_id
.iter()
.cloned()
@@ -173,8 +173,8 @@ impl PathChecker {
self.update_path_statuses(provider_messages);
}
pub(crate) async fn send_test_packet(&mut self, path: &Vec<SphinxNode>, iteration: u8) {
if path.len() == 0 {
pub(crate) async fn send_test_packet(&mut self, path: &[SphinxNode], iteration: u8) {
if path.is_empty() {
warn!("trying to send test packet through an empty path!");
return;
}
@@ -221,7 +221,7 @@ impl PathChecker {
let first_node_client = self
.layer_one_clients
.entry(first_node_key)
.or_insert(Some(mix_client::MixClient::new()));
.or_insert_with(|| Some(mix_client::MixClient::new()));
if first_node_client.is_none() {
debug!("we can ignore this path as layer one mix is inaccessible");
+3 -7
View File
@@ -16,7 +16,7 @@ impl std::fmt::Display for HealthCheckResult {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
write!(f, "NETWORK HEALTH\n==============\n")?;
for score in self.0.iter() {
write!(f, "{}\n", score)?
writeln!(f, "{}", score)?
}
Ok(())
}
@@ -34,12 +34,8 @@ impl HealthCheckResult {
let health = mixes
.into_iter()
.map(|node| NodeScore::from_mixnode(node))
.chain(
providers
.into_iter()
.map(|node| NodeScore::from_provider(node)),
)
.map(NodeScore::from_mixnode)
.chain(providers.into_iter().map(NodeScore::from_provider))
.collect();
HealthCheckResult(health)
+1 -1
View File
@@ -110,7 +110,7 @@ impl NodeScore {
pub_key: NodeAddressBytes::from_base58_string(node.pub_key),
addresses: vec![node.mixnet_listener, node.client_listener],
version: node.version,
layer: format!("provider"),
layer: "provider".to_string(),
packets_sent: 0,
packets_received: 0,
}
+2 -2
View File
@@ -125,7 +125,7 @@ impl ClientRequest {
Err(e) => {
warn!("Failed to fetch client messages - {:?}", e);
return ServerResponse::Error {
message: format!("Server failed to receive messages").to_string(),
message: "Server failed to receive messages".to_string(),
};
}
};
@@ -275,7 +275,7 @@ async fn accept_connection<T: 'static + NymTopology>(
topology: topology.clone(),
msg_input: msg_input.clone(),
msg_query: msg_query.clone(),
self_address: self_address.clone(),
self_address,
};
match handle_connection(&buf[..n], request_handling_data).await {
Ok(res) => res,
+2 -5
View File
@@ -239,7 +239,7 @@ impl ClientRequest {
Err(e) => {
warn!("Failed to fetch client messages - {:?}", e);
return ServerResponse::Error {
message: format!("Server failed to receive messages").to_string(),
message: "Server failed to receive messages".to_string(),
};
}
};
@@ -353,10 +353,7 @@ async fn accept_connection<T: 'static + NymTopology>(
}
};
let mut should_close = false;
if message.is_close() {
should_close = true;
}
let should_close = message.is_close();
if let Err(err) = msg_tx.unbounded_send(message) {
error!(
@@ -72,7 +72,7 @@ impl ProviderResponse for PullResponse {
return Err(ProviderResponseError::UnmarshalErrorInvalidLength);
}
let mut bytes_copy = bytes.clone();
let mut bytes_copy = bytes;
let num_msgs = read_be_u16(&mut bytes_copy);
// can we read all lengths of messages?
+1 -2
View File
@@ -63,7 +63,7 @@ impl ClientLedger {
}
fn has_token(&self, auth_token: &AuthToken) -> bool {
return self.0.contains_key(auth_token);
self.0.contains_key(auth_token)
}
fn insert_token(
@@ -155,7 +155,6 @@ impl ServiceProvider {
)
.unwrap_or_else(|e| {
error!("failed to store processed sphinx message; err = {:?}", e);
return;
});
}
Err(e) => {