mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-03 19:51:33 +00:00
Add Throttled
to libp2p-request-response. (#1696)
* Use a single exchange instead of two one_shots. * Add `Throttled` to libp2p-request-response. Wraps the existing `RequestResponse` behaviour and applies strict limits to the number of inbound and outbound requests per peer. The wrapper is opt-in and if not used, the protocol behaviour of `RequestResponse` does not change. This PR also does not introduce an extra protocol, hence the limits applied need to be known a priori for all nodes which is not always possible or desirable. As mentioned in #1687 I think that we should eventually augment the protocol with metadata which allows a more dynamic exchange of requests and responses. This PR also replaces the two oneshot channels with a single one from the scambio crate which saves one allocation per request/response. If not desirable because the crate has seen less testing the first commit could be reverted. * Fix rustdoc error. * Remove some leftovers from development. * Add docs to `NetworBehaviourAction::{map_in,map_out}`. * Apply suggestions from code review Co-authored-by: Roman Borschel <romanb@users.noreply.github.com> * Add `ping_protocol_throttled` test. * Add another test. * Revert "Use a single exchange instead of two one_shots." This reverts commit e34e1297d411298f6c69e238aa6c96e0b795d989. # Conflicts: # protocols/request-response/Cargo.toml # protocols/request-response/src/handler/protocol.rs * Update CHANGELOG. * Update CHANGELOG. Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
This commit is contained in:
@ -70,9 +70,11 @@
|
||||
|
||||
pub mod codec;
|
||||
pub mod handler;
|
||||
pub mod throttled;
|
||||
|
||||
pub use codec::{RequestResponseCodec, ProtocolName};
|
||||
pub use handler::ProtocolSupport;
|
||||
pub use throttled::Throttled;
|
||||
|
||||
use futures::{
|
||||
channel::oneshot,
|
||||
@ -309,6 +311,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrap this behaviour in [`Throttled`] to limit the number of concurrent requests per peer.
|
||||
pub fn throttled(self) -> Throttled<TCodec> {
|
||||
Throttled::new(self)
|
||||
}
|
||||
|
||||
/// Initiates sending a request.
|
||||
///
|
||||
/// If the targeted peer is currently not connected, a dialing
|
||||
@ -604,4 +611,3 @@ struct Connection {
|
||||
id: ConnectionId,
|
||||
address: Option<Multiaddr>,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user