Просмотр исходного кода

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.
draoi 2 лет назад
Родитель
Сommit
e7d8ba1864
2 измененных файлов с 2 добавлено и 13 удалено
  1. 1 1
      src/net/hosts.rs
  2. 1 12
      src/net/session/refine_session.rs

+ 1 - 1
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) {

+ 1 - 12
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",