Procházet zdrojové kódy

src/net/p2p: added fn to grab a channel pointer by its id

skoupidi před 1 rokem
rodič
revize
cf8d758bb8
2 změnil soubory, kde provedl 20 přidání a 0 odebrání
  1. 15 0
      src/net/hosts.rs
  2. 5 0
      src/net/p2p.rs

+ 15 - 0
src/net/hosts.rs

@@ -1041,6 +1041,21 @@ impl Hosts {
         channels
     }
 
+    /// Grab the channel pointer of provided channel ID, if it exists.
+    pub fn get_channel(&self, id: u32) -> Option<ChannelPtr> {
+        let mut channel = None;
+
+        let channels = self.channels();
+        for c in channels {
+            if c.info.id == id {
+                channel = Some(c.clone());
+                break
+            }
+        }
+
+        channel
+    }
+
     /// Return the list of connected peers. Seed and refinery connections
     /// are not taken into account.
     pub fn peers(&self) -> Vec<ChannelPtr> {

+ 5 - 0
src/net/p2p.rs

@@ -284,4 +284,9 @@ impl P2p {
     pub(super) async fn dnet_notify(&self, event: DnetEvent) {
         self.dnet_publisher.notify(event).await;
     }
+
+    /// Grab the channel pointer of provided channel ID, if it exists.
+    pub fn get_channel(&self, id: u32) -> Option<ChannelPtr> {
+        self.hosts.get_channel(id)
+    }
 }