mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-26 00:01:33 +00:00
Add libp2p-request-response protocol. (#1596)
* Add the libp2p-request-response protocol. This crate provides a generic implementation for request/response protocols, whereby each request is sent on a new substream. * Fix OneShotHandler usage in floodsub. * Custom ProtocolsHandler and multiple protocols. 1. Implement a custom ProtocolsHandler instead of using the OneShotHandler for better control and error handling. In particular, all request/response sending/receiving is kept in the substreams upgrades and thus the background task of a connection. 2. Support multiple protocols (usually protocol versions) with a single `RequestResponse` instance, with configurable inbound/outbound support. * Small doc clarification. * Remove unnecessary Sync bounds. * Remove redundant Clone constraint. * Update protocols/request-response/Cargo.toml Co-authored-by: Toralf Wittner <tw@dtex.org> * Update dev-dependencies. * Update Cargo.tomls. * Add changelog. * Remove Sync bound from RequestResponseCodec::Protocol. Apparently the compiler just needs some help with the scope of borrows, which is unfortunate. * Try async-trait. * Allow checking whether a ResponseChannel is still open. Also expand the commentary on `send_response` to indicate that responses may be discard if they come in too late. * Add `RequestResponse::is_pending`. As an analogue of `ResponseChannel::is_open` for outbound requests. * Revert now unnecessary changes to the OneShotHandler. Since `libp2p-request-response` is no longer using it. * Update CHANGELOG for libp2p-swarm. Co-authored-by: Toralf Wittner <tw@dtex.org>
This commit is contained in:
@ -87,12 +87,12 @@ pub use self::{
|
||||
///
|
||||
/// # Context
|
||||
///
|
||||
/// In situations where we provide a list of protocols that we support, the elements of that list are required to
|
||||
/// implement the [`ProtocolName`] trait.
|
||||
/// In situations where we provide a list of protocols that we support,
|
||||
/// the elements of that list are required to implement the [`ProtocolName`] trait.
|
||||
///
|
||||
/// Libp2p will call the [`ProtocolName::protocol_name`] trait method on each element of that list, and transmit the
|
||||
/// returned value on the network. If the remote accepts a given protocol, the element serves as the return value of
|
||||
/// the function that performed the negotiation.
|
||||
/// Libp2p will call [`ProtocolName::protocol_name`] on each element of that list, and transmit the
|
||||
/// returned value on the network. If the remote accepts a given protocol, the element
|
||||
/// serves as the return value of the function that performed the negotiation.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
@ -118,6 +118,9 @@ pub use self::{
|
||||
///
|
||||
pub trait ProtocolName {
|
||||
/// The protocol name as bytes. Transmitted on the network.
|
||||
///
|
||||
/// **Note:** Valid protocol names must start with `/` and
|
||||
/// not exceed 140 bytes in length.
|
||||
fn protocol_name(&self) -> &[u8];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user