From 577ba9b397761703e237f62d1e4ffe1a29ff1c7c Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 27 Mar 2015 20:34:31 -0400 Subject: [PATCH] initial filtration of bad peers --- Profiling.h | 2 ++ TunnelPool.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Profiling.h b/Profiling.h index 1f175dc7..2f9d80c5 100644 --- a/Profiling.h +++ b/Profiling.h @@ -24,6 +24,8 @@ namespace data void Save (); void Load (); + + bool IsBad () const { return !m_NumTunnelsAgreed && m_NumTunnelsDeclined >= 5; }; void TunnelBuildResponse (uint8_t ret); diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 82de6267..12f1a41d 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -261,8 +261,13 @@ namespace tunnel std::shared_ptr TunnelPool::SelectNextHop (std::shared_ptr prevHop) const { 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); + 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) hop = i2p::data::netdb.GetRandomRouter ();