2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-24 13:18:03 +00:00
|
|
|
#include "abstracthophandler.hpp"
|
|
|
|
#include "path_types.hpp"
|
|
|
|
#include "pathset.hpp"
|
|
|
|
#include "transit_hop.hpp"
|
|
|
|
|
|
|
|
#include <llarp/ev/ev.hpp>
|
2023-10-19 11:49:46 +00:00
|
|
|
#include <llarp/net/ip_address.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/util/compare_ptr.hpp>
|
|
|
|
#include <llarp/util/decaying_hashset.hpp>
|
|
|
|
#include <llarp/util/types.hpp>
|
2023-10-24 13:18:03 +00:00
|
|
|
|
2019-06-17 23:19:39 +00:00
|
|
|
#include <memory>
|
2019-12-03 17:03:19 +00:00
|
|
|
#include <unordered_map>
|
2019-06-17 23:19:39 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2023-09-15 14:55:32 +00:00
|
|
|
struct Router;
|
2019-06-17 23:19:39 +00:00
|
|
|
struct RouterID;
|
|
|
|
|
|
|
|
namespace path
|
|
|
|
{
|
|
|
|
struct TransitHop;
|
|
|
|
struct TransitHopInfo;
|
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
struct TransitHopID
|
|
|
|
{
|
|
|
|
RouterID rid;
|
|
|
|
PathID_t path_id;
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const TransitHopID& other) const
|
|
|
|
{
|
|
|
|
return rid == other.rid && path_id == other.path_id;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace path
|
|
|
|
} // namespace llarp
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template <>
|
|
|
|
struct hash<llarp::path::TransitHopID>
|
|
|
|
{
|
|
|
|
size_t
|
|
|
|
operator()(const llarp::path::TransitHopID& obj) const noexcept
|
2019-06-17 23:19:39 +00:00
|
|
|
{
|
2023-10-21 03:30:10 +00:00
|
|
|
return std::hash<llarp::PathID_t>{}(obj.path_id);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace std
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
namespace llarp::path
|
|
|
|
{
|
|
|
|
struct PathContext
|
|
|
|
{
|
|
|
|
explicit PathContext(Router* router);
|
2019-09-16 10:21:12 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
/// called from router tick function
|
|
|
|
void
|
|
|
|
ExpirePaths(llarp_time_t now);
|
2019-09-05 17:39:09 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
void
|
2023-12-06 21:54:51 +00:00
|
|
|
allow_transit();
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
void
|
2023-12-06 21:54:51 +00:00
|
|
|
reject_transit();
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
bool
|
2023-12-06 21:54:51 +00:00
|
|
|
check_path_limit_hit_by_ip(const IpAddress& ip);
|
2019-12-30 20:15:19 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
bool
|
2023-12-06 21:54:51 +00:00
|
|
|
is_transit_allowed() const;
|
2023-09-29 21:00:13 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
bool
|
2023-12-06 21:54:51 +00:00
|
|
|
has_transit_hop(const TransitHopInfo& info);
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
void
|
2023-12-06 21:54:51 +00:00
|
|
|
put_transit_hop(std::shared_ptr<TransitHop> hop);
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2024-01-17 13:34:07 +00:00
|
|
|
std::shared_ptr<Path>
|
2023-12-06 21:54:51 +00:00
|
|
|
get_path(const PathID_t& path_id);
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
bool
|
|
|
|
TransitHopPreviousIsRouter(const PathID_t& path, const RouterID& r);
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-11-06 21:02:20 +00:00
|
|
|
std::shared_ptr<TransitHop>
|
2023-10-21 03:30:10 +00:00
|
|
|
GetPathForTransfer(const PathID_t& topath);
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
std::shared_ptr<TransitHop>
|
|
|
|
GetTransitHop(const RouterID&, const PathID_t&);
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2024-01-17 13:34:07 +00:00
|
|
|
std::shared_ptr<PathSet>
|
2023-10-21 03:30:10 +00:00
|
|
|
GetLocalPathSet(const PathID_t& id);
|
2021-06-07 12:39:38 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
/// get a set of all paths that we own who's endpoint is r
|
2023-11-06 21:02:20 +00:00
|
|
|
std::vector<std::shared_ptr<Path>>
|
2023-10-21 03:30:10 +00:00
|
|
|
FindOwnedPathsWithEndpoint(const RouterID& r);
|
2021-06-07 12:39:38 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
bool
|
|
|
|
HopIsUs(const RouterID& k) const;
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
void
|
2024-01-17 13:34:07 +00:00
|
|
|
AddOwnPath(std::shared_ptr<PathSet> set, std::shared_ptr<Path> p);
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
void
|
2024-01-17 13:34:07 +00:00
|
|
|
RemovePathSet(std::shared_ptr<PathSet> set);
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
const EventLoop_ptr&
|
|
|
|
loop();
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
const SecretKey&
|
|
|
|
EncryptionSecretKey();
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
const byte_t*
|
|
|
|
OurRouterID() const;
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
/// current number of transit paths we have
|
|
|
|
uint64_t
|
|
|
|
CurrentTransitPaths();
|
2023-09-21 14:20:49 +00:00
|
|
|
|
2023-10-21 03:30:10 +00:00
|
|
|
/// current number of paths we created in status
|
|
|
|
uint64_t
|
2023-12-18 22:15:45 +00:00
|
|
|
CurrentOwnedPaths(path::PathStatus status = path::PathStatus::ESTABLISHED);
|
2023-10-21 03:30:10 +00:00
|
|
|
|
|
|
|
Router*
|
|
|
|
router() const
|
|
|
|
{
|
|
|
|
return _router;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Router* _router;
|
|
|
|
|
2023-11-06 21:02:20 +00:00
|
|
|
std::unordered_map<TransitHopID, std::shared_ptr<TransitHop>> transit_hops;
|
2024-01-17 13:34:07 +00:00
|
|
|
std::unordered_map<PathID_t, std::shared_ptr<Path>> own_paths;
|
2023-10-21 03:30:10 +00:00
|
|
|
bool m_AllowTransit;
|
|
|
|
util::DecayingHashSet<IpAddress> path_limits;
|
|
|
|
};
|
|
|
|
} // namespace llarp::path
|