feat(request-response): make handler and codec modules private

Resolves #3704.

Pull-Request: #3847.
This commit is contained in:
Thomas Coratger
2023-04-28 12:12:07 +02:00
committed by GitHub
parent d66c8271b5
commit 3f6f08d8e0
7 changed files with 38 additions and 19 deletions

2
Cargo.lock generated
View File

@ -2878,7 +2878,7 @@ dependencies = [
[[package]]
name = "libp2p-request-response"
version = "0.24.0"
version = "0.24.1"
dependencies = [
"async-std",
"async-trait",

View File

@ -1,3 +1,9 @@
## 0.24.1 - unreleased
- Deprecate `handler`, `codec` modules to make them private. See [PR 3847].
[PR 3847]: https://github.com/libp2p/rust-libp2p/pull/3847
## 0.24.0
- Update to `libp2p-core` `v0.39.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-request-response"
edition = "2021"
rust-version = "1.62.0"
description = "Generic Request/Response Protocols"
version = "0.24.0"
version = "0.24.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -20,7 +20,7 @@
mod protocol;
use crate::codec::Codec;
use crate::codec_priv::Codec;
use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD};
use libp2p_swarm::handler::{

View File

@ -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::Codec;
use crate::codec_priv::Codec;
use crate::RequestId;
use futures::{channel::oneshot, future::BoxFuture, prelude::*};

View File

@ -58,18 +58,31 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
pub mod codec;
pub mod handler;
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::*;
}
pub use codec::{Codec, ProtocolName};
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::RequestResponseCodec;
pub use codec_priv::RequestResponseCodec;
pub use handler::ProtocolSupport;
pub use handler_priv::ProtocolSupport;
use futures::channel::oneshot;
use handler::{Handler, RequestProtocol};
use handler_priv::{Handler, RequestProtocol};
use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr};
use libp2p_identity::PeerId;
use libp2p_swarm::{
@ -116,7 +129,7 @@ pub type RequestResponseMessage<TRequest, TResponse, TChannelResponse> =
since = "0.24.0",
note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Event`"
)]
pub type HandlerEvent<TCodec> = handler::Event<TCodec>;
pub type HandlerEvent<TCodec> = handler_priv::Event<TCodec>;
/// An inbound request or response.
#[derive(Debug)]
@ -802,7 +815,7 @@ where
event: THandlerOutEvent<Self>,
) {
match event {
handler::Event::Response {
handler_priv::Event::Response {
request_id,
response,
} => {
@ -819,7 +832,7 @@ where
self.pending_events
.push_back(ToSwarm::GenerateEvent(Event::Message { peer, message }));
}
handler::Event::Request {
handler_priv::Event::Request {
request_id,
request,
sender,
@ -850,7 +863,7 @@ where
}
}
}
handler::Event::ResponseSent(request_id) => {
handler_priv::Event::ResponseSent(request_id) => {
let removed = self.remove_pending_outbound_response(&peer, connection, request_id);
debug_assert!(
removed,
@ -863,7 +876,7 @@ where
request_id,
}));
}
handler::Event::ResponseOmission(request_id) => {
handler_priv::Event::ResponseOmission(request_id) => {
let removed = self.remove_pending_outbound_response(&peer, connection, request_id);
debug_assert!(
removed,
@ -877,7 +890,7 @@ where
error: InboundFailure::ResponseOmission,
}));
}
handler::Event::OutboundTimeout(request_id) => {
handler_priv::Event::OutboundTimeout(request_id) => {
let removed = self.remove_pending_inbound_response(&peer, connection, &request_id);
debug_assert!(
removed,
@ -891,7 +904,7 @@ where
error: OutboundFailure::Timeout,
}));
}
handler::Event::InboundTimeout(request_id) => {
handler_priv::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
@ -905,7 +918,7 @@ where
error: InboundFailure::Timeout,
}));
}
handler::Event::OutboundUnsupportedProtocols(request_id) => {
handler_priv::Event::OutboundUnsupportedProtocols(request_id) => {
let removed = self.remove_pending_inbound_response(&peer, connection, &request_id);
debug_assert!(
removed,
@ -919,7 +932,7 @@ where
error: OutboundFailure::UnsupportedProtocols,
}));
}
handler::Event::InboundUnsupportedProtocols(request_id) => {
handler_priv::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`.