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

more precise debugging information for networking submodule

narodnik 5 лет назад
Родитель
Сommit
d867564a77
3 измененных файлов с 11 добавлено и 3 удалено
  1. 3 0
      src/net/p2p.rs
  2. 5 1
      src/net/protocols/protocol_ping.rs
  3. 3 2
      src/net/sessions/outbound_session.rs

+ 3 - 0
src/net/p2p.rs

@@ -50,6 +50,8 @@ impl P2p {
     /// Synchronize the blockchain and then begin long running sessions,
     /// call after start() is invoked.
     pub async fn run(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
+        debug!(target: "net", "P2p::run() [BEGIN]");
+
         let inbound = InboundSession::new(Arc::downgrade(&self));
         inbound.clone().start(executor.clone())?;
 
@@ -64,6 +66,7 @@ impl P2p {
         inbound.stop().await;
         outbound.stop().await;
 
+        debug!(target: "net", "P2p::run() [BEGIN]");
         Ok(())
     }
 

+ 5 - 1
src/net/protocols/protocol_ping.rs

@@ -2,6 +2,7 @@ use log::*;
 use rand::Rng;
 use smol::Executor;
 use std::sync::Arc;
+use std::time::{Duration, Instant};
 
 use crate::net::error::{NetError, NetResult};
 use crate::net::messages;
@@ -58,6 +59,8 @@ impl ProtocolPing {
             let ping = messages::Message::Ping(messages::PingMessage { nonce });
             self.channel.clone().send(ping).await?;
             debug!(target: "net", "ProtocolPing::run_ping_pong() send Ping message");
+            // Start the timer for ping timer
+            let start = Instant::now();
 
             // Wait for pong, check nonce matches
             let pong_msg = receive_message!(pong_sub, messages::Message::Pong);
@@ -66,7 +69,8 @@ impl ProtocolPing {
                 self.channel.stop().await;
                 return Err(NetError::ChannelStopped);
             }
-            debug!(target: "net", "ProtocolPing::run_ping_pong() received Pong message");
+            let duration = start.elapsed().as_millis();
+            debug!(target: "net", "Received Pong message {}ms from [{:?}]", duration, self.channel.address());
         }
     }
 

+ 3 - 2
src/net/sessions/outbound_session.rs

@@ -25,6 +25,7 @@ impl OutboundSession {
 
     pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> NetResult<()> {
         let slots_count = self.p2p().settings().outbound_connections;
+        info!("Starting {} outbound connection slots.", slots_count);
         let mut connect_slots = self.connect_slots.lock().await;
 
         for i in 0..slots_count {
@@ -61,13 +62,13 @@ impl OutboundSession {
 
         loop {
             let addr = self.load_address(slot_number).await?;
-            info!("Connecting to outbound [{}]", addr);
+            info!("#{} connecting to outbound [{}]", slot_number, addr);
 
             match connector.connect(addr).await {
                 Ok(channel) => {
                     // Blacklist goes here
 
-                    info!("Connected outbound [{}]", addr);
+                    info!("#{} connected to outbound [{}]", slot_number, addr);
 
                     let stop_sub = channel.subscribe_stop().await;