ssb: Strip out the old disconnection debug information.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 20m15s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 20m15s
This commit is contained in:
parent
fb0e4060cd
commit
c85dd2655c
@ -738,25 +738,6 @@ static void _httpd_endpoint_mem(tf_http_request_t* request)
|
|||||||
tf_free(response);
|
tf_free(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _httpd_endpoint_disconnections(tf_http_request_t* request)
|
|
||||||
{
|
|
||||||
if (_httpd_redirect(request))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tf_task_t* task = request->user_data;
|
|
||||||
char* response = tf_task_get_disconnections(task);
|
|
||||||
const char* headers[] = {
|
|
||||||
"Content-Type",
|
|
||||||
"application/json; charset=utf-8",
|
|
||||||
"Access-Control-Allow-Origin",
|
|
||||||
"*",
|
|
||||||
};
|
|
||||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, response ? strlen(response) : 0);
|
|
||||||
tf_free(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _httpd_endpoint_hitches(tf_http_request_t* request)
|
static void _httpd_endpoint_hitches(tf_http_request_t* request)
|
||||||
{
|
{
|
||||||
if (_httpd_redirect(request))
|
if (_httpd_redirect(request))
|
||||||
@ -2317,7 +2298,6 @@ void tf_httpd_register(JSContext* context)
|
|||||||
|
|
||||||
tf_http_add_handler(http, "/robots.txt", _httpd_endpoint_robots_txt, NULL, NULL);
|
tf_http_add_handler(http, "/robots.txt", _httpd_endpoint_robots_txt, NULL, NULL);
|
||||||
tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, NULL, task);
|
tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, NULL, task);
|
||||||
tf_http_add_handler(http, "/disconnections", _httpd_endpoint_disconnections, NULL, task);
|
|
||||||
tf_http_add_handler(http, "/hitches", _httpd_endpoint_hitches, NULL, task);
|
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, "/mem", _httpd_endpoint_mem, NULL, task);
|
||||||
tf_http_add_handler(http, "/trace", _httpd_endpoint_trace, NULL, task);
|
tf_http_add_handler(http, "/trace", _httpd_endpoint_trace, NULL, task);
|
||||||
|
136
src/ssb.c
136
src/ssb.c
@ -71,8 +71,6 @@ enum
|
|||||||
{
|
{
|
||||||
k_connections_changed_callbacks_max = 8,
|
k_connections_changed_callbacks_max = 8,
|
||||||
k_tf_ssb_rpc_message_body_length_max = 1 * 1024 * 1024,
|
k_tf_ssb_rpc_message_body_length_max = 1 * 1024 * 1024,
|
||||||
k_debug_close_message_count = 256,
|
|
||||||
k_debug_close_connection_count = 32,
|
|
||||||
k_seed_expire_seconds = 10 * 60,
|
k_seed_expire_seconds = 10 * 60,
|
||||||
k_seed_check_interval_seconds = 5 * 60,
|
k_seed_check_interval_seconds = 5 * 60,
|
||||||
k_udp_discovery_expires_seconds = 10,
|
k_udp_discovery_expires_seconds = 10,
|
||||||
@ -84,24 +82,6 @@ typedef struct _tf_ssb_broadcast_t tf_ssb_broadcast_t;
|
|||||||
typedef struct _tf_ssb_connection_t tf_ssb_connection_t;
|
typedef struct _tf_ssb_connection_t tf_ssb_connection_t;
|
||||||
typedef struct _tf_ssb_request_t tf_ssb_request_t;
|
typedef struct _tf_ssb_request_t tf_ssb_request_t;
|
||||||
|
|
||||||
typedef struct _tf_ssb_debug_message_t
|
|
||||||
{
|
|
||||||
bool outgoing;
|
|
||||||
int flags;
|
|
||||||
int32_t request_number;
|
|
||||||
time_t timestamp;
|
|
||||||
size_t size;
|
|
||||||
uint8_t data[];
|
|
||||||
} tf_ssb_debug_message_t;
|
|
||||||
|
|
||||||
typedef struct _tf_ssb_debug_close_t
|
|
||||||
{
|
|
||||||
char id[k_id_base64_len];
|
|
||||||
char tunnel[k_id_base64_len];
|
|
||||||
char reason[128];
|
|
||||||
tf_ssb_debug_message_t* messages[k_debug_close_message_count];
|
|
||||||
} tf_ssb_debug_close_t;
|
|
||||||
|
|
||||||
typedef struct _tf_ssb_request_t
|
typedef struct _tf_ssb_request_t
|
||||||
{
|
{
|
||||||
char name[256];
|
char name[256];
|
||||||
@ -218,7 +198,6 @@ typedef struct _tf_ssb_t
|
|||||||
uint8_t priv[crypto_sign_SECRETKEYBYTES];
|
uint8_t priv[crypto_sign_SECRETKEYBYTES];
|
||||||
|
|
||||||
bool verbose;
|
bool verbose;
|
||||||
bool store_debug_messages;
|
|
||||||
bool shutting_down;
|
bool shutting_down;
|
||||||
bool shutting_down_deferred;
|
bool shutting_down_deferred;
|
||||||
|
|
||||||
@ -252,8 +231,6 @@ typedef struct _tf_ssb_t
|
|||||||
tf_ssb_broadcasts_changed_callback_node_t* broadcasts_changed;
|
tf_ssb_broadcasts_changed_callback_node_t* broadcasts_changed;
|
||||||
int broadcasts_changed_count;
|
int broadcasts_changed_count;
|
||||||
|
|
||||||
tf_ssb_debug_close_t debug_close[k_debug_close_connection_count];
|
|
||||||
|
|
||||||
int32_t thread_busy_count;
|
int32_t thread_busy_count;
|
||||||
int32_t thread_busy_max;
|
int32_t thread_busy_max;
|
||||||
|
|
||||||
@ -356,7 +333,6 @@ typedef struct _tf_ssb_connection_t
|
|||||||
tf_ssb_connection_scheduled_t* scheduled;
|
tf_ssb_connection_scheduled_t* scheduled;
|
||||||
int scheduled_count;
|
int scheduled_count;
|
||||||
|
|
||||||
tf_ssb_debug_message_t* debug_messages[k_debug_close_message_count];
|
|
||||||
int ref_count;
|
int ref_count;
|
||||||
|
|
||||||
int read_back_pressure;
|
int read_back_pressure;
|
||||||
@ -417,63 +393,6 @@ static const char* _tf_ssb_connection_state_to_string(tf_ssb_state_t state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tf_ssb_add_debug_close(tf_ssb_t* ssb, tf_ssb_connection_t* connection, const char* reason)
|
|
||||||
{
|
|
||||||
if (!ssb->store_debug_messages)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < k_debug_close_message_count; i++)
|
|
||||||
{
|
|
||||||
tf_free(ssb->debug_close[k_debug_close_connection_count - 1].messages[i]);
|
|
||||||
}
|
|
||||||
for (int i = k_debug_close_connection_count - 1; i > 0; i--)
|
|
||||||
{
|
|
||||||
ssb->debug_close[i] = ssb->debug_close[i - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
tf_ssb_id_bin_to_str(ssb->debug_close[0].id, sizeof(ssb->debug_close[0].id), connection->serverpub);
|
|
||||||
if (connection->tunnel_connection)
|
|
||||||
{
|
|
||||||
tf_ssb_id_bin_to_str(ssb->debug_close[0].tunnel, sizeof(ssb->debug_close[0].tunnel), connection->tunnel_connection->serverpub);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memset(ssb->debug_close[0].tunnel, 0, sizeof(ssb->debug_close[0].tunnel));
|
|
||||||
}
|
|
||||||
memcpy(ssb->debug_close[0].messages, connection->debug_messages, sizeof(connection->debug_messages));
|
|
||||||
memset(connection->debug_messages, 0, sizeof(connection->debug_messages));
|
|
||||||
snprintf(ssb->debug_close[0].reason, sizeof(ssb->debug_close[0].reason), "%s", reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _tf_ssb_connection_add_debug_message(tf_ssb_connection_t* connection, bool outgoing, int flags, int32_t request_number, const uint8_t* data, size_t size)
|
|
||||||
{
|
|
||||||
if (!connection->ssb->store_debug_messages)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connection->debug_messages[k_debug_close_message_count - 1])
|
|
||||||
{
|
|
||||||
tf_free(connection->debug_messages[k_debug_close_message_count - 1]);
|
|
||||||
}
|
|
||||||
for (int i = k_debug_close_message_count - 1; i > 0; i--)
|
|
||||||
{
|
|
||||||
connection->debug_messages[i] = connection->debug_messages[i - 1];
|
|
||||||
}
|
|
||||||
tf_ssb_debug_message_t* message = tf_malloc(sizeof(tf_ssb_debug_message_t) + size);
|
|
||||||
*message = (tf_ssb_debug_message_t) {
|
|
||||||
.outgoing = outgoing,
|
|
||||||
.flags = flags,
|
|
||||||
.request_number = request_number,
|
|
||||||
.timestamp = time(NULL),
|
|
||||||
.size = size,
|
|
||||||
};
|
|
||||||
memcpy(message + 1, data, size);
|
|
||||||
connection->debug_messages[0] = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _tf_ssb_connection_send_close(tf_ssb_connection_t* connection)
|
static void _tf_ssb_connection_send_close(tf_ssb_connection_t* connection)
|
||||||
{
|
{
|
||||||
uint8_t message_enc[34];
|
uint8_t message_enc[34];
|
||||||
@ -499,7 +418,6 @@ static void _tf_ssb_connection_close(tf_ssb_connection_t* connection, const char
|
|||||||
else if (connection->state == k_tf_ssb_state_verified || connection->state == k_tf_ssb_state_server_verified)
|
else if (connection->state == k_tf_ssb_state_verified || connection->state == k_tf_ssb_state_server_verified)
|
||||||
{
|
{
|
||||||
tf_printf("Connection %s %p is closing: %s.\n", connection->name, connection, reason);
|
tf_printf("Connection %s %p is closing: %s.\n", connection->name, connection, reason);
|
||||||
_tf_ssb_add_debug_close(connection->ssb, connection, reason);
|
|
||||||
connection->state = k_tf_ssb_state_closing;
|
connection->state = k_tf_ssb_state_closing;
|
||||||
_tf_ssb_connection_send_close(connection);
|
_tf_ssb_connection_send_close(connection);
|
||||||
}
|
}
|
||||||
@ -925,7 +843,6 @@ bool tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags,
|
|||||||
(flags & k_ssb_rpc_flag_end_error) ? "true" : "false", (flags & k_ssb_rpc_flag_stream) ? "true" : "false", k_ssb_type_names[flags & k_ssb_rpc_mask_type],
|
(flags & k_ssb_rpc_flag_end_error) ? "true" : "false", (flags & k_ssb_rpc_flag_stream) ? "true" : "false", k_ssb_type_names[flags & k_ssb_rpc_mask_type],
|
||||||
request_number, size, (flags & k_ssb_rpc_mask_type) == k_ssb_rpc_flag_binary ? 0 : (int)size, message);
|
request_number, size, (flags & k_ssb_rpc_mask_type) == k_ssb_rpc_flag_binary ? 0 : (int)size, message);
|
||||||
}
|
}
|
||||||
_tf_ssb_connection_add_debug_message(connection, true, flags & k_ssb_rpc_mask_send, request_number, message, size);
|
|
||||||
_tf_ssb_connection_box_stream_send(connection, combined, 1 + 2 * sizeof(uint32_t) + size);
|
_tf_ssb_connection_box_stream_send(connection, combined, 1 + 2 * sizeof(uint32_t) + size);
|
||||||
tf_free(combined);
|
tf_free(combined);
|
||||||
connection->ssb->rpc_out++;
|
connection->ssb->rpc_out++;
|
||||||
@ -1659,7 +1576,6 @@ static void _tf_ssb_name_to_string(JSContext* context, JSValue object, char* buf
|
|||||||
static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const uint8_t* message, size_t size)
|
static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const uint8_t* message, size_t size)
|
||||||
{
|
{
|
||||||
connection->ssb->rpc_in++;
|
connection->ssb->rpc_in++;
|
||||||
_tf_ssb_connection_add_debug_message(connection, false, flags, request_number, message, size);
|
|
||||||
bool close_connection = false;
|
bool close_connection = false;
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
{
|
{
|
||||||
@ -2024,12 +1940,6 @@ static void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const ch
|
|||||||
connection->message_requests = NULL;
|
connection->message_requests = NULL;
|
||||||
connection->message_requests_count = 0;
|
connection->message_requests_count = 0;
|
||||||
|
|
||||||
for (int i = 0; i < k_debug_close_message_count; i++)
|
|
||||||
{
|
|
||||||
tf_free(connection->debug_messages[i]);
|
|
||||||
connection->debug_messages[i] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (--connection->ssb->connection_ref_count == 0 && connection->ssb->shutting_down_deferred)
|
if (--connection->ssb->connection_ref_count == 0 && connection->ssb->shutting_down_deferred)
|
||||||
{
|
{
|
||||||
tf_ssb_destroy(connection->ssb);
|
tf_ssb_destroy(connection->ssb);
|
||||||
@ -2298,7 +2208,6 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, const char* db_path
|
|||||||
|
|
||||||
char buffer[8] = { 0 };
|
char buffer[8] = { 0 };
|
||||||
size_t buffer_size = sizeof(buffer);
|
size_t buffer_size = sizeof(buffer);
|
||||||
ssb->store_debug_messages = uv_os_getenv("TF_DEBUG_CLOSE", buffer, &buffer_size) == 0 && strcmp(buffer, "1") == 0;
|
|
||||||
buffer_size = sizeof(buffer);
|
buffer_size = sizeof(buffer);
|
||||||
ssb->verbose = uv_os_getenv("TF_SSB_VERBOSE", buffer, &buffer_size) == 0 && strcmp(buffer, "1") == 0;
|
ssb->verbose = uv_os_getenv("TF_SSB_VERBOSE", buffer, &buffer_size) == 0 && strcmp(buffer, "1") == 0;
|
||||||
|
|
||||||
@ -2692,13 +2601,6 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
|
|||||||
ssb->broadcasts_count--;
|
ssb->broadcasts_count--;
|
||||||
tf_free(broadcast);
|
tf_free(broadcast);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < k_debug_close_connection_count; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < k_debug_close_message_count; j++)
|
|
||||||
{
|
|
||||||
tf_free(ssb->debug_close[i].messages[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < ssb->db_readers_count; i++)
|
for (int i = 0; i < ssb->db_readers_count; i++)
|
||||||
{
|
{
|
||||||
sqlite3_close(ssb->db_readers[i]);
|
sqlite3_close(ssb->db_readers[i]);
|
||||||
@ -3968,44 +3870,6 @@ void tf_ssb_connection_set_ebt_request_number(tf_ssb_connection_t* connection, i
|
|||||||
connection->ebt_request_number = request_number;
|
connection->ebt_request_number = request_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue tf_ssb_get_disconnection_debug(tf_ssb_t* ssb, JSContext* context)
|
|
||||||
{
|
|
||||||
JSValue result = JS_NewObject(context);
|
|
||||||
JSValue disconnections = JS_NewArray(context);
|
|
||||||
for (int i = 0; i < k_debug_close_connection_count; i++)
|
|
||||||
{
|
|
||||||
JSValue disconnection = JS_NewObject(context);
|
|
||||||
if (*ssb->debug_close[i].id)
|
|
||||||
{
|
|
||||||
JS_SetPropertyStr(context, disconnection, "id", JS_NewString(context, ssb->debug_close[i].id));
|
|
||||||
if (*ssb->debug_close[i].tunnel)
|
|
||||||
{
|
|
||||||
JS_SetPropertyStr(context, disconnection, "tunnel", JS_NewString(context, ssb->debug_close[i].tunnel));
|
|
||||||
}
|
|
||||||
JS_SetPropertyStr(context, disconnection, "reason", JS_NewString(context, ssb->debug_close[i].reason));
|
|
||||||
JSValue messages = JS_NewArray(context);
|
|
||||||
for (int j = 0; j < k_debug_close_message_count; j++)
|
|
||||||
{
|
|
||||||
if (ssb->debug_close[i].messages[j])
|
|
||||||
{
|
|
||||||
JSValue message = JS_NewObject(context);
|
|
||||||
JS_SetPropertyStr(context, message, "direction", JS_NewString(context, ssb->debug_close[i].messages[j]->outgoing ? "out" : "in"));
|
|
||||||
JS_SetPropertyStr(context, message, "flags", JS_NewInt32(context, ssb->debug_close[i].messages[j]->flags));
|
|
||||||
JS_SetPropertyStr(context, message, "request_number", JS_NewInt32(context, ssb->debug_close[i].messages[j]->request_number));
|
|
||||||
JS_SetPropertyStr(context, message, "timestamp", JS_NewFloat64(context, ssb->debug_close[i].messages[j]->timestamp));
|
|
||||||
JS_SetPropertyStr(
|
|
||||||
context, message, "payload", JS_NewStringLen(context, (const char*)ssb->debug_close[i].messages[j]->data, ssb->debug_close[i].messages[j]->size));
|
|
||||||
JS_SetPropertyUint32(context, messages, j, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
JS_SetPropertyStr(context, disconnection, "messages", messages);
|
|
||||||
}
|
|
||||||
JS_SetPropertyUint32(context, disconnections, i, disconnection);
|
|
||||||
}
|
|
||||||
JS_SetPropertyStr(context, result, "disconnections", disconnections);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tf_ssb_record_thread_busy(tf_ssb_t* ssb, bool busy)
|
void tf_ssb_record_thread_busy(tf_ssb_t* ssb, bool busy)
|
||||||
{
|
{
|
||||||
int32_t busy_value = __atomic_add_fetch(&ssb->thread_busy_count, busy ? 1 : -1, __ATOMIC_RELAXED);
|
int32_t busy_value = __atomic_add_fetch(&ssb->thread_busy_count, busy ? 1 : -1, __ATOMIC_RELAXED);
|
||||||
|
@ -947,14 +947,6 @@ void tf_ssb_get_stats(tf_ssb_t* ssb, tf_ssb_stats_t* out_stats);
|
|||||||
*/
|
*/
|
||||||
tf_ssb_blob_wants_t* tf_ssb_connection_get_blob_wants_state(tf_ssb_connection_t* connection);
|
tf_ssb_blob_wants_t* tf_ssb_connection_get_blob_wants_state(tf_ssb_connection_t* connection);
|
||||||
|
|
||||||
/**
|
|
||||||
** Get a report of information about recent disconnections.
|
|
||||||
** @param ssb The SSB instance.
|
|
||||||
** @param context A JS context.
|
|
||||||
** @return Information about disconnections.
|
|
||||||
*/
|
|
||||||
JSValue tf_ssb_get_disconnection_debug(tf_ssb_t* ssb, JSContext* context);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Record whether the calling thread is busy.
|
** Record whether the calling thread is busy.
|
||||||
** @param ssb The SSB instance.
|
** @param ssb The SSB instance.
|
||||||
|
15
src/task.c
15
src/task.c
@ -932,21 +932,6 @@ char* tf_task_get_hitches(tf_task_t* task)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* tf_task_get_disconnections(tf_task_t* task)
|
|
||||||
{
|
|
||||||
JSContext* context = task->_context;
|
|
||||||
tf_trace_begin(task->_trace, __func__);
|
|
||||||
JSValue object = tf_ssb_get_disconnection_debug(task->_ssb, context);
|
|
||||||
JSValue json = JS_JSONStringify(context, object, JS_NULL, JS_NewInt32(context, 2));
|
|
||||||
const char* string = JS_ToCString(context, json);
|
|
||||||
char* result = tf_strdup(string);
|
|
||||||
JS_FreeCString(context, string);
|
|
||||||
JS_FreeValue(context, json);
|
|
||||||
JS_FreeValue(context, object);
|
|
||||||
tf_trace_end(task->_trace);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||||
{
|
{
|
||||||
tf_task_t* task = JS_GetContextOpaque(context);
|
tf_task_t* task = JS_GetContextOpaque(context);
|
||||||
|
@ -310,14 +310,6 @@ void tf_task_remove_child(tf_task_t* task, tf_taskstub_t* child);
|
|||||||
*/
|
*/
|
||||||
bool tf_task_send_error_to_parent(tf_task_t* task, JSValue error);
|
bool tf_task_send_error_to_parent(tf_task_t* task, JSValue error);
|
||||||
|
|
||||||
/**
|
|
||||||
** Get a report of recent disconnections.
|
|
||||||
** @param task The task.
|
|
||||||
** @return A JSON representation of recent disconnections that must be freed
|
|
||||||
** with tf_free().
|
|
||||||
*/
|
|
||||||
char* tf_task_get_disconnections(tf_task_t* task);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Get a report of miscellaneous debug information.
|
** Get a report of miscellaneous debug information.
|
||||||
** @param task The task.
|
** @param task The task.
|
||||||
|
Loading…
Reference in New Issue
Block a user