Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions finality-aleph/src/validator_network/outgoing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::{Debug, Display, Error as FmtError, Formatter};

use futures::channel::mpsc;
use log::{debug, info};
use tokio::time::{sleep, Duration};
use tokio::time::{sleep, timeout, Duration};

use crate::validator_network::{
protocols::{
Expand All @@ -15,6 +15,7 @@ enum OutgoingError<PK: PublicKey, A: Data, ND: Dialer<A>> {
Dial(ND::Error),
ProtocolNegotiation(PeerAddressInfo, ProtocolNegotiationError),
Protocol(PeerAddressInfo, ProtocolError<PK>),
TimedOut,
}

impl<PK: PublicKey, A: Data, ND: Dialer<A>> Display for OutgoingError<PK, A, ND> {
Expand All @@ -32,10 +33,13 @@ impl<PK: PublicKey, A: Data, ND: Dialer<A>> Display for OutgoingError<PK, A, ND>
"communication with {} failed, protocol error: {}",
addr, e
),
TimedOut => write!(f, "dial timeout",),
}
}
}

const DIAL_TIMEOUT: Duration = Duration::from_secs(43);

async fn manage_outgoing<SK: SecretKey, D: Data, A: Data, ND: Dialer<A>>(
secret_key: SK,
public_key: SK::PublicKey,
Expand All @@ -45,9 +49,10 @@ async fn manage_outgoing<SK: SecretKey, D: Data, A: Data, ND: Dialer<A>>(
data_for_user: mpsc::UnboundedSender<D>,
) -> Result<(), OutgoingError<SK::PublicKey, A, ND>> {
debug!(target: "validator-network", "Trying to connect to {}.", public_key);
let stream = dialer
.connect(addresses)

let stream = timeout(DIAL_TIMEOUT, dialer.connect(addresses))
.await
.map_err(|_| OutgoingError::TimedOut)?
.map_err(OutgoingError::Dial)?;
let peer_address_info = stream.peer_address_info();
debug!(target: "validator-network", "Performing outgoing protocol negotiation.");
Expand Down