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:
Adrien Béraud committed 2017-10-30 13:12:16 -04:00
1 parent 6378840d33
commit 41ebbe21d4
2 files changed
+17

No files matched your search

+14
View File
@@ -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();
}
}