Răsfoiți Sursa

InboundSession stub which accepts new connections

narodnik 5 ani în urmă
părinte
comite
466abc1dfa
3 a modificat fișierele cu 37 adăugiri și 5 ștergeri
  1. 5 5
      src/net/p2p.rs
  2. 30 0
      src/net/sessions/inbound_session.rs
  3. 2 0
      src/net/sessions/mod.rs

+ 5 - 5
src/net/p2p.rs

@@ -5,7 +5,7 @@ use std::net::SocketAddr;
 use std::sync::Arc;
 
 use crate::error::Result;
-use crate::net::sessions::SeedSession;
+use crate::net::sessions::{SeedSession, InboundSession};
 use crate::net::{Channel, ChannelPtr, Hosts, HostsPtr, Connector, Settings, SettingsPtr};
 
 pub type Pending<T> = Mutex<HashMap<SocketAddr, Arc<T>>>;
@@ -41,10 +41,10 @@ impl P2p {
 
     /// Synchronize the blockchain and then begin long running sessions,
     /// call after start() is invoked.
-    pub fn run() {
-        //let inbound = InboundSession::new(Arc::downgrade(&self));
-        //let inbound_task = inbound.start(executor.clone());
-        //inbound_task.await;
+    pub async fn run(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
+        let inbound = InboundSession::new(Arc::downgrade(&self));
+        let inbound_task = inbound.start(executor.clone());
+        inbound_task.await
     }
 
     pub async fn store(self: Arc<Self>, channel: ChannelPtr) {

+ 30 - 0
src/net/sessions/inbound_session.rs

@@ -0,0 +1,30 @@
+use async_executor::Executor;
+use log::*;
+use std::net::SocketAddr;
+use std::sync::{Arc, Weak};
+
+use crate::error::{Error, Result};
+use crate::net::sessions::Session;
+use crate::net::{ChannelPtr, HostsPtr, Connector, P2p, SettingsPtr};
+use crate::net::protocols::{ProtocolPing, ProtocolSeed};
+
+pub struct InboundSession {
+    p2p: Weak<P2p>
+}
+
+impl InboundSession {
+    pub fn new(p2p: Weak<P2p>) -> Arc<Self> {
+        Arc::new(Self { p2p })
+    }
+
+    pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
+        Ok(())
+    }
+}
+
+impl Session for InboundSession {
+    fn p2p(&self) -> Arc<P2p> {
+        self.p2p.upgrade().unwrap()
+    }
+}
+

+ 2 - 0
src/net/sessions/mod.rs

@@ -1,5 +1,7 @@
+pub mod inbound_session;
 pub mod seed_session;
 pub mod session;
 
+pub use inbound_session::InboundSession;
 pub use seed_session::SeedSession;
 pub use session::Session;