feat(gossipsub): add getter function to obtain TopicScoreParams

Added a getter function to obtain `TopicScoreParams`. I need this function for testing which checks if scoring parameters are updated as expected.

Pull-Request: #4231.
This commit is contained in:
Akihito Nakano
2023-08-04 00:19:25 +09:00
committed by GitHub
parent 4b9c1e5e48
commit f95f39f634
6 changed files with 21 additions and 4 deletions

View File

@ -1,4 +1,11 @@
## 0.45.0
## 0.45.1 - unreleased
- Add getter function to obtain `TopicScoreParams`.
See [PR 4231].
[PR 4231]: https://github.com/libp2p/rust-libp2p/pull/4231
## 0.45.0
- Raise MSRV to 1.65.
See [PR 3715].

View File

@ -3,7 +3,7 @@ name = "libp2p-gossipsub"
edition = "2021"
rust-version = { workspace = true }
description = "Gossipsub protocol for libp2p"
version = "0.45.0"
version = "0.45.1"
authors = ["Age Manning <Age@AgeManning.com>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -930,6 +930,11 @@ where
}
}
/// Returns a scoring parameters for a topic if existent.
pub fn get_topic_params<H: Hasher>(&self, topic: &Topic<H>) -> Option<&TopicScoreParams> {
self.peer_score.as_ref()?.0.get_topic_params(&topic.hash())
}
/// Sets the application specific score for a peer. Returns true if scoring is active and
/// the peer is connected or if the score of the peer is not yet expired, false otherwise.
pub fn set_application_score(&mut self, peer_id: &PeerId, new_score: f64) -> bool {

View File

@ -780,6 +780,11 @@ impl PeerScore {
}
}
/// Returns a scoring parameters for a topic if existent.
pub(crate) fn get_topic_params(&self, topic_hash: &TopicHash) -> Option<&TopicScoreParams> {
self.params.topics.get(topic_hash)
}
/// Increments the "invalid message deliveries" counter for all scored topics the message
/// is published in.
fn mark_invalid_message_delivery(&mut self, peer_id: &PeerId, topic_hash: &TopicHash) {