use named constants for tracing message rejection reasons

This commit is contained in:
vyzo 2020-03-27 20:31:31 +02:00
parent ea7305245d
commit 1c4f0920fe
4 changed files with 27 additions and 17 deletions

View File

@ -814,21 +814,21 @@ func (p *PubSub) pushMsg(msg *Message) {
// reject messages from blacklisted peers
if p.blacklist.Contains(src) {
log.Warningf("dropping message from blacklisted peer %s", src)
p.tracer.RejectMessage(msg, "blacklisted peer")
p.tracer.RejectMessage(msg, rejectBlacklstedPeer)
return
}
// even if they are forwarded by good peers
if p.blacklist.Contains(msg.GetFrom()) {
log.Warningf("dropping message from blacklisted source %s", src)
p.tracer.RejectMessage(msg, "blacklisted source")
p.tracer.RejectMessage(msg, rejectBlacklistedSource)
return
}
// reject unsigned messages when strict before we even process the id
if p.signStrict && msg.Signature == nil {
log.Debugf("dropping unsigned message from %s", src)
p.tracer.RejectMessage(msg, "missing signature")
p.tracer.RejectMessage(msg, rejectMissingSignature)
return
}

View File

@ -505,22 +505,21 @@ func (ps *peerScore) RejectMessage(msg *Message, reason string) {
ps.Lock()
defer ps.Unlock()
// TODO: the reasons should become named strings; good enough for now.
switch reason {
// we don't track those messages, but we penalize the peer as they are clearly invalid
case "missing signature":
case rejectMissingSignature:
fallthrough
case "invalid signature":
case rejectInvalidSignature:
ps.markInvalidMessageDelivery(msg.ReceivedFrom, msg)
return
// we ignore those messages, so do nothing.
case "blacklisted peer":
case rejectBlacklstedPeer:
fallthrough
case "blacklisted source":
case rejectBlacklistedSource:
return
case "validation queue full":
case rejectValidationQueueFull:
// the message was rejected before it entered the validation pipeline;
// we don't know if this message has a valid signature, and thus we also don't know if
// it has a valid message ID; all we can do is ignore it.
@ -529,7 +528,7 @@ func (ps *peerScore) RejectMessage(msg *Message, reason string) {
drec := ps.deliveries.getRecord(ps.msgID(msg.Message))
if reason == "validation throttled" {
if reason == rejectValidationThrottled {
// if we reject with "validation throttled" we don't penalize the peer(s) that forward it
// because we don't know if it was valid.
drec.status = delivery_throttled

View File

@ -24,6 +24,17 @@ import (
var TraceBufferSize = 1 << 16 // 64K ought to be enough for everyone; famous last words.
var MinTraceBatchSize = 16
// rejection reasons
const (
rejectBlacklstedPeer = "blacklisted peer"
rejectBlacklistedSource = "blacklisted source"
rejectMissingSignature = "missing signature"
rejectInvalidSignature = "invalid signature"
rejectValidationQueueFull = "validation queue full"
rejectValidationThrottled = "validation throttled"
rejectValidationFailed = "validation failed"
)
type basicTracer struct {
ch chan struct{}
mx sync.Mutex

View File

@ -152,7 +152,7 @@ func (v *validation) Push(src peer.ID, msg *Message) bool {
case v.validateQ <- &validateReq{vals, src, msg}:
default:
log.Warningf("message validation throttled: queue full; dropping message from %s", src)
v.tracer.RejectMessage(msg, "validation queue full")
v.tracer.RejectMessage(msg, rejectValidationQueueFull)
}
return false
}
@ -195,7 +195,7 @@ func (v *validation) validate(vals []*topicVal, src peer.ID, msg *Message) {
if msg.Signature != nil {
if !v.validateSignature(msg) {
log.Warningf("message signature validation failed; dropping message from %s", src)
v.tracer.RejectMessage(msg, "invalid signature")
v.tracer.RejectMessage(msg, rejectInvalidSignature)
return
}
}
@ -223,7 +223,7 @@ func (v *validation) validate(vals []*topicVal, src peer.ID, msg *Message) {
for _, val := range inline {
if !val.validateMsg(v.p.ctx, src, msg) {
log.Debugf("message validation failed; dropping message from %s", src)
v.tracer.RejectMessage(msg, "validation failed")
v.tracer.RejectMessage(msg, rejectValidationFailed)
return
}
}
@ -238,7 +238,7 @@ func (v *validation) validate(vals []*topicVal, src peer.ID, msg *Message) {
}()
default:
log.Warningf("message validation throttled; dropping message from %s", src)
v.tracer.RejectMessage(msg, "validation throttled")
v.tracer.RejectMessage(msg, rejectValidationThrottled)
}
return
}
@ -260,7 +260,7 @@ func (v *validation) validateSignature(msg *Message) bool {
func (v *validation) doValidateTopic(vals []*topicVal, src peer.ID, msg *Message) {
if !v.validateTopic(vals, src, msg) {
log.Warningf("message validation failed; dropping message from %s", src)
v.tracer.RejectMessage(msg, "validation failed")
v.tracer.RejectMessage(msg, rejectValidationFailed)
return
}
@ -298,7 +298,7 @@ loop:
}
if throttle {
v.tracer.RejectMessage(msg, "validation throttled")
v.tracer.RejectMessage(msg, rejectValidationThrottled)
return false
}
@ -323,7 +323,7 @@ func (v *validation) validateSingleTopic(val *topicVal, src peer.ID, msg *Messag
default:
log.Debugf("validation throttled for topic %s", val.topic)
v.tracer.RejectMessage(msg, "validation throttled")
v.tracer.RejectMessage(msg, rejectValidationThrottled)
return false
}
}