summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2012-03-31 20:01:05 +0000
committererdgeist <>2012-03-31 20:01:05 +0000
commit1af67bab1d0286ecb777529d2b0f8bf9dc98a8b2 (patch)
tree16f9db7f8e18359ba136935e8d81662f309bb9c8
parent1968f47d7429afbbf1b84795c8d0284c93aa5061 (diff)
Try to act upon all udp packets at once
-rw-r--r--opentracker.c2
-rw-r--r--ot_udp.c12
2 files changed, 8 insertions, 6 deletions
diff --git a/opentracker.c b/opentracker.c
index 0c535ec..52078b5 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -266,7 +266,7 @@ static void * server_mainloop( void * args ) {
266 if( (intptr_t)cookie == FLAG_TCP ) 266 if( (intptr_t)cookie == FLAG_TCP )
267 handle_accept( sock ); 267 handle_accept( sock );
268 else if( (intptr_t)cookie == FLAG_UDP ) 268 else if( (intptr_t)cookie == FLAG_UDP )
269 handle_udp6( sock, &ws ); 269 while( handle_udp6( sock, &ws ) ) {};
270 else if( (intptr_t)cookie == FLAG_SELFPIPE ) 270 else if( (intptr_t)cookie == FLAG_SELFPIPE )
271 io_tryread( sock, ws.inbuf, G_INBUF_SIZE ); 271 io_tryread( sock, ws.inbuf, G_INBUF_SIZE );
272 else 272 else
diff --git a/ot_udp.c b/ot_udp.c
index bc2d6cc..e891494 100644
--- a/ot_udp.c
+++ b/ot_udp.c
@@ -28,7 +28,7 @@ static void udp_make_connectionid( uint32_t * connid, const ot_ip6 remoteip ) {
28} 28}
29 29
30/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */ 30/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */
31void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { 31int handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
32 ot_ip6 remoteip; 32 ot_ip6 remoteip;
33 uint32_t *inpacket = (uint32_t*)ws->inbuf; 33 uint32_t *inpacket = (uint32_t*)ws->inbuf;
34 uint32_t *outpacket = (uint32_t*)ws->outbuf; 34 uint32_t *outpacket = (uint32_t*)ws->outbuf;
@@ -37,6 +37,7 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
37 size_t byte_count, scrape_count; 37 size_t byte_count, scrape_count;
38 38
39 byte_count = socket_recv6( serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport, &scopeid ); 39 byte_count = socket_recv6( serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport, &scopeid );
40 if( !byte_count ) return 0;
40 41
41 stats_issue_event( EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip ); 42 stats_issue_event( EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip );
42 stats_issue_event( EVENT_READ, FLAG_UDP, byte_count ); 43 stats_issue_event( EVENT_READ, FLAG_UDP, byte_count );
@@ -44,16 +45,16 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
44 /* Initialise hash pointer */ 45 /* Initialise hash pointer */
45 ws->hash = NULL; 46 ws->hash = NULL;
46 ws->peer_id = NULL; 47 ws->peer_id = NULL;
47 48
48 /* Minimum udp tracker packet size, also catches error */ 49 /* Minimum udp tracker packet size, also catches error */
49 if( byte_count < 16 ) 50 if( byte_count < 16 )
50 return; 51 return 1;
51 52
52 switch( ntohl( inpacket[2] ) ) { 53 switch( ntohl( inpacket[2] ) ) {
53 case 0: /* This is a connect action */ 54 case 0: /* This is a connect action */
54 /* look for udp bittorrent magic id */ 55 /* look for udp bittorrent magic id */
55 if( (ntohl(inpacket[0]) != 0x00000417) || (ntohl(inpacket[1]) != 0x27101980) ) 56 if( (ntohl(inpacket[0]) != 0x00000417) || (ntohl(inpacket[1]) != 0x27101980) )
56 return; 57 return 1;
57 58
58 outpacket[0] = 0; 59 outpacket[0] = 0;
59 outpacket[1] = inpacket[3]; 60 outpacket[1] = inpacket[3];
@@ -65,7 +66,7 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
65 case 1: /* This is an announce action */ 66 case 1: /* This is an announce action */
66 /* Minimum udp announce packet size */ 67 /* Minimum udp announce packet size */
67 if( byte_count < 98 ) 68 if( byte_count < 98 )
68 return; 69 return 1;
69 70
70 /* We do only want to know, if it is zero */ 71 /* We do only want to know, if it is zero */
71 left = inpacket[64/4] | inpacket[68/4]; 72 left = inpacket[64/4] | inpacket[68/4];
@@ -116,6 +117,7 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
116 stats_issue_event( EVENT_SCRAPE, FLAG_UDP, scrape_count ); 117 stats_issue_event( EVENT_SCRAPE, FLAG_UDP, scrape_count );
117 break; 118 break;
118 } 119 }
120 return 1;
119} 121}
120 122
121void udp_init( ) { 123void udp_init( ) {