From 31160964d32772f52dae5a60290023f90bca1120 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 26 Nov 2020 15:08:43 +0100 Subject: [PATCH 1/2] swarm: Add ExpandedSwarm::is_connected Commit 335e55e6 removed the `ConnectionInfo` trait in favor of `PeerId`s. Commit 1bd013c8 removed `ExpandedSwarm::connection_info` as it would only return the `PeerId` that the caller is already aware of. One could use `ExpandedSwarm::connection_info` not only to retrieve the `ConnectionInfo` for a given peer, but also to check whether the underlying `Network` has a connection to the peer. This commit exposes the `is_connected` method on `Network` via `ExpandedSwarm` to check whether the `Network` has an established connection to a given peer. --- swarm/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index af3ccb71bcb..7b00cfbd46a 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -463,6 +463,11 @@ where TBehaviour: NetworkBehaviour, me.banned_peers.remove(&peer_id); } + /// Checks whether the [`Network`] has an established connection to a peer. + pub fn is_connected(me: &Self, peer_id: &PeerId) -> bool { + me.network.is_connected(peer_id) + } + /// Returns the next event that happens in the `Swarm`. /// /// Includes events from the `NetworkBehaviour` but also events about the connections status. From 63fad5a4cdfff9e6e3f2ffef2fa2d09b9dc9e4aa Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 26 Nov 2020 18:40:17 +0100 Subject: [PATCH 2/2] swarm: Update Cargo.toml and CHANGELOG.md --- swarm/CHANGELOG.md | 5 +++++ swarm/Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 1a8d7d8261d..c0437d9eafc 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.25.1 [2020-11-26] + +- Add `ExpandedSwarm::is_connected`. + [PR 1862](https://github.com/libp2p/rust-libp2p/pull/1862). + # 0.25.0 [2020-11-25] - Permit a configuration override for the substream upgrade protocol diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index ca527aabe95..7c82ff67d67 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-swarm" edition = "2018" description = "The libp2p swarm" -version = "0.25.0" +version = "0.25.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p"