InboundSession stub which accepts new connections

This commit is contained in:
narodnik
2021-01-19 11:29:44 +01:00
parent c127266556
commit 466abc1dfa
3 changed files with 37 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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()
}
}

View File

@@ -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;