diff --git a/gossip_tracer.go b/gossip_tracer.go index bafb8f4dc1a3276910a7be3c595972d1873acf5c..6db3fd10113713fcb10506e36f753d7b726b932e 100644 --- a/gossip_tracer.go +++ b/gossip_tracer.go @@ -133,9 +133,9 @@ func (gt *gossipTracer) RejectMessage(msg *Message, reason string) { // We do take exception and apply promise penalty regardless in the following cases, where // the peer delivered an obviously invalid message. switch reason { - case rejectMissingSignature: + case RejectMissingSignature: return - case rejectInvalidSignature: + case RejectInvalidSignature: return } diff --git a/peer_gater.go b/peer_gater.go index 9cc6c984d27e3c7d51b1493dbfcb36b2db37fa34..0a00dedc648365cda43731dbaa4053a16390f9ce 100644 --- a/peer_gater.go +++ b/peer_gater.go @@ -411,13 +411,13 @@ func (pg *peerGater) RejectMessage(msg *Message, reason string) { defer pg.Unlock() switch reason { - case rejectValidationQueueFull: + case RejectValidationQueueFull: fallthrough - case rejectValidationThrottled: + case RejectValidationThrottled: pg.lastThrottle = time.Now() pg.throttle++ - case rejectValidationIgnored: + case RejectValidationIgnored: st := pg.getPeerStats(msg.ReceivedFrom) st.ignore++ diff --git a/peer_gater_test.go b/peer_gater_test.go index bd0fbb639927e18ac205efd35b354340aa2966a0..9ab9d45918c4bdf9b3f0773ce80375228d1686aa 100644 --- a/peer_gater_test.go +++ b/peer_gater_test.go @@ -46,21 +46,21 @@ func TestPeerGater(t *testing.T) { t.Fatal("expected AcceptAll") } - pg.RejectMessage(msg, rejectValidationQueueFull) + pg.RejectMessage(msg, RejectValidationQueueFull) status = pg.AcceptFrom(peerA) if status != AcceptAll { t.Fatal("expected AcceptAll") } - pg.RejectMessage(msg, rejectValidationThrottled) + pg.RejectMessage(msg, RejectValidationThrottled) status = pg.AcceptFrom(peerA) if status != AcceptAll { t.Fatal("expected AcceptAll") } for i := 0; i < 100; i++ { - pg.RejectMessage(msg, rejectValidationIgnored) - pg.RejectMessage(msg, rejectValidationFailed) + pg.RejectMessage(msg, RejectValidationIgnored) + pg.RejectMessage(msg, RejectValidationFailed) } accepted := false diff --git a/pubsub.go b/pubsub.go index fffff93feadf2f6e154cb5c1bd9e37378c23c4df..7ec045a896e7aebf6201a3f8a8ce99df3f4205e4 100644 --- a/pubsub.go +++ b/pubsub.go @@ -987,14 +987,14 @@ func (p *PubSub) pushMsg(msg *Message) { // reject messages from blacklisted peers if p.blacklist.Contains(src) { log.Debugf("dropping message from blacklisted peer %s", src) - p.tracer.RejectMessage(msg, rejectBlacklstedPeer) + p.tracer.RejectMessage(msg, RejectBlacklstedPeer) return } // even if they are forwarded by good peers if p.blacklist.Contains(msg.GetFrom()) { log.Debugf("dropping message from blacklisted source %s", src) - p.tracer.RejectMessage(msg, rejectBlacklistedSource) + p.tracer.RejectMessage(msg, RejectBlacklistedSource) return } @@ -1003,7 +1003,7 @@ func (p *PubSub) pushMsg(msg *Message) { if p.signPolicy.mustSign() { if msg.Signature == nil { log.Debugf("dropping unsigned message from %s", src) - p.tracer.RejectMessage(msg, rejectMissingSignature) + p.tracer.RejectMessage(msg, RejectMissingSignature) return } // Actual signature verification happens in the validation pipeline, @@ -1012,7 +1012,7 @@ func (p *PubSub) pushMsg(msg *Message) { } else { if msg.Signature != nil { log.Debugf("dropping message with unexpected signature from %s", src) - p.tracer.RejectMessage(msg, rejectUnexpectedSignature) + p.tracer.RejectMessage(msg, RejectUnexpectedSignature) return } // If we are expecting signed messages, and not authoring messages, @@ -1022,7 +1022,7 @@ func (p *PubSub) pushMsg(msg *Message) { if p.signID == "" { if msg.Seqno != nil || msg.From != nil || msg.Key != nil { log.Debugf("dropping message with unexpected auth info from %s", src) - p.tracer.RejectMessage(msg, rejectUnexpectedAuthInfo) + p.tracer.RejectMessage(msg, RejectUnexpectedAuthInfo) return } } @@ -1033,7 +1033,7 @@ func (p *PubSub) pushMsg(msg *Message) { self := p.host.ID() if peer.ID(msg.GetFrom()) == self && src != self { log.Debugf("dropping message claiming to be from self but forwarded from %s", src) - p.tracer.RejectMessage(msg, rejectSelfOrigin) + p.tracer.RejectMessage(msg, RejectSelfOrigin) return } diff --git a/score.go b/score.go index 75f9e27f83b0384f42fcc713d01e976bd999b784..e02339b602acbd1cc2194c269b2e4b6730a00a48 100644 --- a/score.go +++ b/score.go @@ -722,25 +722,25 @@ func (ps *peerScore) RejectMessage(msg *Message, reason string) { switch reason { // we don't track those messages, but we penalize the peer as they are clearly invalid - case rejectMissingSignature: + case RejectMissingSignature: fallthrough - case rejectInvalidSignature: + case RejectInvalidSignature: fallthrough - case rejectUnexpectedSignature: + case RejectUnexpectedSignature: fallthrough - case rejectUnexpectedAuthInfo: + case RejectUnexpectedAuthInfo: fallthrough - case rejectSelfOrigin: + case RejectSelfOrigin: ps.markInvalidMessageDelivery(msg.ReceivedFrom, msg) return // we ignore those messages, so do nothing. - case rejectBlacklstedPeer: + case RejectBlacklstedPeer: fallthrough - case rejectBlacklistedSource: + case RejectBlacklistedSource: return - case rejectValidationQueueFull: + 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. @@ -756,14 +756,14 @@ func (ps *peerScore) RejectMessage(msg *Message, reason string) { } switch reason { - case rejectValidationThrottled: + case 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 = deliveryThrottled // release the delivery time tracking map to free some memory early drec.peers = nil return - case rejectValidationIgnored: + case RejectValidationIgnored: // we were explicitly instructed by the validator to ignore the message but not penalize // the peer drec.status = deliveryIgnored diff --git a/score_test.go b/score_test.go index 76d95bfde31e78e833c02231f9622cfa3e73a9df..849f8be55577369b31eefe0e6b94063bb8800ff4 100644 --- a/score_test.go +++ b/score_test.go @@ -475,7 +475,7 @@ func TestScoreInvalidMessageDeliveries(t *testing.T) { pbMsg := makeTestMessage(i) pbMsg.Topic = &mytopic msg := Message{ReceivedFrom: peerA, Message: pbMsg} - ps.RejectMessage(&msg, rejectInvalidSignature) + ps.RejectMessage(&msg, RejectInvalidSignature) } ps.refreshScores() @@ -512,7 +512,7 @@ func TestScoreInvalidMessageDeliveriesDecay(t *testing.T) { pbMsg := makeTestMessage(i) pbMsg.Topic = &mytopic msg := Message{ReceivedFrom: peerA, Message: pbMsg} - ps.RejectMessage(&msg, rejectInvalidSignature) + ps.RejectMessage(&msg, RejectInvalidSignature) } ps.refreshScores() @@ -561,9 +561,9 @@ func TestScoreRejectMessageDeliveries(t *testing.T) { msg2 := Message{ReceivedFrom: peerB, Message: pbMsg} // these should have no effect in the score - ps.RejectMessage(&msg, rejectBlacklstedPeer) - ps.RejectMessage(&msg, rejectBlacklistedSource) - ps.RejectMessage(&msg, rejectValidationQueueFull) + ps.RejectMessage(&msg, RejectBlacklstedPeer) + ps.RejectMessage(&msg, RejectBlacklistedSource) + ps.RejectMessage(&msg, RejectValidationQueueFull) aScore := ps.Score(peerA) expected := 0.0 @@ -576,7 +576,7 @@ func TestScoreRejectMessageDeliveries(t *testing.T) { // this should have no effect in the score, and subsequent duplicate messages should have no // effect either - ps.RejectMessage(&msg, rejectValidationThrottled) + ps.RejectMessage(&msg, RejectValidationThrottled) ps.DuplicateMessage(&msg2) aScore = ps.Score(peerA) @@ -601,7 +601,7 @@ func TestScoreRejectMessageDeliveries(t *testing.T) { // this should have no effect in the score, and subsequent duplicate messages should have no // effect either - ps.RejectMessage(&msg, rejectValidationIgnored) + ps.RejectMessage(&msg, RejectValidationIgnored) ps.DuplicateMessage(&msg2) aScore = ps.Score(peerA) @@ -625,7 +625,7 @@ func TestScoreRejectMessageDeliveries(t *testing.T) { ps.ValidateMessage(&msg) // and reject the message to make sure duplicates are also penalized - ps.RejectMessage(&msg, rejectValidationFailed) + ps.RejectMessage(&msg, RejectValidationFailed) ps.DuplicateMessage(&msg2) aScore = ps.Score(peerA) @@ -650,7 +650,7 @@ func TestScoreRejectMessageDeliveries(t *testing.T) { // and reject the message after a duplciate has arrived ps.DuplicateMessage(&msg2) - ps.RejectMessage(&msg, rejectValidationFailed) + ps.RejectMessage(&msg, RejectValidationFailed) aScore = ps.Score(peerA) expected = -4.0 @@ -1032,7 +1032,7 @@ func TestScoreResetTopicParams(t *testing.T) { pbMsg.Topic = &mytopic msg := Message{ReceivedFrom: peerA, Message: pbMsg} ps.ValidateMessage(&msg) - ps.RejectMessage(&msg, rejectValidationFailed) + ps.RejectMessage(&msg, RejectValidationFailed) } // check the topic score diff --git a/tag_tracer.go b/tag_tracer.go index a04472b5107b1d6ff4af2bf36f352f8a84a7a062..bd6d5e20d0a914b0ef92ab584003a7ab33b2ba04 100644 --- a/tag_tracer.go +++ b/tag_tracer.go @@ -242,11 +242,11 @@ func (t *tagTracer) RejectMessage(msg *Message, reason string) { // the validation pipeline. Other rejection reasons (missing signature, etc) skip the validation // queue, so we don't want to remove the state in case the message is still validating. switch reason { - case rejectValidationThrottled: + case RejectValidationThrottled: fallthrough - case rejectValidationIgnored: + case RejectValidationIgnored: fallthrough - case rejectValidationFailed: + case RejectValidationFailed: delete(t.nearFirst, t.msgID(msg.Message)) } } diff --git a/tracer.go b/tracer.go index eca3f1783f839da2ffaf941cfded047e899012ca..0f0b090fa4090be53eb615d3cb7ac5165d70c47f 100644 --- a/tracer.go +++ b/tracer.go @@ -25,17 +25,17 @@ var MinTraceBatchSize = 16 // rejection reasons const ( - rejectBlacklstedPeer = "blacklisted peer" - rejectBlacklistedSource = "blacklisted source" - rejectMissingSignature = "missing signature" - rejectUnexpectedSignature = "unexpected signature" - rejectUnexpectedAuthInfo = "unexpected auth info" - rejectInvalidSignature = "invalid signature" - rejectValidationQueueFull = "validation queue full" - rejectValidationThrottled = "validation throttled" - rejectValidationFailed = "validation failed" - rejectValidationIgnored = "validation ignored" - rejectSelfOrigin = "self originated message" + RejectBlacklstedPeer = "blacklisted peer" + RejectBlacklistedSource = "blacklisted source" + RejectMissingSignature = "missing signature" + RejectUnexpectedSignature = "unexpected signature" + RejectUnexpectedAuthInfo = "unexpected auth info" + RejectInvalidSignature = "invalid signature" + RejectValidationQueueFull = "validation queue full" + RejectValidationThrottled = "validation throttled" + RejectValidationFailed = "validation failed" + RejectValidationIgnored = "validation ignored" + RejectSelfOrigin = "self originated message" ) type basicTracer struct { diff --git a/validation.go b/validation.go index 7b69ee34d4a161b64a822fbd60a0e70dfe306cf0..328b53a0241b5fd124a3c89dc384c5e82c60ca09 100644 --- a/validation.go +++ b/validation.go @@ -201,7 +201,7 @@ func (v *validation) Push(src peer.ID, msg *Message) bool { case v.validateQ <- &validateReq{vals, src, msg}: default: log.Debugf("message validation throttled: queue full; dropping message from %s", src) - v.tracer.RejectMessage(msg, rejectValidationQueueFull) + v.tracer.RejectMessage(msg, RejectValidationQueueFull) } return false } @@ -242,7 +242,7 @@ func (v *validation) validate(vals []*topicVal, src peer.ID, msg *Message) { if msg.Signature != nil { if !v.validateSignature(msg) { log.Debugf("message signature validation failed; dropping message from %s", src) - v.tracer.RejectMessage(msg, rejectInvalidSignature) + v.tracer.RejectMessage(msg, RejectInvalidSignature) return } } @@ -282,7 +282,7 @@ loop: if result == ValidationReject { log.Debugf("message validation failed; dropping message from %s", src) - v.tracer.RejectMessage(msg, rejectValidationFailed) + v.tracer.RejectMessage(msg, RejectValidationFailed) return } @@ -296,13 +296,13 @@ loop: }() default: log.Debugf("message validation throttled; dropping message from %s", src) - v.tracer.RejectMessage(msg, rejectValidationThrottled) + v.tracer.RejectMessage(msg, RejectValidationThrottled) } return } if result == ValidationIgnore { - v.tracer.RejectMessage(msg, rejectValidationIgnored) + v.tracer.RejectMessage(msg, RejectValidationIgnored) return } @@ -332,15 +332,15 @@ func (v *validation) doValidateTopic(vals []*topicVal, src peer.ID, msg *Message v.p.sendMsg <- msg case ValidationReject: log.Debugf("message validation failed; dropping message from %s", src) - v.tracer.RejectMessage(msg, rejectValidationFailed) + v.tracer.RejectMessage(msg, RejectValidationFailed) return case ValidationIgnore: log.Debugf("message validation punted; ignoring message from %s", src) - v.tracer.RejectMessage(msg, rejectValidationIgnored) + v.tracer.RejectMessage(msg, RejectValidationIgnored) return case validationThrottled: log.Debugf("message validation throttled; ignoring message from %s", src) - v.tracer.RejectMessage(msg, rejectValidationThrottled) + v.tracer.RejectMessage(msg, RejectValidationThrottled) default: // BUG: this would be an internal programming error, so a panic seems appropiate.