fix validation according to specification (#410)

This commit is contained in:
Giovanni Petrantoni 2020-10-21 12:25:42 +09:00 committed by GitHub
parent 5c19668b2d
commit 27b9bf436e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -85,9 +85,13 @@ method rpcHandler*(f: FloodSub,
# g.anonymize needs no evaluation when receiving messages
# as we have a "lax" policy and allow signed messages
if (await f.validate(msg)) == ValidationResult.Reject:
trace "Dropping message due to failed validation", msgId, peer
let validation = await f.validate(msg)
case validation
of ValidationResult.Reject, ValidationResult.Ignore:
debug "Dropping message due to ignored validation", msgId, peer
continue
of ValidationResult.Accept:
discard
var toSendPeers = initHashSet[PubSubPeer]()
for t in msg.topicIDs: # for every topic in the message

View File

@ -1062,10 +1062,17 @@ method rpcHandler*(g: GossipSub,
# g.anonymize needs no evaluation when receiving messages
# as we have a "lax" policy and allow signed messages
if (await g.validate(msg)) == ValidationResult.Reject:
let validation = await g.validate(msg)
case validation
of ValidationResult.Reject:
debug "Dropping message due to failed validation", msgId, peer
g.punishPeer(peer, msg)
continue
of ValidationResult.Ignore:
debug "Dropping message due to ignored validation", msgId, peer
continue
of ValidationResult.Accept:
discard
var toSendPeers = initHashSet[PubSubPeer]()
for t in msg.topicIDs: # for every topic in the message

View File

@ -464,9 +464,13 @@ method rpcHandler*(g: GossipSub,
# g.anonymize needs no evaluation when receiving messages
# as we have a "lax" policy and allow signed messages
if (await g.validate(msg)) == ValidationResult.Reject:
trace "Dropping message due to failed validation", msgId, peer
let validation = await g.validate(msg)
case validation
of ValidationResult.Reject, ValidationResult.Ignore:
debug "Dropping message due to ignored validation", msgId, peer
continue
of ValidationResult.Accept:
discard
var toSendPeers = initHashSet[PubSubPeer]()
for t in msg.topicIDs: # for every topic in the message