Compare commits

...

3 Commits

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

@ -31,6 +31,7 @@ namespace data
std::shared_ptr<I2NPMessage> RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router, std::shared_ptr<I2NPMessage> RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router,
std::shared_ptr<const i2p::tunnel::InboundTunnel> replyTunnel) std::shared_ptr<const i2p::tunnel::InboundTunnel> replyTunnel)
{ {
std::lock_guard<std::mutex> l (m_ExcludedPeerstMutex);
std::shared_ptr<I2NPMessage> msg; std::shared_ptr<I2NPMessage> msg;
if(replyTunnel) if(replyTunnel)
msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination, msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination,
@ -53,8 +54,15 @@ namespace data
return msg; return msg;
} }
bool RequestedDestination::IsExcluded (const IdentHash& ident) const
{
std::lock_guard<std::mutex> l (m_ExcludedPeerstMutex);
return m_ExcludedPeers.count (ident);
}
void RequestedDestination::ClearExcludedPeers () void RequestedDestination::ClearExcludedPeers ()
{ {
std::lock_guard<std::mutex> l (m_ExcludedPeerstMutex);
m_ExcludedPeers.clear (); m_ExcludedPeers.clear ();
} }
@ -199,6 +207,8 @@ namespace data
else else
{ {
auto pool = i2p::tunnel::tunnels.GetExploratoryPool (); auto pool = i2p::tunnel::tunnels.GetExploratoryPool ();
if (pool)
{
auto outbound = pool->GetNextOutboundTunnel (); auto outbound = pool->GetNextOutboundTunnel ();
auto inbound = pool->GetNextInboundTunnel (); auto inbound = pool->GetNextInboundTunnel ();
if (nextFloodfill && outbound && inbound) if (nextFloodfill && outbound && inbound)
@ -216,6 +226,12 @@ namespace data
if (!outbound) LogPrint (eLogWarning, "NetDbReq: No outbound tunnels"); if (!outbound) LogPrint (eLogWarning, "NetDbReq: No outbound tunnels");
} }
} }
else
{
ret = false;
LogPrint (eLogWarning, "NetDbReq: Exploratory pool is not ready");
}
}
} }
else else
{ {

@ -36,12 +36,12 @@ namespace data
const IdentHash& GetDestination () const { return m_Destination; }; const IdentHash& GetDestination () const { return m_Destination; };
int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); }; int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); };
const std::set<IdentHash>& GetExcludedPeers () { return m_ExcludedPeers; }; const std::set<IdentHash>& GetExcludedPeers () const { return m_ExcludedPeers; };
void ClearExcludedPeers (); void ClearExcludedPeers ();
bool IsExploratory () const { return m_IsExploratory; }; bool IsExploratory () const { return m_IsExploratory; };
bool IsDirect () const { return m_IsDirect; }; bool IsDirect () const { return m_IsDirect; };
bool IsActive () const { return m_IsActive; }; bool IsActive () const { return m_IsActive; };
bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); }; bool IsExcluded (const IdentHash& ident) const;
uint64_t GetCreationTime () const { return m_CreationTime; }; uint64_t GetCreationTime () const { return m_CreationTime; };
uint64_t GetLastRequestTime () const { return m_LastRequestTime; }; uint64_t GetLastRequestTime () const { return m_LastRequestTime; };
std::shared_ptr<I2NPMessage> CreateRequestMessage (std::shared_ptr<const RouterInfo>, std::shared_ptr<const i2p::tunnel::InboundTunnel> replyTunnel); std::shared_ptr<I2NPMessage> CreateRequestMessage (std::shared_ptr<const RouterInfo>, std::shared_ptr<const i2p::tunnel::InboundTunnel> replyTunnel);
@ -57,6 +57,7 @@ namespace data
IdentHash m_Destination; IdentHash m_Destination;
bool m_IsExploratory, m_IsDirect, m_IsActive; bool m_IsExploratory, m_IsDirect, m_IsActive;
mutable std::mutex m_ExcludedPeerstMutex;
std::set<IdentHash> m_ExcludedPeers; std::set<IdentHash> m_ExcludedPeers;
uint64_t m_CreationTime, m_LastRequestTime; // in seconds uint64_t m_CreationTime, m_LastRequestTime; // in seconds
RequestComplete m_RequestComplete; RequestComplete m_RequestComplete;

Loading…
Cancel
Save