Skip to content

Commit

Permalink
[swarm] Remove substream-specific protocol negotiation version. (#1962)
Browse files Browse the repository at this point in the history
* Remove substream-specific protocol negotiation version.

Remove the option for a substream-specific multistream select protocol override.
The override at this granularity is no longer deemed useful, in particular because
it can usually not be configured for existing protocols like `libp2p-kad` and others.
There is a `Swarm`-scoped configuration for this version available since
[1858](#1858).

* Update protocol crate versions and changelogs.

* Clean up documentation.
  • Loading branch information
romanb authored Feb 25, 2021
1 parent 6a7576a commit 7dd42fc
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 72 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ bytes = "1"
futures = "0.3.1"
lazy_static = "1.2"
libp2p-core = { version = "0.27.1", path = "core" }
libp2p-floodsub = { version = "0.27.0", path = "protocols/floodsub", optional = true }
libp2p-gossipsub = { version = "0.28.0", path = "./protocols/gossipsub", optional = true }
libp2p-identify = { version = "0.27.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.28.1", path = "protocols/kad", optional = true }
libp2p-floodsub = { version = "0.28.0", path = "protocols/floodsub", optional = true }
libp2p-gossipsub = { version = "0.29.0", path = "./protocols/gossipsub", optional = true }
libp2p-identify = { version = "0.28.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.29.0", path = "protocols/kad", optional = true }
libp2p-mplex = { version = "0.27.1", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.29.0", path = "transports/noise", optional = true }
libp2p-ping = { version = "0.27.0", path = "protocols/ping", optional = true }
libp2p-ping = { version = "0.28.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.27.1", path = "transports/plaintext", optional = true }
libp2p-pnet = { version = "0.20.0", path = "transports/pnet", optional = true }
libp2p-request-response = { version = "0.9.1", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.27.2", path = "swarm" }
libp2p-request-response = { version = "0.10.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.28.0", path = "swarm" }
libp2p-swarm-derive = { version = "0.22.0", path = "swarm-derive" }
libp2p-uds = { version = "0.27.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.27.0", path = "transports/wasm-ext", optional = true }
Expand All @@ -86,7 +86,7 @@ wasm-timer = "0.2.4"
[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies]
libp2p-deflate = { version = "0.27.1", path = "transports/deflate", optional = true }
libp2p-dns = { version = "0.27.0", path = "transports/dns", optional = true }
libp2p-mdns = { version = "0.28.1", path = "protocols/mdns", optional = true }
libp2p-mdns = { version = "0.29.0", path = "protocols/mdns", optional = true }
libp2p-tcp = { version = "0.27.1", path = "transports/tcp", optional = true }
libp2p-websocket = { version = "0.28.0", path = "transports/websocket", optional = true }

Expand Down
4 changes: 4 additions & 0 deletions protocols/floodsub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.28.0 [unreleased]

- Update `libp2p-swarm`.

# 0.27.0 [2021-01-12]

- Update dependencies.
Expand Down
4 changes: 2 additions & 2 deletions protocols/floodsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-floodsub"
edition = "2018"
description = "Floodsub protocol for libp2p"
version = "0.27.0"
version = "0.28.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -14,7 +14,7 @@ cuckoofilter = "0.5.0"
fnv = "1.0"
futures = "0.3.1"
libp2p-core = { version = "0.27.0", path = "../../core" }
libp2p-swarm = { version = "0.27.0", path = "../../swarm" }
libp2p-swarm = { version = "0.28.0", path = "../../swarm" }
log = "0.4"
prost = "0.7"
rand = "0.7"
Expand Down
4 changes: 4 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.29.0 [unreleased]

- Update `libp2p-swarm`.

# 0.28.0 [2021-02-15]

- Prevent non-published messages being added to caches.
Expand Down
4 changes: 2 additions & 2 deletions protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
name = "libp2p-gossipsub"
edition = "2018"
description = "Gossipsub protocol for libp2p"
version = "0.28.0"
version = "0.29.0"
authors = ["Age Manning <Age@AgeManning.com>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]

[dependencies]
libp2p-swarm = { version = "0.27.0", path = "../../swarm" }
libp2p-swarm = { version = "0.28.0", path = "../../swarm" }
libp2p-core = { version = "0.27.0", path = "../../core" }
bytes = "1.0"
byteorder = "1.3.4"
Expand Down
4 changes: 4 additions & 0 deletions protocols/identify/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.28.0 [unreleased]

- Update `libp2p-swarm`.

# 0.27.0 [2021-01-12]

- Update dependencies.
Expand Down
4 changes: 2 additions & 2 deletions protocols/identify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-identify"
edition = "2018"
description = "Nodes identifcation protocol for libp2p"
version = "0.27.0"
version = "0.28.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.27.0", path = "../../core" }
libp2p-swarm = { version = "0.27.0", path = "../../swarm" }
libp2p-swarm = { version = "0.28.0", path = "../../swarm" }
log = "0.4.1"
prost = "0.7"
smallvec = "1.0"
Expand Down
4 changes: 4 additions & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.29.0 [unreleased]

- Update `libp2p-swarm`.

# 0.28.1 [2021-02-15]

- Update dependencies.
Expand Down
4 changes: 2 additions & 2 deletions protocols/kad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-kad"
edition = "2018"
description = "Kademlia protocol for libp2p"
version = "0.28.1"
version = "0.29.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -18,7 +18,7 @@ asynchronous-codec = "0.6"
futures = "0.3.1"
log = "0.4"
libp2p-core = { version = "0.27.0", path = "../../core" }
libp2p-swarm = { version = "0.27.0", path = "../../swarm" }
libp2p-swarm = { version = "0.28.0", path = "../../swarm" }
prost = "0.7"
rand = "0.7.2"
sha2 = "0.9.1"
Expand Down
4 changes: 4 additions & 0 deletions protocols/mdns/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.29.0 [unreleased]

- Update `libp2p-swarm`.

# 0.28.1 [2021-02-15]

- Update dependencies.
Expand Down
4 changes: 2 additions & 2 deletions protocols/mdns/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "libp2p-mdns"
edition = "2018"
version = "0.28.1"
version = "0.29.0"
description = "Implementation of the libp2p mDNS discovery method"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
Expand All @@ -17,7 +17,7 @@ futures = "0.3.8"
if-watch = "0.1.8"
lazy_static = "1.4.0"
libp2p-core = { version = "0.27.0", path = "../../core" }
libp2p-swarm = { version = "0.27.0", path = "../../swarm" }
libp2p-swarm = { version = "0.28.0", path = "../../swarm" }
log = "0.4.11"
rand = "0.7.3"
smallvec = "1.5.0"
Expand Down
4 changes: 4 additions & 0 deletions protocols/ping/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.28.0 [unreleased]

- Update `libp2p-swarm`.

# 0.27.0 [2021-01-12]

- Update dependencies.
Expand Down
4 changes: 2 additions & 2 deletions protocols/ping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-ping"
edition = "2018"
description = "Ping protocol for libp2p"
version = "0.27.0"
version = "0.28.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.27.0", path = "../../core" }
libp2p-swarm = { version = "0.27.0", path = "../../swarm" }
libp2p-swarm = { version = "0.28.0", path = "../../swarm" }
log = "0.4.1"
rand = "0.7.2"
void = "1.0"
Expand Down
4 changes: 4 additions & 0 deletions protocols/request-response/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.10.0 [unreleased]

- Update `libp2p-swarm`.

# 0.9.1 [2021-02-15]

- Make `is_pending_outbound` return true on pending connection.
Expand Down
4 changes: 2 additions & 2 deletions protocols/request-response/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-request-response"
edition = "2018"
description = "Generic Request/Response Protocols"
version = "0.9.1"
version = "0.10.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -14,7 +14,7 @@ async-trait = "0.1"
bytes = "1"
futures = "0.3.1"
libp2p-core = { version = "0.27.0", path = "../../core" }
libp2p-swarm = { version = "0.27.0", path = "../../swarm" }
libp2p-swarm = { version = "0.28.0", path = "../../swarm" }
log = "0.4.11"
lru = "0.6"
minicbor = { version = "0.7", features = ["std", "derive"] }
Expand Down
8 changes: 8 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 0.28.0 [unreleased]

- Remove the option for a substream-specific multistream select protocol override.
The override at this granularity is no longer deemed useful, in particular because
it can usually not be configured for existing protocols like `libp2p-kad` and others.
There is a `Swarm`-scoped configuration for this version available since
[1858](https://github.com/libp2p/rust-libp2p/pull/1858).

# 0.27.2 [2021-02-04]

- Have `ToggleProtoHandler` ignore listen upgrade errors when disabled.
Expand Down
2 changes: 1 addition & 1 deletion swarm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-swarm"
edition = "2018"
description = "The libp2p swarm"
version = "0.27.2"
version = "0.28.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
19 changes: 4 additions & 15 deletions swarm/src/protocols_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use libp2p_core::{
ConnectedPoint,
Multiaddr,
PeerId,
upgrade::{self, UpgradeError},
upgrade::UpgradeError,
};
use std::{cmp::Ordering, error, fmt, task::Context, task::Poll, time::Duration};
use wasm_timer::Instant;
Expand Down Expand Up @@ -242,7 +242,6 @@ pub trait ProtocolsHandler: Send + 'static {
pub struct SubstreamProtocol<TUpgrade, TInfo> {
upgrade: TUpgrade,
info: TInfo,
upgrade_protocol: upgrade::Version,
timeout: Duration,
}

Expand All @@ -255,18 +254,10 @@ impl<TUpgrade, TInfo> SubstreamProtocol<TUpgrade, TInfo> {
SubstreamProtocol {
upgrade,
info,
upgrade_protocol: upgrade::Version::V1,
timeout: Duration::from_secs(10),
}
}

/// Sets the multistream-select protocol (version) to use for negotiating
/// protocols upgrades on outbound substreams.
pub fn with_upgrade_protocol(mut self, version: upgrade::Version) -> Self {
self.upgrade_protocol = version;
self
}

/// Maps a function over the protocol upgrade.
pub fn map_upgrade<U, F>(self, f: F) -> SubstreamProtocol<U, TInfo>
where
Expand All @@ -275,7 +266,6 @@ impl<TUpgrade, TInfo> SubstreamProtocol<TUpgrade, TInfo> {
SubstreamProtocol {
upgrade: f(self.upgrade),
info: self.info,
upgrade_protocol: self.upgrade_protocol,
timeout: self.timeout,
}
}
Expand All @@ -288,7 +278,6 @@ impl<TUpgrade, TInfo> SubstreamProtocol<TUpgrade, TInfo> {
SubstreamProtocol {
upgrade: self.upgrade,
info: f(self.info),
upgrade_protocol: self.upgrade_protocol,
timeout: self.timeout,
}
}
Expand All @@ -315,8 +304,8 @@ impl<TUpgrade, TInfo> SubstreamProtocol<TUpgrade, TInfo> {
}

/// Converts the substream protocol configuration into the contained upgrade.
pub fn into_upgrade(self) -> (upgrade::Version, TUpgrade, TInfo) {
(self.upgrade_protocol, self.upgrade, self.info)
pub fn into_upgrade(self) -> (TUpgrade, TInfo) {
(self.upgrade, self.info)
}
}

Expand Down Expand Up @@ -512,7 +501,7 @@ where T: ProtocolsHandler
}

fn inbound_protocol(&self) -> <Self::Handler as ProtocolsHandler>::InboundProtocol {
self.listen_protocol().into_upgrade().1
self.listen_protocol().into_upgrade().0
}
}

Expand Down
36 changes: 9 additions & 27 deletions swarm/src/protocols_handler/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::upgrade::{
};
use futures::{future::BoxFuture, prelude::*};
use libp2p_core::{ConnectedPoint, Multiaddr, PeerId};
use libp2p_core::upgrade::{self, ProtocolName, UpgradeError, NegotiationError, ProtocolError};
use libp2p_core::upgrade::{ProtocolName, UpgradeError, NegotiationError, ProtocolError};
use rand::Rng;
use std::{
cmp,
Expand Down Expand Up @@ -76,15 +76,12 @@ where
/// Create and populate a `MultiHandler` from the given handler iterator.
///
/// It is an error for any two protocols handlers to share the same protocol name.
///
/// > **Note**: All handlers should use the same [`upgrade::Version`] for
/// > the inbound and outbound [`SubstreamProtocol`]s.
pub fn try_from_iter<I>(iter: I) -> Result<Self, DuplicateProtonameError>
where
I: IntoIterator<Item = (K, H)>
{
let m = MultiHandler { handlers: HashMap::from_iter(iter) };
uniq_proto_names(m.handlers.values().map(|h| h.listen_protocol().into_upgrade().1))?;
uniq_proto_names(m.handlers.values().map(|h| h.listen_protocol().into_upgrade().0))?;
Ok(m)
}
}
Expand All @@ -105,34 +102,22 @@ where
type OutboundOpenInfo = (K, <H as ProtocolsHandler>::OutboundOpenInfo);

fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
let (upgrade, info, timeout, version) = self.handlers.iter()
let (upgrade, info, timeout) = self.handlers.iter()
.map(|(key, handler)| {
let proto = handler.listen_protocol();
let timeout = *proto.timeout();
let (version, upgrade, info) = proto.into_upgrade();
(key.clone(), (version, upgrade, info, timeout))
let (upgrade, info) = proto.into_upgrade();
(key.clone(), (upgrade, info, timeout))
})
.fold((Upgrade::new(), Info::new(), Duration::from_secs(0), None),
|(mut upg, mut inf, mut timeout, mut version), (k, (v, u, i, t))| {
.fold((Upgrade::new(), Info::new(), Duration::from_secs(0)),
|(mut upg, mut inf, mut timeout), (k, (u, i, t))| {
upg.upgrades.push((k.clone(), u));
inf.infos.push((k, i));
timeout = cmp::max(timeout, t);
version = version.map_or(Some(v), |vv|
if v != vv {
// Different upgrade (i.e. protocol negotiation) protocol
// versions are usually incompatible and not negotiated
// themselves, so a protocol upgrade may fail.
log::warn!("Differing upgrade versions. Defaulting to V1.");
Some(upgrade::Version::V1)
} else {
Some(v)
});
(upg, inf, timeout, version)
(upg, inf, timeout)
}
);
SubstreamProtocol::new(upgrade, info)
.with_timeout(timeout)
.with_upgrade_protocol(version.unwrap_or(upgrade::Version::V1))
SubstreamProtocol::new(upgrade, info).with_timeout(timeout)
}

fn inject_fully_negotiated_outbound (
Expand Down Expand Up @@ -315,9 +300,6 @@ where
/// Create and populate an `IntoMultiHandler` from the given iterator.
///
/// It is an error for any two protocols handlers to share the same protocol name.
///
/// > **Note**: All handlers should use the same [`upgrade::Version`] for
/// > the inbound and outbound [`SubstreamProtocol`]s.
pub fn try_from_iter<I>(iter: I) -> Result<Self, DuplicateProtonameError>
where
I: IntoIterator<Item = (K, H)>
Expand Down
Loading

0 comments on commit 7dd42fc

Please sign in to comment.