summaryrefslogtreecommitdiff
path: root/trackerlogic.c
diff options
context:
space:
mode:
Diffstat (limited to 'trackerlogic.c')
-rw-r--r--trackerlogic.c45
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
696void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) { 696size_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
726exit_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
711int init_logic( const char * const serverdir ) { 742int init_logic( const char * const serverdir ) {