Browse Source

don't manage requests if exploratory pool is not ready. use monotonic timer and milliseconds

pull/1941/merge
orignal 8 months ago
parent
commit
cc75ccd070
  1. 26
      libi2pd/NetDb.cpp

26
libi2pd/NetDb.cpp

@ -107,7 +107,7 @@ namespace data
i2p::util::SetThreadName("NetDB"); i2p::util::SetThreadName("NetDB");
uint64_t lastManage = 0, lastExploratory = 0, lastManageRequest = 0; uint64_t lastManage = 0, lastExploratory = 0, lastManageRequest = 0;
uint64_t lastProfilesCleanup = i2p::util::GetSecondsSinceEpoch (); uint64_t lastProfilesCleanup = i2p::util::GetMonotonicMilliseconds ();
int16_t profilesCleanupVariance = 0; int16_t profilesCleanupVariance = 0;
while (m_IsRunning) while (m_IsRunning)
@ -148,41 +148,43 @@ namespace data
if (!m_IsRunning) break; if (!m_IsRunning) break;
if (!i2p::transport::transports.IsOnline ()) continue; // don't manage netdb when offline if (!i2p::transport::transports.IsOnline ()) continue; // don't manage netdb when offline
uint64_t ts = i2p::util::GetSecondsSinceEpoch (); uint64_t mts = i2p::util::GetMonotonicMilliseconds ();
if (ts - lastManageRequest >= MANAGE_REQUESTS_INTERVAL || ts + MANAGE_REQUESTS_INTERVAL < lastManageRequest) // manage requests every 15 seconds if (mts >= lastManageRequest + MANAGE_REQUESTS_INTERVAL*1000)
{
if (lastManageRequest || i2p::tunnel::tunnels.GetExploratoryPool ()) // expolratory pool is ready?
{ {
m_Requests.ManageRequests (); m_Requests.ManageRequests ();
lastManageRequest = ts; lastManageRequest = mts;
}
} }
if (ts - lastManage >= 60 || ts + 60 < lastManage) // manage routers and leasesets every minute if (mts >= lastManage + 60000) // manage routers and leasesets every minute
{ {
if (lastManage) if (lastManage)
{ {
ManageRouterInfos (); ManageRouterInfos ();
ManageLeaseSets (); ManageLeaseSets ();
} }
lastManage = ts; lastManage = mts;
} }
if (ts - lastProfilesCleanup >= (uint64_t)(i2p::data::PEER_PROFILE_AUTOCLEAN_TIMEOUT + profilesCleanupVariance) || if (mts >= lastProfilesCleanup + (uint64_t)(i2p::data::PEER_PROFILE_AUTOCLEAN_TIMEOUT + profilesCleanupVariance)*1000)
ts + i2p::data::PEER_PROFILE_AUTOCLEAN_TIMEOUT < lastProfilesCleanup)
{ {
m_RouterProfilesPool.CleanUpMt (); m_RouterProfilesPool.CleanUpMt ();
if (m_PersistProfiles) PersistProfiles (); if (m_PersistProfiles) PersistProfiles ();
DeleteObsoleteProfiles (); DeleteObsoleteProfiles ();
lastProfilesCleanup = ts; lastProfilesCleanup = mts;
profilesCleanupVariance = (rand () % (2 * i2p::data::PEER_PROFILE_AUTOCLEAN_VARIANCE) - i2p::data::PEER_PROFILE_AUTOCLEAN_VARIANCE); profilesCleanupVariance = (rand () % (2 * i2p::data::PEER_PROFILE_AUTOCLEAN_VARIANCE) - i2p::data::PEER_PROFILE_AUTOCLEAN_VARIANCE);
} }
if (ts - lastExploratory >= 30 || ts + 30 < lastExploratory) // exploratory every 30 seconds if (mts >= lastExploratory + 30000) // exploratory every 30 seconds
{ {
auto numRouters = m_RouterInfos.size (); auto numRouters = m_RouterInfos.size ();
if (!numRouters) if (!numRouters)
throw std::runtime_error("No known routers, reseed seems to be totally failed"); throw std::runtime_error("No known routers, reseed seems to be totally failed");
else // we have peers now else // we have peers now
m_FloodfillBootstrap = nullptr; m_FloodfillBootstrap = nullptr;
if (numRouters < 2500 || ts - lastExploratory >= 90) if (numRouters < 2500 || mts >= lastExploratory + 90000) // 90 seconds
{ {
numRouters = 800/numRouters; numRouters = 800/numRouters;
if (numRouters < 1) numRouters = 1; if (numRouters < 1) numRouters = 1;
@ -190,7 +192,7 @@ namespace data
m_Requests.ManageRequests (); m_Requests.ManageRequests ();
if(!i2p::context.IsHidden ()) if(!i2p::context.IsHidden ())
Explore (numRouters); Explore (numRouters);
lastExploratory = ts; lastExploratory = mts;
} }
} }
} }

Loading…
Cancel
Save