2020-02-26 20:12:14 +00:00
|
|
|
#include <tooling/router_hive.hpp>
|
|
|
|
|
2020-02-26 22:05:04 +00:00
|
|
|
#include <chrono>
|
|
|
|
|
2020-02-26 20:12:14 +00:00
|
|
|
namespace tooling
|
|
|
|
{
|
|
|
|
|
|
|
|
RouterHive::RouterHive(size_t eventQueueSize) : eventQueue(eventQueueSize)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-26 22:05:04 +00:00
|
|
|
void
|
|
|
|
RouterHive::AddRouter(llarp_config* conf)
|
|
|
|
{
|
|
|
|
llarp_main* ctx = llarp_main_init_from_config(conf);
|
|
|
|
routers.push_back(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RouterHive::StartRouters()
|
|
|
|
{
|
|
|
|
llarp_main_runtime_opts opts{false,false,false};
|
|
|
|
|
|
|
|
for (llarp_main* ctx : routers)
|
|
|
|
{
|
|
|
|
routerMainThreads.emplace_back({std::bind(&llarp_main_run, ctx, opts)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RouterHive::StopRouters()
|
|
|
|
{
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
for (llarp_main* ctx : routers)
|
|
|
|
{
|
|
|
|
llarp_main_signal(ctx, 2 /* SIGINT */);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (llarp_main* ctx : routers)
|
|
|
|
{
|
|
|
|
while(llarp_main_is_running(ctx))
|
|
|
|
{
|
|
|
|
std::this_thread::sleep_for(10ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-26 20:12:14 +00:00
|
|
|
void
|
|
|
|
RouterHive::InformEvent(RouterEvent event)
|
|
|
|
{
|
|
|
|
if(eventQueue.tryPushBack(std::move(event))
|
|
|
|
!= llarp::thread::QueueReturn::Success)
|
|
|
|
{
|
|
|
|
LogError("RouterHive Event Queue appears to be full. Either implement/change time dilation or increase the queue size.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RouterHive::ProcessEventQueue()
|
|
|
|
{
|
|
|
|
while(not eventQueue.empty())
|
|
|
|
{
|
|
|
|
RouterEvent event = eventQueue.popFront();
|
|
|
|
|
|
|
|
event.Process(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ProcessPathBuildAttempt(PathBuildAttemptEvent event)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace tooling
|