Commit b583c0e1 authored by Peter Jankuliak's avatar Peter Jankuliak
Browse files

Announcer: fix possible reason for announcer to stop

I could have happened as such:

1. Cache adds foo.bar to the announcer
2. User hits the "purge cache" button and foo.bar is marked for removal
   after some delay
3. Cache adds foo.bar to the announcer again, but nothing happens because
   foo.bar is already there (although marked for removal)
4. Time passes and announcer removes foo.bar

Solution:
* Unmark foo.bar's removal flag in step #3 above
parent 7863fe73
......@@ -78,19 +78,21 @@ struct Announcer::Loop {
, _log_level(log_level)
{ }
bool already_has(const Key& key) const {
for (auto& e : entries) {
if (e.first.key == key) return true;
Entries::iterator find_entry_by_key(const Key& key) {
for (auto i = entries.begin(); i != entries.end(); ++i) {
if (i->first.key == key) return i;
}
return false;
return entries.end();
}
void add(Key key) {
bool already_has_key = already_has(key);
auto entry_i = find_entry_by_key(key);
bool already_has_key = (entry_i != entries.end());
if (_log_level.debug()) {
if (already_has_key) {
std::cerr << "Announcer: adding " << key << " (already exists)\n";
entry_i->first.to_remove = false;
} else {
std::cerr << "Announcer: adding " << key << "\n";
}
......@@ -119,6 +121,9 @@ struct Announcer::Loop {
if (i->first.key == key) break; // found
if (i == entries.end()) return; // not found
if (_log_level.debug()) {
std::cerr << "Announcer: marking " << key << " for removal\n";
}
// The actual removal is not done here but in the main loop.
i->first.to_remove = true;
// No new entries, so no `_timer_cancel` reset.
......
......@@ -439,6 +439,9 @@ struct Client::Impl {
set<udp::endpoint> eps = local_peer_discovery.found_peers();
if (dbg) {
logger.log("Bep5Http: local peers:", eps);
}
{
auto peer_i = peer_cache.find(dht_group);
......
Supports Markdown
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