mirror of https://github.com/oxen-io/lokinet
try fixing bootstrap
This commit is contained in:
parent
0a7021d827
commit
16e20a9e79
|
@ -61,7 +61,8 @@ namespace llarp
|
|||
auto threads = config->router.workerThreads();
|
||||
if(threads <= 0)
|
||||
threads = 1;
|
||||
worker = std::make_shared< llarp::thread::ThreadPool >(threads, 1024, "llarp-worker");
|
||||
worker = std::make_shared< llarp::thread::ThreadPool >(threads, 1024,
|
||||
"llarp-worker");
|
||||
|
||||
nodedb_dir = config->netdb.nodedbDir();
|
||||
|
||||
|
|
|
@ -645,7 +645,7 @@ namespace llarp
|
|||
// ourKey should never be in the connected list
|
||||
// requester is likely in the connected list
|
||||
// 4 or connection nodes (minus a potential requestor), whatever is less
|
||||
if(!_nodes->GetManyNearExcluding(t, found, 1,
|
||||
if(!_nodes->GetManyNearExcluding(t, found, nodeCount >= 4 ? 4 : 1,
|
||||
std::set< Key_t >{ourKey, requester}))
|
||||
{
|
||||
llarp::LogError(
|
||||
|
|
|
@ -920,7 +920,6 @@ namespace llarp
|
|||
std::make_unique< FileLogStream >(diskworker(), logfile, 100, true);
|
||||
}
|
||||
|
||||
|
||||
netConfig.insert(conf->dns.netConfig.begin(), conf->dns.netConfig.end());
|
||||
|
||||
std::vector< std::string > configRouters = conf->connect.routers;
|
||||
|
@ -1074,6 +1073,33 @@ namespace llarp
|
|||
> 0;
|
||||
}
|
||||
|
||||
bool
|
||||
Router::ShouldReportStats(llarp_time_t now) const
|
||||
{
|
||||
static constexpr llarp_time_t ReportStatsInterval = 30 * 1000;
|
||||
return now - m_LastStatsReport > ReportStatsInterval;
|
||||
}
|
||||
|
||||
void
|
||||
Router::ReportStats()
|
||||
{
|
||||
const auto now = Now();
|
||||
LogInfo("---- BEGIN REPORT ----");
|
||||
LogInfo(nodedb()->num_loaded(), " RCs loaded");
|
||||
LogInfo(bootstrapRCList.size(), " bootstrap peers");
|
||||
LogInfo(NumberOfConnectedRouters(), " router connections");
|
||||
if(IsServiceNode())
|
||||
{
|
||||
LogInfo(NumberOfConnectedClients(), " client connections");
|
||||
LogInfo(_rc.Age(now), " ms since we last updated our RC");
|
||||
LogInfo(_rc.TimeUntilExpires(now), " ms until our RC expires");
|
||||
}
|
||||
LogInfo(now, " system time");
|
||||
LogInfo(m_LastStatsReport, " last reported stats");
|
||||
LogInfo("----- END REPORT -----");
|
||||
m_LastStatsReport = now;
|
||||
}
|
||||
|
||||
void
|
||||
Router::Tick()
|
||||
{
|
||||
|
@ -1084,7 +1110,51 @@ namespace llarp
|
|||
|
||||
routerProfiling().Tick();
|
||||
|
||||
if(IsServiceNode())
|
||||
if(ShouldReportStats(now))
|
||||
{
|
||||
ReportStats();
|
||||
}
|
||||
|
||||
const auto insertRouters = [&](const std::vector< RouterContact > &res) {
|
||||
// store found routers
|
||||
for(const auto &rc : res)
|
||||
{
|
||||
// don't accept expired RCs
|
||||
if(rc.Verify(Now(), false))
|
||||
nodedb()->InsertAsync(rc);
|
||||
}
|
||||
};
|
||||
|
||||
const bool isSvcNode = IsServiceNode();
|
||||
|
||||
// try looking up stale routers
|
||||
nodedb()->VisitInsertedBefore(
|
||||
[&](const RouterContact &rc) {
|
||||
if(HasPendingRouterLookup(rc.pubkey))
|
||||
return;
|
||||
LookupRouter(rc.pubkey, insertRouters);
|
||||
},
|
||||
now - RouterContact::UpdateInterval);
|
||||
|
||||
std::set< RouterID > removeStale;
|
||||
// remove stale routers
|
||||
const auto timeout = isSvcNode
|
||||
? RouterContact::Lifetime / 8
|
||||
: RouterContact::UpdateWindow * RouterContact::UpdateTries;
|
||||
nodedb()->VisitInsertedBefore(
|
||||
[&](const RouterContact &rc) {
|
||||
if(IsBootstrapNode(rc.pubkey))
|
||||
return;
|
||||
LogInfo("removing stale router: ", RouterID(rc.pubkey));
|
||||
removeStale.insert(rc.pubkey);
|
||||
},
|
||||
now - timeout);
|
||||
|
||||
nodedb()->RemoveIf([removeStale](const RouterContact &rc) -> bool {
|
||||
return removeStale.count(rc.pubkey) > 0;
|
||||
});
|
||||
|
||||
if(isSvcNode)
|
||||
{
|
||||
if(_rc.ExpiresSoon(now, randint() % 10000)
|
||||
|| (now - _rc.last_updated) > rcRegenInterval)
|
||||
|
@ -1103,36 +1173,7 @@ namespace llarp
|
|||
});
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
// try looking up stale routers
|
||||
nodedb()->VisitInsertedBefore(
|
||||
[&](const RouterContact &rc) {
|
||||
if(HasPendingRouterLookup(rc.pubkey))
|
||||
return;
|
||||
LookupRouter(rc.pubkey,
|
||||
[&](const std::vector< RouterContact > &result) {
|
||||
// store found routers
|
||||
for(const auto &rc : result)
|
||||
nodedb()->InsertAsync(rc);
|
||||
});
|
||||
},
|
||||
now - RouterContact::UpdateInterval);
|
||||
std::set< RouterID > removeStale;
|
||||
// remove stale routers
|
||||
nodedb()->VisitInsertedBefore(
|
||||
[&](const RouterContact &rc) {
|
||||
if(IsBootstrapNode(rc.pubkey))
|
||||
return;
|
||||
removeStale.insert(rc.pubkey);
|
||||
},
|
||||
now - ((RouterContact::UpdateInterval * 3) / 2));
|
||||
|
||||
nodedb()->RemoveIf([removeStale](const RouterContact &rc) -> bool {
|
||||
return removeStale.count(rc.pubkey) > 0;
|
||||
});
|
||||
}
|
||||
// expire transit paths
|
||||
// expire paths
|
||||
paths.ExpirePaths(now);
|
||||
{
|
||||
auto itr = pendingEstablishJobs.begin();
|
||||
|
@ -1215,7 +1256,7 @@ namespace llarp
|
|||
ConnectToRandomRouters(dlt);
|
||||
}
|
||||
|
||||
if(!IsServiceNode())
|
||||
if(!isSvcNode)
|
||||
{
|
||||
_hiddenServiceContext.Tick(now);
|
||||
}
|
||||
|
|
|
@ -549,6 +549,14 @@ namespace llarp
|
|||
std::atomic< bool > _stopping;
|
||||
std::atomic< bool > _running;
|
||||
|
||||
llarp_time_t m_LastStatsReport = 0;
|
||||
|
||||
bool
|
||||
ShouldReportStats(llarp_time_t now) const;
|
||||
|
||||
void
|
||||
ReportStats();
|
||||
|
||||
bool
|
||||
UpdateOurRC(bool rotateKeys = false);
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace llarp
|
|||
llarp_time_t RouterContact::UpdateInterval = 30 * 60 * 1000;
|
||||
// 1 minute window for update
|
||||
llarp_time_t RouterContact::UpdateWindow = 60 * 1000;
|
||||
// try 5 times to update
|
||||
int RouterContact::UpdateTries = 5;
|
||||
|
||||
NetID::NetID(const byte_t *val) : AlignedBuffer< 8 >()
|
||||
{
|
||||
|
@ -235,16 +237,27 @@ namespace llarp
|
|||
|
||||
bool
|
||||
RouterContact::IsExpired(llarp_time_t now) const
|
||||
{
|
||||
return Age(now) >= Lifetime;
|
||||
}
|
||||
|
||||
llarp_time_t
|
||||
RouterContact::TimeUntilExpires(llarp_time_t now) const
|
||||
{
|
||||
const auto expiresAt = last_updated + Lifetime;
|
||||
return now >= expiresAt;
|
||||
return now < expiresAt ? expiresAt - now : 0;
|
||||
}
|
||||
|
||||
llarp_time_t
|
||||
RouterContact::Age(llarp_time_t now) const
|
||||
{
|
||||
return now > last_updated ? now - last_updated : 0;
|
||||
}
|
||||
|
||||
bool
|
||||
RouterContact::ExpiresSoon(llarp_time_t now, llarp_time_t dlt) const
|
||||
{
|
||||
const auto expiresAt = last_updated + Lifetime;
|
||||
return expiresAt <= now || expiresAt - now <= dlt;
|
||||
return TimeUntilExpires(now) <= dlt;
|
||||
}
|
||||
|
||||
std::string
|
||||
|
|
|
@ -71,6 +71,7 @@ namespace llarp
|
|||
static llarp_time_t Lifetime;
|
||||
static llarp_time_t UpdateInterval;
|
||||
static llarp_time_t UpdateWindow;
|
||||
static int UpdateTries;
|
||||
|
||||
RouterContact()
|
||||
{
|
||||
|
@ -179,6 +180,14 @@ namespace llarp
|
|||
bool
|
||||
IsExpired(llarp_time_t now) const;
|
||||
|
||||
/// returns time in ms until we expire or 0 if we have expired
|
||||
llarp_time_t
|
||||
TimeUntilExpires(llarp_time_t now) const;
|
||||
|
||||
/// get the age of this RC in ms
|
||||
llarp_time_t
|
||||
Age(llarp_time_t now) const;
|
||||
|
||||
bool
|
||||
OtherIsNewer(const RouterContact &other) const
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue