Skip to content

Commit d35c87d

Browse files
committed
move helper services to separate package
1 parent ba006d9 commit d35c87d

File tree

17 files changed

+154
-58
lines changed

17 files changed

+154
-58
lines changed

Cargo.toml

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,65 +15,10 @@ edition = "2018"
1515

1616
[workspace]
1717
members = [
18-
"./",
1918
"actix-codec",
2019
"actix-connector",
2120
"actix-service",
2221
"actix-server",
2322
"actix-rt",
23+
"actix-utils",
2424
]
25-
26-
[package.metadata.docs.rs]
27-
features = ["ssl"]
28-
29-
[badges]
30-
travis-ci = { repository = "actix/actix-net", branch = "master" }
31-
# appveyor = { repository = "fafhrd91/actix-web-hdy9d" }
32-
codecov = { repository = "actix/actix-net", branch = "master", service = "github" }
33-
34-
[lib]
35-
name = "actix_net"
36-
path = "src/lib.rs"
37-
38-
[features]
39-
default = []
40-
41-
# openssl
42-
ssl = ["openssl", "tokio-openssl"]
43-
44-
cell = []
45-
46-
[dependencies]
47-
actix-service = "0.1.1"
48-
actix-codec = { path = "actix-codec" }
49-
actix-rt = { path = "actix-rt" }
50-
51-
log = "0.4"
52-
num_cpus = "1.0"
53-
54-
# io
55-
mio = "^0.6.13"
56-
net2 = "0.2"
57-
bytes = "0.4"
58-
futures = "0.1"
59-
slab = "0.4"
60-
tokio-io = "0.1"
61-
tokio-tcp = "0.1"
62-
tokio-timer = "0.2"
63-
tokio-reactor = "0.1"
64-
tokio-signal = "0.2"
65-
66-
trust-dns-proto = "^0.5.0"
67-
trust-dns-resolver = "^0.10.0"
68-
69-
# openssl
70-
openssl = { version="0.10", optional = true }
71-
tokio-openssl = { version="0.3", optional = true }
72-
73-
[dev-dependencies]
74-
env_logger = "0.5"
75-
76-
[profile.release]
77-
lto = true
78-
opt-level = 3
79-
codegen-units = 1

actix-connector/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
mod connector;
1010
mod resolver;
11+
pub mod ssl;
1112

