mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-23 22:51:07 +01:00
move helper services to separate package
This commit is contained in:
parent
ba006d95c7
commit
d35c87d228
57
Cargo.toml
57
Cargo.toml
@ -15,65 +15,10 @@ edition = "2018"
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"./",
|
||||
"actix-codec",
|
||||
"actix-connector",
|
||||
"actix-service",
|
||||
"actix-server",
|
||||
"actix-rt",
|
||||
"actix-utils",
|
||||
]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["ssl"]
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "actix/actix-net", branch = "master" }
|
||||
# appveyor = { repository = "fafhrd91/actix-web-hdy9d" }
|
||||
codecov = { repository = "actix/actix-net", branch = "master", service = "github" }
|
||||
|
||||
[lib]
|
||||
name = "actix_net"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
# openssl
|
||||
ssl = ["openssl", "tokio-openssl"]
|
||||
|
||||
cell = []
|
||||
|
||||
[dependencies]
|
||||
actix-service = "0.1.1"
|
||||
actix-codec = { path = "actix-codec" }
|
||||
actix-rt = { path = "actix-rt" }
|
||||
|
||||
log = "0.4"
|
||||
num_cpus = "1.0"
|
||||
|
||||
# io
|
||||
mio = "^0.6.13"
|
||||
net2 = "0.2"
|
||||
bytes = "0.4"
|
||||
futures = "0.1"
|
||||
slab = "0.4"
|
||||
tokio-io = "0.1"
|
||||
tokio-tcp = "0.1"
|
||||
tokio-timer = "0.2"
|
||||
tokio-reactor = "0.1"
|
||||
tokio-signal = "0.2"
|
||||
|
||||
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 }
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.5"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
opt-level = 3
|
||||
codegen-units = 1
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
mod connector;
|
||||
mod resolver;
|
||||
pub mod ssl;
|
||||
|
||||
pub use self::connector::{
|
||||
Connect, Connector, ConnectorError, DefaultConnector, RequestPort, TcpConnector,
|
||||
|
6
actix-connector/src/ssl/mod.rs
Normal file
6
actix-connector/src/ssl/mod.rs
Normal file
@ -0,0 +1,6 @@
|
||||
//! SSL Services
|
||||
|
||||
#[cfg(feature = "ssl")]
|
||||
mod openssl;
|
||||
#[cfg(feature = "ssl")]
|
||||
pub use self::openssl::OpensslConnector;
|
106
actix-connector/src/ssl/openssl.rs
Normal file
106
actix-connector/src/ssl/openssl.rs
Normal file
@ -0,0 +1,106 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use actix_service::{NewService, Service};
|
||||
use futures::{future::ok, future::FutureResult, Async, Future, Poll};
|
||||
use openssl::ssl::{HandshakeError, SslConnector};
|
||||
use tokio_openssl::{ConnectAsync, SslConnectorExt, SslStream};
|
||||
|
||||
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 = HandshakeError<T>> {
|
||||
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 = HandshakeError<T>;
|
||||
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 = HandshakeError<T>;
|
||||
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 = HandshakeError<T>;
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
5
actix-utils/CHANGES.md
Normal file
5
actix-utils/CHANGES.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Changes
|
||||
|
||||
## [0.1.0] - 2018-12-09
|
||||
|
||||
* Move utils services to separate crate
|
34
actix-utils/Cargo.toml
Normal file
34
actix-utils/Cargo.toml
Normal file
@ -0,0 +1,34 @@
|
||||
[package]
|
||||
name = "actix-utils"
|
||||
version = "0.1.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Actix utils - various actix net related services"
|
||||
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-utils/"
|
||||
categories = ["network-programming", "asynchronous"]
|
||||
license = "MIT/Apache-2.0"
|
||||
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
|
||||
edition = "2018"
|
||||
workspace = "../"
|
||||
|
||||
[lib]
|
||||
name = "actix_utils"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-service = "0.1.1"
|
||||
actix-codec = { path = "../actix-codec" }
|
||||
actix-rt = { path = "../actix-rt" }
|
||||
|
||||
# io
|
||||
bytes = "0.4"
|
||||
futures = "0.1"
|
||||
tokio-timer = "0.2.8"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
opt-level = 3
|
||||
codegen-units = 1
|
@ -2,13 +2,12 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
|
||||
use actix_codec::{Decoder, Encoder, Framed};
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed};
|
||||
use actix_rt::Arbiter;
|
||||
use actix_service::{IntoNewService, IntoService, NewService, Service};
|
||||
use futures::future::{ok, FutureResult};
|
||||
use futures::unsync::mpsc;
|
||||
use futures::{Async, AsyncSink, Future, Poll, Sink, Stream};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
type Request<U> = <U as Decoder>::Item;
|
||||
type Response<U> = <U as Encoder>::Item;
|
Loading…
Reference in New Issue
Block a user