Skip to content
Snippets Groups Projects
Commit 38306eae authored by Simon Désaulniers's avatar Simon Désaulniers
Browse files

only one refill allowed before expiring search

parent 04632a82
Branches
Tags
No related merge requests found
...@@ -609,6 +609,7 @@ private: ...@@ -609,6 +609,7 @@ private:
bool expired {false}; /* no node, or all nodes expired */ bool expired {false}; /* no node, or all nodes expired */
bool done {false}; /* search is over, cached for later */ bool done {false}; /* search is over, cached for later */
bool refilled {false};
std::vector<SearchNode> nodes {}; std::vector<SearchNode> nodes {};
std::vector<Announce> announce {}; std::vector<Announce> announce {};
std::vector<Get> callbacks {}; std::vector<Get> callbacks {};
......
...@@ -1048,13 +1048,19 @@ Dht::searchStep(Search& sr) ...@@ -1048,13 +1048,19 @@ Dht::searchStep(Search& sr)
return sn.candidate or sn.node->isExpired(now); return sn.candidate or sn.node->isExpired(now);
}) == sr.nodes.size()) }) == sr.nodes.size())
{ {
unsigned added = sr.refill(sr.af == AF_INET ? buckets : buckets6, now); unsigned added = 0;
if (not sr.refilled) {
added = sr.refill(sr.af == AF_INET ? buckets : buckets6, now);
sr.refilled = true;
}
if (added) { if (added) {
DHT_WARN("[search %s IPv%c] refilled with %u nodes", sr.id.toString().c_str(), (sr.af == AF_INET) ? '4' : '6', added); DHT_WARN("[search %s IPv%c] refilled with %u nodes", sr.id.toString().c_str(), (sr.af == AF_INET) ? '4' : '6', added);
} else { } else {
DHT_ERROR("[search %s IPv%c] expired", sr.id.toString().c_str(), sr.af == AF_INET ? '4' : '6'); DHT_ERROR("[search %s IPv%c] expired", sr.id.toString().c_str(), sr.af == AF_INET ? '4' : '6');
// no nodes or all expired nodes // no nodes or all expired nodes
sr.expired = true; sr.expired = true;
// reset refilled since the search is now expired.
sr.refilled = false;
if (sr.announce.empty() && sr.listeners.empty()) { if (sr.announce.empty() && sr.listeners.empty()) {
// Listening or announcing requires keeping the cluster up to date. // Listening or announcing requires keeping the cluster up to date.
sr.done = true; sr.done = true;
...@@ -2622,10 +2628,9 @@ Dht::processMessage(const uint8_t *buf, size_t buflen, const sockaddr *from, soc ...@@ -2622,10 +2628,9 @@ Dht::processMessage(const uint8_t *buf, size_t buflen, const sockaddr *from, soc
} }
{ {
// We store a value only if we think we're part of the // We store a value only if we think we're part of the
// 2*TARGET_NODES nodes around the target id. // SEARCH_NODES nodes around the target id.
auto closest_nodes = (from->sa_family == AF_INET ? buckets : buckets6).findClosestNodes(msg.info_hash, 2*TARGET_NODES); auto closest_nodes = (from->sa_family == AF_INET ? buckets : buckets6).findClosestNodes(msg.info_hash, SEARCH_NODES);
if (msg.info_hash.xorCmp(closest_nodes.back()->id, myid) < 0) { if (msg.info_hash.xorCmp(closest_nodes.back()->id, myid) < 0) {
std::cerr << "my id [" << myid << "] is too far from " << msg.info_hash << ". Dropping value." << std::endl;
DHT_WARN("[node %s %s] announce too far from the target id. Dropping value.", DHT_WARN("[node %s %s] announce too far from the target id. Dropping value.",
msg.id.toString().c_str(), print_addr(from, fromlen).c_str()); msg.id.toString().c_str(), print_addr(from, fromlen).c_str());
for (auto& v : msg.values) { for (auto& v : msg.values) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment