diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 0625006e..bb57385c 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -2,8 +2,10 @@ - Raise MSRV to 1.65. See [PR 3715]. +- Remove deprecated `RequestResponse` prefixed items. See [PR 3702]. [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 +[PR 3702]: https://github.com/libp2p/rust-libp2p/pull/3702 ## 0.24.1 diff --git a/protocols/request-response/src/codec.rs b/protocols/request-response/src/codec.rs new file mode 100644 index 00000000..71cfb79a --- /dev/null +++ b/protocols/request-response/src/codec.rs @@ -0,0 +1,80 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +pub use libp2p_core::ProtocolName; + +use async_trait::async_trait; +use futures::prelude::*; +use std::io; + +/// A `Codec` defines the request and response types +/// for a request-response [`Behaviour`](crate::Behaviour) protocol or +/// protocol family and how they are encoded / decoded on an I/O stream. +#[async_trait] +pub trait Codec { + /// The type of protocol(s) or protocol versions being negotiated. + type Protocol: ProtocolName + Send + Clone; + /// The type of inbound and outbound requests. + type Request: Send; + /// The type of inbound and outbound responses. + type Response: Send; + + /// Reads a request from the given I/O stream according to the + /// negotiated protocol. + async fn read_request( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + ) -> io::Result + where + T: AsyncRead + Unpin + Send; + + /// Reads a response from the given I/O stream according to the + /// negotiated protocol. + async fn read_response( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + ) -> io::Result + where + T: AsyncRead + Unpin + Send; + + /// Writes a request to the given I/O stream according to the + /// negotiated protocol. + async fn write_request( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + req: Self::Request, + ) -> io::Result<()> + where + T: AsyncWrite + Unpin + Send; + + /// Writes a response to the given I/O stream according to the + /// negotiated protocol. + async fn write_response( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + res: Self::Response, + ) -> io::Result<()> + where + T: AsyncWrite + Unpin + Send; +} diff --git a/protocols/request-response/src/codec_priv.rs b/protocols/request-response/src/codec_priv.rs deleted file mode 100644 index c5af967d..00000000 --- a/protocols/request-response/src/codec_priv.rs +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -pub use libp2p_core::ProtocolName; - -use async_trait::async_trait; -use futures::prelude::*; -use std::io; - -/// A `RequestResponseCodec` defines the request and response types -/// for a request-response `Behaviour` protocol or -/// protocol family and how they are encoded / decoded on an I/O stream. -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::Codec`" -)] -#[async_trait] -pub trait RequestResponseCodec { - /// The type of protocol(s) or protocol versions being negotiated. - type Protocol: ProtocolName + Send + Clone; - /// The type of inbound and outbound requests. - type Request: Send; - /// The type of inbound and outbound responses. - type Response: Send; - - /// Reads a request from the given I/O stream according to the - /// negotiated protocol. - async fn read_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send; - - /// Reads a response from the given I/O stream according to the - /// negotiated protocol. - async fn read_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send; - - /// Writes a request to the given I/O stream according to the - /// negotiated protocol. - async fn write_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - req: Self::Request, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send; - - /// Writes a response to the given I/O stream according to the - /// negotiated protocol. - async fn write_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - res: Self::Response, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send; -} - -/// A `Codec` defines the request and response types -/// for a request-response [`Behaviour`](crate::Behaviour) protocol or -/// protocol family and how they are encoded / decoded on an I/O stream. -#[async_trait] -pub trait Codec { - /// The type of protocol(s) or protocol versions being negotiated. - type Protocol: ProtocolName + Send + Clone; - /// The type of inbound and outbound requests. - type Request: Send; - /// The type of inbound and outbound responses. - type Response: Send; - - /// Reads a request from the given I/O stream according to the - /// negotiated protocol. - async fn read_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send; - - /// Reads a response from the given I/O stream according to the - /// negotiated protocol. - async fn read_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send; - - /// Writes a request to the given I/O stream according to the - /// negotiated protocol. - async fn write_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - req: Self::Request, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send; - - /// Writes a response to the given I/O stream according to the - /// negotiated protocol. - async fn write_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - res: Self::Response, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send; -} - -#[allow(deprecated)] -#[async_trait] -impl Codec for U -where - U: RequestResponseCodec + Send, - U::Protocol: Sync, -{ - type Protocol = U::Protocol; - - type Request = U::Request; - - type Response = U::Response; - - async fn read_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send, - { - self.read_request(protocol, io).await - } - - async fn read_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send, - { - self.read_response(protocol, io).await - } - - async fn write_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - req: Self::Request, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send, - { - self.write_request(protocol, io, req).await - } - - async fn write_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - res: Self::Response, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send, - { - self.write_response(protocol, io, res).await - } -} diff --git a/protocols/request-response/src/handler_priv.rs b/protocols/request-response/src/handler.rs similarity index 96% rename from protocols/request-response/src/handler_priv.rs rename to protocols/request-response/src/handler.rs index 849c9e57..65aa1f84 100644 --- a/protocols/request-response/src/handler_priv.rs +++ b/protocols/request-response/src/handler.rs @@ -18,20 +18,21 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -mod protocol; +pub(crate) mod protocol; -use crate::codec_priv::Codec; +pub use protocol::ProtocolSupport; + +use crate::codec::Codec; +use crate::handler::protocol::{RequestProtocol, ResponseProtocol}; use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD}; -use libp2p_swarm::handler::{ - ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - ListenUpgradeError, -}; -pub use protocol::{ProtocolSupport, RequestProtocol, ResponseProtocol}; - use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered}; use instant::Instant; use libp2p_core::upgrade::{NegotiationError, UpgradeError}; +use libp2p_swarm::handler::{ + ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, + ListenUpgradeError, +}; use libp2p_swarm::{ handler::{ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive}, SubstreamProtocol, @@ -48,12 +49,6 @@ use std::{ time::Duration, }; -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Handler`" -)] -pub type RequestResponseHandler = Handler; - /// A connection handler for a request response [`Behaviour`](super::Behaviour) protocol. pub struct Handler where @@ -193,12 +188,6 @@ where } } -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Event`" -)] -pub type RequestResponseHandlerEvent = Event; - /// The events emitted by the [`Handler`]. pub enum Event where diff --git a/protocols/request-response/src/handler_priv/protocol.rs b/protocols/request-response/src/handler/protocol.rs similarity index 99% rename from protocols/request-response/src/handler_priv/protocol.rs rename to protocols/request-response/src/handler/protocol.rs index 3ee08c7f..84ef3657 100644 --- a/protocols/request-response/src/handler_priv/protocol.rs +++ b/protocols/request-response/src/handler/protocol.rs @@ -23,7 +23,7 @@ //! receives a request and sends a response, whereas the //! outbound upgrade send a request and receives a response. -use crate::codec_priv::Codec; +use crate::codec::Codec; use crate::RequestId; use futures::{channel::oneshot, future::BoxFuture, prelude::*}; diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 723c11d8..14854dde 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -58,31 +58,15 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -mod codec_priv; -#[deprecated( - note = "The `codec` module will be made private in the future and should not be depended on." -)] -pub mod codec { - pub use super::codec_priv::*; -} +mod codec; +mod handler; -mod handler_priv; -#[deprecated( - note = "The `handler` module will be made private in the future and should not be depended on." -)] -pub mod handler { - pub use super::handler_priv::*; -} - -pub use codec_priv::{Codec, ProtocolName}; - -#[allow(deprecated)] -pub use codec_priv::RequestResponseCodec; - -pub use handler_priv::ProtocolSupport; +pub use codec::{Codec, ProtocolName}; +pub use handler::ProtocolSupport; +use crate::handler::protocol::RequestProtocol; use futures::channel::oneshot; -use handler_priv::{Handler, RequestProtocol}; +use handler::Handler; use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ @@ -100,37 +84,6 @@ use std::{ time::Duration, }; -#[deprecated( - since = "0.24.0", - note = "Use libp2p::request_response::Behaviour instead." -)] -pub type RequestResponse = Behaviour; - -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::Config`" -)] -pub type RequestResponseConfig = Config; - -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::Event`" -)] -pub type RequestResponseEvent = Event; - -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::Message`" -)] -pub type RequestResponseMessage = - Message; - -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Event`" -)] -pub type HandlerEvent = handler_priv::Event; - /// An inbound request or response. #[derive(Debug)] pub enum Message { @@ -815,7 +768,7 @@ where event: THandlerOutEvent, ) { match event { - handler_priv::Event::Response { + handler::Event::Response { request_id, response, } => { @@ -832,7 +785,7 @@ where self.pending_events .push_back(ToSwarm::GenerateEvent(Event::Message { peer, message })); } - handler_priv::Event::Request { + handler::Event::Request { request_id, request, sender, @@ -863,7 +816,7 @@ where } } } - handler_priv::Event::ResponseSent(request_id) => { + handler::Event::ResponseSent(request_id) => { let removed = self.remove_pending_outbound_response(&peer, connection, request_id); debug_assert!( removed, @@ -876,7 +829,7 @@ where request_id, })); } - handler_priv::Event::ResponseOmission(request_id) => { + handler::Event::ResponseOmission(request_id) => { let removed = self.remove_pending_outbound_response(&peer, connection, request_id); debug_assert!( removed, @@ -890,7 +843,7 @@ where error: InboundFailure::ResponseOmission, })); } - handler_priv::Event::OutboundTimeout(request_id) => { + handler::Event::OutboundTimeout(request_id) => { let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); debug_assert!( removed, @@ -904,7 +857,7 @@ where error: OutboundFailure::Timeout, })); } - handler_priv::Event::InboundTimeout(request_id) => { + handler::Event::InboundTimeout(request_id) => { // Note: `Event::InboundTimeout` is emitted both for timing // out to receive the request and for timing out sending the response. In the former // case the request is never added to `pending_outbound_responses` and thus one can @@ -918,7 +871,7 @@ where error: InboundFailure::Timeout, })); } - handler_priv::Event::OutboundUnsupportedProtocols(request_id) => { + handler::Event::OutboundUnsupportedProtocols(request_id) => { let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); debug_assert!( removed, @@ -932,7 +885,7 @@ where error: OutboundFailure::UnsupportedProtocols, })); } - handler_priv::Event::InboundUnsupportedProtocols(request_id) => { + handler::Event::InboundUnsupportedProtocols(request_id) => { // Note: No need to call `self.remove_pending_outbound_response`, // `Event::Request` was never emitted for this request and // thus request was never added to `pending_outbound_responses`.