From 7788fdafacaa0c96da7aa692d3ecb22fd1ad6c64 Mon Sep 17 00:00:00 2001 From: Chris Connelly Date: Wed, 27 Oct 2021 11:56:56 +0100 Subject: [PATCH] refactor!: disable keep-alives by default This changes the `keep_alive_interval` set for `Config::default()` to `None`, disabling keep-alives. This is thought to be a more sane default for a library, since keep-alives may otherwise cause connections to stay open forever, leaking resources. It remains easy to opt-in to keep-alives by simply setting `Some(duration)`. BREAKING CHANGE: The `qp2p::config::DEFAULT_KEEP_ALIVE_INTERVAL` constant has been removed, and the default value for `keep_alive_interval` set for `Config::default()` is now `None`, meaning keep-alives are disabled by default. --- src/config.rs | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/src/config.rs b/src/config.rs index f95c70ed..4e0183a7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,14 +18,6 @@ use std::{future::Future, net::IpAddr, sync::Arc, time::Duration}; /// see no conversation between them. pub const DEFAULT_IDLE_TIMEOUT: Duration = Duration::from_secs(60); -/// Default for [`Config::keep_alive_interval`] (20 seconds). -pub const DEFAULT_KEEP_ALIVE_INTERVAL: Duration = Duration::from_secs(20); - -// serde needs a function when specifying a path for `default` -fn default_keep_alive_interval() -> Option { - Some(DEFAULT_KEEP_ALIVE_INTERVAL) -} - /// Default for [`Config::upnp_lease_duration`] (2 minutes). pub const DEFAULT_UPNP_LEASE_DURATION: Duration = Duration::from_secs(120); @@ -97,7 +89,7 @@ pub struct CertificateGenerationError( ); /// QuicP2p configurations -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct Config { /// Specify if port forwarding via UPnP should be done or not. This can be set to false if the network /// is run locally on the network loopback or on a local area network. @@ -127,8 +119,8 @@ pub struct Config { /// /// Keep-alives prevent otherwise idle connections from timing out. /// - /// If unspecified, this will default to [`DEFAULT_KEEP_ALIVE_INTERVAL`]. - #[serde(default = "default_keep_alive_interval")] + /// If unspecified, this will default to `None`, disabling keep-alives. + #[serde(default)] pub keep_alive_interval: Option, /// How long UPnP port mappings will last. @@ -146,21 +138,6 @@ pub struct Config { pub retry_config: RetryConfig, } -impl Default for Config { - fn default() -> Self { - Self { - #[cfg(feature = "igd")] - forward_port: Default::default(), - external_port: Default::default(), - external_ip: Default::default(), - idle_timeout: Default::default(), - keep_alive_interval: default_keep_alive_interval(), - upnp_lease_duration: Default::default(), - retry_config: Default::default(), - } - } -} - /// Retry configurations for establishing connections and sending messages. /// Determines the retry behaviour of requests, by setting the back off strategy used. #[derive(Clone, Debug, Copy, Serialize, Deserialize)]