Skip to content

Commit

Permalink
CARL PeerMessagingBroker -> Improve logging when peer connects.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfm committed Nov 5, 2024
1 parent a659f83 commit cae4b40
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
11 changes: 7 additions & 4 deletions opendut-carl/src/grpc/peer_messaging_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
28 changes: 24 additions & 4 deletions opendut-carl/src/peer/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,32 @@ impl PeerMessagingBroker {
.map_err(|source| OpenError::Persistence { peer_id, source })??;

let old_peer_configuration = self.resources_manager.get::<OldPeerConfiguration>(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::<PeerConfiguration>(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 {
Expand Down

0 comments on commit cae4b40

Please sign in to comment.