#pragma once #include "abstracthophandler.hpp" #include "path_types.hpp" #include "pathset.hpp" #include "transit_hop.hpp" #include #include #include #include #include #include #include namespace llarp { struct Router; struct RouterID; namespace path { struct TransitHop; struct TransitHopInfo; 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 namespace std { template <> struct hash { size_t operator()(const llarp::path::TransitHopID& obj) const noexcept { return std::hash{}(obj.path_id); } }; } // namespace std namespace llarp::path { struct PathContext { explicit PathContext(Router* router); /// called from router tick function void ExpirePaths(llarp_time_t now); void allow_transit(); void reject_transit(); bool check_path_limit_hit_by_ip(const IpAddress& ip); bool is_transit_allowed() const; bool has_transit_hop(const TransitHopInfo& info); void put_transit_hop(std::shared_ptr hop); Path_ptr get_path(const PathID_t& path_id); bool TransitHopPreviousIsRouter(const PathID_t& path, const RouterID& r); std::shared_ptr GetPathForTransfer(const PathID_t& topath); std::shared_ptr GetTransitHop(const RouterID&, const PathID_t&); PathSet_ptr GetLocalPathSet(const PathID_t& id); /// get a set of all paths that we own who's endpoint is r std::vector> FindOwnedPathsWithEndpoint(const RouterID& r); bool HopIsUs(const RouterID& k) const; void AddOwnPath(PathSet_ptr set, Path_ptr p); void RemovePathSet(PathSet_ptr set); const EventLoop_ptr& loop(); const SecretKey& EncryptionSecretKey(); const byte_t* OurRouterID() const; /// current number of transit paths we have uint64_t CurrentTransitPaths(); /// current number of paths we created in status uint64_t CurrentOwnedPaths(path::PathStatus status = path::PathStatus::ePathEstablished); Router* router() const { return _router; } private: Router* _router; std::unordered_map> transit_hops; std::unordered_map own_paths; bool m_AllowTransit; util::DecayingHashSet path_limits; }; } // namespace llarp::path