2019-11-15 10:54:11 +01:00
|
|
|
use std::future::Future;
|
2019-02-02 05:18:44 +01:00
|
|
|
use std::marker::PhantomData;
|
2019-11-15 10:54:11 +01:00
|
|
|
use std::pin::Pin;
|
|
|
|
use std::task::{Context, Poll};
|
2020-10-30 03:03:26 +01:00
|
|
|
use std::{net, rc::Rc};
|
2019-02-02 05:18:44 +01:00
|
|
|
|
2019-12-13 05:59:02 +01:00
|
|
|
use actix_codec::{AsyncRead, AsyncWrite};
|
2019-12-02 12:33:11 +01:00
|
|
|
use actix_rt::net::TcpStream;
|
|
|
|
use actix_service::{
|
2019-12-08 14:25:24 +01:00
|
|
|
fn_factory, fn_service, pipeline_factory, IntoServiceFactory, Service,
|
2019-12-02 12:33:11 +01:00
|
|
|
ServiceFactory,
|
|
|
|
};
|
2019-02-02 05:18:44 +01:00
|
|
|
use bytes::Bytes;
|
2021-03-26 19:24:51 +01:00
|
|
|
use futures_core::{future::LocalBoxFuture, ready};
|
|
|
|
use futures_util::future::ready;
|
2021-03-11 04:48:38 +01:00
|
|
|
use h2::server::{handshake, Handshake};
|
2019-02-02 05:18:44 +01:00
|
|
|
use log::error;
|
|
|
|
|
|
|
|
use crate::body::MessageBody;
|
2019-12-13 05:59:02 +01:00
|
|
|
use crate::config::ServiceConfig;
|
|
|
|
use crate::error::{DispatchError, Error};
|
2019-02-02 05:18:44 +01:00
|
|
|
use crate::request::Request;
|
|
|
|
use crate::response::Response;
|
2021-01-06 19:43:52 +01:00
|
|
|
use crate::service::HttpFlow;
|
|
|
|
use crate::{ConnectCallback, OnConnectData};
|
2019-02-02 05:18:44 +01:00
|
|
|
|
2019-02-06 20:44:15 +01:00
|
|
|
use super::dispatcher::Dispatcher;
|
2019-02-02 05:18:44 +01:00
|
|
|
|
2021-01-04 01:49:02 +01:00
|
|
|
/// `ServiceFactory` implementation for HTTP/2 transport
|
2019-12-02 12:33:11 +01:00
|
|
|
pub struct H2Service<T, S, B> {
|
2019-02-02 05:18:44 +01:00
|
|
|
srv: S,
|
|
|
|
cfg: ServiceConfig,
|
2020-10-30 03:03:26 +01:00
|
|
|
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
|
2021-01-04 01:49:02 +01:00
|
|
|
_phantom: PhantomData<(T, B)>,
|
2019-02-02 05:18:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:33:11 +01:00
|
|
|
impl<T, S, B> H2Service<T, S, B>
|
2019-02-02 05:18:44 +01:00
|
|
|
where
|
2021-01-04 00:47:04 +01:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2019-11-19 13:54:19 +01:00
|
|
|
S::Error: Into<Error> + 'static,
|
|
|
|
S::Response: Into<Response<B>> + 'static,
|
2021-01-04 00:47:04 +01:00
|
|
|
<S::Service as Service<Request>>::Future: 'static,
|
2019-02-06 20:44:15 +01:00
|
|
|
B: MessageBody + 'static,
|
2019-02-02 05:18:44 +01:00
|
|
|
{
|
2021-01-04 01:49:02 +01:00
|
|
|
/// Create new `H2Service` instance with config.
|
2021-01-04 00:47:04 +01:00
|
|
|
pub(crate) fn with_config<F: IntoServiceFactory<S, Request>>(
|
2019-11-15 10:54:11 +01:00
|
|
|
cfg: ServiceConfig,
|
|
|
|
service: F,
|
|
|
|
) -> Self {
|
2019-03-07 07:59:56 +01:00
|
|
|
H2Service {
|
|
|
|
cfg,
|
2020-10-30 03:03:26 +01:00
|
|
|
on_connect_ext: None,
|
2019-11-15 10:54:11 +01:00
|
|
|
srv: service.into_factory(),
|
2021-01-04 01:49:02 +01:00
|
|
|
_phantom: PhantomData,
|
2019-03-07 07:59:56 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-28 10:34:26 +02:00
|
|
|
|
2020-10-30 03:03:26 +01:00
|
|
|
/// Set on connect callback.
|
|
|
|
pub(crate) fn on_connect_ext(mut self, f: Option<Rc<ConnectCallback<T>>>) -> Self {
|
|
|
|
self.on_connect_ext = f;
|
|
|
|
self
|
|
|
|
}
|
2019-02-02 05:18:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:33:11 +01:00
|
|
|
impl<S, B> H2Service<TcpStream, S, B>
|
|
|
|
where
|
2021-01-04 00:47:04 +01:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2021-03-26 19:24:51 +01:00
|
|
|
S::Future: 'static,
|
2019-12-02 12:33:11 +01:00
|
|
|
S::Error: Into<Error> + 'static,
|
|
|
|
S::Response: Into<Response<B>> + 'static,
|
2021-01-04 00:47:04 +01:00
|
|
|
<S::Service as Service<Request>>::Future: 'static,
|
2019-12-02 12:33:11 +01:00
|
|
|
B: MessageBody + 'static,
|
|
|
|
{
|
2021-01-04 01:49:02 +01:00
|
|
|
/// Create plain TCP based service
|
2019-12-02 12:33:11 +01:00
|
|
|
pub fn tcp(
|
|
|
|
self,
|
|
|
|
) -> impl ServiceFactory<
|
2021-01-04 00:47:04 +01:00
|
|
|
TcpStream,
|
2019-12-02 12:33:11 +01:00
|
|
|
Config = (),
|
|
|
|
Response = (),
|
|
|
|
Error = DispatchError,
|
|
|
|
InitError = S::InitError,
|
|
|
|
> {
|
2021-03-26 19:24:51 +01:00
|
|
|
pipeline_factory(fn_factory(|| {
|
|
|
|
ready(Ok::<_, S::InitError>(fn_service(|io: TcpStream| {
|
2020-02-27 03:10:55 +01:00
|
|
|
let peer_addr = io.peer_addr().ok();
|
2021-03-26 19:24:51 +01:00
|
|
|
ready(Ok::<_, DispatchError>((io, peer_addr)))
|
|
|
|
})))
|
2019-12-02 12:33:11 +01:00
|
|
|
}))
|
|
|
|
.and_then(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "openssl")]
|
|
|
|
mod openssl {
|
2021-01-04 00:47:04 +01:00
|
|
|
use actix_service::{fn_factory, fn_service, ServiceFactoryExt};
|
2021-02-27 20:57:09 +01:00
|
|
|
use actix_tls::accept::openssl::{Acceptor, SslAcceptor, SslError, TlsStream};
|
2021-01-04 00:47:04 +01:00
|
|
|
use actix_tls::accept::TlsError;
|
2019-12-02 12:33:11 +01:00
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
2021-02-27 20:57:09 +01:00
|
|
|
impl<S, B> H2Service<TlsStream<TcpStream>, S, B>
|
2019-12-02 12:33:11 +01:00
|
|
|
where
|
2021-01-04 00:47:04 +01:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2021-03-26 19:24:51 +01:00
|
|
|
S::Future: 'static,
|
2019-12-02 12:33:11 +01:00
|
|
|
S::Error: Into<Error> + 'static,
|
|
|
|
S::Response: Into<Response<B>> + 'static,
|
2021-01-04 00:47:04 +01:00
|
|
|
<S::Service as Service<Request>>::Future: 'static,
|
2019-12-02 12:33:11 +01:00
|
|
|
B: MessageBody + 'static,
|
|
|
|
{
|
2021-01-04 01:49:02 +01:00
|
|
|
/// Create OpenSSL based service
|
2019-12-02 12:33:11 +01:00
|
|
|
pub fn openssl(
|
|
|
|
self,
|
|
|
|
acceptor: SslAcceptor,
|
|
|
|
) -> impl ServiceFactory<
|
2021-01-04 00:47:04 +01:00
|
|
|
TcpStream,
|
2019-12-02 12:33:11 +01:00
|
|
|
Config = (),
|
|
|
|
Response = (),
|
2021-01-04 00:47:04 +01:00
|
|
|
Error = TlsError<SslError, DispatchError>,
|
2019-12-02 12:33:11 +01:00
|
|
|
InitError = S::InitError,
|
|
|
|
> {
|
|
|
|
pipeline_factory(
|
|
|
|
Acceptor::new(acceptor)
|
2020-09-09 10:20:54 +02:00
|
|
|
.map_err(TlsError::Tls)
|
2019-12-02 12:33:11 +01:00
|
|
|
.map_init_err(|_| panic!()),
|
|
|
|
)
|
2019-12-08 14:25:24 +01:00
|
|
|
.and_then(fn_factory(|| {
|
2021-03-26 19:24:51 +01:00
|
|
|
ready(Ok::<_, S::InitError>(fn_service(
|
|
|
|
|io: TlsStream<TcpStream>| {
|
|
|
|
let peer_addr = io.get_ref().peer_addr().ok();
|
|
|
|
ready(Ok((io, peer_addr)))
|
|
|
|
},
|
|
|
|
)))
|
2019-12-02 12:33:11 +01:00
|
|
|
}))
|
2020-09-09 10:20:54 +02:00
|
|
|
.and_then(self.map_err(TlsError::Service))
|
2019-12-02 12:33:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-05 18:35:43 +01:00
|
|
|
#[cfg(feature = "rustls")]
|
|
|
|
mod rustls {
|
|
|
|
use super::*;
|
2021-01-04 00:47:04 +01:00
|
|
|
use actix_service::ServiceFactoryExt;
|
|
|
|
use actix_tls::accept::rustls::{Acceptor, ServerConfig, TlsStream};
|
|
|
|
use actix_tls::accept::TlsError;
|
2019-12-13 06:24:57 +01:00
|
|
|
use std::io;
|
2019-12-05 18:35:43 +01:00
|
|
|
|
|
|
|
impl<S, B> H2Service<TlsStream<TcpStream>, S, B>
|
|
|
|
where
|
2021-01-04 00:47:04 +01:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2021-03-26 19:24:51 +01:00
|
|
|
S::Future: 'static,
|
2019-12-05 18:35:43 +01:00
|
|
|
S::Error: Into<Error> + 'static,
|
|
|
|
S::Response: Into<Response<B>> + 'static,
|
2021-01-04 00:47:04 +01:00
|
|
|
<S::Service as Service<Request>>::Future: 'static,
|
2019-12-05 18:35:43 +01:00
|
|
|
B: MessageBody + 'static,
|
|
|
|
{
|
2021-01-04 01:49:02 +01:00
|
|
|
/// Create Rustls based service
|
2019-12-05 18:35:43 +01:00
|
|
|
pub fn rustls(
|
|
|
|
self,
|
|
|
|
mut config: ServerConfig,
|
|
|
|
) -> impl ServiceFactory<
|
2021-01-04 00:47:04 +01:00
|
|
|
TcpStream,
|
2019-12-05 18:35:43 +01:00
|
|
|
Config = (),
|
|
|
|
Response = (),
|
2020-09-09 10:20:54 +02:00
|
|
|
Error = TlsError<io::Error, DispatchError>,
|
2019-12-05 18:35:43 +01:00
|
|
|
InitError = S::InitError,
|
|
|
|
> {
|
|
|
|
let protos = vec!["h2".to_string().into()];
|
|
|
|
config.set_protocols(&protos);
|
|
|
|
|
|
|
|
pipeline_factory(
|
|
|
|
Acceptor::new(config)
|
2020-09-09 10:20:54 +02:00
|
|
|
.map_err(TlsError::Tls)
|
2019-12-05 18:35:43 +01:00
|
|
|
.map_init_err(|_| panic!()),
|
|
|
|
)
|
2019-12-08 14:25:24 +01:00
|
|
|
.and_then(fn_factory(|| {
|
2021-03-26 19:24:51 +01:00
|
|
|
ready(Ok::<_, S::InitError>(fn_service(
|
|
|
|
|io: TlsStream<TcpStream>| {
|
|
|
|
let peer_addr = io.get_ref().0.peer_addr().ok();
|
|
|
|
ready(Ok((io, peer_addr)))
|
|
|
|
},
|
|
|
|
)))
|
2019-12-05 18:35:43 +01:00
|
|
|
}))
|
2020-09-09 10:20:54 +02:00
|
|
|
.and_then(self.map_err(TlsError::Service))
|
2019-12-05 18:35:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 00:47:04 +01:00
|
|
|
impl<T, S, B> ServiceFactory<(T, Option<net::SocketAddr>)> for H2Service<T, S, B>
|
2019-02-02 05:18:44 +01:00
|
|
|
where
|
2021-03-26 19:24:51 +01:00
|
|
|
T: AsyncRead + AsyncWrite + Unpin + 'static,
|
2021-01-04 00:47:04 +01:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2021-03-26 19:24:51 +01:00
|
|
|
S::Future: 'static,
|
2019-11-19 13:54:19 +01:00
|
|
|
S::Error: Into<Error> + 'static,
|
|
|
|
S::Response: Into<Response<B>> + 'static,
|
2021-01-04 00:47:04 +01:00
|
|
|
<S::Service as Service<Request>>::Future: 'static,
|
2019-02-06 20:44:15 +01:00
|
|
|
B: MessageBody + 'static,
|
2019-02-02 05:18:44 +01:00
|
|
|
{
|
2019-02-06 20:44:15 +01:00
|
|
|
type Response = ();
|
2019-03-07 07:56:34 +01:00
|
|
|
type Error = DispatchError;
|
2021-01-04 00:47:04 +01:00
|
|
|
type Config = ();
|
2019-12-02 12:33:11 +01:00
|
|
|
type Service = H2ServiceHandler<T, S::Service, B>;
|
2021-01-04 00:47:04 +01:00
|
|
|
type InitError = S::InitError;
|
2021-03-26 19:24:51 +01:00
|
|
|
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
2019-02-02 05:18:44 +01:00
|
|
|
|
2019-12-02 16:37:13 +01:00
|
|
|
fn new_service(&self, _: ()) -> Self::Future {
|
2021-03-26 19:24:51 +01:00
|
|
|
let service = self.srv.new_service(());
|
|
|
|
let cfg = self.cfg.clone();
|
|
|
|
let on_connect_ext = self.on_connect_ext.clone();
|
2019-02-02 05:18:44 +01:00
|
|
|
|
2021-03-26 19:24:51 +01:00
|
|
|
Box::pin(async move {
|
|
|
|
let service = service.await?;
|
|
|
|
Ok(H2ServiceHandler::new(cfg, on_connect_ext, service))
|
2021-01-04 01:49:02 +01:00
|
|
|
})
|
2019-02-02 05:18:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-11 23:39:54 +01:00
|
|
|
/// `Service` implementation for HTTP/2 transport
|
2021-01-04 00:47:04 +01:00
|
|
|
pub struct H2ServiceHandler<T, S, B>
|
|
|
|
where
|
|
|
|
S: Service<Request>,
|
|
|
|
{
|
2021-02-07 02:00:40 +01:00
|
|
|
flow: Rc<HttpFlow<S, (), ()>>,
|
2019-02-02 05:18:44 +01:00
|
|
|
cfg: ServiceConfig,
|
2020-10-30 03:03:26 +01:00
|
|
|
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
|
2021-01-04 01:49:02 +01:00
|
|
|
_phantom: PhantomData<B>,
|
2019-02-02 05:18:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:33:11 +01:00
|
|
|
impl<T, S, B> H2ServiceHandler<T, S, B>
|
2019-02-02 05:18:44 +01:00
|
|
|
where
|
2021-01-04 00:47:04 +01:00
|
|
|
S: Service<Request>,
|
2019-11-19 13:54:19 +01:00
|
|
|
S::Error: Into<Error> + 'static,
|
|
|
|
S::Future: 'static,
|
|
|
|
S::Response: Into<Response<B>> + 'static,
|
2019-02-06 20:44:15 +01:00
|
|
|
B: MessageBody + 'static,
|
2019-02-02 05:18:44 +01:00
|
|
|
{
|
2019-06-28 10:34:26 +02:00
|
|
|
fn new(
|
|
|
|
cfg: ServiceConfig,
|
2020-10-30 03:03:26 +01:00
|
|
|
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
|
2021-01-06 19:43:52 +01:00
|
|
|
service: S,
|
2019-12-02 12:33:11 +01:00
|
|
|
) -> H2ServiceHandler<T, S, B> {
|
2019-02-02 05:18:44 +01:00
|
|
|
H2ServiceHandler {
|
2021-01-06 19:52:06 +01:00
|
|
|
flow: HttpFlow::new(service, (), None),
|
2019-02-02 05:18:44 +01:00
|
|
|
cfg,
|
2020-10-30 03:03:26 +01:00
|
|
|
on_connect_ext,
|
2021-01-04 01:49:02 +01:00
|
|
|
_phantom: PhantomData,
|
2019-02-02 05:18:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 00:47:04 +01:00
|
|
|
impl<T, S, B> Service<(T, Option<net::SocketAddr>)> for H2ServiceHandler<T, S, B>
|
2019-02-02 05:18:44 +01:00
|
|
|
where
|
2019-12-02 12:33:11 +01:00
|
|
|
T: AsyncRead + AsyncWrite + Unpin,
|
2021-01-04 00:47:04 +01:00
|
|
|
S: Service<Request>,
|
2019-11-19 13:54:19 +01:00
|
|
|
S::Error: Into<Error> + 'static,
|
|
|
|
S::Future: 'static,
|
|
|
|
S::Response: Into<Response<B>> + 'static,
|
2019-02-06 20:44:15 +01:00
|
|
|
B: MessageBody + 'static,
|
2019-02-02 05:18:44 +01:00
|
|
|
{
|
2019-02-06 20:44:15 +01:00
|
|
|
type Response = ();
|
2019-03-07 07:56:34 +01:00
|
|
|
type Error = DispatchError;
|
2019-02-02 05:18:44 +01:00
|
|
|
type Future = H2ServiceHandlerResponse<T, S, B>;
|
|
|
|
|
2021-02-07 02:00:40 +01:00
|
|
|
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
|
|
self.flow.service.poll_ready(cx).map_err(|e| {
|
2021-01-07 01:35:19 +01:00
|
|
|
let e = e.into();
|
|
|
|
error!("Service readiness error: {:?}", e);
|
|
|
|
DispatchError::Service(e)
|
|
|
|
})
|
2019-02-02 05:18:44 +01:00
|
|
|
}
|
|
|
|
|
2021-02-07 02:00:40 +01:00
|
|
|
fn call(&self, (io, addr): (T, Option<net::SocketAddr>)) -> Self::Future {
|
2021-01-06 19:43:52 +01:00
|
|
|
let on_connect_data =
|
|
|
|
OnConnectData::from_io(&io, self.on_connect_ext.as_deref());
|
2019-06-28 10:34:26 +02:00
|
|
|
|
2019-02-02 05:18:44 +01:00
|
|
|
H2ServiceHandlerResponse {
|
2019-02-06 20:44:15 +01:00
|
|
|
state: State::Handshake(
|
2021-01-06 19:52:06 +01:00
|
|
|
Some(self.flow.clone()),
|
2019-02-06 20:44:15 +01:00
|
|
|
Some(self.cfg.clone()),
|
2019-12-02 12:33:11 +01:00
|
|
|
addr,
|
2021-01-06 19:43:52 +01:00
|
|
|
on_connect_data,
|
2021-03-11 04:48:38 +01:00
|
|
|
handshake(io),
|
2019-02-06 20:44:15 +01:00
|
|
|
),
|
2019-02-02 05:18:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 00:47:04 +01:00
|
|
|
enum State<T, S: Service<Request>, B: MessageBody>
|
2019-04-04 19:59:34 +02:00
|
|
|
where
|
2019-12-02 12:33:11 +01:00
|
|
|
T: AsyncRead + AsyncWrite + Unpin,
|
2019-04-04 19:59:34 +02:00
|
|
|
S::Future: 'static,
|
|
|
|
{
|
2021-01-06 19:43:52 +01:00
|
|
|
Incoming(Dispatcher<T, S, B, (), ()>),
|
2019-02-10 05:27:39 +01:00
|
|
|
Handshake(
|
2021-02-07 02:00:40 +01:00
|
|
|
Option<Rc<HttpFlow<S, (), ()>>>,
|
2019-02-10 05:27:39 +01:00
|
|
|
Option<ServiceConfig>,
|
2019-04-16 18:54:02 +02:00
|
|
|
Option<net::SocketAddr>,
|
2021-01-06 19:43:52 +01:00
|
|
|
OnConnectData,
|
2019-02-10 05:27:39 +01:00
|
|
|
Handshake<T, Bytes>,
|
|
|
|
),
|
2019-02-02 05:18:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct H2ServiceHandlerResponse<T, S, B>
|
|
|
|
where
|
2019-12-02 12:33:11 +01:00
|
|
|
T: AsyncRead + AsyncWrite + Unpin,
|
2021-01-04 00:47:04 +01:00
|
|
|
S: Service<Request>,
|
2019-11-19 13:54:19 +01:00
|
|
|
S::Error: Into<Error> + 'static,
|
|
|
|
S::Future: 'static,
|
|
|
|
S::Response: Into<Response<B>> + 'static,
|
2019-02-06 20:44:15 +01:00
|
|
|
B: MessageBody + 'static,
|
2019-02-02 05:18:44 +01:00
|
|
|
{
|
2019-02-06 20:44:15 +01:00
|
|
|
state: State<T, S, B>,
|
2019-02-02 05:18:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, S, B> Future for H2ServiceHandlerResponse<T, S, B>
|
|
|
|
where
|
2019-12-02 12:33:11 +01:00
|
|
|
T: AsyncRead + AsyncWrite + Unpin,
|
2021-01-04 00:47:04 +01:00
|
|
|
S: Service<Request>,
|
2019-11-19 13:54:19 +01:00
|
|
|
S::Error: Into<Error> + 'static,
|
|
|
|
S::Future: 'static,
|
|
|
|
S::Response: Into<Response<B>> + 'static,
|
2019-02-02 05:18:44 +01:00
|
|
|
B: MessageBody,
|
|
|
|
{
|
2019-11-15 10:54:11 +01:00
|
|
|
type Output = Result<(), DispatchError>;
|
2019-02-02 05:18:44 +01:00
|
|
|
|
2019-12-07 19:46:51 +01:00
|
|
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
2019-02-06 20:44:15 +01:00
|
|
|
match self.state {
|
2019-11-15 10:54:11 +01:00
|
|
|
State::Incoming(ref mut disp) => Pin::new(disp).poll(cx),
|
2019-04-16 18:54:02 +02:00
|
|
|
State::Handshake(
|
|
|
|
ref mut srv,
|
|
|
|
ref mut config,
|
|
|
|
ref peer_addr,
|
2020-10-30 03:03:26 +01:00
|
|
|
ref mut on_connect_data,
|
2019-04-16 18:54:02 +02:00
|
|
|
ref mut handshake,
|
2021-01-04 01:49:02 +01:00
|
|
|
) => match ready!(Pin::new(handshake).poll(cx)) {
|
|
|
|
Ok(conn) => {
|
2021-01-06 19:43:52 +01:00
|
|
|
let on_connect_data = std::mem::take(on_connect_data);
|
2019-04-16 18:54:02 +02:00
|
|
|
self.state = State::Incoming(Dispatcher::new(
|
|
|
|
srv.take().unwrap(),
|
|
|
|
conn,
|
2021-01-06 19:43:52 +01:00
|
|
|
on_connect_data,
|
2019-04-16 18:54:02 +02:00
|
|
|
config.take().unwrap(),
|
2019-07-17 09:55:44 +02:00
|
|
|
*peer_addr,
|
2019-04-16 18:54:02 +02:00
|
|
|
));
|
2019-11-15 10:54:11 +01:00
|
|
|
self.poll(cx)
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
2021-01-04 01:49:02 +01:00
|
|
|
Err(err) => {
|
2019-04-16 18:54:02 +02:00
|
|
|
trace!("H2 handshake error: {}", err);
|
2019-11-15 10:54:11 +01:00
|
|
|
Poll::Ready(Err(err.into()))
|
2019-04-16 18:54:02 +02:00
|
|
|
}
|
|
|
|
},
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
2019-02-02 05:18:44 +01:00
|
|
|
}
|
|
|
|
}
|