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
b7c28b50
Commit
b7c28b50
authored
Aug 20, 2020
by
vyzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add behaviour penalty threshold
parent
c5ece1d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
4 deletions
+11
-4
score.go
score.go
+5
-2
score_params.go
score_params.go
+6
-2
No files found.
score.go
View file @
b7c28b50
...
...
@@ -274,8 +274,11 @@ func (ps *peerScore) score(p peer.ID) float64 {
score
+=
p6
*
ps
.
params
.
IPColocationFactorWeight
// P7: behavioural pattern penalty
p7
:=
pstats
.
behaviourPenalty
*
pstats
.
behaviourPenalty
score
+=
p7
*
ps
.
params
.
BehaviourPenaltyWeight
if
pstats
.
behaviourPenalty
>
ps
.
params
.
BehaviourPenaltyThreshold
{
excess
:=
pstats
.
behaviourPenalty
-
ps
.
params
.
BehaviourPenaltyThreshold
p7
:=
excess
*
excess
score
+=
p7
*
ps
.
params
.
BehaviourPenaltyWeight
}
return
score
}
...
...
score_params.go
View file @
b7c28b50
...
...
@@ -79,9 +79,10 @@ type PeerScoreParams struct {
// - attempting to re-graft before the prune backoff time has elapsed.
// - not following up in IWANT requests for messages advertised with IHAVE.
//
// The value of the parameter is the square of the counter, which decays with BehaviourPenaltyDecay.
// The value of the parameter is the square of the counter over the threshold, which decays with
// BehaviourPenaltyDecay.
// The weight of the parameter MUST be negative (or zero to disable).
BehaviourPenaltyWeight
,
BehaviourPenaltyDecay
float64
BehaviourPenaltyWeight
,
BehaviourPenaltyThreshold
,
BehaviourPenaltyDecay
float64
// the decay interval for parameter counters.
DecayInterval
time
.
Duration
...
...
@@ -179,6 +180,9 @@ func (p *PeerScoreParams) validate() error {
if
p
.
BehaviourPenaltyWeight
!=
0
&&
(
p
.
BehaviourPenaltyDecay
<=
0
||
p
.
BehaviourPenaltyDecay
>=
1
)
{
return
fmt
.
Errorf
(
"invalid BehaviourPenaltyDecay; must be between 0 and 1"
)
}
if
p
.
BehaviourPenaltyThreshold
<
0
{
return
fmt
.
Errorf
(
"invalid BehaviourPenaltyThreshold; must be >= 0"
)
}
// check the decay parameters
if
p
.
DecayInterval
<
time
.
Second
{
...
...
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