diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index bd2e165d18..afbe86420b 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -87,7 +87,7 @@ pub mod net { pub use tokio::net::{UnixDatagram, UnixListener, UnixStream}; /// Extension trait over async read+write types that can also signal readiness. - pub trait ActixStream: AsyncRead + AsyncWrite + Unpin + 'static { + pub trait ActixStream: AsyncRead + AsyncWrite + Unpin { /// Poll stream and check read readiness of Self. /// /// See [tokio::net::TcpStream::poll_read_ready] for detail on intended use. @@ -127,6 +127,16 @@ pub mod net { ready.poll(cx) } } + + impl ActixStream for Box { + fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { + (**self).poll_read_ready(cx) + } + + fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { + (**self).poll_write_ready(cx) + } + } } pub mod time { diff --git a/actix-tls/CHANGES.md b/actix-tls/CHANGES.md index 5bf21d4ed6..d78663d99b 100644 --- a/actix-tls/CHANGES.md +++ b/actix-tls/CHANGES.md @@ -3,9 +3,11 @@ ## Unreleased - 2021-xx-xx * Changed `connect::ssl::rustls::RustlsConnectorService` to return error when `DNSNameRef` generation failed instead of panic. [#296] +* Remove `connect::ssl::openssl::OpensslConnectServiceFactory`. [#297] +* Remove `connect::ssl::openssl::OpensslConnectService`. [#297] [#296]: https://github.com/actix/actix-net/pull/296 - +[#297]: https://github.com/actix/actix-net/pull/297 ## 3.0.0-beta.4 - 2021-02-24 * Rename `accept::openssl::{SslStream => TlsStream}`. diff --git a/actix-tls/src/accept/nativetls.rs b/actix-tls/src/accept/nativetls.rs index 614bdad36e..53294384f8 100644 --- a/actix-tls/src/accept/nativetls.rs +++ b/actix-tls/src/accept/nativetls.rs @@ -113,7 +113,7 @@ impl Clone for Acceptor { } } -impl ServiceFactory for Acceptor { +impl ServiceFactory for Acceptor { type Response = TlsStream; type Error = Error; type Config = (); @@ -138,16 +138,7 @@ pub struct NativeTlsAcceptorService { conns: Counter, } -impl Clone for NativeTlsAcceptorService { - fn clone(&self) -> Self { - Self { - acceptor: self.acceptor.clone(), - conns: self.conns.clone(), - } - } -} - -impl Service for NativeTlsAcceptorService { +impl Service for NativeTlsAcceptorService { type Response = TlsStream; type Error = Error; type Future = LocalBoxFuture<'static, Result, Error>>; @@ -162,9 +153,9 @@ impl Service for NativeTlsAcceptorService { fn call(&self, io: T) -> Self::Future { let guard = self.conns.get(); - let this = self.clone(); + let acceptor = self.acceptor.clone(); Box::pin(async move { - let io = this.acceptor.accept(io).await; + let io = acceptor.accept(io).await; drop(guard); io.map(Into::into) }) diff --git a/actix-tls/src/connect/ssl/openssl.rs b/actix-tls/src/connect/ssl/openssl.rs index b1c53f56d3..b4298fed2c 100755 --- a/actix-tls/src/connect/ssl/openssl.rs +++ b/actix-tls/src/connect/ssl/openssl.rs @@ -1,13 +1,11 @@ use std::{ - fmt, future::Future, io, pin::Pin, task::{Context, Poll}, }; -use actix_codec::{AsyncRead, AsyncWrite}; -use actix_rt::net::TcpStream; +use actix_rt::net::ActixStream; use actix_service::{Service, ServiceFactory}; use futures_core::{future::LocalBoxFuture, ready}; use log::trace; @@ -15,10 +13,7 @@ use log::trace; pub use openssl::ssl::{Error as SslError, HandshakeError, SslConnector, SslMethod}; pub use tokio_openssl::SslStream; -use crate::connect::resolve::Resolve; -use crate::connect::{ - Address, Connect, ConnectError, ConnectService, ConnectServiceFactory, Connection, Resolver, -}; +use crate::connect::{Address, Connection}; /// OpenSSL connector factory pub struct OpensslConnector { @@ -45,8 +40,8 @@ impl Clone for OpensslConnector { impl ServiceFactory> for OpensslConnector where - T: Address + 'static, - U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static, + T: Address, + U: ActixStream + 'static, { type Response = Connection>; type Error = io::Error; @@ -75,8 +70,8 @@ impl Clone for OpensslConnectorService { impl Service> for OpensslConnectorService where - T: Address + 'static, - U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static, + T: Address, + U: ActixStream, { type Response = Connection>; type Error = io::Error; @@ -112,7 +107,8 @@ pub struct ConnectAsyncExt { impl Future for ConnectAsyncExt where - U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static, + T: Address, + U: ActixStream, { type Output = Result>, io::Error>; @@ -132,115 +128,3 @@ where } } } - -pub struct OpensslConnectServiceFactory { - tcp: ConnectServiceFactory, - openssl: OpensslConnector, -} - -impl OpensslConnectServiceFactory { - /// Construct new OpensslConnectService factory - pub fn new(connector: SslConnector) -> Self { - OpensslConnectServiceFactory { - tcp: ConnectServiceFactory::new(Resolver::Default), - openssl: OpensslConnector::new(connector), - } - } - - /// Construct new connect service with custom DNS resolver - pub fn with_resolver(connector: SslConnector, resolver: impl Resolve + 'static) -> Self { - OpensslConnectServiceFactory { - tcp: ConnectServiceFactory::new(Resolver::new_custom(resolver)), - openssl: OpensslConnector::new(connector), - } - } - - /// Construct OpenSSL connect service - pub fn service(&self) -> OpensslConnectService { - OpensslConnectService { - tcp: self.tcp.service(), - openssl: OpensslConnectorService { - connector: self.openssl.connector.clone(), - }, - } - } -} - -impl Clone for OpensslConnectServiceFactory { - fn clone(&self) -> Self { - OpensslConnectServiceFactory { - tcp: self.tcp.clone(), - openssl: self.openssl.clone(), - } - } -} - -impl ServiceFactory> for OpensslConnectServiceFactory { - type Response = SslStream; - type Error = ConnectError; - type Config = (); - type Service = OpensslConnectService; - type InitError = (); - type Future = LocalBoxFuture<'static, Result>; - - fn new_service(&self, _: ()) -> Self::Future { - let service = self.service(); - Box::pin(async { Ok(service) }) - } -} - -#[derive(Clone)] -pub struct OpensslConnectService { - tcp: ConnectService, - openssl: OpensslConnectorService, -} - -impl Service> for OpensslConnectService { - type Response = SslStream; - type Error = ConnectError; - type Future = OpensslConnectServiceResponse; - - actix_service::always_ready!(); - - fn call(&self, req: Connect) -> Self::Future { - OpensslConnectServiceResponse { - fut1: Some(self.tcp.call(req)), - fut2: None, - openssl: self.openssl.clone(), - } - } -} - -pub struct OpensslConnectServiceResponse { - fut1: Option<>>::Future>, - fut2: Option<>>::Future>, - openssl: OpensslConnectorService, -} - -impl Future for OpensslConnectServiceResponse { - type Output = Result, ConnectError>; - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - if let Some(ref mut fut) = self.fut1 { - match ready!(Pin::new(fut).poll(cx)) { - Ok(res) => { - let _ = self.fut1.take(); - self.fut2 = Some(self.openssl.call(res)); - } - Err(e) => return Poll::Ready(Err(e)), - } - } - - if let Some(ref mut fut) = self.fut2 { - match ready!(Pin::new(fut).poll(cx)) { - Ok(connect) => Poll::Ready(Ok(connect.into_parts().0)), - Err(e) => Poll::Ready(Err(ConnectError::Io(io::Error::new( - io::ErrorKind::Other, - e, - )))), - } - } else { - Poll::Pending - } - } -} diff --git a/actix-tls/src/connect/ssl/rustls.rs b/actix-tls/src/connect/ssl/rustls.rs index b03d4b7fb1..ee8ad02d19 100755 --- a/actix-tls/src/connect/ssl/rustls.rs +++ b/actix-tls/src/connect/ssl/rustls.rs @@ -47,7 +47,7 @@ impl Clone for RustlsConnector { impl ServiceFactory> for RustlsConnector where T: Address, - U: ActixStream, + U: ActixStream + 'static, { type Response = Connection>; type Error = io::Error;