mirror of
git://erdgeist.org/opentracker
synced 2025-01-11 15:30:07 +00:00
support for udp scrape
This commit is contained in:
parent
36413e4853
commit
8ac7768b96
@ -315,7 +315,7 @@ SCRAPE_WORKAROUND:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Enough for http header + whole scrape string */
|
/* 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++;
|
ot_overall_tcp_successfulannounces++;
|
||||||
break;
|
break;
|
||||||
@ -590,7 +590,7 @@ static void handle_udp4( int64 serversocket ) {
|
|||||||
unsigned long *outpacket = (unsigned long*)static_outbuf;
|
unsigned long *outpacket = (unsigned long*)static_outbuf;
|
||||||
unsigned long numwant, left, event;
|
unsigned long numwant, left, event;
|
||||||
uint16 port, remoteport;
|
uint16 port, remoteport;
|
||||||
size_t r;
|
size_t r, r_out;
|
||||||
|
|
||||||
r = socket_recv4( serversocket, static_inbuf, 8192, remoteip, &remoteport);
|
r = socket_recv4( serversocket, static_inbuf, 8192, remoteip, &remoteport);
|
||||||
|
|
||||||
@ -647,7 +647,7 @@ static void handle_udp4( int64 serversocket ) {
|
|||||||
if( !torrent )
|
if( !torrent )
|
||||||
return; /* XXX maybe send error */
|
return; /* XXX maybe send error */
|
||||||
|
|
||||||
outpacket[0] = htonl( 1 );
|
outpacket[0] = htonl( 1 ); /* announce action */
|
||||||
outpacket[1] = inpacket[12/4];
|
outpacket[1] = inpacket[12/4];
|
||||||
r = 8 + return_peers_for_torrent( torrent, numwant, static_outbuf + 8, 0 );
|
r = 8 + return_peers_for_torrent( torrent, numwant, static_outbuf + 8, 0 );
|
||||||
socket_send4( serversocket, static_outbuf, r, remoteip, remoteport );
|
socket_send4( serversocket, static_outbuf, r, remoteip, remoteport );
|
||||||
@ -656,7 +656,14 @@ static void handle_udp4( int64 serversocket ) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: /* This is a scrape action */
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,33 @@ size_t return_memstat_for_tracker( char **reply ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fetches scrape info for a specific torrent */
|
/* 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;
|
char *r = reply;
|
||||||
int exactmatch, i;
|
int exactmatch, i;
|
||||||
size_t peers = 0, seeds = 0;
|
size_t peers = 0, seeds = 0;
|
||||||
|
@ -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 );
|
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_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_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_sync_for_torrent( ot_hash *hash, char **reply );
|
||||||
size_t return_stats_for_tracker( char *reply, int mode );
|
size_t return_stats_for_tracker( char *reply, int mode );
|
||||||
size_t return_memstat_for_tracker( char **reply );
|
size_t return_memstat_for_tracker( char **reply );
|
||||||
|
Loading…
Reference in New Issue
Block a user