From 939e296266e26b2c5349654acc1f363e2a458bba Mon Sep 17 00:00:00 2001 From: David Craven Date: Mon, 13 Dec 2021 17:17:12 +0100 Subject: [PATCH] swarm: Expose currently connected peers (#2378) Co-authored-by: Max Inden --- swarm/CHANGELOG.md | 3 +++ swarm/src/lib.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 867d07a6a33..49f42931d79 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -10,6 +10,8 @@ - Move `swarm::Toggle` to `swarm::behaviour::Toggle` (see [PR 2375]). +- Add `Swarm::connected_peers` (see [PR 2378]). + - Implement `swarm::NetworkBehaviour` on `either::Either` (see [PR 2370]). [PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339 @@ -17,6 +19,7 @@ [PR 2362]: https://github.com/libp2p/rust-libp2p/pull/2362 [PR 2370]: https://github.com/libp2p/rust-libp2p/pull/2370 [PR 2375]: https://github.com/libp2p/rust-libp2p/pull/2375 +[PR 2378]: https://github.com/libp2p/rust-libp2p/pull/2378 # 0.32.0 [2021-11-16] diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 25539294d8a..1c4798f06ea 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -584,6 +584,11 @@ where self.network.is_connected(peer_id) } + /// Returns the currently connected peers. + pub fn connected_peers(&self) -> impl Iterator { + self.network.connected_peers() + } + /// Returns a reference to the provided [`NetworkBehaviour`]. pub fn behaviour(&self) -> &TBehaviour { &self.behaviour