From c32fa7cc2bd172490eb3ddbe8ce4d43a06b839b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sat, 20 Jan 2024 10:27:15 +0100 Subject: [PATCH] Fix ws clippy warnings --- crates/ws/src/workers/socket/connection.rs | 9 +++++++- crates/ws/src/workers/socket/mod.rs | 1 + crates/ws/src/workers/swarm/mod.rs | 1 + crates/ws_load_test/src/network.rs | 24 +++++++++++++--------- crates/ws_protocol/src/lib.rs | 4 +--- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/crates/ws/src/workers/socket/connection.rs b/crates/ws/src/workers/socket/connection.rs index 5250b79..00de5c6 100644 --- a/crates/ws/src/workers/socket/connection.rs +++ b/crates/ws/src/workers/socket/connection.rs @@ -41,6 +41,9 @@ use crate::workers::socket::calculate_in_message_consumer_index; #[cfg(feature = "metrics")] use crate::workers::socket::{ip_version_to_metrics_str, WORKER_INDEX}; +/// Optional second tuple field is for peer id hex representation +type PeerClientGauge = (Gauge, Option); + pub struct ConnectionRunner { pub config: Rc, pub access_list: Arc, @@ -283,6 +286,8 @@ impl ConnectionReader { } } + // Silence RefCell lint due to false positives + #[allow(clippy::await_holding_refcell_ref)] async fn handle_announce_request(&mut self, request: AnnounceRequest) -> anyhow::Result<()> { #[cfg(feature = "metrics")] self.total_announce_requests_counter.increment(1); @@ -485,6 +490,8 @@ struct ConnectionWriter { } impl ConnectionWriter { + // Silence RefCell lint due to false positives + #[allow(clippy::await_holding_refcell_ref)] async fn run_out_message_loop(&mut self) -> anyhow::Result<()> { loop { let (meta, out_message) = self.out_message_receiver.recv().await.ok_or_else(|| { @@ -590,7 +597,7 @@ impl ConnectionWriter { struct ConnectionCleanupData { announced_info_hashes: Rc>>, ip_version: IpVersion, - opt_peer_client: Rc)>>>, + opt_peer_client: Rc>>, #[cfg(feature = "metrics")] active_connections_gauge: Gauge, } diff --git a/crates/ws/src/workers/socket/mod.rs b/crates/ws/src/workers/socket/mod.rs index 03e17c5..040fce7 100644 --- a/crates/ws/src/workers/socket/mod.rs +++ b/crates/ws/src/workers/socket/mod.rs @@ -48,6 +48,7 @@ struct ConnectionHandle { valid_until_after_tls_update: Option, } +#[allow(clippy::too_many_arguments)] pub async fn run_socket_worker( _sentinel: PanicSentinel, config: Config, diff --git a/crates/ws/src/workers/swarm/mod.rs b/crates/ws/src/workers/swarm/mod.rs index 7863abe..f26c34d 100644 --- a/crates/ws/src/workers/swarm/mod.rs +++ b/crates/ws/src/workers/swarm/mod.rs @@ -24,6 +24,7 @@ use self::storage::TorrentMaps; #[cfg(feature = "metrics")] thread_local! { static WORKER_INDEX: ::std::cell::Cell = Default::default() } +#[allow(clippy::too_many_arguments)] pub async fn run_swarm_worker( _sentinel: PanicSentinel, config: Config, diff --git a/crates/ws_load_test/src/network.rs b/crates/ws_load_test/src/network.rs index f4e1744..a0aa125 100644 --- a/crates/ws_load_test/src/network.rs +++ b/crates/ws_load_test/src/network.rs @@ -149,6 +149,19 @@ impl Connection { } async fn send_message(&mut self) -> anyhow::Result<()> { + let request = self.create_request(); + + self.stream.send(request.to_ws_message()).await?; + + self.load_test_state + .statistics + .requests + .fetch_add(1, Ordering::Relaxed); + + Ok(()) + } + + fn create_request(&mut self) -> InMessage { let mut rng = self.rng.borrow_mut(); let request = match random_request_type(&self.config, &mut *rng) { @@ -226,18 +239,9 @@ impl Connection { } }; - drop(rng); - self.can_send_answer = None; - self.stream.send(request.to_ws_message()).await?; - - self.load_test_state - .statistics - .requests - .fetch_add(1, Ordering::Relaxed); - - Ok(()) + request } async fn read_message(&mut self) -> anyhow::Result<()> { diff --git a/crates/ws_protocol/src/lib.rs b/crates/ws_protocol/src/lib.rs index 6a4ed40..2652e86 100644 --- a/crates/ws_protocol/src/lib.rs +++ b/crates/ws_protocol/src/lib.rs @@ -370,8 +370,6 @@ mod tests { ::simd_json::serde::from_str(&mut json).unwrap() }; - let success = info_hashes == deserialized; - - success + info_hashes == deserialized } }