Improve log messages by including PeerId

This commit is contained in:
Thomas Eizinger 2021-03-17 14:42:21 +11:00
parent a57f88d1b4
commit e54d26b26c
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
5 changed files with 83 additions and 66 deletions

View File

@ -28,14 +28,17 @@ pub enum OutEvent {
bob_peer_id: PeerId, bob_peer_id: PeerId,
state3: Box<State3>, state3: Box<State3>,
}, },
TransferProofAcknowledged, TransferProofAcknowledged(PeerId),
EncryptedSignature { EncryptedSignature {
msg: Box<EncryptedSignature>, msg: Box<EncryptedSignature>,
channel: ResponseChannel<()>, channel: ResponseChannel<()>,
peer: PeerId, peer: PeerId,
}, },
ResponseSent, // Same variant is used for all messages as no processing is done ResponseSent, // Same variant is used for all messages as no processing is done
Failure(Error), Failure {
peer: PeerId,
error: Error,
},
} }
impl From<peer_tracker::OutEvent> for OutEvent { impl From<peer_tracker::OutEvent> for OutEvent {
@ -62,23 +65,20 @@ impl From<spot_price::OutEvent> for OutEvent {
} => OutEvent::SpotPriceRequested { msg, channel, peer }, } => OutEvent::SpotPriceRequested { msg, channel, peer },
spot_price::OutEvent::Message { spot_price::OutEvent::Message {
message: RequestResponseMessage::Response { .. }, message: RequestResponseMessage::Response { .. },
..
} => OutEvent::Failure(anyhow!(
"Alice is only meant to hand out spot prices, not receive them"
)),
spot_price::OutEvent::ResponseSent { .. } => OutEvent::ResponseSent,
spot_price::OutEvent::InboundFailure { peer, error, .. } => OutEvent::Failure(anyhow!(
"spot_price protocol with peer {} failed due to {:?}",
peer, peer,
error } => OutEvent::Failure {
)), error: anyhow!("Alice is only meant to hand out spot prices, not receive them"),
spot_price::OutEvent::OutboundFailure { peer, error, .. } => { peer,
OutEvent::Failure(anyhow!( },
"spot_price protocol with peer {} failed due to {:?}", spot_price::OutEvent::ResponseSent { .. } => OutEvent::ResponseSent,
peer, spot_price::OutEvent::InboundFailure { peer, error, .. } => OutEvent::Failure {
error error: anyhow!("spot_price protocol failed due to {:?}", error),
)) peer,
} },
spot_price::OutEvent::OutboundFailure { peer, error, .. } => OutEvent::Failure {
error: anyhow!("spot_price protocol failed due to {:?}", error),
peer,
},
} }
} }
} }
@ -92,21 +92,20 @@ impl From<quote::OutEvent> for OutEvent {
} => OutEvent::QuoteRequested { channel, peer }, } => OutEvent::QuoteRequested { channel, peer },
quote::OutEvent::Message { quote::OutEvent::Message {
message: RequestResponseMessage::Response { .. }, message: RequestResponseMessage::Response { .. },
.. peer,
} => OutEvent::Failure(anyhow!( } => OutEvent::Failure {
"Alice is only meant to hand out quotes, not receive them" error: anyhow!("Alice is only meant to hand out quotes, not receive them"),
)), peer,
},
quote::OutEvent::ResponseSent { .. } => OutEvent::ResponseSent, quote::OutEvent::ResponseSent { .. } => OutEvent::ResponseSent,
quote::OutEvent::InboundFailure { peer, error, .. } => OutEvent::Failure(anyhow!( quote::OutEvent::InboundFailure { peer, error, .. } => OutEvent::Failure {
"quote protocol with peer {} failed due to {:?}", error: anyhow!("quote protocol failed due to {:?}", error),
peer, peer,
error },
)), quote::OutEvent::OutboundFailure { peer, error, .. } => OutEvent::Failure {
quote::OutEvent::OutboundFailure { peer, error, .. } => OutEvent::Failure(anyhow!( error: anyhow!("quote protocol failed due to {:?}", error),
"quote protocol with peer {} failed due to {:?}",
peer, peer,
error },
)),
} }
} }
} }
@ -122,7 +121,7 @@ impl From<execution_setup::OutEvent> for OutEvent {
bob_peer_id, bob_peer_id,
state3: Box::new(state3), state3: Box::new(state3),
}, },
Failure(err) => OutEvent::Failure(err), Failure { peer, error } => OutEvent::Failure { peer, error },
} }
} }
} }
@ -131,8 +130,11 @@ impl From<transfer_proof::OutEvent> for OutEvent {
fn from(event: transfer_proof::OutEvent) -> Self { fn from(event: transfer_proof::OutEvent) -> Self {
use crate::protocol::alice::transfer_proof::OutEvent::*; use crate::protocol::alice::transfer_proof::OutEvent::*;
match event { match event {
Acknowledged => OutEvent::TransferProofAcknowledged, Acknowledged(peer) => OutEvent::TransferProofAcknowledged(peer),
Failure(err) => OutEvent::Failure(err.context("Failure with Transfer Proof")), Failure { peer, error } => OutEvent::Failure {
peer,
error: error.context("Failure with Transfer Proof"),
},
} }
} }
} }
@ -147,7 +149,10 @@ impl From<encrypted_signature::OutEvent> for OutEvent {
peer, peer,
}, },
AckSent => OutEvent::ResponseSent, AckSent => OutEvent::ResponseSent,
Failure(err) => OutEvent::Failure(err.context("Failure with Encrypted Signature")), Failure { peer, error } => OutEvent::Failure {
peer,
error: error.context("Failure with Encrypted Signature"),
},
} }
} }
} }

