From ba006d95c712fd68dceaa5066d0534cbab9119ba Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 10 Dec 2018 08:42:31 -0800 Subject: [PATCH] prepare actix-utils --- Cargo.toml | 3 +- actix-connector/CHANGES.md | 5 + actix-connector/Cargo.toml | 47 ++++++++++ {src => actix-connector/src}/connector.rs | 0 actix-connector/src/lib.rs | 15 +++ {src => actix-connector/src}/resolver.rs | 0 src/lib.rs | 18 +--- src/ssl/mod.rs | 6 -- src/ssl/openssl.rs | 108 ---------------------- 9 files changed, 70 insertions(+), 132 deletions(-) create mode 100644 actix-connector/CHANGES.md create mode 100644 actix-connector/Cargo.toml rename {src => actix-connector/src}/connector.rs (100%) create mode 100644 actix-connector/src/lib.rs rename {src => actix-connector/src}/resolver.rs (100%) delete mode 100644 src/ssl/mod.rs delete mode 100644 src/ssl/openssl.rs diff --git a/Cargo.toml b/Cargo.toml index e7b40ec3f..1f8bf448a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,13 +17,14 @@ edition = "2018" members = [ "./", "actix-codec", + "actix-connector", "actix-service", "actix-server", "actix-rt", ] [package.metadata.docs.rs] -features = ["ssl", "tls", "rust-tls"] +features = ["ssl"] [badges] travis-ci = { repository = "actix/actix-net", branch = "master" } diff --git a/actix-connector/CHANGES.md b/actix-connector/CHANGES.md new file mode 100644 index 000000000..953441ef7 --- /dev/null +++ b/actix-connector/CHANGES.md @@ -0,0 +1,5 @@ +# Changes + +## [0.1.0] - 2018-12-09 + +* Move server to separate crate diff --git a/actix-connector/Cargo.toml b/actix-connector/Cargo.toml new file mode 100644 index 000000000..4a86ee049 --- /dev/null +++ b/actix-connector/Cargo.toml @@ -0,0 +1,47 @@ +[package] +name = "actix-connector" +version = "0.1.0" +authors = ["Nikolay Kim "] +description = "Actix Connector - tcp connector service" +readme = "README.md" +keywords = ["network", "framework", "async", "futures"] +homepage = "https://actix.rs" +repository = "https://github.com/actix/actix-net.git" +documentation = "https://docs.rs/actix-net/" +categories = ["network-programming", "asynchronous"] +license = "MIT/Apache-2.0" +exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"] +edition = "2018" +workspace = "../" + +[package.metadata.docs.rs] +features = ["ssl"] + +[lib] +name = "actix_connector" +path = "src/lib.rs" + +[features] +default = [] + +# openssl +ssl = ["openssl", "tokio-openssl"] + +[dependencies] +actix-service = "0.1.1" +actix-codec = { path = "../actix-codec" } +actix-rt = { path = "../actix-rt" } +futures = "0.1" +tokio-tcp = "0.1" + +trust-dns-proto = "^0.5.0" +trust-dns-resolver = "^0.10.0" + +# openssl +openssl = { version="0.10", optional = true } +tokio-openssl = { version="0.3", optional = true } + +[profile.release] +lto = true +opt-level = 3 +codegen-units = 1 diff --git a/src/connector.rs b/actix-connector/src/connector.rs similarity index 100% rename from src/connector.rs rename to actix-connector/src/connector.rs diff --git a/actix-connector/src/lib.rs b/actix-connector/src/lib.rs new file mode 100644 index 000000000..a364dfcf0 --- /dev/null +++ b/actix-connector/src/lib.rs @@ -0,0 +1,15 @@ +//! Actix Connector - tcp connector service +//! +//! ## Package feature +//! +//! * `tls` - enables ssl support via `native-tls` crate +//! * `ssl` - enables ssl support via `openssl` crate +//! * `rust-tls` - enables ssl support via `rustls` crate + +mod connector; +mod resolver; + +pub use self::connector::{ + Connect, Connector, ConnectorError, DefaultConnector, RequestPort, TcpConnector, +}; +pub use self::resolver::{RequestHost, Resolver}; diff --git a/src/resolver.rs b/actix-connector/src/resolver.rs similarity index 100% rename from src/resolver.rs rename to actix-connector/src/resolver.rs diff --git a/src/lib.rs b/src/lib.rs index 0e618c199..6fe708487 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,27 +1,11 @@ -//! Actix net - framework for the compisible network services for Rust. -//! -//! ## Package feature -//! -//! * `tls` - enables ssl support via `native-tls` crate -//! * `ssl` - enables ssl support via `openssl` crate -//! * `rust-tls` - enables ssl support via `rustls` crate -// #![warn(missing_docs)] - -#![allow( - clippy::declare_interior_mutable_const, - clippy::borrow_interior_mutable_const -)] - +//! Actix utils - various helper services mod cell; pub mod cloneable; -pub mod connector; pub mod counter; pub mod either; pub mod framed; pub mod inflight; pub mod keepalive; -pub mod resolver; -pub mod ssl; pub mod stream; pub mod time; pub mod timeout; diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs deleted file mode 100644 index ecbd0a88d..000000000 --- a/src/ssl/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -//! SSL Services - -#[cfg(feature = "ssl")] -mod openssl; -#[cfg(feature = "ssl")] -pub use self::openssl::OpensslConnector; diff --git a/src/ssl/openssl.rs b/src/ssl/openssl.rs deleted file mode 100644 index caaa18a5d..000000000 --- a/src/ssl/openssl.rs +++ /dev/null @@ -1,108 +0,0 @@ -use std::marker::PhantomData; - -use actix_service::{NewService, Service}; -use futures::{future::ok, future::FutureResult, Async, Future, Poll}; -use openssl::ssl::{Error, SslAcceptor, SslConnector}; -use tokio_io::{AsyncRead, AsyncWrite}; -use tokio_openssl::{AcceptAsync, ConnectAsync, SslAcceptorExt, SslConnectorExt, SslStream}; - -use super::MAX_CONN_COUNTER; -use crate::counter::{Counter, CounterGuard}; -use crate::resolver::RequestHost; - -/// Openssl connector factory -pub struct OpensslConnector { - connector: SslConnector, - _t: PhantomData<(R, T, E)>, -} - -impl OpensslConnector { - pub fn new(connector: SslConnector) -> Self { - OpensslConnector { - connector, - _t: PhantomData, - } - } -} - -impl OpensslConnector { - pub fn service( - connector: SslConnector, - ) -> impl Service<(R, T), Response = (R, SslStream), Error = Error> { - OpensslConnectorService { - connector: connector, - _t: PhantomData, - } - } -} - -impl Clone for OpensslConnector { - fn clone(&self) -> Self { - Self { - connector: self.connector.clone(), - _t: PhantomData, - } - } -} - -impl NewService<(R, T)> - for OpensslConnector -{ - type Response = (R, SslStream); - type Error = Error; - type Service = OpensslConnectorService; - type InitError = E; - type Future = FutureResult; - - fn new_service(&self) -> Self::Future { - ok(OpensslConnectorService { - connector: self.connector.clone(), - _t: PhantomData, - }) - } -} - -pub struct OpensslConnectorService { - connector: SslConnector, - _t: PhantomData<(R, T)>, -} - -impl Service<(R, T)> - for OpensslConnectorService -{ - type Response = (R, SslStream); - type Error = Error; - type Future = ConnectAsyncExt; - - fn poll_ready(&mut self) -> Poll<(), Self::Error> { - Ok(Async::Ready(())) - } - - fn call(&mut self, (req, stream): (R, T)) -> Self::Future { - ConnectAsyncExt { - fut: SslConnectorExt::connect_async(&self.connector, req.host(), stream), - req: Some(req), - } - } -} - -pub struct ConnectAsyncExt { - req: Option, - fut: ConnectAsync, -} - -impl Future for ConnectAsyncExt -where - R: RequestHost, - T: AsyncRead + AsyncWrite, -{ - type Item = (R, SslStream); - type Error = Error; - - fn poll(&mut self) -> Poll { - match self.fut.poll()? { - Async::Ready(stream) => Ok(Async::Ready((self.req.take().unwrap(), stream))), - Async::NotReady => Ok(Async::NotReady), - } - } -}