From e7d8ba1864ea26d544019feae401e8ca8495718f Mon Sep 17 00:00:00 2001 From: draoi Date: Thu, 27 Jun 2024 13:54:35 +0200 Subject: [PATCH] refine_session: use remove_if_exists() method to delete entry when refinery fails There's no need to acquire the write lock in the refinery when we can just use one of the hosts methods. --- src/net/hosts.rs | 2 +- src/net/session/refine_session.rs | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/net/hosts.rs b/src/net/hosts.rs index 5980ba31e..07ce89045 100644 --- a/src/net/hosts.rs +++ b/src/net/hosts.rs @@ -645,7 +645,7 @@ impl HostContainer { } /// Remove an entry from a hostlist if it exists. - async fn remove_if_exists(&self, color: HostColor, addr: &Url) { + pub async fn remove_if_exists(&self, color: HostColor, addr: &Url) { let color_code = color.clone() as usize; let mut list = self.hostlists[color_code].write().await; if let Some(position) = list.iter().position(|(u, _)| u == addr) { diff --git a/src/net/session/refine_session.rs b/src/net/session/refine_session.rs index e35f00228..6f5a8eab8 100644 --- a/src/net/session/refine_session.rs +++ b/src/net/session/refine_session.rs @@ -271,18 +271,7 @@ impl GreylistRefinery { } if !self.session().handshake_node(url.clone(), p2p.clone()).await { - { - let mut greylist = - hosts.container.hostlists[HostColor::Grey as usize].write().await; - - let position = hosts - .container - .get_index_at_addr(HostColor::Grey as usize, url.clone()) - .await - .unwrap(); - - greylist.remove(position); - } + hosts.container.remove_if_exists(HostColor::Grey, url).await; debug!( target: "net::refinery",