migrate server rustls support

This commit is contained in:
Nikolay Kim 2019-11-14 15:23:06 +06:00
parent ed83360605
commit b6f9a78011
3 changed files with 16 additions and 20 deletions

View File

@ -26,9 +26,6 @@ nativetls = ["native-tls", "tokio-tls"]
openssl = ["open-ssl", "tokio-openssl", "actix-server-config/openssl"]
rustls = ["rust-tls", "tokio-rustls", "webpki", "webpki-roots", "actix-server-config/rustls"]
# uds
# uds = ["mio-uds", "tokio-uds", "actix-server-config/uds"]
[dependencies]
actix-rt = "1.0.0-alpha.1"
actix-service = "1.0.0-alpha.1"
@ -49,7 +46,6 @@ tokio-timer = "0.3.0-alpha.6"
# unix domain sockets
mio-uds = { version = "0.6.7", optional = true }
#tokio-uds = { version="0.2.5", optional = true }
# nativetls
native-tls = { version = "0.2", optional = true }
@ -61,7 +57,8 @@ tokio-openssl = { version = "0.4.0-alpha.6", optional = true }
# rustls
rust-tls = { version = "0.16.0", package = "rustls", optional = true }
tokio-rustls = { version = "0.12.0-alpha.2", optional = true }
# tokio-rustls = { version = "0.12.0-alpha.2", optional = true }
tokio-rustls = { git = "https://github.com/quininer/tokio-rustls.git", branch = "tokio-0.2", optional = true }
webpki = { version = "0.21", optional = true }
webpki-roots = { version = "0.17", optional = true }

View File

@ -13,10 +13,10 @@ mod nativetls;
#[cfg(feature = "nativetls")]
pub use self::nativetls::NativeTlsAcceptor;
//#[cfg(feature = "rustls")]
//mod rustls;
//#[cfg(feature = "rustls")]
//pub use self::rustls::RustlsAcceptor;
#[cfg(feature = "rustls")]
mod rustls;
#[cfg(feature = "rustls")]
pub use self::rustls::RustlsAcceptor;
/// Sets the maximum per-worker concurrent ssl connection establish process.
///

View File

@ -43,7 +43,7 @@ impl<T, P> Clone for RustlsAcceptor<T, P> {
}
}
impl<T: AsyncRead + AsyncWrite, P> ServiceFactory for RustlsAcceptor<T, P> {
impl<T: AsyncRead + AsyncWrite + Unpin, P> ServiceFactory for RustlsAcceptor<T, P> {
type Request = Io<T, P>;
type Response = Io<TlsStream<T>, P>;
type Error = io::Error;
@ -72,13 +72,13 @@ pub struct RustlsAcceptorService<T, P> {
conns: Counter,
}
impl<T: AsyncRead + AsyncWrite, P> Service for RustlsAcceptorService<T, P> {
impl<T: AsyncRead + AsyncWrite + Unpin, P> Service for RustlsAcceptorService<T, P> {
type Request = Io<T, P>;
type Response = Io<TlsStream<T>, P>;
type Error = io::Error;
type Future = RustlsAcceptorServiceFut<T, P>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
fn poll_ready(&mut self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
if self.conns.available(cx) {
Poll::Ready(Ok(()))
} else {
@ -99,7 +99,7 @@ impl<T: AsyncRead + AsyncWrite, P> Service for RustlsAcceptorService<T, P> {
#[pin_project]
pub struct RustlsAcceptorServiceFut<T, P>
where
T: AsyncRead + AsyncWrite,
T: AsyncRead + AsyncWrite + Unpin,
{
#[pin]
fut: Accept<T>,
@ -107,16 +107,15 @@ where
_guard: CounterGuard,
}
impl<T: AsyncRead + AsyncWrite, P> Future for RustlsAcceptorServiceFut<T, P> {
impl<T: AsyncRead + AsyncWrite + Unpin, P> Future for RustlsAcceptorServiceFut<T, P> {
type Output = Result<Io<TlsStream<T>, P>, io::Error>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
let this = self.project();
let io = futures::ready!(this.fut.poll(cx));
Poll::Ready(Ok(Io::from_parts(
io,
this.params.take().unwrap(),
Protocol::Unknown,
)))
let params = this.params.take().unwrap();
Poll::Ready(
futures::ready!(this.fut.poll(cx))
.map(move |io| Io::from_parts(io, params, Protocol::Unknown)),
)
}
}