From dddec489b983fac68897eb14d1e720394039f47e Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 4 Feb 2025 21:32:16 -0500 Subject: [PATCH] ssb: Results of staring at unexpected shs disconnections: wire up tunnel.endpoints and blobs.createWants more correctly/thoroughly. And add slightly more context when deliberately disconnected from the remote side. --- src/ssb.c | 6 +++++- src/ssb.rpc.c | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ssb.c b/src/ssb.c index 92541fbd..ab74c6f5 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -1712,7 +1712,11 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t bool close_connection = false; if (size == 0) { - tf_ssb_connection_close(connection, "rpc recv zero"); + char buffer[256]; + const char* request_name = ""; + _tf_ssb_connection_get_request_callback(connection, -request_number, NULL, NULL, &request_name); + snprintf(buffer, sizeof(buffer), "rpc recv zero (req=%d, name=%s)", request_number, request_name); + tf_ssb_connection_close(connection, buffer); return; } else if (flags & k_ssb_rpc_flag_json) diff --git a/src/ssb.rpc.c b/src/ssb.rpc.c index 2433d639..45aed2a9 100644 --- a/src/ssb.rpc.c +++ b/src/ssb.rpc.c @@ -21,6 +21,8 @@ static void _tf_ssb_rpc_send_peers_exchange(tf_ssb_connection_t* connection); static void _tf_ssb_rpc_start_delete_blobs(tf_ssb_t* ssb, int delay_ms); static void _tf_ssb_rpc_start_delete_feeds(tf_ssb_t* ssb, int delay_ms); static void _tf_ssb_rpc_ebt_replicate_resend_clock(tf_ssb_connection_t* connection, bool skip, void* user_data); +static void _tf_ssb_rpc_connection_blobs_createWants_callback( + tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data); static void _tf_ssb_rpc_gossip_ping_callback( tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data) @@ -277,6 +279,7 @@ static void _tf_ssb_rpc_blobs_createWants( tf_ssb_connection_rpc_send_error_method_not_allowed(connection, flags, -request_number, "blobs.createWants"); return; } + tf_ssb_connection_add_request(connection, -request_number, "blobs.createWants", _tf_ssb_rpc_connection_blobs_createWants_callback, NULL, NULL, NULL); tf_ssb_blob_wants_t* blob_wants = tf_ssb_connection_get_blob_wants_state(connection); tf_ssb_add_blob_want_added_callback(ssb, _tf_ssb_rpc_blob_wants_added_callback, NULL, connection); blob_wants->request_number = request_number; @@ -457,7 +460,7 @@ static void _tf_ssb_rpc_send_endpoints(tf_ssb_t* ssb) { if (tf_ssb_connection_is_endpoint(connections[i]) && tf_ssb_connection_is_connected(connections[i])) { - int32_t request_number = tf_ssb_connection_get_ebt_request_number(connections[i]); + int32_t request_number = tf_ssb_connection_get_endpoint_request_number(connections[i]); tf_ssb_connection_rpc_send_json(connections[i], k_ssb_rpc_flag_json | k_ssb_rpc_flag_stream, -request_number, NULL, endpoints, NULL, NULL, NULL); } }