Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not save useless peer profiles #1925

Merged
merged 6 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions libi2pd/Profiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,19 @@ namespace data
}
else
{
m_NumTunnelsAgreed++;
m_NumTunnelsAgreed++;
m_LastDeclineTime = 0;
}
}

void RouterProfile::TunnelNonReplied ()
{
m_NumTunnelsNonReplied++;
m_NumTunnelsNonReplied++;
UpdateTime ();
if (m_NumTunnelsNonReplied > 2*m_NumTunnelsAgreed && m_NumTunnelsNonReplied > 3)
{
m_LastDeclineTime = i2p::util::GetSecondsSinceEpoch ();
}
}

void RouterProfile::Unreachable ()
Expand Down Expand Up @@ -221,6 +223,15 @@ namespace data
m_LastUnreachableTime = 0;
return (bool)m_LastUnreachableTime;
}

bool RouterProfile::IsUseful() const {
return
m_NumTunnelsAgreed >= PEER_PROFILE_USEFUL_THRESHOLD ||
m_NumTunnelsDeclined >= PEER_PROFILE_USEFUL_THRESHOLD ||
m_NumTunnelsNonReplied >= PEER_PROFILE_USEFUL_THRESHOLD ||
m_HasConnected;
}


std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash)
{
Expand Down Expand Up @@ -275,7 +286,7 @@ namespace data
}
auto ts = GetTime ();
for (auto& it: tmp)
if (it.second->IsUpdated () && (ts - it.second->GetLastUpdateTime ()).total_seconds () < PEER_PROFILE_EXPIRATION_TIMEOUT*3600)
if (it.second->IsUseful() && it.second->IsUpdated () && (ts - it.second->GetLastUpdateTime ()).total_seconds () < PEER_PROFILE_EXPIRATION_TIMEOUT*3600)
it.second->Save (it.first);
}

Expand Down
3 changes: 3 additions & 0 deletions libi2pd/Profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace data
const int PEER_PROFILE_DECLINED_RECENTLY_INTERVAL = 150; // in seconds (2.5 minutes)
const int PEER_PROFILE_PERSIST_INTERVAL = 3300; // in seconds (55 minutes)
const int PEER_PROFILE_UNREACHABLE_INTERVAL = 2*3600; // on seconds (2 hours)
const int PEER_PROFILE_USEFUL_THRESHOLD = 3;

class RouterProfile
{
Expand All @@ -60,6 +61,8 @@ namespace data
boost::posix_time::ptime GetLastUpdateTime () const { return m_LastUpdateTime; };
bool IsUpdated () const { return m_IsUpdated; };

bool IsUseful() const;

private:

void UpdateTime ();
Expand Down