debug: Add an /ebt endpoint to examine the state of EBT clocks. Prevent invalid identities from getting in there, now that I see them.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 28m58s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 28m58s
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
#include "log.h"
|
||||
#include "mem.h"
|
||||
#include "ssb.db.h"
|
||||
#include "ssb.ebt.h"
|
||||
#include "ssb.h"
|
||||
#include "task.h"
|
||||
#include "tls.h"
|
||||
@ -569,6 +570,50 @@ static void _httpd_endpoint_trace(tf_http_request_t* request)
|
||||
tf_free(json);
|
||||
}
|
||||
|
||||
static void _httpd_endpoint_ebt(tf_http_request_t* request)
|
||||
{
|
||||
if (_httpd_redirect(request))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_ssb_t* ssb = tf_task_get_ssb(task);
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
|
||||
JSValue object = JS_NewObject(context);
|
||||
|
||||
tf_ssb_connection_t* connections[256];
|
||||
int connection_count = tf_ssb_get_connections(ssb, connections, tf_countof(connections));
|
||||
for (int i = 0; i < connection_count; i++)
|
||||
{
|
||||
char id[k_id_base64_len];
|
||||
tf_ssb_connection_get_id(connections[i], id, sizeof(id));
|
||||
|
||||
char key[256];
|
||||
JSValue clock = JS_NewObject(context);
|
||||
snprintf(key, sizeof(key), "%d:%s", i, id);
|
||||
|
||||
tf_ssb_ebt_t* ebt = tf_ssb_connection_get_ebt(connections[i]);
|
||||
tf_ssb_ebt_debug_clock(ebt, context, clock);
|
||||
JS_SetPropertyStr(context, object, key, clock);
|
||||
}
|
||||
|
||||
JSValue json_value = JS_JSONStringify(context, object, JS_NULL, JS_NewInt32(context, 2));
|
||||
const char* json = JS_ToCString(context, json_value);
|
||||
JS_FreeValue(context, json_value);
|
||||
|
||||
const char* headers[] = {
|
||||
"Content-Type",
|
||||
"application/json; charset=utf-8",
|
||||
"Access-Control-Allow-Origin",
|
||||
"*",
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, json, json ? strlen(json) : 0);
|
||||
JS_FreeCString(context, json);
|
||||
JS_FreeValue(context, object);
|
||||
}
|
||||
|
||||
static void _httpd_endpoint_mem(tf_http_request_t* request)
|
||||
{
|
||||
if (_httpd_redirect(request))
|
||||
@ -2387,6 +2432,7 @@ void tf_httpd_register(JSContext* context)
|
||||
tf_http_add_handler(http, "/hitches", _httpd_endpoint_hitches, NULL, task);
|
||||
tf_http_add_handler(http, "/mem", _httpd_endpoint_mem, NULL, task);
|
||||
tf_http_add_handler(http, "/trace", _httpd_endpoint_trace, NULL, task);
|
||||
tf_http_add_handler(http, "/ebt", _httpd_endpoint_ebt, NULL, task);
|
||||
|
||||
tf_http_add_handler(http, "/login/logout", _httpd_endpoint_logout, NULL, task);
|
||||
tf_http_add_handler(http, "/login/auto", _httpd_endpoint_login_auto, NULL, task);
|
||||
|
Reference in New Issue
Block a user