From 50089f72c69e23bb3c7b6b5fdd94d21d45d4ab9a Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 13 Nov 2024 19:15:59 -0500 Subject: [PATCH] ssb: We can show what state a connection is in. --- src/ssb.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ssb.c b/src/ssb.c index 2f552696..39d28ac8 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -389,6 +389,23 @@ static void _tf_ssb_start_update_settings(tf_ssb_t* ssb); static void _tf_ssb_update_settings(tf_ssb_t* ssb); static void _tf_ssb_write(tf_ssb_connection_t* connection, void* data, size_t size); +static const char* _tf_ssb_connection_state_to_string(tf_ssb_state_t state) +{ + switch (state) + { + case k_tf_ssb_state_invalid: return "invalid"; + case k_tf_ssb_state_connected: return "connected"; + case k_tf_ssb_state_sent_hello: return "sent hello"; + case k_tf_ssb_state_sent_identity: return "sent identity"; + case k_tf_ssb_state_verified: return "verified"; + case k_tf_ssb_state_server_wait_hello: return "server wait hello"; + case k_tf_ssb_state_server_wait_client_identity: return "server wait client identity"; + case k_tf_ssb_state_server_verified: return "server verified"; + case k_tf_ssb_state_closing: return "closing"; + default: return "unknown"; + } +} + static void _tf_ssb_add_debug_close(tf_ssb_t* ssb, tf_ssb_connection_t* connection, const char* reason) { if (!ssb->store_debug_messages) @@ -2731,7 +2748,7 @@ static tf_ssb_connection_t* _tf_ssb_connection_create( char id[k_id_base64_len]; tf_ssb_id_bin_to_str(id, sizeof(id), public_key); char reason[1024]; - snprintf(reason, sizeof(reason), "Already connected to %s (state = %d).", id, connection->state); + snprintf(reason, sizeof(reason), "Already connected to %s (%s).", id, _tf_ssb_connection_state_to_string(connection->state)); callback(NULL, reason, user_data); } return NULL;