topic score cap

This commit is contained in:
vyzo 2020-03-27 16:46:41 +02:00
parent 65cff1b421
commit c65a520799
2 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -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")