From 3e2f0b74a2a9c1187690a0ccb9d92d2514ad45d9 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 29 Oct 2020 10:22:31 +1100 Subject: [PATCH] Do not trace events meant for other NBs --- swap/src/alice.rs | 3 +++ swap/src/alice/amounts.rs | 9 ++++----- swap/src/alice/message0.rs | 9 ++++----- swap/src/alice/message1.rs | 9 ++++----- swap/src/alice/message2.rs | 9 ++++----- swap/src/alice/message3.rs | 9 ++++----- swap/src/bob/amounts.rs | 11 ++++++----- swap/src/bob/message0.rs | 11 ++++++----- swap/src/bob/message1.rs | 11 ++++++----- swap/src/bob/message2.rs | 11 ++++++----- swap/src/bob/message3.rs | 9 +++++---- swap/tests/e2e.rs | 7 ++++++- 12 files changed, 58 insertions(+), 50 deletions(-) diff --git a/swap/src/alice.rs b/swap/src/alice.rs index d9a48a6e..dd095be3 100644 --- a/swap/src/alice.rs +++ b/swap/src/alice.rs @@ -94,6 +94,8 @@ pub async fn swap( } } + debug!("swapping ..."); + let mut swarm = new_swarm(listen, local_port)?; let message0: bob::Message0; let mut last_amounts: Option = None; @@ -112,6 +114,7 @@ pub async fn swap( swarm.send_amounts(channel, amounts); } OutEvent::Message0(msg) => { + debug!("got message 0 from Bob"); // We don't want Bob to be able to crash us by sending an out of // order message. Keep looping if Bob has not requested amounts. if last_amounts.is_some() { diff --git a/swap/src/alice/amounts.rs b/swap/src/alice/amounts.rs index ffa87cf7..70dd6b8a 100644 --- a/swap/src/alice/amounts.rs +++ b/swap/src/alice/amounts.rs @@ -11,7 +11,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing::{debug, error}; +use tracing::error; use crate::network::request_response::{AliceToBob, BobToAlice, Codec, Protocol, TIMEOUT}; @@ -79,12 +79,11 @@ impl NetworkBehaviourEventProcess> request, channel, .. }, .. - } => match request { - BobToAlice::AmountsFromBtc(btc) => { + } => { + if let BobToAlice::AmountsFromBtc(btc) = request { self.events.push_back(OutEvent::Btc { btc, channel }) } - other => debug!("got request: {:?}", other), - }, + } RequestResponseEvent::Message { message: RequestResponseMessage::Response { .. }, .. diff --git a/swap/src/alice/message0.rs b/swap/src/alice/message0.rs index 1ec54365..20ca05db 100644 --- a/swap/src/alice/message0.rs +++ b/swap/src/alice/message0.rs @@ -13,7 +13,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing::{debug, error, info}; +use tracing::{error, info}; use crate::network::request_response::{AliceToBob, BobToAlice, Codec, Protocol, TIMEOUT}; use xmr_btc::{alice::State0, bob}; @@ -85,8 +85,8 @@ impl NetworkBehaviourEventProcess> request, channel, .. }, .. - } => match request { - BobToAlice::Message0(msg) => { + } => { + if let BobToAlice::Message0(msg) = request { info!("Got Alice's first message"); let response = match &self.state { None => panic!("No state, did you forget to set it?"), @@ -98,8 +98,7 @@ impl NetworkBehaviourEventProcess> self.rr.send_response(channel, response); self.events.push_back(OutEvent::Msg(msg)); } - other => debug!("got request: {:?}", other), - }, + } RequestResponseEvent::Message { message: RequestResponseMessage::Response { .. }, .. diff --git a/swap/src/alice/message1.rs b/swap/src/alice/message1.rs index 27df9e20..d9831439 100644 --- a/swap/src/alice/message1.rs +++ b/swap/src/alice/message1.rs @@ -11,7 +11,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing::{debug, error}; +use tracing::error; use crate::network::request_response::{AliceToBob, BobToAlice, Codec, Protocol, TIMEOUT}; use xmr_btc::bob; @@ -81,12 +81,11 @@ impl NetworkBehaviourEventProcess> request, channel, .. }, .. - } => match request { - BobToAlice::Message1(msg) => { + } => { + if let BobToAlice::Message1(msg) = request { self.events.push_back(OutEvent::Msg { msg, channel }); } - other => debug!("got request: {:?}", other), - }, + } RequestResponseEvent::Message { message: RequestResponseMessage::Response { .. }, .. diff --git a/swap/src/alice/message2.rs b/swap/src/alice/message2.rs index 28e5fc10..584a16bf 100644 --- a/swap/src/alice/message2.rs +++ b/swap/src/alice/message2.rs @@ -11,7 +11,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing::{debug, error}; +use tracing::error; use crate::network::request_response::{AliceToBob, BobToAlice, Codec, Protocol, TIMEOUT}; use xmr_btc::bob; @@ -81,12 +81,11 @@ impl NetworkBehaviourEventProcess> request, channel, .. }, .. - } => match request { - BobToAlice::Message2(msg) => { + } => { + if let BobToAlice::Message2(msg) = request { self.events.push_back(OutEvent::Msg { msg, channel }); } - other => debug!("got request: {:?}", other), - }, + } RequestResponseEvent::Message { message: RequestResponseMessage::Response { .. }, .. diff --git a/swap/src/alice/message3.rs b/swap/src/alice/message3.rs index 42e1a600..4ee197c3 100644 --- a/swap/src/alice/message3.rs +++ b/swap/src/alice/message3.rs @@ -11,7 +11,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing::{debug, error}; +use tracing::error; use crate::network::request_response::{AliceToBob, BobToAlice, Codec, Protocol, TIMEOUT}; use xmr_btc::bob; @@ -71,14 +71,13 @@ impl NetworkBehaviourEventProcess> request, channel, .. }, .. - } => match request { - BobToAlice::Message3(msg) => { + } => { + if let BobToAlice::Message3(msg) = request { self.events.push_back(OutEvent::Msg(msg)); // Send back empty response so that the request/response protocol completes. self.rr.send_response(channel, AliceToBob::Message3); } - other => debug!("got request: {:?}", other), - }, + } RequestResponseEvent::Message { message: RequestResponseMessage::Response { .. }, .. diff --git a/swap/src/bob/amounts.rs b/swap/src/bob/amounts.rs index 46c71920..6c4c0395 100644 --- a/swap/src/bob/amounts.rs +++ b/swap/src/bob/amounts.rs @@ -12,7 +12,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing::{debug, error}; +use tracing::error; use crate::{ network::request_response::{AliceToBob, BobToAlice, Codec, Protocol, TIMEOUT}, @@ -83,10 +83,11 @@ impl NetworkBehaviourEventProcess> RequestResponseEvent::Message { message: RequestResponseMessage::Response { response, .. }, .. - } => match response { - AliceToBob::Amounts(p) => self.events.push_back(OutEvent::Amounts(p)), - other => debug!("got response: {:?}", other), - }, + } => { + if let AliceToBob::Amounts(p) = response { + self.events.push_back(OutEvent::Amounts(p)); + } + } RequestResponseEvent::InboundFailure { error, .. } => { error!("Inbound failure: {:?}", error); } diff --git a/swap/src/bob/message0.rs b/swap/src/bob/message0.rs index 268244a1..ff6c9420 100644 --- a/swap/src/bob/message0.rs +++ b/swap/src/bob/message0.rs @@ -11,7 +11,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing::{debug, error}; +use tracing::error; use crate::network::request_response::{AliceToBob, BobToAlice, Codec, Protocol, TIMEOUT}; use xmr_btc::{alice, bob}; @@ -77,10 +77,11 @@ impl NetworkBehaviourEventProcess> RequestResponseEvent::Message { message: RequestResponseMessage::Response { response, .. }, .. - } => match response { - AliceToBob::Message0(msg) => self.events.push_back(OutEvent::Msg(msg)), - other => debug!("got response: {:?}", other), - }, + } => { + if let AliceToBob::Message0(msg) = response { + self.events.push_back(OutEvent::Msg(msg)); + } + } RequestResponseEvent::InboundFailure { error, .. } => { error!("Inbound failure: {:?}", error); } diff --git a/swap/src/bob/message1.rs b/swap/src/bob/message1.rs index 9e85ce3d..0a821ec2 100644 --- a/swap/src/bob/message1.rs +++ b/swap/src/bob/message1.rs @@ -11,7 +11,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing::{debug, error}; +use tracing::error; use crate::network::request_response::{AliceToBob, BobToAlice, Codec, Protocol, TIMEOUT}; use xmr_btc::{alice, bob}; @@ -77,10 +77,11 @@ impl NetworkBehaviourEventProcess> RequestResponseEvent::Message { message: RequestResponseMessage::Response { response, .. }, .. - } => match response { - AliceToBob::Message1(msg) => self.events.push_back(OutEvent::Msg(msg)), - other => debug!("got response: {:?}", other), - }, + } => { + if let AliceToBob::Message1(msg) = response { + self.events.push_back(OutEvent::Msg(msg)); + } + } RequestResponseEvent::InboundFailure { error, .. } => { error!("Inbound failure: {:?}", error); } diff --git a/swap/src/bob/message2.rs b/swap/src/bob/message2.rs index 0898c583..e90755b7 100644 --- a/swap/src/bob/message2.rs +++ b/swap/src/bob/message2.rs @@ -11,7 +11,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tracing::{debug, error}; +use tracing::error; use crate::network::request_response::{AliceToBob, BobToAlice, Codec, Protocol, TIMEOUT}; use xmr_btc::{alice, bob}; @@ -77,10 +77,11 @@ impl NetworkBehaviourEventProcess> RequestResponseEvent::Message { message: RequestResponseMessage::Response { response, .. }, .. - } => match response { - AliceToBob::Message2(msg) => self.events.push_back(OutEvent::Msg(msg)), - other => debug!("unexpected response: {:?}", other), - }, + } => { + if let AliceToBob::Message2(msg) = response { + self.events.push_back(OutEvent::Msg(msg)); + } + } RequestResponseEvent::InboundFailure { error, .. } => { error!("Inbound failure: {:?}", error); } diff --git a/swap/src/bob/message3.rs b/swap/src/bob/message3.rs index b9567e81..53648460 100644 --- a/swap/src/bob/message3.rs +++ b/swap/src/bob/message3.rs @@ -69,10 +69,11 @@ impl NetworkBehaviourEventProcess> RequestResponseEvent::Message { message: RequestResponseMessage::Response { response, .. }, .. - } => match response { - AliceToBob::Message3 => debug!("Alice correctly responded to message 3"), - other => debug!("unexpected response: {:?}", other), - }, + } => { + if let AliceToBob::Message3 = response { + debug!("Alice correctly responded to message 3"); + } + } RequestResponseEvent::InboundFailure { error, .. } => { error!("Inbound failure: {:?}", error); } diff --git a/swap/tests/e2e.rs b/swap/tests/e2e.rs index 07651538..61f6aabd 100644 --- a/swap/tests/e2e.rs +++ b/swap/tests/e2e.rs @@ -57,7 +57,12 @@ async fn swap() { let alice_xmr_wallet = Arc::new(swap::monero::Wallet(monero.alice_wallet_rpc_client())); let bob_xmr_wallet = Arc::new(swap::monero::Wallet(monero.bob_wallet_rpc_client())); - let alice_swap = alice::swap(alice_btc_wallet, alice_xmr_wallet, alice_multiaddr.clone()); + let alice_swap = alice::swap( + alice_btc_wallet, + alice_xmr_wallet, + alice_multiaddr.clone(), + None, + ); let (cmd_tx, mut _cmd_rx) = mpsc::channel(1); let (mut rsp_tx, rsp_rx) = mpsc::channel(1);