From cae4b4094bc9c4e0e5f457c348b94657fc37ecd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20M=C3=A4rkle?= Date: Tue, 5 Nov 2024 15:07:51 +0100 Subject: [PATCH] CARL PeerMessagingBroker -> Improve logging when peer connects. --- .../src/grpc/peer_messaging_broker.rs | 11 +++++--- opendut-carl/src/peer/broker.rs | 28 ++++++++++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/opendut-carl/src/grpc/peer_messaging_broker.rs b/opendut-carl/src/grpc/peer_messaging_broker.rs index 89554f13..5dc6768a 100644 --- a/opendut-carl/src/grpc/peer_messaging_broker.rs +++ b/opendut-carl/src/grpc/peer_messaging_broker.rs @@ -53,10 +53,13 @@ impl opendut_carl_api::proto::services::peer_messaging_broker::peer_messaging_br let (tx_inbound, rx_outbound) = self.peer_messaging_broker.open(peer_id, remote_host).await - .map_err(|cause| match cause { - OpenError::PeerAlreadyConnected { .. } => Status::aborted(cause.to_string()), - OpenError::SendApplyPeerConfiguration { .. } => Status::unavailable(cause.to_string()), - OpenError::Persistence { .. } => Status::internal(cause.to_string()), + .map_err(|cause| { + error!("Error while opening stream from newly connected peer <{peer_id}>:\n {cause}"); + match cause { + OpenError::PeerAlreadyConnected { .. } => Status::aborted(cause.to_string()), + OpenError::SendApplyPeerConfiguration { .. } => Status::unavailable(cause.to_string()), + OpenError::Persistence { .. } => Status::internal(cause.to_string()), + } })?; let mut inbound = request.into_inner(); diff --git a/opendut-carl/src/peer/broker.rs b/opendut-carl/src/peer/broker.rs index a4fd83e1..c7b0980d 100644 --- a/opendut-carl/src/peer/broker.rs +++ b/opendut-carl/src/peer/broker.rs @@ -114,12 +114,32 @@ impl PeerMessagingBroker { .map_err(|source| OpenError::Persistence { peer_id, source })??; let old_peer_configuration = self.resources_manager.get::(peer_id).await - .map_err(|source| OpenError::Persistence { peer_id, source })? - .unwrap_or_default(); //PeerConfiguration is not persisted across restarts + .map_err(|source| OpenError::Persistence { peer_id, source })?; + let old_peer_configuration = match old_peer_configuration { + Some(old_peer_configuration) => { + debug!("Found an OldPeerConfiguration for newly connected peer <{peer_id}>. Re-sending this configuration:\n{old_peer_configuration:#?}"); + old_peer_configuration + } + None => { + //PeerConfiguration is not persisted across restarts + debug!("No OldPeerConfiguration found for newly connected peer <{peer_id}>. Sending empty configuration."); + OldPeerConfiguration::default() + } + }; let peer_configuration = self.resources_manager.get::(peer_id).await - .map_err(|source| OpenError::Persistence { peer_id, source })? - .unwrap_or_default(); //PeerConfiguration is not persisted across restarts + .map_err(|source| OpenError::Persistence { peer_id, source })?; + let peer_configuration = match peer_configuration { + Some(peer_configuration) => { + debug!("Found an OldPeerConfiguration for newly connected peer <{peer_id}>. Re-sending this configuration.\n{peer_configuration:#?}"); + peer_configuration + } + None => { + //PeerConfiguration is not persisted across restarts + debug!("No PeerConfiguration found for newly connected peer <{peer_id}>. Sending empty configuration."); + PeerConfiguration::default() + } + }; self.send_to_peer(peer_id, downstream::Message::ApplyPeerConfiguration( ApplyPeerConfiguration {