From 75ae7b0461b695201cd0161d7a7b7840ff879f7e Mon Sep 17 00:00:00 2001 From: Victor Ermolaev <16148931+vnermolaev@users.noreply.github.com> Date: Mon, 6 Dec 2021 17:08:29 +0100 Subject: [PATCH] protocols/floodsub: Propagate messages only to target peers (#2360) Propagate messages only to the target peers and not all connected peers. Co-authored-by: Victor Ermolaev Co-authored-by: Max Inden --- protocols/floodsub/CHANGELOG.md | 4 ++++ protocols/floodsub/src/layer.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index 74c5d3db..116dafef 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -4,8 +4,12 @@ - Migrate to Rust edition 2021 (see [PR 2339]). +- Propagate messages only to the target peers and not all connected peers (see [PR2360]). + [PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339 +[PR 2360]: https://github.com/libp2p/rust-libp2p/pull/2360/ + # 0.32.0 [2021-11-16] - Update dependencies. diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index 73b8edb9..b2093c76 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -253,6 +253,12 @@ impl Floodsub { // Send to peers we know are subscribed to the topic. for (peer_id, sub_topic) in self.connected_peers.iter() { + // Peer must be in a communication list. + if !self.target_peers.contains(peer_id) { + continue; + } + + // Peer must be subscribed for the topic. if !sub_topic .iter() .any(|t| message.topics.iter().any(|u| t == u)) @@ -402,6 +408,12 @@ impl NetworkBehaviour for Floodsub { continue; } + // Peer must be in a communication list. + if !self.target_peers.contains(peer_id) { + continue; + } + + // Peer must be subscribed for the topic. if !subscr_topics .iter() .any(|t| message.topics.iter().any(|u| t == u))