mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-06-23 06:14:28 -04:00
Timeout Bob's execution-setup after 10 seconds
The execution setup is our only libp2p protocol that doesn't have a timeout built-in. Hence, if anything fails on Alice's side, we would wait here forever. Wrapping the future in a timeout ensures that we fail eventually if this protocol doesn't succeed.
This commit is contained in:
parent
5d75f1adba
commit
dbe03ba1cf
1 changed files with 7 additions and 3 deletions
|
@ -5,6 +5,7 @@ use anyhow::{Context, Error, Result};
|
||||||
use libp2p::PeerId;
|
use libp2p::PeerId;
|
||||||
use libp2p_async_await::BehaviourOutEvent;
|
use libp2p_async_await::BehaviourOutEvent;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum OutEvent {
|
pub enum OutEvent {
|
||||||
|
@ -42,8 +43,8 @@ impl Behaviour {
|
||||||
state0: State0,
|
state0: State0,
|
||||||
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
|
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
|
||||||
) {
|
) {
|
||||||
self.inner
|
self.inner.do_protocol_dialer(alice, move |mut substream| {
|
||||||
.do_protocol_dialer(alice, move |mut substream| async move {
|
let protocol = async move {
|
||||||
tracing::debug!("Starting execution setup with {}", alice);
|
tracing::debug!("Starting execution setup with {}", alice);
|
||||||
|
|
||||||
substream
|
substream
|
||||||
|
@ -78,6 +79,9 @@ impl Behaviour {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(state2)
|
Ok(state2)
|
||||||
|
};
|
||||||
|
|
||||||
|
async move { tokio::time::timeout(Duration::from_secs(10), protocol).await? }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue