Browse Source

add protocol names

narodnik 4 years ago
parent
commit
7a8a10aaac

+ 5 - 3
bin/ircd/src/protocol_privmsg.rs

@@ -25,8 +25,6 @@ impl ProtocolPrivMsg {
         let message_subsytem = channel.get_message_subsystem();
         message_subsytem.add_dispatch::<PrivMsg>().await;
 
-        debug!("ADDED DISPATCH");
-
         let privmsg_sub =
             channel.subscribe_msg::<PrivMsg>().await.expect("Missing PrivMsg dispatcher!");
 
@@ -40,7 +38,7 @@ impl ProtocolPrivMsg {
     }
 
     async fn handle_receive_privmsg(self: Arc<Self>) -> Result<()> {
-        debug!(target: "ircd", "ProtocolAddress::handle_receive_privmsg() [START]");
+        debug!(target: "ircd", "ProtocolPrivMsg::handle_receive_privmsg() [START]");
         loop {
             let privmsg = self.privmsg_sub.receive().await?;
 
@@ -78,4 +76,8 @@ impl net::ProtocolBase for ProtocolPrivMsg {
         debug!(target: "ircd", "ProtocolPrivMsg::start() [END]");
         Ok(())
     }
+
+    fn name(&self) -> &'static str {
+        "ProtocolPrivMsg"
+    }
 }

+ 2 - 2
src/net/message.rs

@@ -1,5 +1,5 @@
-use futures::prelude::*;
-use log::*;
+use futures::{AsyncRead, AsyncWrite, AsyncReadExt, AsyncWriteExt};
+use log::debug;
 use std::{io, net::SocketAddr};
 
 use crate::{

+ 3 - 1
src/net/message_subscriber.rs

@@ -1,6 +1,6 @@
 use async_std::sync::Mutex;
 use async_trait::async_trait;
-use log::*;
+use log::{debug, error, warn};
 use rand::Rng;
 use std::{any::Any, collections::HashMap, io, io::Cursor, sync::Arc};
 
@@ -87,6 +87,7 @@ impl<M: Message> MessageDispatcher<M> {
     /// channels.
     async fn trigger_all(&self, message: MessageResult<M>) {
         debug!(
+            target: "net",
             "MessageDispatcher<M={}>::trigger_all({}) [START, subs={}]",
             M::name(),
             if message.is_ok() { "msg" } else { "err" },
@@ -109,6 +110,7 @@ impl<M: Message> MessageDispatcher<M> {
         self.collect_garbage(garbage_ids).await;
 
         debug!(
+            target: "net",
             "MessageDispatcher<M={}>::trigger_all({}) [END, subs={}]",
             M::name(),
             if message.is_ok() { "msg" } else { "err" },

+ 4 - 0
src/net/protocol/protocol_address.rs

@@ -137,4 +137,8 @@ impl ProtocolBase for ProtocolAddress {
         debug!(target: "net", "ProtocolAddress::start() [END]");
         Ok(())
     }
+
+    fn name(&self) -> &'static str {
+        "ProtocolAddress"
+    }
 }

+ 2 - 0
src/net/protocol/protocol_base.rs

@@ -9,4 +9,6 @@ pub type ProtocolBasePtr = Arc<dyn ProtocolBase + Send + Sync>;
 #[async_trait]
 pub trait ProtocolBase {
     async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()>;
+
+    fn name(&self) -> &'static str;
 }

+ 4 - 0
src/net/protocol/protocol_ping.rs

@@ -126,4 +126,8 @@ impl ProtocolBase for ProtocolPing {
         debug!(target: "net", "ProtocolPing::start() [END]");
         Ok(())
     }
+
+    fn name(&self) -> &'static str {
+        "ProtocolPing"
+    }
 }

+ 2 - 0
src/net/protocol/protocol_registry.rs

@@ -1,6 +1,7 @@
 use async_std::sync::Mutex;
 use futures::future::BoxFuture;
 use std::future::Future;
+use log::debug;
 
 use super::protocol_base::ProtocolBase;
 use std::sync::Arc;
@@ -53,6 +54,7 @@ impl ProtocolRegistry {
 
             let protocol: Arc<dyn ProtocolBase + Send + Sync> =
                 construct(channel.clone(), p2p.clone()).await;
+            debug!(target: "net", "Attached {}", protocol.name());
             protocols.push(protocol)
         }
         protocols

+ 4 - 0
src/net/protocol/protocol_seed.rs

@@ -78,4 +78,8 @@ impl ProtocolBase for ProtocolSeed {
         debug!(target: "net", "ProtocolSeed::start() [END]");
         Ok(())
     }
+
+    fn name(&self) -> &'static str {
+        "ProtocolSeed"
+    }
 }

+ 2 - 1
src/net/session/session.rs

@@ -1,5 +1,5 @@
 use async_trait::async_trait;
-use log::*;
+use log::debug;
 use smol::Executor;
 use std::sync::Arc;
 
@@ -57,6 +57,7 @@ pub trait Session: Sync {
         handshake_task.await?;
 
         // Now the channel is ready
+        debug!(target: "net", "Session handshake complete. Activating remaining protocols");
 
         // Now start all the protocols
         // They are responsible for managing their own lifetimes and