1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

prune dht peers every router tick

This commit is contained in:
Jeff Becker 2019-09-10 10:16:32 -04:00
parent b9c130d576
commit d54dc7a988
No known key found for this signature in database
GPG key ID: F357B3B42F6F9B05
2 changed files with 27 additions and 0 deletions

View file

@ -193,6 +193,21 @@ namespace llarp
return nodes.find(key) != nodes.end();
}
// remove all nodes who's key matches a predicate
template < typename Predicate >
void
RemoveIf(Predicate pred)
{
auto itr = nodes.begin();
while(itr != nodes.end())
{
if(pred(itr->first))
itr = nodes.erase(itr);
else
++itr;
}
}
void
Clear()
{

View file

@ -719,6 +719,18 @@ namespace llarp
diskworker()->addJob(
[&]() { routerProfiling().Save(routerProfilesFile.c_str()); });
}
// get connected peers
std::set< dht::Key_t > peersWeHave;
_linkManager.ForEachPeer([&peersWeHave](ILinkSession *s) {
if(!s->IsEstablished())
return;
peersWeHave.emplace(s->GetPubKey());
});
// remove any nodes we don't have connections to
_dht->impl->Nodes()->RemoveIf([&peersWeHave](const dht::Key_t &k) -> bool {
return peersWeHave.count(k) == 0;
});
} // namespace llarp
bool