Commit 05c505ef authored by vyzo's avatar vyzo

export rejection named string constants

parent 6c1addf4
......@@ -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
}
......
......@@ -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++
......
......@@ -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
......
......@@ -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
}
......
......@@ -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
......
......@@ -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
......
......@@ -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))
}
}
......
......@@ -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 {
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment