mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-11-17 15:26:14 +00:00
Peer check for incoming transfer proofs
Bob validates that incoming transfer proof messages are coming from the peer-id of Alice. Currently Bob will ignore any transfer proof message that is not coming from the counterparty peer-id associated to the current swap in execution. Once we add support for trying to save received transfer proofs for swaps that are currently not in execution we can also adapy allowing this for different counterparty peer-ids. This requires access to the database in Bob's event loop.
This commit is contained in:
parent
3c2dfa830a
commit
08fecb8fe3
@ -68,6 +68,7 @@ impl From<(PeerId, Message)> for bob::OutEvent {
|
||||
} => Self::TransferProofReceived {
|
||||
msg: Box::new(request),
|
||||
channel,
|
||||
peer,
|
||||
},
|
||||
Message::Response { .. } => Self::unexpected_response(peer),
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ pub enum OutEvent {
|
||||
TransferProofReceived {
|
||||
msg: Box<transfer_proof::Request>,
|
||||
channel: ResponseChannel<()>,
|
||||
peer: PeerId,
|
||||
},
|
||||
EncryptedSignatureAcknowledged {
|
||||
id: RequestId,
|
||||
|
@ -117,11 +117,22 @@ impl EventLoop {
|
||||
let _ = responder.respond(*response);
|
||||
}
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::TransferProofReceived { msg, channel }) => {
|
||||
if msg.swap_id != self.swap_id {
|
||||
SwarmEvent::Behaviour(OutEvent::TransferProofReceived { msg, channel, peer }) => {
|
||||
let swap_id = msg.swap_id;
|
||||
|
||||
if peer != self.alice_peer_id {
|
||||
tracing::warn!(
|
||||
%swap_id,
|
||||
"Ignoring malicious transfer proof from {}, expected to receive it from {}",
|
||||
peer,
|
||||
self.alice_peer_id);
|
||||
continue;
|
||||
}
|
||||
|
||||
if swap_id != self.swap_id {
|
||||
|
||||
// TODO: Save unexpected transfer proofs in the database and check for messages in the database when handling swaps
|
||||
tracing::warn!("Received unexpected transfer proof for swap {} while running swap {}. This transfer proof will be ignored.", msg.swap_id, self.swap_id);
|
||||
tracing::warn!("Received unexpected transfer proof for swap {} while running swap {}. This transfer proof will be ignored.", swap_id, self.swap_id);
|
||||
|
||||
// When receiving a transfer proof that is unexpected we still have to acknowledge that it was received
|
||||
let _ = self.swarm.behaviour_mut().transfer_proof.send_response(channel, ());
|
||||
|
Loading…
Reference in New Issue
Block a user