mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Timeout on execution_setup
for ASB
Similar to the CLI the ASB has to ensure that the execution_setup is executed within a certain time. Without a timeout the price (returned by `spot_price` would be guaranteed with the CLI indefinitely.
This commit is contained in:
parent
61aaeb1579
commit
593d5be77b
@ -4,6 +4,7 @@ use crate::protocol::{alice, Message0, Message2, Message4};
|
||||
use anyhow::{Context, Error};
|
||||
use libp2p::PeerId;
|
||||
use libp2p_async_await::BehaviourOutEvent;
|
||||
use std::time::Duration;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -49,8 +50,8 @@ impl Default for Behaviour {
|
||||
|
||||
impl Behaviour {
|
||||
pub fn run(&mut self, bob: PeerId, state0: State0) {
|
||||
self.inner
|
||||
.do_protocol_listener(bob, move |mut substream| async move {
|
||||
self.inner.do_protocol_listener(bob, move |mut substream| {
|
||||
let protocol = async move {
|
||||
let message0 =
|
||||
serde_cbor::from_slice::<Message0>(&substream.read_message(BUF_SIZE).await?)
|
||||
.context("Failed to deserialize message0")?;
|
||||
@ -83,7 +84,10 @@ impl Behaviour {
|
||||
let state3 = state2.receive(message4)?;
|
||||
|
||||
Ok((bob, (swap_id, state3)))
|
||||
})
|
||||
};
|
||||
|
||||
async move { tokio::time::timeout(Duration::from_secs(60), protocol).await? }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user