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:
parent
b9c130d576
commit
d54dc7a988
2 changed files with 27 additions and 0 deletions
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue