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

net: make a generic base class for PeerDiscovery

Making PeerDiscovery generic means that in the future we can have
different types of PeerDiscovery.

Specifically, swarming requires us to have 2 kinds of Peer Discovery, a
an overlay network PeerDiscovery (like the one we have currency), and a
PeerDiscovery for subnets that looks for subnets within the overlay
network.

This paves the way for future changes of this nature
draoi 2 лет назад
Родитель
Сommit
ecf81d9f93
1 измененных файлов с 23 добавлено и 1 удалено
  1. 23 1
      src/net/session/outbound_session.rs

+ 23 - 1
src/net/session/outbound_session.rs

@@ -436,6 +436,25 @@ impl Slot {
     }
 }
 
+/// TODO: doc
+#[async_trait]
+pub trait PeerDiscoveryBase {
+    async fn start(self: Arc<Self>);
+
+    async fn stop(self: Arc<Self>);
+
+    async fn run(self: Arc<Self>);
+
+    async fn wait(&self) -> bool;
+
+    fn notify(&self);
+
+    fn session(&self) -> OutboundSessionPtr;
+
+    fn p2p(&self) -> P2pPtr;
+}
+
+/// TODO: doc
 struct PeerDiscovery {
     process: StoppableTaskPtr,
     wakeup_self: CondVar,
@@ -450,7 +469,10 @@ impl PeerDiscovery {
             session: LazyWeak::new(),
         })
     }
+}
 
+#[async_trait]
+impl PeerDiscoveryBase for PeerDiscovery {
     async fn start(self: Arc<Self>) {
         let ex = self.p2p().executor();
         self.process.clone().start(
@@ -610,10 +632,10 @@ impl PeerDiscovery {
     fn notify(&self) {
         self.wakeup_self.notify()
     }
-
     fn session(&self) -> OutboundSessionPtr {
         self.session.upgrade()
     }
+
     fn p2p(&self) -> P2pPtr {
         self.session().p2p()
     }