Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libp2p-request-response protocol. #1596

Merged
merged 21 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ members = [
"protocols/noise",
"protocols/ping",
"protocols/plaintext",
"protocols/request-response",
"protocols/secio",
"swarm",
"transports/dns",
Expand Down
13 changes: 8 additions & 5 deletions core/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -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];
}

Expand Down
11 changes: 6 additions & 5 deletions protocols/floodsub/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use libp2p_swarm::{
NetworkBehaviourAction,
PollParameters,
ProtocolsHandler,
OneShotEvent,
OneShotHandler,
NotifyHandler,
DialPeerCondition,
Expand Down Expand Up @@ -237,7 +238,7 @@ impl Floodsub {
}

impl NetworkBehaviour for Floodsub {
type ProtocolsHandler = OneShotHandler<FloodsubProtocol, FloodsubRpc, InnerMessage>;
type ProtocolsHandler = OneShotHandler<FloodsubProtocol, FloodsubRpc, InnerMessage, ()>;
type OutEvent = FloodsubEvent;

fn new_handler(&mut self) -> Self::ProtocolsHandler {
Expand Down Expand Up @@ -287,12 +288,12 @@ impl NetworkBehaviour for Floodsub {
&mut self,
propagation_source: PeerId,
_connection: ConnectionId,
event: InnerMessage,
event: OneShotEvent<InnerMessage, ()>,
) {
// We ignore successful sends event.
// We ignore successful sends or timeouts.
let event = match event {
InnerMessage::Rx(event) => event,
InnerMessage::Sent => return,
OneShotEvent::Success(InnerMessage::Rx(event)) => event,
OneShotEvent::Success(InnerMessage::Sent) | OneShotEvent::Timeout(()) => return,
};

// Update connected peers topics
Expand Down
24 changes: 24 additions & 0 deletions protocols/request-response/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "libp2p-request-response"
edition = "2018"
description = "Generic Request/Response Protocols"
version = "0.19.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]

[dependencies]
bytes = "0.5"
futures = "0.3.1"
libp2p-core = { version = "0.19.0", path = "../../core" }
libp2p-swarm = { version = "0.19.0", path = "../../swarm" }
smallvec = "1.4"

[dev-dependencies]
async-std = "< 1.6"
romanb marked this conversation as resolved.
Show resolved Hide resolved
libp2p-noise = { version = "0.19.0", path = "../noise" }
libp2p-tcp = { version = "0.19.0", path = "../../transports/tcp", features = ["async-std"] }
libp2p-yamux = { version = "0.19.0", path = "../../muxers/yamux" }
rand = "0.7"
Loading