From 1c644cb3779c5da1db74b9ea6f9dbfe255ece32d Mon Sep 17 00:00:00 2001 From: rishflab Date: Fri, 8 Jan 2021 12:33:23 +1100 Subject: [PATCH] Rename message behaviours --- swap/src/protocol/alice.rs | 19 ++++++++++--------- swap/src/protocol/alice/message0.rs | 10 ++++------ swap/src/protocol/alice/message1.rs | 10 ++++------ swap/src/protocol/alice/message2.rs | 10 ++++------ swap/src/protocol/alice/message3.rs | 10 ++++------ swap/src/protocol/bob.rs | 22 +++++++++++++--------- swap/src/protocol/bob/message0.rs | 10 ++++------ swap/src/protocol/bob/message1.rs | 11 ++++------- swap/src/protocol/bob/message2.rs | 11 ++++------- swap/src/protocol/bob/message3.rs | 10 ++++------ 10 files changed, 55 insertions(+), 68 deletions(-) diff --git a/swap/src/protocol/alice.rs b/swap/src/protocol/alice.rs index af5826bb..2ce70bd3 100644 --- a/swap/src/protocol/alice.rs +++ b/swap/src/protocol/alice.rs @@ -1,6 +1,5 @@ //! Run an XMR/BTC swap in the role of Alice. //! Alice holds XMR and wishes receive BTC. -pub use self::{amounts::*, message0::*, message1::*, message2::*, message3::*, state::*}; use anyhow::Result; use libp2p::{ core::{identity::Keypair, Multiaddr}, @@ -20,6 +19,8 @@ use crate::{ SwapAmounts, }; +pub use self::{amounts::*, message0::Message0, message1::Message1, message2::Message2, state::*}; + mod amounts; pub mod event_loop; mod message0; @@ -135,10 +136,10 @@ impl From for OutEvent { pub struct Behaviour { pt: PeerTracker, amounts: Amounts, - message0: Message0Behaviour, - message1: Message1Behaviour, - message2: Message2Behaviour, - message3: Message3Behaviour, + message0: message0::Behaviour, + message1: message1::Behaviour, + message2: message2::Behaviour, + message3: message3::Behaviour, #[behaviour(ignore)] identity: Keypair, } @@ -185,10 +186,10 @@ impl Default for Behaviour { Self { pt: PeerTracker::default(), amounts: Amounts::default(), - message0: Message0Behaviour::default(), - message1: Message1Behaviour::default(), - message2: Message2Behaviour::default(), - message3: Message3Behaviour::default(), + message0: message0::Behaviour::default(), + message1: message1::Behaviour::default(), + message2: message2::Behaviour::default(), + message3: message3::Behaviour::default(), identity, } } diff --git a/swap/src/protocol/alice/message0.rs b/swap/src/protocol/alice/message0.rs index d9270b3a..76e57c1b 100644 --- a/swap/src/protocol/alice/message0.rs +++ b/swap/src/protocol/alice/message0.rs @@ -43,13 +43,13 @@ pub struct Message0 { #[derive(NetworkBehaviour)] #[behaviour(out_event = "OutEvent", poll_method = "poll")] #[allow(missing_debug_implementations)] -pub struct Message0Behaviour { +pub struct Behaviour { rr: RequestResponse>, #[behaviour(ignore)] events: VecDeque, } -impl Message0Behaviour { +impl Behaviour { pub fn send(&mut self, channel: ResponseChannel, msg: Message0) { let msg = AliceToBob::Message0(Box::new(msg)); self.rr.send_response(channel, msg); @@ -67,7 +67,7 @@ impl Message0Behaviour { } } -impl Default for Message0Behaviour { +impl Default for Behaviour { fn default() -> Self { let timeout = Duration::from_secs(TIMEOUT); let mut config = RequestResponseConfig::default(); @@ -84,9 +84,7 @@ impl Default for Message0Behaviour { } } -impl NetworkBehaviourEventProcess> - for Message0Behaviour -{ +impl NetworkBehaviourEventProcess> for Behaviour { fn inject_event(&mut self, event: RequestResponseEvent) { match event { RequestResponseEvent::Message { diff --git a/swap/src/protocol/alice/message1.rs b/swap/src/protocol/alice/message1.rs index 94ff9be1..c04faa9a 100644 --- a/swap/src/protocol/alice/message1.rs +++ b/swap/src/protocol/alice/message1.rs @@ -40,13 +40,13 @@ pub struct Message1 { #[derive(NetworkBehaviour)] #[behaviour(out_event = "OutEvent", poll_method = "poll")] #[allow(missing_debug_implementations)] -pub struct Message1Behaviour { +pub struct Behaviour { rr: RequestResponse>, #[behaviour(ignore)] events: VecDeque, } -impl Message1Behaviour { +impl Behaviour { pub fn send(&mut self, channel: ResponseChannel, msg: Message1) { let msg = AliceToBob::Message1(Box::new(msg)); self.rr.send_response(channel, msg); @@ -65,7 +65,7 @@ impl Message1Behaviour { } } -impl Default for Message1Behaviour { +impl Default for Behaviour { fn default() -> Self { let timeout = Duration::from_secs(TIMEOUT); let mut config = RequestResponseConfig::default(); @@ -82,9 +82,7 @@ impl Default for Message1Behaviour { } } -impl NetworkBehaviourEventProcess> - for Message1Behaviour -{ +impl NetworkBehaviourEventProcess> for Behaviour { fn inject_event(&mut self, event: RequestResponseEvent) { match event { RequestResponseEvent::Message { diff --git a/swap/src/protocol/alice/message2.rs b/swap/src/protocol/alice/message2.rs index 27e7f965..9b92758e 100644 --- a/swap/src/protocol/alice/message2.rs +++ b/swap/src/protocol/alice/message2.rs @@ -39,13 +39,13 @@ pub struct Message2 { #[derive(NetworkBehaviour)] #[behaviour(out_event = "OutEvent", poll_method = "poll")] #[allow(missing_debug_implementations)] -pub struct Message2Behaviour { +pub struct Behaviour { rr: RequestResponse>, #[behaviour(ignore)] events: VecDeque, } -impl Message2Behaviour { +impl Behaviour { pub fn send(&mut self, channel: ResponseChannel, msg: Message2) { let msg = AliceToBob::Message2(msg); self.rr.send_response(channel, msg); @@ -64,7 +64,7 @@ impl Message2Behaviour { } } -impl Default for Message2Behaviour { +impl Default for Behaviour { fn default() -> Self { let timeout = Duration::from_secs(TIMEOUT); let mut config = RequestResponseConfig::default(); @@ -81,9 +81,7 @@ impl Default for Message2Behaviour { } } -impl NetworkBehaviourEventProcess> - for Message2Behaviour -{ +impl NetworkBehaviourEventProcess> for Behaviour { fn inject_event(&mut self, event: RequestResponseEvent) { match event { RequestResponseEvent::Message { diff --git a/swap/src/protocol/alice/message3.rs b/swap/src/protocol/alice/message3.rs index cf859685..d5f6b563 100644 --- a/swap/src/protocol/alice/message3.rs +++ b/swap/src/protocol/alice/message3.rs @@ -27,13 +27,13 @@ pub enum OutEvent { #[derive(NetworkBehaviour)] #[behaviour(out_event = "OutEvent", poll_method = "poll")] #[allow(missing_debug_implementations)] -pub struct Message3Behaviour { +pub struct Behaviour { rr: RequestResponse>, #[behaviour(ignore)] events: VecDeque, } -impl Message3Behaviour { +impl Behaviour { fn poll( &mut self, _: &mut Context<'_>, @@ -47,7 +47,7 @@ impl Message3Behaviour { } } -impl Default for Message3Behaviour { +impl Default for Behaviour { fn default() -> Self { let timeout = Duration::from_secs(TIMEOUT); let mut config = RequestResponseConfig::default(); @@ -64,9 +64,7 @@ impl Default for Message3Behaviour { } } -impl NetworkBehaviourEventProcess> - for Message3Behaviour -{ +impl NetworkBehaviourEventProcess> for Behaviour { fn inject_event(&mut self, event: RequestResponseEvent) { match event { RequestResponseEvent::Message { diff --git a/swap/src/protocol/bob.rs b/swap/src/protocol/bob.rs index 9ba62485..28789d12 100644 --- a/swap/src/protocol/bob.rs +++ b/swap/src/protocol/bob.rs @@ -1,6 +1,5 @@ //! Run an XMR/BTC swap in the role of Bob. //! Bob holds BTC and wishes receive XMR. -pub use self::{amounts::*, message0::*, message1::*, message2::*, message3::*, state::*}; use anyhow::Result; use libp2p::{ core::{identity::Keypair, Multiaddr}, @@ -19,6 +18,11 @@ use crate::{ SwapAmounts, }; +pub use self::{ + amounts::*, message0::Message0, message1::Message1, message2::Message2, message3::Message3, + state::*, +}; + mod amounts; pub mod event_loop; mod message0; @@ -111,10 +115,10 @@ impl From for OutEvent { pub struct Behaviour { pt: PeerTracker, amounts: Amounts, - message0: Message0Behaviour, - message1: Message1Behaviour, - message2: Message2Behaviour, - message3: Message3Behaviour, + message0: message0::Behaviour, + message1: message1::Behaviour, + message2: message2::Behaviour, + message3: message3::Behaviour, #[behaviour(ignore)] identity: Keypair, } @@ -173,10 +177,10 @@ impl Default for Behaviour { Self { pt: PeerTracker::default(), amounts: Amounts::default(), - message0: Message0Behaviour::default(), - message1: Message1Behaviour::default(), - message2: Message2Behaviour::default(), - message3: Message3Behaviour::default(), + message0: message0::Behaviour::default(), + message1: message1::Behaviour::default(), + message2: message2::Behaviour::default(), + message3: message3::Behaviour::default(), identity, } } diff --git a/swap/src/protocol/bob/message0.rs b/swap/src/protocol/bob/message0.rs index 5bbfd3b2..d1b2a57a 100644 --- a/swap/src/protocol/bob/message0.rs +++ b/swap/src/protocol/bob/message0.rs @@ -39,13 +39,13 @@ pub enum OutEvent { #[derive(NetworkBehaviour)] #[behaviour(out_event = "OutEvent", poll_method = "poll")] #[allow(missing_debug_implementations)] -pub struct Message0Behaviour { +pub struct Behaviour { rr: RequestResponse>, #[behaviour(ignore)] events: VecDeque, } -impl Message0Behaviour { +impl Behaviour { pub fn send(&mut self, alice: PeerId, msg: bob::Message0) { let msg = BobToAlice::Message0(Box::new(msg)); let _id = self.rr.send_request(&alice, msg); @@ -64,7 +64,7 @@ impl Message0Behaviour { } } -impl Default for Message0Behaviour { +impl Default for Behaviour { fn default() -> Self { let timeout = Duration::from_secs(TIMEOUT); let mut config = RequestResponseConfig::default(); @@ -81,9 +81,7 @@ impl Default for Message0Behaviour { } } -impl NetworkBehaviourEventProcess> - for Message0Behaviour -{ +impl NetworkBehaviourEventProcess> for Behaviour { fn inject_event(&mut self, event: RequestResponseEvent) { match event { RequestResponseEvent::Message { diff --git a/swap/src/protocol/bob/message1.rs b/swap/src/protocol/bob/message1.rs index 1701d03b..fbae5ace 100644 --- a/swap/src/protocol/bob/message1.rs +++ b/swap/src/protocol/bob/message1.rs @@ -12,7 +12,6 @@ use std::{ task::{Context, Poll}, time::Duration, }; - use tracing::{debug, error}; use crate::{ @@ -35,13 +34,13 @@ pub enum OutEvent { #[derive(NetworkBehaviour)] #[behaviour(out_event = "OutEvent", poll_method = "poll")] #[allow(missing_debug_implementations)] -pub struct Message1Behaviour { +pub struct Behaviour { rr: RequestResponse>, #[behaviour(ignore)] events: VecDeque, } -impl Message1Behaviour { +impl Behaviour { pub fn send(&mut self, alice: PeerId, msg: Message1) { let msg = BobToAlice::Message1(msg); let _id = self.rr.send_request(&alice, msg); @@ -60,7 +59,7 @@ impl Message1Behaviour { } } -impl Default for Message1Behaviour { +impl Default for Behaviour { fn default() -> Self { let timeout = Duration::from_secs(TIMEOUT); let mut config = RequestResponseConfig::default(); @@ -77,9 +76,7 @@ impl Default for Message1Behaviour { } } -impl NetworkBehaviourEventProcess> - for Message1Behaviour -{ +impl NetworkBehaviourEventProcess> for Behaviour { fn inject_event(&mut self, event: RequestResponseEvent) { match event { RequestResponseEvent::Message { diff --git a/swap/src/protocol/bob/message2.rs b/swap/src/protocol/bob/message2.rs index 11f0acb1..62c55147 100644 --- a/swap/src/protocol/bob/message2.rs +++ b/swap/src/protocol/bob/message2.rs @@ -13,7 +13,6 @@ use std::{ task::{Context, Poll}, time::Duration, }; - use tracing::{debug, error}; use crate::{ @@ -36,13 +35,13 @@ pub enum OutEvent { #[derive(NetworkBehaviour)] #[behaviour(out_event = "OutEvent", poll_method = "poll")] #[allow(missing_debug_implementations)] -pub struct Message2Behaviour { +pub struct Behaviour { rr: RequestResponse>, #[behaviour(ignore)] events: VecDeque, } -impl Message2Behaviour { +impl Behaviour { pub fn send(&mut self, alice: PeerId, msg: Message2) { let msg = BobToAlice::Message2(msg); let _id = self.rr.send_request(&alice, msg); @@ -61,7 +60,7 @@ impl Message2Behaviour { } } -impl Default for Message2Behaviour { +impl Default for Behaviour { fn default() -> Self { let timeout = Duration::from_secs(TIMEOUT); let mut config = RequestResponseConfig::default(); @@ -78,9 +77,7 @@ impl Default for Message2Behaviour { } } -impl NetworkBehaviourEventProcess> - for Message2Behaviour -{ +impl NetworkBehaviourEventProcess> for Behaviour { fn inject_event(&mut self, event: RequestResponseEvent) { match event { RequestResponseEvent::Message { diff --git a/swap/src/protocol/bob/message3.rs b/swap/src/protocol/bob/message3.rs index 9c9ed4fd..7c9e2df6 100644 --- a/swap/src/protocol/bob/message3.rs +++ b/swap/src/protocol/bob/message3.rs @@ -33,13 +33,13 @@ pub enum OutEvent { #[derive(NetworkBehaviour)] #[behaviour(out_event = "OutEvent", poll_method = "poll")] #[allow(missing_debug_implementations)] -pub struct Message3Behaviour { +pub struct Behaviour { rr: RequestResponse>, #[behaviour(ignore)] events: VecDeque, } -impl Message3Behaviour { +impl Behaviour { pub fn send(&mut self, alice: PeerId, msg: Message3) { let msg = BobToAlice::Message3(msg); let _id = self.rr.send_request(&alice, msg); @@ -58,7 +58,7 @@ impl Message3Behaviour { } } -impl Default for Message3Behaviour { +impl Default for Behaviour { fn default() -> Self { let timeout = Duration::from_secs(TIMEOUT); let mut config = RequestResponseConfig::default(); @@ -75,9 +75,7 @@ impl Default for Message3Behaviour { } } -impl NetworkBehaviourEventProcess> - for Message3Behaviour -{ +impl NetworkBehaviourEventProcess> for Behaviour { fn inject_event(&mut self, event: RequestResponseEvent) { match event { RequestResponseEvent::Message {