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

channel: create ban() method

Explicitly ban a node when it misbehaves and stop the channel.
draoi 2 лет назад
Родитель
Сommit
71b1e8ddab
1 измененных файлов с 9 добавлено и 1 удалено
  1. 9 1
      src/net/channel.rs

+ 9 - 1
src/net/channel.rs

@@ -299,7 +299,7 @@ impl Channel {
                     debug!(target: "net::channel::main_receive_loop()", "Stopping channel {:?}", self);
 
                     // We will reject further connections from this peer
-                    self.p2p().hosts().mark_rejected(self.address()).await;
+                    self.ban(self.address()).await;
 
                     return Err(Error::ChannelStopped)
                 }
@@ -308,6 +308,14 @@ impl Channel {
         }
     }
 
+    /// Ban a malicious peer and stop the channel.
+    pub async fn ban(&self, peer: &Url) {
+        debug!(target: "net::channel::ban()", "START {:?}", self);
+        self.p2p().hosts().mark_rejected(peer).await;
+        self.stop().await;
+        debug!(target: "net::channel::ban()", "START {:?}", self);
+    }
+
     /// Returns the local socket address
     pub fn address(&self) -> &Url {
         &self.info.addr