View File

@ -17,7 +17,10 @@ pub enum OutEvent {
peer: PeerId, peer: PeerId,
}, },
AckSent, AckSent,
Failure(Error), Failure {
peer: PeerId,
error: Error,
},
} }
/// A `NetworkBehaviour` that represents receiving the Bitcoin encrypted /// A `NetworkBehaviour` that represents receiving the Bitcoin encrypted
@ -73,14 +76,19 @@ impl From<RequestResponseEvent<EncryptedSignature, ()>> for OutEvent {
} }
RequestResponseEvent::Message { RequestResponseEvent::Message {
message: RequestResponseMessage::Response { .. }, message: RequestResponseMessage::Response { .. },
.. peer,
} => OutEvent::Failure(anyhow!("Alice should not get a Response")), } => OutEvent::Failure {
RequestResponseEvent::InboundFailure { error, .. } => { peer,
OutEvent::Failure(anyhow!("Inbound failure: {:?}", error)) error: anyhow!("Alice should not get a Response"),
} },
RequestResponseEvent::OutboundFailure { error, .. } => { RequestResponseEvent::InboundFailure { error, peer, .. } => OutEvent::Failure {
OutEvent::Failure(anyhow!("Outbound failure: {:?}", error)) peer,
} error: anyhow!("Inbound failure: {:?}", error),
},
RequestResponseEvent::OutboundFailure { error, peer, .. } => OutEvent::Failure {
peer,
error: anyhow!("Outbound failure: {:?}", error),
},
RequestResponseEvent::ResponseSent { .. } => OutEvent::AckSent, RequestResponseEvent::ResponseSent { .. } => OutEvent::AckSent,
} }
} }

View File

