mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-10 11:28:27 +01:00
save only non-default peer profile
This commit is contained in:
parent
b6de474fda
commit
7646147ed2
3 changed files with 17 additions and 5 deletions
|
@ -35,7 +35,7 @@ namespace data
|
||||||
m_LastUpdateTime (GetTime ()), m_IsUpdated (false),
|
m_LastUpdateTime (GetTime ()), m_IsUpdated (false),
|
||||||
m_LastDeclineTime (0), m_LastUnreachableTime (0),
|
m_LastDeclineTime (0), m_LastUnreachableTime (0),
|
||||||
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0), m_NumTunnelsNonReplied (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 ();
|
UpdateTime ();
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
m_NumTunnelsDeclined++;
|
if (++m_NumTunnelsDeclined > PEER_PROFILE_USEFUL_THRESHOLD) m_IsUseful = true;
|
||||||
m_LastDeclineTime = i2p::util::GetSecondsSinceEpoch ();
|
m_LastDeclineTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_NumTunnelsAgreed++;
|
if (++m_NumTunnelsAgreed > PEER_PROFILE_USEFUL_THRESHOLD) m_IsUseful = true;
|
||||||
m_LastDeclineTime = 0;
|
m_LastDeclineTime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterProfile::TunnelNonReplied ()
|
void RouterProfile::TunnelNonReplied ()
|
||||||
{
|
{
|
||||||
m_NumTunnelsNonReplied++;
|
if (++m_NumTunnelsNonReplied > PEER_PROFILE_USEFUL_THRESHOLD) m_IsUseful = true;
|
||||||
UpdateTime ();
|
UpdateTime ();
|
||||||
if (m_NumTunnelsNonReplied > 2*m_NumTunnelsAgreed && m_NumTunnelsNonReplied > 3)
|
if (m_NumTunnelsNonReplied > 2*m_NumTunnelsAgreed && m_NumTunnelsNonReplied > 3)
|
||||||
|
{
|
||||||
m_LastDeclineTime = i2p::util::GetSecondsSinceEpoch ();
|
m_LastDeclineTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
|
m_IsUseful = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterProfile::Unreachable ()
|
void RouterProfile::Unreachable ()
|
||||||
|
@ -206,6 +209,7 @@ namespace data
|
||||||
m_NumTunnelsAgreed = 0;
|
m_NumTunnelsAgreed = 0;
|
||||||
m_NumTunnelsDeclined = 0;
|
m_NumTunnelsDeclined = 0;
|
||||||
m_NumTunnelsNonReplied = 0;
|
m_NumTunnelsNonReplied = 0;
|
||||||
|
m_IsUseful = false;
|
||||||
isBad = false;
|
isBad = false;
|
||||||
}
|
}
|
||||||
if (isBad) m_NumTimesRejected++; else m_NumTimesTaken++;
|
if (isBad) m_NumTimesRejected++; else m_NumTimesTaken++;
|
||||||
|
@ -275,7 +279,7 @@ namespace data
|
||||||
}
|
}
|
||||||
auto ts = GetTime ();
|
auto ts = GetTime ();
|
||||||
for (auto& it: tmp)
|
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);
|
it.second->Save (it.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ namespace data
|
||||||
const int PEER_PROFILE_DECLINED_RECENTLY_INTERVAL = 150; // in seconds (2.5 minutes)
|
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_PERSIST_INTERVAL = 3300; // in seconds (55 minutes)
|
||||||
const int PEER_PROFILE_UNREACHABLE_INTERVAL = 2*3600; // on seconds (2 hours)
|
const int PEER_PROFILE_UNREACHABLE_INTERVAL = 2*3600; // on seconds (2 hours)
|
||||||
|
const int PEER_PROFILE_USEFUL_THRESHOLD = 3;
|
||||||
|
|
||||||
class RouterProfile
|
class RouterProfile
|
||||||
{
|
{
|
||||||
|
@ -59,6 +60,7 @@ namespace data
|
||||||
|
|
||||||
boost::posix_time::ptime GetLastUpdateTime () const { return m_LastUpdateTime; };
|
boost::posix_time::ptime GetLastUpdateTime () const { return m_LastUpdateTime; };
|
||||||
bool IsUpdated () const { return m_IsUpdated; };
|
bool IsUpdated () const { return m_IsUpdated; };
|
||||||
|
bool IsUseful() const { return m_IsUseful; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -82,6 +84,8 @@ namespace data
|
||||||
uint32_t m_NumTimesTaken;
|
uint32_t m_NumTimesTaken;
|
||||||
uint32_t m_NumTimesRejected;
|
uint32_t m_NumTimesRejected;
|
||||||
bool m_HasConnected; // incoming connection received
|
bool m_HasConnected; // incoming connection received
|
||||||
|
// is need to be saved
|
||||||
|
bool m_IsUseful;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash);
|
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash);
|
||||||
|
|
|
@ -363,7 +363,11 @@ namespace data
|
||||||
if (!s) return;
|
if (!s) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
if ((address->s[31] & 0x80) || !i2p::data::CheckStaticKey(address->s, GetIdentHash()))
|
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
|
continue; // skip address
|
||||||
|
|
||||||
if (address->transportStyle == eTransportNTCP2)
|
if (address->transportStyle == eTransportNTCP2)
|
||||||
|
|
Loading…
Add table
Reference in a new issue