From 119f2a7c543a0e965d6bdd352bbd439433dc08cb Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 29 Oct 2020 13:59:57 +1100 Subject: [PATCH] Add error logging to request_response --- swap/src/alice/amounts.rs | 1 + swap/src/alice/message0.rs | 3 ++- swap/src/network/request_response.rs | 25 ++++++++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/swap/src/alice/amounts.rs b/swap/src/alice/amounts.rs index 70dd6b8a..e0fb3bcd 100644 --- a/swap/src/alice/amounts.rs +++ b/swap/src/alice/amounts.rs @@ -80,6 +80,7 @@ impl NetworkBehaviourEventProcess> }, .. } => { + tracing::debug!("amounts: Request from Bob received"); if let BobToAlice::AmountsFromBtc(btc) = request { self.events.push_back(OutEvent::Btc { btc, channel }) } diff --git a/swap/src/alice/message0.rs b/swap/src/alice/message0.rs index 20ca05db..04c5222d 100644 --- a/swap/src/alice/message0.rs +++ b/swap/src/alice/message0.rs @@ -86,8 +86,9 @@ impl NetworkBehaviourEventProcess> }, .. } => { + tracing::debug!("message0: Request from Bob received"); if let BobToAlice::Message0(msg) = request { - info!("Got Alice's first message"); + info!("Got Bob's first message"); let response = match &self.state { None => panic!("No state, did you forget to set it?"), Some(state) => { diff --git a/swap/src/network/request_response.rs b/swap/src/network/request_response.rs index 7026626e..6f033ae6 100644 --- a/swap/src/network/request_response.rs +++ b/swap/src/network/request_response.rs @@ -6,6 +6,7 @@ use libp2p::{ }; use serde::{Deserialize, Serialize}; use std::{fmt::Debug, io}; +use tracing::debug; use crate::SwapAmounts; use xmr_btc::{alice, bob, monero}; @@ -65,12 +66,15 @@ impl RequestResponseCodec for Codec { where T: AsyncRead + Unpin + Send, { + debug!("enter read_request"); let message = upgrade::read_one(io, BUF_SIZE) .await .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; let mut de = serde_cbor::Deserializer::from_slice(&message); - let msg = BobToAlice::deserialize(&mut de) - .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + let msg = BobToAlice::deserialize(&mut de).map_err(|e| { + tracing::debug!("serde read_request error: {:?}", e); + io::Error::new(io::ErrorKind::Other, e) + })?; Ok(msg) } @@ -83,12 +87,15 @@ impl RequestResponseCodec for Codec { where T: AsyncRead + Unpin + Send, { + debug!("enter read_response"); let message = upgrade::read_one(io, BUF_SIZE) .await .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; let mut de = serde_cbor::Deserializer::from_slice(&message); - let msg = AliceToBob::deserialize(&mut de) - .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; + let msg = AliceToBob::deserialize(&mut de).map_err(|e| { + tracing::debug!("serde read_response error: {:?}", e); + io::Error::new(io::ErrorKind::InvalidData, e) + })?; Ok(msg) } @@ -102,8 +109,9 @@ impl RequestResponseCodec for Codec { where T: AsyncWrite + Unpin + Send, { + debug!("enter write_request"); let bytes = serde_cbor::to_vec(&req).map_err(|e| { - tracing::debug!("yes Lucas we are actually here"); + tracing::debug!("serde write_request error: {:?}", e); io::Error::new(io::ErrorKind::InvalidData, e) })?; @@ -121,8 +129,11 @@ impl RequestResponseCodec for Codec { where T: AsyncWrite + Unpin + Send, { - let bytes = - serde_cbor::to_vec(&res).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; + debug!("enter write_response"); + let bytes = serde_cbor::to_vec(&res).map_err(|e| { + tracing::debug!("serde write_reponse error: {:?}", e); + io::Error::new(io::ErrorKind::InvalidData, e) + })?; upgrade::write_one(io, &bytes).await?; Ok(())