Skip to content

Commit

Permalink
small refactorings to make the code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Nov 11, 2023
1 parent fdee626 commit f2b1f42
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2817,24 +2817,27 @@ where
.connections
.push(connection_id);

if other_established == 0 {
// Ignore connections from blacklisted peers.
if self.blacklisted_peers.contains(&peer_id) {
tracing::debug!(peer=%peer_id, "Ignoring connection from blacklisted peer");
} else {
tracing::debug!(peer=%peer_id, "New peer connected");
// We need to send our subscriptions to the newly-connected node.
for topic_hash in self.mesh.keys().cloned().collect::<Vec<_>>() {
self.send_message(peer_id, RpcOut::Subscribe(topic_hash));
}
}
if other_established > 0 {
return; // Not our first connection to this peer, hence nothing to do.
}

// Ignore connections from blacklisted peers.
if self.blacklisted_peers.contains(&peer_id) {
tracing::debug!(peer=%peer_id, "Ignoring connection from blacklisted peer");
return;
}

// Insert an empty set of the topics of this peer until known.
self.peer_topics.insert(peer_id, Default::default());
tracing::debug!(peer=%peer_id, "New peer connected");
// We need to send our subscriptions to the newly-connected node.
for topic_hash in self.mesh.keys().cloned().collect::<Vec<_>>() {
self.send_message(peer_id, RpcOut::Subscribe(topic_hash));
}

if let Some((peer_score, ..)) = &mut self.peer_score {
peer_score.add_peer(peer_id);
}
// Insert an empty set of the topics of this peer until known.
self.peer_topics.insert(peer_id, Default::default());

if let Some((peer_score, ..)) = &mut self.peer_score {
peer_score.add_peer(peer_id);
}
}

Expand Down

0 comments on commit f2b1f42

Please sign in to comment.