diff --git a/swap/src/network/request_response.rs b/swap/src/network/request_response.rs index 1fd46224..3d9c5b9d 100644 --- a/swap/src/network/request_response.rs +++ b/swap/src/network/request_response.rs @@ -1,4 +1,4 @@ -use crate::protocol::{alice, bob}; +use crate::protocol::{alice, bob, bob::Message5}; use async_trait::async_trait; use futures::prelude::*; use libp2p::{ @@ -25,7 +25,7 @@ pub enum BobToAlice { Message0(Box), Message1(bob::Message1), Message2(bob::Message2), - Message3(bob::Message3), + Message5(Message5), } /// Messages Alice sends to Bob. @@ -35,7 +35,7 @@ pub enum AliceToBob { Message0(Box), Message1(Box), Message2(alice::Message2), - Message3, // empty response + Message5, // empty response } #[derive(Debug, Clone, Copy, Default)] @@ -51,7 +51,7 @@ pub struct Message1Protocol; pub struct Message2Protocol; #[derive(Debug, Clone, Copy, Default)] -pub struct Message3Protocol; +pub struct Message5Protocol; impl ProtocolName for Swap { fn protocol_name(&self) -> &[u8] { @@ -77,9 +77,9 @@ impl ProtocolName for Message2Protocol { } } -impl ProtocolName for Message3Protocol { +impl ProtocolName for Message5Protocol { fn protocol_name(&self) -> &[u8] { - b"/xmr/btc/message3/1.0.0" + b"/xmr/btc/message5/1.0.0" } } diff --git a/swap/src/protocol/alice.rs b/swap/src/protocol/alice.rs index 51c7134b..a640b854 100644 --- a/swap/src/protocol/alice.rs +++ b/swap/src/protocol/alice.rs @@ -21,7 +21,7 @@ use crate::{ transport::build, Seed as NetworkSeed, }, - protocol::{bob, SwapAmounts}, + protocol::{bob, bob::Message5, SwapAmounts}, seed::Seed, }; use anyhow::{bail, Result}; @@ -37,7 +37,7 @@ pub mod event_loop; mod message0; mod message1; mod message2; -mod message3; +mod message5; pub mod state; mod steps; pub mod swap; @@ -235,7 +235,7 @@ pub enum OutEvent { msg: bob::Message2, channel: ResponseChannel, }, - Message3(bob::Message3), + Message5(Message5), } impl From for OutEvent { @@ -281,10 +281,10 @@ impl From for OutEvent { } } -impl From for OutEvent { - fn from(event: message3::OutEvent) -> Self { +impl From for OutEvent { + fn from(event: message5::OutEvent) -> Self { match event { - message3::OutEvent::Msg(msg) => OutEvent::Message3(msg), + message5::OutEvent::Msg(msg) => OutEvent::Message5(msg), } } } @@ -299,7 +299,7 @@ pub struct Behaviour { message0: message0::Behaviour, message1: message1::Behaviour, message2: message2::Behaviour, - message3: message3::Behaviour, + message5: message5::Behaviour, } impl Behaviour { diff --git a/swap/src/protocol/alice/event_loop.rs b/swap/src/protocol/alice/event_loop.rs index a648d1a6..bdd626bf 100644 --- a/swap/src/protocol/alice/event_loop.rs +++ b/swap/src/protocol/alice/event_loop.rs @@ -4,6 +4,7 @@ use crate::{ alice, alice::{Behaviour, OutEvent, SwapResponse}, bob, + bob::Message5, }, }; use anyhow::{anyhow, Context, Result}; @@ -37,7 +38,7 @@ pub struct EventLoopHandle { msg0: Receiver<(bob::Message0, ResponseChannel)>, msg1: Receiver<(bob::Message1, ResponseChannel)>, msg2: Receiver<(bob::Message2, ResponseChannel)>, - msg3: Receiver, + msg5: Receiver, request: Receiver, conn_established: Receiver, send_swap_response: Sender<(ResponseChannel, SwapResponse)>, @@ -75,8 +76,8 @@ impl EventLoopHandle { .ok_or_else(|| anyhow!("Failed o receive message 2 from Bob")) } - pub async fn recv_message3(&mut self) -> Result { - self.msg3 + pub async fn recv_message5(&mut self) -> Result { + self.msg5 .recv() .await .ok_or_else(|| anyhow!("Failed to receive Bitcoin encrypted signature from Bob")) @@ -137,7 +138,7 @@ pub struct EventLoop { msg0: Sender<(bob::Message0, ResponseChannel)>, msg1: Sender<(bob::Message1, ResponseChannel)>, msg2: Sender<(bob::Message2, ResponseChannel)>, - msg3: Sender, + msg5: Sender, request: Sender, conn_established: Sender, send_swap_response: Receiver<(ResponseChannel, SwapResponse)>, @@ -165,7 +166,7 @@ impl EventLoop { let msg0 = Channels::new(); let msg1 = Channels::new(); let msg2 = Channels::new(); - let msg3 = Channels::new(); + let msg5 = Channels::new(); let request = Channels::new(); let conn_established = Channels::new(); let send_swap_response = Channels::new(); @@ -178,7 +179,7 @@ impl EventLoop { msg0: msg0.sender, msg1: msg1.sender, msg2: msg2.sender, - msg3: msg3.sender, + msg5: msg5.sender, request: request.sender, conn_established: conn_established.sender, send_swap_response: send_swap_response.receiver, @@ -191,7 +192,7 @@ impl EventLoop { msg0: msg0.receiver, msg1: msg1.receiver, msg2: msg2.receiver, - msg3: msg3.receiver, + msg5: msg5.receiver, request: request.receiver, conn_established: conn_established.receiver, send_swap_response: send_swap_response.sender, @@ -220,8 +221,8 @@ impl EventLoop { OutEvent::Message2 { msg, channel } => { let _ = self.msg2.send((msg, channel)).await; } - OutEvent::Message3(msg) => { - let _ = self.msg3.send(msg).await; + OutEvent::Message5(msg) => { + let _ = self.msg5.send(msg).await; } OutEvent::Request(event) => { let _ = self.request.send(*event).await; diff --git a/swap/src/protocol/alice/message3.rs b/swap/src/protocol/alice/message5.rs similarity index 86% rename from swap/src/protocol/alice/message3.rs rename to swap/src/protocol/alice/message5.rs index 9c85cc96..fd6d40d4 100644 --- a/swap/src/protocol/alice/message3.rs +++ b/swap/src/protocol/alice/message5.rs @@ -1,6 +1,6 @@ use crate::{ - network::request_response::{AliceToBob, BobToAlice, Codec, Message3Protocol, TIMEOUT}, - protocol::bob, + network::request_response::{AliceToBob, BobToAlice, Codec, Message5Protocol, TIMEOUT}, + protocol::bob::Message5, }; use libp2p::{ request_response::{ @@ -19,15 +19,15 @@ use tracing::{debug, error}; #[derive(Debug)] pub enum OutEvent { - Msg(bob::Message3), + Msg(Message5), } -/// A `NetworkBehaviour` that represents receiving of message 3 from Bob. +/// A `NetworkBehaviour` that represents receiving of message 5 from Bob. #[derive(NetworkBehaviour)] #[behaviour(out_event = "OutEvent", poll_method = "poll")] #[allow(missing_debug_implementations)] pub struct Behaviour { - rr: RequestResponse>, + rr: RequestResponse>, #[behaviour(ignore)] events: VecDeque, } @@ -37,7 +37,7 @@ impl Behaviour { &mut self, _: &mut Context<'_>, _: &mut impl PollParameters, - ) -> Poll>, OutEvent>> { + ) -> Poll>, OutEvent>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event)); } @@ -55,7 +55,7 @@ impl Default for Behaviour { Self { rr: RequestResponse::new( Codec::default(), - vec![(Message3Protocol, ProtocolSupport::Full)], + vec![(Message5Protocol, ProtocolSupport::Full)], config, ), events: Default::default(), @@ -73,11 +73,11 @@ impl NetworkBehaviourEventProcess> }, .. } => { - if let BobToAlice::Message3(msg) = request { - debug!("Received Message3"); + if let BobToAlice::Message5(msg) = request { + debug!("Received message 5"); 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); + self.rr.send_response(channel, AliceToBob::Message5); } } RequestResponseEvent::Message { diff --git a/swap/src/protocol/alice/state.rs b/swap/src/protocol/alice/state.rs index e838568f..118a3791 100644 --- a/swap/src/protocol/alice/state.rs +++ b/swap/src/protocol/alice/state.rs @@ -9,7 +9,7 @@ use crate::{ monero, monero::CreateWalletForOutput, network::request_response::AliceToBob, - protocol::{alice, bob, SwapAmounts}, + protocol::{alice, bob, bob::Message5, SwapAmounts}, }; use anyhow::{anyhow, Context, Result}; use ecdsa_fun::{ @@ -482,7 +482,7 @@ impl State5 { } } - pub fn receive(self, msg: bob::Message3) -> State6 { + pub fn receive(self, msg: Message5) -> State6 { State6 { a: self.a, B: self.B, diff --git a/swap/src/protocol/alice/steps.rs b/swap/src/protocol/alice/steps.rs index d6be5ae8..c2a89415 100644 --- a/swap/src/protocol/alice/steps.rs +++ b/swap/src/protocol/alice/steps.rs @@ -146,7 +146,7 @@ pub async fn wait_for_bitcoin_encrypted_signature( event_loop_handle: &mut EventLoopHandle, ) -> Result { let msg3 = event_loop_handle - .recv_message3() + .recv_message5() .await .context("Failed to receive Bitcoin encrypted signature from Bob")?; diff --git a/swap/src/protocol/bob.rs b/swap/src/protocol/bob.rs index 20e8d2a2..7431209e 100644 --- a/swap/src/protocol/bob.rs +++ b/swap/src/protocol/bob.rs @@ -26,7 +26,7 @@ pub use self::{ message0::Message0, message1::Message1, message2::Message2, - message3::Message3, + message5::Message5, state::*, swap::{run, run_until}, swap_request::*, @@ -36,7 +36,7 @@ pub mod event_loop; mod message0; mod message1; mod message2; -mod message3; +mod message5; pub mod state; pub mod swap; mod swap_request; @@ -211,7 +211,7 @@ pub enum OutEvent { Message0(Box), Message1(Box), Message2(alice::Message2), - Message3, + Message5, } impl From for OutEvent { @@ -254,10 +254,10 @@ impl From for OutEvent { } } -impl From for OutEvent { - fn from(event: message3::OutEvent) -> Self { +impl From for OutEvent { + fn from(event: message5::OutEvent) -> Self { match event { - message3::OutEvent::Msg => OutEvent::Message3, + message5::OutEvent::Msg => OutEvent::Message5, } } } @@ -272,7 +272,7 @@ pub struct Behaviour { message0: message0::Behaviour, message1: message1::Behaviour, message2: message2::Behaviour, - message3: message3::Behaviour, + message5: message5::Behaviour, } impl Behaviour { @@ -302,8 +302,8 @@ impl Behaviour { /// Sends Bob's fourth message to Alice. pub fn send_message3(&mut self, alice: PeerId, tx_redeem_encsig: EncryptedSignature) { - let msg = bob::Message3 { tx_redeem_encsig }; - self.message3.send(alice, msg); + let msg = Message5 { tx_redeem_encsig }; + self.message5.send(alice, msg); debug!("Sent Message3"); } diff --git a/swap/src/protocol/bob/event_loop.rs b/swap/src/protocol/bob/event_loop.rs index 99130973..45cbac17 100644 --- a/swap/src/protocol/bob/event_loop.rs +++ b/swap/src/protocol/bob/event_loop.rs @@ -217,7 +217,7 @@ impl EventLoop { OutEvent::Message2(msg) => { let _ = self.msg2.send(msg).await; } - OutEvent::Message3 => info!("Alice acknowledged message 3 received"), + OutEvent::Message5 => info!("Alice acknowledged message 5 received"), } }, option = self.dial_alice.next().fuse() => { diff --git a/swap/src/protocol/bob/message3.rs b/swap/src/protocol/bob/message5.rs similarity index 86% rename from swap/src/protocol/bob/message3.rs rename to swap/src/protocol/bob/message5.rs index f9703ad1..801e6532 100644 --- a/swap/src/protocol/bob/message3.rs +++ b/swap/src/protocol/bob/message5.rs @@ -1,6 +1,6 @@ use crate::{ bitcoin::EncryptedSignature, - network::request_response::{AliceToBob, BobToAlice, Codec, Message3Protocol, TIMEOUT}, + network::request_response::{AliceToBob, BobToAlice, Codec, Message5Protocol, TIMEOUT}, }; use libp2p::{ request_response::{ @@ -19,7 +19,7 @@ use std::{ use tracing::error; #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Message3 { +pub struct Message5 { pub tx_redeem_encsig: EncryptedSignature, } @@ -28,19 +28,19 @@ pub enum OutEvent { Msg, } -/// A `NetworkBehaviour` that represents sending message 3 to Alice. +/// A `NetworkBehaviour` that represents sending message 5 to Alice. #[derive(NetworkBehaviour)] #[behaviour(out_event = "OutEvent", poll_method = "poll")] #[allow(missing_debug_implementations)] pub struct Behaviour { - rr: RequestResponse>, + rr: RequestResponse>, #[behaviour(ignore)] events: VecDeque, } impl Behaviour { - pub fn send(&mut self, alice: PeerId, msg: Message3) { - let msg = BobToAlice::Message3(msg); + pub fn send(&mut self, alice: PeerId, msg: Message5) { + let msg = BobToAlice::Message5(msg); let _id = self.rr.send_request(&alice, msg); } @@ -48,7 +48,7 @@ impl Behaviour { &mut self, _: &mut Context<'_>, _: &mut impl PollParameters, - ) -> Poll>, OutEvent>> { + ) -> Poll>, OutEvent>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event)); } @@ -66,7 +66,7 @@ impl Default for Behaviour { Self { rr: RequestResponse::new( Codec::default(), - vec![(Message3Protocol, ProtocolSupport::Full)], + vec![(Message5Protocol, ProtocolSupport::Full)], config, ), events: Default::default(), @@ -85,7 +85,7 @@ impl NetworkBehaviourEventProcess> message: RequestResponseMessage::Response { response, .. }, .. } => { - if let AliceToBob::Message3 = response { + if let AliceToBob::Message5 = response { self.events.push_back(OutEvent::Msg); } } diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index f06cfd17..0498e81e 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -9,7 +9,7 @@ use crate::{ config::Config, monero, monero::{monero_private_key, TransferProof}, - protocol::{alice, bob, SwapAmounts}, + protocol::{alice, bob, bob::Message5, SwapAmounts}, }; use anyhow::{anyhow, Result}; use ecdsa_fun::{ @@ -438,11 +438,11 @@ pub struct State4 { } impl State4 { - pub fn next_message(&self) -> bob::Message3 { + pub fn next_message(&self) -> Message5 { let tx_redeem = bitcoin::TxRedeem::new(&self.tx_lock, &self.redeem_address); let tx_redeem_encsig = self.b.encsign(self.S_a_bitcoin, tx_redeem.digest()); - bob::Message3 { tx_redeem_encsig } + Message5 { tx_redeem_encsig } } pub fn tx_redeem_encsig(&self) -> EncryptedSignature {