@ -158,8 +158,8 @@ where
OutEvent::ExecutionSetupDone{bob_peer_id, state3} => { OutEvent::ExecutionSetupDone{bob_peer_id, state3} => {
let _ = self.handle_execution_setup_done(bob_peer_id, *state3).await; let _ = self.handle_execution_setup_done(bob_peer_id, *state3).await;
} }
OutEvent::TransferProofAcknowledged => { OutEvent::TransferProofAcknowledged(peer) => {
trace!("Bob acknowledged transfer proof"); trace!(%peer, "Bob acknowledged transfer proof");
} }
OutEvent::EncryptedSignature{ msg, channel, peer } => { OutEvent::EncryptedSignature{ msg, channel, peer } => {
match self.recv_encrypted_signature.remove(&peer) { match self.recv_encrypted_signature.remove(&peer) {
@ -177,8 +177,8 @@ where
} }
} }
OutEvent::ResponseSent => {} OutEvent::ResponseSent => {}
OutEvent::Failure(err) => { OutEvent::Failure {peer, error} => {
error!("Communication error: {:#}", err); error!(%peer, "Communication error: {:#}", error);
} }
} }
}, },

View File

@ -29,7 +29,7 @@ pub struct Message3 {
#[derive(Debug)] #[derive(Debug)]
pub enum OutEvent { pub enum OutEvent {
Done { bob_peer_id: PeerId, state3: State3 }, Done { bob_peer_id: PeerId, state3: State3 },
Failure(Error), Failure { peer: PeerId, error: Error },
} }
impl From<BehaviourOutEvent<(PeerId, State3), (), Error>> for OutEvent { impl From<BehaviourOutEvent<(PeerId, State3), (), Error>> for OutEvent {
@ -39,7 +39,7 @@ impl From<BehaviourOutEvent<(PeerId, State3), (), Error>> for OutEvent {
bob_peer_id, bob_peer_id,
state3, state3,
}, },
BehaviourOutEvent::Inbound(_, Err(e)) => OutEvent::Failure(e), BehaviourOutEvent::Inbound(peer, Err(e)) => OutEvent::Failure { peer, error: e },
BehaviourOutEvent::Outbound(..) => unreachable!("Alice only supports inbound"), BehaviourOutEvent::Outbound(..) => unreachable!("Alice only supports inbound"),
} }
} }

View File

@ -16,8 +16,8 @@ pub struct TransferProof {
#[derive(Debug)] #[derive(Debug)]
pub enum OutEvent { pub enum OutEvent {
Acknowledged, Acknowledged(PeerId),
Failure(Error), Failure { peer: PeerId, error: Error },
} }
/// A `NetworkBehaviour` that represents sending the Monero transfer proof to /// A `NetworkBehaviour` that represents sending the Monero transfer proof to
@ -56,23 +56,27 @@ impl From<RequestResponseEvent<TransferProof, ()>> for OutEvent {
match event { match event {
RequestResponseEvent::Message { RequestResponseEvent::Message {
message: RequestResponseMessage::Request { .. }, message: RequestResponseMessage::Request { .. },
.. peer,
} => OutEvent::Failure(anyhow!( } => OutEvent::Failure {
"Alice should never get a transfer proof request from Bob" peer,
)), error: anyhow!("Alice should never get a transfer proof request from Bob"),
},
RequestResponseEvent::Message { RequestResponseEvent::Message {
message: RequestResponseMessage::Response { .. }, message: RequestResponseMessage::Response { .. },
.. peer,
} => OutEvent::Acknowledged, } => OutEvent::Acknowledged(peer),
RequestResponseEvent::InboundFailure { error, .. } => { RequestResponseEvent::InboundFailure { error, peer, .. } => OutEvent::Failure {
OutEvent::Failure(anyhow!("Inbound failure: {:?}", error)) peer,
} error: anyhow!("Inbound failure: {:?}", error),
RequestResponseEvent::OutboundFailure { error, .. } => { },
OutEvent::Failure(anyhow!("Outbound failure: {:?}", error)) RequestResponseEvent::OutboundFailure { error, peer, .. } => OutEvent::Failure {
} peer,
RequestResponseEvent::ResponseSent { .. } => { error: anyhow!("Outbound failure: {:?}", error),
OutEvent::Failure(anyhow!("Alice should not send a response")) },
} RequestResponseEvent::ResponseSent { peer, .. } => OutEvent::Failure {
peer,
error: anyhow!("Alice should not send a response"),
},
} }
} }
} }