Add a timeout for peer handshakes.

This commit is contained in:
Henry de Valence 2019-10-21 22:17:57 -07:00
parent 027bdc8465
commit 9a779a639f
2 changed files with 8 additions and 1 deletions

View File

@ -22,6 +22,8 @@ pub struct Config {
pub ewma_decay_time: Duration,
/// The outgoing request buffer size for the peer set.
pub peerset_request_buffer_size: usize,
/// The timeout for peer handshakes.
pub handshake_timeout: Duration,
}
impl Default for Config {
@ -36,6 +38,7 @@ impl Default for Config {
ewma_default_rtt: Duration::from_secs(1),
ewma_decay_time: Duration::from_secs(60),
peerset_request_buffer_size: 1,
handshake_timeout: Duration::from_secs(4),
}
}
}

View File

@ -19,6 +19,7 @@ use tokio::net::{TcpListener, TcpStream};
use tower::{
buffer::Buffer,
discover::{Change, ServiceStream},
timeout::Timeout,
Service, ServiceExt,
};
use tower_load::{peak_ewma::PeakEwmaDiscover, NoInstrument};
@ -74,7 +75,10 @@ where
{
let (address_book, timestamp_collector) = TimestampCollector::spawn();
let peer_connector = Buffer::new(
Timeout::new(
PeerConnector::new(config.clone(), inbound_service, timestamp_collector),
config.handshake_timeout,
),
1,
);