mode = STATS_TCP;
else if( !byte_diff(data,4,"udp4"))
mode = STATS_UDP;
+ else if( !byte_diff(data,4,"s24s"))
+ mode = STATS_SLASH24S;
else
HTTPERROR_400_PARAM;
}
/* Enough for http header + whole scrape string */
if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500;
break;
+ case STATS_SLASH24S:
+ if( !( reply_size = return_stats_for_slash24s( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 64 ) ) ) HTTPERROR_500;
+ break;
}
break;
return r - reply;
}
+size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ) {
+ ot_word *count = malloc( 0x1000000 * sizeof(ot_word) );
+ ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */
+ size_t i, j, k, l;
+ char *r = reply;
+
+ if( !count )
+ return 0;
+
+ byte_zero( count, 0x1000000 * sizeof(ot_word) );
+ byte_zero( slash24s, amount * 2 * sizeof(ot_dword) );
+
+ r += sprintf( r, "Stats for all /24s with more than %d announced torrents:\n\n", ((int)thresh) );
+
+ for( i=0; i<256; ++i ) {
+ ot_vector *torrents_list = &all_torrents[i];
+ for( j=0; j<torrents_list->size; ++j ) {
+ ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
+ for( k=0; k<OT_POOLS_COUNT; ++k ) {
+ ot_peer *peers = peer_list->peers[k].data;
+ size_t numpeers = peer_list->peers[k].size;
+ for( l=0; l<numpeers; ++l )
+ if( ++count[ (*(ot_dword*)(peers+l))>>8 ] == 65335 )
+ count[ (*(ot_dword*)(peers+l))>>8 ] = 65334;
+ }
+ }
+ }
+
+ for( i=0; i<0x1000000; ++i )
+ if( count[i] >= thresh ) {
+ /* This subnet seems to announce more torrents than the last in our list */
+ int insert_pos = amount - 1;
+ while( ( insert_pos >= 0 ) && ( count[i] > slash24s[ 2 * insert_pos ] ) )
+ --insert_pos;
+ ++insert_pos;
+ memmove( slash24s + 2 * ( insert_pos + 1 ), slash24s + 2 * ( insert_pos ), 2 * sizeof( ot_dword ) * ( amount - insert_pos - 1 ) );
+ slash24s[ 2 * insert_pos ] = count[i];
+ slash24s[ 2 * insert_pos + 1 ] = i;
+ if( slash24s[ 2 * amount - 2 ] > thresh )
+ thresh = slash24s[ 2 * amount - 2 ];
+ }
+
+ free( count );
+
+ for( i=0; i < amount; ++i )
+ if( slash24s[ 2*i ] >= thresh ) {
+ unsigned long ip = slash24s[ 2*i +1 ];
+ r += sprintf( r, "% 10ld %d.%d.%d/24\n", (long)slash24s[ 2*i ], (int)(ip >> 16), (int)(255 & ( ip >> 8 )), (int)(ip & 255) );
+ }
+
+ return r - reply;
+}
+
void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) {
int exactmatch, i;
ot_vector *torrents_list = &all_torrents[*hash[0]];
int init_logic( const char * const serverdir );
void deinit_logic( void );
-enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, SYNC_IN, SYNC_OUT };
+enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, SYNC_IN, SYNC_OUT };
ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset );
int add_changeset_to_tracker( ot_byte *data, size_t len );
size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply );
size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply );
size_t return_stats_for_tracker( char *reply, int mode );
+size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh );
size_t return_memstat_for_tracker( char **reply );
size_t return_changeset_for_tracker( char **reply );
void clean_all_torrents( void );