|
|
|
@ -108,7 +108,7 @@ namespace data
|
|
|
|
|
|
|
|
|
|
uint64_t lastManage = 0, lastExploratory = 0, lastManageRequest = 0;
|
|
|
|
|
uint64_t lastProfilesCleanup = i2p::util::GetMonotonicMilliseconds (), lastObsoleteProfilesCleanup = lastProfilesCleanup;
|
|
|
|
|
int16_t profilesCleanupVariance = 0, obsoleteProfilesCleanVariance = 0;
|
|
|
|
|
int16_t profilesCleanupVariance = 0, obsoleteProfilesCleanVariance = 0, exploratoryIntervalVariance = 0;
|
|
|
|
|
|
|
|
|
|
while (m_IsRunning)
|
|
|
|
|
{
|
|
|
|
@ -186,7 +186,7 @@ namespace data
|
|
|
|
|
LogPrint (eLogWarning, "NetDb: Can't persist profiles. Profiles are being saved to disk");
|
|
|
|
|
}
|
|
|
|
|
lastProfilesCleanup = mts;
|
|
|
|
|
profilesCleanupVariance = (rand () % (2 * i2p::data::PEER_PROFILE_AUTOCLEAN_VARIANCE) - i2p::data::PEER_PROFILE_AUTOCLEAN_VARIANCE);
|
|
|
|
|
profilesCleanupVariance = rand () % i2p::data::PEER_PROFILE_AUTOCLEAN_VARIANCE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mts >= lastObsoleteProfilesCleanup + (uint64_t)(i2p::data::PEER_PROFILE_OBSOLETE_PROFILES_CLEAN_TIMEOUT + obsoleteProfilesCleanVariance)*1000)
|
|
|
|
@ -202,25 +202,27 @@ namespace data
|
|
|
|
|
else
|
|
|
|
|
LogPrint (eLogWarning, "NetDb: Can't delete profiles. Profiles are being deleted from disk");
|
|
|
|
|
lastObsoleteProfilesCleanup = mts;
|
|
|
|
|
obsoleteProfilesCleanVariance = (rand () % (2 * i2p::data::PEER_PROFILE_OBSOLETE_PROFILES_CLEAN_VARIANCE) - i2p::data::PEER_PROFILE_OBSOLETE_PROFILES_CLEAN_TIMEOUT);
|
|
|
|
|
obsoleteProfilesCleanVariance = rand () % i2p::data::PEER_PROFILE_OBSOLETE_PROFILES_CLEAN_VARIANCE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mts >= lastExploratory + 30000) // exploratory every 30 seconds
|
|
|
|
|
if (mts >= lastExploratory + NETDB_EXPLORATORY_INTERVAL) // check exploratory every 55 seconds
|
|
|
|
|
{
|
|
|
|
|
auto numRouters = m_RouterInfos.size ();
|
|
|
|
|
if (!numRouters)
|
|
|
|
|
throw std::runtime_error("No known routers, reseed seems to be totally failed");
|
|
|
|
|
else // we have peers now
|
|
|
|
|
m_FloodfillBootstrap = nullptr;
|
|
|
|
|
if (numRouters < 2500 || mts >= lastExploratory + 90000) // 90 seconds
|
|
|
|
|
if (numRouters < 2500 || mts >= lastExploratory + (NETDB_EXPLORATORY_INTERVAL + exploratoryIntervalVariance)*1000LL)
|
|
|
|
|
{
|
|
|
|
|
numRouters = 800/numRouters;
|
|
|
|
|
if (numRouters < 1) numRouters = 1;
|
|
|
|
|
if (numRouters > 9) numRouters = 9;
|
|
|
|
|
m_Requests.ManageRequests ();
|
|
|
|
|
if(!i2p::context.IsHidden ())
|
|
|
|
|
{
|
|
|
|
|
numRouters = 800/numRouters;
|
|
|
|
|
if (numRouters < 1) numRouters = 1;
|
|
|
|
|
if (numRouters > 9) numRouters = 9;
|
|
|
|
|
Explore (numRouters);
|
|
|
|
|
}
|
|
|
|
|
lastExploratory = mts;
|
|
|
|
|
exploratoryIntervalVariance = rand () % NETDB_EXPLORATORY_INTERVAL_VARIANCE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -991,15 +993,18 @@ namespace data
|
|
|
|
|
auto dest = m_Requests.FindRequest (ident);
|
|
|
|
|
if (dest)
|
|
|
|
|
{
|
|
|
|
|
if (num > 0 || dest->GetNumExcludedPeers () < 3) // before 3-rd attempt might be just bad luck
|
|
|
|
|
if (!dest->IsExploratory () && (num > 0 || dest->GetNumExcludedPeers () < 3)) // before 3-rd attempt might be just bad luck
|
|
|
|
|
// try to send next requests
|
|
|
|
|
m_Requests.SendNextRequest (dest);
|
|
|
|
|
else
|
|
|
|
|
// no more requests for destination possible. delete it
|
|
|
|
|
m_Requests.RequestComplete (ident, nullptr);
|
|
|
|
|
}
|
|
|
|
|
else if(!m_FloodfillBootstrap)
|
|
|
|
|
LogPrint (eLogWarning, "NetDb: Requested destination for ", key, " not found");
|
|
|
|
|
else if (!m_FloodfillBootstrap)
|
|
|
|
|
{
|
|
|
|
|
LogPrint (eLogWarning, "NetDb: Unsolicited database search reply for ", key);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// try responses
|
|
|
|
|
for (int i = 0; i < num; i++)
|
|
|
|
@ -1138,9 +1143,9 @@ namespace data
|
|
|
|
|
excludedRouters.insert (exclude_ident);
|
|
|
|
|
exclude_ident += 32;
|
|
|
|
|
}
|
|
|
|
|
auto closestFloodfills = GetClosestFloodfills (ident, 3, excludedRouters, true);
|
|
|
|
|
auto closestFloodfills = GetClosestFloodfills (ident, 3, excludedRouters, false);
|
|
|
|
|
if (closestFloodfills.empty ())
|
|
|
|
|
LogPrint (eLogWarning, "NetDb: Requested ", key, " not found, ", numExcluded, " peers excluded");
|
|
|
|
|
LogPrint (eLogWarning, "NetDb: No more floodfills for ", key, " found. ", numExcluded, " peers excluded");
|
|
|
|
|
replyMsg = CreateDatabaseSearchReply (ident, closestFloodfills);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|