Przeglądaj źródła

store: improve error naming

Error::InvalidIndex -> Error::HostDoesNotExist
lunar-mining 2 lat temu
rodzic
commit
ca885a43ee
2 zmienionych plików z 8 dodań i 7 usunięć
  1. 2 2
      src/error.rs
  2. 6 5
      src/net/hosts/store.rs

+ 2 - 2
src/error.rs

@@ -190,8 +190,8 @@ pub enum Error {
     #[error("P2P network stopped")]
     #[error("P2P network stopped")]
     P2PNetworkStopped,
     P2PNetworkStopped,
 
 
-    #[error("Invalid hostlist index")]
-    InvalidIndex,
+    #[error("No matching hostlist entry")]
+    HostDoesNotExist,
 
 
     // =============
     // =============
     // Crypto errors
     // Crypto errors

+ 6 - 5
src/net/hosts/store.rs

@@ -340,6 +340,7 @@ impl Hosts {
     pub async fn whitelist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
     pub async fn whitelist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
         debug!(target: "net::hosts::whitelist_store_or_update()", "[START]");
         debug!(target: "net::hosts::whitelist_store_or_update()", "[START]");
 
 
+        // No address filtering for whitelist (whitelist is created from greylist)
         for (addr, last_seen) in addrs {
         for (addr, last_seen) in addrs {
             if !self.whitelist_contains(addr).await {
             if !self.whitelist_contains(addr).await {
                 debug!(target: "net::hosts::whitelist_store_or_update()",
                 debug!(target: "net::hosts::whitelist_store_or_update()",
@@ -360,8 +361,7 @@ impl Hosts {
     pub async fn greylist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
     pub async fn greylist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
         debug!(target: "net::hosts::store::greylist_store_or_update()", "[START]");
         debug!(target: "net::hosts::store::greylist_store_or_update()", "[START]");
 
 
-        // We filter addresses before writing to the greylist.
-        // We don't need to do this for the whitelist (whitelist is created from greylist)
+        // Filter addresses before writing to the greylist.
         let filtered_addrs = self.filter_addresses(addrs).await;
         let filtered_addrs = self.filter_addresses(addrs).await;
         let filtered_addrs_len = filtered_addrs.len();
         let filtered_addrs_len = filtered_addrs.len();
         for (addr, last_seen) in filtered_addrs {
         for (addr, last_seen) in filtered_addrs {
@@ -384,6 +384,7 @@ impl Hosts {
     pub async fn anchorlist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
     pub async fn anchorlist_store_or_update(&self, addrs: &[(Url, u64)]) -> Result<()> {
         debug!(target: "net::hosts::store::anchor_store_or_update()", "[START]");
         debug!(target: "net::hosts::store::anchor_store_or_update()", "[START]");
 
 
+        // No address filtering for anchorlist (contains addresses we have already connected to)
         for (addr, last_seen) in addrs {
         for (addr, last_seen) in addrs {
             if !self.anchorlist_contains(addr).await {
             if !self.anchorlist_contains(addr).await {
                 debug!(target: "net::hosts::anchorlist_store_or_update()",
                 debug!(target: "net::hosts::anchorlist_store_or_update()",
@@ -747,7 +748,7 @@ impl Hosts {
                 return Ok(i)
                 return Ok(i)
             }
             }
         }
         }
-        return Err(Error::InvalidIndex)
+        return Err(Error::HostDoesNotExist)
     }
     }
 
 
     /// Get the index for a given addr on the greylist.
     /// Get the index for a given addr on the greylist.
@@ -758,7 +759,7 @@ impl Hosts {
                 return Ok(i)
                 return Ok(i)
             }
             }
         }
         }
-        return Err(Error::InvalidIndex)
+        return Err(Error::HostDoesNotExist)
     }
     }
 
 
     /// Get the index for a given addr on the anchorlist.
     /// Get the index for a given addr on the anchorlist.
@@ -769,7 +770,7 @@ impl Hosts {
                 return Ok(i)
                 return Ok(i)
             }
             }
         }
         }
-        return Err(Error::InvalidIndex)
+        return Err(Error::HostDoesNotExist)
     }
     }
 
 
     /// Return all known whitelisted hosts
     /// Return all known whitelisted hosts