Explorar el Código

net/session: do not panic if fetch_last_seen() cannot retrieve a host

It's possible that we cannot find a host on any active hostlist if
the host has been blacklisted just prior to the downgrade inside
subscribe_on_stop(). Instead of panicking, we simply return an error
and do not proceed with the downgrade operation.
darkfi hace 1 año
padre
commit
219895d507
Se han modificado 1 ficheros con 13 adiciones y 3 borrados
  1. 13 3
      src/net/session/mod.rs

+ 13 - 3
src/net/session/mod.rs

@@ -78,10 +78,20 @@ pub async fn remove_sub_on_stop(
             "Downgrading {}", addr,
         );
 
-        let last_seen = hosts.fetch_last_seen(addr).unwrap();
-        if let Err(e) = hosts.move_host(addr, last_seen, HostColor::Grey) {
-            error!(target: "net::session::remove_sub_on_stop()",
+        // If the host we are downgrading has been moved to blacklist,
+        // fetch_last_seen(addr) can return None. We simply print an
+        // error in this case.
+        match hosts.fetch_last_seen(addr) {
+            Some(last_seen) => {
+                if let Err(e) = hosts.move_host(addr, last_seen, HostColor::Grey) {
+                    error!(target: "net::session::remove_sub_on_stop()",
             "Failed to move host {} to Greylist! Err={}", addr.clone(), e);
+                }
+            }
+            None => {
+                error!(target: "net::session::remove_sub_on_stop()",
+               "Failed to fetch last seen for {}", addr);
+            }
         }
     }