|
|
@ -11,8 +11,8 @@ namespace data |
|
|
|
{ |
|
|
|
{ |
|
|
|
RouterProfile::RouterProfile (const IdentHash& identHash): |
|
|
|
RouterProfile::RouterProfile (const IdentHash& identHash): |
|
|
|
m_IdentHash (identHash), m_LastUpdateTime (boost::posix_time::second_clock::local_time()), |
|
|
|
m_IdentHash (identHash), m_LastUpdateTime (boost::posix_time::second_clock::local_time()), |
|
|
|
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0), |
|
|
|
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0), m_NumTunnelsNonReplied (0), |
|
|
|
m_NumTunnelsNonReplied (0) |
|
|
|
m_NumTimesTaken (0), m_NumTimesRejected (0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -33,10 +33,14 @@ namespace data |
|
|
|
participation.put (PEER_PROFILE_PARTICIPATION_AGREED, m_NumTunnelsAgreed); |
|
|
|
participation.put (PEER_PROFILE_PARTICIPATION_AGREED, m_NumTunnelsAgreed); |
|
|
|
participation.put (PEER_PROFILE_PARTICIPATION_DECLINED, m_NumTunnelsDeclined); |
|
|
|
participation.put (PEER_PROFILE_PARTICIPATION_DECLINED, m_NumTunnelsDeclined); |
|
|
|
participation.put (PEER_PROFILE_PARTICIPATION_NON_REPLIED, m_NumTunnelsNonReplied); |
|
|
|
participation.put (PEER_PROFILE_PARTICIPATION_NON_REPLIED, m_NumTunnelsNonReplied); |
|
|
|
|
|
|
|
boost::property_tree::ptree usage; |
|
|
|
|
|
|
|
usage.put (PEER_PROFILE_USAGE_TAKEN, m_NumTimesTaken); |
|
|
|
|
|
|
|
usage.put (PEER_PROFILE_USAGE_REJECTED, m_NumTimesRejected); |
|
|
|
// fill property tree
|
|
|
|
// fill property tree
|
|
|
|
boost::property_tree::ptree pt; |
|
|
|
boost::property_tree::ptree pt; |
|
|
|
pt.put (PEER_PROFILE_LAST_UPDATE_TIME, boost::posix_time::to_simple_string (m_LastUpdateTime)); |
|
|
|
pt.put (PEER_PROFILE_LAST_UPDATE_TIME, boost::posix_time::to_simple_string (m_LastUpdateTime)); |
|
|
|
pt.put_child (PEER_PROFILE_SECTION_PARTICIPATION, participation); |
|
|
|
pt.put_child (PEER_PROFILE_SECTION_PARTICIPATION, participation); |
|
|
|
|
|
|
|
pt.put_child (PEER_PROFILE_SECTION_USAGE, usage); |
|
|
|
|
|
|
|
|
|
|
|
// save to file
|
|
|
|
// save to file
|
|
|
|
auto path = i2p::util::filesystem::GetDefaultDataDir() / PEER_PROFILES_DIRECTORY; |
|
|
|
auto path = i2p::util::filesystem::GetDefaultDataDir() / PEER_PROFILES_DIRECTORY; |
|
|
@ -102,6 +106,10 @@ namespace data |
|
|
|
m_NumTunnelsAgreed = participations.get (PEER_PROFILE_PARTICIPATION_AGREED, 0); |
|
|
|
m_NumTunnelsAgreed = participations.get (PEER_PROFILE_PARTICIPATION_AGREED, 0); |
|
|
|
m_NumTunnelsDeclined = participations.get (PEER_PROFILE_PARTICIPATION_DECLINED, 0); |
|
|
|
m_NumTunnelsDeclined = participations.get (PEER_PROFILE_PARTICIPATION_DECLINED, 0); |
|
|
|
m_NumTunnelsNonReplied = participations.get (PEER_PROFILE_PARTICIPATION_NON_REPLIED, 0); |
|
|
|
m_NumTunnelsNonReplied = participations.get (PEER_PROFILE_PARTICIPATION_NON_REPLIED, 0); |
|
|
|
|
|
|
|
// read usage
|
|
|
|
|
|
|
|
auto usage = pt.get_child (PEER_PROFILE_SECTION_USAGE); |
|
|
|
|
|
|
|
m_NumTimesTaken = usage.get (PEER_PROFILE_USAGE_TAKEN, 0); |
|
|
|
|
|
|
|
m_NumTimesRejected = usage.get (PEER_PROFILE_USAGE_REJECTED, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
*this = RouterProfile (m_IdentHash); |
|
|
|
*this = RouterProfile (m_IdentHash); |
|
|
@ -128,27 +136,32 @@ namespace data |
|
|
|
UpdateTime (); |
|
|
|
UpdateTime (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool RouterProfile::IsLowPartcipationRate (uint32_t elapsedTime) const |
|
|
|
bool RouterProfile::IsLowPartcipationRate () const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (elapsedTime < 900) // if less than 15 minutes
|
|
|
|
return 4*m_NumTunnelsAgreed < m_NumTunnelsDeclined; // < 20% rate
|
|
|
|
return m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 50% rate
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return 3*m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 25% rate
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool RouterProfile::IsLowReplyRate (uint32_t elapsedTime) const |
|
|
|
bool RouterProfile::IsLowReplyRate () const |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto total = m_NumTunnelsAgreed + m_NumTunnelsDeclined; |
|
|
|
auto total = m_NumTunnelsAgreed + m_NumTunnelsDeclined; |
|
|
|
if (elapsedTime < 300) // if less than 5 minutes
|
|
|
|
return m_NumTunnelsNonReplied > 10*(total + 1); |
|
|
|
return m_NumTunnelsNonReplied > 5*(total + 1); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return !total && m_NumTunnelsNonReplied*15 > elapsedTime; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool RouterProfile::IsBad () const |
|
|
|
bool RouterProfile::IsBad () |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto elapsedTime = (GetTime () - m_LastUpdateTime).total_seconds (); |
|
|
|
auto elapsedTime = (GetTime () - m_LastUpdateTime).total_seconds (); |
|
|
|
return IsAlwaysDeclining () || IsLowPartcipationRate (elapsedTime) || IsLowReplyRate (elapsedTime); |
|
|
|
if (elapsedTime > 1800) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_NumTunnelsNonReplied = 0; // drop non-replied after 30 minutes of inactivity
|
|
|
|
|
|
|
|
if (elapsedTime > 14400) // drop agreed and declined after 4 hours of inactivity
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_NumTunnelsAgreed = 0; |
|
|
|
|
|
|
|
m_NumTunnelsDeclined = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
auto isBad = IsAlwaysDeclining () || IsLowPartcipationRate () || IsLowReplyRate (); |
|
|
|
|
|
|
|
if (isBad) m_NumTimesRejected++; else m_NumTimesTaken++; |
|
|
|
|
|
|
|
return isBad; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash) |
|
|
|
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash) |
|
|
|