156: Improve logging and network error handling r=D4nte a=D4nte



Co-authored-by: Franck Royer <franck@coblox.tech>
remove-lib-rs
bors[bot] 3 years ago committed by GitHub
commit 9eae0db9ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,7 +16,6 @@ pub struct Config {
pub monero_network: monero::Network,
}
// TODO: This trait is not needed
pub trait GetConfig {
fn get_config() -> Config;
}

@ -324,7 +324,7 @@ impl Behaviour {
swap_response: SwapResponse,
) -> Result<()> {
self.amounts.send(channel, swap_response)?;
info!("Sent amounts response");
info!("Sent swap response");
Ok(())
}

@ -265,7 +265,7 @@ impl EventLoop {
},
transfer_proof = self.send_transfer_proof.recv().fuse() => {
if let Some((bob_peer_id, msg)) = transfer_proof {
self.swarm.send_transfer_proof(bob_peer_id, msg)
self.swarm.send_transfer_proof(bob_peer_id, msg);
}
},
}

@ -54,7 +54,7 @@ impl Behaviour {
let msg = AliceToBob::Message0(Box::new(msg));
self.rr
.send_response(channel, msg)
.map_err(|_| anyhow!("Sending Amounts response failed"))
.map_err(|alice_to_bob| anyhow!("Could not send response {:?}", alice_to_bob))
}
fn poll(
&mut self,
@ -112,7 +112,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
error!("Outbound failure: {:?}", error);
}
RequestResponseEvent::ResponseSent { .. } => {
debug!("Alice has sent an Message0 response to Bob");
debug!("Alice has sent Message0 as response to Bob");
}
}
}

@ -51,7 +51,7 @@ impl Behaviour {
let msg = AliceToBob::Message1(Box::new(msg));
self.rr
.send_response(channel, msg)
.map_err(|_| anyhow!("Sending Amounts response failed"))
.map_err(|alice_to_bob| anyhow!("Could not send response {:?}", alice_to_bob))
}
fn poll(

@ -97,7 +97,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
error!("Outbound failure: {:?}", error);
}
RequestResponseEvent::ResponseSent { .. } => {
debug!("Alice has sent an Message2 response to Bob");
debug!("Alice has sent a Message2 response to Bob");
}
}
}

@ -1,3 +1,8 @@
use crate::{
monero,
network::request_response::{AliceToBob, BobToAlice, Codec, Swap, TIMEOUT},
protocol::bob,
};
use anyhow::{anyhow, Result};
use libp2p::{
request_response::{
@ -15,12 +20,6 @@ use std::{
};
use tracing::{debug, error};
use crate::{
monero,
network::request_response::{AliceToBob, BobToAlice, Codec, Swap, TIMEOUT},
protocol::bob,
};
#[derive(Debug)]
pub struct OutEvent {
pub msg: bob::SwapRequest,
@ -109,7 +108,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
error!("Outbound failure: {:?}", error);
}
RequestResponseEvent::ResponseSent { .. } => {
debug!("Alice has sent an Amounts response to Bob");
debug!("Alice has sent a swap response to Bob");
}
}
}

@ -97,7 +97,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<Request, Response>> for B
error!("Outbound failure: {:?}", error);
}
RequestResponseEvent::ResponseSent { .. } => {
unreachable!("Bob should never send a Amounts response to Alice");
unreachable!("Bob does not send the encrypted signature response to Alice");
}
}
}

@ -103,7 +103,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
error!("Outbound failure: {:?}", error);
}
RequestResponseEvent::ResponseSent { .. } => {
unreachable!("Bob should never send a Amounts response to Alice");
unreachable!("Bob does not send a message0 response to Alice");
}
}
}

@ -98,7 +98,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
error!("Outbound failure: {:?}", error);
}
RequestResponseEvent::ResponseSent { .. } => {
unreachable!("Bob should never send a Amounts response to Alice");
unreachable!("Bob does not send a message 1 response to Alice");
}
}
}

@ -96,7 +96,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
error!("Outbound failure: {:?}", error);
}
RequestResponseEvent::ResponseSent { .. } => {
unreachable!("Bob should never send a Amounts response to Alice");
unreachable!("Bob does not send a Message2 response to Alice");
}
}
}

@ -104,7 +104,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<BobToAlice, AliceToBob>>
error!("Outbound failure: {:?}", error);
}
RequestResponseEvent::ResponseSent { .. } => {
error!("Bob should never send a Amounts response to Alice");
error!("Bob does not send a swap response to Alice");
}
}
}

@ -79,7 +79,10 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<Request, Response>> for B
debug!("Received Transfer Proof");
self.events.push_back(OutEvent::Msg(*msg));
// Send back empty response so that the request/response protocol completes.
let _ = self.rr.send_response(channel, Response::TransferProof);
let _ = self
.rr
.send_response(channel, Response::TransferProof)
.map_err(|err| error!("Failed to send message 3: {:?}", err));
}
}
RequestResponseEvent::Message {

Loading…
Cancel
Save