Skip to content

Commit 4bd4653

Browse files
authored
chore(request-response): remove deprecated items
Related: #3647. Pull-Request: #3703.
1 parent 25d1434 commit 4bd4653

File tree

6 files changed

+105
-280
lines changed

6 files changed

+105
-280
lines changed

protocols/request-response/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
- Raise MSRV to 1.65.
44
See [PR 3715].
5+
- Remove deprecated `RequestResponse` prefixed items. See [PR 3702].
56

67
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
8+
[PR 3702]: https://github.com/libp2p/rust-libp2p/pull/3702
79

810
## 0.24.1
911

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2020 Parity Technologies (UK) Ltd.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the "Software"),
5+
// to deal in the Software without restriction, including without limitation
6+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
// and/or sell copies of the Software, and to permit persons to whom the
8+
// Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
// DEALINGS IN THE SOFTWARE.
20+
21+
pub use libp2p_core::ProtocolName;
22+
23+
use async_trait::async_trait;
24+
use futures::prelude::*;
25+
use std::io;
26+
27+
/// A `Codec` defines the request and response types
28+
/// for a request-response [`Behaviour`](crate::Behaviour) protocol or
29+
/// protocol family and how they are encoded / decoded on an I/O stream.
30+
#[async_trait]
31+
pub trait Codec {
32+
/// The type of protocol(s) or protocol versions being negotiated.
33+
type Protocol: ProtocolName + Send + Clone;
34+
/// The type of inbound and outbound requests.
35+
type Request: Send;
36+
/// The type of inbound and outbound responses.
37+
type Response: Send;
38+
39+
/// Reads a request from the given I/O stream according to the
40+
/// negotiated protocol.
41+
async fn read_request<T>(
42+
&mut self,
43+
protocol: &Self::Protocol,
44+
io: &mut T,
45+
) -> io::Result<Self::Request>
46+
where
47+
T: AsyncRead + Unpin + Send;
48+
49+
/// Reads a response from the given I/O stream according to the
50+
/// negotiated protocol.
51+
async fn read_response<T>(
52+
&mut self,
53+
protocol: &Self::Protocol,
54+
io: &mut T,
55+
) -> io::Result<Self::Response>
56+
where
57+
T: AsyncRead + Unpin + Send;
58+
59+
/// Writes a request to the given I/O stream according to the
60+
/// negotiated protocol.
61+
async fn write_request<T>(
62+
&mut self,
63+
protocol: &Self::Protocol,
64+
io: &mut T,
65+
req: Self::Request,
66+
) -> io::Result<()>
67+
where
68+
T: AsyncWrite + Unpin + Send;
69+
70+
/// Writes a response to the given I/O stream according to the
71+
/// negotiated protocol.
72+
async fn write_response<T>(
73+
&mut self,
74+
protocol: &Self::Protocol,
75+
io: &mut T,
76+
res: Self::Response,
77+
) -> io::Result<()>
78+
where
79+
T: AsyncWrite + Unpin + Send;
80+
}

protocols/request-response/src/codec_priv.rs

Lines changed: 0 additions & 199 deletions
This file was deleted.

protocols/request-response/src/handler_priv.rs renamed to protocols/request-response/src/handler.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@
1818
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
// DEALINGS IN THE SOFTWARE.
2020

21-
mod protocol;
21+
pub(crate) mod protocol;
2222

23-
use crate::codec_priv::Codec;
23+
pub use protocol::ProtocolSupport;
24+
25+
use crate::codec::Codec;
26+
use crate::handler::protocol::{RequestProtocol, ResponseProtocol};
2427
use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD};
2528

29+
use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered};
30+
use instant::Instant;
31+
use libp2p_core::upgrade::{NegotiationError, UpgradeError};
2632
use libp2p_swarm::handler::{
2733
ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
2834
ListenUpgradeError,
2935
};
30-
pub use protocol::{ProtocolSupport, RequestProtocol, ResponseProtocol};
31-
32-
use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered};
33-
use instant::Instant;
34-
use libp2p_core::upgrade::{NegotiationError, UpgradeError};
3536
use libp2p_swarm::{
3637
handler::{ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive},
3738
SubstreamProtocol,
@@ -48,12 +49,6 @@ use std::{
4849
time::Duration,
4950
};
5051

51-
#[deprecated(
52-
since = "0.24.0",
53-
note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Handler`"
54-
)]
55-
pub type RequestResponseHandler<TCodec> = Handler<TCodec>;
56-
5752
/// A connection handler for a request response [`Behaviour`](super::Behaviour) protocol.
5853
pub struct Handler<TCodec>
5954
where
@@ -193,12 +188,6 @@ where
193188
}
194189
}
195190

196-
#[deprecated(
197-
since = "0.24.0",
198-
note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Event`"
199-
)]
200-
pub type RequestResponseHandlerEvent<TCodec> = Event<TCodec>;
201-
202191
/// The events emitted by the [`Handler`].
203192
pub enum Event<TCodec>
204193
where

protocols/request-response/src/handler_priv/protocol.rs renamed to protocols/request-response/src/handler/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//! receives a request and sends a response, whereas the
2424
//! outbound upgrade send a request and receives a response.
2525
26-
use crate::codec_priv::Codec;
26+
use crate::codec::Codec;
2727
use crate::RequestId;
2828

2929
use futures::{channel::oneshot, future::BoxFuture, prelude::*};

0 commit comments

Comments
 (0)