1213
pub use self::connector::{
1314
Connect, Connector, ConnectorError, DefaultConnector, RequestPort, TcpConnector,

actix-connector/src/ssl/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! SSL Services
2+
3+
#[cfg(feature = "ssl")]
4+
mod openssl;
5+
#[cfg(feature = "ssl")]
6+
pub use self::openssl::OpensslConnector;

actix-connector/src/ssl/openssl.rs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
use std::marker::PhantomData;
2+
3+
use actix_codec::{AsyncRead, AsyncWrite};
4+
use actix_service::{NewService, Service};
5+
use futures::{future::ok, future::FutureResult, Async, Future, Poll};
6+
use openssl::ssl::{HandshakeError, SslConnector};
7+
use tokio_openssl::{ConnectAsync, SslConnectorExt, SslStream};
8+
9+
use crate::resolver::RequestHost;
10+
11+
/// Openssl connector factory
12+
pub struct OpensslConnector<R, T, E> {
13+
connector: SslConnector,
14+
_t: PhantomData<(R, T, E)>,
15+
}
16+
17+
impl<R, T, E> OpensslConnector<R, T, E> {
18+
pub fn new(connector: SslConnector) -> Self {
19+
OpensslConnector {
20+
connector,
21+
_t: PhantomData,
22+
}
23+
}
24+
}
25+
26+
impl<R: RequestHost, T: AsyncRead + AsyncWrite> OpensslConnector<R, T, ()> {
27+
pub fn service(
28+
connector: SslConnector,
29+
) -> impl Service<(R, T), Response = (R, SslStream<T>), Error = HandshakeError<T>> {
30+
OpensslConnectorService {
31+
connector: connector,
32+
_t: PhantomData,
33+
}
34+
}
35+
}
36+
37+
impl<R, T, E> Clone for OpensslConnector<R, T, E> {
38+
fn clone(&self) -> Self {
39+
Self {
40+
connector: self.connector.clone(),
41+
_t: PhantomData,
42+
}
43+
}
44+
}
45+
46+
impl<R: RequestHost, T: AsyncRead + AsyncWrite, E> NewService<(R, T)>
47+
for OpensslConnector<R, T, E>
48+
{
49+
type Response = (R, SslStream<T>);
50+
type Error = HandshakeError<T>;
51+
type Service = OpensslConnectorService<R, T>;
52+
type InitError = E;
53+
type Future = FutureResult<Self::Service, Self::InitError>;
54+
55+
fn new_service(&self) -> Self::Future {
56+
ok(OpensslConnectorService {
57+
connector: self.connector.clone(),
58+
_t: PhantomData,
59+
})
60+
}
61+
}
62+
63+
pub struct OpensslConnectorService<R, T> {
64+
connector: SslConnector,
65+
_t: PhantomData<(R, T)>,
66+
}
67+
68+
impl<R: RequestHost, T: AsyncRead + AsyncWrite> Service<(R, T)>
69+
for OpensslConnectorService<R, T>
70+
{
71+
type Response = (R, SslStream<T>);
72+
type Error = HandshakeError<T>;
73+
type Future = ConnectAsyncExt<R, T>;
74+
75+
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
76+
Ok(Async::Ready(()))
77+
}
78+
79+
fn call(&mut self, (req, stream): (R, T)) -> Self::Future {
80+
ConnectAsyncExt {
81+
fut: SslConnectorExt::connect_async(&self.connector, req.host(), stream),
82+
req: Some(req),
83+
}
84+
}
85+
}
86+
87+
pub struct ConnectAsyncExt<R, T> {
88+
req: Option<R>,
89+
fut: ConnectAsync<T>,
90+
}
91+
92+
impl<R, T> Future for ConnectAsyncExt<R, T>
93+
where
94+
R: RequestHost,
95+
T: AsyncRead + AsyncWrite,
96+
{
97+
type Item = (R, SslStream<T>);
98+
type Error = HandshakeError<T>;
99+
100+
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
101+
match self.fut.poll()? {
102+
Async::Ready(stream) => Ok(Async::Ready((self.req.take().unwrap(), stream))),
103+
Async::NotReady => Ok(Async::NotReady),
104+
}
105+
}
106+
}

actix-utils/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changes
2+
3+
## [0.1.0] - 2018-12-09
4+
5+
* Move utils services to separate crate

actix-utils/Cargo.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "actix-utils"
3+
version = "0.1.0"
4+
authors = ["Nikolay Kim <[email protected]>"]
5+
description = "Actix utils - various actix net related services"
6+
readme = "README.md"
7+
keywords = ["network", "framework", "async", "futures"]
8+
homepage = "https://actix.rs"
9+
repository = "https://github.com/actix/actix-net.git"
10+
documentation = "https://docs.rs/actix-utils/"
11+
categories = ["network-programming", "asynchronous"]
12+
license = "MIT/Apache-2.0"
13+
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
14+
edition = "2018"
15+
workspace = "../"
16+
17+
[lib]
18+
name = "actix_utils"
19+
path = "src/lib.rs"
20+
21+
[dependencies]
22+
actix-service = "0.1.1"
23+
actix-codec = { path = "../actix-codec" }
24+
actix-rt = { path = "../actix-rt" }
25+
26+
# io
27+
bytes = "0.4"
28+
futures = "0.1"
29+
tokio-timer = "0.2.8"
30+
31+
[profile.release]
32+
lto = true
33+
opt-level = 3
34+
codegen-units = 1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)