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

async remove dead rc files when we think they are dead

This commit is contained in:
Jeff Becker 2019-03-25 09:52:22 -04:00
parent 7065b00c22
commit fbb2c78d3c
No known key found for this signature in database
GPG key ID: F357B3B42F6F9B05
3 changed files with 56 additions and 1 deletions

View file

@ -45,6 +45,48 @@ llarp_nodedb::Get(const llarp::RouterID &pk, llarp::RouterContact &result)
return true;
}
// kill rcs from disk async
struct AsyncKillRCJobs
{
std::set< std::string > files;
static void
Work(void *u)
{
static_cast< AsyncKillRCJobs * >(u)->Kill();
}
void
Kill()
{
for(const auto &file : files)
fs::remove(file);
delete this;
}
};
void
llarp_nodedb::RemoveIf(
std::function< bool(const llarp::RouterContact &rc) > filter)
{
AsyncKillRCJobs *job = new AsyncKillRCJobs();
{
llarp::util::Lock l(&access);
auto itr = entries.begin();
while(itr != entries.end())
{
if(filter(itr->second))
{
job->files.insert(getRCFilePath(itr->second.pubkey));
itr = entries.erase(itr);
}
else
++itr;
}
}
llarp_threadpool_queue_job(disk, {job, AsyncKillRCJobs::Work});
}
bool
llarp_nodedb::Has(const llarp::RouterID &pk)
{
@ -476,9 +518,14 @@ llarp_nodedb::select_random_hop_excluding(
llarp::util::Lock lock(&access);
/// checking for "guard" status for N = 0 is done by caller inside of
/// pathbuilder's scope
size_t sz = entries.size();
const size_t sz = entries.size();
if(sz < 3)
{
llarp::LogWarn(
"we don't have enough entries in nodedb to select hop, have ", sz,
" need ", 3);
return false;
}
llarp_time_t now = llarp::time_now_ms();
auto itr = entries.begin();

View file

@ -56,6 +56,10 @@ struct llarp_nodedb
bool
Remove(const llarp::RouterID &pk) LOCKS_EXCLUDED(access);
void
RemoveIf(std::function< bool(const llarp::RouterContact &) > filter)
LOCKS_EXCLUDED(access);
void
Clear() LOCKS_EXCLUDED(access);

View file

@ -1039,6 +1039,10 @@ namespace llarp
return true;
});
}
// kill dead nodes
nodedb()->RemoveIf([&](const RouterContact &rc) -> bool {
return routerProfiling().IsBad(rc.pubkey);
});
paths.TickPaths(now);
paths.ExpirePaths(now);