mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-08 15:53:07 +00:00
validate that TimeInMeshQuantum is non-zero
otherwise we get a division by zero
This commit is contained in:
parent
11ef2a9cf2
commit
61a13a3ed7
@ -179,6 +179,9 @@ func (p *TopicScoreParams) validate() error {
|
||||
}
|
||||
|
||||
// check P1
|
||||
if p.TimeInMeshQuantum == 0 {
|
||||
return fmt.Errorf("invalid TimeInMeshQuantum; must be non zero")
|
||||
}
|
||||
if p.TimeInMeshWeight < 0 {
|
||||
return fmt.Errorf("invalid TimeInMeshWeight; must be positive (or 0 to disable)")
|
||||
}
|
||||
|
||||
@ -32,6 +32,10 @@ func TestPeerScoreThresholdsValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTopicScoreParamsValidation(t *testing.T) {
|
||||
if (&TopicScoreParams{}).validate() == nil {
|
||||
t.Fatal("expected validation error")
|
||||
}
|
||||
|
||||
if (&TopicScoreParams{TopicWeight: -1}).validate() == nil {
|
||||
t.Fatal("expected validation error")
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user