use random good path for outbound traffic so that it uses an even spread accross

all paths
pull/1272/head
Jeff Becker 4 years ago
parent 382e4215a8
commit a45f92dca7
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -5,6 +5,8 @@
#include <routing/dht_message.hpp>
#include <router/abstractrouter.hpp>
#include <random>
namespace llarp
{
namespace path
@ -161,6 +163,33 @@ namespace llarp
return chosen;
}
Path_ptr
PathSet::GetRandomPathByRouter(RouterID id, PathRole roles) const
{
Lock_t l(m_PathsMutex);
std::vector<Path_ptr> chosen;
auto itr = m_Paths.begin();
while (itr != m_Paths.end())
{
if (itr->second->IsReady() && itr->second->SupportsAnyRoles(roles))
{
if (itr->second->Endpoint() == id)
{
chosen.emplace_back(itr->second);
}
}
++itr;
}
if (chosen.empty())
return nullptr;
size_t idx = 0;
if (chosen.size() >= 2)
{
idx = rand() % chosen.size();
}
return chosen[idx];
}
Path_ptr
PathSet::GetByEndpointWithID(RouterID ep, PathID_t id) const
{

@ -230,6 +230,9 @@ namespace llarp
Path_ptr
GetNewestPathByRouter(RouterID router, PathRole roles = ePathRoleAny) const;
Path_ptr
GetRandomPathByRouter(RouterID router, PathRole roles = ePathRoleAny) const;
Path_ptr
GetPathByID(PathID_t id) const;

@ -74,7 +74,7 @@ namespace llarp
f->T = currentConvoTag;
f->S = ++sequenceNo;
auto path = m_PathSet->GetNewestPathByRouter(remoteIntro.router);
auto path = m_PathSet->GetRandomPathByRouter(remoteIntro.router);
if (!path)
{
LogError(m_Endpoint->Name(), " cannot encrypt and send: no path for intro ", remoteIntro);

Loading…
Cancel
Save