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/trackerlogic.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/trackerlogic.h') diff --git a/src/trackerlogic.h b/src/trackerlogic.h index 241b6a7..6b53406 100644 --- a/src/trackerlogic.h +++ b/src/trackerlogic.h @@ -165,17 +165,17 @@ struct ot_peerlist; typedef struct ot_peerlist ot_peerlist; typedef struct { ot_hash hash; - ot_peerlist *peer_list6; - ot_peerlist *peer_list4; + ot_peerlist *peer_list6; /* NULL until the torrent has a v6 peer */ + ot_peerlist *peer_list4; /* NULL until the torrent has a v4 peer */ + uint32_t base; /* minutes, when the torrent was last cleaned */ + uint32_t down_count; /* completed events, summed over both families */ } ot_torrent; #include "ot_vector.h" struct ot_peerlist { - ot_time base; - size_t seed_count; - size_t peer_count; - size_t down_count; + uint32_t seed_count; + uint32_t peer_count; /* normal peers vector or pointer to ot_vector[32] buckets if data != NULL and space == 0 */ @@ -183,6 +183,9 @@ struct ot_peerlist { }; #define OT_PEERLIST_HASBUCKETS(peer_list) ((peer_list)->peers.size > (peer_list)->peers.space) +static inline uint32_t peerlist_peer_count(const ot_peerlist *peer_list) { return peer_list ? peer_list->peer_count : 0; } +static inline uint32_t peerlist_seed_count(const ot_peerlist *peer_list) { return peer_list ? peer_list->seed_count : 0; } + /* The http replies the tracker counts when it has to refuse a request. */ enum { CODE_HTTPERROR_302, -- cgit v1.3