Fixed most recent nightly clippy warnings (#817)

* Fixed most recent nightly clippy warnings

* Missing wasm32 changes
This commit is contained in:
Jędrzej Stuczyński
2021-10-15 08:57:16 +01:00
committed by GitHub
parent 673e13ec57
commit 0f7280c227
9 changed files with 46 additions and 76 deletions
+1 -7
View File
@@ -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 {
@@ -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
@@ -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,
+26 -35
View File
@@ -63,6 +63,13 @@ 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)]
@@ -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<ConnectRequest>),
/// Re-use an existing TCP connection, sending more request data up it.
Send(ConnectionId, Vec<u8>, 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<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)
@@ -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()
);
}
@@ -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())
}
+1 -7
View File
@@ -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 {
+1 -7
View File
@@ -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 {
@@ -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)
+4 -3
View File
@@ -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)
}