|
|
|
@ -15,12 +15,14 @@ namespace llarp
|
|
|
|
|
PathSet::ShouldBuildMore(llarp_time_t now) const
|
|
|
|
|
{
|
|
|
|
|
(void)now;
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
return m_Paths.size() < m_NumPaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
PathSet::ShouldBuildMoreForRoles(llarp_time_t now, PathRole roles) const
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
const size_t required = MinRequiredForRoles(roles);
|
|
|
|
|
size_t has = 0;
|
|
|
|
|
for(const auto& item : m_Paths)
|
|
|
|
@ -45,6 +47,7 @@ namespace llarp
|
|
|
|
|
PathSet::NumPathsExistingAt(llarp_time_t futureTime) const
|
|
|
|
|
{
|
|
|
|
|
size_t num = 0;
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
for(const auto& item : m_Paths)
|
|
|
|
|
{
|
|
|
|
|
if(!item.second->Expired(futureTime))
|
|
|
|
@ -56,6 +59,7 @@ namespace llarp
|
|
|
|
|
void
|
|
|
|
|
PathSet::Tick(llarp_time_t now, llarp_router* r)
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
for(auto& item : m_Paths)
|
|
|
|
|
{
|
|
|
|
|
item.second->Tick(now, r);
|
|
|
|
@ -65,6 +69,7 @@ namespace llarp
|
|
|
|
|
void
|
|
|
|
|
PathSet::ExpirePaths(llarp_time_t now)
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
if(m_Paths.size() == 0)
|
|
|
|
|
return;
|
|
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
@ -84,6 +89,7 @@ namespace llarp
|
|
|
|
|
PathSet::GetEstablishedPathClosestTo(const AlignedBuffer< 32 >& id,
|
|
|
|
|
PathRole roles) const
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
Path* path = nullptr;
|
|
|
|
|
AlignedBuffer< 32 > dist;
|
|
|
|
|
dist.Fill(0xff);
|
|
|
|
@ -106,6 +112,7 @@ namespace llarp
|
|
|
|
|
Path*
|
|
|
|
|
PathSet::GetNewestPathByRouter(const RouterID& id, PathRole roles) const
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
Path* chosen = nullptr;
|
|
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
|
while(itr != m_Paths.end())
|
|
|
|
@ -128,6 +135,7 @@ namespace llarp
|
|
|
|
|
Path*
|
|
|
|
|
PathSet::GetPathByRouter(const RouterID& id, PathRole roles) const
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
Path* chosen = nullptr;
|
|
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
|
while(itr != m_Paths.end())
|
|
|
|
@ -150,6 +158,7 @@ namespace llarp
|
|
|
|
|
Path*
|
|
|
|
|
PathSet::GetPathByID(const PathID_t& id) const
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
|
while(itr != m_Paths.end())
|
|
|
|
|
{
|
|
|
|
@ -163,6 +172,7 @@ namespace llarp
|
|
|
|
|
size_t
|
|
|
|
|
PathSet::AvailablePaths(PathRole roles) const
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
size_t count = 0;
|
|
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
|
while(itr != m_Paths.end())
|
|
|
|
@ -178,6 +188,7 @@ namespace llarp
|
|
|
|
|
size_t
|
|
|
|
|
PathSet::NumInStatus(PathStatus st) const
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
size_t count = 0;
|
|
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
|
while(itr != m_Paths.end())
|
|
|
|
@ -192,6 +203,7 @@ namespace llarp
|
|
|
|
|
void
|
|
|
|
|
PathSet::AddPath(Path* path)
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
auto upstream = path->Upstream(); // RouterID
|
|
|
|
|
auto RXID = path->RXID(); // PathID
|
|
|
|
|
m_Paths.insert(std::make_pair(std::make_pair(upstream, RXID), path));
|
|
|
|
@ -200,12 +212,14 @@ namespace llarp
|
|
|
|
|
void
|
|
|
|
|
PathSet::RemovePath(Path* path)
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
m_Paths.erase({path->Upstream(), path->RXID()});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Path*
|
|
|
|
|
PathSet::GetByUpstream(const RouterID& remote, const PathID_t& rxid) const
|
|
|
|
|
{
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
auto itr = m_Paths.find({remote, rxid});
|
|
|
|
|
if(itr == m_Paths.end())
|
|
|
|
|
return nullptr;
|
|
|
|
@ -227,6 +241,7 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
intros.clear();
|
|
|
|
|
size_t count = 0;
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
|
while(itr != m_Paths.end())
|
|
|
|
|
{
|
|
|
|
@ -246,6 +261,7 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
intros.clear();
|
|
|
|
|
size_t count = 0;
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
|
while(itr != m_Paths.end())
|
|
|
|
|
{
|
|
|
|
@ -270,6 +286,7 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
intro.Clear();
|
|
|
|
|
bool found = false;
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
|
while(itr != m_Paths.end())
|
|
|
|
|
{
|
|
|
|
@ -288,6 +305,7 @@ namespace llarp
|
|
|
|
|
PathSet::PickRandomEstablishedPath(PathRole roles) const
|
|
|
|
|
{
|
|
|
|
|
std::vector< Path* > established;
|
|
|
|
|
Lock_t l(m_PathsMutex);
|
|
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
|
while(itr != m_Paths.end())
|
|
|
|
|
{
|
|
|
|
|