summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2024-04-07 00:06:27 +0200
committerDirk Engling <erdgeist@erdgeist.org>2024-04-07 00:06:27 +0200
commitb7b84bdec4c94c459ea67b44b829c495d6144312 (patch)
treeba5c8f503e8a5d1705f08aaadacf2cd7975f4cc0
parentdb28465e0c8b30cb7d5e4e9636d4b7a10793656c (diff)
Number of reported removed peers was too high, correct it by size of peer
-rw-r--r--ot_clean.c2
-rw-r--r--ot_vector.c4
-rw-r--r--ot_vector.h1
-rw-r--r--trackerlogic.c12
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
45 (*removed_seeders)++; 45 (*removed_seeders)++;
46 } 46 }
47 47
48 return peers - insert_point; 48 return (peers - insert_point) / peer_size;
49} 49}
50 50
51int clean_single_peer_list( ot_peerlist *peer_list, size_t peer_size ) { 51int 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 ) {
157 157
158 /* If this is being called after a unsuccessful malloc() for peer_list 158 /* If this is being called after a unsuccessful malloc() for peer_list
159 in add_peer_to_torrent, match->peer_list actually might be NULL */ 159 in add_peer_to_torrent, match->peer_list actually might be NULL */
160 if( match->peer_list6) free_peerlist( match->peer_list6 ); 160 free_peerlist( match->peer_list6 );
161 if( match->peer_list4) free_peerlist( match->peer_list4 ); 161 free_peerlist( match->peer_list4 );
162 162
163 memmove( match, match + 1, sizeof(ot_torrent) * ( end - match - 1 ) ); 163 memmove( match, match + 1, sizeof(ot_torrent) * ( end - match - 1 ) );
164 if( ( --vector->size * OT_VECTOR_SHRINK_THRESH < vector->space ) && ( vector->space >= OT_VECTOR_SHRINK_RATIO * OT_VECTOR_MIN_MEMBERS ) ) { 164 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 );
32/* For ot_clean.c */ 32/* For ot_clean.c */
33void vector_redistribute_buckets( ot_peerlist * peer_list, size_t peer_size ); 33void vector_redistribute_buckets( ot_peerlist * peer_list, size_t peer_size );
34void vector_fixup_peers( ot_vector * vector, size_t peer_size ); 34void vector_fixup_peers( ot_vector * vector, size_t peer_size );
35void vector_clean_list( ot_vector * vector, int num_buckets);
35 36
36#endif 37#endif
diff --git a/trackerlogic.c b/trackerlogic.c
index 5e32f13..11113d2 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -21,6 +21,7 @@
21 21
22/* Opentracker */ 22/* Opentracker */
23#include "trackerlogic.h" 23#include "trackerlogic.h"
24#include "ot_vector.h"
24#include "ot_mutex.h" 25#include "ot_mutex.h"
25#include "ot_stats.h" 26#include "ot_stats.h"
26#include "ot_clean.h" 27#include "ot_clean.h"
@@ -34,13 +35,10 @@ size_t return_peers_for_torrent( struct ot_workstruct * ws, ot_torrent *torrent,
34 35
35void free_peerlist( ot_peerlist *peer_list ) { 36void free_peerlist( ot_peerlist *peer_list ) {
36 if( peer_list->peers.data ) { 37 if( peer_list->peers.data ) {
37 if( OT_PEERLIST_HASBUCKETS( peer_list ) ) { 38 if( OT_PEERLIST_HASBUCKETS( peer_list ) )
38 ot_vector *bucket_list = (ot_vector*)(peer_list->peers.data); 39 vector_clean_list( (ot_vector*)peer_list->peers.data, peer_list->peers.size );
39 40 else
40 while( peer_list->peers.size-- ) 41 free( peer_list->peers.data );
41 free( bucket_list++->data );
42 }
43 free( peer_list->peers.data );
44 } 42 }
45 free( peer_list ); 43 free( peer_list );
46} 44}