From aaa6e4add30c6a905c8a00ec85ef6912d1a89b49 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2020 11:46:57 +0200 Subject: [PATCH] Update cuckoofilter requirement from 0.3.2 to 0.5.0 (#1763) * Update cuckoofilter requirement from 0.3.2 to 0.5.0 Updates the requirements on [cuckoofilter](https://github.com/axiomhq/rust-cuckoofilter) to permit the latest version. - [Release notes](https://github.com/axiomhq/rust-cuckoofilter/releases) - [Changelog](https://github.com/axiomhq/rust-cuckoofilter/blob/master/CHANGELOG.md) - [Commits](https://github.com/axiomhq/rust-cuckoofilter/commits) Signed-off-by: dependabot[bot] * protocols/floodsub: Warn when Cuckoofilter has to evict item With Cuckoofilter `v0.4.0` `add` and `test_and_add` return an error when an old element has to be evicted in favor of a new one to take its place. The previous behavior was panicing. With this commit the error is logged on `warn` level. * *: Update changelogs and cargo tomls Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Inden --- CHANGELOG.md | 6 +++--- Cargo.toml | 2 +- protocols/floodsub/CHANGELOG.md | 4 ++++ protocols/floodsub/Cargo.toml | 5 +++-- protocols/floodsub/src/layer.rs | 23 ++++++++++++++++++----- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7761b7e1..69555d53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,9 +25,9 @@ # Version 0.29.0 [unreleased] -- Update `libp2p-core`, `libp2p-gossipsub`, `libp2p-mplex`, `libp2p-noise`, - `libp2p-plaintext`, `libp2p-request-response`, `libp2p-websocket` and - `parity-multiaddr`. +- Update `libp2p-core`, `libp2p-floodsub`, `libp2p-gossipsub`, `libp2p-mplex`, + `libp2p-noise`, `libp2p-plaintext`, `libp2p-request-response`, + `libp2p-websocket` and `parity-multiaddr`. # Version 0.28.1 [2020-09-10] diff --git a/Cargo.toml b/Cargo.toml index 78ee1be9..04640d18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,7 +64,7 @@ futures = "0.3.1" lazy_static = "1.2" libp2p-core = { version = "0.22.2", path = "core" } libp2p-core-derive = { version = "0.20.2", path = "misc/core-derive" } -libp2p-floodsub = { version = "0.22.0", path = "protocols/floodsub", optional = true } +libp2p-floodsub = { version = "0.23.0", path = "protocols/floodsub", optional = true } libp2p-gossipsub = { version = "0.22.1", path = "./protocols/gossipsub", optional = true } libp2p-identify = { version = "0.22.0", path = "protocols/identify", optional = true } libp2p-kad = { version = "0.23.1", path = "protocols/kad", optional = true } diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index b3617968..59498af8 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.23.0 [unreleased] + +- Update dependencies. + # 0.22.0 [2020-09-09] - Update `libp2p-swarm` and `libp2p-core`. diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index ce96ba29..08d453ee 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-floodsub" edition = "2018" description = "Floodsub protocol for libp2p" -version = "0.22.0" +version = "0.23.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -10,11 +10,12 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -cuckoofilter = "0.3.2" +cuckoofilter = "0.5.0" fnv = "1.0" futures = "0.3.1" libp2p-core = { version = "0.22.0", path = "../../core" } libp2p-swarm = { version = "0.22.0", path = "../../swarm" } +log = "0.4" prost = "0.6.1" rand = "0.7" smallvec = "1.0" diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index c2ae8146..2d5d3e12 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -21,7 +21,7 @@ use crate::protocol::{FloodsubProtocol, FloodsubMessage, FloodsubRpc, FloodsubSubscription, FloodsubSubscriptionAction}; use crate::topic::Topic; use crate::FloodsubConfig; -use cuckoofilter::CuckooFilter; +use cuckoofilter::{CuckooError, CuckooFilter}; use fnv::FnvHashSet; use libp2p_core::{Multiaddr, PeerId, connection::ConnectionId}; use libp2p_swarm::{ @@ -33,6 +33,7 @@ use libp2p_swarm::{ NotifyHandler, DialPeerCondition, }; +use log::warn; use rand; use smallvec::SmallVec; use std::{collections::VecDeque, iter}; @@ -206,7 +207,12 @@ impl Floodsub { let self_subscribed = self.subscribed_topics.iter().any(|t| message.topics.iter().any(|u| t == u)); if self_subscribed { - self.received.add(&message); + if let Err(e @ CuckooError::NotEnoughSpace) = self.received.add(&message) { + warn!( + "Message was added to 'received' Cuckoofilter but some \ + other message was removed as a consequence: {}", e, + ); + } if self.config.subscribe_local_messages { self.events.push_back( NetworkBehaviourAction::GenerateEvent(FloodsubEvent::Message(message.clone()))); @@ -327,9 +333,16 @@ impl NetworkBehaviour for Floodsub { for message in event.messages { // Use `self.received` to skip the messages that we have already received in the past. - // Note that this can false positive. - if !self.received.test_and_add(&message) { - continue; + // Note that this can result in false positives. + match self.received.test_and_add(&message) { + Ok(true) => {}, // Message was added. + Ok(false) => continue, // Message already existed. + Err(e @ CuckooError::NotEnoughSpace) => { // Message added, but some other removed. + warn!( + "Message was added to 'received' Cuckoofilter but some \ + other message was removed as a consequence: {}", e, + ); + } } // Add the message to be dispatched to the user.