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
7644a650
Commit
7644a650
authored
Mar 31, 2021
by
nisdas
Committed by
vyzo
Mar 31, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add last amount of validation
parent
3ea67516
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
10 deletions
+24
-10
score_params.go
score_params.go
+10
-10
score_params_test.go
score_params_test.go
+14
-0
No files found.
score_params.go
View file @
7644a650
...
...
@@ -157,8 +157,8 @@ 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)"
)
if
p
.
TopicScoreCap
<
0
||
isInvalidNumber
(
p
.
TopicScoreCap
)
{
return
fmt
.
Errorf
(
"invalid topic score cap; must be positive (or 0 for no cap)
and a valid number
"
)
}
// check that we have an app specific score; the weight can be anything (but expected positive)
...
...
@@ -167,29 +167,29 @@ func (p *PeerScoreParams) validate() error {
}
// check the IP colocation factor
if
p
.
IPColocationFactorWeight
>
0
{
return
fmt
.
Errorf
(
"invalid IPColocationFactorWeight; must be negative (or 0 to disable)"
)
if
p
.
IPColocationFactorWeight
>
0
||
isInvalidNumber
(
p
.
IPColocationFactorWeight
)
{
return
fmt
.
Errorf
(
"invalid IPColocationFactorWeight; must be negative (or 0 to disable)
and a valid number
"
)
}
if
p
.
IPColocationFactorWeight
!=
0
&&
p
.
IPColocationFactorThreshold
<
1
{
return
fmt
.
Errorf
(
"invalid IPColocationFactorThreshold; must be at least 1"
)
}
// check the behaviour penalty
if
p
.
BehaviourPenaltyWeight
>
0
{
return
fmt
.
Errorf
(
"invalid BehaviourPenaltyWeight; must be negative (or 0 to disable)"
)
if
p
.
BehaviourPenaltyWeight
>
0
||
isInvalidNumber
(
p
.
BehaviourPenaltyWeight
)
{
return
fmt
.
Errorf
(
"invalid BehaviourPenaltyWeight; must be negative (or 0 to disable)
and a valid number
"
)
}
if
p
.
BehaviourPenaltyWeight
!=
0
&&
(
p
.
BehaviourPenaltyDecay
<=
0
||
p
.
BehaviourPenaltyDecay
>=
1
)
{
if
p
.
BehaviourPenaltyWeight
!=
0
&&
(
p
.
BehaviourPenaltyDecay
<=
0
||
p
.
BehaviourPenaltyDecay
>=
1
||
isInvalidNumber
(
p
.
BehaviourPenaltyDecay
)
)
{
return
fmt
.
Errorf
(
"invalid BehaviourPenaltyDecay; must be between 0 and 1"
)
}
if
p
.
BehaviourPenaltyThreshold
<
0
{
return
fmt
.
Errorf
(
"invalid BehaviourPenaltyThreshold; must be >= 0"
)
if
p
.
BehaviourPenaltyThreshold
<
0
||
isInvalidNumber
(
p
.
BehaviourPenaltyThreshold
)
{
return
fmt
.
Errorf
(
"invalid BehaviourPenaltyThreshold; must be >= 0
and a valid number
"
)
}
// check the decay parameters
if
p
.
DecayInterval
<
time
.
Second
{
return
fmt
.
Errorf
(
"invalid DecayInterval; must be at least 1s"
)
}
if
p
.
DecayToZero
<=
0
||
p
.
DecayToZero
>=
1
{
if
p
.
DecayToZero
<=
0
||
p
.
DecayToZero
>=
1
||
isInvalidNumber
(
p
.
DecayToZero
)
{
return
fmt
.
Errorf
(
"invalid DecayToZero; must be between 0 and 1"
)
}
...
...
score_params_test.go
View file @
7644a650
...
...
@@ -272,6 +272,20 @@ func TestPeerScoreParamsValidation(t *testing.T) {
// Checks the topic parameters for invalid values such as infinite and
// NaN numbers.
// Don't use these params in production!
if
(
&
PeerScoreParams
{
AppSpecificScore
:
appScore
,
DecayInterval
:
time
.
Second
,
DecayToZero
:
math
.
Inf
(
0
),
IPColocationFactorWeight
:
math
.
Inf
(
-
1
),
IPColocationFactorThreshold
:
1
,
BehaviourPenaltyWeight
:
math
.
Inf
(
0
),
BehaviourPenaltyDecay
:
math
.
NaN
(),
})
.
validate
()
==
nil
{
t
.
Fatal
(
"expected validation failure"
)
}
if
(
&
PeerScoreParams
{
TopicScoreCap
:
1
,
AppSpecificScore
:
appScore
,
...
...
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