diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2024-04-03 22:25:30 +0200 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2024-04-03 22:25:30 +0200 |
commit | 2afc4893bf802700a1decfff57673cefc861c7e7 (patch) | |
tree | 9a0817371ac05062dbcf25107fcf5a6481feccc0 /ot_stats.c | |
parent | eb8834f7783cb85ae825976425800cd4af711263 (diff) |
Prepare opentracker for dual stack capabilities
Diffstat (limited to 'ot_stats.c')
-rw-r--r-- | ot_stats.c | 36 |
1 files changed, 20 insertions, 16 deletions
@@ -73,13 +73,13 @@ static time_t ot_start_time; | |||
73 | #define __LDR(P,D) ((__BYTE((P),(D))>>__SHFT((D)))&__MSK) | 73 | #define __LDR(P,D) ((__BYTE((P),(D))>>__SHFT((D)))&__MSK) |
74 | #define __STR(P,D,V) __BYTE((P),(D))=(__BYTE((P),(D))&~(__MSK<<__SHFT((D))))|((V)<<__SHFT((D))) | 74 | #define __STR(P,D,V) __BYTE((P),(D))=(__BYTE((P),(D))&~(__MSK<<__SHFT((D))))|((V)<<__SHFT((D))) |
75 | 75 | ||
76 | #ifdef WANT_V6 | 76 | //#ifdef WANT_V6 |
77 | #define STATS_NETWORK_NODE_MAXDEPTH (68-STATS_NETWORK_NODE_BITWIDTH) | 77 | //#define STATS_NETWORK_NODE_MAXDEPTH (68-STATS_NETWORK_NODE_BITWIDTH) |
78 | #define STATS_NETWORK_NODE_LIMIT (48-STATS_NETWORK_NODE_BITWIDTH) | 78 | //#define STATS_NETWORK_NODE_LIMIT (48-STATS_NETWORK_NODE_BITWIDTH) |
79 | #else | 79 | //#else |
80 | #define STATS_NETWORK_NODE_MAXDEPTH (28-STATS_NETWORK_NODE_BITWIDTH) | 80 | #define STATS_NETWORK_NODE_MAXDEPTH (28-STATS_NETWORK_NODE_BITWIDTH) |
81 | #define STATS_NETWORK_NODE_LIMIT (24-STATS_NETWORK_NODE_BITWIDTH) | 81 | #define STATS_NETWORK_NODE_LIMIT (24-STATS_NETWORK_NODE_BITWIDTH) |
82 | #endif | 82 | //#endif |
83 | 83 | ||
84 | typedef union stats_network_node stats_network_node; | 84 | typedef union stats_network_node stats_network_node; |
85 | union stats_network_node { | 85 | union stats_network_node { |
@@ -219,12 +219,12 @@ static size_t stats_slash24s_txt( char *reply, size_t amount ) { | |||
219 | stats_network_node *slash24s_network_counters_root = NULL; | 219 | stats_network_node *slash24s_network_counters_root = NULL; |
220 | char *r=reply; | 220 | char *r=reply; |
221 | int bucket; | 221 | int bucket; |
222 | size_t i; | 222 | size_t i, peer_size = OT_PEER_SIZE4; |
223 | 223 | ||
224 | for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { | 224 | for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { |
225 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | 225 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); |
226 | for( i=0; i<torrents_list->size; ++i ) { | 226 | for( i=0; i<torrents_list->size; ++i ) { |
227 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[i] ).peer_list; | 227 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[i] ).peer_list4; |
228 | ot_vector *bucket_list = &peer_list->peers; | 228 | ot_vector *bucket_list = &peer_list->peers; |
229 | int num_buckets = 1; | 229 | int num_buckets = 1; |
230 | 230 | ||
@@ -236,9 +236,11 @@ static size_t stats_slash24s_txt( char *reply, size_t amount ) { | |||
236 | while( num_buckets-- ) { | 236 | while( num_buckets-- ) { |
237 | ot_peer *peers = (ot_peer*)bucket_list->data; | 237 | ot_peer *peers = (ot_peer*)bucket_list->data; |
238 | size_t numpeers = bucket_list->size; | 238 | size_t numpeers = bucket_list->size; |
239 | while( numpeers-- ) | 239 | while( numpeers-- ) { |
240 | if( stat_increase_network_count( &slash24s_network_counters_root, 0, (uintptr_t)(peers++) ) ) | 240 | if( stat_increase_network_count( &slash24s_network_counters_root, 0, (uintptr_t)(peers) ) ) |
241 | goto bailout_unlock; | 241 | goto bailout_unlock; |
242 | peers += peer_size; | ||
243 | } | ||
242 | ++bucket_list; | 244 | ++bucket_list; |
243 | } | 245 | } |
244 | } | 246 | } |
@@ -285,8 +287,8 @@ typedef struct { | |||
285 | static int torrent_statter( ot_torrent *torrent, uintptr_t data ) { | 287 | static int torrent_statter( ot_torrent *torrent, uintptr_t data ) { |
286 | torrent_stats *stats = (torrent_stats*)data; | 288 | torrent_stats *stats = (torrent_stats*)data; |
287 | stats->torrent_count++; | 289 | stats->torrent_count++; |
288 | stats->peer_count += torrent->peer_list->peer_count; | 290 | stats->peer_count += torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; |
289 | stats->seed_count += torrent->peer_list->seed_count; | 291 | stats->seed_count += torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; |
290 | return 0; | 292 | return 0; |
291 | } | 293 | } |
292 | 294 | ||
@@ -312,21 +314,23 @@ size_t stats_top_txt( char * reply, int amount ) { | |||
312 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | 314 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); |
313 | for( j=0; j<torrents_list->size; ++j ) { | 315 | for( j=0; j<torrents_list->size; ++j ) { |
314 | ot_torrent *torrent = (ot_torrent*)(torrents_list->data) + j; | 316 | ot_torrent *torrent = (ot_torrent*)(torrents_list->data) + j; |
317 | size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; | ||
318 | size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; | ||
315 | idx = amount - 1; | 319 | idx = amount - 1; |
316 | while( (idx >= 0) && ( torrent->peer_list->peer_count > top100c[idx].val ) ) | 320 | while( (idx >= 0) && ( peer_count > top100c[idx].val ) ) |
317 | --idx; | 321 | --idx; |
318 | if ( idx++ != amount - 1 ) { | 322 | if ( idx++ != amount - 1 ) { |
319 | memmove( top100c + idx + 1, top100c + idx, ( amount - 1 - idx ) * sizeof( ot_record ) ); | 323 | memmove( top100c + idx + 1, top100c + idx, ( amount - 1 - idx ) * sizeof( ot_record ) ); |
320 | memcpy( &top100c[idx].hash, &torrent->hash, sizeof(ot_hash)); | 324 | memcpy( &top100c[idx].hash, &torrent->hash, sizeof(ot_hash)); |
321 | top100c[idx].val = torrent->peer_list->peer_count; | 325 | top100c[idx].val = peer_count; |
322 | } | 326 | } |
323 | idx = amount - 1; | 327 | idx = amount - 1; |
324 | while( (idx >= 0) && ( torrent->peer_list->seed_count > top100s[idx].val ) ) | 328 | while( (idx >= 0) && ( seed_count > top100s[idx].val ) ) |
325 | --idx; | 329 | --idx; |
326 | if ( idx++ != amount - 1 ) { | 330 | if ( idx++ != amount - 1 ) { |
327 | memmove( top100s + idx + 1, top100s + idx, ( amount - 1 - idx ) * sizeof( ot_record ) ); | 331 | memmove( top100s + idx + 1, top100s + idx, ( amount - 1 - idx ) * sizeof( ot_record ) ); |
328 | memcpy( &top100s[idx].hash, &torrent->hash, sizeof(ot_hash)); | 332 | memcpy( &top100s[idx].hash, &torrent->hash, sizeof(ot_hash)); |
329 | top100s[idx].val = torrent->peer_list->seed_count; | 333 | top100s[idx].val = seed_count; |
330 | } | 334 | } |
331 | } | 335 | } |
332 | mutex_bucket_unlock( bucket, 0 ); | 336 | mutex_bucket_unlock( bucket, 0 ); |
@@ -718,7 +722,7 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event | |||
718 | break; | 722 | break; |
719 | case EVENT_SYNC: | 723 | case EVENT_SYNC: |
720 | ot_overall_sync_count+=event_data; | 724 | ot_overall_sync_count+=event_data; |
721 | break; | 725 | break; |
722 | case EVENT_BUCKET_LOCKED: | 726 | case EVENT_BUCKET_LOCKED: |
723 | ot_overall_stall_count++; | 727 | ot_overall_stall_count++; |
724 | break; | 728 | break; |