mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
delete obsolete profiles
This commit is contained in:
parent
1839b85d97
commit
128a8f3b48
29
NetDb.cpp
29
NetDb.cpp
@ -65,19 +65,24 @@ namespace data
|
||||
|
||||
void NetDb::Stop ()
|
||||
{
|
||||
for (auto it: m_RouterInfos)
|
||||
it.second->SaveProfile ();
|
||||
m_RouterInfos.clear ();
|
||||
if (m_Thread)
|
||||
if (m_IsRunning)
|
||||
{
|
||||
m_IsRunning = false;
|
||||
m_Queue.WakeUp ();
|
||||
m_Thread->join ();
|
||||
delete m_Thread;
|
||||
m_Thread = 0;
|
||||
}
|
||||
m_LeaseSets.clear();
|
||||
m_Requests.Stop ();
|
||||
for (auto it: m_RouterInfos)
|
||||
it.second->SaveProfile ();
|
||||
DeleteObsoleteProfiles ();
|
||||
m_RouterInfos.clear ();
|
||||
m_Floodfills.clear ();
|
||||
if (m_Thread)
|
||||
{
|
||||
m_IsRunning = false;
|
||||
m_Queue.WakeUp ();
|
||||
m_Thread->join ();
|
||||
delete m_Thread;
|
||||
m_Thread = 0;
|
||||
}
|
||||
m_LeaseSets.clear();
|
||||
m_Requests.Stop ();
|
||||
}
|
||||
}
|
||||
|
||||
void NetDb::Run ()
|
||||
|
@ -95,7 +95,7 @@ namespace data
|
||||
auto t = pt.get (PEER_PROFILE_LAST_UPDATE_TIME, "");
|
||||
if (t.length () > 0)
|
||||
m_LastUpdateTime = boost::posix_time::time_from_string (t);
|
||||
if ((GetTime () - m_LastUpdateTime).hours () < 72) // profile becomes obsolete after 3 days of inactivity
|
||||
if ((GetTime () - m_LastUpdateTime).hours () < PEER_PROFILE_EXPIRATION_TIMEOUT)
|
||||
{
|
||||
// read participations
|
||||
auto participations = pt.get_child (PEER_PROFILE_SECTION_PARTICIPATION);
|
||||
@ -133,7 +133,7 @@ namespace data
|
||||
if ((GetTime () - m_LastUpdateTime).total_seconds () < 900) // if less than 15 minutes
|
||||
return m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 50% rate
|
||||
else
|
||||
return 4*m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 20% rate
|
||||
return 3*m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 25% rate
|
||||
}
|
||||
|
||||
bool RouterProfile::IsBad () const
|
||||
@ -147,5 +147,32 @@ namespace data
|
||||
profile->Load (); // if possible
|
||||
return profile;
|
||||
}
|
||||
|
||||
void DeleteObsoleteProfiles ()
|
||||
{
|
||||
int num = 0;
|
||||
auto ts = boost::posix_time::second_clock::local_time();
|
||||
boost::filesystem::path p (i2p::util::filesystem::GetDataDir()/PEER_PROFILES_DIRECTORY);
|
||||
if (boost::filesystem::exists (p))
|
||||
{
|
||||
boost::filesystem::directory_iterator end;
|
||||
for (boost::filesystem::directory_iterator it (p); it != end; ++it)
|
||||
{
|
||||
if (boost::filesystem::is_directory (it->status()))
|
||||
{
|
||||
for (boost::filesystem::directory_iterator it1 (it->path ()); it1 != end; ++it1)
|
||||
{
|
||||
auto lastModified = boost::posix_time::from_time_t (boost::filesystem::last_write_time (it1->path ()));
|
||||
if ((ts - lastModified).hours () >= PEER_PROFILE_EXPIRATION_TIMEOUT)
|
||||
{
|
||||
boost::filesystem::remove (it1->path ());
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LogPrint (eLogInfo, num, " obsolete profiles deleted");
|
||||
}
|
||||
}
|
||||
}
|
@ -18,6 +18,8 @@ namespace data
|
||||
const char PEER_PROFILE_PARTICIPATION_AGREED[] = "agreed";
|
||||
const char PEER_PROFILE_PARTICIPATION_DECLINED[] = "declined";
|
||||
const char PEER_PROFILE_PARTICIPATION_NON_REPLIED[] = "nonreplied";
|
||||
|
||||
const int PEER_PROFILE_EXPIRATION_TIMEOUT = 72; // in hours (3 days)
|
||||
|
||||
class RouterProfile
|
||||
{
|
||||
@ -54,6 +56,7 @@ namespace data
|
||||
};
|
||||
|
||||
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash);
|
||||
void DeleteObsoleteProfiles ();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user