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 <victorermolaev@gmail.com>
Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
Victor Ermolaev
2021-12-06 17:08:29 +01:00
committed by GitHub
parent 4401ffa8b3
commit 75ae7b0461
2 changed files with 16 additions and 0 deletions

View File

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