Compare commits

...

3 Commits

@ -107,7 +107,7 @@ namespace data
i2p::util::SetThreadName("NetDB");
uint64_t lastManage = 0, lastExploratory = 0, lastManageRequest = 0;
uint64_t lastProfilesCleanup = i2p::util::GetSecondsSinceEpoch ();
uint64_t lastProfilesCleanup = i2p::util::GetMonotonicMilliseconds ();
int16_t profilesCleanupVariance = 0;
while (m_IsRunning)
@ -148,41 +148,43 @@ namespace data
if (!m_IsRunning) break;
if (!i2p::transport::transports.IsOnline ()) continue; // don't manage netdb when offline
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
if (ts - lastManageRequest >= MANAGE_REQUESTS_INTERVAL || ts + MANAGE_REQUESTS_INTERVAL < lastManageRequest) // manage requests every 15 seconds
uint64_t mts = i2p::util::GetMonotonicMilliseconds ();
if (mts >= lastManageRequest + MANAGE_REQUESTS_INTERVAL*1000)
{
m_Requests.ManageRequests ();
lastManageRequest = ts;
if (lastManageRequest || i2p::tunnel::tunnels.GetExploratoryPool ()) // expolratory pool is ready?
{
m_Requests.ManageRequests ();
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)
{
ManageRouterInfos ();
ManageLeaseSets ();
}
lastManage = ts;
lastManage = mts;
}
if (ts - lastProfilesCleanup >= (uint64_t)(i2p::data::PEER_PROFILE_AUTOCLEAN_TIMEOUT + profilesCleanupVariance) ||
ts + i2p::data::PEER_PROFILE_AUTOCLEAN_TIMEOUT < lastProfilesCleanup)
if (mts >= lastProfilesCleanup + (uint64_t)(i2p::data::PEER_PROFILE_AUTOCLEAN_TIMEOUT + profilesCleanupVariance)*1000)
{
m_RouterProfilesPool.CleanUpMt ();
if (m_PersistProfiles) PersistProfiles ();
DeleteObsoleteProfiles ();
lastProfilesCleanup = ts;
lastProfilesCleanup = mts;
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 ();
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 || ts - lastExploratory >= 90)
if (numRouters < 2500 || mts >= lastExploratory + 90000) // 90 seconds
{
numRouters = 800/numRouters;
if (numRouters < 1) numRouters = 1;
@ -190,7 +192,7 @@ namespace data
m_Requests.ManageRequests ();
if(!i2p::context.IsHidden ())
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<const i2p::tunnel::InboundTunnel> replyTunnel)
{
std::lock_guard<std::mutex> l (m_ExcludedPeerstMutex);
std::shared_ptr<I2NPMessage> msg;
if(replyTunnel)
msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination,
@ -53,8 +54,15 @@ namespace data
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 ()
{
std::lock_guard<std::mutex> l (m_ExcludedPeerstMutex);
m_ExcludedPeers.clear ();
}
@ -199,22 +207,30 @@ namespace data
else
{
auto pool = i2p::tunnel::tunnels.GetExploratoryPool ();
auto outbound = pool->GetNextOutboundTunnel ();
auto inbound = pool->GetNextInboundTunnel ();
if (nextFloodfill && outbound && inbound)
{
LogPrint (eLogDebug, "NetDbReq: Try ", dest->GetDestination ().ToBase64 (), " at ", count, " floodfill ", nextFloodfill->GetIdentHash ().ToBase64 (), " through tunnels");
auto msg = dest->CreateRequestMessage (nextFloodfill, inbound);
msg->onDrop = [this, dest]() { if (dest->IsActive ()) this->SendNextRequest (dest); };
outbound->SendTunnelDataMsgTo (nextFloodfill->GetIdentHash (), 0,
i2p::garlic::WrapECIESX25519MessageForRouter (msg, nextFloodfill->GetIdentity ()->GetEncryptionPublicKey ()));
if (pool)
{
auto outbound = pool->GetNextOutboundTunnel ();
auto inbound = pool->GetNextInboundTunnel ();
if (nextFloodfill && outbound && inbound)
{
LogPrint (eLogDebug, "NetDbReq: Try ", dest->GetDestination ().ToBase64 (), " at ", count, " floodfill ", nextFloodfill->GetIdentHash ().ToBase64 (), " through tunnels");
auto msg = dest->CreateRequestMessage (nextFloodfill, inbound);
msg->onDrop = [this, dest]() { if (dest->IsActive ()) this->SendNextRequest (dest); };
outbound->SendTunnelDataMsgTo (nextFloodfill->GetIdentHash (), 0,
i2p::garlic::WrapECIESX25519MessageForRouter (msg, nextFloodfill->GetIdentity ()->GetEncryptionPublicKey ()));
}
else
{
ret = false;
if (!inbound) LogPrint (eLogWarning, "NetDbReq: No inbound tunnels");
if (!outbound) LogPrint (eLogWarning, "NetDbReq: No outbound tunnels");
}
}
else
{
ret = false;
if (!inbound) LogPrint (eLogWarning, "NetDbReq: No inbound tunnels");
if (!outbound) LogPrint (eLogWarning, "NetDbReq: No outbound tunnels");
}
LogPrint (eLogWarning, "NetDbReq: Exploratory pool is not ready");
}
}
}
else

@ -36,12 +36,12 @@ namespace data
const IdentHash& GetDestination () const { return m_Destination; };
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 ();
bool IsExploratory () const { return m_IsExploratory; };
bool IsDirect () const { return m_IsDirect; };
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 GetLastRequestTime () const { return m_LastRequestTime; };
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;
bool m_IsExploratory, m_IsDirect, m_IsActive;
mutable std::mutex m_ExcludedPeerstMutex;
std::set<IdentHash> m_ExcludedPeers;
uint64_t m_CreationTime, m_LastRequestTime; // in seconds
RequestComplete m_RequestComplete;

Loading…
Cancel
Save