From f2ae6db391bcb3e417e0813fbc2b32bee69f37bf Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 13 Aug 2024 16:52:11 +0200 Subject: [PATCH] Add further API debugging to top_client generation and fix an incorrect condition that skipped all clients without a name Signed-off-by: DL6ER --- src/api/stats.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/api/stats.c b/src/api/stats.c index 12024bfc5..05075a3e2 100644 --- a/src/api/stats.c +++ b/src/api/stats.c @@ -388,12 +388,26 @@ cJSON *get_top_clients(struct ftl_conn *api, const int count, // Skip invalid clients and also those managed by alias clients if(client == NULL || (!client->flags.aliasclient && client->aliasclient_id >= 0)) + { + log_debug(DEBUG_API, "Skipping client %i because %s", clientID, + client == NULL ? "it is invalid" : "it is an alias client"); continue; + } + + // Skip recycled clients + if(client->ippos == 0) + { + log_debug(DEBUG_API, "Skipping client %i because it is recycled", clientID); + continue; + } const char *client_ip = getstr(client->ippos); // Hidden client, probably due to privacy level. Skip this in the top lists if(strcmp(client_ip, HIDDEN_CLIENT) == 0) + { + log_debug(DEBUG_API, "Skipping client %i because it is hidden", clientID); continue; + } // Use either blocked or total count based on request string top_clients[added_clients].count = blocked ? client->blockedcount : client->count; @@ -405,6 +419,8 @@ cJSON *get_top_clients(struct ftl_conn *api, const int count, added_clients++; } + log_debug(DEBUG_API, "Found %u clients", added_clients); + // Unlock shared memory unlock_shm(); @@ -426,10 +442,6 @@ cJSON *get_top_clients(struct ftl_conn *api, const int count, for(unsigned int i = 0; i < added_clients; i++) { - // Skip e.g. recycled clients - if(top_clients[i].namepos == 0) - continue; - const char *client_ip = getstr(top_clients[i].ippos); const char *client_name = getstr(top_clients[i].namepos); @@ -457,7 +469,11 @@ cJSON *get_top_clients(struct ftl_conn *api, const int count, } if(skip_client || top_clients[i].count < 1) + { + log_debug(DEBUG_API, "Skipping client %s because it %s", client_ip, + skip_client ? "matches a filter" : "has no queries"); continue; + } if(clients_only) {