diff options
Diffstat (limited to 'p2p/src/monitor.rs')
-rw-r--r-- | p2p/src/monitor.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/p2p/src/monitor.rs b/p2p/src/monitor.rs index bc3ea7f..945c6aa 100644 --- a/p2p/src/monitor.rs +++ b/p2p/src/monitor.rs @@ -1,11 +1,11 @@ -use std::fmt; - -use crate::PeerID; +use std::{fmt, sync::Arc}; use karyon_core::event::{ArcEventSys, EventListener, EventSys, EventValue, EventValueTopic}; use karyon_net::Endpoint; +use crate::{Config, PeerID}; + /// Responsible for network and system monitoring. /// /// It use pub-sub pattern to notify the subscribers with new events. @@ -37,13 +37,16 @@ use karyon_net::Endpoint; /// ``` pub struct Monitor { event_sys: ArcEventSys<MonitorTopic>, + + config: Arc<Config>, } impl Monitor { /// Creates a new Monitor - pub(crate) fn new() -> Self { + pub(crate) fn new(config: Arc<Config>) -> Self { Self { event_sys: EventSys::new(), + config, } } @@ -52,7 +55,9 @@ impl Monitor { where E: EventValue + Clone + EventValueTopic<Topic = MonitorTopic>, { - self.event_sys.emit(&event).await + if self.config.enable_monitor { + self.event_sys.emit(&event).await + } } /// Registers a new event listener for connection events. |