2021-10-26 01:37:40 +02:00
|
|
|
use std::{net::IpAddr, time::Duration};
|
2020-03-07 03:09:31 +01:00
|
|
|
|
2021-01-15 06:38:50 +01:00
|
|
|
const DEFAULT_H2_CONN_WINDOW: u32 = 1024 * 1024 * 2; // 2MB
|
|
|
|
const DEFAULT_H2_STREAM_WINDOW: u32 = 1024 * 1024; // 1MB
|
2020-03-07 03:09:31 +01:00
|
|
|
|
|
|
|
/// Connector configuration
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub(crate) struct ConnectorConfig {
|
|
|
|
pub(crate) timeout: Duration,
|
2021-03-18 18:53:22 +01:00
|
|
|
pub(crate) handshake_timeout: Duration,
|
2020-03-07 03:09:31 +01:00
|
|
|
pub(crate) conn_lifetime: Duration,
|
|
|
|
pub(crate) conn_keep_alive: Duration,
|
|
|
|
pub(crate) disconnect_timeout: Option<Duration>,
|
|
|
|
pub(crate) limit: usize,
|
|
|
|
pub(crate) conn_window_size: u32,
|
|
|
|
pub(crate) stream_window_size: u32,
|
2021-02-27 23:31:14 +01:00
|
|
|
pub(crate) local_address: Option<IpAddr>,
|
2020-03-07 03:09:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ConnectorConfig {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2021-02-07 02:00:40 +01:00
|
|
|
timeout: Duration::from_secs(5),
|
2021-03-18 18:53:22 +01:00
|
|
|
handshake_timeout: Duration::from_secs(5),
|
2020-03-07 03:09:31 +01:00
|
|
|
conn_lifetime: Duration::from_secs(75),
|
|
|
|
conn_keep_alive: Duration::from_secs(15),
|
|
|
|
disconnect_timeout: Some(Duration::from_millis(3000)),
|
|
|
|
limit: 100,
|
|
|
|
conn_window_size: DEFAULT_H2_CONN_WINDOW,
|
|
|
|
stream_window_size: DEFAULT_H2_STREAM_WINDOW,
|
2021-02-27 23:31:14 +01:00
|
|
|
local_address: None,
|
2020-03-07 03:09:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ConnectorConfig {
|
|
|
|
pub(crate) fn no_disconnect_timeout(&self) -> Self {
|
|
|
|
let mut res = self.clone();
|
|
|
|
res.disconnect_timeout = None;
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|