From 7a3848073e8be642451415a2bbdc094cd3ad3fb0 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 27 Mar 2020 17:54:59 +0200 Subject: [PATCH] only retain negative scores --- score.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/score.go b/score.go index fd6405e..ab996a0 100644 --- a/score.go +++ b/score.go @@ -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) }