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

net: remove unwrap()'s and cleanup

lunar-mining 2 лет назад
Родитель
Сommit
ca4d523dd3
3 измененных файлов с 18 добавлено и 35 удалено
  1. 16 6
      src/net/hosts/refinery.rs
  2. 1 26
      src/net/hosts/store.rs
  3. 1 3
      src/net/session/mod.rs

+ 16 - 6
src/net/hosts/refinery.rs

@@ -45,9 +45,14 @@ impl GreylistRefinery {
     }
     }
 
 
     pub async fn start(self: Arc<Self>) {
     pub async fn start(self: Arc<Self>) {
-        // TODO: FIXME: unwrap
-        self.p2p().hosts().load_hosts().await.unwrap();
-
+        match self.p2p().hosts().load_hosts().await {
+            Ok(()) => {
+                debug!(target: "net::refinery::start()", "Load hosts successful!");
+            }
+            Err(e) => {
+                warn!(target: "net::refinery::start()", "Error loading hosts {}", e);
+            }
+        }
         let ex = self.p2p().executor();
         let ex = self.p2p().executor();
         self.process.clone().start(
         self.process.clone().start(
             async move {
             async move {
@@ -62,9 +67,14 @@ impl GreylistRefinery {
     }
     }
 
 
     pub async fn stop(self: Arc<Self>) {
     pub async fn stop(self: Arc<Self>) {
-        debug!(target: "net::refinery::stop()", "Saving hostlist...");
-        // TODO: FIXME: unwrap
-        self.p2p().hosts().save_hosts().await.unwrap();
+        match self.p2p().hosts().save_hosts().await {
+            Ok(()) => {
+                debug!(target: "net::refinery::stop()", "Save hosts successful!");
+            }
+            Err(e) => {
+                warn!(target: "net::refinery::stop()", "Error saving hosts {}", e);
+            }
+        }
         self.process.stop().await
         self.process.stop().await
     }
     }
 
 

+ 1 - 26
src/net/hosts/store.rs

@@ -499,30 +499,6 @@ impl Hosts {
         debug!(target: "net::hosts::store::anchorlist_update_last_seen()", "[END]");
         debug!(target: "net::hosts::store::anchorlist_update_last_seen()", "[END]");
     }
     }
 
 
-    //pub async fn whitelist_downgrade(&self, addr: &Url) {
-    //    // First lookup the entry using its addr.
-    //    let mut entry = vec![];
-
-    //    let whitelist = self.whitelist.read().await;
-    //    for (url, time) in whitelist.iter() {
-    //        if url == addr {
-    //            entry.push((url.clone(), time.clone()));
-    //        }
-    //    }
-
-    //    // Remove this item from the whitelist.
-    //    let mut whitelist = self.whitelist.write().await;
-    //    // TODO: test!
-    //    let index = whitelist.iter().position(|x| *x == entry[0]);
-    //    // This should never fail since the entry exists.
-    //    whitelist.remove(index.unwrap());
-
-    //    // Add it to the greylist.
-    //    let addr = entry[0].0.clone();
-    //    let last_seen = entry[0].1.clone();
-    //    self.greylist_store(addr, last_seen).await;
-    //}
-
     pub async fn greylist_remove(&self, addr: &Url, position: usize) {
     pub async fn greylist_remove(&self, addr: &Url, position: usize) {
         debug!(target: "net::refinery::run()", "Removing whitelisted peer {} from greylist", addr);
         debug!(target: "net::refinery::run()", "Removing whitelisted peer {} from greylist", addr);
         let mut greylist = self.greylist.write().await;
         let mut greylist = self.greylist.write().await;
@@ -1062,8 +1038,6 @@ impl Hosts {
     }
     }
 
 
     pub async fn load_hosts(&self) -> Result<()> {
     pub async fn load_hosts(&self) -> Result<()> {
-        // TODO: FIXME: make this a net::Setting
-        //let path = expand_path(&"~/.config/darkfi/hostlist.tsv")?;
         let path = expand_path(&self.settings.hostlist)?;
         let path = expand_path(&self.settings.hostlist)?;
 
 
         if !path.exists() {
         if !path.exists() {
@@ -1137,6 +1111,7 @@ impl Hosts {
                 error!(target: "net::hosts::store", "Failed saving hosts: {}", e);
                 error!(target: "net::hosts::store", "Failed saving hosts: {}", e);
             }
             }
         }
         }
+
         Ok(())
         Ok(())
     }
     }
 }
 }

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

@@ -140,12 +140,10 @@ pub trait Session: Sync {
             // Channel is now initialized. Timestamp this.
             // Channel is now initialized. Timestamp this.
             let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
             let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
 
 
-            // TODO: FIXME: unwrap
             self.p2p()
             self.p2p()
                 .hosts()
                 .hosts()
                 .anchorlist_store_or_update(&[(channel.address().clone(), last_seen)])
                 .anchorlist_store_or_update(&[(channel.address().clone(), last_seen)])
-                .await
-                .unwrap();
+                .await?;
         }
         }
 
 
         // Add channel to p2p
         // Add channel to p2p