Răsfoiți Sursa

net: organize the modules structures

ghassmo 4 ani în urmă
părinte
comite
b23517c8fa

+ 11 - 14
src/net/protocol/protocol_address.rs

@@ -4,14 +4,11 @@ use async_trait::async_trait;
 use log::debug;
 use smol::Executor;
 
-use crate::{
-    net::{
-        message,
-        message_subscriber::MessageSubscription,
-        protocol::{ProtocolBase, ProtocolBasePtr, ProtocolJobsManager, ProtocolJobsManagerPtr},
-        ChannelPtr, HostsPtr, P2pPtr,
-    },
-    Result,
+use crate::Result;
+
+use super::{
+    super::{message, message_subscriber::MessageSubscription, ChannelPtr, HostsPtr, P2pPtr},
+    ProtocolBase, ProtocolBasePtr, ProtocolJobsManager, ProtocolJobsManagerPtr,
 };
 
 /// Defines address and get-address messages.
@@ -61,9 +58,9 @@ impl ProtocolAddress {
             let addrs_msg = self.addrs_sub.receive().await?;
 
             debug!(
-                target: "net",
-                "ProtocolAddress::handle_receive_addrs() received {} addrs",
-                addrs_msg.addrs.len()
+            target: "net",
+            "ProtocolAddress::handle_receive_addrs() received {} addrs",
+            addrs_msg.addrs.len()
             );
             for (i, addr) in addrs_msg.addrs.iter().enumerate() {
                 debug!("  addr[{}]: {}", i, addr);
@@ -85,9 +82,9 @@ impl ProtocolAddress {
             // Loads the list of hosts.
             let addrs = self.hosts.load_all().await;
             debug!(
-                target: "net",
-                "ProtocolAddress::handle_receive_get_addrs() sending {} addrs",
-                addrs.len()
+            target: "net",
+            "ProtocolAddress::handle_receive_get_addrs() sending {} addrs",
+            addrs.len()
             );
             // Creates an address messages containing host address.
             let addrs_msg = message::AddrsMessage { addrs };

+ 3 - 2
src/net/protocol/protocol_base.rs

@@ -1,8 +1,9 @@
+use std::sync::Arc;
+
 use async_trait::async_trait;
 use smol::Executor;
-use std::sync::Arc;
 
-use crate::error::Result;
+use crate::Result;
 
 pub type ProtocolBasePtr = Arc<dyn ProtocolBase + Send + Sync>;
 

+ 5 - 2
src/net/protocol/protocol_jobs_manager.rs

@@ -1,10 +1,13 @@
 use async_std::sync::Mutex;
+use std::sync::Arc;
+
 use futures::Future;
 use log::*;
 use smol::Task;
-use std::sync::Arc;
 
-use crate::{error::Result, net::ChannelPtr, system::ExecutorPtr};
+use crate::{system::ExecutorPtr, Result};
+
+use super::super::ChannelPtr;
 
 /// Pointer to protocol jobs manager.
 pub type ProtocolJobsManagerPtr = Arc<ProtocolJobsManager>;

+ 7 - 10
src/net/protocol/protocol_ping.rs

@@ -1,18 +1,15 @@
+use std::{sync::Arc, time::Instant};
+
 use async_trait::async_trait;
 use log::{debug, error};
 use rand::Rng;
 use smol::Executor;
-use std::{sync::Arc, time::Instant};
 
-use crate::{
-    error::{Error, Result},
-    net::{
-        message,
-        message_subscriber::MessageSubscription,
-        protocol::{ProtocolBase, ProtocolBasePtr, ProtocolJobsManager, ProtocolJobsManagerPtr},
-        ChannelPtr, P2pPtr, SettingsPtr,
-    },
-    util::sleep,
+use crate::{util::sleep, Error, Result};
+
+use super::{
+    super::{message, message_subscriber::MessageSubscription, ChannelPtr, P2pPtr, SettingsPtr},
+    ProtocolBase, ProtocolBasePtr, ProtocolJobsManager, ProtocolJobsManagerPtr,
 };
 
 /// Defines ping and pong messages.

+ 6 - 2
src/net/protocol/protocol_registry.rs

@@ -1,9 +1,13 @@
 use async_std::sync::Mutex;
+use std::future::Future;
+
 use futures::future::BoxFuture;
 use log::debug;
-use std::future::Future;
 
-use crate::net::{protocol::ProtocolBasePtr, session::SessionBitflag, ChannelPtr, P2pPtr};
+use super::{
+    super::{session::SessionBitflag, ChannelPtr, P2pPtr},
+    ProtocolBasePtr,
+};
 
 type Constructor =
     Box<dyn Fn(ChannelPtr, P2pPtr) -> BoxFuture<'static, ProtocolBasePtr> + Send + Sync>;

+ 7 - 8
src/net/protocol/protocol_seed.rs

@@ -1,15 +1,14 @@
+use std::sync::Arc;
+
 use async_trait::async_trait;
 use log::debug;
 use smol::Executor;
-use std::sync::Arc;
 
-use crate::{
-    error::Result,
-    net::{
-        message,
-        protocol::{ProtocolBase, ProtocolBasePtr},
-        ChannelPtr, HostsPtr, P2pPtr, SettingsPtr,
-    },
+use crate::Result;
+
+use super::{
+    super::{message, ChannelPtr, HostsPtr, P2pPtr, SettingsPtr},
+    ProtocolBase, ProtocolBasePtr,
 };
 
 /// Implements the seed protocol.

+ 5 - 5
src/net/protocol/protocol_version.rs

@@ -1,12 +1,12 @@
 use async_std::future::timeout;
+use std::{sync::Arc, time::Duration};
+
 use log::*;
 use smol::Executor;
-use std::{sync::Arc, time::Duration};
 
-use crate::{
-    error::{Error, Result},
-    net::{message, message_subscriber::MessageSubscription, ChannelPtr, SettingsPtr},
-};
+use crate::{Error, Result};
+
+use super::super::{message, message_subscriber::MessageSubscription, ChannelPtr, SettingsPtr};
 
 /// Implements the protocol version handshake sent out by nodes at the beginning
 /// of a connection.

+ 8 - 7
src/net/session/inbound_session.rs

@@ -1,22 +1,23 @@
 use async_std::sync::Mutex;
-use async_trait::async_trait;
-use serde_json::json;
 use std::{
     net::SocketAddr,
     sync::{Arc, Weak},
 };
 
 use async_executor::Executor;
+use async_trait::async_trait;
 use fxhash::FxHashMap;
 use log::{error, info};
+use serde_json::json;
 
 use crate::{
-    error::{Error, Result},
-    net::{
-        session::{Session, SessionBitflag, SESSION_INBOUND},
-        Acceptor, AcceptorPtr, ChannelPtr, P2p,
-    },
     system::{StoppableTask, StoppableTaskPtr},
+    Error, Result,
+};
+
+use super::{
+    super::{Acceptor, AcceptorPtr, ChannelPtr, P2p},
+    Session, SessionBitflag, SESSION_INBOUND,
 };
 
 struct InboundInfo {

+ 21 - 20
src/net/session/manual_session.rs

@@ -1,22 +1,23 @@
 use async_std::sync::Mutex;
-use async_trait::async_trait;
-use serde_json::json;
 use std::{
     net::SocketAddr,
     sync::{Arc, Weak},
 };
 
 use async_executor::Executor;
+use async_trait::async_trait;
 use log::*;
+use serde_json::json;
 
 use crate::{
-    error::{Error, Result},
-    net::{
-        session::{Session, SessionBitflag, SESSION_MANUAL},
-        Connector, P2p,
-    },
     system::{StoppableTask, StoppableTaskPtr},
     util::sleep,
+    Error, Result,
+};
+
+use super::{
+    super::{Connector, P2p},
+    Session, SessionBitflag, SESSION_MANUAL,
 };
 
 pub struct ManualSession {
@@ -105,10 +106,10 @@ impl ManualSession {
         }
 
         warn!(
-            target: "net",
-            "Suspending manual connection to [{}] after {} failed attempts.",
-            addr,
-            attempts
+        target: "net",
+        "Suspending manual connection to [{}] after {} failed attempts.",
+        addr,
+        attempts
         );
 
         Ok(())
@@ -116,19 +117,19 @@ impl ManualSession {
 
     // Starts sending keep-alive and address messages across the channels.
     /*async fn attach_protocols(
-        self: Arc<Self>,
-        channel: ChannelPtr,
-        executor: Arc<Executor<'_>>,
+    self: Arc<Self>,
+    channel: ChannelPtr,
+    executor: Arc<Executor<'_>>,
     ) -> Result<()> {
-        let hosts = self.p2p().hosts();
+    let hosts = self.p2p().hosts();
 
-        let protocol_ping = ProtocolPing::new(channel.clone(), self.p2p());
-        let protocol_addr = ProtocolAddress::new(channel, hosts).await;
+    let protocol_ping = ProtocolPing::new(channel.clone(), self.p2p());
+    let protocol_addr = ProtocolAddress::new(channel, hosts).await;
 
-        protocol_ping.start(executor.clone()).await;
-        protocol_addr.start(executor).await;
+    protocol_ping.start(executor.clone()).await;
+    protocol_addr.start(executor).await;
 
-        Ok(())
+    Ok(())
     }*/
 }
 

+ 5 - 5
src/net/session/mod.rs

@@ -1,12 +1,12 @@
+use std::sync::Arc;
+
 use async_trait::async_trait;
 use log::debug;
 use smol::Executor;
-use std::sync::Arc;
 
-use crate::{
-    error::Result,
-    net::{p2p::P2pPtr, protocol::ProtocolVersion, ChannelPtr},
-};
+use crate::Result;
+
+use super::{p2p::P2pPtr, protocol::ProtocolVersion, ChannelPtr};
 
 /// 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

+ 6 - 5
src/net/session/outbound_session.rs

@@ -12,12 +12,13 @@ use rand::seq::SliceRandom;
 use serde_json::json;
 
 use crate::{
-    error::{Error, Result},
-    net::{
-        session::{Session, SessionBitflag, SESSION_OUTBOUND},
-        ChannelPtr, Connector, P2p,
-    },
     system::{StoppableTask, StoppableTaskPtr},
+    Error, Result,
+};
+
+use super::{
+    super::{ChannelPtr, Connector, P2p},
+    Session, SessionBitflag, SESSION_OUTBOUND,
 };
 
 #[derive(Clone)]

+ 7 - 8
src/net/session/seed_session.rs

@@ -1,6 +1,4 @@
 use async_std::future::timeout;
-use async_trait::async_trait;
-use serde_json::json;
 use std::{
     net::SocketAddr,
     sync::{Arc, Weak},
@@ -8,14 +6,15 @@ use std::{
 };
 
 use async_executor::Executor;
+use async_trait::async_trait;
 use log::*;
+use serde_json::json;
+
+use crate::{Error, Result};
 
-use crate::{
-    error::{Error, Result},
-    net::{
-        session::{Session, SessionBitflag, SESSION_SEED},
-        Connector, P2p,
-    },
+use super::{
+    super::{Connector, P2p},
+    Session, SessionBitflag, SESSION_SEED,
 };
 
 /// Defines seed connections session.