mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
node cache: expire nodes on destructions
Expiring nodes on cache destruction allow to cancel any remaining request before the dht instance is destructed, since Node instances might remain alive after the dht instance is destroyed.
This commit is contained in:
1 parent
6378840d33
commit
41ebbe21d4
2 files changed
+17
No files matched your search
@@ -20,6 +20,12 @@
|
||||
|
||||
namespace dht {
|
||||
|
||||
NodeCache::~NodeCache()
|
||||
{
|
||||
cache_4.setExpired();
|
||||
cache_6.setExpired();
|
||||
}
|
||||
|
||||
Sp<Node>
|
||||
NodeCache::getNode(const InfoHash& id, sa_family_t family) {
|
||||
return cache(family).getNode(id);
|
||||
@@ -116,4 +122,12 @@ NodeCache::NodeMap::clearBadNodes() {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NodeCache::NodeMap::setExpired() {
|
||||
for (auto& wn : *this)
|
||||
if (auto n = wn.second.lock())
|
||||
n->setExpired();
|
||||
clear();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user