mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
remove unecessary plurals: protocols -> protocol, sessions -> session, messages -> message
This commit is contained in:
@@ -17,8 +17,8 @@ use crate::{
|
||||
error::{Error, Result},
|
||||
net::{
|
||||
message_subscriber::{MessageSubscription, MessageSubsystem},
|
||||
messages,
|
||||
protocols::{ProtocolBase, ProtocolBasePtr},
|
||||
message,
|
||||
protocol::{ProtocolBase, ProtocolBasePtr},
|
||||
},
|
||||
system::{StoppableTask, StoppableTaskPtr, Subscriber, SubscriberPtr, Subscription},
|
||||
};
|
||||
@@ -108,7 +108,7 @@ impl Channel {
|
||||
/// Sends a message across a channel. Calls function 'send_message' that
|
||||
/// creates a new payload and sends it over the TCP connection as a
|
||||
/// packet. Returns an error if something goes wrong.
|
||||
pub async fn send<M: messages::Message>(&self, message: M) -> Result<()> {
|
||||
pub async fn send<M: message::Message>(&self, message: M) -> Result<()> {
|
||||
debug!(target: "net",
|
||||
"Channel::send() [START, command={:?}, address={}]",
|
||||
M::name(),
|
||||
@@ -139,17 +139,17 @@ impl Channel {
|
||||
/// it. Then creates a message packet- the base type of the network- and
|
||||
/// copies the payload into it. Then we send the packet over the TCP
|
||||
/// stream.
|
||||
async fn send_message<M: messages::Message>(&self, message: M) -> Result<()> {
|
||||
async fn send_message<M: message::Message>(&self, message: M) -> Result<()> {
|
||||
let mut payload = Vec::new();
|
||||
message.encode(&mut payload)?;
|
||||
let packet = messages::Packet { command: String::from(M::name()), payload };
|
||||
let packet = message::Packet { command: String::from(M::name()), payload };
|
||||
|
||||
let stream = &mut *self.writer.lock().await;
|
||||
messages::send_packet(stream, packet).await
|
||||
message::send_packet(stream, packet).await
|
||||
}
|
||||
|
||||
/// Subscribe to a messages on the message subsystem.
|
||||
pub async fn subscribe_msg<M: messages::Message>(&self) -> Result<MessageSubscription<M>> {
|
||||
pub async fn subscribe_msg<M: message::Message>(&self) -> Result<MessageSubscription<M>> {
|
||||
debug!(target: "net",
|
||||
"Channel::subscribe_msg() [START, command={:?}, address={}]",
|
||||
M::name(),
|
||||
@@ -179,12 +179,12 @@ impl Channel {
|
||||
|
||||
/// Perform network handshake for message subsystem dispatchers.
|
||||
async fn setup_dispatchers(message_subsystem: &MessageSubsystem) {
|
||||
message_subsystem.add_dispatch::<messages::VersionMessage>().await;
|
||||
message_subsystem.add_dispatch::<messages::VerackMessage>().await;
|
||||
message_subsystem.add_dispatch::<messages::PingMessage>().await;
|
||||
message_subsystem.add_dispatch::<messages::PongMessage>().await;
|
||||
message_subsystem.add_dispatch::<messages::GetAddrsMessage>().await;
|
||||
message_subsystem.add_dispatch::<messages::AddrsMessage>().await;
|
||||
message_subsystem.add_dispatch::<message::VersionMessage>().await;
|
||||
message_subsystem.add_dispatch::<message::VerackMessage>().await;
|
||||
message_subsystem.add_dispatch::<message::PingMessage>().await;
|
||||
message_subsystem.add_dispatch::<message::PongMessage>().await;
|
||||
message_subsystem.add_dispatch::<message::GetAddrsMessage>().await;
|
||||
message_subsystem.add_dispatch::<message::AddrsMessage>().await;
|
||||
}
|
||||
|
||||
/// Convenience function that returns the Message Subsystem.
|
||||
@@ -203,7 +203,7 @@ impl Channel {
|
||||
let reader = &mut *self.reader.lock().await;
|
||||
|
||||
loop {
|
||||
let packet = match messages::read_packet(reader).await {
|
||||
let packet = match message::read_packet(reader).await {
|
||||
Ok(packet) => packet,
|
||||
Err(err) => {
|
||||
if Self::is_eof_error(err.clone()) {
|
||||
|
||||
@@ -5,7 +5,7 @@ use rand::Rng;
|
||||
use std::{any::Any, collections::HashMap, io, io::Cursor, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
net::messages::Message,
|
||||
net::message::Message,
|
||||
util::serial::{Decodable, Encodable},
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ pub mod message_subscriber;
|
||||
///
|
||||
/// Implements a type called Packet which is the base message type. Packets are
|
||||
/// converted into messages and passed to an event loop.
|
||||
pub mod messages;
|
||||
pub mod message;
|
||||
|
||||
/// P2P provides all core functionality to interact with the peer-to-peer
|
||||
/// network.
|
||||
@@ -72,7 +72,7 @@ pub mod p2p;
|
||||
///
|
||||
/// Protocol submodule also implements a jobs manager than handles the
|
||||
/// asynchronous execution of the protocols.
|
||||
pub mod protocols;
|
||||
pub mod protocol;
|
||||
|
||||
/// Defines the interaction between nodes during a connection. Consists of an
|
||||
/// inbound session, which describes how to set up an incoming connection, and
|
||||
@@ -80,7 +80,7 @@ pub mod protocols;
|
||||
/// describes the seed session, which is the type of connection used when a node
|
||||
/// connects to the network for the first time. Implements the session trait
|
||||
/// which describes the common functions across all sessions.
|
||||
pub mod sessions;
|
||||
pub mod session;
|
||||
|
||||
/// Network configuration settings.
|
||||
pub mod settings;
|
||||
@@ -90,7 +90,7 @@ pub use channel::{Channel, ChannelPtr};
|
||||
pub use connector::Connector;
|
||||
pub use hosts::{Hosts, HostsPtr};
|
||||
pub use message_subscriber::MessageSubscription;
|
||||
pub use messages::Message;
|
||||
pub use message::Message;
|
||||
pub use p2p::{P2p, P2pPtr};
|
||||
pub use protocols::{ProtocolJobsManager, ProtocolJobsManagerPtr};
|
||||
pub use protocol::{ProtocolJobsManager, ProtocolJobsManagerPtr};
|
||||
pub use settings::{Settings, SettingsPtr};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use async_executor::Executor;
|
||||
use async_std::sync::Mutex;
|
||||
use log::*;
|
||||
use log::debug;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
net::SocketAddr,
|
||||
@@ -10,9 +10,9 @@ use std::{
|
||||
use crate::{
|
||||
error::{Error, Result},
|
||||
net::{
|
||||
messages::Message,
|
||||
protocols::{register_default_protocols, ProtocolRegistry},
|
||||
sessions::{InboundSession, ManualSession, OutboundSession, SeedSession},
|
||||
message::Message,
|
||||
protocol::{register_default_protocols, ProtocolRegistry},
|
||||
session::{InboundSession, ManualSession, OutboundSession, SeedSession},
|
||||
Channel, ChannelPtr, Hosts, HostsPtr, Settings, SettingsPtr,
|
||||
},
|
||||
system::{Subscriber, SubscriberPtr, Subscription},
|
||||
|
||||
@@ -7,8 +7,8 @@ use crate::{
|
||||
error::Result,
|
||||
net::{
|
||||
message_subscriber::MessageSubscription,
|
||||
messages,
|
||||
protocols::{ProtocolBase, ProtocolBasePtr, ProtocolJobsManager, ProtocolJobsManagerPtr},
|
||||
message,
|
||||
protocol::{ProtocolBase, ProtocolBasePtr, ProtocolJobsManager, ProtocolJobsManagerPtr},
|
||||
ChannelPtr, HostsPtr, P2pPtr,
|
||||
},
|
||||
};
|
||||
@@ -16,8 +16,8 @@ use crate::{
|
||||
/// Defines address and get-address messages.
|
||||
pub struct ProtocolAddress {
|
||||
channel: ChannelPtr,
|
||||
addrs_sub: MessageSubscription<messages::AddrsMessage>,
|
||||
get_addrs_sub: MessageSubscription<messages::GetAddrsMessage>,
|
||||
addrs_sub: MessageSubscription<message::AddrsMessage>,
|
||||
get_addrs_sub: MessageSubscription<message::GetAddrsMessage>,
|
||||
hosts: HostsPtr,
|
||||
jobsman: ProtocolJobsManagerPtr,
|
||||
}
|
||||
@@ -29,14 +29,14 @@ impl ProtocolAddress {
|
||||
// Creates a subscription to address message.
|
||||
let addrs_sub = channel
|
||||
.clone()
|
||||
.subscribe_msg::<messages::AddrsMessage>()
|
||||
.subscribe_msg::<message::AddrsMessage>()
|
||||
.await
|
||||
.expect("Missing addrs dispatcher!");
|
||||
|
||||
// Creates a subscription to get-address message.
|
||||
let get_addrs_sub = channel
|
||||
.clone()
|
||||
.subscribe_msg::<messages::GetAddrsMessage>()
|
||||
.subscribe_msg::<message::GetAddrsMessage>()
|
||||
.await
|
||||
.expect("Missing getaddrs dispatcher!");
|
||||
|
||||
@@ -55,14 +55,14 @@ impl ProtocolAddress {
|
||||
// Creates a subscription to address message.
|
||||
let addrs_sub = channel
|
||||
.clone()
|
||||
.subscribe_msg::<messages::AddrsMessage>()
|
||||
.subscribe_msg::<message::AddrsMessage>()
|
||||
.await
|
||||
.expect("Missing addrs dispatcher!");
|
||||
|
||||
// Creates a subscription to get-address message.
|
||||
let get_addrs_sub = channel
|
||||
.clone()
|
||||
.subscribe_msg::<messages::GetAddrsMessage>()
|
||||
.subscribe_msg::<message::GetAddrsMessage>()
|
||||
.await
|
||||
.expect("Missing getaddrs dispatcher!");
|
||||
|
||||
@@ -113,7 +113,7 @@ impl ProtocolAddress {
|
||||
addrs.len()
|
||||
);
|
||||
// Creates an address messages containing host address.
|
||||
let addrs_msg = messages::AddrsMessage { addrs };
|
||||
let addrs_msg = message::AddrsMessage { addrs };
|
||||
// Sends the address message across the channel.
|
||||
self.channel.clone().send(addrs_msg).await?;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ impl ProtocolBase for ProtocolAddress {
|
||||
self.jobsman.clone().spawn(self.clone().handle_receive_get_addrs(), executor).await;
|
||||
|
||||
// Send get_address message.
|
||||
let get_addrs = messages::GetAddrsMessage {};
|
||||
let get_addrs = message::GetAddrsMessage {};
|
||||
let _ = self.channel.clone().send(get_addrs).await;
|
||||
debug!(target: "net", "ProtocolAddress::start() [END]");
|
||||
}
|
||||
@@ -7,8 +7,8 @@ use async_trait::async_trait;
|
||||
use crate::{
|
||||
error::{Error, Result},
|
||||
net::{
|
||||
messages,
|
||||
protocols::{ProtocolBase, ProtocolBasePtr, ProtocolJobsManager, ProtocolJobsManagerPtr},
|
||||
message,
|
||||
protocol::{ProtocolBase, ProtocolBasePtr, ProtocolJobsManager, ProtocolJobsManagerPtr},
|
||||
ChannelPtr, P2pPtr, SettingsPtr,
|
||||
},
|
||||
util::sleep,
|
||||
@@ -53,7 +53,7 @@ impl ProtocolPing {
|
||||
let pong_sub = self
|
||||
.channel
|
||||
.clone()
|
||||
.subscribe_msg::<messages::PongMessage>()
|
||||
.subscribe_msg::<message::PongMessage>()
|
||||
.await
|
||||
.expect("Missing pong dispatcher!");
|
||||
|
||||
@@ -65,7 +65,7 @@ impl ProtocolPing {
|
||||
let nonce = Self::random_nonce();
|
||||
|
||||
// Send ping message.
|
||||
let ping = messages::PingMessage { nonce };
|
||||
let ping = message::PingMessage { nonce };
|
||||
self.channel.clone().send(ping).await?;
|
||||
debug!(target: "net", "ProtocolPing::run_ping_pong() send Ping message");
|
||||
// Start the timer for ping timer.
|
||||
@@ -91,7 +91,7 @@ impl ProtocolPing {
|
||||
let ping_sub = self
|
||||
.channel
|
||||
.clone()
|
||||
.subscribe_msg::<messages::PingMessage>()
|
||||
.subscribe_msg::<message::PingMessage>()
|
||||
.await
|
||||
.expect("Missing ping dispatcher!");
|
||||
|
||||
@@ -101,7 +101,7 @@ impl ProtocolPing {
|
||||
debug!(target: "net", "ProtocolPing::reply_to_ping() received Ping message");
|
||||
|
||||
// Send pong message.
|
||||
let pong = messages::PongMessage { nonce: ping.nonce };
|
||||
let pong = message::PongMessage { nonce: ping.nonce };
|
||||
self.channel.clone().send(pong).await?;
|
||||
debug!(target: "net", "ProtocolPing::reply_to_ping() sent Pong reply");
|
||||
}
|
||||
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
error::Result,
|
||||
net::{messages, ChannelPtr, HostsPtr, SettingsPtr},
|
||||
net::{message, ChannelPtr, HostsPtr, SettingsPtr},
|
||||
};
|
||||
|
||||
/// Implements the seed protocol.
|
||||
@@ -29,7 +29,7 @@ impl ProtocolSeed {
|
||||
let addr_sub = self
|
||||
.channel
|
||||
.clone()
|
||||
.subscribe_msg::<messages::AddrsMessage>()
|
||||
.subscribe_msg::<message::AddrsMessage>()
|
||||
.await
|
||||
.expect("Missing addrs dispatcher!");
|
||||
|
||||
@@ -37,7 +37,7 @@ impl ProtocolSeed {
|
||||
self.send_self_address().await?;
|
||||
|
||||
// Send get address message.
|
||||
let get_addr = messages::GetAddrsMessage {};
|
||||
let get_addr = message::GetAddrsMessage {};
|
||||
self.channel.clone().send(get_addr).await?;
|
||||
|
||||
// Receive addresses.
|
||||
@@ -56,7 +56,7 @@ impl ProtocolSeed {
|
||||
match self.settings.external_addr {
|
||||
Some(addr) => {
|
||||
debug!(target: "net", "ProtocolSeed::send_own_address() addr={}", addr);
|
||||
let addr = messages::AddrsMessage { addrs: vec![addr] };
|
||||
let addr = message::AddrsMessage { addrs: vec![addr] };
|
||||
Ok(self.channel.clone().send(addr).await?)
|
||||
}
|
||||
// Do nothing if external address is not configured
|
||||
@@ -5,7 +5,7 @@ use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
error::{Error, Result},
|
||||
net::{message_subscriber::MessageSubscription, messages, ChannelPtr, SettingsPtr},
|
||||
net::{message_subscriber::MessageSubscription, message, ChannelPtr, SettingsPtr},
|
||||
util::sleep,
|
||||
};
|
||||
|
||||
@@ -13,8 +13,8 @@ use crate::{
|
||||
/// of a connection.
|
||||
pub struct ProtocolVersion {
|
||||
channel: ChannelPtr,
|
||||
version_sub: MessageSubscription<messages::VersionMessage>,
|
||||
verack_sub: MessageSubscription<messages::VerackMessage>,
|
||||
version_sub: MessageSubscription<message::VersionMessage>,
|
||||
verack_sub: MessageSubscription<message::VerackMessage>,
|
||||
settings: SettingsPtr,
|
||||
}
|
||||
|
||||
@@ -26,14 +26,14 @@ impl ProtocolVersion {
|
||||
// Creates a version subscription.
|
||||
let version_sub = channel
|
||||
.clone()
|
||||
.subscribe_msg::<messages::VersionMessage>()
|
||||
.subscribe_msg::<message::VersionMessage>()
|
||||
.await
|
||||
.expect("Missing version dispatcher!");
|
||||
|
||||
// Creates a version acknowledgement subscription.
|
||||
let verack_sub = channel
|
||||
.clone()
|
||||
.subscribe_msg::<messages::VerackMessage>()
|
||||
.subscribe_msg::<message::VerackMessage>()
|
||||
.await
|
||||
.expect("Missing verack dispatcher!");
|
||||
|
||||
@@ -71,7 +71,7 @@ impl ProtocolVersion {
|
||||
/// Send version info and wait for version acknowledgement.
|
||||
async fn send_version(self: Arc<Self>) -> Result<()> {
|
||||
debug!(target: "net", "ProtocolVersion::send_version() [START]");
|
||||
let version = messages::VersionMessage {};
|
||||
let version = message::VersionMessage {};
|
||||
self.channel.clone().send(version).await?;
|
||||
|
||||
// Wait for version acknowledgement
|
||||
@@ -90,7 +90,7 @@ impl ProtocolVersion {
|
||||
// Check the message is OK
|
||||
|
||||
// Send version acknowledgement
|
||||
let verack = messages::VerackMessage {};
|
||||
let verack = message::VerackMessage {};
|
||||
self.channel.clone().send(verack).await?;
|
||||
|
||||
debug!(target: "net", "ProtocolVersion::recv_version() [END]");
|
||||
@@ -8,8 +8,8 @@ use std::{
|
||||
use crate::{
|
||||
error::{Error, Result},
|
||||
net::{
|
||||
protocols::{ProtocolAddress, ProtocolPing, ProtocolBase},
|
||||
sessions::Session,
|
||||
protocol::{ProtocolAddress, ProtocolPing, ProtocolBase},
|
||||
session::Session,
|
||||
Acceptor, AcceptorPtr, ChannelPtr, P2p,
|
||||
},
|
||||
system::{StoppableTask, StoppableTaskPtr},
|
||||
@@ -9,8 +9,8 @@ use std::{
|
||||
use crate::{
|
||||
error::{Error, Result},
|
||||
net::{
|
||||
protocols::{ProtocolAddress, ProtocolPing, ProtocolBase},
|
||||
sessions::Session,
|
||||
protocol::{ProtocolAddress, ProtocolPing, ProtocolBase},
|
||||
session::Session,
|
||||
ChannelPtr, Connector, P2p,
|
||||
},
|
||||
system::{StoppableTask, StoppableTaskPtr},
|
||||
@@ -9,8 +9,8 @@ use std::{
|
||||
use crate::{
|
||||
error::{Error, Result},
|
||||
net::{
|
||||
protocols::{ProtocolAddress, ProtocolPing, ProtocolBase},
|
||||
sessions::Session,
|
||||
protocol::{ProtocolAddress, ProtocolPing, ProtocolBase},
|
||||
session::Session,
|
||||
ChannelPtr, Connector, P2p,
|
||||
},
|
||||
system::{StoppableTask, StoppableTaskPtr},
|
||||
@@ -9,8 +9,8 @@ use std::{
|
||||
use crate::{
|
||||
error::{Error, Result},
|
||||
net::{
|
||||
protocols::{ProtocolPing, ProtocolSeed, ProtocolBase},
|
||||
sessions::Session,
|
||||
protocol::{ProtocolPing, ProtocolSeed, ProtocolBase},
|
||||
session::Session,
|
||||
ChannelPtr, Connector, HostsPtr, P2p, SettingsPtr,
|
||||
},
|
||||
util::sleep,
|
||||
@@ -5,7 +5,7 @@ use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
error::Result,
|
||||
net::{p2p::P2pPtr, protocols::ProtocolVersion, ChannelPtr},
|
||||
net::{p2p::P2pPtr, protocol::ProtocolVersion, ChannelPtr},
|
||||
};
|
||||
|
||||
/// Removes channel from the list of connected channels when a stop signal is
|
||||
Reference in New Issue
Block a user