Add getPeers method

To know if relay messages would be published.
This commit is contained in:
Franck Royer 2021-05-13 16:42:18 +10:00
parent eb9955314c
commit a8d4d494f8
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 15 additions and 0 deletions

View File

@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added
- `WakuRelay.getPeers` method.
### Changed ### Changed
- Enable passing `string`s to `addPeerToAddressBook`. - Enable passing `string`s to `addPeerToAddressBook`.
- Use `addPeerToAddressBook` in examples and usage doc. - Use `addPeerToAddressBook` in examples and usage doc.

View File

@ -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<string> {
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. * Join pubsub topic.
* This is present to override the behavior of Gossipsub and should not * This is present to override the behavior of Gossipsub and should not