mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
don't drop router buffer if connected or being updated
This commit is contained in:
@@ -120,8 +120,8 @@ namespace data
|
|||||||
|
|
||||||
uint64_t lastManage = 0;
|
uint64_t lastManage = 0;
|
||||||
uint64_t lastProfilesCleanup = i2p::util::GetMonotonicMilliseconds (),
|
uint64_t lastProfilesCleanup = i2p::util::GetMonotonicMilliseconds (),
|
||||||
lastObsoleteProfilesCleanup = lastProfilesCleanup, lastApplingProfileUpdates = lastProfilesCleanup;
|
lastObsoleteProfilesCleanup = lastProfilesCleanup, lastApplyingProfileUpdates = lastProfilesCleanup;
|
||||||
int16_t profilesCleanupVariance = 0, obsoleteProfilesCleanVariance = 0, applingProfileUpdatesVariance = 0;
|
int16_t profilesCleanupVariance = 0, obsoleteProfilesCleanVariance = 0, applyingProfileUpdatesVariance = 0;
|
||||||
|
|
||||||
std::list<std::shared_ptr<const I2NPMessage> > msgs;
|
std::list<std::shared_ptr<const I2NPMessage> > msgs;
|
||||||
while (m_IsRunning)
|
while (m_IsRunning)
|
||||||
@@ -200,18 +200,18 @@ namespace data
|
|||||||
lastObsoleteProfilesCleanup = mts;
|
lastObsoleteProfilesCleanup = mts;
|
||||||
obsoleteProfilesCleanVariance = rand () % i2p::data::PEER_PROFILE_OBSOLETE_PROFILES_CLEAN_VARIANCE;
|
obsoleteProfilesCleanVariance = rand () % i2p::data::PEER_PROFILE_OBSOLETE_PROFILES_CLEAN_VARIANCE;
|
||||||
}
|
}
|
||||||
if (mts >= lastApplingProfileUpdates + i2p::data::PEER_PROFILE_APPLY_POSTPONED_TIMEOUT + applingProfileUpdatesVariance)
|
if (mts >= lastApplyingProfileUpdates + i2p::data::PEER_PROFILE_APPLY_POSTPONED_TIMEOUT + applyingProfileUpdatesVariance)
|
||||||
{
|
{
|
||||||
bool isAppling = m_ApplingProfileUpdates.valid ();
|
bool isApplying = m_ApplyingProfileUpdates.valid ();
|
||||||
if (isAppling && m_ApplingProfileUpdates.wait_for(std::chrono::seconds(0)) == std::future_status::ready) // still active?
|
if (isApplying && m_ApplyingProfileUpdates.wait_for(std::chrono::seconds(0)) == std::future_status::ready) // still active?
|
||||||
{
|
{
|
||||||
m_ApplingProfileUpdates.get ();
|
m_ApplyingProfileUpdates.get ();
|
||||||
isAppling = false;
|
isApplying = false;
|
||||||
}
|
}
|
||||||
if (!isAppling)
|
if (!isApplying)
|
||||||
m_ApplingProfileUpdates = i2p::data::FlushPostponedRouterProfileUpdates ();
|
m_ApplyingProfileUpdates = i2p::data::FlushPostponedRouterProfileUpdates ();
|
||||||
lastApplingProfileUpdates = mts;
|
lastApplyingProfileUpdates = mts;
|
||||||
applingProfileUpdatesVariance = rand () % i2p::data::PEER_PROFILE_APPLY_POSTPONED_TIMEOUT_VARIANCE;
|
applyingProfileUpdatesVariance = rand () % i2p::data::PEER_PROFILE_APPLY_POSTPONED_TIMEOUT_VARIANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception& ex)
|
catch (std::exception& ex)
|
||||||
@@ -674,10 +674,11 @@ namespace data
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> l(m_RouterInfosMutex); // possible collision between DeleteBuffer and Update
|
std::lock_guard<std::mutex> l(m_RouterInfosMutex); // possible collision between DeleteBuffer and Update
|
||||||
buffer = r->CopyBuffer ();
|
buffer = r->CopyBuffer ();
|
||||||
r->ScheduleBufferToDelete ();
|
|
||||||
}
|
}
|
||||||
|
if (!i2p::transport::transports.IsConnected (ident))
|
||||||
|
r->ScheduleBufferToDelete ();
|
||||||
if (buffer)
|
if (buffer)
|
||||||
saveToDisk.push_back(std::make_pair(ident.ToBase64 (), buffer));
|
saveToDisk.emplace_back(ident.ToBase64 (), buffer);
|
||||||
}
|
}
|
||||||
r->SetUpdated (false);
|
r->SetUpdated (false);
|
||||||
updatedCount++;
|
updatedCount++;
|
||||||
@@ -710,18 +711,15 @@ namespace data
|
|||||||
r->SetUnreachable (true);
|
r->SetUnreachable (true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// make router reachable back and don't delete buffer if connected now
|
// make router reachable back if connected now
|
||||||
if ((r->IsUnreachable () || r->IsBufferScheduledToDelete ()) && i2p::transport::transports.IsConnected (ident))
|
if (r->IsUnreachable () && i2p::transport::transports.IsConnected (ident))
|
||||||
{
|
|
||||||
r->SetUnreachable (false);
|
r->SetUnreachable (false);
|
||||||
r->CancelBufferToDelete ();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r->IsUnreachable ())
|
if (r->IsUnreachable ())
|
||||||
{
|
{
|
||||||
if (r->IsFloodfill ()) deletedFloodfillsCount++;
|
if (r->IsFloodfill ()) deletedFloodfillsCount++;
|
||||||
// delete RI file
|
// delete RI file
|
||||||
removeFromDisk.push_back (ident.ToBase64());
|
removeFromDisk.emplace_back (ident.ToBase64());
|
||||||
deletedCount++;
|
deletedCount++;
|
||||||
if (total - deletedCount < NETDB_MIN_ROUTERS) checkForExpiration = false;
|
if (total - deletedCount < NETDB_MIN_ROUTERS) checkForExpiration = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ namespace data
|
|||||||
std::shared_ptr<NetDbRequests> m_Requests;
|
std::shared_ptr<NetDbRequests> m_Requests;
|
||||||
|
|
||||||
bool m_PersistProfiles;
|
bool m_PersistProfiles;
|
||||||
std::future<void> m_SavingProfiles, m_DeletingProfiles, m_ApplingProfileUpdates, m_PersistingRouters;
|
std::future<void> m_SavingProfiles, m_DeletingProfiles, m_ApplyingProfileUpdates, m_PersistingRouters;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<const RouterInfo> > m_ExploratorySelection;
|
std::vector<std::shared_ptr<const RouterInfo> > m_ExploratorySelection;
|
||||||
uint64_t m_LastExploratorySelectionUpdateTime; // in monotonic seconds
|
uint64_t m_LastExploratorySelectionUpdateTime; // in monotonic seconds
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -1136,12 +1136,12 @@ namespace data
|
|||||||
|
|
||||||
void RouterInfo::UpdateBuffer (const uint8_t * buf, size_t len)
|
void RouterInfo::UpdateBuffer (const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
|
m_IsBufferScheduledToDelete = false;
|
||||||
if (!m_Buffer)
|
if (!m_Buffer)
|
||||||
m_Buffer = NewBuffer ();
|
m_Buffer = NewBuffer ();
|
||||||
if (len > m_Buffer->size ()) len = m_Buffer->size ();
|
if (len > m_Buffer->size ()) len = m_Buffer->size ();
|
||||||
memcpy (m_Buffer->data (), buf, len);
|
memcpy (m_Buffer->data (), buf, len);
|
||||||
m_Buffer->SetBufferLen (len);
|
m_Buffer->SetBufferLen (len);
|
||||||
m_IsBufferScheduledToDelete = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<RouterInfo::Buffer> RouterInfo::CopyBuffer () const
|
std::shared_ptr<RouterInfo::Buffer> RouterInfo::CopyBuffer () const
|
||||||
|
|||||||
Reference in New Issue
Block a user