Explorar o código

net: rename rejected to blacklist

also add documentation, and upgrade "Peer {} is blacklisted" debug statements to warnings
draoi %!s(int64=2) %!d(string=hai) anos
pai
achega
3c06e215a2
Modificáronse 4 ficheiros con 25 adicións e 24 borrados
  1. 3 3
      src/net/acceptor.rs
  2. 2 2
      src/net/channel.rs
  3. 3 3
      src/net/connector.rs
  4. 17 16
      src/net/hosts/store.rs

+ 3 - 3
src/net/acceptor.rs

@@ -24,7 +24,7 @@ use std::{
     },
     },
 };
 };
 
 
-use log::{debug, error, warn};
+use log::{error, warn};
 use smol::Executor;
 use smol::Executor;
 use url::Url;
 use url::Url;
 
 
@@ -117,8 +117,8 @@ impl Acceptor {
             match listener.next().await {
             match listener.next().await {
                 Ok((stream, url)) => {
                 Ok((stream, url)) => {
                     // Check if we reject this peer
                     // Check if we reject this peer
-                    if self.session.upgrade().unwrap().p2p().hosts().is_rejected(&url).await {
-                        debug!(target: "net::acceptor::run_accept_loop()", "Peer {} is rejected", url);
+                    if self.session.upgrade().unwrap().p2p().hosts().is_blacklist(&url).await {
+                        warn!(target: "net::acceptor::run_accept_loop()", "Peer {} is blacklisted", url);
                         continue
                         continue
                     }
                     }
 
 

+ 2 - 2
src/net/channel.rs

@@ -311,9 +311,9 @@ impl Channel {
     /// Ban a malicious peer and stop the channel.
     /// Ban a malicious peer and stop the channel.
     pub async fn ban(&self, peer: &Url) {
     pub async fn ban(&self, peer: &Url) {
         debug!(target: "net::channel::ban()", "START {:?}", self);
         debug!(target: "net::channel::ban()", "START {:?}", self);
-        self.p2p().hosts().mark_rejected(peer).await;
+        self.p2p().hosts().blacklist(peer).await;
         self.stop().await;
         self.stop().await;
-        debug!(target: "net::channel::ban()", "START {:?}", self);
+        debug!(target: "net::channel::ban()", "STOP {:?}", self);
     }
     }
 
 
     /// Returns the local socket address
     /// Returns the local socket address

+ 3 - 3
src/net/connector.rs

@@ -18,7 +18,7 @@
 
 
 use std::time::Duration;
 use std::time::Duration;
 
 
-use log::debug;
+use log::warn;
 use url::Url;
 use url::Url;
 
 
 use super::{
 use super::{
@@ -45,8 +45,8 @@ impl Connector {
 
 
     /// Establish an outbound connection
     /// Establish an outbound connection
     pub async fn connect(&self, url: &Url) -> Result<(Url, ChannelPtr)> {
     pub async fn connect(&self, url: &Url) -> Result<(Url, ChannelPtr)> {
-        if self.session.upgrade().unwrap().p2p().hosts().is_rejected(url).await {
-            debug!(target: "net::connector::connect", "Peer {} is rejected", url);
+        if self.session.upgrade().unwrap().p2p().hosts().is_blacklist(url).await {
+            warn!(target: "net::connector::connect", "Peer {} is blacklisted", url);
             return Err(Error::ConnectFailed)
             return Err(Error::ConnectFailed)
         }
         }
 
 

+ 17 - 16
src/net/hosts/store.rs

@@ -70,8 +70,9 @@ pub struct Hosts {
     /// Internet interrupt (goblins unplugging cables)
     /// Internet interrupt (goblins unplugging cables)
     quarantine: RwLock<HashMap<Url, usize>>,
     quarantine: RwLock<HashMap<Url, usize>>,
 
 
-    /// Peers we reject from connecting to
-    rejected: RwLock<HashSet<String>>,
+    /// Peers on the blacklist are considered hostile and can neither be connected to
+    /// nor establish connections to us for the duration of the program.
+    blacklist: RwLock<HashSet<String>>,
 
 
     /// Peers that are currently being removed from the hostlist
     /// Peers that are currently being removed from the hostlist
     migrating: RwLock<HashSet<Url>>,
     migrating: RwLock<HashSet<Url>>,
@@ -91,7 +92,7 @@ impl Hosts {
             whitelist: RwLock::new(Vec::new()),
             whitelist: RwLock::new(Vec::new()),
             anchorlist: RwLock::new(Vec::new()),
             anchorlist: RwLock::new(Vec::new()),
             quarantine: RwLock::new(HashMap::new()),
             quarantine: RwLock::new(HashMap::new()),
-            rejected: RwLock::new(HashSet::new()),
+            blacklist: RwLock::new(HashSet::new()),
             migrating: RwLock::new(HashSet::new()),
             migrating: RwLock::new(HashSet::new()),
             store_subscriber: Subscriber::new(),
             store_subscriber: Subscriber::new(),
             settings,
             settings,
@@ -592,8 +593,8 @@ impl Hosts {
                 continue
                 continue
             }
             }
 
 
-            if self.is_rejected(addr_).await {
-                debug!(target: "store::filter_addresses()", "Peer {} is rejected", addr_);
+            if self.is_blacklist(addr_).await {
+                warn!(target: "store::filter_addresses()", "Peer {} is blacklisted", addr_);
                 continue
                 continue
             }
             }
 
 
@@ -674,38 +675,38 @@ impl Hosts {
         }
         }
     }
     }
 
 
-    /// Check if a given peer (URL) is in the set of rejected hosts
-    pub async fn is_rejected(&self, peer: &Url) -> bool {
+    /// Check if a given peer (URL) is in the set of blacklist hosts
+    pub async fn is_blacklist(&self, peer: &Url) -> bool {
         // Skip lookup for UNIX sockets and localhost connections
         // Skip lookup for UNIX sockets and localhost connections
-        // as they should never belong to the list of rejected URLs.
+        // as they should never belong to the blacklist.
         let Some(hostname) = peer.host_str() else { return false };
         let Some(hostname) = peer.host_str() else { return false };
 
 
         if self.is_local_host(peer.clone()).await {
         if self.is_local_host(peer.clone()).await {
             return false
             return false
         }
         }
 
 
-        self.rejected.read().await.contains(hostname)
+        self.blacklist.read().await.contains(hostname)
     }
     }
 
 
-    /// Mark a peer as rejected by adding it to the set of rejected URLs.
-    pub async fn mark_rejected(&self, peer: &Url) {
+    /// Mark a peer as blacklist by adding it to the set of blacklist URLs.
+    pub async fn blacklist(&self, peer: &Url) {
         // We ignore UNIX sockets here so we will just work
         // We ignore UNIX sockets here so we will just work
         // with stuff that has host_str().
         // with stuff that has host_str().
         if let Some(hostname) = peer.host_str() {
         if let Some(hostname) = peer.host_str() {
-            // Localhost connections should not be rejected
+            // Localhost connections should never enter the blacklist
             // This however allows any Tor and Nym connections.
             // This however allows any Tor and Nym connections.
             if self.is_local_host(peer.clone()).await {
             if self.is_local_host(peer.clone()).await {
                 return
                 return
             }
             }
 
 
-            self.rejected.write().await.insert(hostname.to_string());
+            self.blacklist.write().await.insert(hostname.to_string());
         }
         }
     }
     }
 
 
-    /// Unmark a rejected peer
-    pub async fn unmark_rejected(&self, peer: &Url) {
+    /// Unmark a blacklist peer
+    pub async fn unblacklist(&self, peer: &Url) {
         if let Some(hostname) = peer.host_str() {
         if let Some(hostname) = peer.host_str() {
-            self.rejected.write().await.remove(hostname);
+            self.blacklist.write().await.remove(hostname);
         }
         }
     }
     }