From b5530bb9c218d929e9a53bed7bc61d9cc3048773 Mon Sep 17 00:00:00 2001 From: Felix Prillwitz Date: Sun, 24 Nov 2024 15:41:24 +0100 Subject: [PATCH] core: disable trace logging of handled mercury responses --- core/src/dealer/manager.rs | 12 ++++++++++++ core/src/dealer/maps.rs | 23 +++++++++++++++++++++-- core/src/dealer/mod.rs | 27 +++++++++++++++++++++++++++ core/src/mercury/mod.rs | 9 ++++++--- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/core/src/dealer/manager.rs b/core/src/dealer/manager.rs index 43ce13e17..2fd3e1624 100644 --- a/core/src/dealer/manager.rs +++ b/core/src/dealer/manager.rs @@ -113,6 +113,18 @@ impl DealerManager { }) } + pub fn handles(&self, uri: &str) -> bool { + self.lock(|inner| { + if let Some(dealer) = inner.dealer.get() { + dealer.handles(uri) + } else if let Some(builder) = inner.builder.get() { + builder.handles(uri) + } else { + false + } + }) + } + pub async fn start(&self) -> Result<(), Error> { debug!("Launching dealer"); diff --git a/core/src/dealer/maps.rs b/core/src/dealer/maps.rs index 91388a59e..23d21a115 100644 --- a/core/src/dealer/maps.rs +++ b/core/src/dealer/maps.rs @@ -1,8 +1,7 @@ use std::collections::HashMap; -use thiserror::Error; - use crate::Error; +use thiserror::Error; #[derive(Debug, Error)] pub enum HandlerMapError { @@ -28,6 +27,10 @@ impl Default for HandlerMap { } impl HandlerMap { + pub fn contains(&self, path: &str) -> bool { + matches!(self, HandlerMap::Branch(map) if map.contains_key(path)) + } + pub fn insert<'a>( &mut self, mut path: impl Iterator, @@ -107,6 +110,22 @@ impl SubscriberMap { } } + pub fn contains<'a>(&self, mut path: impl Iterator) -> bool { + if !self.subscribed.is_empty() { + return true; + } + + if let Some(next) = path.next() { + if let Some(next_map) = self.children.get(next) { + return next_map.contains(path); + } + } else { + return !self.is_empty(); + } + + false + } + pub fn is_empty(&self) -> bool { self.children.is_empty() && self.subscribed.is_empty() } diff --git a/core/src/dealer/mod.rs b/core/src/dealer/mod.rs index 9000fcc63..abcba3e53 100644 --- a/core/src/dealer/mod.rs +++ b/core/src/dealer/mod.rs @@ -234,6 +234,21 @@ fn subscribe( Ok(Subscription(rx)) } +fn handles( + req_map: &HandlerMap>, + msg_map: &SubscriberMap, + uri: &str, +) -> bool { + if req_map.contains(uri) { + return true; + } + + match split_uri(uri) { + None => false, + Some(mut split) => msg_map.contains(&mut split), + } +} + #[derive(Default)] struct Builder { message_handlers: SubscriberMap, @@ -277,6 +292,10 @@ impl Builder { subscribe(&mut self.message_handlers, uris) } + pub fn handles(&self, uri: &str) -> bool { + handles(&self.request_handlers, &self.message_handlers, uri) + } + pub fn launch_in_background(self, get_url: F, proxy: Option) -> Dealer where Fut: Future + Send + 'static, @@ -416,6 +435,14 @@ impl Dealer { subscribe(&mut self.shared.message_handlers.lock(), uris) } + pub fn handles(&self, uri: &str) -> bool { + handles( + &self.shared.request_handlers.lock(), + &self.shared.message_handlers.lock(), + uri, + ) + } + pub async fn close(mut self) { debug!("closing dealer"); diff --git a/core/src/mercury/mod.rs b/core/src/mercury/mod.rs index 7fde9b7fd..76b060a39 100644 --- a/core/src/mercury/mod.rs +++ b/core/src/mercury/mod.rs @@ -276,12 +276,15 @@ impl MercuryManager { }); }); - if !found { + if found { + Ok(()) + } else if self.session().dealer().handles(&response.uri) { + trace!("mercury response <{}> is handled by dealer", response.uri); + Ok(()) + } else { debug!("unknown subscription uri={}", &response.uri); trace!("response pushed over Mercury: {:?}", response); Err(MercuryError::Response(response).into()) - } else { - Ok(()) } } else if let Some(cb) = pending.callback { cb.send(Ok(response)).map_err(|_| MercuryError::Channel)?;