mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Do not consider transfer proof sent until it's ack'd
This commit is contained in:
parent
b968c98805
commit
f9f17b0e23
@ -236,7 +236,7 @@ pub enum OutEvent {
|
|||||||
msg: Box<bob::Message2>,
|
msg: Box<bob::Message2>,
|
||||||
bob_peer_id: PeerId,
|
bob_peer_id: PeerId,
|
||||||
},
|
},
|
||||||
TransferProof,
|
TransferProofAcknowledged,
|
||||||
EncryptedSignature(EncryptedSignature),
|
EncryptedSignature(EncryptedSignature),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ impl From<message2::OutEvent> for OutEvent {
|
|||||||
impl From<transfer_proof::OutEvent> for OutEvent {
|
impl From<transfer_proof::OutEvent> for OutEvent {
|
||||||
fn from(event: transfer_proof::OutEvent) -> Self {
|
fn from(event: transfer_proof::OutEvent) -> Self {
|
||||||
match event {
|
match event {
|
||||||
transfer_proof::OutEvent::Msg => OutEvent::TransferProof,
|
transfer_proof::OutEvent::Acknowledged => OutEvent::TransferProofAcknowledged,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ pub struct EventLoopHandle {
|
|||||||
send_message0: Sender<(ResponseChannel<AliceToBob>, alice::Message0)>,
|
send_message0: Sender<(ResponseChannel<AliceToBob>, alice::Message0)>,
|
||||||
send_message1: Sender<(ResponseChannel<AliceToBob>, alice::Message1)>,
|
send_message1: Sender<(ResponseChannel<AliceToBob>, alice::Message1)>,
|
||||||
send_transfer_proof: Sender<(PeerId, TransferProof)>,
|
send_transfer_proof: Sender<(PeerId, TransferProof)>,
|
||||||
|
recv_transfer_proof_ack: Receiver<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventLoopHandle {
|
impl EventLoopHandle {
|
||||||
@ -124,6 +125,11 @@ impl EventLoopHandle {
|
|||||||
|
|
||||||
pub async fn send_transfer_proof(&mut self, bob: PeerId, msg: TransferProof) -> Result<()> {
|
pub async fn send_transfer_proof(&mut self, bob: PeerId, msg: TransferProof) -> Result<()> {
|
||||||
let _ = self.send_transfer_proof.send((bob, msg)).await?;
|
let _ = self.send_transfer_proof.send((bob, msg)).await?;
|
||||||
|
|
||||||
|
self.recv_transfer_proof_ack
|
||||||
|
.recv()
|
||||||
|
.await
|
||||||
|
.ok_or_else(|| anyhow!("Failed to receive transfer proof ack from Bob"))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,6 +147,7 @@ pub struct EventLoop {
|
|||||||
send_message0: Receiver<(ResponseChannel<AliceToBob>, alice::Message0)>,
|
send_message0: Receiver<(ResponseChannel<AliceToBob>, alice::Message0)>,
|
||||||
send_message1: Receiver<(ResponseChannel<AliceToBob>, alice::Message1)>,
|
send_message1: Receiver<(ResponseChannel<AliceToBob>, alice::Message1)>,
|
||||||
send_transfer_proof: Receiver<(PeerId, TransferProof)>,
|
send_transfer_proof: Receiver<(PeerId, TransferProof)>,
|
||||||
|
recv_transfer_proof_ack: Sender<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventLoop {
|
impl EventLoop {
|
||||||
@ -169,6 +176,7 @@ impl EventLoop {
|
|||||||
let send_message0 = Channels::new();
|
let send_message0 = Channels::new();
|
||||||
let send_message1 = Channels::new();
|
let send_message1 = Channels::new();
|
||||||
let send_transfer_proof = Channels::new();
|
let send_transfer_proof = Channels::new();
|
||||||
|
let recv_transfer_proof_ack = Channels::new();
|
||||||
|
|
||||||
let driver = EventLoop {
|
let driver = EventLoop {
|
||||||
swarm,
|
swarm,
|
||||||
@ -182,6 +190,7 @@ impl EventLoop {
|
|||||||
send_message0: send_message0.receiver,
|
send_message0: send_message0.receiver,
|
||||||
send_message1: send_message1.receiver,
|
send_message1: send_message1.receiver,
|
||||||
send_transfer_proof: send_transfer_proof.receiver,
|
send_transfer_proof: send_transfer_proof.receiver,
|
||||||
|
recv_transfer_proof_ack: recv_transfer_proof_ack.sender,
|
||||||
};
|
};
|
||||||
|
|
||||||
let handle = EventLoopHandle {
|
let handle = EventLoopHandle {
|
||||||
@ -195,6 +204,7 @@ impl EventLoop {
|
|||||||
send_message0: send_message0.sender,
|
send_message0: send_message0.sender,
|
||||||
send_message1: send_message1.sender,
|
send_message1: send_message1.sender,
|
||||||
send_transfer_proof: send_transfer_proof.sender,
|
send_transfer_proof: send_transfer_proof.sender,
|
||||||
|
recv_transfer_proof_ack: recv_transfer_proof_ack.receiver,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((driver, handle))
|
Ok((driver, handle))
|
||||||
@ -217,7 +227,10 @@ impl EventLoop {
|
|||||||
OutEvent::Message2 { msg, bob_peer_id : _} => {
|
OutEvent::Message2 { msg, bob_peer_id : _} => {
|
||||||
let _ = self.recv_message2.send(*msg).await;
|
let _ = self.recv_message2.send(*msg).await;
|
||||||
}
|
}
|
||||||
OutEvent::TransferProof => trace!("Bob ack'd receiving the transfer proof"),
|
OutEvent::TransferProofAcknowledged => {
|
||||||
|
trace!("Bob acknowledged transfer proof");
|
||||||
|
let _ = self.recv_transfer_proof_ack.send(()).await;
|
||||||
|
}
|
||||||
OutEvent::EncryptedSignature(msg) => {
|
OutEvent::EncryptedSignature(msg) => {
|
||||||
let _ = self.recv_encrypted_signature.send(msg).await;
|
let _ = self.recv_encrypted_signature.send(msg).await;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ pub struct TransferProof {
|
|||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum OutEvent {
|
pub enum OutEvent {
|
||||||
Msg,
|
Acknowledged,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `NetworkBehaviour` that represents sending the Monero transfer proof to
|
/// A `NetworkBehaviour` that represents sending the Monero transfer proof to
|
||||||
@ -88,7 +88,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<Request, Response>> for B
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
if let Response::TransferProof = response {
|
if let Response::TransferProof = response {
|
||||||
self.events.push_back(OutEvent::Msg);
|
self.events.push_back(OutEvent::Acknowledged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RequestResponseEvent::InboundFailure { error, .. } => {
|
RequestResponseEvent::InboundFailure { error, .. } => {
|
||||||
|
Loading…
Reference in New Issue
Block a user