diff options
author | erdgeist <> | 2007-09-10 02:43:11 +0000 |
---|---|---|
committer | erdgeist <> | 2007-09-10 02:43:11 +0000 |
commit | 33c9c530d00f6993118ee23cc4cde1b16c7ad978 (patch) | |
tree | 08c7b57bca3abe93bf1297be1dca3a4d50bdc7ba /trackerlogic.c | |
parent | ea276fa0bf0cd17537344549860e490e527db53f (diff) |
An announce with event=stopped now returns correct number of leechers and seeders. In TCP and UDP.
Diffstat (limited to 'trackerlogic.c')
-rw-r--r-- | trackerlogic.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/trackerlogic.c b/trackerlogic.c index c8b9e03..4306822 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
@@ -693,19 +693,50 @@ size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ) | |||
693 | return r - reply; | 693 | return r - reply; |
694 | } | 694 | } |
695 | 695 | ||
696 | void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) { | 696 | size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp ) { |
697 | int exactmatch, i; | 697 | int exactmatch; |
698 | size_t peer_count, seed_count, index; | ||
698 | ot_vector *torrents_list = &all_torrents[*hash[0]]; | 699 | ot_vector *torrents_list = &all_torrents[*hash[0]]; |
699 | ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); | 700 | ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); |
700 | 701 | ||
701 | if( !exactmatch ) return; | 702 | if( !exactmatch ) { |
703 | if( is_tcp ) | ||
704 | return sprintf( reply, "d8:completei0e10:incompletei0e8:intervali%ie5:peers0:e", OT_CLIENT_REQUEST_INTERVAL_RANDOM ); | ||
702 | 705 | ||
703 | for( i=0; i<OT_POOLS_COUNT; ++i ) | 706 | /* Create fake packet to satisfy parser on the other end */ |
704 | switch( vector_remove_peer( &torrent->peer_list->peers[i], peer, i == 0 ) ) { | 707 | ((ot_dword*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); |
708 | ((ot_dword*)reply)[3] = ((ot_dword*)reply)[4] = 0; | ||
709 | return (size_t)20; | ||
710 | } | ||
711 | |||
712 | for( peer_count = seed_count = index = 0; index<OT_POOLS_COUNT; ++index ) { | ||
713 | peer_count += torrent->peer_list->peers[index].size; | ||
714 | seed_count += torrent->peer_list->seed_count[index]; | ||
715 | |||
716 | switch( vector_remove_peer( &torrent->peer_list->peers[index], peer, index == 0 ) ) { | ||
705 | case 0: continue; | 717 | case 0: continue; |
706 | case 2: torrent->peer_list->seed_count[i]--; | 718 | case 2: torrent->peer_list->seed_count[index]--; |
707 | case 1: default: return; | 719 | seed_count--; |
720 | case 1: default: | ||
721 | peer_count--; | ||
722 | goto exit_loop; | ||
708 | } | 723 | } |
724 | } | ||
725 | |||
726 | exit_loop: | ||
727 | for( ++index; index < OT_POOLS_COUNT; ++index ) { | ||
728 | peer_count += torrent->peer_list->peers[index].size; | ||
729 | seed_count += torrent->peer_list->seed_count[index]; | ||
730 | } | ||
731 | |||
732 | if( is_tcp ) | ||
733 | return sprintf( reply, "d8:completei%zde10:incompletei%zde8:intervali%ie5:peers0:e", seed_count, peer_count - seed_count, OT_CLIENT_REQUEST_INTERVAL_RANDOM ); | ||
734 | |||
735 | /* else { Handle UDP reply */ | ||
736 | ((ot_dword*)reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); | ||
737 | ((ot_dword*)reply)[3] = peer_count - seed_count; | ||
738 | ((ot_dword*)reply)[4] = seed_count; | ||
739 | return (size_t)20; | ||
709 | } | 740 | } |
710 | 741 | ||
711 | int init_logic( const char * const serverdir ) { | 742 | int init_logic( const char * const serverdir ) { |