public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox Backup Server development discussion
	<pbs-devel@lists.proxmox.com>,
	Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup v2 1/3] rest-server: use hypers AddrStream for proxmox-backup-api
Date: Wed, 29 Sep 2021 08:27:06 +0200	[thread overview]
Message-ID: <556bb335-5bc6-d10d-c956-82058bf1f547@proxmox.com> (raw)
In-Reply-To: <20210928091152.2151682-2-d.csapak@proxmox.com>

On 28.09.21 11:11, Dominik Csapak wrote:
> so that the StaticIncoming wrapper is not necessary anymore.

since when and why? IIRC it was some addition to tokio that fixed it.
Such info is important for review and git history, especially for such a crucial
code part...

> 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@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)
> 





  reply	other threads:[~2021-09-29  6:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28  9:11 [pbs-devel] [PATCH proxmox-backup v2 0/3] add rest_server example Dominik Csapak
2021-09-28  9:11 ` [pbs-devel] [PATCH proxmox-backup v2 1/3] rest-server: use hypers AddrStream for proxmox-backup-api Dominik Csapak
2021-09-29  6:27   ` Thomas Lamprecht [this message]
2021-09-28  9:11 ` [pbs-devel] [PATCH proxmox-backup v2 2/3] remove tools/async_io.rs Dominik Csapak
2021-09-28  9:11 ` [pbs-devel] [PATCH proxmox-backup v2 3/3] examples: add example for a simple rest server with a small api Dominik Csapak
2021-09-29  6:41   ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=556bb335-5bc6-d10d-c956-82058bf1f547@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal