save only non-default peer profile

This commit is contained in:
weko 2023-05-05 21:30:44 +00:00
parent b6de474fda
commit 7646147ed2
3 changed files with 17 additions and 5 deletions

View File

@ -35,7 +35,7 @@ namespace data
m_LastUpdateTime (GetTime ()), m_IsUpdated (false),
m_LastDeclineTime (0), m_LastUnreachableTime (0),
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0), m_NumTunnelsNonReplied (0),
m_NumTimesTaken (0), m_NumTimesRejected (0), m_HasConnected (false)
m_NumTimesTaken (0), m_NumTimesRejected (0), m_HasConnected (false), m_IsUseful (0)
{
}
@ -145,22 +145,25 @@ namespace data
UpdateTime ();
if (ret > 0)
{
m_NumTunnelsDeclined++;
if (++m_NumTunnelsDeclined > PEER_PROFILE_USEFUL_THRESHOLD) m_IsUseful = true;
m_LastDeclineTime = i2p::util::GetSecondsSinceEpoch ();
}
else
{
m_NumTunnelsAgreed++;
if (++m_NumTunnelsAgreed > PEER_PROFILE_USEFUL_THRESHOLD) m_IsUseful = true;
m_LastDeclineTime = 0;
}
}
void RouterProfile::TunnelNonReplied ()
{
m_NumTunnelsNonReplied++;
if (++m_NumTunnelsNonReplied > PEER_PROFILE_USEFUL_THRESHOLD) m_IsUseful = true;
UpdateTime ();
if (m_NumTunnelsNonReplied > 2*m_NumTunnelsAgreed && m_NumTunnelsNonReplied > 3)
{
m_LastDeclineTime = i2p::util::GetSecondsSinceEpoch ();
m_IsUseful = true;
}
}
void RouterProfile::Unreachable ()
@ -206,6 +209,7 @@ namespace data
m_NumTunnelsAgreed = 0;
m_NumTunnelsDeclined = 0;
m_NumTunnelsNonReplied = 0;
m_IsUseful = false;
isBad = false;
}
if (isBad) m_NumTimesRejected++; else m_NumTimesTaken++;
@ -275,7 +279,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);
}

View File

@ -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
{
@ -59,6 +60,7 @@ namespace data
boost::posix_time::ptime GetLastUpdateTime () const { return m_LastUpdateTime; };
bool IsUpdated () const { return m_IsUpdated; };
bool IsUseful() const { return m_IsUseful; };
private:
@ -82,6 +84,8 @@ namespace data
uint32_t m_NumTimesTaken;
uint32_t m_NumTimesRejected;
bool m_HasConnected; // incoming connection received
// is need to be saved
bool m_IsUseful;
};
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash);

View File

@ -363,7 +363,11 @@ namespace data
if (!s) return;
}
<<<<<<< HEAD
if ((address->s[31] & 0x80) || !i2p::data::CheckStaticKey(address->s, GetIdentHash()))
=======
if (!i2p::data::CheckStaticKey(address->s, GetIdentHash()))
>>>>>>> 146e446b (save only non-default peer profile)
continue; // skip address
if (address->transportStyle == eTransportNTCP2)