diff options
-rw-r--r-- | opentracker.c | 15 | ||||
-rw-r--r-- | trackerlogic.c | 28 | ||||
-rw-r--r-- | trackerlogic.h | 3 |
3 files changed, 40 insertions, 6 deletions
diff --git a/opentracker.c b/opentracker.c index 5e8ebc1..2fb6bf5 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -315,7 +315,7 @@ SCRAPE_WORKAROUND: | |||
315 | } | 315 | } |
316 | 316 | ||
317 | /* Enough for http header + whole scrape string */ | 317 | /* Enough for http header + whole scrape string */ |
318 | if( !( reply_size = return_scrape_for_torrent( hash, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) ) HTTPERROR_500; | 318 | if( !( reply_size = return_tcp_scrape_for_torrent( hash, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) ) HTTPERROR_500; |
319 | 319 | ||
320 | ot_overall_tcp_successfulannounces++; | 320 | ot_overall_tcp_successfulannounces++; |
321 | break; | 321 | break; |
@@ -590,7 +590,7 @@ static void handle_udp4( int64 serversocket ) { | |||
590 | unsigned long *outpacket = (unsigned long*)static_outbuf; | 590 | unsigned long *outpacket = (unsigned long*)static_outbuf; |
591 | unsigned long numwant, left, event; | 591 | unsigned long numwant, left, event; |
592 | uint16 port, remoteport; | 592 | uint16 port, remoteport; |
593 | size_t r; | 593 | size_t r, r_out; |
594 | 594 | ||
595 | r = socket_recv4( serversocket, static_inbuf, 8192, remoteip, &remoteport); | 595 | r = socket_recv4( serversocket, static_inbuf, 8192, remoteip, &remoteport); |
596 | 596 | ||
@@ -647,7 +647,7 @@ static void handle_udp4( int64 serversocket ) { | |||
647 | if( !torrent ) | 647 | if( !torrent ) |
648 | return; /* XXX maybe send error */ | 648 | return; /* XXX maybe send error */ |
649 | 649 | ||
650 | outpacket[0] = htonl( 1 ); | 650 | outpacket[0] = htonl( 1 ); /* announce action */ |
651 | outpacket[1] = inpacket[12/4]; | 651 | outpacket[1] = inpacket[12/4]; |
652 | r = 8 + return_peers_for_torrent( torrent, numwant, static_outbuf + 8, 0 ); | 652 | r = 8 + return_peers_for_torrent( torrent, numwant, static_outbuf + 8, 0 ); |
653 | socket_send4( serversocket, static_outbuf, r, remoteip, remoteport ); | 653 | socket_send4( serversocket, static_outbuf, r, remoteip, remoteport ); |
@@ -656,7 +656,14 @@ static void handle_udp4( int64 serversocket ) { | |||
656 | break; | 656 | break; |
657 | 657 | ||
658 | case 2: /* This is a scrape action */ | 658 | case 2: /* This is a scrape action */ |
659 | ot_overall_udp_connections--; // subtract again because we don't answer scrapes but it is also not an error | 659 | outpacket[0] = htonl( 2 ); /* scrape action */ |
660 | outpacket[1] = inpacket[12/4]; | ||
661 | |||
662 | for( r_out = 0; ( r_out * 20 < r - 16) && ( r_out <= 74 ); r_out++ ) | ||
663 | return_udp_scrape_for_torrent( (ot_hash*)( static_inbuf + 16 + 20 * r_out ), static_outbuf + 8 + 12 * r_out ); | ||
664 | |||
665 | socket_send4( serversocket, static_outbuf, 8 + 12 * r_out, remoteip, remoteport ); | ||
666 | ot_overall_udp_successfulannounces++; | ||
660 | break; | 667 | break; |
661 | } | 668 | } |
662 | } | 669 | } |
diff --git a/trackerlogic.c b/trackerlogic.c index bc9010e..ff6f45a 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
@@ -408,7 +408,33 @@ size_t return_memstat_for_tracker( char **reply ) { | |||
408 | } | 408 | } |
409 | 409 | ||
410 | /* Fetches scrape info for a specific torrent */ | 410 | /* Fetches scrape info for a specific torrent */ |
411 | size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) { | 411 | size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ) { |
412 | int exactmatch, i; | ||
413 | size_t peers = 0, seeds = 0; | ||
414 | ot_vector *torrents_list = &all_torrents[*hash[0]]; | ||
415 | ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); | ||
416 | |||
417 | if( !exactmatch ) { | ||
418 | memset( reply, 0, 12); | ||
419 | } | ||
420 | else | ||
421 | { | ||
422 | unsigned long *r = (unsigned long*) reply; | ||
423 | clean_peerlist( NOW, torrent->peer_list ); | ||
424 | |||
425 | for( i=0; i<OT_POOLS_COUNT; ++i ) { | ||
426 | peers += torrent->peer_list->peers[i].size; | ||
427 | seeds += torrent->peer_list->seed_count[i]; | ||
428 | } | ||
429 | r[0] = seeds; | ||
430 | r[1] = torrent->peer_list->downloaded; | ||
431 | r[2] = peers-seeds; | ||
432 | } | ||
433 | return 12; | ||
434 | } | ||
435 | |||
436 | /* Fetches scrape info for a specific torrent */ | ||
437 | size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply ) { | ||
412 | char *r = reply; | 438 | char *r = reply; |
413 | int exactmatch, i; | 439 | int exactmatch, i; |
414 | size_t peers = 0, seeds = 0; | 440 | size_t peers = 0, seeds = 0; |
diff --git a/trackerlogic.h b/trackerlogic.h index 59d256e..fbc86ea 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
@@ -96,7 +96,8 @@ enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP }; | |||
96 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ); | 96 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ); |
97 | size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp ); | 97 | size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp ); |
98 | size_t return_fullscrape_for_tracker( char **reply ); | 98 | size_t return_fullscrape_for_tracker( char **reply ); |
99 | size_t return_scrape_for_torrent( ot_hash *hash, char *reply ); | 99 | size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply ); |
100 | size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ); | ||
100 | size_t return_sync_for_torrent( ot_hash *hash, char **reply ); | 101 | size_t return_sync_for_torrent( ot_hash *hash, char **reply ); |
101 | size_t return_stats_for_tracker( char *reply, int mode ); | 102 | size_t return_stats_for_tracker( char *reply, int mode ); |
102 | size_t return_memstat_for_tracker( char **reply ); | 103 | size_t return_memstat_for_tracker( char **reply ); |