Skip to content

Commit

Permalink
dht: keep track of storage usage in maintainStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
aberaud committed Oct 4, 2016
1 parent 261c193 commit f53c7a6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/dht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct Dht::Storage {
return values.empty();
}

void clear();
std::pair<ssize_t, ssize_t> clear();

size_t valueCount() const {
return values.size();
Expand Down Expand Up @@ -2205,11 +2205,14 @@ Dht::Storage::store(const std::shared_ptr<Value>& value, time_point created, ssi
}
}

void
std::pair<ssize_t, ssize_t>
Dht::Storage::clear()
{
size_t num_values = values.size();
size_t tot_size = total_size;
values.clear();
total_size = 0;
return std::make_pair(-tot_size, -num_values);
}

void
Expand Down Expand Up @@ -2793,7 +2796,9 @@ Dht::maintainStorage(InfoHash id, bool force, DoneCallback donecb) {

if (not want4 and not want6) {
DHT_LOG.DEBUG("Discarding storage values %s", id.toString().c_str());
local_storage->second.clear();
auto diff = local_storage->second.clear();
total_store_size += diff.first;
total_values += diff.second;
}

return announce_per_af;
Expand Down

0 comments on commit f53c7a6

Please sign in to comment.