From b7b84bdec4c94c459ea67b44b829c495d6144312 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 7 Apr 2024 00:06:27 +0200 Subject: [PATCH] Number of reported removed peers was too high, correct it by size of peer --- ot_clean.c | 2 +- ot_vector.c | 4 ++-- ot_vector.h | 1 + trackerlogic.c | 12 +++++------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ot_clean.c b/ot_clean.c index 3b494f4..739e785 100644 --- a/ot_clean.c +++ b/ot_clean.c @@ -45,7 +45,7 @@ static ssize_t clean_single_bucket( ot_peer *peers, size_t peer_count, size_t pe (*removed_seeders)++; } - return peers - insert_point; + return (peers - insert_point) / peer_size; } int clean_single_peer_list( ot_peerlist *peer_list, size_t peer_size ) { diff --git a/ot_vector.c b/ot_vector.c index 36b326a..479e832 100644 --- a/ot_vector.c +++ b/ot_vector.c @@ -157,8 +157,8 @@ void vector_remove_torrent( ot_vector *vector, ot_torrent *match ) { /* If this is being called after a unsuccessful malloc() for peer_list in add_peer_to_torrent, match->peer_list actually might be NULL */ - if( match->peer_list6) free_peerlist( match->peer_list6 ); - if( match->peer_list4) free_peerlist( match->peer_list4 ); + free_peerlist( match->peer_list6 ); + free_peerlist( match->peer_list4 ); memmove( match, match + 1, sizeof(ot_torrent) * ( end - match - 1 ) ); if( ( --vector->size * OT_VECTOR_SHRINK_THRESH < vector->space ) && ( vector->space >= OT_VECTOR_SHRINK_RATIO * OT_VECTOR_MIN_MEMBERS ) ) { diff --git a/ot_vector.h b/ot_vector.h index f60c291..37e2592 100644 --- a/ot_vector.h +++ b/ot_vector.h @@ -32,5 +32,6 @@ void vector_remove_torrent( ot_vector *vector, ot_torrent *match ); /* For ot_clean.c */ void vector_redistribute_buckets( ot_peerlist * peer_list, size_t peer_size ); void vector_fixup_peers( ot_vector * vector, size_t peer_size ); +void vector_clean_list( ot_vector * vector, int num_buckets); #endif diff --git a/trackerlogic.c b/trackerlogic.c index 5e32f13..11113d2 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -21,6 +21,7 @@ /* Opentracker */ #include "trackerlogic.h" +#include "ot_vector.h" #include "ot_mutex.h" #include "ot_stats.h" #include "ot_clean.h" @@ -34,13 +35,10 @@ size_t return_peers_for_torrent( struct ot_workstruct * ws, ot_torrent *torrent, void free_peerlist( ot_peerlist *peer_list ) { if( peer_list->peers.data ) { - if( OT_PEERLIST_HASBUCKETS( peer_list ) ) { - ot_vector *bucket_list = (ot_vector*)(peer_list->peers.data); - - while( peer_list->peers.size-- ) - free( bucket_list++->data ); - } - free( peer_list->peers.data ); + if( OT_PEERLIST_HASBUCKETS( peer_list ) ) + vector_clean_list( (ot_vector*)peer_list->peers.data, peer_list->peers.size ); + else + free( peer_list->peers.data ); } free( peer_list ); }