Do not consider encrypted signature sent until it's ack'd

This commit is contained in:
Franck Royer 2021-01-29 15:13:40 +11:00
parent 5af3532cbf
commit cc76b201b5
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
4 changed files with 20 additions and 7 deletions

View File

@ -84,7 +84,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<Request, Response>> for B
// Send back empty response so that the request/response protocol completes. // Send back empty response so that the request/response protocol completes.
if let Err(error) = self.rr.send_response(channel, Response::EncryptedSignature) if let Err(error) = self.rr.send_response(channel, Response::EncryptedSignature)
{ {
error!("Failed to sen Encrypted Signature ack: {:?}", error); error!("Failed to send Encrypted Signature ack: {:?}", error);
} }
} }
} }

View File

@ -213,7 +213,7 @@ pub enum OutEvent {
Message1(Box<alice::Message1>), Message1(Box<alice::Message1>),
Message2, Message2,
TransferProof(Box<TransferProof>), TransferProof(Box<TransferProof>),
EncryptedSignature, EncryptedSignatureAcknowledged,
} }
impl From<peer_tracker::OutEvent> for OutEvent { impl From<peer_tracker::OutEvent> for OutEvent {
@ -267,7 +267,7 @@ impl From<transfer_proof::OutEvent> for OutEvent {
impl From<encrypted_signature::OutEvent> for OutEvent { impl From<encrypted_signature::OutEvent> for OutEvent {
fn from(event: encrypted_signature::OutEvent) -> Self { fn from(event: encrypted_signature::OutEvent) -> Self {
match event { match event {
encrypted_signature::OutEvent::Msg => OutEvent::EncryptedSignature, encrypted_signature::OutEvent::Acknowledged => OutEvent::EncryptedSignatureAcknowledged,
} }
} }
} }

View File

@ -24,7 +24,7 @@ pub struct EncryptedSignature {
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum OutEvent { pub enum OutEvent {
Msg, Acknowledged,
} }
/// A `NetworkBehaviour` that represents sending encrypted signature to Alice. /// A `NetworkBehaviour` that represents sending encrypted signature to Alice.
@ -87,7 +87,7 @@ impl NetworkBehaviourEventProcess<RequestResponseEvent<Request, Response>> for B
.. ..
} => { } => {
if let Response::EncryptedSignature = response { if let Response::EncryptedSignature = response {
self.events.push_back(OutEvent::Msg); self.events.push_back(OutEvent::Acknowledged);
} }
} }
RequestResponseEvent::InboundFailure { error, .. } => { RequestResponseEvent::InboundFailure { error, .. } => {

View File

@ -45,6 +45,7 @@ pub struct EventLoopHandle {
send_message1: Sender<bob::Message1>, send_message1: Sender<bob::Message1>,
send_message2: Sender<bob::Message2>, send_message2: Sender<bob::Message2>,
send_encrypted_signature: Sender<EncryptedSignature>, send_encrypted_signature: Sender<EncryptedSignature>,
recv_encrypted_signature_ack: Receiver<()>,
} }
impl EventLoopHandle { impl EventLoopHandle {
@ -114,7 +115,12 @@ impl EventLoopHandle {
&mut self, &mut self,
tx_redeem_encsig: EncryptedSignature, tx_redeem_encsig: EncryptedSignature,
) -> Result<()> { ) -> Result<()> {
let _ = self.send_encrypted_signature.send(tx_redeem_encsig).await?; self.send_encrypted_signature.send(tx_redeem_encsig).await?;
self.recv_encrypted_signature_ack
.recv()
.await
.ok_or_else(|| anyhow!("Failed to receive encrypted signature ack from Alice"))?;
Ok(()) Ok(())
} }
} }
@ -134,6 +140,7 @@ pub struct EventLoop {
send_message1: Receiver<bob::Message1>, send_message1: Receiver<bob::Message1>,
send_message2: Receiver<bob::Message2>, send_message2: Receiver<bob::Message2>,
send_encrypted_signature: Receiver<EncryptedSignature>, send_encrypted_signature: Receiver<EncryptedSignature>,
recv_encrypted_signature_ack: Sender<()>,
} }
impl EventLoop { impl EventLoop {
@ -163,6 +170,7 @@ impl EventLoop {
let send_message1 = Channels::new(); let send_message1 = Channels::new();
let send_message2 = Channels::new(); let send_message2 = Channels::new();
let send_encrypted_signature = Channels::new(); let send_encrypted_signature = Channels::new();
let recv_encrypted_signature_ack = Channels::new();
let event_loop = EventLoop { let event_loop = EventLoop {
swarm, swarm,
@ -178,6 +186,7 @@ impl EventLoop {
send_message1: send_message1.receiver, send_message1: send_message1.receiver,
send_message2: send_message2.receiver, send_message2: send_message2.receiver,
send_encrypted_signature: send_encrypted_signature.receiver, send_encrypted_signature: send_encrypted_signature.receiver,
recv_encrypted_signature_ack: recv_encrypted_signature_ack.sender,
}; };
let handle = EventLoopHandle { let handle = EventLoopHandle {
@ -192,6 +201,7 @@ impl EventLoop {
send_message1: send_message1.sender, send_message1: send_message1.sender,
send_message2: send_message2.sender, send_message2: send_message2.sender,
send_encrypted_signature: send_encrypted_signature.sender, send_encrypted_signature: send_encrypted_signature.sender,
recv_encrypted_signature_ack: recv_encrypted_signature_ack.receiver,
}; };
Ok((event_loop, handle)) Ok((event_loop, handle))
@ -218,7 +228,10 @@ impl EventLoop {
OutEvent::TransferProof(msg) => { OutEvent::TransferProof(msg) => {
let _ = self.recv_transfer_proof.send(*msg).await; let _ = self.recv_transfer_proof.send(*msg).await;
} }
OutEvent::EncryptedSignature => info!("Alice acknowledged encrypted signature received"), OutEvent::EncryptedSignatureAcknowledged => {
debug!("Alice acknowledged encrypted signature");
let _ = self.recv_encrypted_signature_ack.send(()).await;
}
} }
}, },
option = self.dial_alice.recv().fuse() => { option = self.dial_alice.recv().fuse() => {