ssb: Fix activity indication of muxrpc requests expiring.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 17m54s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 17m54s
This commit is contained in:
parent
1bb9d737d8
commit
90e000c18e
@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "tildefriends-app",
|
||||
"emoji": "🐌",
|
||||
"previous": "&nPhjx+lscaqxp3pwcpLlQ2HyJDPQPssdfzcFKsPEMsI=.sha256"
|
||||
"previous": "&PK+UixgYQEYFKKPJ3BVacSKaDRRjiNO6M/fmgzDJaRM=.sha256"
|
||||
}
|
||||
|
@ -137,7 +137,8 @@ class TfTabConnectionsElement extends LitElement {
|
||||
${requests.map(
|
||||
(x) => html`
|
||||
<span
|
||||
class=${'w3-tag w3-small ' + (x.active ? 'w3-blue' : 'w3-black')}
|
||||
class=${'w3-tag w3-small ' +
|
||||
(x.active ? 'w3-theme-l3' : 'w3-theme-d3')}
|
||||
>${x.request_number > 0 ? '🟩' : '🟥'} ${x.name}
|
||||
<span
|
||||
class="w3-badge w3-white"
|
||||
|
33
src/ssb.c
33
src/ssb.c
@ -81,6 +81,7 @@ enum
|
||||
k_seed_check_interval_seconds = 5 * 60,
|
||||
k_udp_discovery_expires_seconds = 10,
|
||||
k_handshake_timeout_ms = 15000,
|
||||
k_rpc_active_ms = 3000,
|
||||
};
|
||||
|
||||
typedef struct _tf_ssb_broadcast_t tf_ssb_broadcast_t;
|
||||
@ -362,6 +363,8 @@ typedef struct _tf_ssb_connection_t
|
||||
|
||||
int read_back_pressure;
|
||||
int active_write_count;
|
||||
|
||||
time_t last_notified_active;
|
||||
} tf_ssb_connection_t;
|
||||
|
||||
static JSClassID _connection_class_id;
|
||||
@ -684,7 +687,25 @@ static bool _tf_ssb_connection_get_request_callback(tf_ssb_connection_t* connect
|
||||
static void _tf_ssb_request_activity_timer(uv_timer_t* timer)
|
||||
{
|
||||
tf_ssb_t* ssb = timer->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))
|
||||
|
Loading…
Reference in New Issue
Block a user