mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-23 13:51:08 -05: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 anyhow::{Context, Error};
|
||||||
use libp2p::PeerId;
|
use libp2p::PeerId;
|
||||||
use libp2p_async_await::BehaviourOutEvent;
|
use libp2p_async_await::BehaviourOutEvent;
|
||||||
|
use std::time::Duration;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -49,8 +50,8 @@ impl Default for Behaviour {
|
|||||||
|
|
||||||
impl Behaviour {
|
impl Behaviour {
|
||||||
pub fn run(&mut self, bob: PeerId, state0: State0) {
|
pub fn run(&mut self, bob: PeerId, state0: State0) {
|
||||||
self.inner
|
self.inner.do_protocol_listener(bob, move |mut substream| {
|
||||||
.do_protocol_listener(bob, move |mut substream| async move {
|
let protocol = async move {
|
||||||
let message0 =
|
let message0 =
|
||||||
serde_cbor::from_slice::<Message0>(&substream.read_message(BUF_SIZE).await?)
|
serde_cbor::from_slice::<Message0>(&substream.read_message(BUF_SIZE).await?)
|
||||||
.context("Failed to deserialize message0")?;
|
.context("Failed to deserialize message0")?;
|
||||||
@ -83,7 +84,10 @@ impl Behaviour {
|
|||||||
let state3 = state2.receive(message4)?;
|
let state3 = state2.receive(message4)?;
|
||||||
|
|
||||||
Ok((bob, (swap_id, state3)))
|
Ok((bob, (swap_id, state3)))
|
||||||
})
|
};
|
||||||
|
|
||||||
|
async move { tokio::time::timeout(Duration::from_secs(60), protocol).await? }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user