Просмотр исходного кода

Merge branch 'master' of github.com:narodnik/sapvi

plato 5 лет назад
Родитель
Сommit
c4b508237f

+ 5 - 5
src/net/acceptor.rs

@@ -10,8 +10,8 @@ use crate::system::{StoppableTask, StoppableTaskPtr, Subscriber, SubscriberPtr,
 /// Atomic pointer to Acceptor class.
 pub type AcceptorPtr = Arc<Acceptor>;
 
-/// Handles the acceptance of inbound socket connections. Used to start listening on a local socket
-/// address, to accept incoming connections and to handle network errors.
+/// Handles the acceptance of inbound socket connections. Used to start listening
+/// on a local socket address, to accept incoming connections and to handle network errors.
 pub struct Acceptor {
     channel_subscriber: SubscriberPtr<NetResult<ChannelPtr>>,
     task: StoppableTaskPtr,
@@ -25,9 +25,9 @@ impl Acceptor {
             task: StoppableTask::new(),
         })
     }
-    /// Start accepting inbound socket connections. Creates a listener to start listening on a
-    /// local socket address. Then runs an accept loop in a new thread, erroring if a connection
-    /// problem occurs.
+    /// Start accepting inbound socket connections. Creates a listener to start
+    /// listening on a local socket address. Then runs an accept loop in a new
+    /// thread, erroring if a connection problem occurs.
     pub fn start(
         self: Arc<Self>,
         accept_addr: SocketAddr,

+ 5 - 4
src/net/message_subscriber.rs

@@ -17,8 +17,8 @@ use crate::serial::{Decodable, Encodable};
 pub type MessageSubscriptionID = u64;
 type MessageResult<M> = NetResult<Arc<M>>;
 
-/// Handles message subscriptions through a subscription ID and a receiver channel.
-/// Inherits from Message Dispatcher.
+/// Handles message subscriptions through a subscription ID and a receiver
+/// channel. Inherits from Message Dispatcher.
 pub struct MessageSubscription<M: Message> {
     id: MessageSubscriptionID,
     recv_queue: async_channel::Receiver<MessageResult<M>>,
@@ -160,8 +160,9 @@ impl<M: Message> MessageDispatcherInterface for MessageDispatcher<M> {
 }
 
 /// Generic publish/subscribe class that can dispatch any kind of message
-/// to a subscribed list of dispatchers. Dispatchers subscribe to a single message format of any
-/// type. This is a generalized version of the pub/sub model in system::Subscriber.
+/// to a subscribed list of dispatchers. Dispatchers subscribe to a single
+/// message format of any type. This is a generalized version of the pub/sub
+/// model in system::Subscriber.
 pub struct MessageSubsystem {
     dispatchers: Mutex<HashMap<&'static str, Arc<dyn MessageDispatcherInterface>>>,
 }

+ 2 - 2
src/net/messages.rs

@@ -158,8 +158,8 @@ impl Decodable for VerackMessage {
     }
 }
 
-/// Packets are the base type read from the network. Converted to messages and passed to event
-/// loop.
+/// Packets are the base type read from the network. Converted to messages and
+/// passed to event loop.
 pub struct Packet {
     pub command: String,
     pub payload: Vec<u8>,

+ 1 - 0
src/net/p2p.rs

@@ -80,6 +80,7 @@ impl P2p {
         Ok(())
     }
 
+    /// Broadcasts a message across all channels.
     pub async fn broadcast<M: Message + Clone>(&self, message: M) -> NetResult<()> {
         for channel in self.channels.lock().await.values() {
             channel.send(message.clone()).await?;

+ 8 - 8
src/net/protocols/protocol_address.rs

@@ -21,8 +21,8 @@ pub struct ProtocolAddress {
 }
 
 impl ProtocolAddress {
-    /// Create a new address protocol. Makes an address and get-address subscription and adds them
-    /// to the address protocol instance.
+    /// Create a new address protocol. Makes an address and get-address subscription
+    /// and adds them to the address protocol instance.
     pub async fn new(channel: ChannelPtr, hosts: HostsPtr) -> Arc<Self> {
         // Creates a subscription to address message.
         let addrs_sub = channel
@@ -47,8 +47,8 @@ impl ProtocolAddress {
         })
     }
 
-    /// Starts the address protocol. Runs receive address and get address protocols on the protocol
-    /// task manager. Then sends get-address message.
+    /// Starts the address protocol. Runs receive address and get address protocols
+    /// on the protocol task manager. Then sends get-address message.
     pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) {
         debug!(target: "net", "ProtocolAddress::start() [START]");
         self.jobsman.clone().start(executor.clone());
@@ -67,8 +67,8 @@ impl ProtocolAddress {
         debug!(target: "net", "ProtocolAddress::start() [END]");
     }
 
-    /// Handles receiving the address message. Loops to continually recieve address messages on the
-    /// address subsciption. Adds the recieved addresses to the list of hosts.
+    /// Handles receiving the address message. Loops to continually recieve address
+    /// messages on the address subsciption. Adds the recieved addresses to the list of hosts.
     async fn handle_receive_addrs(self: Arc<Self>) -> NetResult<()> {
         debug!(target: "net", "ProtocolAddress::handle_receive_addrs() [START]");
         loop {
@@ -86,8 +86,8 @@ impl ProtocolAddress {
         }
     }
 
-    /// Handles receiving the get-address message. Continually recieves get-address messages on the
-    /// get-address subsciption. Then replies with an address message.
+    /// Handles receiving the get-address message. Continually recieves get-address
+    /// messages on the get-address subsciption. Then replies with an address message.
     async fn handle_receive_get_addrs(self: Arc<Self>) -> NetResult<()> {
         debug!(target: "net", "ProtocolAddress::handle_receive_get_addrs() [START]");
         loop {

+ 2 - 2
src/net/protocols/protocol_jobs_manager.rs

@@ -41,8 +41,8 @@ impl ProtocolJobsManager {
         self.tasks.lock().await.push(executor.spawn(future))
     }
 
-    /// Waits for a stop signal, then closes all tasks. Insures that all tasks are stopped when a
-    /// channel closes. Called in start().
+    /// Waits for a stop signal, then closes all tasks. Insures that all tasks are
+    /// stopped when a channel closes. Called in start().
     async fn handle_stop(self: Arc<Self>) {
         let stop_sub = self.channel.clone().subscribe_stop().await;
 

+ 7 - 6
src/net/protocols/protocol_ping.rs

@@ -28,9 +28,9 @@ impl ProtocolPing {
         })
     }
 
-    /// Starts ping-pong keep-alive messages exchange. Runs ping-pong in the protocol task manager,
-    /// then queues the reply. run_ping_pong() sends out a ping and waits for pong reply.
-    /// reply_to_ping() waits for ping and replies with a pong.
+    /// Starts ping-pong keep-alive messages exchange. Runs ping-pong in the protocol
+    /// task manager, then queues the reply. Sends out a ping and waits for pong
+    /// reply. Waits for ping and replies with a pong.
     pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) {
         debug!(target: "net", "ProtocolPing::start() [START]");
         self.jobsman.clone().start(executor.clone());
@@ -45,9 +45,10 @@ impl ProtocolPing {
         debug!(target: "net", "ProtocolPing::start() [END]");
     }
 
-    /// Runs ping-pong protocol. Creates a subscription to pong, then starts a loop. Loop sleeps
-    /// for the duration of the channel heartbeat, then sends a ping message with a random nonce.
-    /// Loop starts a timer, waits for the pong reply and insures the nonce is the same.
+    /// Runs ping-pong protocol. Creates a subscription to pong, then starts a loop.
+    /// Loop sleeps for the duration of the channel heartbeat, then sends a ping
+    /// message with a random nonce. Loop starts a timer, waits for the pong reply
+    /// and insures the nonce is the same.
     async fn run_ping_pong(self: Arc<Self>) -> NetResult<()> {
         debug!(target: "net", "ProtocolPing::run_ping_pong() [START]");
         // Creates a subscription to pong message.

+ 7 - 6
src/net/protocols/protocol_seed.rs

@@ -6,8 +6,8 @@ use crate::net::error::NetResult;
 use crate::net::messages;
 use crate::net::{ChannelPtr, HostsPtr, SettingsPtr};
 
-/// Seed server protocol. Seed server is used when connecting to the network for the first time.
-/// Returns a list of IP addresses that nodes can connect to.
+/// Seed server protocol. Seed server is used when connecting to the network for
+/// the first time. Returns a list of IP addresses that nodes can connect to.
 pub struct ProtocolSeed {
     channel: ChannelPtr,
     hosts: HostsPtr,
@@ -24,8 +24,9 @@ impl ProtocolSeed {
         })
     }
 
-    /// Starts the seed protocol. Creates a subscription to the address message, then sends our
-    /// address to the seed server. Sends a get-address message and receives an address message.
+    /// Starts the seed protocol. Creates a subscription to the address message, then
+    /// sends our address to the seed server. Sends a get-address message and receives
+    /// an address message.
     pub async fn start(self: Arc<Self>, _executor: Arc<Executor<'_>>) -> NetResult<()> {
         debug!(target: "net", "ProtocolSeed::start() [START]");
         // Create a subscription to address message.
@@ -52,8 +53,8 @@ impl ProtocolSeed {
         Ok(())
     }
 
-    /// Sends own external address over a channel. Imports own external address from settings, then
-    /// adds that address to an address message and sends it out over the channel.
+    /// Sends own external address over a channel. Imports own external address from
+    /// settings, then adds that address to an address message and sends it out over the channel.
     pub async fn send_self_address(&self) -> NetResult<()> {
         match self.settings.external_addr {
             Some(addr) => {

+ 4 - 4
src/net/protocols/protocol_version.rs

@@ -18,8 +18,8 @@ pub struct ProtocolVersion {
 }
 
 impl ProtocolVersion {
-    /// Create a new version protocol. Makes a version and version acknowledgement subscription,
-    /// then adds them to a version protocol instance.
+    /// Create a new version protocol. Makes a version and version acknowledgement
+    /// subscription, then adds them to a version protocol instance.
     pub async fn new(channel: ChannelPtr, settings: SettingsPtr) -> Arc<Self> {
         // Creates a version subscription.
         let version_sub = channel
@@ -42,8 +42,8 @@ impl ProtocolVersion {
             settings,
         })
     }
-    /// Start version information exchange. Start the timer. Send version info and wait for version
-    /// acknowledgement. Wait for version info and send version acknowledgement.
+    /// Start version information exchange. Start the timer. Send version info and
+    /// wait for version acknowledgement. Wait for version info and send version acknowledgement.
     pub async fn run(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
         debug!(target: "net", "ProtocolVersion::run() [START]");
         // Start timer

+ 4 - 4
src/net/sessions/inbound_session.rs

@@ -28,8 +28,8 @@ impl InboundSession {
             accept_task: StoppableTask::new(),
         })
     }
-    /// Starts the inbound session. Begins by accepting connections and fails if the address is not
-    /// configured. Then runs the channel subscription loop.
+    /// 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<'_>>) -> NetResult<()> {
         match self.p2p().settings().inbound {
             Some(accept_addr) => {
@@ -84,8 +84,8 @@ impl InboundSession {
         }
     }
 
-    /// Registers the channel. First performs a network handshake and starts the channel. Then starts
-    /// sending keep-alive and address messages across the channel.
+    /// Registers the channel. First performs a network handshake and starts the
+    /// channel. Then starts sending keep-alive and address messages across the channel.
     async fn setup_channel(
         self: Arc<Self>,
         channel: ChannelPtr,

+ 8 - 8
src/net/sessions/outbound_session.rs

@@ -56,10 +56,10 @@ impl OutboundSession {
         }
     }
 
-    /// Start making outbound connections.
-    /// Creates a connector object, then starts a connect loop. Loads a valid address then tries to
-    /// connect. Once connected, registers the channel, removes it from the list of pending
-    /// channels, and starts sending messages across the channel. Otherwise returns a network error.
+    /// Start making outbound connections. Creates a connector object, then starts a
+    /// connect loop. Loads a valid address then tries to connect. Once connected,
+    /// registers the channel, removes it from the list of pending channels, and
+    /// starts sending messages across the channel. Otherwise returns a network error.
     pub async fn channel_connect_loop(
         self: Arc<Self>,
         slot_number: u32,
@@ -102,10 +102,10 @@ impl OutboundSession {
         }
     }
 
-    /// Loops through host addresses to find a outbound address that we can connect to.
-    /// Checks whether address is valid by making sure it isn't our own inbound address,
-    /// then checks whether it is already connected (exists) or connecting (pending).
-    /// Keeps looping until address is found that passes all checks.
+    /// Loops through host addresses to find a outbound address that we can connect
+    /// to. Checks whether address is valid by making sure it isn't our own inbound
+    /// address, then checks whether it is already connected (exists) or connecting
+    /// (pending). Keeps looping until address is found that passes all checks.
     async fn load_address(&self, slot_number: u32) -> NetResult<SocketAddr> {
         let p2p = self.p2p();
         let hosts = p2p.hosts();

+ 8 - 5
src/net/sessions/session.rs

@@ -25,10 +25,12 @@ async fn remove_sub_on_stop(p2p: P2pPtr, channel: ChannelPtr) {
 }
 
 #[async_trait]
-/// Session trait. Defines methods that are used across sessions. Implements registering the channel
-/// and initializing the channel by performing a network handshake.
+/// Session trait. Defines methods that are used across sessions. Implements
+/// registering the channel and initializing the channel by performing a network
+/// handshake.
 pub trait Session: Sync {
-    /// Registers a new channel with the session. Performs a network handshake and starts the channel.
+    /// Registers a new channel with the session. Performs a network handshake and
+    /// starts the channel.
     async fn register_channel(
         self: Arc<Self>,
         channel: ChannelPtr,
@@ -49,8 +51,9 @@ pub trait Session: Sync {
         Ok(())
     }
 
-    /// Performs network handshake to initialize channel. Adds the channel to the list of connected
-    /// channels, and prepares to remove the channel when a stop signal is received.
+    /// Performs network handshake to initialize channel. Adds the channel to the
+    /// list of connected channels, and prepares to remove the channel when a stop
+    /// signal is received.
     async fn perform_handshake_protocols(
         &self,
         protocol_version: Arc<ProtocolVersion>,

+ 1 - 1
src/net/settings.rs

@@ -4,7 +4,7 @@ use std::sync::Arc;
 /// Atomic pointer to network settings.
 pub type SettingsPtr = Arc<Settings>;
 
-/// Default network configuration settings.
+/// Network configuration settings.
 #[derive(Clone)]
 pub struct Settings {
     pub inbound: Option<SocketAddr>,