lokinet/include/llarp/pathset.hpp

135 lines
2.8 KiB
C++
Raw Normal View History

#ifndef LLARP_PATHSET_HPP
#define LLARP_PATHSET_HPP
2018-07-09 17:32:11 +00:00
#include <llarp/time.h>
2018-07-12 18:21:44 +00:00
#include <functional>
#include <list>
#include <llarp/path_types.hpp>
#include <llarp/router_id.hpp>
2018-07-18 03:10:21 +00:00
#include <llarp/routing/message.hpp>
#include <llarp/service/IntroSet.hpp>
2018-07-18 03:10:21 +00:00
#include <llarp/service/lookup.hpp>
2018-08-30 18:48:43 +00:00
#include <llarp/dht/messages/all.hpp>
#include <map>
#include <tuple>
namespace llarp
{
2018-07-09 17:32:11 +00:00
namespace dht
{
struct GotIntroMessage;
}
namespace path
{
enum PathStatus
{
ePathBuilding,
ePathEstablished,
ePathTimeout,
ePathExpired
};
// forward declare
struct Path;
/// a set of paths owned by an entity
struct PathSet
{
/// construct
/// @params numPaths the number of paths to maintain
PathSet(size_t numPaths);
/// tick owned paths
void
Tick(llarp_time_t now, llarp_router* r);
void
RemovePath(Path* path);
virtual void
HandlePathBuilt(Path* path);
void
AddPath(Path* path);
Path*
2018-08-01 22:10:38 +00:00
GetByUpstream(const RouterID& remote, const PathID_t& rxid) const;
void
ExpirePaths(llarp_time_t now);
size_t
NumInStatus(PathStatus st) const;
/// return true if we should build another path
virtual bool
ShouldBuildMore() const;
2018-07-09 17:32:11 +00:00
/// return true if we should publish a new hidden service descriptor
2018-07-18 03:10:21 +00:00
virtual bool
2018-07-18 22:50:05 +00:00
ShouldPublishDescriptors(llarp_time_t now) const
2018-07-18 03:10:21 +00:00
{
2018-07-18 22:50:05 +00:00
(void)now;
2018-07-18 03:10:21 +00:00
return false;
}
2018-07-09 17:32:11 +00:00
2018-07-17 06:17:13 +00:00
/// override me in subtype
virtual bool
HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg)
{
return false;
}
2018-08-10 21:34:11 +00:00
/// override me in subtype
virtual bool
HandleGotRouterMessage(const llarp::dht::GotRouterMessage* msg)
{
return false;
}
virtual routing::IMessageHandler*
GetDHTHandler()
{
return nullptr;
}
Path*
2018-08-01 22:10:38 +00:00
GetEstablishedPathClosestTo(const RouterID& router) const;
2018-07-22 23:14:29 +00:00
Path*
2018-08-01 22:10:38 +00:00
PickRandomEstablishedPath() const;
Path*
GetPathByRouter(const RouterID& router) const;
2018-07-22 23:14:29 +00:00
Path*
GetNewestPathByRouter(const RouterID& router) const;
2018-08-10 21:34:11 +00:00
Path*
GetPathByID(const PathID_t& id) const;
bool
GetCurrentIntroductions(
2018-07-19 04:58:39 +00:00
std::set< llarp::service::Introduction >& intros) const;
2018-07-18 03:10:21 +00:00
virtual bool
PublishIntroSet(llarp_router* r)
{
return false;
}
2018-07-17 06:17:13 +00:00
virtual bool
2018-08-30 18:48:43 +00:00
SelectHop(llarp_nodedb* db, const RouterContact& prev, RouterContact& cur,
size_t hop) = 0;
private:
typedef std::pair< RouterID, PathID_t > PathInfo_t;
typedef std::map< PathInfo_t, Path* > PathMap_t;
size_t m_NumPaths;
PathMap_t m_Paths;
};
} // namespace path
} // namespace llarp
2018-08-18 14:01:21 +00:00
#endif