Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-pubsub
Commits
3ea67516
Commit
3ea67516
authored
Mar 31, 2021
by
nisdas
Committed by
vyzo
Mar 31, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add threshold validation
parent
5cd1316e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
10 deletions
+25
-10
score_params.go
score_params.go
+10
-10
score_params_test.go
score_params_test.go
+15
-0
No files found.
score_params.go
View file @
3ea67516
...
...
@@ -32,20 +32,20 @@ type PeerScoreThresholds struct {
}
func
(p *PeerScoreThresholds) validate()
error
{
if
p.GossipThreshold > 0 {
return
fmt.Errorf(
"invalid gossip threshold; it must be <= 0"
)
if
p.GossipThreshold > 0
|| isInvalidNumber(p.GossipThreshold)
{
return
fmt.Errorf(
"invalid gossip threshold; it must be <= 0
and a valid number
"
)
}
if
p.PublishThreshold > 0 || p.PublishThreshold > p.GossipThreshold {
return
fmt.Errorf(
"invalid publish threshold; it must be <= 0 and <= gossip threshold"
)
if
p.PublishThreshold > 0 || p.PublishThreshold > p.GossipThreshold
|| isInvalidNumber(p.PublishThreshold)
{
return
fmt.Errorf(
"invalid publish threshold; it must be <= 0 and <= gossip threshold
and a valid number
"
)
}
if
p.GraylistThreshold > 0 || p.GraylistThreshold > p.PublishThreshold {
return
fmt.Errorf(
"invalid graylist threshold; it must be <= 0 and <= publish threshold"
)
if
p.GraylistThreshold > 0 || p.GraylistThreshold > p.PublishThreshold
|| isInvalidNumber(p.GraylistThreshold)
{
return
fmt.Errorf(
"invalid graylist threshold; it must be <= 0 and <= publish threshold
and a valid number
"
)
}
if
p.AcceptPXThreshold < 0 {
return
fmt.Errorf(
"invalid accept PX threshold; it must be >= 0"
)
if
p.AcceptPXThreshold < 0
|| isInvalidNumber(p.AcceptPXThreshold)
{
return
fmt.Errorf(
"invalid accept PX threshold; it must be >= 0
and a valid number
"
)
}
if
p.OpportunisticGraftThreshold < 0 {
return
fmt.Errorf(
"invalid opportunistic grafting threshold; it must be >= 0"
)
if
p.OpportunisticGraftThreshold < 0
|| isInvalidNumber(p.OpportunisticGraftThreshold)
{
return
fmt.Errorf(
"invalid opportunistic grafting threshold; it must be >= 0
and a valid number
"
)
}
return
nil
}
...
...
score_params_test.go
View file @
3ea67516
...
...
@@ -30,6 +30,21 @@ func TestPeerScoreThresholdsValidation(t *testing.T) {
if
(&PeerScoreThresholds{GossipThreshold: -1, PublishThreshold: -2, GraylistThreshold: -3, AcceptPXThreshold: 1, OpportunisticGraftThreshold: 2}).validate() != nil {
t.Fatal(
"expected validation success"
)
}
if
(&PeerScoreThresholds{GossipThreshold: math.Inf(-1), PublishThreshold: -2, GraylistThreshold: -3, AcceptPXThreshold: 1, OpportunisticGraftThreshold: 2}).validate() == nil {
t.Fatal(
"expected validation error"
)
}
if
(&PeerScoreThresholds{GossipThreshold: -1, PublishThreshold: math.Inf(-1), GraylistThreshold: -3, AcceptPXThreshold: 1, OpportunisticGraftThreshold: 2}).validate() == nil {
t.Fatal(
"expected validation error"
)
}
if
(&PeerScoreThresholds{GossipThreshold: -1, PublishThreshold: -2, GraylistThreshold: math.Inf(-1), AcceptPXThreshold: 1, OpportunisticGraftThreshold: 2}).validate() == nil {
t.Fatal(
"expected validation error"
)
}
if
(&PeerScoreThresholds{GossipThreshold: -1, PublishThreshold: -2, GraylistThreshold: -3, AcceptPXThreshold: math.NaN(), OpportunisticGraftThreshold: 2}).validate() == nil {
t.Fatal(
"expected validation error"
)
}
if
(&PeerScoreThresholds{GossipThreshold: -1, PublishThreshold: -2, GraylistThreshold: -3, AcceptPXThreshold: 1, OpportunisticGraftThreshold: math.Inf(0)}).validate() == nil {
t.Fatal(
"expected validation error"
)
}
}
func
TestTopicScoreParamsValidation(t *testing.T) {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment