Skip to content

Commit

Permalink
src/query/peers/closest: Consider all peers at initialization
Browse files Browse the repository at this point in the history
Instead of initializing the iterator with `num_results` amount of nodes,
discarding the remaining, initialize the iterator with all provided
peers.

This patch allows the following scenario:

> Given an iterator with the configured goal of 1 result and an initial
set of peers of 2, one would expect the iterator to try the second peer
in case the first fails.

There is a downside to this patch. Say the iterator is initialized with
100 peers. Each peer is doomed to fail. In this case the iterator will
try each peer resulting in many connection attempts.

While the previous state is a safeguard against the scenario above, the
same could happen when the iterator is configured with num_result of 10,
the 9 first peers return 100 peers, each of them being doomed to fail,
thus the iterator would again attempt to make 100 connections only to
fail overall.
  • Loading branch information
mxinden committed Apr 1, 2020
1 parent 129920b commit 4fb9366
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions protocols/kad/src/query/peers/closest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ impl ClosestPeersIter {
let distance = key.distance(&target);
let state = PeerState::NotContacted;
(distance, Peer { key, state })
})
.take(config.num_results));
}));

// The iterator initially makes progress by iterating towards the target.
let state = State::Iterating { no_progress : 0 };
Expand Down

0 comments on commit 4fb9366

Please sign in to comment.