Skip to content
Snippets Groups Projects
Commit fdfa10bd authored by Adrien Béraud's avatar Adrien Béraud
Browse files

dht: clear search before expiring it

parent f200f9df
No related branches found
No related tags found
No related merge requests found
...@@ -357,7 +357,7 @@ struct Dht::Search { ...@@ -357,7 +357,7 @@ struct Dht::Search {
callbacks.clear(); callbacks.clear();
listeners.clear(); listeners.clear();
nodes.clear(); nodes.clear();
nextSearchStep = {}; nextSearchStep.reset();
} }
}; };
...@@ -465,10 +465,10 @@ Dht::trySearchInsert(const std::shared_ptr<Node>& node) ...@@ -465,10 +465,10 @@ Dht::trySearchInsert(const std::shared_ptr<Node>& node)
auto family = node->getFamily(); auto family = node->getFamily();
auto& srs = family == AF_INET ? searches4 : searches6; auto& srs = family == AF_INET ? searches4 : searches6;
for (auto& srp : srs) { for (auto& srp : srs) {
auto& s = srp.second; auto& s = *srp.second;
if (s->insertNode(node, now)) { if (s.insertNode(node, now)) {
inserted = true; inserted = true;
scheduler.edit(s->nextSearchStep, s->getNextStepTime(types, now)); scheduler.edit(s.nextSearchStep, s.getNextStepTime(types, now));
} }
} }
return inserted; return inserted;
...@@ -704,10 +704,11 @@ Dht::expireSearches() ...@@ -704,10 +704,11 @@ Dht::expireSearches()
{ {
auto t = scheduler.time() - SEARCH_EXPIRE_TIME; auto t = scheduler.time() - SEARCH_EXPIRE_TIME;
auto expired = [&](std::pair<const InfoHash, std::shared_ptr<Search>>& srp) { auto expired = [&](std::pair<const InfoHash, std::shared_ptr<Search>>& srp) {
auto& sr = srp.second; auto& sr = *srp.second;
auto b = sr->callbacks.empty() && sr->announce.empty() && sr->listeners.empty() && sr->step_time < t; auto b = sr.callbacks.empty() && sr.announce.empty() && sr.listeners.empty() && sr.step_time < t;
if (b) { if (b) {
DHT_LOG.DEBUG("Removing search %s", srp.first.toString().c_str()); DHT_LOG.DEBUG("Removing search %s", srp.first.toString().c_str());
sr.clear();
return b; return b;
} else { return false; } } else { return false; }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment