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

prepare actix-utils

This commit is contained in:
Nikolay Kim 2018-12-10 08:42:31 -08:00
parent 9577b7bbed
commit ba006d95c7
9 changed files with 70 additions and 132 deletions

View File

@ -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" }

View File

@ -0,0 +1,5 @@
# Changes
## [0.1.0] - 2018-12-09
* Move server to separate crate

View File

@ -0,0 +1,47 @@
[package]
name = "actix-connector"
version = "0.1.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
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

View File

@ -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};

View File

@ -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;

View File

@ -1,6 +0,0 @@
//! SSL Services
#[cfg(feature = "ssl")]
mod openssl;
#[cfg(feature = "ssl")]
pub use self::openssl::OpensslConnector;

View File

@ -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<R, T, E> {
connector: SslConnector,
_t: PhantomData<(R, T, E)>,
}
impl<R, T, E> OpensslConnector<R, T, E> {
pub fn new(connector: SslConnector) -> Self {
OpensslConnector {
connector,
_t: PhantomData,
}
}
}
impl<R: RequestHost, T: AsyncRead + AsyncWrite> OpensslConnector<R, T, ()> {
pub fn service(
connector: SslConnector,
) -> impl Service<(R, T), Response = (R, SslStream<T>), Error = Error> {
OpensslConnectorService {
connector: connector,
_t: PhantomData,
}
}
}
impl<R, T, E> Clone for OpensslConnector<R, T, E> {
fn clone(&self) -> Self {
Self {
connector: self.connector.clone(),
_t: PhantomData,
}
}
}
impl<R: RequestHost, T: AsyncRead + AsyncWrite, E> NewService<(R, T)>
for OpensslConnector<R, T, E>
{
type Response = (R, SslStream<T>);
type Error = Error;
type Service = OpensslConnectorService<R, T>;
type InitError = E;
type Future = FutureResult<Self::Service, Self::InitError>;
fn new_service(&self) -> Self::Future {
ok(OpensslConnectorService {
connector: self.connector.clone(),
_t: PhantomData,
})
}
}
pub struct OpensslConnectorService<R, T> {
connector: SslConnector,
_t: PhantomData<(R, T)>,
}
impl<R: RequestHost, T: AsyncRead + AsyncWrite> Service<(R, T)>
for OpensslConnectorService<R, T>
{
type Response = (R, SslStream<T>);
type Error = Error;
type Future = ConnectAsyncExt<R, T>;
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<R, T> {
req: Option<R>,
fut: ConnectAsync<T>,
}
impl<R, T> Future for ConnectAsyncExt<R, T>
where
R: RequestHost,
T: AsyncRead + AsyncWrite,
{
type Item = (R, SslStream<T>);
type Error = Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
match self.fut.poll()? {
Async::Ready(stream) => Ok(Async::Ready((self.req.take().unwrap(), stream))),
Async::NotReady => Ok(Async::NotReady),
}
}
}