#pragma once #include #include #include #include #include #include #include struct llarp_config; struct llarp_main; namespace llarp { struct Context; struct AbstractRouter; } // 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 AbstractRouter or Context void ForEachRelayRouter(std::function visit); void ForEachClientRouter(std::function visit); void ForEachRouterRouter(std::function visit); void ForEachRelayContext(std::function visit); void ForEachClientContext(std::function visit); void ForEachRouterContext(std::function visit); llarp::AbstractRouter* 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