From 27b9bf436e76458a7f0eb62f9b155600a10c710c Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com> Date: Wed, 21 Oct 2020 12:25:42 +0900 Subject: [PATCH] fix validation according to specification (#410) --- libp2p/protocols/pubsub/floodsub.nim | 8 ++++++-- libp2p/protocols/pubsub/gossipsub.nim | 9 ++++++++- libp2p/protocols/pubsub/gossipsub10.nim | 8 ++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libp2p/protocols/pubsub/floodsub.nim b/libp2p/protocols/pubsub/floodsub.nim index 62d973d..cabcc7c 100644 --- a/libp2p/protocols/pubsub/floodsub.nim +++ b/libp2p/protocols/pubsub/floodsub.nim @@ -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 diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 9468cb7..10cdadc 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -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 diff --git a/libp2p/protocols/pubsub/gossipsub10.nim b/libp2p/protocols/pubsub/gossipsub10.nim index cb97c10..47c542f 100644 --- a/libp2p/protocols/pubsub/gossipsub10.nim +++ b/libp2p/protocols/pubsub/gossipsub10.nim @@ -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