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 most recent nightly clippy warnings #817

Merged
merged 2 commits into from
Oct 15, 2021
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
8 changes: 1 addition & 7 deletions clients/client-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,10 @@ impl<T: NymConfig> Client<T> {
}
}

#[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 {
Expand Down
12 changes: 6 additions & 6 deletions common/client-libs/gateway-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
Expand All @@ -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(_) => {
Expand All @@ -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(())
}

Expand All @@ -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(())
}

Expand Down Expand Up @@ -605,7 +605,7 @@ impl GatewayClient {
_ => unreachable!(),
};

self.connection = SocketState::Available(conn);
self.connection = SocketState::Available(Box::new(conn));
Ok(())
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion common/client-libs/gateway-client/src/socket_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WsConn>),
PartiallyDelegated(PartiallyDelegated),
NotConnected,
Invalid,
Expand Down
61 changes: 26 additions & 35 deletions common/socks5/requests/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,21 @@ impl TryFrom<u8> 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)]
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<ConnectRequest>),

/// Re-use an existing TCP connection, sending more request data up it.
Send(ConnectionId, Vec<u8>, bool),
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -177,19 +180,15 @@ impl Request {
pub fn into_bytes(self) -> Vec<u8> {
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)
Expand Down Expand Up @@ -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()
);
}
Expand Down Expand Up @@ -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()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<GatewayEncryptionAlgorithm>();
let iv = iv.unwrap_or(&zero_iv);
stream_cipher::decrypt_in_place::<GatewayEncryptionAlgorithm>(
self.encryption_key(),
iv,
&mut message_bytes_mut,
message_bytes_mut,
);
Ok(message_bytes_mut.to_vec())
}
Expand Down
8 changes: 1 addition & 7 deletions gateway/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 1 addition & 7 deletions mixnode/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 4 additions & 8 deletions service-providers/network-requester/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions validator-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down