Skip to content

Commit

Permalink
swarm: Add ExpandedSwarm::is_connected (#1862)
Browse files Browse the repository at this point in the history
Commit 335e55e removed the `ConnectionInfo` trait in favor of
`PeerId`s. Commit 1bd013c 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.
  • Loading branch information
mxinden authored Nov 26, 2020
1 parent d3ce352 commit dae07b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
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.25.0"
version = "0.25.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
5 changes: 5 additions & 0 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit dae07b0

Please sign in to comment.