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 6122D70809 for ; Wed, 29 Sep 2021 09:04:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 380A5F46A for ; Wed, 29 Sep 2021 09:04:23 +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 BDA41F448 for ; Wed, 29 Sep 2021 09:04:21 +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 9139C44B81 for ; Wed, 29 Sep 2021 09:04:21 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Wed, 29 Sep 2021 09:04:17 +0200 Message-Id: <20210929070420.617226-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210929070420.617226-1-d.csapak@proxmox.com> References: <20210929070420.617226-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.346 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 Subject: [pbs-devel] [PATCH proxmox-backup v3 1/4] rest-server: use hypers AddrIncoming for proxmox-backup-api 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: Wed, 29 Sep 2021 07:04:53 -0000 this has a 'from_listener' (tokio::net::TcpListener) since hyper 0.14.5 in the 'tcp' feature (we use 'full', which includes that; since 0.14.13 it is not behind a feature flag anymore). this makes it possible to create a hyper server without our 'StaticIncoming' wrapper and thus makes it unnecessary. The only other thing we have to do is to change the Service impl from tokio::net::TcpStream to hyper::server::conn::AddStream to fulfill the trait requirements. Signed-off-by: Dominik Csapak --- proxmox-rest-server/src/rest.rs | 18 ++++++++---------- src/bin/proxmox-backup-api.rs | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs index ba2edf11..8c1e34a3 100644 --- a/proxmox-rest-server/src/rest.rs +++ b/proxmox-rest-server/src/rest.rs @@ -93,7 +93,7 @@ impl tower_service::Service<&Pin for RestServer { +impl tower_service::Service<&hyper::server::conn::AddrStream> for RestServer { type Response = ApiService; type Error = Error; type Future = Pin> + Send>>; @@ -102,15 +102,13 @@ impl tower_service::Service<&tokio::net::TcpStream> for RestServer { Poll::Ready(Ok(())) } - fn call(&mut self, ctx: &tokio::net::TcpStream) -> Self::Future { - match ctx.peer_addr() { - Err(err) => future::err(format_err!("unable to get peer address - {}", err)).boxed(), - Ok(peer) => future::ok(ApiService { - peer, - api_config: self.api_config.clone(), - }) - .boxed(), - } + fn call(&mut self, ctx: &hyper::server::conn::AddrStream) -> Self::Future { + let peer = ctx.remote_addr(); + future::ok(ApiService { + peer, + api_config: self.api_config.clone(), + }) + .boxed() } } diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index 86650de6..e3f2531f 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -108,7 +108,8 @@ async fn run() -> Result<(), Error> { let server = daemon::create_daemon( ([127,0,0,1], 82).into(), move |listener, ready| { - let incoming = proxmox_backup::tools::async_io::StaticIncoming::from(listener); + let incoming = hyper::server::conn::AddrIncoming::from_listener(listener)?; + Ok(ready .and_then(|_| hyper::Server::builder(incoming) .serve(rest_server) -- 2.30.2