mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-19 01:09:58 +00:00
make more attempts to select not bad hop
This commit is contained in:
parent
cb8fbb0135
commit
b092e712ec
@ -1257,7 +1257,7 @@ namespace data
|
|||||||
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter (Filter filter) const
|
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter (Filter filter) const
|
||||||
{
|
{
|
||||||
if (m_RouterInfos.empty())
|
if (m_RouterInfos.empty())
|
||||||
return 0;
|
return nullptr;
|
||||||
uint16_t inds[3];
|
uint16_t inds[3];
|
||||||
RAND_bytes ((uint8_t *)inds, sizeof (inds));
|
RAND_bytes ((uint8_t *)inds, sizeof (inds));
|
||||||
std::lock_guard<std::mutex> l(m_RouterInfosMutex);
|
std::lock_guard<std::mutex> l(m_RouterInfosMutex);
|
||||||
|
@ -494,11 +494,23 @@ namespace tunnel
|
|||||||
std::shared_ptr<const i2p::data::RouterInfo> TunnelPool::SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop,
|
std::shared_ptr<const i2p::data::RouterInfo> TunnelPool::SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop,
|
||||||
bool reverse, bool endpoint) const
|
bool reverse, bool endpoint) const
|
||||||
{
|
{
|
||||||
auto hop = IsExploratory () ? i2p::data::netdb.GetRandomRouter (prevHop, reverse, endpoint):
|
bool tryHighBandwidth = !IsExploratory ();
|
||||||
i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop, reverse, endpoint);
|
std::shared_ptr<const i2p::data::RouterInfo> hop;
|
||||||
|
for (int i = 0; i < TUNNEL_POOL_MAX_HOP_SELECTION_ATTEMPTS; i++)
|
||||||
if (!hop || hop->GetProfile ()->IsBad ())
|
{
|
||||||
hop = i2p::data::netdb.GetRandomRouter (prevHop, reverse, endpoint);
|
hop = tryHighBandwidth ?
|
||||||
|
i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop, reverse, endpoint) :
|
||||||
|
i2p::data::netdb.GetRandomRouter (prevHop, reverse, endpoint);
|
||||||
|
if (hop)
|
||||||
|
{
|
||||||
|
if (!hop->GetProfile ()->IsBad ())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (tryHighBandwidth)
|
||||||
|
tryHighBandwidth = false;
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
return hop;
|
return hop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ namespace tunnel
|
|||||||
const int TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY = 16;
|
const int TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY = 16;
|
||||||
const int TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY = 16;
|
const int TUNNEL_POOL_MAX_OUTBOUND_TUNNELS_QUANTITY = 16;
|
||||||
const int TUNNEL_POOL_MAX_NUM_BUILD_REQUESTS = 3;
|
const int TUNNEL_POOL_MAX_NUM_BUILD_REQUESTS = 3;
|
||||||
|
const int TUNNEL_POOL_MAX_HOP_SELECTION_ATTEMPTS = 3;
|
||||||
|
|
||||||
class Tunnel;
|
class Tunnel;
|
||||||
class InboundTunnel;
|
class InboundTunnel;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user