2018-06-25 15:12:08 +00:00
|
|
|
#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>
|
2018-07-11 16:11:19 +00:00
|
|
|
#include <list>
|
2018-06-25 15:12:08 +00:00
|
|
|
#include <llarp/path_types.hpp>
|
2018-07-11 16:11:19 +00:00
|
|
|
#include <llarp/router_id.hpp>
|
2018-07-18 03:10:21 +00:00
|
|
|
#include <llarp/routing/message.hpp>
|
2018-07-11 16:11:19 +00:00
|
|
|
#include <llarp/service/IntroSet.hpp>
|
2018-07-18 03:10:21 +00:00
|
|
|
#include <llarp/service/lookup.hpp>
|
2018-06-25 15:12:08 +00:00
|
|
|
#include <map>
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2018-07-09 17:32:11 +00:00
|
|
|
namespace dht
|
|
|
|
{
|
|
|
|
struct GotIntroMessage;
|
|
|
|
}
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
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);
|
|
|
|
|
2018-06-29 16:02:39 +00:00
|
|
|
/// tick owned paths
|
|
|
|
void
|
|
|
|
Tick(llarp_time_t now, llarp_router* r);
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
void
|
|
|
|
RemovePath(Path* path);
|
|
|
|
|
|
|
|
void
|
|
|
|
HandlePathBuilt(Path* path);
|
|
|
|
|
|
|
|
void
|
|
|
|
AddPath(Path* path);
|
|
|
|
|
|
|
|
Path*
|
|
|
|
GetByUpstream(const RouterID& remote, const PathID_t& rxid);
|
|
|
|
|
|
|
|
void
|
|
|
|
ExpirePaths(llarp_time_t now);
|
|
|
|
|
|
|
|
size_t
|
|
|
|
NumInStatus(PathStatus st) const;
|
|
|
|
|
|
|
|
/// return true if we should build another path
|
|
|
|
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
|
2018-07-11 16:11:19 +00:00
|
|
|
virtual bool
|
|
|
|
HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Path*
|
|
|
|
PickRandomEstablishedPath();
|
|
|
|
|
2018-07-22 23:14:29 +00:00
|
|
|
Path*
|
|
|
|
GetPathByRouter(const RouterID& router);
|
|
|
|
|
2018-07-11 16:11:19 +00:00
|
|
|
bool
|
|
|
|
GetCurrentIntroductions(
|
2018-07-19 04:58:39 +00:00
|
|
|
std::set< llarp::service::Introduction >& intros) const;
|
2018-07-11 16:11:19 +00:00
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
virtual bool
|
|
|
|
PublishIntroSet(llarp_router* r)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-17 06:17:13 +00:00
|
|
|
|
2018-07-19 21:08:11 +00:00
|
|
|
virtual bool
|
|
|
|
SelectHop(llarp_nodedb* db, llarp_rc* prev, llarp_rc* cur,
|
|
|
|
size_t hop) = 0;
|
|
|
|
|
2018-07-25 01:54:37 +00:00
|
|
|
static bool
|
2018-07-19 21:08:11 +00:00
|
|
|
SelectHopCallback(void* user, llarp_nodedb* db, llarp_rc* prev,
|
|
|
|
llarp_rc* cur, size_t hopno)
|
|
|
|
{
|
|
|
|
PathSet* self = static_cast< PathSet* >(user);
|
2018-07-25 01:54:37 +00:00
|
|
|
return self->SelectHop(db, prev, cur, hopno);
|
2018-07-19 21:08:11 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
private:
|
2018-06-26 14:52:19 +00:00
|
|
|
typedef std::pair< RouterID, PathID_t > PathInfo_t;
|
|
|
|
typedef std::map< PathInfo_t, Path* > PathMap_t;
|
2018-06-25 15:12:08 +00:00
|
|
|
size_t m_NumPaths;
|
2018-06-26 14:52:19 +00:00
|
|
|
PathMap_t m_Paths;
|
2018-06-25 15:12:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace path
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|