aboutsummaryrefslogtreecommitdiff
path: root/p2p
diff options
context:
space:
mode:
Diffstat (limited to 'p2p')
-rw-r--r--p2p/src/backend.rs2
-rw-r--r--p2p/src/connection.rs (renamed from p2p/src/net/connection_queue.rs)19
-rw-r--r--p2p/src/connector.rs (renamed from p2p/src/net/connector.rs)3
-rw-r--r--p2p/src/discovery/lookup.rs4
-rw-r--r--p2p/src/discovery/mod.rs6
-rw-r--r--p2p/src/lib.rs5
-rw-r--r--p2p/src/listener.rs (renamed from p2p/src/net/listener.rs)3
-rw-r--r--p2p/src/net/mod.rs27
-rw-r--r--p2p/src/peer/mod.rs2
-rw-r--r--p2p/src/peer_pool.rs3
-rw-r--r--p2p/src/slots.rs (renamed from p2p/src/net/slots.rs)0
11 files changed, 32 insertions, 42 deletions
diff --git a/p2p/src/backend.rs b/p2p/src/backend.rs
index 290e3e7..bb18f06 100644
--- a/p2p/src/backend.rs
+++ b/p2p/src/backend.rs
@@ -6,9 +6,9 @@ use karyons_core::{pubsub::Subscription, Executor};
use crate::{
config::Config,
+ connection::ConnQueue,
discovery::{ArcDiscovery, Discovery},
monitor::{Monitor, MonitorEvent},
- net::ConnQueue,
peer_pool::PeerPool,
protocol::{ArcProtocol, Protocol},
ArcPeer, PeerID, Result,
diff --git a/p2p/src/net/connection_queue.rs b/p2p/src/connection.rs
index 4c0de28..7c81aa2 100644
--- a/p2p/src/net/connection_queue.rs
+++ b/p2p/src/connection.rs
@@ -1,12 +1,25 @@
-use std::{collections::VecDeque, sync::Arc};
-
use smol::{channel::Sender, lock::Mutex};
+use std::{collections::VecDeque, fmt, sync::Arc};
use karyons_core::async_utils::CondVar;
use karyons_net::Conn;
-use crate::net::ConnDirection;
+/// Defines the direction of a network connection.
+#[derive(Clone, Debug)]
+pub enum ConnDirection {
+ Inbound,
+ Outbound,
+}
+
+impl fmt::Display for ConnDirection {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ ConnDirection::Inbound => write!(f, "Inbound"),
+ ConnDirection::Outbound => write!(f, "Outbound"),
+ }
+ }
+}
pub struct NewConn {
pub direction: ConnDirection,
diff --git a/p2p/src/net/connector.rs b/p2p/src/connector.rs
index 72dc0d8..3932c41 100644
--- a/p2p/src/net/connector.rs
+++ b/p2p/src/connector.rs
@@ -10,11 +10,10 @@ use karyons_net::{dial, Conn, Endpoint, NetError};
use crate::{
monitor::{ConnEvent, Monitor},
+ slots::ConnectionSlots,
Result,
};
-use super::slots::ConnectionSlots;
-
/// Responsible for creating outbound connections with other peers.
pub struct Connector {
/// Managing spawned tasks.
diff --git a/p2p/src/discovery/lookup.rs b/p2p/src/discovery/lookup.rs
index f404133..94da900 100644
--- a/p2p/src/discovery/lookup.rs
+++ b/p2p/src/discovery/lookup.rs
@@ -10,14 +10,16 @@ use karyons_core::{async_utils::timeout, utils::decode, Executor};
use karyons_net::{Conn, Endpoint};
use crate::{
+ connector::Connector,
io_codec::IOCodec,
+ listener::Listener,
message::{
get_msg_payload, FindPeerMsg, NetMsg, NetMsgCmd, PeerMsg, PeersMsg, PingMsg, PongMsg,
ShutdownMsg,
},
monitor::{ConnEvent, DiscoveryEvent, Monitor},
- net::{ConnectionSlots, Connector, Listener},
routing_table::RoutingTable,
+ slots::ConnectionSlots,
utils::version_match,
Config, Error, PeerID, Result,
};
diff --git a/p2p/src/discovery/mod.rs b/p2p/src/discovery/mod.rs
index 94b350b..7b8e7dc 100644
--- a/p2p/src/discovery/mod.rs
+++ b/p2p/src/discovery/mod.rs
@@ -16,13 +16,15 @@ use karyons_net::{Conn, Endpoint};
use crate::{
config::Config,
+ connection::{ConnDirection, ConnQueue},
+ connector::Connector,
+ listener::Listener,
monitor::Monitor,
- net::ConnQueue,
- net::{ConnDirection, ConnectionSlots, Connector, Listener},
routing_table::{
Entry, EntryStatusFlag, RoutingTable, CONNECTED_ENTRY, DISCONNECTED_ENTRY, PENDING_ENTRY,
UNREACHABLE_ENTRY, UNSTABLE_ENTRY,
},
+ slots::ConnectionSlots,
Error, PeerID, Result,
};
diff --git a/p2p/src/lib.rs b/p2p/src/lib.rs
index 08ba059..3cf1e7c 100644
--- a/p2p/src/lib.rs
+++ b/p2p/src/lib.rs
@@ -1,14 +1,17 @@
mod backend;
mod config;
+mod connection;
+mod connector;
mod discovery;
mod error;
mod io_codec;
+mod listener;
mod message;
-mod net;
mod peer;
mod peer_pool;
mod protocols;
mod routing_table;
+mod slots;
mod utils;
/// Responsible for network and system monitoring.
diff --git a/p2p/src/net/listener.rs b/p2p/src/listener.rs
index d1a7bfb..ee92536 100644
--- a/p2p/src/net/listener.rs
+++ b/p2p/src/listener.rs
@@ -11,11 +11,10 @@ use karyons_net::{listen, Conn, Endpoint, Listener as NetListener};
use crate::{
monitor::{ConnEvent, Monitor},
+ slots::ConnectionSlots,
Result,
};
-use super::slots::ConnectionSlots;
-
/// Responsible for creating inbound connections with other peers.
pub struct Listener {
/// Managing spawned tasks.
diff --git a/p2p/src/net/mod.rs b/p2p/src/net/mod.rs
deleted file mode 100644
index 9cdc748..0000000
--- a/p2p/src/net/mod.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-mod connection_queue;
-mod connector;
-mod listener;
-mod slots;
-
-pub use connection_queue::ConnQueue;
-pub use connector::Connector;
-pub use listener::Listener;
-pub use slots::ConnectionSlots;
-
-use std::fmt;
-
-/// Defines the direction of a network connection.
-#[derive(Clone, Debug)]
-pub enum ConnDirection {
- Inbound,
- Outbound,
-}
-
-impl fmt::Display for ConnDirection {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- match self {
- ConnDirection::Inbound => write!(f, "Inbound"),
- ConnDirection::Outbound => write!(f, "Outbound"),
- }
- }
-}
diff --git a/p2p/src/peer/mod.rs b/p2p/src/peer/mod.rs
index ee0fdc4..60e76a1 100644
--- a/p2p/src/peer/mod.rs
+++ b/p2p/src/peer/mod.rs
@@ -20,9 +20,9 @@ use karyons_core::{
use karyons_net::Endpoint;
use crate::{
+ connection::ConnDirection,
io_codec::{CodecMsg, IOCodec},
message::{NetMsgCmd, ProtocolMsg, ShutdownMsg},
- net::ConnDirection,
peer_pool::{ArcPeerPool, WeakPeerPool},
protocol::{Protocol, ProtocolEvent, ProtocolID},
Config, Error, Result,
diff --git a/p2p/src/peer_pool.rs b/p2p/src/peer_pool.rs
index eac4d3d..2433cfc 100644
--- a/p2p/src/peer_pool.rs
+++ b/p2p/src/peer_pool.rs
@@ -20,11 +20,10 @@ use karyons_net::Conn;
use crate::{
config::Config,
+ connection::{ConnDirection, ConnQueue},
io_codec::{CodecMsg, IOCodec},
message::{get_msg_payload, NetMsg, NetMsgCmd, VerAckMsg, VerMsg},
monitor::{Monitor, PeerPoolEvent},
- net::ConnDirection,
- net::ConnQueue,
peer::{ArcPeer, Peer, PeerID},
protocol::{Protocol, ProtocolConstructor, ProtocolID},
protocols::PingProtocol,
diff --git a/p2p/src/net/slots.rs b/p2p/src/slots.rs
index 99f0a78..99f0a78 100644
--- a/p2p/src/net/slots.rs
+++ b/p2p/src/slots.rs