From b40457d77491a50a407bd7fda9e3cc8a8dda00b7 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 10 Jan 2024 02:41:28 +0000 Subject: [PATCH] Disable storing messages for disconnection debug by default, and add another environment variable for logging SSB RPC messages. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4751 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/ssb.c b/src/ssb.c index d53cb754..367800dc 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -203,6 +203,7 @@ typedef struct _tf_ssb_t uint8_t priv[crypto_sign_SECRETKEYBYTES]; bool verbose; + bool store_debug_messages; int messages_stored; int blobs_stored; @@ -349,6 +350,11 @@ static void _tf_ssb_start_update_settings(tf_ssb_t* ssb, int delay_ms); 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]); @@ -374,6 +380,11 @@ static void _tf_ssb_add_debug_close(tf_ssb_t* ssb, tf_ssb_connection_t* connecti 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]); @@ -2134,6 +2145,13 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, const char* db_path { tf_ssb_t* ssb = tf_malloc(sizeof(tf_ssb_t)); memset(ssb, 0, sizeof(*ssb)); + + char buffer[8] = { 0 }; + 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); + ssb->verbose = uv_os_getenv("TF_SSB_VERBOSE", buffer, &buffer_size) == 0 && strcmp(buffer, "1") == 0; + if (context) { ssb->context = context;