2018-06-25 15:12:08 +00:00
|
|
|
#include <llarp/path.hpp>
|
|
|
|
#include <llarp/pathset.hpp>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace path
|
|
|
|
{
|
|
|
|
PathSet::PathSet(size_t num) : m_NumPaths(num)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PathSet::ShouldBuildMore() const
|
|
|
|
{
|
2018-06-26 14:52:19 +00:00
|
|
|
return m_Paths.size() < m_NumPaths;
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
|
|
|
|
2018-06-29 16:02:39 +00:00
|
|
|
void
|
|
|
|
PathSet::Tick(llarp_time_t now, llarp_router* r)
|
|
|
|
{
|
|
|
|
for(auto& item : m_Paths)
|
|
|
|
{
|
|
|
|
if(item.second->status == ePathEstablished)
|
|
|
|
{
|
|
|
|
item.second->Tick(now, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
void
|
|
|
|
PathSet::ExpirePaths(llarp_time_t now)
|
|
|
|
{
|
2018-06-26 14:52:19 +00:00
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
while(itr != m_Paths.end())
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
2018-06-26 14:52:19 +00:00
|
|
|
if(itr->second->Expired(now))
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
2018-06-26 14:52:19 +00:00
|
|
|
delete itr->second;
|
|
|
|
itr = m_Paths.erase(itr);
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
2018-06-26 14:52:19 +00:00
|
|
|
else
|
|
|
|
++itr;
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
PathSet::NumInStatus(PathStatus st) const
|
|
|
|
{
|
|
|
|
size_t count = 0;
|
2018-06-26 14:52:19 +00:00
|
|
|
auto itr = m_Paths.begin();
|
|
|
|
while(itr != m_Paths.end())
|
2018-06-25 15:12:08 +00:00
|
|
|
{
|
|
|
|
if(itr->second->status == st)
|
|
|
|
++count;
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathSet::AddPath(Path* path)
|
|
|
|
{
|
2018-06-26 14:52:19 +00:00
|
|
|
m_Paths.emplace(std::make_pair(path->Upstream(), path->RXID()), path);
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathSet::RemovePath(Path* path)
|
|
|
|
{
|
2018-06-26 14:52:19 +00:00
|
|
|
m_Paths.erase({path->Upstream(), path->RXID()});
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Path*
|
|
|
|
PathSet::GetByUpstream(const RouterID& remote, const PathID_t& rxid)
|
|
|
|
{
|
2018-06-26 14:52:19 +00:00
|
|
|
auto itr = m_Paths.find({remote, rxid});
|
|
|
|
if(itr == m_Paths.end())
|
|
|
|
return nullptr;
|
|
|
|
return itr->second;
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathSet::HandlePathBuilt(Path* path)
|
|
|
|
{
|
2018-06-29 16:02:39 +00:00
|
|
|
auto dlt = llarp_time_now_ms() - path->buildStarted;
|
|
|
|
llarp::Info("Path build took ", dlt, "ms for tx=", path->TXID(),
|
|
|
|
" rx=", path->RXID());
|
2018-06-25 15:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace path
|
|
|
|
} // namespace llarp
|