mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-05 06:13:10 +00:00
topic score cap
This commit is contained in:
parent
65cff1b421
commit
c65a520799
5
score.go
5
score.go
@ -216,6 +216,11 @@ func (ps *peerScore) score(p peer.ID) float64 {
|
||||
score += topicScore * topicParams.TopicWeight
|
||||
}
|
||||
|
||||
// apply the topic score cap, if any
|
||||
if ps.params.TopicScoreCap > 0 && score > ps.params.TopicScoreCap {
|
||||
score = ps.params.TopicScoreCap
|
||||
}
|
||||
|
||||
// P5: application-specific score
|
||||
p5 := ps.params.AppSpecificScore(p)
|
||||
score += p5 * ps.params.AppSpecificWeight
|
||||
|
||||
@ -45,6 +45,10 @@ type PeerScoreParams struct {
|
||||
// Score parameters per topic.
|
||||
Topics map[string]*TopicScoreParams
|
||||
|
||||
// Aggregate topic score cap; this limits the total contribution of topics towards a positive
|
||||
// score. It must be positive (or 0 for no cap).
|
||||
TopicScoreCap float64
|
||||
|
||||
// P5: Application-specific peer scoring
|
||||
AppSpecificScore func(p peer.ID) float64
|
||||
AppSpecificWeight float64
|
||||
@ -130,6 +134,11 @@ func (p *PeerScoreParams) validate() error {
|
||||
}
|
||||
}
|
||||
|
||||
// check that the topic score is 0 or something positive
|
||||
if p.TopicScoreCap < 0 {
|
||||
return fmt.Errorf("invalid topic score cap; must be positive (or 0 for no cap)")
|
||||
}
|
||||
|
||||
// check that we have an app specific score; the weight can be anything (but expected positive)
|
||||
if p.AppSpecificScore == nil {
|
||||
return fmt.Errorf("missing application specific score function")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user