From 2afc4893bf802700a1decfff57673cefc861c7e7 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Wed, 3 Apr 2024 22:25:30 +0200 Subject: Prepare opentracker for dual stack capabilities --- ot_stats.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'ot_stats.c') diff --git a/ot_stats.c b/ot_stats.c index 7d2749f..b3cc48a 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -73,13 +73,13 @@ static time_t ot_start_time; #define __LDR(P,D) ((__BYTE((P),(D))>>__SHFT((D)))&__MSK) #define __STR(P,D,V) __BYTE((P),(D))=(__BYTE((P),(D))&~(__MSK<<__SHFT((D))))|((V)<<__SHFT((D))) -#ifdef WANT_V6 -#define STATS_NETWORK_NODE_MAXDEPTH (68-STATS_NETWORK_NODE_BITWIDTH) -#define STATS_NETWORK_NODE_LIMIT (48-STATS_NETWORK_NODE_BITWIDTH) -#else +//#ifdef WANT_V6 +//#define STATS_NETWORK_NODE_MAXDEPTH (68-STATS_NETWORK_NODE_BITWIDTH) +//#define STATS_NETWORK_NODE_LIMIT (48-STATS_NETWORK_NODE_BITWIDTH) +//#else #define STATS_NETWORK_NODE_MAXDEPTH (28-STATS_NETWORK_NODE_BITWIDTH) #define STATS_NETWORK_NODE_LIMIT (24-STATS_NETWORK_NODE_BITWIDTH) -#endif +//#endif typedef union stats_network_node stats_network_node; union stats_network_node { @@ -219,12 +219,12 @@ static size_t stats_slash24s_txt( char *reply, size_t amount ) { stats_network_node *slash24s_network_counters_root = NULL; char *r=reply; int bucket; - size_t i; + size_t i, peer_size = OT_PEER_SIZE4; for( bucket=0; bucketsize; ++i ) { - ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[i] ).peer_list; + ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[i] ).peer_list4; ot_vector *bucket_list = &peer_list->peers; int num_buckets = 1; @@ -236,9 +236,11 @@ static size_t stats_slash24s_txt( char *reply, size_t amount ) { while( num_buckets-- ) { ot_peer *peers = (ot_peer*)bucket_list->data; size_t numpeers = bucket_list->size; - while( numpeers-- ) - if( stat_increase_network_count( &slash24s_network_counters_root, 0, (uintptr_t)(peers++) ) ) + while( numpeers-- ) { + if( stat_increase_network_count( &slash24s_network_counters_root, 0, (uintptr_t)(peers) ) ) goto bailout_unlock; + peers += peer_size; + } ++bucket_list; } } @@ -285,8 +287,8 @@ typedef struct { static int torrent_statter( ot_torrent *torrent, uintptr_t data ) { torrent_stats *stats = (torrent_stats*)data; stats->torrent_count++; - stats->peer_count += torrent->peer_list->peer_count; - stats->seed_count += torrent->peer_list->seed_count; + stats->peer_count += torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; + stats->seed_count += torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; return 0; } @@ -312,21 +314,23 @@ size_t stats_top_txt( char * reply, int amount ) { ot_vector *torrents_list = mutex_bucket_lock( bucket ); for( j=0; jsize; ++j ) { ot_torrent *torrent = (ot_torrent*)(torrents_list->data) + j; + size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; + size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; idx = amount - 1; - while( (idx >= 0) && ( torrent->peer_list->peer_count > top100c[idx].val ) ) + while( (idx >= 0) && ( peer_count > top100c[idx].val ) ) --idx; if ( idx++ != amount - 1 ) { memmove( top100c + idx + 1, top100c + idx, ( amount - 1 - idx ) * sizeof( ot_record ) ); memcpy( &top100c[idx].hash, &torrent->hash, sizeof(ot_hash)); - top100c[idx].val = torrent->peer_list->peer_count; + top100c[idx].val = peer_count; } idx = amount - 1; - while( (idx >= 0) && ( torrent->peer_list->seed_count > top100s[idx].val ) ) + while( (idx >= 0) && ( seed_count > top100s[idx].val ) ) --idx; if ( idx++ != amount - 1 ) { memmove( top100s + idx + 1, top100s + idx, ( amount - 1 - idx ) * sizeof( ot_record ) ); memcpy( &top100s[idx].hash, &torrent->hash, sizeof(ot_hash)); - top100s[idx].val = torrent->peer_list->seed_count; + top100s[idx].val = seed_count; } } mutex_bucket_unlock( bucket, 0 ); @@ -718,7 +722,7 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event break; case EVENT_SYNC: ot_overall_sync_count+=event_data; - break; + break; case EVENT_BUCKET_LOCKED: ot_overall_stall_count++; break; -- cgit v1.2.3