From 7d862e2ee62a76058d7f43e0c63d57ac963864f4 Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 9 Mar 2020 11:16:50 +0200 Subject: [PATCH] double check delivery to aboid duplicate counts --- score.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/score.go b/score.go index 0e7f696..59ab3d8 100644 --- a/score.go +++ b/score.go @@ -63,9 +63,9 @@ type TopicScoreParams struct { // when validation succeeds. // This window accounts for the minimum time before a hostile mesh peer trying to game the score // could replay back a valid message we just sent them. - // It effectively tracks near-first deliveries, ie a message seen from a mesh peer before we - // have forwarded it to them. - // The parameter has an associated counter, decaying with MessageMessageDeliveriesDecay. + // It effectively tracks first and near-first deliveries, ie a message seen from a mesh peer + // before we have forwarded it to them. + // The parameter has an associated counter, decaying with MeshMessageDeliveriesDecay. // If the counter exceeds the threshold, its value is 0. // If the counter is below the MeshMessageDeliveriesThreshold, the value is the square of // the deficit, ie (MessageDeliveriesThreshold - counter)^2 @@ -414,7 +414,11 @@ func (ps *peerScore) DeliverMessage(msg *Message) { drec.status = delivery_valid drec.validated = time.Now() for p := range drec.peers { - ps.markDuplicateMessageDelivery(p, msg, time.Time{}) + // this check is to make sure a peer can't send us a message twice and get a double count + // if it is a first delivery. + if p != msg.ReceivedFrom { + ps.markDuplicateMessageDelivery(p, msg, time.Time{}) + } } } @@ -487,7 +491,7 @@ func (ps *peerScore) DuplicateMessage(msg *Message) { ps.markInvalidMessageDelivery(msg.ReceivedFrom, msg) case delivery_throttled: - // the message ws throttled; do nothing (we don't know if it was valid) + // the message was throttled; do nothing (we don't know if it was valid) } }