Skip to content

Commit

Permalink
Add enhanced proxy session listing
Browse files Browse the repository at this point in the history
- new `proxy_session_connid_list_plus` is sent immediately, if action webhook responses with HTTP 202 (Accept)
  this is indication information was not complete and ping with enhanced session info is sent

- ping-plus message will be probably enhanced even further in the future

- ping-plus solves webhook applications long delay to receive ping with proxy OIDs not even having session labels

- 'ping' is useful to wipe periodically stale sessions
- 'ping-plus' can be used to "quickly" get active sessions info on webhook app start
  • Loading branch information
astibal committed Mar 12, 2024
1 parent 78c4ba9 commit 984e000
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/service/core/smithproxy_objapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,26 @@ nlohmann::json ObjAPI::proxy_session_connid_list() {
json ret;

for_each_proxy([&ret](MitmProxy const* px){
if(px) ret.push_back(px->to_connection_ID());
if(px and px->first_left() and px->first_right()) ret.push_back(px->to_connection_ID());
});

return ret;
}

nlohmann::json ObjAPI::proxy_session_connid_list_plus() {

using nlohmann::json;
json ret;

for_each_proxy([&ret](MitmProxy const* px){
if(px and px->first_left() and px->first_right())
ret.push_back(string_format("%s=%s", px->to_connection_ID().c_str(), px->to_connection_label().c_str()));
});

return ret;
}


nlohmann::json ObjAPI::proxy_session_list_json(uint64_t oid, bool active_only, bool tls_info, bool verbose) {
using nlohmann::json;
auto const& instance = SmithProxy::instance();
Expand Down
1 change: 1 addition & 0 deletions src/service/core/smithproxy_objapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct ObjAPI {

std::string instance_OID();
nlohmann::json proxy_session_connid_list();
nlohmann::json proxy_session_connid_list_plus(); // list, but append also session label
nlohmann::json proxy_session_list_json(uint64_t oid, bool active_only, bool tls_info, bool verbose);
};

29 changes: 26 additions & 3 deletions src/service/http/webhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,31 @@ namespace sx::http::webhooks {
};
sx::http::AsyncRequest::emit(
to_string(ping),
[](auto reply){
[](auto ){
// we don't need any response
});
}
}

void ping_plus() {
if(enabled) {
nlohmann::json const ping = {
{ "action", "ping" },
{"source", get_hostid() },
{"type", "proxy"},
{"instance", SmithProxy::instance().API.instance_OID() },
{"proxies", SmithProxy::instance().API.proxy_session_connid_list() },
{"proxies-plus", SmithProxy::instance().API.proxy_session_connid_list_plus() }
};
sx::http::AsyncRequest::emit(
to_string(ping),
[](auto ){
// we don't need any response
});
}
}


void neighbor_new(std::string const& address_str) {
if(enabled) {
nlohmann::json const nbr_update = {
Expand All @@ -68,10 +87,14 @@ namespace sx::http::webhooks {
{"type", "proxy"}};

msg.push_back({"details", details});

sx::http::AsyncRequest::emit(
to_string(msg),
[](auto reply) {
// we don't need response
[](sx::http::expected_reply repl) {
// if not OK but ACCEPTED, they don't have enough of information - send it
if(repl.has_value() and repl.value().first == 202) {
ping_plus();
}
});
}
}
Expand Down

0 comments on commit 984e000

Please sign in to comment.