summaryrefslogtreecommitdiff
path: root/opentracker.c
diff options
context:
space:
mode:
authordenis <>2007-03-16 22:46:41 +0000
committerdenis <>2007-03-16 22:46:41 +0000
commit8ac7768b961d3ef90e4b4b7ac6fc6b2322f1aa7f (patch)
tree74c65ac90cc8a91e5b4d766c732cc33569cd9f54 /opentracker.c
parent36413e4853a02b7adbd192d362c4c091330e5e88 (diff)
support for udp scrape
Diffstat (limited to 'opentracker.c')
-rw-r--r--opentracker.c15
1 files changed, 11 insertions, 4 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}