dht: fix recycling of existing search

This commit is contained in:
Adrien Béraud committed 2026-03-03 17:01:51 -05:00
1 parent 71d14bb0fe
commit 3d42ad6b9b
4 files changed
+19 -1

No files matched your search

+10 -1
View File
@@ -889,10 +889,16 @@ Dht::search(const InfoHash& id,
sr = std::make_shared<Search>();
srs.emplace(id, sr);
} else {
for (auto it = srs.begin(); it != srs.end();) {
for (auto it = srs.begin(); it != srs.end(); ++it) {
auto& s = *it->second;
if ((s.done or s.expired) and s.announce.empty() and s.listeners.empty()) {
sr = it->second;
if (sr->nextSearchStep)
scheduler.cancel(sr->nextSearchStep);
if (sr->opExpirationJob)
scheduler.cancel(sr->opExpirationJob);
sr->clear();
srs.erase(it);
break;
}
}
@@ -901,8 +907,11 @@ Dht::search(const InfoHash& id,
logger_->error("[search {} IPv{}] Maximum number of searches reached!",
id.toString(),
(af == AF_INET) ? '4' : '6');
if (dcb)
dcb(false, {});
return {};
}
srs.emplace(id, sr);
}
sr->af = af;
sr->tid = search_id++;
+7
View File
@@ -210,6 +210,13 @@ SearchCache::cancelAll(const std::function<void(size_t)>& onCancel)
ops.clear();
}
void
SearchCache::clear()
{
ops.clear();
nextExpiration_ = time_point::max();
}
time_point
SearchCache::expire(const time_point& now, const std::function<void(size_t)>& onCancel)
{
+1
View File
@@ -164,6 +164,7 @@ public:
bool cancelListen(size_t gtoken, const time_point& now);
void cancelAll(const std::function<void(size_t)>& onCancel);
void clear();
time_point expire(const time_point& now, const std::function<void(size_t)>& onCancel);
time_point getExpiration() const { return nextExpiration_; }
+1
View File
@@ -836,6 +836,7 @@ struct Dht::Search
listeners.clear();
nodes.clear();
nextSearchStep.reset();
cache.clear();
}
};