فهرست منبع

lilith: Also purge host after handshake failure.

So far we've been only doing it when the host is unreachable,
but we can be aggressive now.
parazyd 2 سال پیش
والد
کامیت
3a948fee72
1فایلهای تغییر یافته به همراه11 افزوده شده و 4 حذف شده
  1. 11 4
      bin/lilith/src/main.rs

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

@@ -52,6 +52,11 @@ use darkfi::{
 const CONFIG_FILE: &str = "lilith_config.toml";
 const CONFIG_FILE_CONTENTS: &str = include_str!("../lilith_config.toml");
 
+/// Period in which the peer purge happens (in seconds)
+const PURGE_PERIOD: u64 = 60;
+/// Amount of hosts to try each purge iteration
+const PROBE_HOSTS_N: u32 = 10;
+
 #[derive(Clone, Debug, serde::Deserialize, StructOpt, StructOptToml)]
 #[serde(default)]
 #[structopt(name = "lilith", about = cli_desc!())]
@@ -141,11 +146,12 @@ impl Lilith {
     async fn periodic_purge(name: String, p2p: P2pPtr, ex: Arc<Executor<'_>>) -> Result<()> {
         info!(target: "lilith", "Starting periodic host purge task for \"{}\"", name);
         loop {
-            // We'll pick up to 10 hosts every minute and try to connect to
-            // them. If we can't reach them, we'll remove them from our set.
-            sleep(60).await;
+            // We'll pick up to PROBE_HOSTS_N hosts every PURGE_PERIOD and try to
+            // connect to them. If we can't reach them, remove them from our set.
+            sleep(PURGE_PERIOD).await;
             debug!(target: "lilith", "[{}] Picking random hosts from db", name);
-            let lottery_winners = p2p.clone().hosts().fetch_n_random(10).await;
+
+            let lottery_winners = p2p.clone().hosts().fetch_n_random(PROBE_HOSTS_N).await;
             let win_str: Vec<&str> = lottery_winners.iter().map(|x| x.as_str()).collect();
             debug!(target: "lilith", "[{}] Got: {:?}", name, win_str);
 
@@ -185,6 +191,7 @@ impl Lilith {
                                 }
                                 Err(e) => {
                                     debug!(target: "lilith", "Handshake failure! {}", e);
+                                    p2p_.hosts().remove(host).await;
                                 }
                             }
                         }