Commit 2b6b0d81 authored by Matt Whitlock's avatar Matt Whitlock
Browse files

dht: expire announcement tokens after 30 minutes

dht::Database was exhibiting unbounded memory consumption due to
generating and remembering announcement tokens without ever expiring
and forgetting them. This commit augments the existing
dht::Database::expire(bt::Timestamp) function so that it erases tokens
that are more than MAX_ITEM_AGE (30 minutes) old. Also, it deletes and
erases DBItemList instances when they have been emptied by expirations.
parent a3f8f376
......@@ -118,7 +118,22 @@ void Database::expire(bt::TimeStamp now)
while (dbl->count() > 0 && dbl->first().expired(now)) {
dbl->pop_front();
}
++itr;
if (dbl->count() == 0) {
// PtrMap::erase(PtrMap::iterator) does not auto-delete
delete dbl;
itr = items.erase(itr);
} else {
++itr;
}
}
QMap<QByteArray, bt::TimeStamp>::iterator token_itr = tokens.begin();
while (token_itr != tokens.end()) {
if (now - token_itr.value() >= MAX_ITEM_AGE) {
token_itr = tokens.erase(token_itr);
} else {
++token_itr;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment