1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 18:02:58 +01:00

prepare actix-tls release 3.0.0-rc.1 (#423)

This commit is contained in:
Rob Ede 2021-11-30 12:34:46 +00:00 committed by GitHub
parent 5dc2bfcb01
commit 183bcf6ae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 86 additions and 39 deletions

View File

@ -1,6 +1,43 @@
# Changes # Changes
## Unreleased - 2021-xx-xx ## Unreleased - 2021-xx-xx
## 3.0.0-rc.1 - 2021-11-29
### Added
* Derive `Debug` for `connect::Connection`. [#422]
* Implement `Display` for `accept::TlsError`. [#422]
* Implement `Error` for `accept::TlsError` where both types also implement `Error`. [#422]
* Implement `Default` for `connect::Resolver`. [#422]
* Implement `Error` for `connect::ConnectError`. [#422]
* Implement `Default` for `connect::tcp::{TcpConnector, TcpConnectorService}`. [#423]
* Implement `Default` for `connect::ConnectorService`. [#423]
### Changed
* The crate's default features flags no longer include `uri`. [#422]
* Useful re-exports from underlying TLS crates are exposed in a `reexports` modules in all acceptors and connectors.
* Convert `connect::ResolverService` from enum to struct. [#422]
* Make `ConnectAddrsIter` private. [#422]
* Mark `tcp::{TcpConnector, TcpConnectorService}` structs `#[non_exhaustive]`. [#423]
* Rename `accept::native_tls::{NativeTlsAcceptorService => AcceptorService}`. [#422]
* Rename `connect::{Address => Host}` trait. [#422]
* Rename method `connect::Connection::{host => hostname}`. [#422]
* Rename struct `connect::{Connect => ConnectInfo}`. [#422]
* Rename struct `connect::{ConnectService => ConnectorService}`. [#422]
* Rename struct `connect::{ConnectServiceFactory => Connector}`. [#422]
* Rename TLS acceptor service future types and hide from docs. [#422]
* Unbox some service futures types. [#422]
* Inline modules in `connect::tls` to `connect` module. [#422]
### Removed
* Remove `connect::{new_connector, new_connector_factory, default_connector, default_connector_factory}` methods. [#422]
* Remove `connect::native_tls::Connector::service` method. [#422]
* Remove redundant `connect::Connection::from_parts` method. [#422]
[#422]: https://github.com/actix/actix-net/pull/422
[#423]: https://github.com/actix/actix-net/pull/423
### Added ### Added
* Derive `Debug` for `connect::Connection`. [#422] * Derive `Debug` for `connect::Connection`. [#422]
* Implement `Display` for `accept::TlsError`. [#422] * Implement `Display` for `accept::TlsError`. [#422]
@ -9,7 +46,7 @@
* Implement `Error` for `connect::ConnectError`. [#422] * Implement `Error` for `connect::ConnectError`. [#422]
### Changed ### Changed
* There are now no default features. [#422] * The crate's default features flags no longer include `uri`. [#422]
* Useful re-exports from underlying TLS crates are exposed in a `reexports` modules in all acceptors and connectors. * Useful re-exports from underlying TLS crates are exposed in a `reexports` modules in all acceptors and connectors.
* Convert `connect::ResolverService` from enum to struct. [#422] * Convert `connect::ResolverService` from enum to struct. [#422]
* Make `ConnectAddrsIter` private. [#422] * Make `ConnectAddrsIter` private. [#422]
@ -21,6 +58,7 @@
* Rename struct `connect::{ConnectServiceFactory => Connector}`. [#422] * Rename struct `connect::{ConnectServiceFactory => Connector}`. [#422]
* Rename TLS acceptor service future types and hide from docs. [#422] * Rename TLS acceptor service future types and hide from docs. [#422]
* Unbox some service futures types. [#422] * Unbox some service futures types. [#422]
* Inline modules in `connect::tls` to `connect` module. [#422]
### Removed ### Removed
* Remove `connect::{new_connector, new_connector_factory, default_connector, default_connector_factory}` methods. [#422] * Remove `connect::{new_connector, new_connector_factory, default_connector, default_connector_factory}` methods. [#422]

View File

@ -1,6 +1,6 @@
[package] [package]
name = "actix-tls" name = "actix-tls"
version = "3.0.0-beta.9" version = "3.0.0-rc.1"
authors = [ authors = [
"Nikolay Kim <fafhrd91@gmail.com>", "Nikolay Kim <fafhrd91@gmail.com>",
"Rob Ede <robjtede@icloud.com>", "Rob Ede <robjtede@icloud.com>",
@ -21,7 +21,7 @@ name = "actix_tls"
path = "src/lib.rs" path = "src/lib.rs"
[features] [features]
default = [] default = ["accept", "connect"]
# enable acceptor services # enable acceptor services
accept = [] accept = []

View File

@ -93,7 +93,7 @@ pub struct Acceptor {
} }
impl Acceptor { impl Acceptor {
/// Constructs `native-tls` based `Acceptor` service factory. /// Constructs `native-tls` based acceptor service factory.
pub fn new(acceptor: TlsAcceptor) -> Self { pub fn new(acceptor: TlsAcceptor) -> Self {
Acceptor { Acceptor {
acceptor, acceptor,

View File

@ -96,7 +96,7 @@ pub struct Acceptor {
} }
impl Acceptor { impl Acceptor {
/// Create OpenSSL based `Acceptor` service factory. /// Create `openssl` based acceptor service factory.
#[inline] #[inline]
pub fn new(acceptor: SslAcceptor) -> Self { pub fn new(acceptor: SslAcceptor) -> Self {
Acceptor { Acceptor {

View File

@ -96,7 +96,7 @@ pub struct Acceptor {
} }
impl Acceptor { impl Acceptor {
/// Constructs Rustls based acceptor service factory. /// Constructs `rustls` based acceptor service factory.
pub fn new(config: ServerConfig) -> Self { pub fn new(config: ServerConfig) -> Self {
Acceptor { Acceptor {
config: Arc::new(config), config: Arc::new(config),

View File

@ -34,7 +34,7 @@ impl Connector {
/// Build connector service. /// Build connector service.
pub fn service(&self) -> ConnectorService { pub fn service(&self) -> ConnectorService {
ConnectorService { ConnectorService {
tcp: TcpConnector.service(), tcp: TcpConnector::default().service(),
resolver: self.resolver.service(), resolver: self.resolver.service(),
} }
} }
@ -57,7 +57,7 @@ impl<R: Host> ServiceFactory<ConnectInfo<R>> for Connector {
/// ///
/// Service implementation receives connection information, resolves DNS if required, and returns /// Service implementation receives connection information, resolves DNS if required, and returns
/// a TCP stream. /// a TCP stream.
#[derive(Clone)] #[derive(Clone, Default)]
pub struct ConnectorService { pub struct ConnectorService {
tcp: TcpConnectorService, tcp: TcpConnectorService,
resolver: ResolverService, resolver: ResolverService,
@ -78,14 +78,14 @@ impl<R: Host> Service<ConnectInfo<R>> for ConnectorService {
} }
} }
/// Helper enum to generic over futures of resolve and connect steps. /// Chains futures of resolve and connect steps.
pub(crate) enum ConnectFut<R: Host> { pub(crate) enum ConnectFut<R: Host> {
Resolve(<ResolverService as Service<ConnectInfo<R>>>::Future), Resolve(<ResolverService as Service<ConnectInfo<R>>>::Future),
Connect(<TcpConnectorService as Service<ConnectInfo<R>>>::Future), Connect(<TcpConnectorService as Service<ConnectInfo<R>>>::Future),
} }
/// Helper enum to contain the future output of `ConnectFuture`. /// Container for the intermediate states of [`ConnectFut`].
pub(crate) enum ConnectOutput<R: Host> { pub(crate) enum ConnectFutState<R: Host> {
Resolved(ConnectInfo<R>), Resolved(ConnectInfo<R>),
Connected(Connection<R, TcpStream>), Connected(Connection<R, TcpStream>),
} }
@ -94,13 +94,14 @@ impl<R: Host> ConnectFut<R> {
fn poll_connect( fn poll_connect(
&mut self, &mut self,
cx: &mut Context<'_>, cx: &mut Context<'_>,
) -> Poll<Result<ConnectOutput<R>, ConnectError>> { ) -> Poll<Result<ConnectFutState<R>, ConnectError>> {
match self { match self {
ConnectFut::Resolve(ref mut fut) => { ConnectFut::Resolve(ref mut fut) => {
Pin::new(fut).poll(cx).map_ok(ConnectOutput::Resolved) Pin::new(fut).poll(cx).map_ok(ConnectFutState::Resolved)
} }
ConnectFut::Connect(ref mut fut) => { ConnectFut::Connect(ref mut fut) => {
Pin::new(fut).poll(cx).map_ok(ConnectOutput::Connected) Pin::new(fut).poll(cx).map_ok(ConnectFutState::Connected)
} }
} }
} }
@ -117,10 +118,10 @@ impl<R: Host> Future for ConnectServiceResponse<R> {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
loop { loop {
match ready!(self.fut.poll_connect(cx))? { match ready!(self.fut.poll_connect(cx))? {
ConnectOutput::Resolved(res) => { ConnectFutState::Resolved(res) => {
self.fut = ConnectFut::Connect(self.tcp.call(res)); self.fut = ConnectFut::Connect(self.tcp.call(res));
} }
ConnectOutput::Connected(res) => return Poll::Ready(Ok(res)), ConnectFutState::Connected(res) => return Poll::Ready(Ok(res)),
} }
} }
} }

View File

@ -10,22 +10,24 @@ use actix_utils::future::{ok, Ready};
use futures_core::future::LocalBoxFuture; use futures_core::future::LocalBoxFuture;
use log::trace; use log::trace;
use tokio_native_tls::{ use tokio_native_tls::{
native_tls::TlsConnector as NativeTlsConnector, TlsConnector as TokioNativeTlsConnector, native_tls::TlsConnector as NativeTlsConnector, TlsConnector as AsyncNativeTlsConnector,
TlsStream, TlsStream as AsyncTlsStream,
}; };
use crate::connect::{Connection, Host}; use crate::connect::{Connection, Host};
pub mod reexports { pub mod reexports {
//! Re-exports from `native-tls` that are useful for connectors. //! Re-exports from `native-tls` and `tokio-native-tls` that are useful for connectors.
pub use tokio_native_tls::native_tls::TlsConnector; pub use tokio_native_tls::native_tls::TlsConnector;
pub use tokio_native_tls::TlsStream as AsyncTlsStream;
} }
/// Connector service and factory using `native-tls`. /// Connector service and factory using `native-tls`.
#[derive(Clone)] #[derive(Clone)]
pub struct TlsConnector { pub struct TlsConnector {
connector: TokioNativeTlsConnector, connector: AsyncNativeTlsConnector,
} }
impl TlsConnector { impl TlsConnector {
@ -34,7 +36,7 @@ impl TlsConnector {
/// This type is it's own service factory, so it can be used in that setting, too. /// This type is it's own service factory, so it can be used in that setting, too.
pub fn new(connector: NativeTlsConnector) -> Self { pub fn new(connector: NativeTlsConnector) -> Self {
Self { Self {
connector: TokioNativeTlsConnector::from(connector), connector: AsyncNativeTlsConnector::from(connector),
} }
} }
} }
@ -43,7 +45,7 @@ impl<R: Host, IO> ServiceFactory<Connection<R, IO>> for TlsConnector
where where
IO: ActixStream + 'static, IO: ActixStream + 'static,
{ {
type Response = Connection<R, TlsStream<IO>>; type Response = Connection<R, AsyncTlsStream<IO>>;
type Error = io::Error; type Error = io::Error;
type Config = (); type Config = ();
type Service = Self; type Service = Self;
@ -62,7 +64,7 @@ where
R: Host, R: Host,
IO: ActixStream + 'static, IO: ActixStream + 'static,
{ {
type Response = Connection<R, TlsStream<IO>>; type Response = Connection<R, AsyncTlsStream<IO>>;
type Error = io::Error; type Error = io::Error;
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>; type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;

View File

@ -15,14 +15,16 @@ use actix_utils::future::{ok, Ready};
use futures_core::ready; use futures_core::ready;
use log::trace; use log::trace;
use openssl::ssl::SslConnector; use openssl::ssl::SslConnector;
use tokio_openssl::SslStream; use tokio_openssl::SslStream as AsyncSslStream;
use crate::connect::{Connection, Host}; use crate::connect::{Connection, Host};
pub mod reexports { pub mod reexports {
//! Re-exports from `openssl` that are useful for connectors. //! Re-exports from `openssl` and `tokio-openssl` that are useful for connectors.
pub use openssl::ssl::{Error as SslError, HandshakeError, SslConnector, SslMethod}; pub use openssl::ssl::{Error, HandshakeError, SslConnector, SslMethod};
pub use tokio_openssl::SslStream as AsyncSslStream;
} }
/// Connector service factory using `openssl`. /// Connector service factory using `openssl`.
@ -55,7 +57,7 @@ where
R: Host, R: Host,
IO: ActixStream + 'static, IO: ActixStream + 'static,
{ {
type Response = Connection<R, SslStream<IO>>; type Response = Connection<R, AsyncSslStream<IO>>;
type Error = io::Error; type Error = io::Error;
type Config = (); type Config = ();
type Service = TlsConnectorService; type Service = TlsConnectorService;
@ -87,7 +89,7 @@ where
R: Host, R: Host,
IO: ActixStream, IO: ActixStream,
{ {
type Response = Connection<R, SslStream<IO>>; type Response = Connection<R, AsyncSslStream<IO>>;
type Error = io::Error; type Error = io::Error;
type Future = ConnectFut<R, IO>; type Future = ConnectFut<R, IO>;
@ -108,7 +110,7 @@ where
.expect("SSL connect configuration was invalid."); .expect("SSL connect configuration was invalid.");
ConnectFut { ConnectFut {
io: Some(SslStream::new(ssl, io).unwrap()), io: Some(AsyncSslStream::new(ssl, io).unwrap()),
stream: Some(stream), stream: Some(stream),
} }
} }
@ -117,7 +119,7 @@ where
/// Connect future for OpenSSL service. /// Connect future for OpenSSL service.
#[doc(hidden)] #[doc(hidden)]
pub struct ConnectFut<R, IO> { pub struct ConnectFut<R, IO> {
io: Option<SslStream<IO>>, io: Option<AsyncSslStream<IO>>,
stream: Option<Connection<R, ()>>, stream: Option<Connection<R, ()>>,
} }
@ -126,7 +128,7 @@ where
R: Host, R: Host,
IO: ActixStream, IO: ActixStream,
{ {
type Output = Result<Connection<R, SslStream<IO>>, io::Error>; type Output = Result<Connection<R, AsyncSslStream<IO>>, io::Error>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut(); let this = self.get_mut();

View File

@ -17,7 +17,7 @@ use actix_utils::future::{ok, Ready};
use futures_core::ready; use futures_core::ready;
use log::trace; use log::trace;
use tokio_rustls::rustls::{client::ServerName, OwnedTrustAnchor, RootCertStore}; use tokio_rustls::rustls::{client::ServerName, OwnedTrustAnchor, RootCertStore};
use tokio_rustls::{client::TlsStream, rustls::ClientConfig}; use tokio_rustls::{client::TlsStream as AsyncTlsStream, rustls::ClientConfig};
use tokio_rustls::{Connect as RustlsConnect, TlsConnector as RustlsTlsConnector}; use tokio_rustls::{Connect as RustlsConnect, TlsConnector as RustlsTlsConnector};
use webpki_roots::TLS_SERVER_ROOTS; use webpki_roots::TLS_SERVER_ROOTS;
@ -26,7 +26,9 @@ use crate::connect::{Connection, Host};
pub mod reexports { pub mod reexports {
//! Re-exports from `rustls` and `webpki_roots` that are useful for connectors. //! Re-exports from `rustls` and `webpki_roots` that are useful for connectors.
pub use tokio_rustls::{client::TlsStream, rustls::ClientConfig}; pub use tokio_rustls::rustls::ClientConfig;
pub use tokio_rustls::client::TlsStream as AsyncTlsStream;
pub use webpki_roots::TLS_SERVER_ROOTS; pub use webpki_roots::TLS_SERVER_ROOTS;
} }
@ -69,7 +71,7 @@ where
R: Host, R: Host,
IO: ActixStream + 'static, IO: ActixStream + 'static,
{ {
type Response = Connection<R, TlsStream<IO>>; type Response = Connection<R, AsyncTlsStream<IO>>;
type Error = io::Error; type Error = io::Error;
type Config = (); type Config = ();
type Service = TlsConnectorService; type Service = TlsConnectorService;
@ -94,7 +96,7 @@ where
R: Host, R: Host,
IO: ActixStream, IO: ActixStream,
{ {
type Response = Connection<R, TlsStream<IO>>; type Response = Connection<R, AsyncTlsStream<IO>>;
type Error = io::Error; type Error = io::Error;
type Future = ConnectFut<R, IO>; type Future = ConnectFut<R, IO>;
@ -130,7 +132,7 @@ where
R: Host, R: Host,
IO: ActixStream, IO: ActixStream,
{ {
type Output = Result<Connection<R, TlsStream<IO>>, io::Error>; type Output = Result<Connection<R, AsyncTlsStream<IO>>, io::Error>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.get_mut() { match self.get_mut() {

View File

@ -21,13 +21,14 @@ use tokio_util::sync::ReusableBoxFuture;
use super::{connect_addrs::ConnectAddrs, error::ConnectError, ConnectInfo, Connection, Host}; use super::{connect_addrs::ConnectAddrs, error::ConnectError, ConnectInfo, Connection, Host};
/// TCP connector service factory. /// TCP connector service factory.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Clone, Copy, Default)]
#[non_exhaustive]
pub struct TcpConnector; pub struct TcpConnector;
impl TcpConnector { impl TcpConnector {
/// Returns a new TCP connector service. /// Returns a new TCP connector service.
pub fn service(&self) -> TcpConnectorService { pub fn service(&self) -> TcpConnectorService {
TcpConnectorService TcpConnectorService::default()
} }
} }
@ -45,7 +46,8 @@ impl<R: Host> ServiceFactory<ConnectInfo<R>> for TcpConnector {
} }
/// TCP connector service. /// TCP connector service.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone, Default)]
#[non_exhaustive]
pub struct TcpConnectorService; pub struct TcpConnectorService;
impl<R: Host> Service<ConnectInfo<R>> for TcpConnectorService { impl<R: Host> Service<ConnectInfo<R>> for TcpConnectorService {