|
|
@ -18,25 +18,16 @@ namespace tooling
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto& container = (isRelay ? relays : clients);
|
|
|
|
auto& container = (isRelay ? relays : clients);
|
|
|
|
|
|
|
|
|
|
|
|
llarp_main* ctx = llarp_main_init_from_config(config->Copy(), isRelay);
|
|
|
|
Context_ptr context = std::make_shared<llarp::Context>();
|
|
|
|
auto result = llarp_main_setup(ctx, isRelay);
|
|
|
|
context->config = std::make_unique<llarp::Config>(*config.get());
|
|
|
|
if (result == 0)
|
|
|
|
context->Configure(isRelay, {});
|
|
|
|
{
|
|
|
|
context->Setup(isRelay);
|
|
|
|
auto context = llarp::Context::Get(ctx);
|
|
|
|
|
|
|
|
auto routerId = llarp::RouterID(context->router->pubkey());
|
|
|
|
auto routerId = llarp::RouterID(context->router->pubkey());
|
|
|
|
context->InjectHive(this);
|
|
|
|
context->InjectHive(this);
|
|
|
|
container[routerId] = ctx;
|
|
|
|
container[routerId] = context;
|
|
|
|
std::cout << "Generated router with ID " << routerId << std::endl;
|
|
|
|
std::cout << "Generated router with ID " << routerId << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw std::runtime_error(llarp::stringify(
|
|
|
|
|
|
|
|
"Failed to add RouterHive ",
|
|
|
|
|
|
|
|
(isRelay ? "relay" : "client"),
|
|
|
|
|
|
|
|
", llarp_main_setup() returned ",
|
|
|
|
|
|
|
|
result));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
RouterHive::AddRelay(const std::shared_ptr<llarp::Config>& config)
|
|
|
|
RouterHive::AddRelay(const std::shared_ptr<llarp::Config>& config)
|
|
|
@ -58,7 +49,7 @@ namespace tooling
|
|
|
|
for (auto [routerId, ctx] : container)
|
|
|
|
for (auto [routerId, ctx] : container)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
routerMainThreads.emplace_back([=]() {
|
|
|
|
routerMainThreads.emplace_back([=]() {
|
|
|
|
llarp_main_run(ctx, llarp_main_runtime_opts{false, false, false, isRelay});
|
|
|
|
ctx->Run(llarp::RuntimeOptions{false, false, isRelay});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
std::this_thread::sleep_for(2ms);
|
|
|
|
std::this_thread::sleep_for(2ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -82,24 +73,24 @@ namespace tooling
|
|
|
|
llarp::LogInfo("Signalling all routers to stop");
|
|
|
|
llarp::LogInfo("Signalling all routers to stop");
|
|
|
|
for (auto [routerId, ctx] : relays)
|
|
|
|
for (auto [routerId, ctx] : relays)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
llarp_main_signal(ctx, 2 /* SIGINT */);
|
|
|
|
LogicCall(ctx->logic, [ctx]() { ctx->HandleSignal(SIGINT); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto [routerId, ctx] : clients)
|
|
|
|
for (auto [routerId, ctx] : clients)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
llarp_main_signal(ctx, 2 /* SIGINT */);
|
|
|
|
LogicCall(ctx->logic, [ctx]() { ctx->HandleSignal(SIGINT); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
llarp::LogInfo("Waiting on routers to be stopped");
|
|
|
|
llarp::LogInfo("Waiting on routers to be stopped");
|
|
|
|
for (auto [routerId, ctx] : relays)
|
|
|
|
for (auto [routerId, ctx] : relays)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
while (llarp_main_is_running(ctx))
|
|
|
|
while (ctx->IsUp())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::this_thread::sleep_for(10ms);
|
|
|
|
std::this_thread::sleep_for(10ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto [routerId, ctx] : clients)
|
|
|
|
for (auto [routerId, ctx] : clients)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
while (llarp_main_is_running(ctx))
|
|
|
|
while (ctx->IsUp())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::this_thread::sleep_for(10ms);
|
|
|
|
std::this_thread::sleep_for(10ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -154,9 +145,8 @@ namespace tooling
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
RouterHive::VisitRouter(llarp_main* router, std::function<void(Context_ptr)> visit)
|
|
|
|
RouterHive::VisitRouter(Context_ptr ctx, std::function<void(Context_ptr)> visit)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto ctx = llarp::Context::Get(router);
|
|
|
|
|
|
|
|
LogicCall(ctx->logic, [visit, ctx]() { visit(ctx); });
|
|
|
|
LogicCall(ctx->logic, [visit, ctx]() { visit(ctx); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -170,7 +160,7 @@ namespace tooling
|
|
|
|
if (itr == relays.end())
|
|
|
|
if (itr == relays.end())
|
|
|
|
return nullptr;
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
auto ctx = llarp::Context::Get(itr->second);
|
|
|
|
auto ctx = itr->second;
|
|
|
|
return ctx->router.get();
|
|
|
|
return ctx->router.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -186,9 +176,8 @@ namespace tooling
|
|
|
|
size_t done_count = 0;
|
|
|
|
size_t done_count = 0;
|
|
|
|
for (auto [routerId, ctx] : relays)
|
|
|
|
for (auto [routerId, ctx] : relays)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto context = llarp::Context::Get(ctx);
|
|
|
|
LogicCall(ctx->logic, [&, i, ctx]() {
|
|
|
|
LogicCall(context->logic, [&, i, context]() {
|
|
|
|
size_t count = ctx->router->NumberOfConnectedRouters();
|
|
|
|
size_t count = context->router->NumberOfConnectedRouters();
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> guard{results_lock};
|
|
|
|
std::lock_guard<std::mutex> guard{results_lock};
|
|
|
|
results[i] = count;
|
|
|
|
results[i] = count;
|
|
|
|
done_count++;
|
|
|
|
done_count++;
|
|
|
@ -222,8 +211,7 @@ namespace tooling
|
|
|
|
size_t i = 0;
|
|
|
|
size_t i = 0;
|
|
|
|
for (auto [routerId, ctx] : relays)
|
|
|
|
for (auto [routerId, ctx] : relays)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto context = llarp::Context::Get(ctx);
|
|
|
|
results[i] = ctx->router->rc();
|
|
|
|
results[i] = context->router->rc();
|
|
|
|
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
return results;
|
|
|
|