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

net: remove HostPtr from ProtocolVersion and update probe_node()

lunar-mining 2 лет назад
Родитель
Сommit
9a09e8c6cd
4 измененных файлов с 9 добавлено и 15 удалено
  1. 1 1
      bin/lilith/src/main.rs
  2. 3 8
      src/net/hosts.rs
  3. 4 5
      src/net/protocol/protocol_version.rs
  4. 1 1
      src/net/session/mod.rs

+ 1 - 1
bin/lilith/src/main.rs

@@ -200,7 +200,7 @@ impl Lilith {
                             let proto_ver = ProtocolVersion::new(
                                 channel.clone(),
                                 p2p_.settings().clone(),
-                                p2p_.hosts().clone(),
+                                //p2p_.hosts().clone(),
                             )
                             .await;
 

+ 3 - 8
src/net/hosts.rs

@@ -525,17 +525,12 @@ impl Hosts {
         let session_out = p2p_.session_outbound();
         let session_weak = Arc::downgrade(&session_out);
 
-        let connector = Connector::new(p2p_.settings(), session_weak);
+        let connector = Connector::new(self.settings.clone(), session_weak);
         debug!(target: "net::hosts::probe_node()", "Connecting to {}", host);
         match connector.connect(host).await {
             Ok((_url, channel)) => {
                 debug!(target: "net::hosts::probe_node()", "Connected successfully!");
-                let proto_ver = ProtocolVersion::new(
-                    channel.clone(),
-                    p2p_.settings().clone(),
-                    p2p_.hosts().clone(),
-                )
-                .await;
+                let proto_ver = ProtocolVersion::new(channel.clone(), self.settings.clone()).await;
 
                 let handshake_task = session_out.perform_handshake_protocols(
                     proto_ver,
@@ -556,7 +551,7 @@ impl Hosts {
                         return false
                     }
                 }
-            }
+            }                   
 
             Err(e) => {
                 debug!(target: "net::hosts::probe_node()", "Failed to connect to {}, ({})", host, e);

+ 4 - 5
src/net/protocol/protocol_version.rs

@@ -38,13 +38,12 @@ pub struct ProtocolVersion {
     version_sub: MessageSubscription<VersionMessage>,
     verack_sub: MessageSubscription<VerackMessage>,
     settings: SettingsPtr,
-    hosts: HostsPtr,
 }
 
 impl ProtocolVersion {
     /// Create a new version protocol. Makes a version and version ack
     /// subscription, then adds them to a version protocol instance.
-    pub async fn new(channel: ChannelPtr, settings: SettingsPtr, hosts: HostsPtr) -> Arc<Self> {
+    pub async fn new(channel: ChannelPtr, settings: SettingsPtr) -> Arc<Self> {
         // Creates a versi5on subscription
         let version_sub =
             channel.subscribe_msg::<VersionMessage>().await.expect("Missing version dispatcher!");
@@ -53,7 +52,7 @@ impl ProtocolVersion {
         let verack_sub =
             channel.subscribe_msg::<VerackMessage>().await.expect("Missing verack dispatcher!");
 
-        Arc::new(Self { channel, version_sub, verack_sub, settings, hosts })
+        Arc::new(Self { channel, version_sub, verack_sub, settings })
     }
 
     /// Start version information exchange. Start the timer. Send version
@@ -79,7 +78,7 @@ impl ProtocolVersion {
             );
 
             // Remove from hosts
-            self.hosts.remove(self.channel.address()).await;
+            //self.hosts.remove(self.channel.address()).await;
             self.channel.stop().await;
             return Err(Error::ChannelTimeout)
         }
@@ -153,7 +152,7 @@ impl ProtocolVersion {
                 self.channel.address(),
             );
 
-            self.hosts.remove(self.channel.address()).await;
+            //self.hosts.remove(self.channel.address()).await;
             self.channel.stop().await;
             return Err(Error::ChannelStopped)
         }

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

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