2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-08-30 18:48:43 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include "pathset.hpp"
|
|
|
|
#include <llarp/util/status.hpp>
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
#include <atomic>
|
2019-07-15 09:15:51 +00:00
|
|
|
#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
|
|
|
|
{
|
2018-09-26 13:04:25 +00:00
|
|
|
// milliseconds waiting between builds on a path
|
2020-02-24 19:40:45 +00:00
|
|
|
static constexpr auto MIN_PATH_BUILD_INTERVAL = 500ms;
|
2018-09-26 13:04:25 +00:00
|
|
|
|
2019-04-23 16:13:22 +00:00
|
|
|
struct Builder : public PathSet
|
2018-08-30 18:48:43 +00:00
|
|
|
{
|
2019-07-01 14:56:56 +00:00
|
|
|
private:
|
2020-02-24 19:40:45 +00:00
|
|
|
llarp_time_t m_LastWarn = 0s;
|
2019-07-01 14:56:56 +00:00
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
protected:
|
|
|
|
/// flag for PathSet::Stop()
|
2020-04-07 18:38:56 +00:00
|
|
|
std::atomic<bool> _run;
|
2018-12-24 16:09:05 +00:00
|
|
|
|
2019-05-07 12:31:34 +00:00
|
|
|
virtual bool
|
|
|
|
UrgentBuild(llarp_time_t now) const;
|
|
|
|
|
2019-06-20 16:22:29 +00:00
|
|
|
private:
|
2019-07-31 12:51:24 +00:00
|
|
|
void
|
|
|
|
DoPathBuildBackoff();
|
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
public:
|
2019-08-02 09:27:27 +00:00
|
|
|
AbstractRouter* m_router;
|
2019-02-18 10:35:16 +00:00
|
|
|
SecretKey enckey;
|
2018-08-30 18:48:43 +00:00
|
|
|
size_t numHops;
|
2020-04-07 18:38:56 +00:00
|
|
|
llarp_time_t lastBuild = 0s;
|
2018-09-26 13:04:25 +00:00
|
|
|
llarp_time_t buildIntervalLimit = MIN_PATH_BUILD_INTERVAL;
|
2018-12-24 16:09:05 +00:00
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
/// construct
|
2020-10-27 20:27:14 +00:00
|
|
|
Builder(AbstractRouter* p_router, size_t numDesiredPaths, 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
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
bool
|
2018-12-24 21:10:35 +00:00
|
|
|
ShouldBuildMore(llarp_time_t now) const override;
|
2018-10-29 16:48:36 +00:00
|
|
|
|
2019-04-18 11:49:54 +00:00
|
|
|
/// should we bundle RCs in builds?
|
|
|
|
virtual bool
|
|
|
|
ShouldBundleRC() const = 0;
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
void
|
2019-05-07 17:46:38 +00:00
|
|
|
ResetInternalState() override;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-02-25 22:32:57 +00:00
|
|
|
BuildStats
|
|
|
|
CurrentBuildStats() const
|
|
|
|
{
|
|
|
|
return m_BuildStats;
|
|
|
|
}
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
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
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
void
|
2019-04-23 16:13:22 +00:00
|
|
|
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
|
|
|
|
2019-05-07 12:31:34 +00:00
|
|
|
bool
|
|
|
|
BuildOneAlignedTo(const RouterID endpoint) override;
|
|
|
|
|
2021-02-18 13:28:53 +00:00
|
|
|
std::optional<std::vector<RouterContact>>
|
2021-02-18 17:20:58 +00:00
|
|
|
GetHopsAlignedToForBuild(RouterID endpoint, const std::set<RouterID>& exclude = {});
|
2021-02-02 14:35:40 +00:00
|
|
|
|
2018-09-28 15:46:47 +00:00
|
|
|
void
|
2021-02-02 14:35:40 +00:00
|
|
|
Build(std::vector<RouterContact> hops, PathRole roles = ePathRoleAny) override;
|
2018-09-28 15:46:47 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
/// pick a first hop
|
2021-02-18 13:28:53 +00:00
|
|
|
std::optional<RouterContact>
|
2021-02-18 17:20:58 +00:00
|
|
|
SelectFirstHop(const std::set<RouterID>& exclude = {}) const;
|
2021-02-02 14:35:40 +00:00
|
|
|
|
2021-02-18 13:28:53 +00:00
|
|
|
virtual std::optional<std::vector<RouterContact>>
|
2021-02-02 14:35:40 +00:00
|
|
|
GetHopsForBuild() override;
|
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
|
|
|
|
2019-09-20 16:56:19 +00:00
|
|
|
virtual void
|
2019-04-23 14:28:59 +00:00
|
|
|
HandlePathBuilt(Path_ptr p) override;
|
2018-09-26 13:04:25 +00:00
|
|
|
|
2019-09-20 16:56:19 +00:00
|
|
|
virtual void
|
2019-04-23 14:28:59 +00:00
|
|
|
HandlePathBuildTimeout(Path_ptr p) override;
|
2019-07-31 12:51:24 +00:00
|
|
|
|
2019-09-20 16:56:19 +00:00
|
|
|
virtual void
|
2019-07-31 12:51:24 +00:00
|
|
|
HandlePathBuildFailed(Path_ptr p) override;
|
2018-08-30 18:48:43 +00:00
|
|
|
};
|
2019-04-23 14:28:59 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using Builder_ptr = std::shared_ptr<Builder>;
|
2019-04-23 14:28:59 +00:00
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
} // namespace path
|
|
|
|
|
|
|
|
} // namespace llarp
|