mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
dht: unify bootstrapSearch and refill method
Since bootstrapSearch was rewritten to use the node cache, it made it clear that refill should be rewritten as such. However, then bootstrapSearch becomes irrelevant. An enhancement to refill is that it will let insertNode review its whole list of nodes and then let it insert nodes up to SEARCH_NODES nodes. The previous method would not garantee this behavior since, most of the times, it would pass less than SEARCH_NODES nodes to insertNode.
This commit is contained in:
6 files changed
+37
-67
No files matched your search
+3
-3
@@ -34,19 +34,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) {
|
||||
NodeCache::getCachedNodes(const InfoHash& id, sa_family_t sa_f, size_t count) {
|
||||
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));
|
||||
nodes.reserve(std::min(c.size(), count));
|
||||
NodeMap::const_iterator it;
|
||||
|
||||
if (it_p != c.begin()) /* Create 2 separate iterator if we could */
|
||||
--it_p;
|
||||
|
||||
while (nodes.size() < total and (it_n != c.end() or it_p != c.end())) {
|
||||
while (nodes.size() < count 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. */
|
||||
|
||||
Reference in new issue
Block a user