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/ot_stats.c | |
| 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/ot_stats.c')
| -rw-r--r-- | src/ot_stats.c | 8 |
1 files changed, 4 insertions, 4 deletions
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 { | |||
| 299 | static int torrent_statter(ot_torrent *torrent, uintptr_t data) { | 299 | static int torrent_statter(ot_torrent *torrent, uintptr_t data) { |
| 300 | torrent_stats *stats = (torrent_stats *)data; | 300 | torrent_stats *stats = (torrent_stats *)data; |
| 301 | stats->torrent_count++; | 301 | stats->torrent_count++; |
| 302 | stats->peer_count += torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; | 302 | stats->peer_count += peerlist_peer_count(torrent->peer_list6) + peerlist_peer_count(torrent->peer_list4); |
| 303 | stats->seed_count += torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; | 303 | stats->seed_count += peerlist_seed_count(torrent->peer_list6) + peerlist_seed_count(torrent->peer_list4); |
| 304 | return 0; | 304 | return 0; |
| 305 | } | 305 | } |
| 306 | 306 | ||
| @@ -343,8 +343,8 @@ void stats_top_txt(char **reply, const char *reply_end, size_t amount) { | |||
| 343 | ot_vector *torrents_list = mutex_bucket_lock(bucket); | 343 | ot_vector *torrents_list = mutex_bucket_lock(bucket); |
| 344 | for (j = 0; j < torrents_list->size; ++j) { | 344 | for (j = 0; j < torrents_list->size; ++j) { |
| 345 | ot_torrent *torrent = (ot_torrent *)(torrents_list->data) + j; | 345 | ot_torrent *torrent = (ot_torrent *)(torrents_list->data) + j; |
| 346 | size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; | 346 | size_t peer_count = peerlist_peer_count(torrent->peer_list6) + peerlist_peer_count(torrent->peer_list4); |
| 347 | size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; | 347 | size_t seed_count = peerlist_seed_count(torrent->peer_list6) + peerlist_seed_count(torrent->peer_list4); |
| 348 | size_t leech_count = peer_count - seed_count; | 348 | size_t leech_count = peer_count - seed_count; |
| 349 | 349 | ||
| 350 | stats_insert_into_highscore(peer_count, top100c, amount, &torrent->hash); | 350 | stats_insert_into_highscore(peer_count, top100c, amount, &torrent->hash); |
