From 1892fdb6092c9164f7ac753ae820c1e8b6781cf0 Mon Sep 17 00:00:00 2001 From: quininer Date: Fri, 23 Mar 2018 17:47:44 +0800 Subject: [PATCH] remove tokio-proto support --- src/proto.rs | 552 --------------------------------------------------- 1 file changed, 552 deletions(-) delete mode 100644 src/proto.rs diff --git a/src/proto.rs b/src/proto.rs deleted file mode 100644 index 7c659e4..0000000 --- a/src/proto.rs +++ /dev/null @@ -1,552 +0,0 @@ -//! Wrappers for `tokio-proto` -//! -//! This module contains wrappers for protocols defined by the `tokio-proto` -//! crate. These wrappers will all attempt to negotiate a TLS connection first -//! and then delegate all further protocol information to the protocol -//! specified. -//! -//! This module requires the `tokio-proto` feature to be enabled. - -#![cfg(feature = "tokio-proto")] - -extern crate tokio_proto; - -use std::io; -use std::sync::Arc; -use futures::{ Future, IntoFuture, Poll }; -use tokio_io::{ AsyncRead, AsyncWrite }; -use rustls::{ ServerConfig, ClientConfig, ServerSession, ClientSession }; -use self::tokio_proto::multiplex; -use self::tokio_proto::pipeline; -use self::tokio_proto::streaming; -use webpki; - -use { TlsStream, ServerConfigExt, ClientConfigExt, AcceptAsync, ConnectAsync }; - -/// TLS server protocol wrapper. -/// -/// This structure is a wrapper for other implementations of `ServerProto` in -/// the `tokio-proto` crate. This structure will negotiate a TLS connection -/// first and then delegate all further operations to the `ServerProto` -/// implementation for the underlying type. -pub struct Server { - inner: Arc, - acceptor: Arc, -} - -impl Server { - /// Constructs a new TLS protocol which will delegate to the underlying - /// `protocol` specified. - /// - /// The `acceptor` provided will be used to accept TLS connections. All new - /// connections will go through the TLS acceptor first and then further I/O - /// will go through the negotiated TLS stream through the `protocol` - /// specified. - pub fn new(protocol: T, acceptor: Arc) -> Server { - Server { - inner: Arc::new(protocol), - acceptor: acceptor, - } - } -} - -/// Future returned from `bind_transport` in the `ServerProto` implementation. -pub struct ServerPipelineBind - where T: pipeline::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - state: PipelineState, -} - -enum PipelineState - where T: pipeline::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - First(AcceptAsync, Arc), - Next(::Future), -} - -impl pipeline::ServerProto for Server - where T: pipeline::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Request = T::Request; - type Response = T::Response; - type Transport = T::Transport; - type BindTransport = ServerPipelineBind; - - fn bind_transport(&self, io: I) -> Self::BindTransport { - let proto = self.inner.clone(); - - ServerPipelineBind { - state: PipelineState::First(self.acceptor.accept_async(io), proto), - } - } -} - -impl Future for ServerPipelineBind - where T: pipeline::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Item = T::Transport; - type Error = io::Error; - - fn poll(&mut self) -> Poll { - loop { - let next = match self.state { - PipelineState::First(ref mut a, ref state) => { - let res = a.poll().map_err(|e| { - io::Error::new(io::ErrorKind::Other, e) - }); - state.bind_transport(try_ready!(res)) - } - PipelineState::Next(ref mut b) => return b.poll(), - }; - self.state = PipelineState::Next(next.into_future()); - } - } -} - -/// Future returned from `bind_transport` in the `ServerProto` implementation. -pub struct ServerMultiplexBind - where T: multiplex::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - state: MultiplexState, -} - -enum MultiplexState - where T: multiplex::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - First(AcceptAsync, Arc), - Next(::Future), -} - -impl multiplex::ServerProto for Server - where T: multiplex::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Request = T::Request; - type Response = T::Response; - type Transport = T::Transport; - type BindTransport = ServerMultiplexBind; - - fn bind_transport(&self, io: I) -> Self::BindTransport { - let proto = self.inner.clone(); - - ServerMultiplexBind { - state: MultiplexState::First(self.acceptor.accept_async(io), proto), - } - } -} - -impl Future for ServerMultiplexBind - where T: multiplex::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Item = T::Transport; - type Error = io::Error; - - fn poll(&mut self) -> Poll { - loop { - let next = match self.state { - MultiplexState::First(ref mut a, ref state) => { - let res = a.poll().map_err(|e| { - io::Error::new(io::ErrorKind::Other, e) - }); - state.bind_transport(try_ready!(res)) - } - MultiplexState::Next(ref mut b) => return b.poll(), - }; - self.state = MultiplexState::Next(next.into_future()); - } - } -} - -/// Future returned from `bind_transport` in the `ServerProto` implementation. -pub struct ServerStreamingPipelineBind - where T: streaming::pipeline::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - state: StreamingPipelineState, -} - -enum StreamingPipelineState - where T: streaming::pipeline::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - First(AcceptAsync, Arc), - Next(::Future), -} - -impl streaming::pipeline::ServerProto for Server - where T: streaming::pipeline::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Request = T::Request; - type RequestBody = T::RequestBody; - type Response = T::Response; - type ResponseBody = T::ResponseBody; - type Error = T::Error; - type Transport = T::Transport; - type BindTransport = ServerStreamingPipelineBind; - - fn bind_transport(&self, io: I) -> Self::BindTransport { - let proto = self.inner.clone(); - - ServerStreamingPipelineBind { - state: StreamingPipelineState::First(self.acceptor.accept_async(io), proto), - } - } -} - -impl Future for ServerStreamingPipelineBind - where T: streaming::pipeline::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Item = T::Transport; - type Error = io::Error; - - fn poll(&mut self) -> Poll { - loop { - let next = match self.state { - StreamingPipelineState::First(ref mut a, ref state) => { - let res = a.poll().map_err(|e| { - io::Error::new(io::ErrorKind::Other, e) - }); - state.bind_transport(try_ready!(res)) - } - StreamingPipelineState::Next(ref mut b) => return b.poll(), - }; - self.state = StreamingPipelineState::Next(next.into_future()); - } - } -} - -/// Future returned from `bind_transport` in the `ServerProto` implementation. -pub struct ServerStreamingMultiplexBind - where T: streaming::multiplex::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - state: StreamingMultiplexState, -} - -enum StreamingMultiplexState - where T: streaming::multiplex::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - First(AcceptAsync, Arc), - Next(::Future), -} - -impl streaming::multiplex::ServerProto for Server - where T: streaming::multiplex::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Request = T::Request; - type RequestBody = T::RequestBody; - type Response = T::Response; - type ResponseBody = T::ResponseBody; - type Error = T::Error; - type Transport = T::Transport; - type BindTransport = ServerStreamingMultiplexBind; - - fn bind_transport(&self, io: I) -> Self::BindTransport { - let proto = self.inner.clone(); - - ServerStreamingMultiplexBind { - state: StreamingMultiplexState::First(self.acceptor.accept_async(io), proto), - } - } -} - -impl Future for ServerStreamingMultiplexBind - where T: streaming::multiplex::ServerProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Item = T::Transport; - type Error = io::Error; - - fn poll(&mut self) -> Poll { - loop { - let next = match self.state { - StreamingMultiplexState::First(ref mut a, ref state) => { - let res = a.poll().map_err(|e| { - io::Error::new(io::ErrorKind::Other, e) - }); - state.bind_transport(try_ready!(res)) - } - StreamingMultiplexState::Next(ref mut b) => return b.poll(), - }; - self.state = StreamingMultiplexState::Next(next.into_future()); - } - } -} - -/// TLS client protocol wrapper. -/// -/// This structure is a wrapper for other implementations of `ClientProto` in -/// the `tokio-proto` crate. This structure will negotiate a TLS connection -/// first and then delegate all further operations to the `ClientProto` -/// implementation for the underlying type. -pub struct Client { - inner: Arc, - connector: Arc, - hostname: webpki::DNSName, -} - -impl Client { - /// Constructs a new TLS protocol which will delegate to the underlying - /// `protocol` specified. - /// - /// The `connector` provided will be used to configure the TLS connection. Further I/O - /// will go through the negotiated TLS stream through the `protocol` specified. - pub fn new(protocol: T, - connector: Arc, - hostname: webpki::DNSName) -> Client { - Client { - inner: Arc::new(protocol), - connector: connector, - hostname: hostname, - } - } -} - -/// Future returned from `bind_transport` in the `ClientProto` implementation. -pub struct ClientPipelineBind - where T: pipeline::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - state: ClientPipelineState, -} - -enum ClientPipelineState - where T: pipeline::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - First(ConnectAsync, Arc), - Next(::Future), -} - -impl pipeline::ClientProto for Client - where T: pipeline::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Request = T::Request; - type Response = T::Response; - type Transport = T::Transport; - type BindTransport = ClientPipelineBind; - - fn bind_transport(&self, io: I) -> Self::BindTransport { - let proto = self.inner.clone(); - let io = self.connector.connect_async(self.hostname.as_ref(), io); - - ClientPipelineBind { - state: ClientPipelineState::First(io, proto), - } - } -} - -impl Future for ClientPipelineBind - where T: pipeline::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Item = T::Transport; - type Error = io::Error; - - fn poll(&mut self) -> Poll { - loop { - let next = match self.state { - ClientPipelineState::First(ref mut a, ref state) => { - let res = a.poll().map_err(|e| { - io::Error::new(io::ErrorKind::Other, e) - }); - state.bind_transport(try_ready!(res)) - } - ClientPipelineState::Next(ref mut b) => return b.poll(), - }; - self.state = ClientPipelineState::Next(next.into_future()); - } - } -} - -/// Future returned from `bind_transport` in the `ClientProto` implementation. -pub struct ClientMultiplexBind - where T: multiplex::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - state: ClientMultiplexState, -} - -enum ClientMultiplexState - where T: multiplex::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - First(ConnectAsync, Arc), - Next(::Future), -} - -impl multiplex::ClientProto for Client - where T: multiplex::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Request = T::Request; - type Response = T::Response; - type Transport = T::Transport; - type BindTransport = ClientMultiplexBind; - - fn bind_transport(&self, io: I) -> Self::BindTransport { - let proto = self.inner.clone(); - let io = self.connector.connect_async(self.hostname.as_ref(), io); - - ClientMultiplexBind { - state: ClientMultiplexState::First(io, proto), - } - } -} - -impl Future for ClientMultiplexBind - where T: multiplex::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Item = T::Transport; - type Error = io::Error; - - fn poll(&mut self) -> Poll { - loop { - let next = match self.state { - ClientMultiplexState::First(ref mut a, ref state) => { - let res = a.poll().map_err(|e| { - io::Error::new(io::ErrorKind::Other, e) - }); - state.bind_transport(try_ready!(res)) - } - ClientMultiplexState::Next(ref mut b) => return b.poll(), - }; - self.state = ClientMultiplexState::Next(next.into_future()); - } - } -} - -/// Future returned from `bind_transport` in the `ClientProto` implementation. -pub struct ClientStreamingPipelineBind - where T: streaming::pipeline::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - state: ClientStreamingPipelineState, -} - -enum ClientStreamingPipelineState - where T: streaming::pipeline::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - First(ConnectAsync, Arc), - Next(::Future), -} - -impl streaming::pipeline::ClientProto for Client - where T: streaming::pipeline::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Request = T::Request; - type RequestBody = T::RequestBody; - type Response = T::Response; - type ResponseBody = T::ResponseBody; - type Error = T::Error; - type Transport = T::Transport; - type BindTransport = ClientStreamingPipelineBind; - - fn bind_transport(&self, io: I) -> Self::BindTransport { - let proto = self.inner.clone(); - let io = self.connector.connect_async(self.hostname.as_ref(), io); - - ClientStreamingPipelineBind { - state: ClientStreamingPipelineState::First(io, proto), - } - } -} - -impl Future for ClientStreamingPipelineBind - where T: streaming::pipeline::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Item = T::Transport; - type Error = io::Error; - - fn poll(&mut self) -> Poll { - loop { - let next = match self.state { - ClientStreamingPipelineState::First(ref mut a, ref state) => { - let res = a.poll().map_err(|e| { - io::Error::new(io::ErrorKind::Other, e) - }); - state.bind_transport(try_ready!(res)) - } - ClientStreamingPipelineState::Next(ref mut b) => return b.poll(), - }; - self.state = ClientStreamingPipelineState::Next(next.into_future()); - } - } -} - -/// Future returned from `bind_transport` in the `ClientProto` implementation. -pub struct ClientStreamingMultiplexBind - where T: streaming::multiplex::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - state: ClientStreamingMultiplexState, -} - -enum ClientStreamingMultiplexState - where T: streaming::multiplex::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - First(ConnectAsync, Arc), - Next(::Future), -} - -impl streaming::multiplex::ClientProto for Client - where T: streaming::multiplex::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Request = T::Request; - type RequestBody = T::RequestBody; - type Response = T::Response; - type ResponseBody = T::ResponseBody; - type Error = T::Error; - type Transport = T::Transport; - type BindTransport = ClientStreamingMultiplexBind; - - fn bind_transport(&self, io: I) -> Self::BindTransport { - let proto = self.inner.clone(); - let io = self.connector.connect_async(self.hostname.as_ref(), io); - - ClientStreamingMultiplexBind { - state: ClientStreamingMultiplexState::First(io, proto), - } - } -} - -impl Future for ClientStreamingMultiplexBind - where T: streaming::multiplex::ClientProto>, - I: AsyncRead + AsyncWrite + 'static, -{ - type Item = T::Transport; - type Error = io::Error; - - fn poll(&mut self) -> Poll { - loop { - let next = match self.state { - ClientStreamingMultiplexState::First(ref mut a, ref state) => { - let res = a.poll().map_err(|e| { - io::Error::new(io::ErrorKind::Other, e) - }); - state.bind_transport(try_ready!(res)) - } - ClientStreamingMultiplexState::Next(ref mut b) => return b.poll(), - }; - self.state = ClientStreamingMultiplexState::Next(next.into_future()); - } - } -}