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

lilith: migrate whitelist refinery to new HostState logic

draoi 2 лет назад
Родитель
Сommit
9d685f408b
2 измененных файлов с 12 добавлено и 9 удалено
  1. 11 8
      bin/lilith/src/main.rs
  2. 1 1
      src/net/hosts/mod.rs

+ 11 - 8
bin/lilith/src/main.rs

@@ -39,7 +39,7 @@ use url::Url;
 
 use darkfi::{
     async_daemonize, cli_desc,
-    net::{self, hosts::refinery::ping_node, P2p, P2pPtr},
+    net::{self, hosts::store::HostState, hosts::refinery::ping_node, P2p, P2pPtr},
     rpc::{
         jsonrpc::*,
         server::{listen_and_serve, RequestHandler},
@@ -176,13 +176,9 @@ impl Lilith {
             let (entry, position) = hosts.whitelist_fetch_last().await;
             let url = &entry.0;
 
-            // Skip this node if it's being migrated currently.
-            if hosts.is_migrating(url).await {
-                continue
-            }
-
-            // Don't refine nodes that we are already connected to.
-            if p2p.exists(url).await {
+            if let Err(_) =
+                hosts.try_update_registry(url.clone(), HostState::Refining).await
+            {
                 continue
             }
 
@@ -193,6 +189,13 @@ impl Lilith {
                 hosts.whitelist_remove(url, position).await;
                 debug!(target: "lilith", "Host {} is not responsive. Downgraded from whitelist", url);
 
+                // Remove this entry from HostRegistry to avoid this host getting
+                // stuck in the Refining state.
+                //
+                // It is not necessary to call this when the refinery passes, since the
+                // state will be changed to Connected.
+                hosts.remove(url).await;
+
                 continue
             }
 

+ 1 - 1
src/net/hosts/mod.rs

@@ -42,4 +42,4 @@ pub mod refinery;
 ///
 /// `store` contains various methods for reading from, quering and writing to the hostlists.
 /// It is also responsible for filtering addresses and ensuring channel transport validity.
-pub(super) mod store;
+pub mod store;