diff options
Diffstat (limited to 'trackerlogic.c')
-rw-r--r-- | trackerlogic.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/trackerlogic.c b/trackerlogic.c index 98fcef9..ee49eb7 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
@@ -634,6 +634,59 @@ size_t return_stats_for_tracker( char *reply, int mode ) { | |||
634 | return r - reply; | 634 | return r - reply; |
635 | } | 635 | } |
636 | 636 | ||
637 | size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ) { | ||
638 | ot_word *count = malloc( 0x1000000 * sizeof(ot_word) ); | ||
639 | ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */ | ||
640 | size_t i, j, k, l; | ||
641 | char *r = reply; | ||
642 | |||
643 | if( !count ) | ||
644 | return 0; | ||
645 | |||
646 | byte_zero( count, 0x1000000 * sizeof(ot_word) ); | ||
647 | byte_zero( slash24s, amount * 2 * sizeof(ot_dword) ); | ||
648 | |||
649 | r += sprintf( r, "Stats for all /24s with more than %d announced torrents:\n\n", ((int)thresh) ); | ||
650 | |||
651 | for( i=0; i<256; ++i ) { | ||
652 | ot_vector *torrents_list = &all_torrents[i]; | ||
653 | for( j=0; j<torrents_list->size; ++j ) { | ||
654 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; | ||
655 | for( k=0; k<OT_POOLS_COUNT; ++k ) { | ||
656 | ot_peer *peers = peer_list->peers[k].data; | ||
657 | size_t numpeers = peer_list->peers[k].size; | ||
658 | for( l=0; l<numpeers; ++l ) | ||
659 | if( ++count[ (*(ot_dword*)(peers+l))>>8 ] == 65335 ) | ||
660 | count[ (*(ot_dword*)(peers+l))>>8 ] = 65334; | ||
661 | } | ||
662 | } | ||
663 | } | ||
664 | |||
665 | for( i=0; i<0x1000000; ++i ) | ||
666 | if( count[i] >= thresh ) { | ||
667 | /* This subnet seems to announce more torrents than the last in our list */ | ||
668 | int insert_pos = amount - 1; | ||
669 | while( ( insert_pos >= 0 ) && ( count[i] > slash24s[ 2 * insert_pos ] ) ) | ||
670 | --insert_pos; | ||
671 | ++insert_pos; | ||
672 | memmove( slash24s + 2 * ( insert_pos + 1 ), slash24s + 2 * ( insert_pos ), 2 * sizeof( ot_dword ) * ( amount - insert_pos - 1 ) ); | ||
673 | slash24s[ 2 * insert_pos ] = count[i]; | ||
674 | slash24s[ 2 * insert_pos + 1 ] = i; | ||
675 | if( slash24s[ 2 * amount - 2 ] > thresh ) | ||
676 | thresh = slash24s[ 2 * amount - 2 ]; | ||
677 | } | ||
678 | |||
679 | free( count ); | ||
680 | |||
681 | for( i=0; i < amount; ++i ) | ||
682 | if( slash24s[ 2*i ] >= thresh ) { | ||
683 | unsigned long ip = slash24s[ 2*i +1 ]; | ||
684 | r += sprintf( r, "% 10ld %d.%d.%d/24\n", (long)slash24s[ 2*i ], (int)(ip >> 16), (int)(255 & ( ip >> 8 )), (int)(ip & 255) ); | ||
685 | } | ||
686 | |||
687 | return r - reply; | ||
688 | } | ||
689 | |||
637 | void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) { | 690 | void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) { |
638 | int exactmatch, i; | 691 | int exactmatch, i; |
639 | ot_vector *torrents_list = &all_torrents[*hash[0]]; | 692 | ot_vector *torrents_list = &all_torrents[*hash[0]]; |