[swarm] Remove substream-specific protocol negotiation version. (#1962)

* 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](https://github.com/libp2p/rust-libp2p/pull/1858).

* Update protocol crate versions and changelogs.

* Clean up documentation.
This commit is contained in:
Roman Borschel
2021-02-25 11:35:52 +01:00
committed by GitHub
parent 6a7576afec
commit 7dd42fcaaf
21 changed files with 80 additions and 72 deletions

View File

@ -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 }
@ -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 }

View File

@ -1,3 +1,7 @@
# 0.28.0 [unreleased]
- Update `libp2p-swarm`.
# 0.27.0 [2021-01-12]
- Update dependencies.

View File

@ -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"
@ -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"

View File

@ -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.

View File

@ -2,7 +2,7 @@
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"
@ -10,7 +10,7 @@ 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"

View File

@ -1,3 +1,7 @@
# 0.28.0 [unreleased]
- Update `libp2p-swarm`.
# 0.27.0 [2021-01-12]
- Update dependencies.

View File

@ -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"
@ -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"

View File

@ -1,3 +1,7 @@
# 0.29.0 [unreleased]
- Update `libp2p-swarm`.
# 0.28.1 [2021-02-15]
- Update dependencies.

View File

@ -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"
@ -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"

View File

@ -1,3 +1,7 @@
# 0.29.0 [unreleased]
- Update `libp2p-swarm`.
# 0.28.1 [2021-02-15]
- Update dependencies.

View File

@ -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"
@ -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"

View File

@ -1,3 +1,7 @@
# 0.28.0 [unreleased]
- Update `libp2p-swarm`.
# 0.27.0 [2021-01-12]
- Update dependencies.

View File

@ -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"
@ -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"

View File

@ -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.

View File

@ -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"
@ -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"] }

View File

@ -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.

View File

@ -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"

View File

@ -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;
@ -242,7 +242,6 @@ pub trait ProtocolsHandler: Send + 'static {
pub struct SubstreamProtocol<TUpgrade, TInfo> {
upgrade: TUpgrade,
info: TInfo,
upgrade_protocol: upgrade::Version,
timeout: Duration,
}
@ -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
@ -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,
}
}
@ -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,
}
}
@ -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)
}
}
@ -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
}
}

View File

@ -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,
@ -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)
}
}
@ -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 (
@ -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)>

View File

@ -116,7 +116,7 @@ where
>>,
/// For each outbound substream request, how to upgrade it. The first element of the tuple
/// is the unique identifier (see `unique_dial_upgrade_id`).
queued_dial_upgrades: Vec<(u64, (upgrade::Version, SendWrapper<TProtoHandler::OutboundProtocol>))>,
queued_dial_upgrades: Vec<(u64, SendWrapper<TProtoHandler::OutboundProtocol>)>,
/// Unique identifier assigned to each queued dial upgrade.
unique_dial_upgrade_id: u64,
/// The currently planned connection & handler shutdown.
@ -246,7 +246,7 @@ where
SubstreamEndpoint::Listener => {
let protocol = self.handler.listen_protocol();
let timeout = *protocol.timeout();
let (_, upgrade, user_data) = protocol.into_upgrade();
let (upgrade, user_data) = protocol.into_upgrade();
let upgrade = upgrade::apply_inbound(substream, SendWrapper(upgrade));
let timeout = Delay::new(timeout);
self.negotiating_in.push(SubstreamUpgrade {
@ -268,7 +268,8 @@ where
}
};
let (_, (mut version, upgrade)) = self.queued_dial_upgrades.remove(pos);
let (_, upgrade) = self.queued_dial_upgrades.remove(pos);
let mut version = upgrade::Version::default();
if let Some(v) = self.substream_upgrade_protocol_override {
if v != version {
log::debug!("Substream upgrade protocol override: {:?} -> {:?}", version, v);
@ -336,8 +337,8 @@ where
let id = self.unique_dial_upgrade_id;
let timeout = *protocol.timeout();
self.unique_dial_upgrade_id += 1;
let (version, upgrade, info) = protocol.into_upgrade();
self.queued_dial_upgrades.push((id, (version, SendWrapper(upgrade))));
let (upgrade, info) = protocol.into_upgrade();
self.queued_dial_upgrades.push((id, SendWrapper(upgrade)));
return Poll::Ready(Ok(
ConnectionHandlerEvent::OutboundSubstreamRequest((id, info, timeout)),
));

View File

@ -111,8 +111,8 @@ where
let proto1 = self.proto1.listen_protocol();
let proto2 = self.proto2.listen_protocol();
let timeout = *std::cmp::max(proto1.timeout(), proto2.timeout());
let (_, u1, i1) = proto1.into_upgrade();
let (_, u2, i2) = proto2.into_upgrade();
let (u1, i1) = proto1.into_upgrade();
let (u2, i2) = proto2.into_upgrade();
let choice = SelectUpgrade::new(SendWrapper(u1), SendWrapper(u2));
SubstreamProtocol::new(choice, (i1, i2)).with_timeout(timeout)
}