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 5656570B16 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 8643617CA6 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 9F89D17C67 for ; Fri, 14 May 2021 15:45:14 +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 7993646566 for ; Fri, 14 May 2021 15:45:14 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Fri, 14 May 2021 15:44:52 +0200 Message-Id: <20210514134457.1447930-17-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. [proxmox.com, http.rs] Subject: [pbs-devel] [PATCH proxmox-backup 3/8] move MaybeTlsStream wrapper to proxmox_http 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 Signed-off-by: Fabian Grünbichler --- Notes: requires proxmox patch #6 Cargo.toml | 2 +- src/tools/async_io.rs | 119 +----------------------------------------- src/tools/http.rs | 6 +-- 3 files changed, 4 insertions(+), 123 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 997017c0..df649c1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ proxmox = { version = "0.11.4", features = [ "sortable-macro", "api-macro" ] } #proxmox = { git = "git://git.proxmox.com/git/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] } #proxmox = { path = "../proxmox/proxmox", features = [ "sortable-macro", "api-macro" ] } proxmox-fuse = "0.1.1" -proxmox-http = { version = "0.1.0", path = "../proxmox/proxmox-http", features = [ "websocket" ] } +proxmox-http = { version = "0.1.0", path = "../proxmox/proxmox-http", features = [ "http-helpers", "websocket" ] } pxar = { version = "0.10.1", features = [ "tokio-io" ] } #pxar = { path = "../pxar", features = [ "tokio-io" ] } regex = "1.2" diff --git a/src/tools/async_io.rs b/src/tools/async_io.rs index 83110912..66d38094 100644 --- a/src/tools/async_io.rs +++ b/src/tools/async_io.rs @@ -1,131 +1,14 @@ //! AsyncRead/AsyncWrite utilities. -use std::io; use std::os::unix::io::{AsRawFd, RawFd}; use std::pin::Pin; use std::task::{Context, Poll}; use futures::stream::{Stream, TryStream}; use futures::ready; -use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; +use tokio::io::{AsyncRead, AsyncWrite}; use tokio::net::TcpListener; -use tokio_openssl::SslStream; -use hyper::client::connect::{Connection, Connected}; -/// Asynchronous stream, possibly encrypted and proxied -/// -/// Usefule for HTTP client implementations using hyper. -pub enum MaybeTlsStream { - Normal(S), - Proxied(S), - Secured(SslStream), -} - -impl AsyncRead for MaybeTlsStream { - fn poll_read( - self: Pin<&mut Self>, - cx: &mut Context, - buf: &mut ReadBuf, - ) -> Poll> { - match self.get_mut() { - MaybeTlsStream::Normal(ref mut s) => { - Pin::new(s).poll_read(cx, buf) - } - MaybeTlsStream::Proxied(ref mut s) => { - Pin::new(s).poll_read(cx, buf) - } - MaybeTlsStream::Secured(ref mut s) => { - Pin::new(s).poll_read(cx, buf) - } - } - } -} - -impl AsyncWrite for MaybeTlsStream { - fn poll_write( - self: Pin<&mut Self>, - cx: &mut Context, - buf: &[u8], - ) -> Poll> { - match self.get_mut() { - MaybeTlsStream::Normal(ref mut s) => { - Pin::new(s).poll_write(cx, buf) - } - MaybeTlsStream::Proxied(ref mut s) => { - Pin::new(s).poll_write(cx, buf) - } - MaybeTlsStream::Secured(ref mut s) => { - Pin::new(s).poll_write(cx, buf) - } - } - } - - fn poll_write_vectored( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - bufs: &[io::IoSlice<'_>], - ) -> Poll> { - match self.get_mut() { - MaybeTlsStream::Normal(ref mut s) => { - Pin::new(s).poll_write_vectored(cx, bufs) - } - MaybeTlsStream::Proxied(ref mut s) => { - Pin::new(s).poll_write_vectored(cx, bufs) - } - MaybeTlsStream::Secured(ref mut s) => { - Pin::new(s).poll_write_vectored(cx, bufs) - } - } - } - - fn is_write_vectored(&self) -> bool { - match self { - MaybeTlsStream::Normal(s) => s.is_write_vectored(), - MaybeTlsStream::Proxied(s) => s.is_write_vectored(), - MaybeTlsStream::Secured(s) => s.is_write_vectored(), - } - } - - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - match self.get_mut() { - MaybeTlsStream::Normal(ref mut s) => { - Pin::new(s).poll_flush(cx) - } - MaybeTlsStream::Proxied(ref mut s) => { - Pin::new(s).poll_flush(cx) - } - MaybeTlsStream::Secured(ref mut s) => { - Pin::new(s).poll_flush(cx) - } - } - } - - fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - match self.get_mut() { - MaybeTlsStream::Normal(ref mut s) => { - Pin::new(s).poll_shutdown(cx) - } - MaybeTlsStream::Proxied(ref mut s) => { - Pin::new(s).poll_shutdown(cx) - } - MaybeTlsStream::Secured(ref mut s) => { - Pin::new(s).poll_shutdown(cx) - } - } - } -} - -// we need this for the hyper http client -impl Connection for MaybeTlsStream -{ - fn connected(&self) -> Connected { - match self { - MaybeTlsStream::Normal(s) => s.connected(), - MaybeTlsStream::Proxied(s) => s.connected().proxy(true), - MaybeTlsStream::Secured(s) => s.get_ref().connected(), - } - } -} /// Tokio's `Incoming` now is a reference type and hyper's `AddrIncoming` misses some standard /// stuff like `AsRawFd`, so here's something implementing hyper's `Accept` from a `TcpListener` diff --git a/src/tools/http.rs b/src/tools/http.rs index 1d96c70f..0f5b8470 100644 --- a/src/tools/http.rs +++ b/src/tools/http.rs @@ -19,11 +19,9 @@ use tokio::{ 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, - async_io::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 { -- 2.20.1