[pbs-devel] [PATCH proxmox-backup v2 1/3] rest-server: use hypers AddrStream for proxmox-backup-api

Dominik Csapak d.csapak at proxmox.com
Tue Sep 28 11:11:50 CEST 2021


so that the StaticIncoming wrapper is not necessary anymore. The only
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 <d.csapak at proxmox.com>
---
new in v2
 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<Box<tokio_openssl::SslStream<tokio::net::TcpStr
     }
 }
 
-impl tower_service::Service<&tokio::net::TcpStream> for RestServer {
+impl tower_service::Service<&hyper::server::conn::AddrStream> for RestServer {
     type Response = ApiService;
     type Error = Error;
     type Future = Pin<Box<dyn Future<Output = Result<ApiService, Error>> + 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






More information about the pbs-devel mailing list