only retain negative scores

This commit is contained in:
vyzo 2020-03-27 17:54:59 +02:00
parent c65a520799
commit 7a3848073e
1 changed files with 22 additions and 0 deletions

View File

@ -393,6 +393,28 @@ func (ps *peerScore) RemovePeer(p peer.ID) {
return
}
// decide whether to retain the score; this currently only retains non-positive scores
// to dissuade attacks on the score function.
if ps.score(p) > 0 {
ps.removeIPs(p, pstats.ips)
delete(ps.peerStats, p)
return
}
// furthermore, when we decide to retain the score, the firstMessageDelivery counters are
// reset to 0 and mesh delivery penalties applied.
for topic, tstats := range pstats.topics {
tstats.firstMessageDeliveries = 0
threshold := ps.params.Topics[topic].MeshMessageDeliveriesThreshold
if tstats.inMesh && tstats.meshMessageDeliveriesActive && tstats.meshMessageDeliveries < threshold {
deficit := threshold - tstats.meshMessageDeliveries
tstats.meshFailurePenalty += deficit * deficit
}
tstats.inMesh = false
}
pstats.connected = false
pstats.expire = time.Now().Add(ps.params.RetainScore)
}