Browse Source

net: prevent inbound session channels from being stored in the anchorlist

lunar-mining 2 years ago
parent
commit
6a39e926f1
2 changed files with 15 additions and 11 deletions
  1. 1 8
      src/net/p2p.rs
  2. 14 3
      src/net/session/mod.rs

+ 1 - 8
src/net/p2p.rs

@@ -232,16 +232,9 @@ impl P2p {
     }
     }
 
 
     /// Add a channel to the set of connected channels
     /// Add a channel to the set of connected channels
-    pub(super) async fn store(&self, channel: ChannelPtr, last_seen: u64) {
+    pub(super) async fn store(&self, channel: ChannelPtr) {
         self.channels.lock().await.insert(channel.address().clone(), channel.clone());
         self.channels.lock().await.insert(channel.address().clone(), channel.clone());
 
 
-        // TODO: check for duplicates.
-        // TODO: FIXME: unwrap
-        self.hosts()
-            .anchorlist_store_or_update(&[(channel.address().clone(), last_seen)])
-            .await
-            .unwrap();
-
         self.channel_subscriber.notify(Ok(channel)).await;
         self.channel_subscriber.notify(Ok(channel)).await;
     }
     }
 
 

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

@@ -99,6 +99,7 @@ pub trait Session: Sync {
 
 
         // Perform the handshake protocol
         // Perform the handshake protocol
         let protocol_version = ProtocolVersion::new(channel.clone(), p2p.settings().clone()).await;
         let protocol_version = ProtocolVersion::new(channel.clone(), p2p.settings().clone()).await;
+        debug!(target: "net::session::register_channel()", "register_channel {}", channel.clone().address());
         let handshake_task =
         let handshake_task =
             self.perform_handshake_protocols(protocol_version, channel.clone(), executor.clone());
             self.perform_handshake_protocols(protocol_version, channel.clone(), executor.clone());
 
 
@@ -135,11 +136,21 @@ pub trait Session: Sync {
         // Perform handshake
         // Perform handshake
         protocol_version.run(executor.clone()).await?;
         protocol_version.run(executor.clone()).await?;
 
 
-        // Channel is now initialized. Timestamp this.
-        let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
+        if self.type_id() != SESSION_INBOUND {
+            // Channel is now initialized. Timestamp this.
+            let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
+
+            // TODO: FIXME: unwrap
+            self.p2p()
+                .hosts()
+                .anchorlist_store_or_update(&[(channel.address().clone(), last_seen)])
+                .await
+                .unwrap();
+        }
 
 
         // Add channel to p2p
         // Add channel to p2p
-        self.p2p().store(channel.clone(), last_seen).await;
+        debug!(target: "net::session::register_channel()", "perform_handshake_protocol {}", channel.clone().address());
+        self.p2p().store(channel.clone()).await;
 
 
         // Subscribe to stop, so we can remove from p2p
         // Subscribe to stop, so we can remove from p2p
         executor.spawn(remove_sub_on_stop(self.p2p(), channel)).detach();
         executor.spawn(remove_sub_on_stop(self.p2p(), channel)).detach();