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

net: remove an address from the hosts list if doesn't match

ghassmo 3 лет назад
Родитель
Сommit
400c66cb88
3 измененных файлов с 12 добавлено и 5 удалено
  1. 1 1
      bin/ircd/src/protocol_privmsg.rs
  2. 8 3
      src/net/protocol/protocol_version.rs
  3. 3 1
      src/net/session/mod.rs

+ 1 - 1
bin/ircd/src/protocol_privmsg.rs

@@ -77,7 +77,7 @@ impl ProtocolPrivmsg {
         let message_subsytem = channel.get_message_subsystem();
         message_subsytem.add_dispatch::<Privmsg>().await;
         message_subsytem.add_dispatch::<Inv>().await;
-        message_subsytem.add_dispatch::<GetData>().await; 
+        message_subsytem.add_dispatch::<GetData>().await;
         message_subsytem.add_dispatch::<LastTerm>().await;
 
         let msg_sub =

+ 8 - 3
src/net/protocol/protocol_version.rs

@@ -6,7 +6,9 @@ use smol::Executor;
 
 use crate::{Error, Result};
 
-use super::super::{message, message_subscriber::MessageSubscription, ChannelPtr, SettingsPtr};
+use super::super::{
+    message, message_subscriber::MessageSubscription, ChannelPtr, HostsPtr, SettingsPtr,
+};
 
 /// Implements the protocol version handshake sent out by nodes at the beginning
 /// of a connection.
@@ -15,13 +17,14 @@ pub struct ProtocolVersion {
     version_sub: MessageSubscription<message::VersionMessage>,
     verack_sub: MessageSubscription<message::VerackMessage>,
     settings: SettingsPtr,
+    hosts: HostsPtr,
 }
 
 impl ProtocolVersion {
     /// Create a new version protocol. Makes a version and version
     /// acknowledgement subscription, then adds them to a version protocol
     /// instance.
-    pub async fn new(channel: ChannelPtr, settings: SettingsPtr) -> Arc<Self> {
+    pub async fn new(channel: ChannelPtr, settings: SettingsPtr, hosts: HostsPtr) -> Arc<Self> {
         // Creates a version subscription.
         let version_sub = channel
             .clone()
@@ -36,7 +39,7 @@ impl ProtocolVersion {
             .await
             .expect("Missing verack dispatcher!");
 
-        Arc::new(Self { channel, version_sub, verack_sub, settings })
+        Arc::new(Self { channel, version_sub, verack_sub, settings, hosts })
     }
 
     /// Start version information exchange. Start the timer. Send version info
@@ -100,6 +103,8 @@ impl ProtocolVersion {
                             "Wrong app version from [{}]. Disconnecting from channel.",
                             self.channel.address()
                         );
+
+                        self.hosts.remove(&self.channel.address()).await;
                         self.channel.stop().await;
                         return Err(Error::ChannelStopped)
                     }

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

@@ -113,7 +113,9 @@ pub trait Session: Sync {
             p2p.protocol_registry().attach(self.type_id(), channel.clone(), p2p.clone()).await;
 
         // Perform the handshake protocol
-        let protocol_version = ProtocolVersion::new(channel.clone(), self.p2p().settings()).await;
+        let protocol_version =
+            ProtocolVersion::new(channel.clone(), p2p.settings().clone(), p2p.hosts().clone())
+                .await;
         let handshake_task =
             self.perform_handshake_protocols(protocol_version, channel.clone(), executor.clone());