ソースを参照

net: create perform_local_handshake which does a version exchange without adding channel to the p2p store, and use in ping_node

lunar-mining 2 年 前
コミット
560b332e37
2 ファイル変更19 行追加1 行削除
  1. 1 1
      src/net/hosts/refinery.rs
  2. 18 0
      src/net/session/mod.rs

+ 1 - 1
src/net/hosts/refinery.rs

@@ -119,7 +119,7 @@ pub async fn ping_node(addr: &Url, p2p: P2pPtr) -> bool {
             debug!(target: "net::refinery::ping_node()", "Connected successfully!");
             let proto_ver = ProtocolVersion::new(channel.clone(), p2p.settings()).await;
 
-            let handshake_task = session_outbound.perform_handshake_protocols(
+            let handshake_task = session_outbound.perform_local_handshake(
                 proto_ver,
                 channel.clone(),
                 p2p.executor(),

+ 18 - 0
src/net/session/mod.rs

@@ -144,6 +144,24 @@ pub trait Session: Sync {
         Ok(())
     }
 
+    async fn perform_local_handshake(
+        &self,
+        protocol_version: Arc<ProtocolVersion>,
+        channel: ChannelPtr,
+        executor: Arc<Executor<'_>>,
+    ) -> Result<()> {
+        // Perform handshake
+        protocol_version.run(executor.clone()).await?;
+
+        // Channel is now initialized
+
+        // Subscribe to stop, so we can remove from p2p
+        executor.spawn(remove_sub_on_stop(self.p2p(), channel)).detach();
+
+        // Channel is ready for use
+        Ok(())
+    }
+
     /// Returns a pointer to the p2p network interface
     fn p2p(&self) -> P2pPtr;