Skip to content

Commit

Permalink
don't delete actively use profile. Last persist time
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jan 28, 2025
1 parent d411da4 commit 35f7bd5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
22 changes: 14 additions & 8 deletions libi2pd/Profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace data

RouterProfile::RouterProfile ():
m_IsUpdated (false), m_LastDeclineTime (0), m_LastUnreachableTime (0),
m_LastUpdateTime (i2p::util::GetSecondsSinceEpoch ()),
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0), m_NumTunnelsNonReplied (0),
m_NumTimesTaken (0), m_NumTimesRejected (0), m_HasConnected (false),
m_IsDuplicated (false)
m_LastUpdateTime (i2p::util::GetSecondsSinceEpoch ()), m_LastAccessTime (0),
m_LastPersistTime (0), m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0),
m_NumTunnelsNonReplied (0),m_NumTimesTaken (0), m_NumTimesRejected (0),
m_HasConnected (false), m_IsDuplicated (false)
{
}

Expand Down Expand Up @@ -80,6 +80,7 @@ namespace data

void RouterProfile::Load (const IdentHash& identHash)
{
m_IsUpdated = false;
std::string ident = identHash.ToBase64 ();
std::string path = g_ProfilesStorage.Path(ident);
boost::property_tree::ptree pt;
Expand Down Expand Up @@ -257,7 +258,10 @@ namespace data
std::unique_lock<std::mutex> l(g_ProfilesMutex);
auto it = g_Profiles.find (identHash);
if (it != g_Profiles.end ())
{
it->second->SetLastAccessTime (i2p::util::GetSecondsSinceEpoch ());
return it->second;
}
}
auto profile = netdb.NewRouterProfile ();
profile->Load (identHash); // if possible
Expand Down Expand Up @@ -295,12 +299,14 @@ namespace data
std::lock_guard<std::mutex> l(g_ProfilesMutex);
for (auto it = g_Profiles.begin (); it != g_Profiles.end ();)
{
if (ts - it->second->GetLastUpdateTime () > PEER_PROFILE_PERSIST_INTERVAL)
if (it->second->IsUpdated () && ts > it->second->GetLastPersistTime () + PEER_PROFILE_PERSIST_INTERVAL)
{
if (it->second->IsUpdated ())
tmp.push_back (std::make_pair (it->first, it->second));
tmp.push_back (std::make_pair (it->first, it->second));
it->second->SetLastPersistTime (ts);
it->second->SetUpdated (false);
}
if (!it->second->IsUpdated () && ts > std::max (it->second->GetLastUpdateTime (), it->second->GetLastAccessTime ()) + PEER_PROFILE_PERSIST_INTERVAL)
it = g_Profiles.erase (it);
}
else
it++;
}
Expand Down
8 changes: 7 additions & 1 deletion libi2pd/Profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ namespace data

uint64_t GetLastUpdateTime () const { return m_LastUpdateTime; };
bool IsUpdated () const { return m_IsUpdated; };
void SetUpdated (bool updated) { m_IsUpdated = updated; }
uint64_t GetLastAccessTime () const { return m_LastAccessTime; };
void SetLastAccessTime (uint64_t ts) { m_LastAccessTime = ts; };
uint64_t GetLastPersistTime () const { return m_LastPersistTime; };
void SetLastPersistTime (uint64_t ts) { m_LastPersistTime = ts; };

bool IsUseful() const;
bool IsDuplicated () const { return m_IsDuplicated; };
Expand All @@ -91,7 +96,8 @@ namespace data
private:

bool m_IsUpdated;
uint64_t m_LastDeclineTime, m_LastUnreachableTime, m_LastUpdateTime; // in seconds
uint64_t m_LastDeclineTime, m_LastUnreachableTime, m_LastUpdateTime,
m_LastAccessTime, m_LastPersistTime; // in seconds
// participation
uint32_t m_NumTunnelsAgreed;
uint32_t m_NumTunnelsDeclined;
Expand Down

0 comments on commit 35f7bd5

Please sign in to comment.