Browse Source

Number of reported removed peers was too high, correct it by size of peer

master
Dirk Engling 8 months ago
parent
commit
b7b84bdec4
  1. 2
      ot_clean.c
  2. 4
      ot_vector.c
  3. 1
      ot_vector.h
  4. 12
      trackerlogic.c

2
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)++; (*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 ) { int clean_single_peer_list( ot_peerlist *peer_list, size_t peer_size ) {

4
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 /* If this is being called after a unsuccessful malloc() for peer_list
in add_peer_to_torrent, match->peer_list actually might be NULL */ in add_peer_to_torrent, match->peer_list actually might be NULL */
if( match->peer_list6) free_peerlist( match->peer_list6 ); free_peerlist( match->peer_list6 );
if( match->peer_list4) free_peerlist( match->peer_list4 ); free_peerlist( match->peer_list4 );
memmove( match, match + 1, sizeof(ot_torrent) * ( end - match - 1 ) ); 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 ) ) { if( ( --vector->size * OT_VECTOR_SHRINK_THRESH < vector->space ) && ( vector->space >= OT_VECTOR_SHRINK_RATIO * OT_VECTOR_MIN_MEMBERS ) ) {

1
ot_vector.h

@ -32,5 +32,6 @@ void vector_remove_torrent( ot_vector *vector, ot_torrent *match );
/* For ot_clean.c */ /* For ot_clean.c */
void vector_redistribute_buckets( ot_peerlist * peer_list, size_t peer_size ); 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_fixup_peers( ot_vector * vector, size_t peer_size );
void vector_clean_list( ot_vector * vector, int num_buckets);
#endif #endif

12
trackerlogic.c

@ -21,6 +21,7 @@
/* Opentracker */ /* Opentracker */
#include "trackerlogic.h" #include "trackerlogic.h"
#include "ot_vector.h"
#include "ot_mutex.h" #include "ot_mutex.h"
#include "ot_stats.h" #include "ot_stats.h"
#include "ot_clean.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 ) { void free_peerlist( ot_peerlist *peer_list ) {
if( peer_list->peers.data ) { if( peer_list->peers.data ) {
if( OT_PEERLIST_HASBUCKETS( peer_list ) ) { if( OT_PEERLIST_HASBUCKETS( peer_list ) )
ot_vector *bucket_list = (ot_vector*)(peer_list->peers.data); vector_clean_list( (ot_vector*)peer_list->peers.data, peer_list->peers.size );
else
while( peer_list->peers.size-- ) free( peer_list->peers.data );
free( bucket_list++->data );
}
free( peer_list->peers.data );
} }
free( peer_list ); free( peer_list );
} }

Loading…
Cancel
Save