diff options
| author | erdgeist <> | 2007-09-26 16:49:13 +0000 |
|---|---|---|
| committer | erdgeist <> | 2007-09-26 16:49:13 +0000 |
| commit | c350fa0b3c323979f73d079d389219e7f98edc1b (patch) | |
| tree | 61bb2ce1140874c5d5db98c26a043d836ae5d5ea /trackerlogic.c | |
| parent | c4f924810ee0aa390ccbcf306149512646875757 (diff) | |
New stats for s24s code, this is debug, do not use in real world
Diffstat (limited to 'trackerlogic.c')
| -rw-r--r-- | trackerlogic.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/trackerlogic.c b/trackerlogic.c index 0777c54..7d50ed4 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
| @@ -641,7 +641,93 @@ size_t return_stats_for_tracker( char *reply, int mode ) { | |||
| 641 | return r - reply; | 641 | return r - reply; |
| 642 | } | 642 | } |
| 643 | 643 | ||
| 644 | /* This function collects 4096 /24s in 4096 possible | ||
| 645 | malloc blocks | ||
| 646 | */ | ||
| 644 | size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ) { | 647 | size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ) { |
| 648 | |||
| 649 | #define NUM_TOPBITS 12 | ||
| 650 | #define NUM_LOWBITS (24-NUM_TOPBITS) | ||
| 651 | #define NUM_BUFS (1<<NUM_TOPBITS) | ||
| 652 | #define NUM_S24S (1<<NUM_LOWBITS) | ||
| 653 | #define MSK_S24S (NUM_S24S-1) | ||
| 654 | |||
| 655 | ot_dword *counts[ NUM_BUFS ]; | ||
| 656 | ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */ | ||
| 657 | size_t i, j, k, l; | ||
| 658 | char *r = reply; | ||
| 659 | |||
| 660 | byte_zero( counts, sizeof( counts ) ); | ||
| 661 | byte_zero( slash24s, amount * 2 * sizeof(ot_dword) ); | ||
| 662 | |||
| 663 | r += sprintf( r, "Stats for all /24s with more than %ld announced torrents:\n\n", thresh ); | ||
| 664 | |||
| 665 | for( i=0; i<256; ++i ) { | ||
| 666 | ot_vector *torrents_list = &all_torrents[i]; | ||
| 667 | for( j=0; j<torrents_list->size; ++j ) { | ||
| 668 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; | ||
| 669 | for( k=0; k<OT_POOLS_COUNT; ++k ) { | ||
| 670 | ot_peer *peers = peer_list->peers[k].data; | ||
| 671 | size_t numpeers = peer_list->peers[k].size; | ||
| 672 | for( l=0; l<numpeers; ++l ) { | ||
| 673 | ot_dword s24 = ntohl(*(ot_dword*)(peers+l)) >> 8; | ||
| 674 | ot_dword *count = counts[ s24 >> NUM_LOWBITS ]; | ||
| 675 | if( !count ) { | ||
| 676 | count = malloc( sizeof(ot_dword) * NUM_S24S ); | ||
| 677 | if( !count ) | ||
| 678 | goto bailout_cleanup; | ||
| 679 | byte_zero( count, sizeof( ot_dword ) * NUM_S24S ); | ||
| 680 | counts[ s24 >> NUM_LOWBITS ] = count; | ||
| 681 | } | ||
| 682 | count[ s24 & MSK_S24S ]++; | ||
| 683 | } | ||
| 684 | } | ||
| 685 | } | ||
| 686 | } | ||
| 687 | |||
| 688 | k = l = 0; /* Debug: count allocated bufs */ | ||
| 689 | for( i=0; i < NUM_BUFS; ++i ) { | ||
| 690 | ot_dword *count = counts[i]; | ||
| 691 | if( !counts[i] ) | ||
| 692 | continue; | ||
| 693 | ++k; /* Debug: count allocated bufs */ | ||
| 694 | for( j=0; j < NUM_S24S; ++j ) { | ||
| 695 | if( count[j] > thresh ) { | ||
| 696 | /* This subnet seems to announce more torrents than the last in our list */ | ||
| 697 | int insert_pos = amount - 1; | ||
| 698 | while( ( insert_pos >= 0 ) && ( count[j] > slash24s[ 2 * insert_pos ] ) ) | ||
| 699 | --insert_pos; | ||
| 700 | ++insert_pos; | ||
| 701 | memmove( slash24s + 2 * ( insert_pos + 1 ), slash24s + 2 * ( insert_pos ), 2 * sizeof( ot_dword ) * ( amount - insert_pos - 1 ) ); | ||
| 702 | slash24s[ 2 * insert_pos ] = count[j]; | ||
| 703 | slash24s[ 2 * insert_pos + 1 ] = ( i << NUM_TOPBITS ) + j; | ||
| 704 | if( slash24s[ 2 * amount - 2 ] > thresh ) | ||
| 705 | thresh = slash24s[ 2 * amount - 2 ]; | ||
| 706 | } | ||
| 707 | if( count[j] ) ++l; | ||
| 708 | } | ||
| 709 | free( count ); | ||
| 710 | } | ||
| 711 | |||
| 712 | r += sprintf( r, "Allocated bufs: %zd, used s24s: %zd\n", k, l ); | ||
| 713 | |||
| 714 | for( i=0; i < amount; ++i ) | ||
| 715 | if( slash24s[ 2*i ] >= thresh ) { | ||
| 716 | ot_dword ip = slash24s[ 2*i +1 ]; | ||
| 717 | r += sprintf( r, "% 10ld %d.%d.%d.0/24\n", (long)slash24s[ 2*i ], (int)(ip >> 16), (int)(255 & ( ip >> 8 )), (int)(ip & 255) ); | ||
| 718 | } | ||
| 719 | |||
| 720 | return r - reply; | ||
| 721 | |||
| 722 | bailout_cleanup: | ||
| 723 | |||
| 724 | for( i=0; i < NUM_BUFS; ++i ) | ||
| 725 | free( counts[i] ); | ||
| 726 | |||
| 727 | return 0; | ||
| 728 | } | ||
| 729 | |||
| 730 | size_t return_stats_for_slash24s_old( char *reply, size_t amount, ot_dword thresh ) { | ||
| 645 | ot_word *count = malloc( 0x1000000 * sizeof(ot_word) ); | 731 | ot_word *count = malloc( 0x1000000 * sizeof(ot_word) ); |
| 646 | ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */ | 732 | ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */ |
| 647 | size_t i, j, k, l; | 733 | size_t i, j, k, l; |
