Jelajahi Sumber

ManualSession stub

narodnik 4 tahun lalu
induk
melakukan
8b37435806
3 mengubah file dengan 55 tambahan dan 8 penghapusan
  1. 8 2
      src/net/p2p.rs
  2. 38 0
      src/net/sessions/manual_session.rs
  3. 9 6
      src/net/sessions/mod.rs

+ 8 - 2
src/net/p2p.rs

@@ -11,7 +11,7 @@ use crate::{
     error::{Error, Result},
     net::{
         messages::Message,
-        sessions::{InboundSession, OutboundSession, SeedSession},
+        sessions::{InboundSession, OutboundSession, SeedSession, ManualSession},
         Channel, ChannelPtr, Hosts, HostsPtr, Settings, SettingsPtr,
     },
     system::{Subscriber, SubscriberPtr, Subscription},
@@ -52,7 +52,6 @@ impl P2p {
     /// Invoke startup and seeding sequence. Call from constructing thread.
     pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
         debug!(target: "net", "P2p::start() [BEGIN]");
-        // Start manual connections
 
         // Start seed session
         let seed = SeedSession::new(Arc::downgrade(&self));
@@ -68,6 +67,13 @@ impl P2p {
     pub async fn run(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
         debug!(target: "net", "P2p::run() [BEGIN]");
 
+        let manual = ManualSession::new(Arc::downgrade(&self));
+        manual.clone().start(executor.clone())?;
+
+        for peer in &self.settings.peers {
+            manual.clone().connect(peer);
+        }
+
         let inbound = InboundSession::new(Arc::downgrade(&self));
         inbound.clone().start(executor.clone())?;
 

+ 38 - 0
src/net/sessions/manual_session.rs

@@ -0,0 +1,38 @@
+use async_executor::Executor;
+use log::*;
+use std::{
+    net::SocketAddr,
+    sync::{Arc, Weak},
+};
+
+use crate::error::{Error, Result};
+//use crate::net::error::{Error, Result};
+use crate::{
+    net::{
+        protocols::{ProtocolAddress, ProtocolPing},
+        sessions::Session,
+        Acceptor, AcceptorPtr, ChannelPtr, P2p,
+    },
+    system::{StoppableTask, StoppableTaskPtr},
+};
+
+pub struct ManualSession {
+    p2p: Weak<P2p>,
+}
+
+impl ManualSession {
+    /// Create a new inbound session.
+    pub fn new(p2p: Weak<P2p>) -> Arc<Self> {
+        Arc::new(Self { p2p, })
+    }
+    /// Starts the inbound session. Begins by accepting connections and fails if
+    /// the address is not configured. Then runs the channel subscription
+    /// loop.
+    pub fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
+        Ok(())
+    }
+
+    pub fn connect(self: Arc<Self>, addr: &SocketAddr) {
+    }
+}
+

+ 9 - 6
src/net/sessions/mod.rs

@@ -1,3 +1,10 @@
+/// Seed connections session. Manages the creation of seed sessions. Used on
+/// first time connecting to the network. The seed node stores a list of other
+/// nodes in the network.
+pub mod seed_session;
+
+pub mod manual_session;
+
 /// Inbound connections session. Manages the creation of inbound sessions. Used
 /// to create an inbound session and start and stop the session.
 ///
@@ -16,16 +23,12 @@ pub mod inbound_session;
 /// no other part of the program uses the slots at the same time.
 pub mod outbound_session;
 
-/// Seed connections session. Manages the creation of seed sessions. Used on
-/// first time connecting to the network. The seed node stores a list of other
-/// nodes in the network.
-pub mod seed_session;
-
 /// Defines methods that are used across sessions. Implements registering the
 /// channel and initializing the channel by performing a network handshake.
 pub mod session;
 
+pub use seed_session::SeedSession;
+pub use manual_session::ManualSession;
 pub use inbound_session::InboundSession;
 pub use outbound_session::OutboundSession;
-pub use seed_session::SeedSession;
 pub use session::Session;