#pragma once #include "router_event.hpp" #include #include #include #include #include #include #include struct llarp_config; struct llarp_main; namespace llarp { struct Context; } // namespace llarp namespace tooling { struct HiveRouter; // Hive's version of Router struct RouterHive { using Context_ptr = std::shared_ptr; private: void StartRouters(bool isRelay); void AddRouter(const std::shared_ptr& config, bool isRelay); /// safely visit router (asynchronously) void VisitRouter(Context_ptr ctx, std::function visit); public: RouterHive() = default; void AddRelay(const std::shared_ptr& conf); void AddClient(const std::shared_ptr& conf); void StartRelays(); void StartClients(); void StopRouters(); void NotifyEvent(RouterEventPtr event); RouterEventPtr GetNextEvent(); std::deque GetAllEvents(); // functions to safely visit each relay and/or client's HiveContext void ForEachRelay(std::function visit); void ForEachClient(std::function visit); void ForEachRouter(std::function visit); HiveRouter* GetRelay(const llarp::RouterID& id, bool needMutexLock = true); std::vector RelayConnectedRelays(); std::vector GetRelayRCs(); std::mutex routerMutex; std::unordered_map relays; std::unordered_map clients; std::vector routerMainThreads; std::mutex eventQueueMutex; std::deque eventQueue; }; } // namespace tooling