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

net: make disconnect_publisher notify with an Error instead of a bool

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

+ 2 - 2
src/net/hosts.rs

@@ -800,7 +800,7 @@ pub struct Hosts {
     pub(in crate::net) channel_publisher: PublisherPtr<Result<ChannelPtr>>,
 
     /// Publisher listening for network disconnects
-    pub(in crate::net) disconnect_publisher: PublisherPtr<bool>,
+    pub(in crate::net) disconnect_publisher: PublisherPtr<Error>,
 
     /// Keeps track of the last time a connection was made.
     pub(in crate::net) last_connection: Mutex<Instant>,
@@ -1011,7 +1011,7 @@ impl Hosts {
     }
 
     /// Get notified when a node has no active connections (is disconnected)
-    pub async fn subscribe_disconnect(&self) -> Subscription<bool> {
+    pub async fn subscribe_disconnect(&self) -> Subscription<Error> {
         self.disconnect_publisher.clone().subscribe().await
     }
 

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

@@ -26,7 +26,7 @@ use log::{debug, trace};
 use smol::Executor;
 
 use super::{channel::ChannelPtr, hosts::HostColor, p2p::P2pPtr, protocol::ProtocolVersion};
-use crate::Result;
+use crate::{Error, Result};
 
 pub mod inbound_session;
 pub use inbound_session::{InboundSession, InboundSessionPtr};
@@ -86,7 +86,7 @@ pub async fn remove_sub_on_stop(p2p: P2pPtr, channel: ChannelPtr, type_id: Sessi
     hosts.unregister(channel.address()).await;
 
     if hosts.channels().await.is_empty() {
-        hosts.disconnect_publisher.notify(true).await;
+        hosts.disconnect_publisher.notify(Error::NetworkNotConnected).await;
     }
     debug!(target: "net::session::remove_sub_on_stop()", "[END]");
 }