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))