mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-21 22:01:34 +00:00
feat(request-response): make handler and codec modules private
Resolves #3704. Pull-Request: #3847.
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2878,7 +2878,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libp2p-request-response"
|
name = "libp2p-request-response"
|
||||||
version = "0.24.0"
|
version = "0.24.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
@ -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
|
## 0.24.0
|
||||||
|
|
||||||
- Update to `libp2p-core` `v0.39.0`.
|
- Update to `libp2p-core` `v0.39.0`.
|
||||||
|
@ -3,7 +3,7 @@ name = "libp2p-request-response"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.62.0"
|
rust-version = "1.62.0"
|
||||||
description = "Generic Request/Response Protocols"
|
description = "Generic Request/Response Protocols"
|
||||||
version = "0.24.0"
|
version = "0.24.1"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
mod protocol;
|
mod protocol;
|
||||||
|
|
||||||
use crate::codec::Codec;
|
use crate::codec_priv::Codec;
|
||||||
use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD};
|
use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD};
|
||||||
|
|
||||||
use libp2p_swarm::handler::{
|
use libp2p_swarm::handler::{
|
@ -23,7 +23,7 @@
|
|||||||
//! receives a request and sends a response, whereas the
|
//! receives a request and sends a response, whereas the
|
||||||
//! outbound upgrade send a request and receives a response.
|
//! outbound upgrade send a request and receives a response.
|
||||||
|
|
||||||
use crate::codec::Codec;
|
use crate::codec_priv::Codec;
|
||||||
use crate::RequestId;
|
use crate::RequestId;
|
||||||
|
|
||||||
use futures::{channel::oneshot, future::BoxFuture, prelude::*};
|
use futures::{channel::oneshot, future::BoxFuture, prelude::*};
|
@ -58,18 +58,31 @@
|
|||||||
|
|
||||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||||
|
|
||||||
pub mod codec;
|
mod codec_priv;
|
||||||
pub mod handler;
|
#[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)]
|
#[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 futures::channel::oneshot;
|
||||||
use handler::{Handler, RequestProtocol};
|
use handler_priv::{Handler, RequestProtocol};
|
||||||
use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr};
|
use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr};
|
||||||
use libp2p_identity::PeerId;
|
use libp2p_identity::PeerId;
|
||||||
use libp2p_swarm::{
|
use libp2p_swarm::{
|
||||||
@ -116,7 +129,7 @@ pub type RequestResponseMessage<TRequest, TResponse, TChannelResponse> =
|
|||||||
since = "0.24.0",
|
since = "0.24.0",
|
||||||
note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Event`"
|
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.
|
/// An inbound request or response.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -802,7 +815,7 @@ where
|
|||||||
event: THandlerOutEvent<Self>,
|
event: THandlerOutEvent<Self>,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
handler::Event::Response {
|
handler_priv::Event::Response {
|
||||||
request_id,
|
request_id,
|
||||||
response,
|
response,
|
||||||
} => {
|
} => {
|
||||||
@ -819,7 +832,7 @@ where
|
|||||||
self.pending_events
|
self.pending_events
|
||||||
.push_back(ToSwarm::GenerateEvent(Event::Message { peer, message }));
|
.push_back(ToSwarm::GenerateEvent(Event::Message { peer, message }));
|
||||||
}
|
}
|
||||||
handler::Event::Request {
|
handler_priv::Event::Request {
|
||||||
request_id,
|
request_id,
|
||||||
request,
|
request,
|
||||||
sender,
|
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);
|
let removed = self.remove_pending_outbound_response(&peer, connection, request_id);
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
removed,
|
removed,
|
||||||
@ -863,7 +876,7 @@ where
|
|||||||
request_id,
|
request_id,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
handler::Event::ResponseOmission(request_id) => {
|
handler_priv::Event::ResponseOmission(request_id) => {
|
||||||
let removed = self.remove_pending_outbound_response(&peer, connection, request_id);
|
let removed = self.remove_pending_outbound_response(&peer, connection, request_id);
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
removed,
|
removed,
|
||||||
@ -877,7 +890,7 @@ where
|
|||||||
error: InboundFailure::ResponseOmission,
|
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);
|
let removed = self.remove_pending_inbound_response(&peer, connection, &request_id);
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
removed,
|
removed,
|
||||||
@ -891,7 +904,7 @@ where
|
|||||||
error: OutboundFailure::Timeout,
|
error: OutboundFailure::Timeout,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
handler::Event::InboundTimeout(request_id) => {
|
handler_priv::Event::InboundTimeout(request_id) => {
|
||||||
// Note: `Event::InboundTimeout` is emitted both for timing
|
// Note: `Event::InboundTimeout` is emitted both for timing
|
||||||
// out to receive the request and for timing out sending the response. In the former
|
// 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
|
// case the request is never added to `pending_outbound_responses` and thus one can
|
||||||
@ -905,7 +918,7 @@ where
|
|||||||
error: InboundFailure::Timeout,
|
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);
|
let removed = self.remove_pending_inbound_response(&peer, connection, &request_id);
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
removed,
|
removed,
|
||||||
@ -919,7 +932,7 @@ where
|
|||||||
error: OutboundFailure::UnsupportedProtocols,
|
error: OutboundFailure::UnsupportedProtocols,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
handler::Event::InboundUnsupportedProtocols(request_id) => {
|
handler_priv::Event::InboundUnsupportedProtocols(request_id) => {
|
||||||
// Note: No need to call `self.remove_pending_outbound_response`,
|
// Note: No need to call `self.remove_pending_outbound_response`,
|
||||||
// `Event::Request` was never emitted for this request and
|
// `Event::Request` was never emitted for this request and
|
||||||
// thus request was never added to `pending_outbound_responses`.
|
// thus request was never added to `pending_outbound_responses`.
|
||||||
|
Reference in New Issue
Block a user