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

store: remove redundant Result<()> type on register_channel()

draoi 2 лет назад
Родитель
Сommit
b5764d2c9f
2 измененных файлов с 6 добавлено и 9 удалено
  1. 4 3
      src/net/hosts/store.rs
  2. 2 6
      src/net/session/mod.rs

+ 4 - 3
src/net/hosts/store.rs

@@ -921,9 +921,12 @@ impl Hosts {
     }
 
     /// Add a channel to the set of connected channels
-    pub async fn register_channel(&self, channel: ChannelPtr) -> Result<()> {
+    pub async fn register_channel(&self, channel: ChannelPtr) {
         let address = channel.address().clone();
 
+        // This will panic if we are already connected to this peer, this peer
+        // is suspended, or this peer is currently being inserted into the hostlist.
+        // None of these scenarios should ever happen.
         self.try_register(address.clone(), HostState::Connected(channel.clone())).await.unwrap();
 
         // Notify that channel processing was successful
@@ -931,8 +934,6 @@ impl Hosts {
 
         let mut last_online = self.last_connection.write().await;
         *last_online = Instant::now();
-
-        Ok(())
     }
 
     pub async fn subscribe_store(&self) -> Subscription<usize> {

+ 2 - 6
src/net/session/mod.rs

@@ -19,7 +19,7 @@
 use std::sync::{Arc, Weak};
 
 use async_trait::async_trait;
-use log::{debug, warn};
+use log::debug;
 use smol::Executor;
 
 use super::{channel::ChannelPtr, p2p::P2pPtr, protocol::ProtocolVersion};
@@ -145,11 +145,7 @@ pub trait Session: Sync {
         protocol_version.run(executor.clone()).await?;
 
         // Attempt to add channel to registry
-        if let Err(e) = self.p2p().hosts().register_channel(channel.clone()).await {
-            warn!(target: "net::session::perform_handshake_protocols()",
-            "Couldn't add channel {} to registry! {}", channel.address(), e);
-            return Err(e)
-        }
+        self.p2p().hosts().register_channel(channel.clone()).await;
 
         // Subscribe to stop, so we can remove from registry
         executor.spawn(remove_sub_on_stop(self.p2p(), channel)).detach();