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.
This commit is contained in:
draoi
2024-06-27 13:54:35 +02:00
parent ad627b7f26
commit e7d8ba1864
2 changed files with 2 additions and 13 deletions

View File

@@ -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) {

View File

@@ -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",