mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-09 23:12:40 -04:00
Merge #321
321: Properly handle concurrent messages to and from peers r=thomaseizinger a=thomaseizinger Previously, we were forwarding incoming messages from peers to all swaps that were currently running. That is obviously wrong. The new design scopes an `EventLoopHandle` to a specific PeerId to avoid this problem. Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
This commit is contained in:
commit
2c385ee7d9
11 changed files with 181 additions and 223 deletions
|
@ -28,13 +28,17 @@ pub enum OutEvent {
|
|||
bob_peer_id: PeerId,
|
||||
state3: Box<State3>,
|
||||
},
|
||||
TransferProofAcknowledged,
|
||||
TransferProofAcknowledged(PeerId),
|
||||
EncryptedSignature {
|
||||
msg: Box<EncryptedSignature>,
|
||||
channel: ResponseChannel<()>,
|
||||
peer: PeerId,
|
||||
},
|
||||
ResponseSent, // Same variant is used for all messages as no processing is done
|
||||
Failure(Error),
|
||||
Failure {
|
||||
peer: PeerId,
|
||||
error: Error,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<peer_tracker::OutEvent> for OutEvent {
|
||||
|
@ -61,23 +65,20 @@ impl From<spot_price::OutEvent> for OutEvent {
|
|||
} => OutEvent::SpotPriceRequested { msg, channel, peer },
|
||||
spot_price::OutEvent::Message {
|
||||
message: RequestResponseMessage::Response { .. },
|
||||
..
|
||||
} => OutEvent::Failure(anyhow!(
|
||||
"Alice is only meant to hand out spot prices, not receive them"
|
||||
)),
|
||||
spot_price::OutEvent::ResponseSent { .. } => OutEvent::ResponseSent,
|
||||
spot_price::OutEvent::InboundFailure { peer, error, .. } => OutEvent::Failure(anyhow!(
|
||||
"spot_price protocol with peer {} failed due to {:?}",
|
||||
peer,
|
||||
error
|
||||
)),
|
||||
spot_price::OutEvent::OutboundFailure { peer, error, .. } => {
|
||||
OutEvent::Failure(anyhow!(
|
||||
"spot_price protocol with peer {} failed due to {:?}",
|
||||
peer,
|
||||
error
|
||||
))
|
||||
}
|
||||
} => OutEvent::Failure {
|
||||
error: anyhow!("Alice is only meant to hand out spot prices, not receive them"),
|
||||
peer,
|
||||
},
|
||||
spot_price::OutEvent::ResponseSent { .. } => OutEvent::ResponseSent,
|
||||
spot_price::OutEvent::InboundFailure { peer, error, .. } => OutEvent::Failure {
|
||||
error: anyhow!("spot_price protocol failed due to {:?}", error),
|
||||
peer,
|
||||
},
|
||||
spot_price::OutEvent::OutboundFailure { peer, error, .. } => OutEvent::Failure {
|
||||
error: anyhow!("spot_price protocol failed due to {:?}", error),
|
||||
peer,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,21 +92,20 @@ impl From<quote::OutEvent> for OutEvent {
|
|||
} => OutEvent::QuoteRequested { channel, peer },
|
||||
quote::OutEvent::Message {
|
||||
message: RequestResponseMessage::Response { .. },
|
||||
..
|
||||
} => OutEvent::Failure(anyhow!(
|
||||
"Alice is only meant to hand out quotes, not receive them"
|
||||
)),
|
||||
peer,
|
||||
} => OutEvent::Failure {
|
||||
error: anyhow!("Alice is only meant to hand out quotes, not receive them"),
|
||||
peer,
|
||||
},
|
||||
quote::OutEvent::ResponseSent { .. } => OutEvent::ResponseSent,
|
||||
quote::OutEvent::InboundFailure { peer, error, .. } => OutEvent::Failure(anyhow!(
|
||||
"quote protocol with peer {} failed due to {:?}",
|
||||
quote::OutEvent::InboundFailure { peer, error, .. } => OutEvent::Failure {
|
||||
error: anyhow!("quote protocol failed due to {:?}", error),
|
||||
peer,
|
||||
error
|
||||
)),
|
||||
quote::OutEvent::OutboundFailure { peer, error, .. } => OutEvent::Failure(anyhow!(
|
||||
"quote protocol with peer {} failed due to {:?}",
|
||||
},
|
||||
quote::OutEvent::OutboundFailure { peer, error, .. } => OutEvent::Failure {
|
||||
error: anyhow!("quote protocol failed due to {:?}", error),
|
||||
peer,
|
||||
error
|
||||
)),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ impl From<execution_setup::OutEvent> for OutEvent {
|
|||
bob_peer_id,
|
||||
state3: Box::new(state3),
|
||||
},
|
||||
Failure(err) => OutEvent::Failure(err),
|
||||
Failure { peer, error } => OutEvent::Failure { peer, error },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,8 +130,11 @@ impl From<transfer_proof::OutEvent> for OutEvent {
|
|||
fn from(event: transfer_proof::OutEvent) -> Self {
|
||||
use crate::protocol::alice::transfer_proof::OutEvent::*;
|
||||
match event {
|
||||
Acknowledged => OutEvent::TransferProofAcknowledged,
|
||||
Failure(err) => OutEvent::Failure(err.context("Failure with Transfer Proof")),
|
||||
Acknowledged(peer) => OutEvent::TransferProofAcknowledged(peer),
|
||||
Failure { peer, error } => OutEvent::Failure {
|
||||
peer,
|
||||
error: error.context("Failure with Transfer Proof"),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,12 +143,16 @@ impl From<encrypted_signature::OutEvent> for OutEvent {
|
|||
fn from(event: encrypted_signature::OutEvent) -> Self {
|
||||
use crate::protocol::alice::encrypted_signature::OutEvent::*;
|
||||
match event {
|
||||
MsgReceived { msg, channel } => OutEvent::EncryptedSignature {
|
||||
MsgReceived { msg, channel, peer } => OutEvent::EncryptedSignature {
|
||||
msg: Box::new(msg),
|
||||
channel,
|
||||
peer,
|
||||
},
|
||||
AckSent => OutEvent::ResponseSent,
|
||||
Failure(err) => OutEvent::Failure(err.context("Failure with Encrypted Signature")),
|
||||
Failure { peer, error } => OutEvent::Failure {
|
||||
peer,
|
||||
error: error.context("Failure with Encrypted Signature"),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue