From bbfd674e08c6b1fa4081f9c678fd220bead749d7 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 7 Nov 2026 03:55:27 +0100 Subject: Start to opentracker's memory requirements * peer lists for v4 and v6 are now lazily allocated and, more importantly, will be freed once there are no more peers * The downloaded count is now per torrent and not per peer list anymore, moving in what was alignment loss, anyway * The (now) per torrent downloaded and the per peer list peer and seed count shrunk from size_t to uint32_t * A helper guards accesses to the peer and seed count to prevent null pointer dereferences * The base time also shrank from time_t to uint32_t, minutes since the epoch currently fits in 25 bits --- src/ot_stats.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ot_stats.c') diff --git a/src/ot_stats.c b/src/ot_stats.c index 9901081..c50d4e3 100644 --- a/src/ot_stats.c +++ b/src/ot_stats.c @@ -299,8 +299,8 @@ typedef struct { static int torrent_statter(ot_torrent *torrent, uintptr_t data) { torrent_stats *stats = (torrent_stats *)data; stats->torrent_count++; - stats->peer_count += torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; - stats->seed_count += torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; + stats->peer_count += peerlist_peer_count(torrent->peer_list6) + peerlist_peer_count(torrent->peer_list4); + stats->seed_count += peerlist_seed_count(torrent->peer_list6) + peerlist_seed_count(torrent->peer_list4); return 0; } @@ -343,8 +343,8 @@ void stats_top_txt(char **reply, const char *reply_end, size_t amount) { ot_vector *torrents_list = mutex_bucket_lock(bucket); for (j = 0; j < torrents_list->size; ++j) { ot_torrent *torrent = (ot_torrent *)(torrents_list->data) + j; - size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; - size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; + size_t peer_count = peerlist_peer_count(torrent->peer_list6) + peerlist_peer_count(torrent->peer_list4); + size_t seed_count = peerlist_seed_count(torrent->peer_list6) + peerlist_seed_count(torrent->peer_list4); size_t leech_count = peer_count - seed_count; stats_insert_into_highscore(peer_count, top100c, amount, &torrent->hash); -- cgit v1.3