Browse Source

always check profile for peer selection

pull/189/head
orignal 10 years ago
parent
commit
76c54ffdef
  1. 3
      NetDb.cpp
  2. 16
      Profiling.cpp
  3. 4
      Profiling.h
  4. 5
      TunnelPool.cpp

3
NetDb.cpp

@ -912,7 +912,8 @@ namespace data
{ {
if (i >= ind) if (i >= ind)
{ {
if (!it.second->IsUnreachable () && filter (it.second)) if (!it.second->IsUnreachable () && filter (it.second) &&
(j || !it.second->GetProfile ()->IsBad ()))
return it.second; return it.second;
} }
else else

16
Profiling.cpp

@ -128,17 +128,27 @@ namespace data
UpdateTime (); UpdateTime ();
} }
bool RouterProfile::IsLowPartcipationRate () const bool RouterProfile::IsLowPartcipationRate (int elapsedTime) const
{ {
if ((GetTime () - m_LastUpdateTime).total_seconds () < 900) // if less than 15 minutes if (elapsedTime < 900) // if less than 15 minutes
return m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 50% rate return m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 50% rate
else else
return 3*m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 25% rate return 3*m_NumTunnelsAgreed < m_NumTunnelsDeclined; // 25% rate
} }
bool RouterProfile::IsLowReplyRate (int elapsedTime) const
{
auto total = m_NumTunnelsAgreed + m_NumTunnelsDeclined;
if (elapsedTime < 300) // if less than 5 minutes
return m_NumTunnelsNonReplied > 10*total;
else
return !total && m_NumTunnelsNonReplied > 20;
}
bool RouterProfile::IsBad () const bool RouterProfile::IsBad () const
{ {
return IsAlwaysDeclining () || IsNonResponding () || IsLowPartcipationRate (); auto elapsedTime = (GetTime () - m_LastUpdateTime).total_seconds ();
return IsAlwaysDeclining () || IsLowPartcipationRate (elapsedTime) || IsLowReplyRate (elapsedTime);
} }
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash) std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash)

4
Profiling.h

@ -42,8 +42,8 @@ namespace data
void UpdateTime (); void UpdateTime ();
bool IsAlwaysDeclining () const { return !m_NumTunnelsAgreed && m_NumTunnelsDeclined >= 5; }; bool IsAlwaysDeclining () const { return !m_NumTunnelsAgreed && m_NumTunnelsDeclined >= 5; };
bool IsNonResponding () const { return m_NumTunnelsNonReplied > 20 && !(m_NumTunnelsAgreed + m_NumTunnelsDeclined); }; bool IsLowPartcipationRate (int elapsedTime) const;
bool IsLowPartcipationRate () const; bool IsLowReplyRate (int elapsedTime) const;
private: private:

5
TunnelPool.cpp

@ -263,11 +263,6 @@ namespace tunnel
bool isExploratory = (m_LocalDestination == &i2p::context); // TODO: implement it better bool isExploratory = (m_LocalDestination == &i2p::context); // TODO: implement it better
auto hop = isExploratory ? i2p::data::netdb.GetRandomRouter (prevHop): auto hop = isExploratory ? i2p::data::netdb.GetRandomRouter (prevHop):
i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop); i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop);
if (!isExploratory && hop && hop->GetProfile ()->IsBad ())
{
LogPrint (eLogInfo, "Selected peer for tunnel has bad profile. Selecting another");
hop = i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop);
}
if (!hop) if (!hop)
hop = i2p::data::netdb.GetRandomRouter (); hop = i2p::data::netdb.GetRandomRouter ();

Loading…
Cancel
Save