#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 AllowTransit(); void RejectTransit(); bool CheckPathLimitHitByIP(const IpAddress& ip); bool CheckPathLimitHitByIP(const std::string& ip); bool AllowingTransit() const; bool HasTransitHop(const TransitHopInfo& info); void PutTransitHop(std::shared_ptr hop); Path_ptr GetPath(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