From 0f7280c2271a14a03c9331dd338e0ff80a3db9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Fri, 15 Oct 2021 08:57:16 +0100 Subject: [PATCH] Fixed most recent nightly clippy warnings (#817) * Fixed most recent nightly clippy warnings * Missing wasm32 changes --- clients/client-core/src/config/mod.rs | 8 +-- .../client-libs/gateway-client/src/client.rs | 12 ++-- .../gateway-client/src/socket_state.rs | 2 +- common/socks5/requests/src/request.rs | 61 ++++++++----------- .../src/registration/handshake/shared_key.rs | 4 +- gateway/src/config/mod.rs | 8 +-- mixnode/src/config/mod.rs | 8 +-- .../network-requester/src/core.rs | 12 ++-- validator-api/src/main.rs | 7 ++- 9 files changed, 46 insertions(+), 76 deletions(-) diff --git a/clients/client-core/src/config/mod.rs b/clients/client-core/src/config/mod.rs index 857a57d1f0..6f28610494 100644 --- a/clients/client-core/src/config/mod.rs +++ b/clients/client-core/src/config/mod.rs @@ -328,16 +328,10 @@ impl Client { } } -#[derive(Debug, Deserialize, PartialEq, Serialize)] +#[derive(Debug, Default, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct Logging {} -impl Default for Logging { - fn default() -> Self { - Logging {} - } -} - #[derive(Debug, Deserialize, PartialEq, Serialize)] #[serde(default, deny_unknown_fields)] pub struct Debug { diff --git a/common/client-libs/gateway-client/src/client.rs b/common/client-libs/gateway-client/src/client.rs index ddca41f92b..3d32e03145 100644 --- a/common/client-libs/gateway-client/src/client.rs +++ b/common/client-libs/gateway-client/src/client.rs @@ -135,7 +135,7 @@ impl GatewayClient { #[cfg(not(target_arch = "wasm32"))] async fn _close_connection(&mut self) -> Result<(), GatewayClientError> { match std::mem::replace(&mut self.connection, SocketState::NotConnected) { - SocketState::Available(mut socket) => Ok(socket.close(None).await?), + SocketState::Available(mut socket) => Ok((*socket).close(None).await?), SocketState::PartiallyDelegated(_) => { unreachable!("this branch should have never been reached!") } @@ -147,7 +147,7 @@ impl GatewayClient { async fn _close_connection(&mut self) -> Result<(), GatewayClientError> { match std::mem::replace(&mut self.connection, SocketState::NotConnected) { SocketState::Available(mut socket) => { - socket.close(None).await; + (*socket).close(None).await; Ok(()) } SocketState::PartiallyDelegated(_) => { @@ -172,7 +172,7 @@ impl GatewayClient { Err(e) => return Err(GatewayClientError::NetworkError(e)), }; - self.connection = SocketState::Available(ws_stream); + self.connection = SocketState::Available(Box::new(ws_stream)); Ok(()) } @@ -183,7 +183,7 @@ impl GatewayClient { Err(e) => return Err(GatewayClientError::NetworkErrorWasm(e)), }; - self.connection = SocketState::Available(ws_stream); + self.connection = SocketState::Available(Box::new(ws_stream)); Ok(()) } @@ -605,7 +605,7 @@ impl GatewayClient { _ => unreachable!(), }; - self.connection = SocketState::Available(conn); + self.connection = SocketState::Available(Box::new(conn)); Ok(()) } @@ -628,7 +628,7 @@ impl GatewayClient { match std::mem::replace(&mut self.connection, SocketState::Invalid) { SocketState::Available(conn) => { PartiallyDelegated::split_and_listen_for_mixnet_messages( - conn, + *conn, self.packet_router.clone(), Arc::clone( self.shared_key diff --git a/common/client-libs/gateway-client/src/socket_state.rs b/common/client-libs/gateway-client/src/socket_state.rs index 7a7a01834b..80b8085499 100644 --- a/common/client-libs/gateway-client/src/socket_state.rs +++ b/common/client-libs/gateway-client/src/socket_state.rs @@ -193,7 +193,7 @@ impl PartiallyDelegated { // by notifying the future owning it to finish the execution and awaiting the result // which should be almost immediate (or an invalid state which should never, ever happen) pub(crate) enum SocketState { - Available(WsConn), + Available(Box), PartiallyDelegated(PartiallyDelegated), NotConnected, Invalid, diff --git a/common/socks5/requests/src/request.rs b/common/socks5/requests/src/request.rs index ba8c85cac8..b6551da1d4 100644 --- a/common/socks5/requests/src/request.rs +++ b/common/socks5/requests/src/request.rs @@ -63,6 +63,13 @@ impl TryFrom for RequestFlag { } } +#[derive(Debug)] +pub struct ConnectRequest { + pub conn_id: ConnectionId, + pub remote_addr: RemoteAddress, + pub return_address: Recipient, +} + /// A request from a SOCKS5 client that a Nym Socks5 service provider should /// take an action for an application using a (probably local) Nym Socks5 proxy. #[derive(Debug)] @@ -70,11 +77,7 @@ pub enum Request { /// Start a new TCP connection to the specified `RemoteAddress` and send /// the request data up the connection. /// All responses produced on this `ConnectionId` should come back to the specified `Recipient` - Connect { - conn_id: ConnectionId, - remote_addr: RemoteAddress, - return_address: Recipient, - }, + Connect(Box), /// Re-use an existing TCP connection, sending more request data up it. Send(ConnectionId, Vec, bool), @@ -87,11 +90,11 @@ impl Request { remote_addr: RemoteAddress, return_address: Recipient, ) -> Request { - Request::Connect { + Request::Connect(Box::new(ConnectRequest { conn_id, remote_addr, return_address, - } + })) } /// Construct a new Request::Send instance @@ -156,11 +159,11 @@ impl Request { let return_address = Recipient::try_from_bytes(return_bytes) .map_err(RequestError::MalformedReturnAddress)?; - Ok(Request::Connect { - conn_id: connection_id, - remote_addr: remote_address, + Ok(Request::new_connect( + connection_id, + remote_address, return_address, - }) + )) } RequestFlag::Send => { let local_closed = b[9] != 0; @@ -177,19 +180,15 @@ impl Request { pub fn into_bytes(self) -> Vec { match self { // connect is: CONN_FLAG || CONN_ID || REMOTE_LEN || REMOTE || RETURN - Request::Connect { - conn_id, - remote_addr, - return_address, - } => { - let remote_address_bytes = remote_addr.into_bytes(); + Request::Connect(req) => { + let remote_address_bytes = req.remote_addr.into_bytes(); let remote_address_bytes_len = remote_address_bytes.len() as u16; std::iter::once(RequestFlag::Connect as u8) - .chain(conn_id.to_be_bytes().iter().cloned()) + .chain(req.conn_id.to_be_bytes().iter().cloned()) .chain(remote_address_bytes_len.to_be_bytes().iter().cloned()) .chain(remote_address_bytes.into_iter()) - .chain(return_address.to_bytes().iter().cloned()) + .chain(req.return_address.to_bytes().iter().cloned()) .collect() } Request::Send(conn_id, data, local_closed) => std::iter::once(RequestFlag::Send as u8) @@ -373,15 +372,11 @@ mod request_deserialization_tests { let request = Request::try_from_bytes(&request_bytes).unwrap(); match request { - Request::Connect { - conn_id, - remote_addr, - return_address, - } => { - assert_eq!("foo.com".to_string(), remote_addr); - assert_eq!(u64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]), conn_id); + Request::Connect(req) => { + assert_eq!("foo.com".to_string(), req.remote_addr); + assert_eq!(u64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]), req.conn_id); assert_eq!( - return_address.to_bytes().to_vec(), + req.return_address.to_bytes().to_vec(), recipient.to_bytes().to_vec() ); } @@ -424,15 +419,11 @@ mod request_deserialization_tests { let request = Request::try_from_bytes(&request_bytes).unwrap(); match request { - Request::Connect { - conn_id, - remote_addr, - return_address, - } => { - assert_eq!("foo.com".to_string(), remote_addr); - assert_eq!(u64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]), conn_id); + Request::Connect(req) => { + assert_eq!("foo.com".to_string(), req.remote_addr); + assert_eq!(u64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]), req.conn_id); assert_eq!( - return_address.to_bytes().to_vec(), + req.return_address.to_bytes().to_vec(), recipient.to_bytes().to_vec() ); } diff --git a/gateway/gateway-requests/src/registration/handshake/shared_key.rs b/gateway/gateway-requests/src/registration/handshake/shared_key.rs index 063cbfaaf0..afa0d2a842 100644 --- a/gateway/gateway-requests/src/registration/handshake/shared_key.rs +++ b/gateway/gateway-requests/src/registration/handshake/shared_key.rs @@ -126,14 +126,14 @@ impl SharedKeys { // couldn't have made the first borrow mutable as you can't have an immutable borrow // together with a mutable one - let mut message_bytes_mut = &mut enc_data.to_vec()[mac_size..]; + let message_bytes_mut = &mut enc_data.to_vec()[mac_size..]; let zero_iv = stream_cipher::zero_iv::(); let iv = iv.unwrap_or(&zero_iv); stream_cipher::decrypt_in_place::( self.encryption_key(), iv, - &mut message_bytes_mut, + message_bytes_mut, ); Ok(message_bytes_mut.to_vec()) } diff --git a/gateway/src/config/mod.rs b/gateway/src/config/mod.rs index ec95e583fc..dd952ce882 100644 --- a/gateway/src/config/mod.rs +++ b/gateway/src/config/mod.rs @@ -335,16 +335,10 @@ impl Default for Gateway { } } -#[derive(Debug, Deserialize, PartialEq, Serialize)] +#[derive(Debug, Default, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct Logging {} -impl Default for Logging { - fn default() -> Self { - Logging {} - } -} - #[derive(Debug, Deserialize, PartialEq, Serialize)] #[serde(default)] pub struct Debug { diff --git a/mixnode/src/config/mod.rs b/mixnode/src/config/mod.rs index d23c04165f..26bc2d33e9 100644 --- a/mixnode/src/config/mod.rs +++ b/mixnode/src/config/mod.rs @@ -391,16 +391,10 @@ impl Default for MixNode { } } -#[derive(Debug, Deserialize, PartialEq, Serialize)] +#[derive(Debug, Default, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct Logging {} -impl Default for Logging { - fn default() -> Self { - Logging {} - } -} - #[derive(Debug, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct Verloc { diff --git a/service-providers/network-requester/src/core.rs b/service-providers/network-requester/src/core.rs index 232374e411..43b317b3ee 100644 --- a/service-providers/network-requester/src/core.rs +++ b/service-providers/network-requester/src/core.rs @@ -210,16 +210,12 @@ impl ServiceProvider { }; match deserialized_request { - Request::Connect { - conn_id, - remote_addr, - return_address, - } => self.handle_proxy_connect( + Request::Connect(req) => self.handle_proxy_connect( controller_sender, mix_input_sender, - conn_id, - remote_addr, - return_address, + req.conn_id, + req.remote_addr, + req.return_address, ), Request::Send(conn_id, data, closed) => { self.handle_proxy_send(controller_sender, conn_id, data, closed) diff --git a/validator-api/src/main.rs b/validator-api/src/main.rs index 0e4fb5e9b0..6bc517e24d 100644 --- a/validator-api/src/main.rs +++ b/validator-api/src/main.rs @@ -263,9 +263,10 @@ fn override_config(mut config: Config, matches: &ArgMatches) -> Config { { let monitor_threshold = monitor_threshold.expect("Provided monitor threshold is not a number!"); - if monitor_threshold > 100 { - panic!("Provided monitor threshold is greater than 100!"); - } + assert!( + !(monitor_threshold > 100), + "Provided monitor threshold is greater than 100!" + ); config = config.with_minimum_epoch_monitor_threshold(monitor_threshold) }