diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-07 03:55:27 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-07 03:55:27 +0100 |
| commit | bbfd674e08c6b1fa4081f9c678fd220bead749d7 (patch) | |
| tree | 41c279103efda2765217a26c8164817d3db96606 /src/trackerlogic.h | |
| parent | f18339a50eed09ed47b2b22212d2a50e543e9b09 (diff) | |
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
Diffstat (limited to 'src/trackerlogic.h')
| -rw-r--r-- | src/trackerlogic.h | 15 |
1 files changed, 9 insertions, 6 deletions
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; | |||
| 165 | typedef struct ot_peerlist ot_peerlist; | 165 | typedef struct ot_peerlist ot_peerlist; |
| 166 | typedef struct { | 166 | typedef struct { |
| 167 | ot_hash hash; | 167 | ot_hash hash; |
| 168 | ot_peerlist *peer_list6; | 168 | ot_peerlist *peer_list6; /* NULL until the torrent has a v6 peer */ |
| 169 | ot_peerlist *peer_list4; | 169 | ot_peerlist *peer_list4; /* NULL until the torrent has a v4 peer */ |
| 170 | uint32_t base; /* minutes, when the torrent was last cleaned */ | ||
| 171 | uint32_t down_count; /* completed events, summed over both families */ | ||
| 170 | } ot_torrent; | 172 | } ot_torrent; |
| 171 | 173 | ||
| 172 | #include "ot_vector.h" | 174 | #include "ot_vector.h" |
| 173 | 175 | ||
| 174 | struct ot_peerlist { | 176 | struct ot_peerlist { |
| 175 | ot_time base; | 177 | uint32_t seed_count; |
| 176 | size_t seed_count; | 178 | uint32_t peer_count; |
| 177 | size_t peer_count; | ||
| 178 | size_t down_count; | ||
| 179 | /* normal peers vector or | 179 | /* normal peers vector or |
| 180 | pointer to ot_vector[32] buckets if data != NULL and space == 0 | 180 | pointer to ot_vector[32] buckets if data != NULL and space == 0 |
| 181 | */ | 181 | */ |
| @@ -183,6 +183,9 @@ struct ot_peerlist { | |||
| 183 | }; | 183 | }; |
| 184 | #define OT_PEERLIST_HASBUCKETS(peer_list) ((peer_list)->peers.size > (peer_list)->peers.space) | 184 | #define OT_PEERLIST_HASBUCKETS(peer_list) ((peer_list)->peers.size > (peer_list)->peers.space) |
| 185 | 185 | ||
| 186 | static inline uint32_t peerlist_peer_count(const ot_peerlist *peer_list) { return peer_list ? peer_list->peer_count : 0; } | ||
| 187 | static inline uint32_t peerlist_seed_count(const ot_peerlist *peer_list) { return peer_list ? peer_list->seed_count : 0; } | ||
| 188 | |||
| 186 | /* The http replies the tracker counts when it has to refuse a request. */ | 189 | /* The http replies the tracker counts when it has to refuse a request. */ |
| 187 | enum { | 190 | enum { |
| 188 | CODE_HTTPERROR_302, | 191 | CODE_HTTPERROR_302, |
