mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 22:32:57 +01:00
prepare actix-utils
This commit is contained in:
parent
9577b7bbed
commit
ba006d95c7
@ -17,13 +17,14 @@ edition = "2018"
|
|||||||
members = [
|
members = [
|
||||||
"./",
|
"./",
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
|
"actix-connector",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
"actix-server",
|
"actix-server",
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = ["ssl", "tls", "rust-tls"]
|
features = ["ssl"]
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "actix/actix-net", branch = "master" }
|
travis-ci = { repository = "actix/actix-net", branch = "master" }
|
||||||
|
5
actix-connector/CHANGES.md
Normal file
5
actix-connector/CHANGES.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.0] - 2018-12-09
|
||||||
|
|
||||||
|
* Move server to separate crate
|
47
actix-connector/Cargo.toml
Normal file
47
actix-connector/Cargo.toml
Normal 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
|
15
actix-connector/src/lib.rs
Normal file
15
actix-connector/src/lib.rs
Normal 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};
|
18
src/lib.rs
18
src/lib.rs
@ -1,27 +1,11 @@
|
|||||||
//! Actix net - framework for the compisible network services for Rust.
|
//! Actix utils - various helper services
|
||||||
//!
|
|
||||||
//! ## 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
|
|
||||||
)]
|
|
||||||
|
|
||||||
mod cell;
|
mod cell;
|
||||||
pub mod cloneable;
|
pub mod cloneable;
|
||||||
pub mod connector;
|
|
||||||
pub mod counter;
|
pub mod counter;
|
||||||
pub mod either;
|
pub mod either;
|
||||||
pub mod framed;
|
pub mod framed;
|
||||||
pub mod inflight;
|
pub mod inflight;
|
||||||
pub mod keepalive;
|
pub mod keepalive;
|
||||||
pub mod resolver;
|
|
||||||
pub mod ssl;
|
|
||||||
pub mod stream;
|
pub mod stream;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod timeout;
|
pub mod timeout;
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
//! SSL Services
|
|
||||||
|
|
||||||
#[cfg(feature = "ssl")]
|
|
||||||
mod openssl;
|
|
||||||
#[cfg(feature = "ssl")]
|
|
||||||
pub use self::openssl::OpensslConnector;
|
|
@ -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),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user