Browse Source

delete obsolete profiles

pull/189/head
orignal 10 years ago
parent
commit
128a8f3b48
  1. 27
      NetDb.cpp
  2. 31
      Profiling.cpp
  3. 3
      Profiling.h

27
NetDb.cpp

@ -65,19 +65,24 @@ namespace data
void NetDb::Stop () void NetDb::Stop ()
{ {
for (auto it: m_RouterInfos) if (m_IsRunning)
it.second->SaveProfile ();
m_RouterInfos.clear ();
if (m_Thread)
{ {
m_IsRunning = false; for (auto it: m_RouterInfos)
m_Queue.WakeUp (); it.second->SaveProfile ();
m_Thread->join (); DeleteObsoleteProfiles ();
delete m_Thread; m_RouterInfos.clear ();
m_Thread = 0; 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 ();
} }
m_LeaseSets.clear();
m_Requests.Stop ();
} }
void NetDb::Run () void NetDb::Run ()

31
Profiling.cpp

@ -95,7 +95,7 @@ namespace data
auto t = pt.get (PEER_PROFILE_LAST_UPDATE_TIME, ""); auto t = pt.get (PEER_PROFILE_LAST_UPDATE_TIME, "");
if (t.length () > 0) if (t.length () > 0)
m_LastUpdateTime = boost::posix_time::time_from_string (t); 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 // read participations
auto participations = pt.get_child (PEER_PROFILE_SECTION_PARTICIPATION); 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 if ((GetTime () - m_LastUpdateTime).total_seconds () < 900) // if less than 15 minutes
return m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 50% rate return m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 50% rate
else else
return 4*m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 20% rate return 3*m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 25% rate
} }
bool RouterProfile::IsBad () const bool RouterProfile::IsBad () const
@ -147,5 +147,32 @@ namespace data
profile->Load (); // if possible profile->Load (); // if possible
return profile; 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");
}
} }
} }

3
Profiling.h

@ -19,6 +19,8 @@ namespace data
const char PEER_PROFILE_PARTICIPATION_DECLINED[] = "declined"; const char PEER_PROFILE_PARTICIPATION_DECLINED[] = "declined";
const char PEER_PROFILE_PARTICIPATION_NON_REPLIED[] = "nonreplied"; const char PEER_PROFILE_PARTICIPATION_NON_REPLIED[] = "nonreplied";
const int PEER_PROFILE_EXPIRATION_TIMEOUT = 72; // in hours (3 days)
class RouterProfile class RouterProfile
{ {
public: public:
@ -54,6 +56,7 @@ namespace data
}; };
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash); std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash);
void DeleteObsoleteProfiles ();
} }
} }

Loading…
Cancel
Save