Browse Source

support for udp scrape

master
Denis Ahrens 15 years ago
parent
commit
b3f72c444b
  1. 15
      opentracker.c
  2. 28
      trackerlogic.c
  3. 3
      trackerlogic.h

15
opentracker.c

@ -315,7 +315,7 @@ SCRAPE_WORKAROUND:
}
/* Enough for http header + whole scrape string */
if( !( reply_size = return_scrape_for_torrent( hash, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) ) HTTPERROR_500;
if( !( reply_size = return_tcp_scrape_for_torrent( hash, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) ) HTTPERROR_500;
ot_overall_tcp_successfulannounces++;
break;
@ -590,7 +590,7 @@ static void handle_udp4( int64 serversocket ) {
unsigned long *outpacket = (unsigned long*)static_outbuf;
unsigned long numwant, left, event;
uint16 port, remoteport;
size_t r;
size_t r, r_out;
r = socket_recv4( serversocket, static_inbuf, 8192, remoteip, &remoteport);
@ -647,7 +647,7 @@ static void handle_udp4( int64 serversocket ) {
if( !torrent )
return; /* XXX maybe send error */
outpacket[0] = htonl( 1 );
outpacket[0] = htonl( 1 ); /* announce action */
outpacket[1] = inpacket[12/4];
r = 8 + return_peers_for_torrent( torrent, numwant, static_outbuf + 8, 0 );
socket_send4( serversocket, static_outbuf, r, remoteip, remoteport );
@ -656,7 +656,14 @@ static void handle_udp4( int64 serversocket ) {
break;
case 2: /* This is a scrape action */
ot_overall_udp_connections--; // subtract again because we don't answer scrapes but it is also not an error
outpacket[0] = htonl( 2 ); /* scrape action */
outpacket[1] = inpacket[12/4];
for( r_out = 0; ( r_out * 20 < r - 16) && ( r_out <= 74 ); r_out++ )
return_udp_scrape_for_torrent( (ot_hash*)( static_inbuf + 16 + 20 * r_out ), static_outbuf + 8 + 12 * r_out );
socket_send4( serversocket, static_outbuf, 8 + 12 * r_out, remoteip, remoteport );
ot_overall_udp_successfulannounces++;
break;
}
}

28
trackerlogic.c

@ -408,7 +408,33 @@ size_t return_memstat_for_tracker( char **reply ) {
}
/* Fetches scrape info for a specific torrent */
size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) {
size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ) {
int exactmatch, i;
size_t peers = 0, seeds = 0;
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 ) {
memset( reply, 0, 12);
}
else
{
unsigned long *r = (unsigned long*) reply;
clean_peerlist( NOW, torrent->peer_list );
for( i=0; i<OT_POOLS_COUNT; ++i ) {
peers += torrent->peer_list->peers[i].size;
seeds += torrent->peer_list->seed_count[i];
}
r[0] = seeds;
r[1] = torrent->peer_list->downloaded;
r[2] = peers-seeds;
}
return 12;
}
/* Fetches scrape info for a specific torrent */
size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply ) {
char *r = reply;
int exactmatch, i;
size_t peers = 0, seeds = 0;

3
trackerlogic.h

@ -96,7 +96,8 @@ enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP };
ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer );
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_scrape_for_torrent( ot_hash *hash, char *reply );
size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply );
size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply );
size_t return_sync_for_torrent( ot_hash *hash, char **reply );
size_t return_stats_for_tracker( char *reply, int mode );
size_t return_memstat_for_tracker( char **reply );

Loading…
Cancel
Save