Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix peerset not filtering incoming connections in reserved-only #6249

Merged
1 commit merged into from
Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions client/peerset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,13 @@ impl Peerset {
trace!(target: "peerset", "Incoming {:?}", peer_id);
self.update_time();

if self.reserved_only {
if !self.priority_groups.get(RESERVED_NODES).map_or(false, |n| n.contains(&peer_id)) {
self.message_queue.push_back(Message::Reject(index));
return;
}
}

let not_connected = match self.data.peer(&peer_id) {
// If we're already connected, don't answer, as the docs mention.
peersstate::Peer::Connected(_) => return,
Expand Down Expand Up @@ -740,6 +747,26 @@ mod tests {
]);
}

#[test]
fn test_peerset_reject_incoming_in_reserved_only() {
let incoming = PeerId::random();
let ii = IncomingIndex(1);
let config = PeersetConfig {
in_peers: 50,
out_peers: 50,
bootnodes: vec![],
reserved_only: true,
priority_groups: vec![],
};

let (mut peerset, _) = Peerset::from_config(config);
peerset.incoming(incoming.clone(), ii);

assert_messages(peerset, vec![
Message::Reject(ii),
]);
}

#[test]
fn test_peerset_discovered() {
let bootnode = PeerId::random();
Expand Down