]> git.proxmox.com Git - proxmox-backup.git/commitdiff
HttpsConnector: make keepalive configurable
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 14 May 2021 13:44:53 +0000 (15:44 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 17 May 2021 08:31:15 +0000 (10:31 +0200)
it's the only PBS-specific part in there, so let's make it
product-agnostic before moving it off to proxmox-http.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/client/http_client.rs
src/tools/http.rs
src/tools/simple_http_client.rs

index 7fe33bcc457f8a0ca6d75f902c80b5a6ac97d6ac..056f30e53768f3c82cac06bac6d2d6205eb5b15c 100644 (file)
@@ -26,6 +26,7 @@ use crate::tools::{
     self,
     BroadcastFuture,
     DEFAULT_ENCODE_SET,
+    PROXMOX_BACKUP_TCP_KEEPALIVE_TIME,
     http::{
         build_authority,
         HttpsConnector,
@@ -343,7 +344,7 @@ impl HttpClient {
         httpc.enforce_http(false); // we want https...
 
         httpc.set_connect_timeout(Some(std::time::Duration::new(10, 0)));
-        let https = HttpsConnector::with_connector(httpc, ssl_connector_builder.build());
+        let https = HttpsConnector::with_connector(httpc, ssl_connector_builder.build(), PROXMOX_BACKUP_TCP_KEEPALIVE_TIME);
 
         let client = Client::builder()
         //.http2_initial_stream_window_size( (1 << 31) - 2)
index 0f5b8470f70ed02d1e1136bfa3c64ccbaba0a199..a6b92aade64a86c0a0a4561c6575548298528697 100644 (file)
@@ -21,8 +21,6 @@ use tokio_openssl::SslStream;
 use proxmox::sys::linux::socket::set_tcp_keepalive;
 use proxmox_http::http::MaybeTlsStream;
 
-use crate::tools::PROXMOX_BACKUP_TCP_KEEPALIVE_TIME;
-
 // Build a http::uri::Authority ("host:port"), use '[..]' around IPv6 addresses
 pub(crate) fn build_authority(host: &str, port: u16) -> Result<Authority, Error> {
     let bytes = host.as_bytes();
@@ -120,15 +118,17 @@ pub struct HttpsConnector {
     connector: HttpConnector,
     ssl_connector: Arc<SslConnector>,
     proxy: Option<ProxyConfig>,
+    tcp_keepalive: u32,
 }
 
 impl HttpsConnector {
-    pub fn with_connector(mut connector: HttpConnector, ssl_connector: SslConnector) -> Self {
+    pub fn with_connector(mut connector: HttpConnector, ssl_connector: SslConnector, tcp_keepalive: u32) -> Self {
         connector.enforce_http(false);
         Self {
             connector,
             ssl_connector: Arc::new(ssl_connector),
             proxy: None,
+            tcp_keepalive,
         }
     }
 
@@ -213,6 +213,7 @@ impl hyper::service::Service<Uri> for HttpsConnector {
             }
         };
         let port = dst.port_u16().unwrap_or(if is_https { 443 } else { 80 });
+        let keepalive = self.tcp_keepalive;
 
         if let Some(ref proxy) = self.proxy {
 
@@ -243,7 +244,7 @@ impl hyper::service::Service<Uri> for HttpsConnector {
                         .await
                         .map_err(|err| format_err!("error connecting to {} - {}", proxy_authority, err))?;
 
-                    let _ = set_tcp_keepalive(tcp_stream.as_raw_fd(), PROXMOX_BACKUP_TCP_KEEPALIVE_TIME);
+                    let _ = set_tcp_keepalive(tcp_stream.as_raw_fd(), keepalive);
 
                     let mut connect_request = format!("CONNECT {0}:{1} HTTP/1.1\r\n", host, port);
                     if let Some(authorization) = authorization {
@@ -272,7 +273,7 @@ impl hyper::service::Service<Uri> for HttpsConnector {
                        .await
                        .map_err(|err| format_err!("error connecting to {} - {}", proxy_authority, err))?;
 
-                   let _ = set_tcp_keepalive(tcp_stream.as_raw_fd(), PROXMOX_BACKUP_TCP_KEEPALIVE_TIME);
+                   let _ = set_tcp_keepalive(tcp_stream.as_raw_fd(), keepalive);
 
                    Ok(MaybeTlsStream::Proxied(tcp_stream))
                }.boxed()
@@ -285,7 +286,7 @@ impl hyper::service::Service<Uri> for HttpsConnector {
                     .await
                     .map_err(|err| format_err!("error connecting to {} - {}", dst_str, err))?;
 
-                let _ = set_tcp_keepalive(tcp_stream.as_raw_fd(), PROXMOX_BACKUP_TCP_KEEPALIVE_TIME);
+                let _ = set_tcp_keepalive(tcp_stream.as_raw_fd(), keepalive);
 
                 if is_https {
                     Self::secure_stream(tcp_stream, &ssl_connector, &host).await
index ca11ded85c13e180e140af5fe9259c53b8e11f3b..1e399267e0006163122dc6dc6778dadffbf1e045 100644 (file)
@@ -7,6 +7,7 @@ use http::{Request, Response, HeaderValue};
 use openssl::ssl::{SslConnector, SslMethod};
 use futures::*;
 
+use crate::tools::PROXMOX_BACKUP_TCP_KEEPALIVE_TIME;
 use crate::tools::http::{HttpsConnector, ProxyConfig};
 
 /// Asyncrounous HTTP client implementation
@@ -35,7 +36,7 @@ impl SimpleHttp {
         }
 
         let connector = HttpConnector::new();
-        let mut https = HttpsConnector::with_connector(connector, ssl_connector);
+        let mut https = HttpsConnector::with_connector(connector, ssl_connector, PROXMOX_BACKUP_TCP_KEEPALIVE_TIME);
         if let Some(proxy_config) = proxy_config {
             https.set_proxy(proxy_config);
         }