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
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
// TODO: implement me
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace path
|
|
|
|
} // namespace llarp
|