node_cache: fix bad condition in getCachedNodes

This commit is contained in:
Simon Désaulniers committed 2016-08-05 13:07:14 -04:00
1 parent 9c1a0ae27f
commit f6cd79952c
1 file changed
+4 -6
+4 -6
View File
@@ -35,21 +35,19 @@ NodeCache::getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, tim
std::vector<std::shared_ptr<Node>>
NodeCache::getCachedNodes(const InfoHash& id, sa_family_t sa_f, size_t total) {
auto c = (sa_f == AF_INET ? cache_4 : cache_6);
const auto& c = (sa_f == AF_INET ? cache_4 : cache_6);
auto it_p = c.lower_bound(id),
it_n = it_p;
std::vector<std::shared_ptr<Node>> nodes;
nodes.reserve(std::min(c.size(), total));
decltype(c)::iterator it;
NodeMap::const_iterator it;
if (it_p != c.begin()) /* Create 2 separate iterator if we could */
--it_p;
while ( nodes.size() != total
or (it_n == c.end() and it_p == c.end()) ) {
/* If one of the iterator is at the end, then take the other one
while (nodes.size() < total and (it_n != c.end() or it_p != c.end())) {
/* If one of the iterator is at the end, then take the other one
If they are both in middle of somewhere comapre both and take
the closest to the id. */
if (it_p == c.end()) it = it_n++;