summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2007-09-10 02:43:11 +0000
committererdgeist <>2007-09-10 02:43:11 +0000
commit33c9c530d00f6993118ee23cc4cde1b16c7ad978 (patch)
tree08c7b57bca3abe93bf1297be1dca3a4d50bdc7ba
parentea276fa0bf0cd17537344549860e490e527db53f (diff)
An announce with event=stopped now returns correct number of leechers and seeders. In TCP and UDP.
-rw-r--r--opentracker.c19
-rw-r--r--trackerlogic.c45
-rw-r--r--trackerlogic.h5
3 files changed, 47 insertions, 22 deletions
diff --git a/opentracker.c b/opentracker.c
index 4ffde37..646184c 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -441,10 +441,9 @@ ANNOUNCE_WORKAROUND:
441 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" ); 441 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" );
442 break; 442 break;
443 } 443 }
444 if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) { 444 if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED )
445 remove_peer_from_torrent( hash, &peer ); 445 reply_size = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 );
446 reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "d8:completei0e10:incompletei0e8:intervali%ie5:peers0:e", OT_CLIENT_REQUEST_INTERVAL_RANDOM ); 446 else {
447 } else {
448 torrent = add_peer_to_torrent( hash, &peer, 0 ); 447 torrent = add_peer_to_torrent( hash, &peer, 0 );
449 if( !torrent || !( reply_size = return_peers_for_torrent( torrent, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 ) ) ) HTTPERROR_500; 448 if( !torrent || !( reply_size = return_peers_for_torrent( torrent, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 ) ) ) HTTPERROR_500;
450 } 449 }
@@ -680,15 +679,9 @@ static void handle_udp4( int64 serversocket ) {
680 outpacket[0] = htonl( 1 ); /* announce action */ 679 outpacket[0] = htonl( 1 ); /* announce action */
681 outpacket[1] = inpacket[12/4]; 680 outpacket[1] = inpacket[12/4];
682 681
683 if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) { 682 if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) /* Peer is gone. */
684 /* Peer is gone. */ 683 r = remove_peer_from_torrent( hash, &peer, static_outbuf, 0 );
685 remove_peer_from_torrent( hash, &peer ); 684 else {
686
687 /* Create fake packet to satisfy parser on the other end */
688 outpacket[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
689 outpacket[3] = outpacket[4] = 0;
690 r = 20;
691 } else {
692 torrent = add_peer_to_torrent( hash, &peer, 0 ); 685 torrent = add_peer_to_torrent( hash, &peer, 0 );
693 if( !torrent ) 686 if( !torrent )
694 return; /* XXX maybe send error */ 687 return; /* XXX maybe send error */
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 ) {
diff --git a/trackerlogic.h b/trackerlogic.h
index 8fcf66e..cb67244 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -87,7 +87,7 @@ void deinit_logic( void );
87enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, SYNC_IN, SYNC_OUT }; 87enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, SYNC_IN, SYNC_OUT };
88 88
89ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset ); 89ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset );
90int add_changeset_to_tracker( ot_byte *data, size_t len ); 90size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp );
91size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp ); 91size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp );
92size_t return_fullscrape_for_tracker( char **reply ); 92size_t return_fullscrape_for_tracker( char **reply );
93size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply ); 93size_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 );
96size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ); 96size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh );
97size_t return_memstat_for_tracker( char **reply ); 97size_t return_memstat_for_tracker( char **reply );
98size_t return_changeset_for_tracker( char **reply ); 98size_t return_changeset_for_tracker( char **reply );
99int add_changeset_to_tracker( ot_byte *data, size_t len );
99void clean_all_torrents( void ); 100void clean_all_torrents( void );
100void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ); 101
101#if defined ( WANT_BLACKLISTING ) || defined ( WANT_CLOSED_TRACKER ) 102#if defined ( WANT_BLACKLISTING ) || defined ( WANT_CLOSED_TRACKER )
102int accesslist_addentry( ot_hash *hash ); 103int accesslist_addentry( ot_hash *hash );
103void accesslist_reset( void ); 104void accesslist_reset( void );