mirror of https://github.com/fafhrd91/actix-net
update openssl impl
This commit is contained in:
parent
210f183aa0
commit
b12b3b12a9
|
@ -36,7 +36,7 @@ actix-server-config = "0.2.0"
|
||||||
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
num_cpus = "1.0"
|
num_cpus = "1.0"
|
||||||
|
pin-project = "0.4.5"
|
||||||
mio = "0.6.19"
|
mio = "0.6.19"
|
||||||
net2 = "0.2"
|
net2 = "0.2"
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
|
|
|
@ -13,10 +13,10 @@ mod nativetls;
|
||||||
#[cfg(feature = "nativetls")]
|
#[cfg(feature = "nativetls")]
|
||||||
pub use self::nativetls::NativeTlsAcceptor;
|
pub use self::nativetls::NativeTlsAcceptor;
|
||||||
|
|
||||||
#[cfg(feature = "rustls")]
|
//#[cfg(feature = "rustls")]
|
||||||
mod rustls;
|
//mod rustls;
|
||||||
#[cfg(feature = "rustls")]
|
//#[cfg(feature = "rustls")]
|
||||||
pub use self::rustls::RustlsAcceptor;
|
//pub use self::rustls::RustlsAcceptor;
|
||||||
|
|
||||||
/// Sets the maximum per-worker concurrent ssl connection establish process.
|
/// Sets the maximum per-worker concurrent ssl connection establish process.
|
||||||
///
|
///
|
||||||
|
|
|
@ -3,10 +3,7 @@ use std::marker::PhantomData;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use futures::{
|
use futures::future::{self, FutureExt as _, LocalBoxFuture, TryFutureExt as _};
|
||||||
future::{self, LocalBoxFuture},
|
|
||||||
FutureExt as _, TryFutureExt as _,
|
|
||||||
};
|
|
||||||
use native_tls::Error;
|
use native_tls::Error;
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
use tokio_tls::{TlsAcceptor, TlsStream};
|
use tokio_tls::{TlsAcceptor, TlsStream};
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
|
use std::future::Future;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
use std::pin::Pin;
|
||||||
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use actix_service::{NewService, Service};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use futures::{future::ok, future::Ready, Future, FutureExt, Poll};
|
use futures::future::{ok, FutureExt, LocalBoxFuture, Ready};
|
||||||
use openssl::ssl::SslAcceptor;
|
use open_ssl::ssl::SslAcceptor;
|
||||||
|
use pin_project::pin_project;
|
||||||
use tokio_io::{AsyncRead, AsyncWrite};
|
use tokio_io::{AsyncRead, AsyncWrite};
|
||||||
use tokio_openssl::{HandshakeError, SslStream};
|
use tokio_openssl::{HandshakeError, SslStream};
|
||||||
|
|
||||||
use crate::counter::{Counter, CounterGuard};
|
use crate::counter::{Counter, CounterGuard};
|
||||||
use crate::ssl::MAX_CONN_COUNTER;
|
use crate::ssl::MAX_CONN_COUNTER;
|
||||||
use crate::{Io, Protocol, ServerConfig};
|
use crate::{Io, Protocol, ServerConfig};
|
||||||
use futures::future::LocalBoxFuture;
|
|
||||||
use std::io;
|
|
||||||
use std::pin::Pin;
|
|
||||||
use std::task::Context;
|
|
||||||
|
|
||||||
/// Support `SSL` connections via openssl package
|
/// Support `SSL` connections via openssl package
|
||||||
///
|
///
|
||||||
|
@ -41,7 +41,7 @@ impl<T: AsyncRead + AsyncWrite, P> Clone for OpensslAcceptor<T, P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsyncRead + AsyncWrite + Unpin + 'static, P> NewService for OpensslAcceptor<T, P> {
|
impl<T: AsyncRead + AsyncWrite + Unpin + 'static, P> ServiceFactory for OpensslAcceptor<T, P> {
|
||||||
type Request = Io<T, P>;
|
type Request = Io<T, P>;
|
||||||
type Response = Io<SslStream<T>, P>;
|
type Response = Io<SslStream<T>, P>;
|
||||||
type Error = HandshakeError<T>;
|
type Error = HandshakeError<T>;
|
||||||
|
@ -75,22 +75,13 @@ impl<T: AsyncRead + AsyncWrite + Unpin + 'static, P> Service for OpensslAcceptor
|
||||||
type Error = HandshakeError<T>;
|
type Error = HandshakeError<T>;
|
||||||
type Future = OpensslAcceptorServiceFut<T, P>;
|
type Future = OpensslAcceptorServiceFut<T, P>;
|
||||||
|
|
||||||
fn poll_ready(
|
fn poll_ready(&mut self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
self: Pin<&mut Self>,
|
if self.conns.available(ctx) {
|
||||||
ctx: &mut Context<'_>,
|
Poll::Ready(Ok(()))
|
||||||
) -> Poll<Result<(), Self::Error>> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
|
||||||
if self.conns.available() {
|
|
||||||
Ok(Async::Ready(()))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(Async::NotReady)
|
Poll::Pending
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: Self::Request) -> Self::Future {
|
||||||
let (io, params, _) = req.into_parts();
|
let (io, params, _) = req.into_parts();
|
||||||
|
@ -107,10 +98,12 @@ impl<T: AsyncRead + AsyncWrite + Unpin + 'static, P> Service for OpensslAcceptor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pin_project]
|
||||||
pub struct OpensslAcceptorServiceFut<T, P>
|
pub struct OpensslAcceptorServiceFut<T, P>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
|
#[pin]
|
||||||
fut: LocalBoxFuture<'static, Result<SslStream<T>, HandshakeError<T>>>,
|
fut: LocalBoxFuture<'static, Result<SslStream<T>, HandshakeError<T>>>,
|
||||||
params: Option<P>,
|
params: Option<P>,
|
||||||
_guard: CounterGuard,
|
_guard: CounterGuard,
|
||||||
|
@ -120,16 +113,10 @@ impl<T: AsyncRead + AsyncWrite, P> Future for OpensslAcceptorServiceFut<T, P> {
|
||||||
type Output = Result<Io<SslStream<T>, P>, HandshakeError<T>>;
|
type Output = Result<Io<SslStream<T>, P>, HandshakeError<T>>;
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
unimplemented!()
|
let this = self.project();
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
let io = futures::ready!(this.fut.poll(cx))?;
|
||||||
type Item = Io<SslStream<T>, P>;
|
let proto = if let Some(protos) = io.ssl().selected_alpn_protocol() {
|
||||||
type Error = HandshakeError<T>;
|
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
|
||||||
let io = futures::ready!(self.fut.poll())?;
|
|
||||||
let proto = if let Some(protos) = io.get_ref().ssl().selected_alpn_protocol() {
|
|
||||||
const H2: &[u8] = b"\x02h2";
|
const H2: &[u8] = b"\x02h2";
|
||||||
const HTTP10: &[u8] = b"\x08http/1.0";
|
const HTTP10: &[u8] = b"\x08http/1.0";
|
||||||
const HTTP11: &[u8] = b"\x08http/1.1";
|
const HTTP11: &[u8] = b"\x08http/1.1";
|
||||||
|
@ -146,11 +133,7 @@ impl<T: AsyncRead + AsyncWrite, P> Future for OpensslAcceptorServiceFut<T, P> {
|
||||||
} else {
|
} else {
|
||||||
Protocol::Unknown
|
Protocol::Unknown
|
||||||
};
|
};
|
||||||
Ok(Async::Ready(Io::from_parts(
|
|
||||||
io,
|
Poll::Ready(Ok(Io::from_parts(io, this.params.take().unwrap(), proto)))
|
||||||
self.params.take().unwrap(),
|
|
||||||
proto,
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
|
use std::future::Future;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use actix_service::{NewService, Service};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use futures::{future::ok, future::FutureResult, Async, Future, Poll};
|
use futures::future::{ok, Ready};
|
||||||
use rustls::ServerConfig;
|
use pin_project::pin_project;
|
||||||
|
use rust_tls::ServerConfig;
|
||||||
use tokio_io::{AsyncRead, AsyncWrite};
|
use tokio_io::{AsyncRead, AsyncWrite};
|
||||||
use tokio_rustls::{server::TlsStream, Accept, TlsAcceptor};
|
use tokio_rustls::{server::TlsStream, Accept, TlsAcceptor};
|
||||||
|
|
||||||
use crate::counter::{Counter, CounterGuard};
|
use crate::counter::{Counter, CounterGuard};
|
||||||
use crate::ssl::MAX_CONN_COUNTER;
|
use crate::ssl::MAX_CONN_COUNTER;
|
||||||
use crate::{Io, Protocol, ServerConfig as SrvConfig};
|
use crate::{Io, Protocol, ServerConfig as SrvConfig};
|
||||||
use std::pin::Pin;
|
|
||||||
use std::task::Context;
|
|
||||||
|
|
||||||
/// Support `SSL` connections via rustls package
|
/// Support `SSL` connections via rustls package
|
||||||
///
|
///
|
||||||
|
@ -41,7 +43,7 @@ impl<T, P> Clone for RustlsAcceptor<T, P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsyncRead + AsyncWrite, P> NewService for RustlsAcceptor<T, P> {
|
impl<T: AsyncRead + AsyncWrite, P> ServiceFactory for RustlsAcceptor<T, P> {
|
||||||
type Request = Io<T, P>;
|
type Request = Io<T, P>;
|
||||||
type Response = Io<TlsStream<T>, P>;
|
type Response = Io<TlsStream<T>, P>;
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
|
@ -49,7 +51,7 @@ impl<T: AsyncRead + AsyncWrite, P> NewService for RustlsAcceptor<T, P> {
|
||||||
type Config = SrvConfig;
|
type Config = SrvConfig;
|
||||||
type Service = RustlsAcceptorService<T, P>;
|
type Service = RustlsAcceptorService<T, P>;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Future = FutureResult<Self::Service, Self::InitError>;
|
type Future = Ready<Result<Self::Service, Self::InitError>>;
|
||||||
|
|
||||||
fn new_service(&self, cfg: &SrvConfig) -> Self::Future {
|
fn new_service(&self, cfg: &SrvConfig) -> Self::Future {
|
||||||
cfg.set_secure();
|
cfg.set_secure();
|
||||||
|
@ -76,14 +78,11 @@ impl<T: AsyncRead + AsyncWrite, P> Service for RustlsAcceptorService<T, P> {
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
type Future = RustlsAcceptorServiceFut<T, P>;
|
type Future = RustlsAcceptorServiceFut<T, P>;
|
||||||
|
|
||||||
fn poll_ready(
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
self: Pin<&mut Self>,
|
|
||||||
ctx: &mut Context<'_>,
|
|
||||||
) -> Poll<Result<(), Self::Error>> {
|
|
||||||
if self.conns.available(cx) {
|
if self.conns.available(cx) {
|
||||||
Ok(Async::Ready(()))
|
Poll::Ready(Ok(()))
|
||||||
} else {
|
} else {
|
||||||
Ok(Async::NotReady)
|
Poll::Pending
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,24 +96,26 @@ impl<T: AsyncRead + AsyncWrite, P> Service for RustlsAcceptorService<T, P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pin_project]
|
||||||
pub struct RustlsAcceptorServiceFut<T, P>
|
pub struct RustlsAcceptorServiceFut<T, P>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
|
#[pin]
|
||||||
fut: Accept<T>,
|
fut: Accept<T>,
|
||||||
params: Option<P>,
|
params: Option<P>,
|
||||||
_guard: CounterGuard,
|
_guard: CounterGuard,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsyncRead + AsyncWrite, P> Future for RustlsAcceptorServiceFut<T, P> {
|
impl<T: AsyncRead + AsyncWrite, P> Future for RustlsAcceptorServiceFut<T, P> {
|
||||||
type Item = Io<TlsStream<T>, P>;
|
type Output = Result<Io<TlsStream<T>, P>, io::Error>;
|
||||||
type Error = io::Error;
|
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
||||||
let io = futures::try_ready!(self.fut.poll());
|
let this = self.project();
|
||||||
Ok(Async::Ready(Io::from_parts(
|
let io = futures::ready!(this.fut.poll(cx));
|
||||||
|
Poll::Ready(Ok(Io::from_parts(
|
||||||
io,
|
io,
|
||||||
self.params.take().unwrap(),
|
this.params.take().unwrap(),
|
||||||
Protocol::Unknown,
|
Protocol::Unknown,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue