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 62d973d6e..cabcc7cfd 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 9468cb7ab..10cdadc08 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 cb97c1025..47c542ff4 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