An announce with event=stopped now returns correct number of leechers and seeders. In TCP and UDP.

dynamic-accesslists
erdgeist 17 years ago
parent ea276fa0bf
commit 33c9c530d0

@ -441,10 +441,9 @@ ANNOUNCE_WORKAROUND:
reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "d14:failure reason81:Your client forgot to send your torrent's info_hash. Please upgrade your client.e" );
break;
}
if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) {
remove_peer_from_torrent( hash, &peer );
reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "d8:completei0e10:incompletei0e8:intervali%ie5:peers0:e", OT_CLIENT_REQUEST_INTERVAL_RANDOM );
} else {
if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED )
reply_size = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 );
else {
torrent = add_peer_to_torrent( hash, &peer, 0 );
if( !torrent || !( reply_size = return_peers_for_torrent( torrent, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 ) ) ) HTTPERROR_500;
}
@ -680,15 +679,9 @@ static void handle_udp4( int64 serversocket ) {
outpacket[0] = htonl( 1 ); /* announce action */
outpacket[1] = inpacket[12/4];
if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) {
/* Peer is gone. */
remove_peer_from_torrent( hash, &peer );
/* Create fake packet to satisfy parser on the other end */
outpacket[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
outpacket[3] = outpacket[4] = 0;
r = 20;
} else {
if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) /* Peer is gone. */
r = remove_peer_from_torrent( hash, &peer, static_outbuf, 0 );
else {
torrent = add_peer_to_torrent( hash, &peer, 0 );
if( !torrent )
return; /* XXX maybe send error */

@ -693,19 +693,50 @@ size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh )
return r - reply;
}
void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) {
int exactmatch, i;
size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp ) {
int exactmatch;
size_t peer_count, seed_count, index;
ot_vector *torrents_list = &all_torrents[*hash[0]];
ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch );
if( !exactmatch ) return;
if( !exactmatch ) {
if( is_tcp )
return sprintf( reply, "d8:completei0e10:incompletei0e8:intervali%ie5:peers0:e", OT_CLIENT_REQUEST_INTERVAL_RANDOM );
for( i=0; i<OT_POOLS_COUNT; ++i )
switch( vector_remove_peer( &torrent->peer_list->peers[i], peer, i == 0 ) ) {
/* Create fake packet to satisfy parser on the other end */
((ot_dword*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
((ot_dword*)reply)[3] = ((ot_dword*)reply)[4] = 0;
return (size_t)20;
}
for( peer_count = seed_count = index = 0; index<OT_POOLS_COUNT; ++index ) {
peer_count += torrent->peer_list->peers[index].size;
seed_count += torrent->peer_list->seed_count[index];
switch( vector_remove_peer( &torrent->peer_list->peers[index], peer, index == 0 ) ) {
case 0: continue;
case 2: torrent->peer_list->seed_count[i]--;
case 1: default: return;
case 2: torrent->peer_list->seed_count[index]--;
seed_count--;
case 1: default:
peer_count--;
goto exit_loop;
}
}
exit_loop:
for( ++index; index < OT_POOLS_COUNT; ++index ) {
peer_count += torrent->peer_list->peers[index].size;
seed_count += torrent->peer_list->seed_count[index];
}
if( is_tcp )
return sprintf( reply, "d8:completei%zde10:incompletei%zde8:intervali%ie5:peers0:e", seed_count, peer_count - seed_count, OT_CLIENT_REQUEST_INTERVAL_RANDOM );
/* else { Handle UDP reply */
((ot_dword*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
((ot_dword*)reply)[3] = peer_count - seed_count;
((ot_dword*)reply)[4] = seed_count;
return (size_t)20;
}
int init_logic( const char * const serverdir ) {

@ -87,7 +87,7 @@ void deinit_logic( void );
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 remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp );
size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp );
size_t return_fullscrape_for_tracker( char **reply );
size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply );
@ -96,8 +96,9 @@ 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 );
int add_changeset_to_tracker( ot_byte *data, size_t len );
void clean_all_torrents( void );
void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer );
#if defined ( WANT_BLACKLISTING ) || defined ( WANT_CLOSED_TRACKER )
int accesslist_addentry( ot_hash *hash );
void accesslist_reset( void );

Loading…
Cancel
Save