Skip to content

Commit

Permalink
add authenticated API /api/diag/proxy/neighbor/list endpoint
Browse files Browse the repository at this point in the history
- returns all neighbors (connection initiators) and their stats
  • Loading branch information
astibal committed Apr 20, 2024
1 parent d10efe8 commit 3fa0495
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/service/httpd/diag/daig_proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <ext/lmhpp/include/lmhttpd.hpp>
#include <service/httpd/util.hpp>
#include <service/http/jsonize.hpp>
#include <proxy/nbrhood.hpp>


static nlohmann::json json_proxy_session_list(struct MHD_Connection * connection, std::string const& meth, std::string const& req) {
Expand All @@ -56,4 +57,15 @@ static nlohmann::json json_proxy_session_list(struct MHD_Connection * connection

return SmithProxy::instance().API.proxy_session_list_json(oid, flag_active_only, flag_tlsinfo, flag_verbose);

}
}

static nlohmann::json json_proxy_neighbor_list(struct MHD_Connection * connection, std::string const& meth, std::string const& req) {

auto oid = connection_ull_param(connection, "oid", 0ULL);
using namespace jsonize;

bool flag_verbose = load_json_params<bool>(req, "verbose").value_or(false);

return NbrHood::instance().to_json();

}
11 changes: 11 additions & 0 deletions src/service/httpd/handlers/dispatchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ namespace sx::webserver::dispatchers {
handler.Content_Type = "application/json";
server.addController(&handler);
}

for(auto const& meth: {"GET", "POST"}) {
static Http_Responder handler(
meth,
"/api/diag/proxy/neighbor/list",
authorized::token_protected<json>(json_proxy_neighbor_list)
);
handler.Content_Type = "application/json";
server.addController(&handler);
}

}

void controller_add_uni(lmh::WebServer &server) {
Expand Down

0 comments on commit 3fa0495

Please sign in to comment.