Browse Source

Try to act upon all udp packets at once

master
Dirk Engling 10 years ago
parent
commit
a3de74bdd4
  1. 6
      opentracker.c
  2. 14
      ot_udp.c

6
opentracker.c

@ -2,7 +2,7 @@
It is considered beerware. Prost. Skol. Cheers or whatever.
Some of the stuff below is stolen from Fefes example libowfat httpd.
$Id: opentracker.c,v 1.233 2010/12/11 15:50:56 erdgeist Exp $ */
$Id: opentracker.c,v 1.234 2012/03/31 20:01:05 erdgeist Exp $ */
/* System */
#include <stdlib.h>
@ -266,7 +266,7 @@ static void * server_mainloop( void * args ) {
if( (intptr_t)cookie == FLAG_TCP )
handle_accept( sock );
else if( (intptr_t)cookie == FLAG_UDP )
handle_udp6( sock, &ws );
while( handle_udp6( sock, &ws ) ) {};
else if( (intptr_t)cookie == FLAG_SELFPIPE )
io_tryread( sock, ws.inbuf, G_INBUF_SIZE );
else
@ -644,4 +644,4 @@ int main( int argc, char **argv ) {
return 0;
}
const char *g_version_opentracker_c = "$Source: /home/cvsroot/opentracker/opentracker.c,v $: $Revision: 1.233 $\n";
const char *g_version_opentracker_c = "$Source: /home/cvsroot/opentracker/opentracker.c,v $: $Revision: 1.234 $\n";

14
ot_udp.c

@ -28,7 +28,7 @@ static void udp_make_connectionid( uint32_t * connid, const ot_ip6 remoteip ) {
}
/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */
void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
int handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
ot_ip6 remoteip;
uint32_t *inpacket = (uint32_t*)ws->inbuf;
uint32_t *outpacket = (uint32_t*)ws->outbuf;
@ -37,6 +37,7 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
size_t byte_count, scrape_count;
byte_count = socket_recv6( serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport, &scopeid );
if( !byte_count ) return 0;
stats_issue_event( EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip );
stats_issue_event( EVENT_READ, FLAG_UDP, byte_count );
@ -44,16 +45,16 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
/* Initialise hash pointer */
ws->hash = NULL;
ws->peer_id = NULL;
/* Minimum udp tracker packet size, also catches error */
if( byte_count < 16 )
return;
return 1;
switch( ntohl( inpacket[2] ) ) {
case 0: /* This is a connect action */
/* look for udp bittorrent magic id */
if( (ntohl(inpacket[0]) != 0x00000417) || (ntohl(inpacket[1]) != 0x27101980) )
return;
return 1;
outpacket[0] = 0;
outpacket[1] = inpacket[3];
@ -65,7 +66,7 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
case 1: /* This is an announce action */
/* Minimum udp announce packet size */
if( byte_count < 98 )
return;
return 1;
/* We do only want to know, if it is zero */
left = inpacket[64/4] | inpacket[68/4];
@ -116,10 +117,11 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
stats_issue_event( EVENT_SCRAPE, FLAG_UDP, scrape_count );
break;
}
return 1;
}
void udp_init( ) {
}
const char *g_version_udp_c = "$Source: /home/cvsroot/opentracker/ot_udp.c,v $: $Revision: 1.24 $\n";
const char *g_version_udp_c = "$Source: /home/cvsroot/opentracker/ot_udp.c,v $: $Revision: 1.25 $\n";

Loading…
Cancel
Save