You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/tooling/router_hive.cpp

84 lines
1.6 KiB
C++

#include <tooling/router_hive.hpp>
#include "llarp.h"
#include "llarp.hpp"
#include <chrono>
namespace tooling
{
const size_t RouterHive::MAX_EVENT_QUEUE_SIZE = 200;
RouterHive::RouterHive(size_t eventQueueSize) : eventQueue(eventQueueSize)
{
}
void
RouterHive::AddRouter(llarp_config* conf)
{
llarp_main* ctx = llarp_main_init_from_config(conf);
llarp::Context::Get(ctx)->InjectHive(this);
routers.push_back(ctx);
}
void
RouterHive::StartRouters()
{
llarp_main_runtime_opts opts{false,false,false};
for (llarp_main* ctx : routers)
{
std::thread t{std::bind(&llarp_main_run, ctx, opts)};
routerMainThreads.emplace_back(std::move(t));
}
}
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);
}
}
}
void
RouterHive::NotifyEvent(RouterEventPtr event)
{
if(eventQueue.tryPushBack(std::move(event))
!= llarp::thread::QueueReturn::Success)
{
5 years ago
llarp::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())
{
RouterEventPtr event = eventQueue.popFront();
event->Process(*this);
}
}
void
RouterHive::ProcessPathBuildAttempt(const PathBuildAttemptEvent& event)
{
}
} // namespace tooling