Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bunch of clippy warnings #427

Merged
merged 2 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/client-core/src/client/cover_traffic_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl LoopCoverTrafficStream<OsRng> {
self.average_cover_message_sending_delay,
));

while let Some(_) = self.next().await {
while self.next().await.is_some() {
self.on_new_message().await;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ where
pending_acks.push(PendingAcknowledgement::new(
message_chunk,
prepared_fragment.total_delay,
recipient.clone(),
recipient,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ where

let message_preparer = MessagePreparer::new(
rng,
ack_recipient.clone(),
ack_recipient,
config.average_packet_delay,
config.average_ack_delay,
config.packet_mode,
Expand All @@ -211,7 +211,7 @@ where
// will listen for any new messages from the client
let input_message_listener = InputMessageListener::new(
Arc::clone(&ack_key),
ack_recipient.clone(),
ack_recipient,
connectors.input_receiver,
message_preparer.clone(),
action_sender.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl RealMessagesController<OsRng> {
rng,
topology_access.clone(),
Arc::clone(&config.ack_key),
config.self_recipient.clone(),
config.self_recipient,
reply_key_storage,
ack_controller_connectors,
);
Expand Down
2 changes: 1 addition & 1 deletion clients/native/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl NymClient {
pub fn as_mix_recipient(&self) -> Recipient {
Recipient::new(
*self.key_manager.identity_keypair().public_key(),
self.key_manager.encryption_keypair().public_key().clone(),
*self.key_manager.encryption_keypair().public_key(),
// TODO: below only works under assumption that gateway address == gateway id
// (which currently is true)
NodeIdentity::from_base58_string(self.config.get_base().get_gateway_id()).unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions clients/native/src/websocket/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Clone for Handler {
Handler {
msg_input: self.msg_input.clone(),
buffer_requester: self.buffer_requester.clone(),
self_full_address: self.self_full_address.clone(),
self_full_address: self.self_full_address,
socket: None,
received_response_type: Default::default(),
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Handler {
}

fn handle_self_address(&self) -> ServerResponse {
ServerResponse::SelfAddress(self.self_full_address.clone())
ServerResponse::SelfAddress(self.self_full_address)
}

fn handle_request(&mut self, request: ClientRequest) -> Option<ServerResponse> {
Expand Down
5 changes: 1 addition & 4 deletions clients/native/src/websocket/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ enum State {

impl State {
fn is_connected(&self) -> bool {
match self {
State::Connected => true,
_ => false,
}
matches!(self, State::Connected)
}
}

Expand Down
2 changes: 1 addition & 1 deletion clients/native/websocket-requests/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ mod tests {
let recipient_string = recipient.to_string();

let send_request_no_surb = ClientRequest::Send {
recipient: recipient.clone(),
recipient,
message: b"foomp".to_vec(),
with_reply_surb: false,
};
Expand Down
10 changes: 4 additions & 6 deletions clients/native/websocket-requests/src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,10 @@ impl ServerResponse {
RECEIVED_RESPONSE_TAG => Self::deserialize_received(b),
SELF_ADDRESS_RESPONSE_TAG => Self::deserialize_self_address(b),
ERROR_RESPONSE_TAG => Self::deserialize_error(b),
n => {
return Err(error::Error::new(
ErrorKind::UnknownResponse,
format!("type {}", n),
))
}
n => Err(error::Error::new(
ErrorKind::UnknownResponse,
format!("type {}", n),
)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion clients/socks5/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl NymClient {
pub fn as_mix_recipient(&self) -> Recipient {
Recipient::new(
*self.key_manager.identity_keypair().public_key(),
self.key_manager.encryption_keypair().public_key().clone(),
*self.key_manager.encryption_keypair().public_key(),
// TODO: below only works under assumption that gateway address == gateway id
// (which currently is true)
NodeIdentity::from_base58_string(self.config.get_base().get_gateway_id()).unwrap(),
Expand Down
23 changes: 4 additions & 19 deletions clients/socks5/src/socks/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl SocksClient {
let connection_id = self.connection_id;
let input_sender = self.input_sender.clone();

let recipient = self.service_provider.clone();
let recipient = self.service_provider;
let (stream, _) = ProxyRunner::new(
stream,
local_stream_remote,
Expand Down Expand Up @@ -365,27 +365,12 @@ impl SocksClient {

// Username parsing
let ulen = header[1];

let mut username = Vec::with_capacity(ulen as usize);

// For some reason the vector needs to actually be full
for _ in 0..ulen {
username.push(0);
}

let mut username = vec![0; ulen as usize];
self.stream.read_exact(&mut username).await?;

// Password Parsing
let mut plen = [0u8; 1];
self.stream.read_exact(&mut plen).await?;

let mut password = Vec::with_capacity(plen[0] as usize);

// For some reason the vector needs to actually be full
for _ in 0..plen[0] {
password.push(0);
}

let plen = self.stream.read_u8().await?;
let mut password = vec![0; plen as usize];
self.stream.read_exact(&mut password).await?;

let username_str = String::from_utf8(username)?;
Expand Down
7 changes: 5 additions & 2 deletions clients/socks5/src/socks/request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::types::{AddrType, ResponseCode, SocksProxyError};
use super::{utils as socks_utils, SOCKS_VERSION};
use log::*;
use std::fmt::{self, Display};
use tokio::prelude::*;

/// A Socks5 request hitting the proxy.
Expand Down Expand Up @@ -95,12 +96,14 @@ impl SocksRequest {
port,
})
}
}

impl Display for SocksRequest {
/// Print out the address and port to a String.
/// This might return domain:port, ipv6:port, or ipv4:port.
pub(crate) fn to_string(&self) -> String {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let address = socks_utils::pretty_print_addr(&self.addr_type, &self.addr);
format!("{}:{}", address, self.port)
write!(f, "{}:{}", address, self.port)
}
}

Expand Down
4 changes: 2 additions & 2 deletions clients/socks5/src/socks/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ impl SphinxSocksServer {
stream,
self.authenticator.clone(),
input_sender.clone(),
self.service_provider.clone(),
self.service_provider,
controller_sender.clone(),
self.self_address.clone(),
self.self_address,
);

tokio::spawn(async move {
Expand Down
15 changes: 3 additions & 12 deletions common/client-libs/gateway-client/src/socket_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,14 @@ pub(crate) enum SocketState {

impl SocketState {
pub(crate) fn is_available(&self) -> bool {
match self {
SocketState::Available(_) => true,
_ => false,
}
matches!(self, SocketState::Available(_))
}

pub(crate) fn is_partially_delegated(&self) -> bool {
match self {
SocketState::PartiallyDelegated(_) => true,
_ => false,
}
matches!(self, SocketState::PartiallyDelegated(_))
}

pub(crate) fn is_established(&self) -> bool {
match self {
SocketState::Available(_) | SocketState::PartiallyDelegated(_) => true,
_ => false,
}
matches!(self, SocketState::Available(_) | SocketState::PartiallyDelegated(_))
}
}
2 changes: 1 addition & 1 deletion common/client-libs/validator-client/src/models/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl TryInto<topology::gateway::Node> for RegisteredGateway {
.node_info
.mix_host
.to_socket_addrs()
.map_err(|err| ConversionError::InvalidAddress(err))?
.map_err(ConversionError::InvalidAddress)?
.next()
.ok_or_else(|| {
ConversionError::InvalidAddress(io::Error::new(
Expand Down
2 changes: 1 addition & 1 deletion common/client-libs/validator-client/src/models/mixnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl TryInto<topology::mix::Node> for RegisteredMix {
.node_info
.mix_host
.to_socket_addrs()
.map_err(|err| ConversionError::InvalidAddress(err))?
.map_err(ConversionError::InvalidAddress)?
.next()
.ok_or_else(|| {
ConversionError::InvalidAddress(io::Error::new(
Expand Down
2 changes: 1 addition & 1 deletion common/client-libs/validator-client/src/models/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Into<NymTopology> for Topology {
}
let mix_id = mix.mix_info.node_info.identity_key.clone();

let layer_entry = mixes.entry(layer).or_insert(Vec::new());
let layer_entry = mixes.entry(layer).or_insert_with(Vec::new);
match mix.try_into() {
Ok(mix) => layer_entry.push(mix),
Err(err) => {
Expand Down
1 change: 0 additions & 1 deletion common/crypto/src/asymmetric/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use bs58;
use ed25519_dalek::ed25519::signature::Signature as SignatureTrait;
pub use ed25519_dalek::SignatureError;
pub use ed25519_dalek::{Verifier, PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH, SIGNATURE_LENGTH};
Expand Down
2 changes: 1 addition & 1 deletion common/mixnode-common/src/cached_packet_processor/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl KeyCache {

pub(super) fn insert(&self, key: SharedSecret, cached_keys: CachedKeys) -> bool {
trace!("inserting {:?} into the cache", key);
let insertion_result = self.vpn_key_cache.insert(key.clone(), cached_keys);
let insertion_result = self.vpn_key_cache.insert(key, cached_keys);
if !insertion_result {
debug!("{:?} was put into the cache", key);
// this shouldn't really happen, but don't insert entry to invalidator if it was already
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ mod tests {
let initial_secret = final_hop.shared_secret();
let processed = final_hop.process(&processor.sphinx_key).unwrap();

processor.cache_keys(initial_secret.clone(), &processed);
processor.cache_keys(initial_secret, &processed);
let cache_entry = processor.vpn_key_cache.get(&initial_secret).unwrap();

let (cached_secret, cached_routing_keys) = cache_entry.value();
Expand All @@ -376,7 +376,7 @@ mod tests {
let initial_secret = forward_hop.shared_secret();
let processed = forward_hop.process(&processor.sphinx_key).unwrap();

processor.cache_keys(initial_secret.clone(), &processed);
processor.cache_keys(initial_secret, &processed);
let cache_entry = processor.vpn_key_cache.get(&initial_secret).unwrap();

let (cached_secret, cached_routing_keys) = cache_entry.value();
Expand Down Expand Up @@ -463,7 +463,7 @@ mod tests {

let long_data = vec![42u8; SURBAck::len() * 5];
let (ack, data) = processor
.split_hop_data_into_ack_and_message(long_data.clone())
.split_hop_data_into_ack_and_message(long_data)
.unwrap();
assert_eq!(ack.len(), SURBAck::len());
assert_eq!(data.len(), SURBAck::len() * 4)
Expand Down
2 changes: 1 addition & 1 deletion common/nymsphinx/acknowledgements/src/surb_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl SURBAck {

let expected_total_delay = delays.iter().sum();
let first_hop_address =
NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone()).unwrap();
NymNodeRoutingAddress::try_from(route.first().unwrap().address).unwrap();

Ok(SURBAck {
surb_ack_packet,
Expand Down
10 changes: 5 additions & 5 deletions common/nymsphinx/addressing/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ impl<'de> Deserialize<'de> for Recipient {
// this shouldn't panic as we just checked for length
recipient_bytes.copy_from_slice(&bytes);

Recipient::try_from_bytes(recipient_bytes).or_else(|_| {
Err(SerdeError::invalid_value(
Recipient::try_from_bytes(recipient_bytes).map_err(|_| {
SerdeError::invalid_value(
Unexpected::Other("At least one of the curve points was malformed"),
&self,
))
)
})
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ mod tests {

let recipient = Recipient::new(
*client_id_pair.public_key(),
client_enc_pair.public_key().clone(),
*client_enc_pair.public_key(),
*gateway_id_pair.public_key(),
);

Expand Down Expand Up @@ -281,7 +281,7 @@ mod tests {

let recipient = Recipient::new(
*client_id_pair.public_key(),
client_enc_pair.public_key().clone(),
*client_enc_pair.public_key(),
*gateway_id_pair.public_key(),
);

Expand Down
2 changes: 1 addition & 1 deletion common/nymsphinx/anonymous-replies/src/reply_surb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'de> Deserialize<'de> for ReplySURB {
E: SerdeError,
{
ReplySURB::from_bytes(bytes)
.or_else(|_| Err(SerdeError::invalid_length(bytes.len(), &self)))
.map_err(|_| SerdeError::invalid_length(bytes.len(), &self))
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/nymsphinx/cover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ where
.unwrap();

let first_hop_address =
NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone()).unwrap();
NymNodeRoutingAddress::try_from(route.first().unwrap().address).unwrap();

// if client is running in vpn mode, he won't even be sending cover traffic
Ok(MixPacket::new(first_hop_address, packet, PacketMode::Mix))
Expand Down
2 changes: 1 addition & 1 deletion common/nymsphinx/src/preparer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ where

// from the previously constructed route extract the first hop
let first_hop_address =
NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone()).unwrap();
NymNodeRoutingAddress::try_from(route.first().unwrap().address).unwrap();

Ok(PreparedFragment {
// the round-trip delay is the sum of delays of all hops on the forward route as
Expand Down
4 changes: 2 additions & 2 deletions common/nymsphinx/src/preparer/vpn_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ impl VPNManager {
}

#[cfg(not(target_arch = "wasm32"))]
pub(super) async fn current_secret<'a>(&'a self) -> SpinhxKeyRef<'a> {
pub(super) async fn current_secret(&self) -> SpinhxKeyRef<'_> {
self.inner.current_initial_secret.read().await
}

#[cfg(target_arch = "wasm32")]
pub(super) async fn current_secret<'a>(&'a self) -> SpinhxKeyRef<'a> {
pub(super) async fn current_secret(&self) -> SpinhxKeyRef<'_> {
&self.inner.current_initial_secret
}

Expand Down
11 changes: 4 additions & 7 deletions common/socks5/ordered-buffer/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ impl OrderedMessageBuffer {

let mut contiguous_messages = Vec::new();
let mut index = self.next_index;
loop {
if let Some(ordered_message) = self.messages.remove(&index) {
contiguous_messages.push(ordered_message);
index += 1;
} else {
break;
}

while let Some(ordered_message) = self.messages.remove(&index) {
contiguous_messages.push(ordered_message);
index += 1;
}

let high_water = index;
Expand Down
Loading