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

Revert "chore: cargo fmt"

This reverts commit e46cb5d55aa0bfe97bce87155481d62cebed7840.
draoi 2 лет назад
Родитель
Сommit
4883b2f213
2 измененных файлов с 23 добавлено и 1 удалено
  1. 1 1
      src/net/channel.rs
  2. 22 0
      src/net/hosts/store.rs

+ 1 - 1
src/net/channel.rs

@@ -37,11 +37,11 @@ use url::Url;
 
 use super::{
     dnet::{self, dnetev, DnetEvent},
-    hosts::store::HostColor,
     message,
     message::Packet,
     message_subscriber::{MessageSubscription, MessageSubsystem},
     p2p::P2pPtr,
+    hosts::store::HostColor,
     session::{Session, SessionBitFlag, SessionWeakPtr},
     transport::PtStream,
 };

+ 22 - 0
src/net/hosts/store.rs

@@ -1014,6 +1014,28 @@ impl Hosts {
             q.insert(addr.clone(), 0);
         }
     }
+
+    /// Mark a peer as blacklist.
+    pub async fn blacklist(&self, peer: &Url) {
+        // We ignore UNIX sockets here so we will just work
+        // with stuff that has host_str().
+        if peer.host_str().is_some() {
+            // Localhost connections should never enter the blacklist
+            // This however allows any Tor and Nym connections.
+            if self.is_local_host(peer.clone()).await {
+                return
+            }
+
+            // Insert into the blacklist. We set last_seen to 0 (we don't care about this
+            // field).
+            self.container.hostlists[HostColor::Black as usize]
+                .write()
+                .await
+                .push((peer.clone(), 0));
+        }
+    }
+=======
+>>>>>>> 8aad26601 (net: replace downgrade() and update(), and blacklist methods with a single method move_hosts())
 }
 
 #[cfg(test)]