net: organize the modules structures

This commit is contained in:
ghassmo
2022-04-23 02:23:22 +03:00
parent 29a9182010
commit b23517c8fa
12 changed files with 94 additions and 91 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,12 +1,12 @@
use async_std::future::timeout;
use log::*;
use smol::Executor;
use std::{sync::Arc, time::Duration};
use crate::{
error::{Error, Result},
net::{message, message_subscriber::MessageSubscription, ChannelPtr, SettingsPtr},
};
use log::*;
use smol::Executor;
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.

View File

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

View File

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

View File

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

View File

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

View File

@@ -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::{Error, Result},
net::{
session::{Session, SessionBitflag, SESSION_SEED},
Connector, P2p,
},
use crate::{Error, Result};
use super::{
super::{Connector, P2p},
Session, SessionBitflag, SESSION_SEED,
};
/// Defines seed connections session.