From cc1d61c401e52ba3b6cd264c5400fb7ab52522dc Mon Sep 17 00:00:00 2001 From: hozan23 Date: Wed, 22 May 2024 18:23:14 +0200 Subject: p2p: add enable_monitor field to Config --- p2p/src/monitor.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'p2p/src/monitor.rs') 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, + + config: Arc, } impl Monitor { /// Creates a new Monitor - pub(crate) fn new() -> Self { + pub(crate) fn new(config: Arc) -> Self { Self { event_sys: EventSys::new(), + config, } } @@ -52,7 +55,9 @@ impl Monitor { where E: EventValue + Clone + EventValueTopic, { - 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. -- cgit v1.2.3