lokinet/llarp/path/pathbuilder.hpp

126 lines
2.8 KiB
C++
Raw Normal View History

2019-06-17 23:19:39 +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>
#include <atomic>
#include <set>
2018-06-18 22:03:50 +00:00
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
{
// milliseconds waiting between builds on a path
2019-05-06 16:00:10 +00:00
constexpr llarp_time_t MIN_PATH_BUILD_INTERVAL = 500;
2019-04-23 16:13:22 +00:00
struct Builder : public PathSet
2018-08-30 18:48:43 +00:00
{
private:
llarp_time_t m_LastWarn = 0;
protected:
/// flag for PathSet::Stop()
std::atomic< bool > _run;
virtual bool
UrgentBuild(llarp_time_t now) const;
2019-06-20 16:22:29 +00:00
private:
bool
DoUrgentBuildAlignedTo(const RouterID remote,
std::vector< RouterContact >& hops);
bool
DoBuildAlignedTo(const RouterID remote,
std::vector< RouterContact >& hops);
public:
AbstractRouter* router;
SecretKey enckey;
2018-08-30 18:48:43 +00:00
size_t numHops;
llarp_time_t lastBuild = 0;
llarp_time_t buildIntervalLimit = MIN_PATH_BUILD_INTERVAL;
2018-08-30 18:48:43 +00:00
/// construct
2019-06-20 16:22:29 +00:00
Builder(AbstractRouter* p_router, size_t numPaths, size_t numHops);
2018-08-30 18:48:43 +00:00
2019-06-20 16:22:29 +00:00
virtual ~Builder() = default;
2018-08-30 18:48:43 +00:00
2019-04-19 15:10:26 +00:00
util::StatusObject
ExtractStatus() const;
2019-02-08 19:43:25 +00:00
2018-08-30 18:48:43 +00:00
virtual bool
2019-05-08 14:01:31 +00:00
SelectHop(llarp_nodedb* db, const std::set< RouterID >& prev,
RouterContact& cur, 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
/// should we bundle RCs in builds?
virtual bool
ShouldBundleRC() const = 0;
2019-05-07 17:46:38 +00:00
virtual void
ResetInternalState() override;
2018-12-27 12:00:28 +00:00
/// return true if we hit our soft limit for building paths too fast
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;
}
virtual bool
2018-12-24 21:10:35 +00:00
Stop() override;
2019-02-05 14:50:33 +00:00
bool
IsStopped() const override;
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
2019-04-23 16:13:22 +00:00
virtual void
Tick(llarp_time_t now) override;
2018-08-30 18:48:43 +00:00
void
2019-04-23 16:13:22 +00:00
BuildOne(PathRole roles = ePathRoleAny) override;
2018-08-30 18:48:43 +00:00
bool
BuildOneAlignedTo(const RouterID endpoint) override;
void
2018-11-14 18:02:27 +00:00
Build(const std::vector< RouterContact >& hops,
2019-05-06 16:00:10 +00:00
PathRole roles = ePathRoleAny) override;
bool
2018-11-14 18:02:27 +00:00
SelectHops(llarp_nodedb* db, std::vector< RouterContact >& hops,
PathRole roles = ePathRoleAny);
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
virtual const SecretKey&
2018-08-30 18:48:43 +00:00
GetTunnelEncryptionSecretKey() const;
virtual void
HandlePathBuilt(Path_ptr p) override;
virtual void
HandlePathBuildTimeout(Path_ptr p) override;
2018-08-30 18:48:43 +00:00
};
2019-04-23 16:13:22 +00:00
using Builder_ptr = std::shared_ptr< Builder >;
2018-08-30 18:48:43 +00:00
} // namespace path
} // namespace llarp
2018-06-18 22:03:50 +00:00
#endif