2018-07-09 17:32:11 +00:00
|
|
|
#ifndef LLARP_PATHBUILDER_HPP_
|
|
|
|
#define LLARP_PATHBUILDER_HPP_
|
2018-08-30 18:48:43 +00:00
|
|
|
|
2019-01-11 01:19:36 +00:00
|
|
|
#include <path/pathset.hpp>
|
2019-02-08 19:43:25 +00:00
|
|
|
#include <util/status.hpp>
|
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
#include <atomic>
|
2018-06-18 22:03:50 +00:00
|
|
|
|
2019-01-16 00:24:16 +00:00
|
|
|
struct llarp_dht_context;
|
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
namespace llarp
|
2018-06-18 22:03:50 +00:00
|
|
|
{
|
2018-08-30 18:48:43 +00:00
|
|
|
namespace path
|
|
|
|
{
|
2018-09-26 13:04:25 +00:00
|
|
|
// milliseconds waiting between builds on a path
|
2019-01-07 17:28:59 +00:00
|
|
|
constexpr llarp_time_t MIN_PATH_BUILD_INTERVAL = 5 * 1000;
|
2018-09-26 13:04:25 +00:00
|
|
|
|
2019-02-08 19:43:25 +00:00
|
|
|
struct Builder : public PathSet, public util::IStateful
|
2018-08-30 18:48:43 +00:00
|
|
|
{
|
2018-12-24 16:09:05 +00:00
|
|
|
protected:
|
|
|
|
/// flag for PathSet::Stop()
|
|
|
|
std::atomic< bool > _run;
|
|
|
|
|
|
|
|
public:
|
2019-02-11 19:45:42 +00:00
|
|
|
AbstractRouter* router;
|
2019-01-16 00:24:16 +00:00
|
|
|
llarp_dht_context* dht;
|
2019-02-18 10:35:16 +00:00
|
|
|
SecretKey enckey;
|
2018-08-30 18:48:43 +00:00
|
|
|
size_t numHops;
|
2018-09-26 13:04:25 +00:00
|
|
|
llarp_time_t lastBuild = 0;
|
|
|
|
llarp_time_t buildIntervalLimit = MIN_PATH_BUILD_INTERVAL;
|
2018-12-24 16:09:05 +00:00
|
|
|
|
|
|
|
// how many keygens are currently happening
|
|
|
|
std::atomic< uint8_t > keygens;
|
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
/// construct
|
2019-02-11 19:45:42 +00:00
|
|
|
Builder(AbstractRouter* p_router, llarp_dht_context* p_dht,
|
2018-08-30 18:48:43 +00:00
|
|
|
size_t numPaths, size_t numHops);
|
|
|
|
|
|
|
|
virtual ~Builder();
|
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
virtual util::StatusObject
|
|
|
|
ExtractStatus() const override;
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
virtual bool
|
|
|
|
SelectHop(llarp_nodedb* db, const RouterContact& prev, RouterContact& cur,
|
2018-12-24 21:10:35 +00:00
|
|
|
size_t hop, PathRole roles) override;
|
2018-08-30 18:48:43 +00:00
|
|
|
|
|
|
|
virtual bool
|
2018-12-24 21:10:35 +00:00
|
|
|
ShouldBuildMore(llarp_time_t now) const override;
|
2018-10-29 16:48:36 +00:00
|
|
|
|
2018-12-27 12:00:28 +00:00
|
|
|
/// return true if we hit our soft limit for building paths too fast
|
2019-01-02 01:04:04 +00:00
|
|
|
bool
|
2018-12-27 12:00:28 +00:00
|
|
|
BuildCooldownHit(llarp_time_t now) const;
|
|
|
|
|
2019-03-07 22:53:36 +00:00
|
|
|
/// get roles for this path builder
|
|
|
|
virtual PathRole
|
|
|
|
GetRoles() const
|
|
|
|
{
|
|
|
|
return ePathRoleAny;
|
|
|
|
}
|
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
virtual bool
|
2018-12-24 21:10:35 +00:00
|
|
|
Stop() override;
|
2018-12-24 16:09:05 +00:00
|
|
|
|
2019-02-05 14:50:33 +00:00
|
|
|
bool
|
|
|
|
IsStopped() const override;
|
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
bool
|
|
|
|
ShouldRemove() const override;
|
|
|
|
|
2018-10-29 16:48:36 +00:00
|
|
|
llarp_time_t
|
2018-12-24 21:10:35 +00:00
|
|
|
Now() const override;
|
2018-08-30 18:48:43 +00:00
|
|
|
|
|
|
|
void
|
2018-11-14 18:02:27 +00:00
|
|
|
BuildOne(PathRole roles = ePathRoleAny);
|
2018-08-30 18:48:43 +00:00
|
|
|
|
2018-09-28 15:46:47 +00:00
|
|
|
void
|
2018-11-14 18:02:27 +00:00
|
|
|
Build(const std::vector< RouterContact >& hops,
|
|
|
|
PathRole roles = ePathRoleAny);
|
2018-09-28 15:46:47 +00:00
|
|
|
|
|
|
|
bool
|
2018-11-14 18:02:27 +00:00
|
|
|
SelectHops(llarp_nodedb* db, std::vector< RouterContact >& hops,
|
|
|
|
PathRole roles = ePathRoleAny);
|
2018-09-28 15:46:47 +00:00
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
void
|
2018-11-14 18:02:27 +00:00
|
|
|
ManualRebuild(size_t N, PathRole roles = ePathRoleAny);
|
2018-08-30 18:48:43 +00:00
|
|
|
|
2019-01-02 01:04:04 +00:00
|
|
|
virtual const SecretKey&
|
2018-08-30 18:48:43 +00:00
|
|
|
GetTunnelEncryptionSecretKey() const;
|
2018-09-26 13:04:25 +00:00
|
|
|
|
|
|
|
virtual void
|
2018-12-24 21:10:35 +00:00
|
|
|
HandlePathBuilt(Path* p) override;
|
2018-09-26 13:04:25 +00:00
|
|
|
|
|
|
|
virtual void
|
2018-12-24 21:10:35 +00:00
|
|
|
HandlePathBuildTimeout(Path* p) override;
|
2018-08-30 18:48:43 +00:00
|
|
|
};
|
|
|
|
} // namespace path
|
|
|
|
|
|
|
|
} // namespace llarp
|
2018-06-18 22:03:50 +00:00
|
|
|
#endif
|