rest-server: PeerAddress for Pin<Box<T>>

since this is how tokio-openssl's SslStream is used in
practice

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2023-01-25 10:49:48 +01:00
parent 515cc729d0
commit 4639542fce

View File

@ -101,6 +101,15 @@ pub trait PeerAddress {
fn peer_addr(&self) -> Result<std::net::SocketAddr, Error>;
}
// tokio_openssl's SslStream requires the stream to be pinned in order to accept it, and we need to
// accept before the peer address is requested, so let's just generally implement this for
// Pin<Box<T>>
impl<T: PeerAddress> PeerAddress for Pin<Box<T>> {
fn peer_addr(&self) -> Result<std::net::SocketAddr, Error> {
T::peer_addr(&*self)
}
}
impl<T: PeerAddress> PeerAddress for tokio_openssl::SslStream<T> {
fn peer_addr(&self) -> Result<std::net::SocketAddr, Error> {
self.get_ref().peer_addr()