From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 5B99070B17 for ; Fri, 14 May 2021 15:46:00 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 86E0A17CA7 for ; Fri, 14 May 2021 15:45:16 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 82EA817C9B for ; Fri, 14 May 2021 15:45:15 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4FA2046568 for ; Fri, 14 May 2021 15:45:15 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Fri, 14 May 2021 15:44:53 +0200 Message-Id: <20210514134457.1447930-18-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210514134457.1447930-1-f.gruenbichler@proxmox.com> References: <20210514134457.1447930-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.013 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [http.rs] Subject: [pbs-devel] [PATCH proxmox-backup 4/8] HttpsConnector: make keepalive configurable X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 May 2021 13:46:00 -0000 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 --- src/client/http_client.rs | 3 ++- src/tools/http.rs | 13 +++++++------ src/tools/simple_http_client.rs | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/client/http_client.rs b/src/client/http_client.rs index 7fe33bcc..056f30e5 100644 --- a/src/client/http_client.rs +++ b/src/client/http_client.rs @@ -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) diff --git a/src/tools/http.rs b/src/tools/http.rs index 0f5b8470..a6b92aad 100644 --- a/src/tools/http.rs +++ b/src/tools/http.rs @@ -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 { let bytes = host.as_bytes(); @@ -120,15 +118,17 @@ pub struct HttpsConnector { connector: HttpConnector, ssl_connector: Arc, proxy: Option, + 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 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 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 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 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 diff --git a/src/tools/simple_http_client.rs b/src/tools/simple_http_client.rs index ca11ded8..1e399267 100644 --- a/src/tools/simple_http_client.rs +++ b/src/tools/simple_http_client.rs @@ -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); } -- 2.20.1