|
|
|
@ -110,7 +110,9 @@ namespace llarp::rpc
|
|
|
|
|
auto ftr = result.get_future();
|
|
|
|
|
msg.send_reply(CreateJSONResponse(ftr.get()));
|
|
|
|
|
})
|
|
|
|
|
.add_request_command("exit", [&](lokimq::Message& msg) {
|
|
|
|
|
.add_request_command(
|
|
|
|
|
"exit",
|
|
|
|
|
[&](lokimq::Message& msg) {
|
|
|
|
|
HandleJSONRequest(msg, [r = m_Router](nlohmann::json obj, ReplyFunction_t reply) {
|
|
|
|
|
if (r->IsServiceNode())
|
|
|
|
|
{
|
|
|
|
@ -236,6 +238,48 @@ namespace llarp::rpc
|
|
|
|
|
reply(CreateJSONResponse("OK"));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.add_request_command("config", [&](lokimq::Message& msg) {
|
|
|
|
|
HandleJSONRequest(msg, [r = m_Router](nlohmann::json obj, ReplyFunction_t reply) {
|
|
|
|
|
{
|
|
|
|
|
const auto itr = obj.find("override");
|
|
|
|
|
if (itr != obj.end())
|
|
|
|
|
{
|
|
|
|
|
if (not itr->is_object())
|
|
|
|
|
{
|
|
|
|
|
reply(CreateJSONError(stringify("override is not an object")));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (const auto& [section, value] : itr->items())
|
|
|
|
|
{
|
|
|
|
|
if (not value.is_object())
|
|
|
|
|
{
|
|
|
|
|
reply(CreateJSONError(
|
|
|
|
|
stringify("failed to set [", section, "] section is not an object")));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (const auto& [key, value] : value.items())
|
|
|
|
|
{
|
|
|
|
|
if (not value.is_string())
|
|
|
|
|
{
|
|
|
|
|
reply(CreateJSONError(stringify(
|
|
|
|
|
"failed to set [", section, "]:", key, " value is not a string")));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
r->GetConfig()->Override(section, key, value.get<std::string>());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
const auto itr = obj.find("reload");
|
|
|
|
|
if (itr != obj.end() and itr->get<bool>())
|
|
|
|
|
{
|
|
|
|
|
r->QueueDiskIO([conf = r->GetConfig()]() { conf->Save(); });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
reply(CreateJSONResponse("OK"));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} // namespace llarp::rpc
|
|
|
|
|