mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-15 02:51:25 +00:00
[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:
16
Cargo.toml
16
Cargo.toml
@ -62,17 +62,17 @@ bytes = "1"
|
|||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
lazy_static = "1.2"
|
lazy_static = "1.2"
|
||||||
libp2p-core = { version = "0.27.1", path = "core" }
|
libp2p-core = { version = "0.27.1", path = "core" }
|
||||||
libp2p-floodsub = { version = "0.27.0", path = "protocols/floodsub", optional = true }
|
libp2p-floodsub = { version = "0.28.0", path = "protocols/floodsub", optional = true }
|
||||||
libp2p-gossipsub = { version = "0.28.0", path = "./protocols/gossipsub", optional = true }
|
libp2p-gossipsub = { version = "0.29.0", path = "./protocols/gossipsub", optional = true }
|
||||||
libp2p-identify = { version = "0.27.0", path = "protocols/identify", optional = true }
|
libp2p-identify = { version = "0.28.0", path = "protocols/identify", optional = true }
|
||||||
libp2p-kad = { version = "0.28.1", path = "protocols/kad", 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-mplex = { version = "0.27.1", path = "muxers/mplex", optional = true }
|
||||||
libp2p-noise = { version = "0.29.0", path = "transports/noise", 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-plaintext = { version = "0.27.1", path = "transports/plaintext", optional = true }
|
||||||
libp2p-pnet = { version = "0.20.0", path = "transports/pnet", 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-request-response = { version = "0.10.0", path = "protocols/request-response", optional = true }
|
||||||
libp2p-swarm = { version = "0.27.2", path = "swarm" }
|
libp2p-swarm = { version = "0.28.0", path = "swarm" }
|
||||||
libp2p-swarm-derive = { version = "0.22.0", path = "swarm-derive" }
|
libp2p-swarm-derive = { version = "0.22.0", path = "swarm-derive" }
|
||||||
libp2p-uds = { version = "0.27.0", path = "transports/uds", optional = true }
|
libp2p-uds = { version = "0.27.0", path = "transports/uds", optional = true }
|
||||||
libp2p-wasm-ext = { version = "0.27.0", path = "transports/wasm-ext", 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]
|
[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-deflate = { version = "0.27.1", path = "transports/deflate", optional = true }
|
||||||
libp2p-dns = { version = "0.27.0", path = "transports/dns", 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-tcp = { version = "0.27.1", path = "transports/tcp", optional = true }
|
||||||
libp2p-websocket = { version = "0.28.0", path = "transports/websocket", optional = true }
|
libp2p-websocket = { version = "0.28.0", path = "transports/websocket", optional = true }
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# 0.28.0 [unreleased]
|
||||||
|
|
||||||
|
- Update `libp2p-swarm`.
|
||||||
|
|
||||||
# 0.27.0 [2021-01-12]
|
# 0.27.0 [2021-01-12]
|
||||||
|
|
||||||
- Update dependencies.
|
- Update dependencies.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "libp2p-floodsub"
|
name = "libp2p-floodsub"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Floodsub protocol for libp2p"
|
description = "Floodsub protocol for libp2p"
|
||||||
version = "0.27.0"
|
version = "0.28.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
@ -14,7 +14,7 @@ cuckoofilter = "0.5.0"
|
|||||||
fnv = "1.0"
|
fnv = "1.0"
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
libp2p-core = { version = "0.27.0", path = "../../core" }
|
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"
|
log = "0.4"
|
||||||
prost = "0.7"
|
prost = "0.7"
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# 0.29.0 [unreleased]
|
||||||
|
|
||||||
|
- Update `libp2p-swarm`.
|
||||||
|
|
||||||
# 0.28.0 [2021-02-15]
|
# 0.28.0 [2021-02-15]
|
||||||
|
|
||||||
- Prevent non-published messages being added to caches.
|
- Prevent non-published messages being added to caches.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "libp2p-gossipsub"
|
name = "libp2p-gossipsub"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Gossipsub protocol for libp2p"
|
description = "Gossipsub protocol for libp2p"
|
||||||
version = "0.28.0"
|
version = "0.29.0"
|
||||||
authors = ["Age Manning <Age@AgeManning.com>"]
|
authors = ["Age Manning <Age@AgeManning.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
@ -10,7 +10,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
|
|||||||
categories = ["network-programming", "asynchronous"]
|
categories = ["network-programming", "asynchronous"]
|
||||||
|
|
||||||
[dependencies]
|
[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" }
|
libp2p-core = { version = "0.27.0", path = "../../core" }
|
||||||
bytes = "1.0"
|
bytes = "1.0"
|
||||||
byteorder = "1.3.4"
|
byteorder = "1.3.4"
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# 0.28.0 [unreleased]
|
||||||
|
|
||||||
|
- Update `libp2p-swarm`.
|
||||||
|
|
||||||
# 0.27.0 [2021-01-12]
|
# 0.27.0 [2021-01-12]
|
||||||
|
|
||||||
- Update dependencies.
|
- Update dependencies.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "libp2p-identify"
|
name = "libp2p-identify"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Nodes identifcation protocol for libp2p"
|
description = "Nodes identifcation protocol for libp2p"
|
||||||
version = "0.27.0"
|
version = "0.28.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
libp2p-core = { version = "0.27.0", path = "../../core" }
|
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"
|
log = "0.4.1"
|
||||||
prost = "0.7"
|
prost = "0.7"
|
||||||
smallvec = "1.0"
|
smallvec = "1.0"
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# 0.29.0 [unreleased]
|
||||||
|
|
||||||
|
- Update `libp2p-swarm`.
|
||||||
|
|
||||||
# 0.28.1 [2021-02-15]
|
# 0.28.1 [2021-02-15]
|
||||||
|
|
||||||
- Update dependencies.
|
- Update dependencies.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "libp2p-kad"
|
name = "libp2p-kad"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Kademlia protocol for libp2p"
|
description = "Kademlia protocol for libp2p"
|
||||||
version = "0.28.1"
|
version = "0.29.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
@ -18,7 +18,7 @@ asynchronous-codec = "0.6"
|
|||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
libp2p-core = { version = "0.27.0", path = "../../core" }
|
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"
|
prost = "0.7"
|
||||||
rand = "0.7.2"
|
rand = "0.7.2"
|
||||||
sha2 = "0.9.1"
|
sha2 = "0.9.1"
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# 0.29.0 [unreleased]
|
||||||
|
|
||||||
|
- Update `libp2p-swarm`.
|
||||||
|
|
||||||
# 0.28.1 [2021-02-15]
|
# 0.28.1 [2021-02-15]
|
||||||
|
|
||||||
- Update dependencies.
|
- Update dependencies.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "libp2p-mdns"
|
name = "libp2p-mdns"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
version = "0.28.1"
|
version = "0.29.0"
|
||||||
description = "Implementation of the libp2p mDNS discovery method"
|
description = "Implementation of the libp2p mDNS discovery method"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@ -17,7 +17,7 @@ futures = "0.3.8"
|
|||||||
if-watch = "0.1.8"
|
if-watch = "0.1.8"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
libp2p-core = { version = "0.27.0", path = "../../core" }
|
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"
|
log = "0.4.11"
|
||||||
rand = "0.7.3"
|
rand = "0.7.3"
|
||||||
smallvec = "1.5.0"
|
smallvec = "1.5.0"
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# 0.28.0 [unreleased]
|
||||||
|
|
||||||
|
- Update `libp2p-swarm`.
|
||||||
|
|
||||||
# 0.27.0 [2021-01-12]
|
# 0.27.0 [2021-01-12]
|
||||||
|
|
||||||
- Update dependencies.
|
- Update dependencies.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "libp2p-ping"
|
name = "libp2p-ping"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Ping protocol for libp2p"
|
description = "Ping protocol for libp2p"
|
||||||
version = "0.27.0"
|
version = "0.28.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
libp2p-core = { version = "0.27.0", path = "../../core" }
|
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"
|
log = "0.4.1"
|
||||||
rand = "0.7.2"
|
rand = "0.7.2"
|
||||||
void = "1.0"
|
void = "1.0"
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
# 0.10.0 [unreleased]
|
||||||
|
|
||||||
|
- Update `libp2p-swarm`.
|
||||||
|
|
||||||
# 0.9.1 [2021-02-15]
|
# 0.9.1 [2021-02-15]
|
||||||
|
|
||||||
- Make `is_pending_outbound` return true on pending connection.
|
- Make `is_pending_outbound` return true on pending connection.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "libp2p-request-response"
|
name = "libp2p-request-response"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Generic Request/Response Protocols"
|
description = "Generic Request/Response Protocols"
|
||||||
version = "0.9.1"
|
version = "0.10.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
@ -14,7 +14,7 @@ async-trait = "0.1"
|
|||||||
bytes = "1"
|
bytes = "1"
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
libp2p-core = { version = "0.27.0", path = "../../core" }
|
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"
|
log = "0.4.11"
|
||||||
lru = "0.6"
|
lru = "0.6"
|
||||||
minicbor = { version = "0.7", features = ["std", "derive"] }
|
minicbor = { version = "0.7", features = ["std", "derive"] }
|
||||||
|
@ -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]
|
# 0.27.2 [2021-02-04]
|
||||||
|
|
||||||
- Have `ToggleProtoHandler` ignore listen upgrade errors when disabled.
|
- Have `ToggleProtoHandler` ignore listen upgrade errors when disabled.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "libp2p-swarm"
|
name = "libp2p-swarm"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "The libp2p swarm"
|
description = "The libp2p swarm"
|
||||||
version = "0.27.2"
|
version = "0.28.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
|
@ -55,7 +55,7 @@ use libp2p_core::{
|
|||||||
ConnectedPoint,
|
ConnectedPoint,
|
||||||
Multiaddr,
|
Multiaddr,
|
||||||
PeerId,
|
PeerId,
|
||||||
upgrade::{self, UpgradeError},
|
upgrade::UpgradeError,
|
||||||
};
|
};
|
||||||
use std::{cmp::Ordering, error, fmt, task::Context, task::Poll, time::Duration};
|
use std::{cmp::Ordering, error, fmt, task::Context, task::Poll, time::Duration};
|
||||||
use wasm_timer::Instant;
|
use wasm_timer::Instant;
|
||||||
@ -242,7 +242,6 @@ pub trait ProtocolsHandler: Send + 'static {
|
|||||||
pub struct SubstreamProtocol<TUpgrade, TInfo> {
|
pub struct SubstreamProtocol<TUpgrade, TInfo> {
|
||||||
upgrade: TUpgrade,
|
upgrade: TUpgrade,
|
||||||
info: TInfo,
|
info: TInfo,
|
||||||
upgrade_protocol: upgrade::Version,
|
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,18 +254,10 @@ impl<TUpgrade, TInfo> SubstreamProtocol<TUpgrade, TInfo> {
|
|||||||
SubstreamProtocol {
|
SubstreamProtocol {
|
||||||
upgrade,
|
upgrade,
|
||||||
info,
|
info,
|
||||||
upgrade_protocol: upgrade::Version::V1,
|
|
||||||
timeout: Duration::from_secs(10),
|
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.
|
/// Maps a function over the protocol upgrade.
|
||||||
pub fn map_upgrade<U, F>(self, f: F) -> SubstreamProtocol<U, TInfo>
|
pub fn map_upgrade<U, F>(self, f: F) -> SubstreamProtocol<U, TInfo>
|
||||||
where
|
where
|
||||||
@ -275,7 +266,6 @@ impl<TUpgrade, TInfo> SubstreamProtocol<TUpgrade, TInfo> {
|
|||||||
SubstreamProtocol {
|
SubstreamProtocol {
|
||||||
upgrade: f(self.upgrade),
|
upgrade: f(self.upgrade),
|
||||||
info: self.info,
|
info: self.info,
|
||||||
upgrade_protocol: self.upgrade_protocol,
|
|
||||||
timeout: self.timeout,
|
timeout: self.timeout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,7 +278,6 @@ impl<TUpgrade, TInfo> SubstreamProtocol<TUpgrade, TInfo> {
|
|||||||
SubstreamProtocol {
|
SubstreamProtocol {
|
||||||
upgrade: self.upgrade,
|
upgrade: self.upgrade,
|
||||||
info: f(self.info),
|
info: f(self.info),
|
||||||
upgrade_protocol: self.upgrade_protocol,
|
|
||||||
timeout: self.timeout,
|
timeout: self.timeout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -315,8 +304,8 @@ impl<TUpgrade, TInfo> SubstreamProtocol<TUpgrade, TInfo> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the substream protocol configuration into the contained upgrade.
|
/// Converts the substream protocol configuration into the contained upgrade.
|
||||||
pub fn into_upgrade(self) -> (upgrade::Version, TUpgrade, TInfo) {
|
pub fn into_upgrade(self) -> (TUpgrade, TInfo) {
|
||||||
(self.upgrade_protocol, self.upgrade, self.info)
|
(self.upgrade, self.info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,7 +501,7 @@ where T: ProtocolsHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn inbound_protocol(&self) -> <Self::Handler as ProtocolsHandler>::InboundProtocol {
|
fn inbound_protocol(&self) -> <Self::Handler as ProtocolsHandler>::InboundProtocol {
|
||||||
self.listen_protocol().into_upgrade().1
|
self.listen_protocol().into_upgrade().0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ use crate::upgrade::{
|
|||||||
};
|
};
|
||||||
use futures::{future::BoxFuture, prelude::*};
|
use futures::{future::BoxFuture, prelude::*};
|
||||||
use libp2p_core::{ConnectedPoint, Multiaddr, PeerId};
|
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 rand::Rng;
|
||||||
use std::{
|
use std::{
|
||||||
cmp,
|
cmp,
|
||||||
@ -76,15 +76,12 @@ where
|
|||||||
/// Create and populate a `MultiHandler` from the given handler iterator.
|
/// 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.
|
/// 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>
|
pub fn try_from_iter<I>(iter: I) -> Result<Self, DuplicateProtonameError>
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = (K, H)>
|
I: IntoIterator<Item = (K, H)>
|
||||||
{
|
{
|
||||||
let m = MultiHandler { handlers: HashMap::from_iter(iter) };
|
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)
|
Ok(m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,34 +102,22 @@ where
|
|||||||
type OutboundOpenInfo = (K, <H as ProtocolsHandler>::OutboundOpenInfo);
|
type OutboundOpenInfo = (K, <H as ProtocolsHandler>::OutboundOpenInfo);
|
||||||
|
|
||||||
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
|
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)| {
|
.map(|(key, handler)| {
|
||||||
let proto = handler.listen_protocol();
|
let proto = handler.listen_protocol();
|
||||||
let timeout = *proto.timeout();
|
let timeout = *proto.timeout();
|
||||||
let (version, upgrade, info) = proto.into_upgrade();
|
let (upgrade, info) = proto.into_upgrade();
|
||||||
(key.clone(), (version, upgrade, info, timeout))
|
(key.clone(), (upgrade, info, timeout))
|
||||||
})
|
})
|
||||||
.fold((Upgrade::new(), Info::new(), Duration::from_secs(0), None),
|
.fold((Upgrade::new(), Info::new(), Duration::from_secs(0)),
|
||||||
|(mut upg, mut inf, mut timeout, mut version), (k, (v, u, i, t))| {
|
|(mut upg, mut inf, mut timeout), (k, (u, i, t))| {
|
||||||
upg.upgrades.push((k.clone(), u));
|
upg.upgrades.push((k.clone(), u));
|
||||||
inf.infos.push((k, i));
|
inf.infos.push((k, i));
|
||||||
timeout = cmp::max(timeout, t);
|
timeout = cmp::max(timeout, t);
|
||||||
version = version.map_or(Some(v), |vv|
|
(upg, inf, timeout)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
SubstreamProtocol::new(upgrade, info)
|
SubstreamProtocol::new(upgrade, info).with_timeout(timeout)
|
||||||
.with_timeout(timeout)
|
|
||||||
.with_upgrade_protocol(version.unwrap_or(upgrade::Version::V1))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inject_fully_negotiated_outbound (
|
fn inject_fully_negotiated_outbound (
|
||||||
@ -315,9 +300,6 @@ where
|
|||||||
/// Create and populate an `IntoMultiHandler` from the given iterator.
|
/// Create and populate an `IntoMultiHandler` from the given iterator.
|
||||||
///
|
///
|
||||||
/// It is an error for any two protocols handlers to share the same protocol name.
|
/// 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>
|
pub fn try_from_iter<I>(iter: I) -> Result<Self, DuplicateProtonameError>
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = (K, H)>
|
I: IntoIterator<Item = (K, H)>
|
||||||
|
@ -116,7 +116,7 @@ where
|
|||||||
>>,
|
>>,
|
||||||
/// For each outbound substream request, how to upgrade it. The first element of the tuple
|
/// For each outbound substream request, how to upgrade it. The first element of the tuple
|
||||||
/// is the unique identifier (see `unique_dial_upgrade_id`).
|
/// 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 identifier assigned to each queued dial upgrade.
|
||||||
unique_dial_upgrade_id: u64,
|
unique_dial_upgrade_id: u64,
|
||||||
/// The currently planned connection & handler shutdown.
|
/// The currently planned connection & handler shutdown.
|
||||||
@ -246,7 +246,7 @@ where
|
|||||||
SubstreamEndpoint::Listener => {
|
SubstreamEndpoint::Listener => {
|
||||||
let protocol = self.handler.listen_protocol();
|
let protocol = self.handler.listen_protocol();
|
||||||
let timeout = *protocol.timeout();
|
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 upgrade = upgrade::apply_inbound(substream, SendWrapper(upgrade));
|
||||||
let timeout = Delay::new(timeout);
|
let timeout = Delay::new(timeout);
|
||||||
self.negotiating_in.push(SubstreamUpgrade {
|
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 let Some(v) = self.substream_upgrade_protocol_override {
|
||||||
if v != version {
|
if v != version {
|
||||||
log::debug!("Substream upgrade protocol override: {:?} -> {:?}", version, v);
|
log::debug!("Substream upgrade protocol override: {:?} -> {:?}", version, v);
|
||||||
@ -336,8 +337,8 @@ where
|
|||||||
let id = self.unique_dial_upgrade_id;
|
let id = self.unique_dial_upgrade_id;
|
||||||
let timeout = *protocol.timeout();
|
let timeout = *protocol.timeout();
|
||||||
self.unique_dial_upgrade_id += 1;
|
self.unique_dial_upgrade_id += 1;
|
||||||
let (version, upgrade, info) = protocol.into_upgrade();
|
let (upgrade, info) = protocol.into_upgrade();
|
||||||
self.queued_dial_upgrades.push((id, (version, SendWrapper(upgrade))));
|
self.queued_dial_upgrades.push((id, SendWrapper(upgrade)));
|
||||||
return Poll::Ready(Ok(
|
return Poll::Ready(Ok(
|
||||||
ConnectionHandlerEvent::OutboundSubstreamRequest((id, info, timeout)),
|
ConnectionHandlerEvent::OutboundSubstreamRequest((id, info, timeout)),
|
||||||
));
|
));
|
||||||
|
@ -111,8 +111,8 @@ where
|
|||||||
let proto1 = self.proto1.listen_protocol();
|
let proto1 = self.proto1.listen_protocol();
|
||||||
let proto2 = self.proto2.listen_protocol();
|
let proto2 = self.proto2.listen_protocol();
|
||||||
let timeout = *std::cmp::max(proto1.timeout(), proto2.timeout());
|
let timeout = *std::cmp::max(proto1.timeout(), proto2.timeout());
|
||||||
let (_, u1, i1) = proto1.into_upgrade();
|
let (u1, i1) = proto1.into_upgrade();
|
||||||
let (_, u2, i2) = proto2.into_upgrade();
|
let (u2, i2) = proto2.into_upgrade();
|
||||||
let choice = SelectUpgrade::new(SendWrapper(u1), SendWrapper(u2));
|
let choice = SelectUpgrade::new(SendWrapper(u1), SendWrapper(u2));
|
||||||
SubstreamProtocol::new(choice, (i1, i2)).with_timeout(timeout)
|
SubstreamProtocol::new(choice, (i1, i2)).with_timeout(timeout)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user