From 90e000c18e6dada579234f75e90d54e59620776e Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 3 Oct 2024 12:41:45 -0400 Subject: [PATCH] ssb: Fix activity indication of muxrpc requests expiring. --- apps/ssb.json | 2 +- apps/ssb/tf-tab-connections.js | 3 ++- src/ssb.c | 33 ++++++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/apps/ssb.json b/apps/ssb.json index f6d7bcc5..cc9d61e4 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🐌", - "previous": "&nPhjx+lscaqxp3pwcpLlQ2HyJDPQPssdfzcFKsPEMsI=.sha256" + "previous": "&PK+UixgYQEYFKKPJ3BVacSKaDRRjiNO6M/fmgzDJaRM=.sha256" } diff --git a/apps/ssb/tf-tab-connections.js b/apps/ssb/tf-tab-connections.js index 865e0564..da424002 100644 --- a/apps/ssb/tf-tab-connections.js +++ b/apps/ssb/tf-tab-connections.js @@ -137,7 +137,8 @@ class TfTabConnectionsElement extends LitElement { ${requests.map( (x) => html` ${x.request_number > 0 ? '🟩' : '🟥'} ${x.name} data; - _tf_ssb_notify_connections_changed(ssb, k_tf_ssb_change_update, NULL); + time_t now = time(NULL); + for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next) + { + bool any_changed = false; + bool last_notified_active = (now - connection->last_notified_active) * 1000 < k_rpc_active_ms; + for (int i = 0; i < connection->requests_count; i++) + { + bool last_active = (now - connection->requests[i].last_active) * 1000 <= k_rpc_active_ms; + if (last_active != last_notified_active) + { + any_changed = true; + } + } + if (any_changed) + { + _tf_ssb_notify_connections_changed(ssb, k_tf_ssb_change_update, connection); + connection->last_notified_active = now; + } + } } void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t request_number, const char* name, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, @@ -692,13 +713,14 @@ void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t requ { tf_ssb_request_t* existing = connection->requests_count ? bsearch(&request_number, connection->requests, connection->requests_count, sizeof(tf_ssb_request_t), _request_compare) : NULL; + time_t now = time(NULL); if (existing) { assert(!existing->callback); assert(!existing->cleanup); assert(!existing->user_data); assert(!existing->dependent_connection); - existing->last_active = time(NULL); + existing->last_active = now; existing->callback = callback; existing->cleanup = cleanup; existing->user_data = user_data; @@ -713,7 +735,7 @@ void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t requ .cleanup = cleanup, .user_data = user_data, .dependent_connection = dependent_connection, - .last_active = time(NULL), + .last_active = now, }; snprintf(request.name, sizeof(request.name), "%s", name); int index = tf_util_insert_index(&request_number, connection->requests, connection->requests_count, sizeof(tf_ssb_request_t), _request_compare); @@ -728,9 +750,10 @@ void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t requ } if (uv_timer_get_due_in(&connection->ssb->request_activity_timer) == 0) { - uv_timer_start(&connection->ssb->request_activity_timer, _tf_ssb_request_activity_timer, 3000, 0); + uv_timer_start(&connection->ssb->request_activity_timer, _tf_ssb_request_activity_timer, k_rpc_active_ms, 0); } _tf_ssb_notify_connections_changed(connection->ssb, k_tf_ssb_change_update, connection); + connection->last_notified_active = now; } static int _message_request_compare(const void* a, const void* b) @@ -2231,7 +2254,7 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, const char* db_path ssb->request_activity_timer.data = ssb; uv_timer_init(ssb->loop, &ssb->request_activity_timer); - uv_timer_start(&ssb->request_activity_timer, _tf_ssb_request_activity_timer, 3000, 0); + uv_timer_start(&ssb->request_activity_timer, _tf_ssb_request_activity_timer, k_rpc_active_ms, 0); uv_unref((uv_handle_t*)&ssb->request_activity_timer); if (!_tf_ssb_load_keys(ssb))