mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-23 12:17:37 +01:00
Periodic obsolete profiles cleanup
This commit is contained in:
parent
3fd69311cb
commit
6c79ccd1dc
3 changed files with 24 additions and 1 deletions
|
@ -82,7 +82,7 @@ namespace data
|
|||
|
||||
void NetDb::Run ()
|
||||
{
|
||||
uint32_t lastSave = 0, lastLeasesetsManage = 0, lastPublish = 0, lastExploratory = 0, lastManageRequest = 0, lastDestinationCleanup = 0;
|
||||
uint32_t lastSave = 0, lastLeasesetsManage = 0, lastPublish = 0, lastExploratory = 0, lastManageRequest = 0, lastDestinationCleanup = 0, lastProfilesCleanup = 0;
|
||||
while (m_IsRunning)
|
||||
{
|
||||
try
|
||||
|
@ -171,6 +171,11 @@ namespace data
|
|||
lastExploratory = ts;
|
||||
}
|
||||
}
|
||||
if (ts - lastProfilesCleanup >= PEER_PROFILE_EXPIRATION_TIMEOUT * 3600)
|
||||
{
|
||||
RemoveObsoleteProfiles ();
|
||||
lastProfilesCleanup = ts;
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
|
@ -607,6 +612,21 @@ namespace data
|
|||
}
|
||||
}
|
||||
|
||||
void NetDb::RemoveObsoleteProfiles ()
|
||||
{
|
||||
DeleteObsoleteProfiles ();
|
||||
auto now = boost::posix_time::second_clock::local_time ();
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m_UnsavedProfilesMutex);
|
||||
for (auto it = m_UnsavedProfiles.begin (); it != m_UnsavedProfiles.end ();)
|
||||
if ((now - it->second->GetLastUpdateTime ()).hours () >= PEER_PROFILE_EXPIRATION_TIMEOUT)
|
||||
it = m_UnsavedProfiles.erase (it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
LogPrint (eLogInfo, "NetDb: obsolete profiles were removed");
|
||||
}
|
||||
|
||||
void NetDb::RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete)
|
||||
{
|
||||
auto dest = m_Requests.CreateRequest (destination, false, requestComplete); // non-exploratory
|
||||
|
|
|
@ -110,6 +110,7 @@ namespace data
|
|||
bool LoadRouterInfo (const std::string & path);
|
||||
void SaveUpdated ();
|
||||
void RemoveExpired ();
|
||||
void RemoveObsoleteProfiles ();
|
||||
void Run (); // exploratory thread
|
||||
void Explore (int numDestinations);
|
||||
void Publish ();
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace data
|
|||
RouterProfile ();
|
||||
RouterProfile& operator= (const RouterProfile& ) = default;
|
||||
|
||||
boost::posix_time::ptime GetLastUpdateTime () const { return m_LastUpdateTime; };
|
||||
|
||||
void Save (const IdentHash& identHash);
|
||||
void Load (const IdentHash& identHash);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue