track message delivery time within the validation pipeline

This commit is contained in:
vyzo 2020-03-08 21:43:28 +02:00
parent 3610b05538
commit e17e266aa9
3 changed files with 34 additions and 2 deletions

View File

@ -378,13 +378,32 @@ func (ps *peerScore) DeliverMessage(msg *Message) {
}
}
func (ps *peerScore) ValidateMessage(msg *Message) {
ps.Lock()
defer ps.Unlock()
// the pubsub subsystem is beginning validation; create a record to track time in
// the validation pipeline with an accurate firstSeen time.
_ = ps.deliveries.getRecord(ps.msgID(msg.Message))
}
func (ps *peerScore) RejectMessage(msg *Message, reason string) {
ps.Lock()
defer ps.Unlock()
if reason == "invalid signature" {
// 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":
fallthrough
case "invalid signature":
ps.markInvalidMessageDelivery(msg.ReceivedFrom, msg)
// if we reject with "invalid signature" we don't track this message delivery.
return
// we ignore those messages, so do nothing.
case "blacklisted peer":
fallthrough
case "blacklisted source":
return
}

View File

@ -22,6 +22,7 @@ type scoreTracer interface {
Leave(topic string)
Graft(p peer.ID, topic string)
Prune(p peer.ID, topic string)
ValidateMessage(msg *Message)
DeliverMessage(msg *Message)
RejectMessage(msg *Message, reason string)
DuplicateMessage(msg *Message)
@ -58,6 +59,16 @@ func (t *pubsubTracer) PublishMessage(msg *Message) {
t.tracer.Trace(evt)
}
func (t *pubsubTracer) ValidateMessage(msg *Message) {
if t == nil {
return
}
if t.score != nil && msg.ReceivedFrom != t.pid {
t.score.ValidateMessage(msg)
}
}
func (t *pubsubTracer) RejectMessage(msg *Message, reason string) {
if t == nil {
return

View File

@ -206,6 +206,8 @@ func (v *validation) validate(vals []*topicVal, src peer.ID, msg *Message) {
if !v.p.markSeen(id) {
v.tracer.DuplicateMessage(msg)
return
} else {
v.tracer.ValidateMessage(msg)
}
var inline, async []*topicVal