mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-31 08:12:07 +01:00
prepare connect v2 stable release (#185)
This commit is contained in:
parent
d28687d0d7
commit
7632f51509
@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-connect"
|
name = "actix-connect"
|
||||||
version = "2.0.0-alpha.4"
|
version = "2.0.0"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix connect - tcp connector service"
|
description = "TCP connector service for Actix ecosystem."
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
homepage = "https://actix.rs"
|
homepage = "https://actix.rs"
|
||||||
repository = "https://github.com/actix/actix-net.git"
|
repository = "https://github.com/actix/actix-net.git"
|
||||||
@ -31,10 +31,11 @@ rustls = ["rust-tls", "tokio-rustls", "webpki"]
|
|||||||
uri = ["http"]
|
uri = ["http"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-service = "1.0.3"
|
actix-service = "1.0.6"
|
||||||
actix-codec = "0.3.0"
|
actix-codec = "0.3.0"
|
||||||
actix-utils = "2.0.0"
|
actix-utils = "2.0.0"
|
||||||
actix-rt = "1.0.0"
|
actix-rt = "1.1.1"
|
||||||
|
|
||||||
derive_more = "0.99.2"
|
derive_more = "0.99.2"
|
||||||
either = "1.5.3"
|
either = "1.5.3"
|
||||||
futures-util = { version = "0.3.4", default-features = false }
|
futures-util = { version = "0.3.4", default-features = false }
|
||||||
@ -44,14 +45,14 @@ trust-dns-proto = { version = "0.19", default-features = false, features = ["tok
|
|||||||
trust-dns-resolver = { version = "0.19", default-features = false, features = ["tokio-runtime", "system-config"] }
|
trust-dns-resolver = { version = "0.19", default-features = false, features = ["tokio-runtime", "system-config"] }
|
||||||
|
|
||||||
# openssl
|
# openssl
|
||||||
open-ssl = { version="0.10", package = "openssl", optional = true }
|
open-ssl = { package = "openssl", version = "0.10", optional = true }
|
||||||
tokio-openssl = { version = "0.4.0", optional = true }
|
tokio-openssl = { version = "0.4.0", optional = true }
|
||||||
|
|
||||||
# rustls
|
# rustls
|
||||||
rust-tls = { version = "0.18.0", package = "rustls", optional = true }
|
rust-tls = { package = "rustls", version = "0.18.0", optional = true }
|
||||||
tokio-rustls = { version = "0.14.0", optional = true }
|
tokio-rustls = { version = "0.14.0", optional = true }
|
||||||
webpki = { version = "0.21", optional = true }
|
webpki = { version = "0.21", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bytes = "0.5.3"
|
bytes = "0.5.3"
|
||||||
actix-testing = { version="1.0.0" }
|
actix-testing = "1.0.0"
|
||||||
|
@ -43,7 +43,7 @@ pub struct Connect<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Address> Connect<T> {
|
impl<T: Address> Connect<T> {
|
||||||
/// Create `Connect` instance by spliting the string by ':' and convert the second part to u16
|
/// Create `Connect` instance by splitting the string by ':' and convert the second part to u16
|
||||||
pub fn new(req: T) -> Connect<T> {
|
pub fn new(req: T) -> Connect<T> {
|
||||||
let (_, port) = parse(req.host());
|
let (_, port) = parse(req.host());
|
||||||
Connect {
|
Connect {
|
||||||
@ -53,7 +53,8 @@ impl<T: Address> Connect<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create new `Connect` instance from host and address. Connector skips name resolution stage for such connect messages.
|
/// Create new `Connect` instance from host and address. Connector skips name resolution stage
|
||||||
|
/// for such connect messages.
|
||||||
pub fn with(req: T, addr: SocketAddr) -> Connect<T> {
|
pub fn with(req: T, addr: SocketAddr) -> Connect<T> {
|
||||||
Connect {
|
Connect {
|
||||||
req,
|
req,
|
||||||
@ -102,7 +103,7 @@ impl<T: Address> Connect<T> {
|
|||||||
self.req.port().unwrap_or(self.port)
|
self.req.port().unwrap_or(self.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Preresolved addresses of the request.
|
/// Pre-resolved addresses of the request.
|
||||||
pub fn addrs(&self) -> ConnectAddrsIter<'_> {
|
pub fn addrs(&self) -> ConnectAddrsIter<'_> {
|
||||||
let inner = match self.addr {
|
let inner = match self.addr {
|
||||||
None => Either::Left(None),
|
None => Either::Left(None),
|
||||||
@ -113,7 +114,7 @@ impl<T: Address> Connect<T> {
|
|||||||
ConnectAddrsIter { inner }
|
ConnectAddrsIter { inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Takes preresolved addresses of the request.
|
/// Takes pre-resolved addresses of the request.
|
||||||
pub fn take_addrs(&mut self) -> ConnectTakeAddrsIter {
|
pub fn take_addrs(&mut self) -> ConnectTakeAddrsIter {
|
||||||
let inner = match self.addr.take() {
|
let inner = match self.addr.take() {
|
||||||
None => Either::Left(None),
|
None => Either::Left(None),
|
||||||
|
@ -13,7 +13,7 @@ use futures_util::future::{err, ok, BoxFuture, Either, FutureExt, Ready};
|
|||||||
use super::connect::{Address, Connect, Connection};
|
use super::connect::{Address, Connect, Connection};
|
||||||
use super::error::ConnectError;
|
use super::error::ConnectError;
|
||||||
|
|
||||||
/// Tcp connector service factory
|
/// TCP connector service factory
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TcpConnectorFactory<T>(PhantomData<T>);
|
pub struct TcpConnectorFactory<T>(PhantomData<T>);
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ impl<T> TcpConnectorFactory<T> {
|
|||||||
TcpConnectorFactory(PhantomData)
|
TcpConnectorFactory(PhantomData)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create tcp connector service
|
/// Create TCP connector service
|
||||||
pub fn service(&self) -> TcpConnector<T> {
|
pub fn service(&self) -> TcpConnector<T> {
|
||||||
TcpConnector(PhantomData)
|
TcpConnector(PhantomData)
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ impl<T: Address> ServiceFactory for TcpConnectorFactory<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tcp connector service
|
/// TCP connector service
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct TcpConnector<T>(PhantomData<T>);
|
pub struct TcpConnector<T>(PhantomData<T>);
|
||||||
|
|
||||||
@ -74,6 +74,7 @@ impl<T: Address> Service for TcpConnector<T> {
|
|||||||
type Request = Connect<T>;
|
type Request = Connect<T>;
|
||||||
type Response = Connection<T, TcpStream>;
|
type Response = Connection<T, TcpStream>;
|
||||||
type Error = ConnectError;
|
type Error = ConnectError;
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
type Future = Either<TcpConnectorResponse<T>, Ready<Result<Self::Response, Self::Error>>>;
|
type Future = Either<TcpConnectorResponse<T>, Ready<Result<Self::Response, Self::Error>>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
@ -94,7 +95,7 @@ impl<T: Address> Service for TcpConnector<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Tcp stream connector response future
|
/// TCP stream connector response future
|
||||||
pub struct TcpConnectorResponse<T> {
|
pub struct TcpConnectorResponse<T> {
|
||||||
req: Option<T>,
|
req: Option<T>,
|
||||||
port: u16,
|
port: u16,
|
||||||
|
@ -20,7 +20,7 @@ pub enum ConnectError {
|
|||||||
#[display(fmt = "Connector received `Connect` method with unresolved host")]
|
#[display(fmt = "Connector received `Connect` method with unresolved host")]
|
||||||
Unresolved,
|
Unresolved,
|
||||||
|
|
||||||
/// Connection io error
|
/// Connection IO error
|
||||||
#[display(fmt = "{}", _0)]
|
#[display(fmt = "{}", _0)]
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
//! Actix connect - tcp connector service
|
//! TCP connector service for Actix ecosystem.
|
||||||
//!
|
//!
|
||||||
//! ## Package feature
|
//! ## Package feature
|
||||||
//!
|
//!
|
||||||
//! * `openssl` - enables ssl support via `openssl` crate
|
//! * `openssl` - enables ssl support via `openssl` crate
|
||||||
//! * `rustls` - enables ssl support via `rustls` crate
|
//! * `rustls` - enables ssl support via `rustls` crate
|
||||||
#![deny(rust_2018_idioms, warnings)]
|
|
||||||
#![allow(clippy::type_complexity)]
|
#![deny(rust_2018_idioms)]
|
||||||
#![recursion_limit = "128"]
|
#![recursion_limit = "128"]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -71,7 +71,7 @@ pub async fn start_default_resolver() -> Result<AsyncResolver, ConnectError> {
|
|||||||
get_default_resolver().await
|
get_default_resolver().await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create tcp connector service
|
/// Create TCP connector service.
|
||||||
pub fn new_connector<T: Address + 'static>(
|
pub fn new_connector<T: Address + 'static>(
|
||||||
resolver: AsyncResolver,
|
resolver: AsyncResolver,
|
||||||
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
|
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
|
||||||
@ -79,7 +79,7 @@ pub fn new_connector<T: Address + 'static>(
|
|||||||
pipeline(Resolver::new(resolver)).and_then(TcpConnector::new())
|
pipeline(Resolver::new(resolver)).and_then(TcpConnector::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create tcp connector service
|
/// Create TCP connector service factory.
|
||||||
pub fn new_connector_factory<T: Address + 'static>(
|
pub fn new_connector_factory<T: Address + 'static>(
|
||||||
resolver: AsyncResolver,
|
resolver: AsyncResolver,
|
||||||
) -> impl ServiceFactory<
|
) -> impl ServiceFactory<
|
||||||
@ -92,14 +92,14 @@ pub fn new_connector_factory<T: Address + 'static>(
|
|||||||
pipeline_factory(ResolverFactory::new(resolver)).and_then(TcpConnectorFactory::new())
|
pipeline_factory(ResolverFactory::new(resolver)).and_then(TcpConnectorFactory::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create connector service with default parameters
|
/// Create connector service with default parameters.
|
||||||
pub fn default_connector<T: Address + 'static>(
|
pub fn default_connector<T: Address + 'static>(
|
||||||
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
|
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
|
||||||
+ Clone {
|
+ Clone {
|
||||||
pipeline(Resolver::default()).and_then(TcpConnector::new())
|
pipeline(Resolver::default()).and_then(TcpConnector::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create connector service factory with default parameters
|
/// Create connector service factory with default parameters.
|
||||||
pub fn default_connector_factory<T: Address + 'static>() -> impl ServiceFactory<
|
pub fn default_connector_factory<T: Address + 'static>() -> impl ServiceFactory<
|
||||||
Config = (),
|
Config = (),
|
||||||
Request = Connect<T>,
|
Request = Connect<T>,
|
||||||
|
@ -106,6 +106,7 @@ impl<T: Address> Service for Resolver<T> {
|
|||||||
type Request = Connect<T>;
|
type Request = Connect<T>;
|
||||||
type Response = Connect<T>;
|
type Response = Connect<T>;
|
||||||
type Error = ConnectError;
|
type Error = ConnectError;
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>,
|
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>,
|
||||||
Ready<Result<Connect<T>, Self::Error>>,
|
Ready<Result<Connect<T>, Self::Error>>,
|
||||||
|
@ -114,6 +114,7 @@ enum ConnectState<T: Address> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Address> ConnectState<T> {
|
impl<T: Address> ConnectState<T> {
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
fn poll(
|
fn poll(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
|
@ -17,7 +17,7 @@ use crate::{
|
|||||||
Address, Connect, ConnectError, ConnectService, ConnectServiceFactory, Connection,
|
Address, Connect, ConnectError, ConnectService, ConnectServiceFactory, Connection,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Openssl connector factory
|
/// OpenSSL connector factory
|
||||||
pub struct OpensslConnector<T, U> {
|
pub struct OpensslConnector<T, U> {
|
||||||
connector: SslConnector,
|
connector: SslConnector,
|
||||||
_t: PhantomData<(T, U)>,
|
_t: PhantomData<(T, U)>,
|
||||||
@ -97,6 +97,7 @@ where
|
|||||||
type Request = Connection<T, U>;
|
type Request = Connection<T, U>;
|
||||||
type Response = Connection<T, SslStream<U>>;
|
type Response = Connection<T, SslStream<U>>;
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
type Future = Either<ConnectAsyncExt<T, U>, Ready<Result<Self::Response, Self::Error>>>;
|
type Future = Either<ConnectAsyncExt<T, U>, Ready<Result<Self::Response, Self::Error>>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
@ -164,7 +165,7 @@ impl<T> OpensslConnectServiceFactory<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct new connect service with custom dns resolver
|
/// Construct new connect service with custom DNS resolver
|
||||||
pub fn with_resolver(connector: SslConnector, resolver: AsyncResolver) -> Self {
|
pub fn with_resolver(connector: SslConnector, resolver: AsyncResolver) -> Self {
|
||||||
OpensslConnectServiceFactory {
|
OpensslConnectServiceFactory {
|
||||||
tcp: ConnectServiceFactory::with_resolver(resolver),
|
tcp: ConnectServiceFactory::with_resolver(resolver),
|
||||||
@ -172,7 +173,7 @@ impl<T> OpensslConnectServiceFactory<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct openssl connect service
|
/// Construct OpenSSL connect service
|
||||||
pub fn service(&self) -> OpensslConnectService<T> {
|
pub fn service(&self) -> OpensslConnectService<T> {
|
||||||
OpensslConnectService {
|
OpensslConnectService {
|
||||||
tcp: self.tcp.service(),
|
tcp: self.tcp.service(),
|
||||||
|
@ -88,9 +88,9 @@ async fn test_new_service() {
|
|||||||
assert_eq!(con.peer_addr().unwrap(), srv.addr());
|
assert_eq!(con.peer_addr().unwrap(), srv.addr());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
#[cfg(all(feature = "openssl", feature = "uri"))]
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_uri() {
|
async fn test_openssl_uri() {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
let srv = TestServer::with(|| {
|
let srv = TestServer::with(|| {
|
||||||
@ -107,7 +107,7 @@ async fn test_uri() {
|
|||||||
assert_eq!(con.peer_addr().unwrap(), srv.addr());
|
assert_eq!(con.peer_addr().unwrap(), srv.addr());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rustls")]
|
#[cfg(all(feature = "rustls", feature = "uri"))]
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_rustls_uri() {
|
async fn test_rustls_uri() {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user