mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d42ad6b9b |
No files matched your search
+10
-1
@@ -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++;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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_; }
|
||||
|
||||
@@ -836,6 +836,7 @@ struct Dht::Search
|
||||
listeners.clear();
|
||||
nodes.clear();
|
||||
nextSearchStep.reset();
|
||||
cache.clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user