swarm: Add ExpandedSwarm::is_connected (#1862)

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.
This commit is contained in:
Max Inden 2020-11-26 21:01:38 +01:00 committed by GitHub
parent d3ce35291b
commit dae07b075b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View File

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

View File

@ -2,7 +2,7 @@
name = "libp2p-swarm"
edition = "2018"
description = "The libp2p swarm"
version = "0.25.0"
version = "0.25.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -463,6 +463,11 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
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.