diff --git a/CHANGELOG.md b/CHANGELOG.md index ea1b4986f4..6593a46674 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- `WakuRelay.getPeers` method. + ### Changed - Enable passing `string`s to `addPeerToAddressBook`. - Use `addPeerToAddressBook` in examples and usage doc. diff --git a/src/lib/waku_relay/index.ts b/src/lib/waku_relay/index.ts index 8ce2430e92..951d77648c 100644 --- a/src/lib/waku_relay/index.ts +++ b/src/lib/waku_relay/index.ts @@ -152,6 +152,18 @@ export class WakuRelay extends Gossipsub implements Pubsub { } } + /** + * Return the relay peers we are connected to and we would publish a message to + */ + getPeers(): Set { + return getRelayPeers(this, DefaultPubsubTopic, this._options.D, (id) => { + // Filter peers we would not publish to + return ( + this.score.score(id) >= this._options.scoreThresholds.publishThreshold + ); + }); + } + /** * Join pubsub topic. * This is present to override the behavior of Gossipsub and should not