|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|