mirror of
git://erdgeist.org/opentracker
synced 2025-03-29 17:42:55 +08:00
Try to act upon all udp packets at once
This commit is contained in:
parent
1968f47d74
commit
1af67bab1d
@ -266,7 +266,7 @@ static void * server_mainloop( void * args ) {
|
|||||||
if( (intptr_t)cookie == FLAG_TCP )
|
if( (intptr_t)cookie == FLAG_TCP )
|
||||||
handle_accept( sock );
|
handle_accept( sock );
|
||||||
else if( (intptr_t)cookie == FLAG_UDP )
|
else if( (intptr_t)cookie == FLAG_UDP )
|
||||||
handle_udp6( sock, &ws );
|
while( handle_udp6( sock, &ws ) ) {};
|
||||||
else if( (intptr_t)cookie == FLAG_SELFPIPE )
|
else if( (intptr_t)cookie == FLAG_SELFPIPE )
|
||||||
io_tryread( sock, ws.inbuf, G_INBUF_SIZE );
|
io_tryread( sock, ws.inbuf, G_INBUF_SIZE );
|
||||||
else
|
else
|
||||||
|
12
ot_udp.c
12
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 */
|
/* 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;
|
ot_ip6 remoteip;
|
||||||
uint32_t *inpacket = (uint32_t*)ws->inbuf;
|
uint32_t *inpacket = (uint32_t*)ws->inbuf;
|
||||||
uint32_t *outpacket = (uint32_t*)ws->outbuf;
|
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;
|
size_t byte_count, scrape_count;
|
||||||
|
|
||||||
byte_count = socket_recv6( serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport, &scopeid );
|
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_ACCEPT, FLAG_UDP, (uintptr_t)remoteip );
|
||||||
stats_issue_event( EVENT_READ, FLAG_UDP, byte_count );
|
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 */
|
/* Initialise hash pointer */
|
||||||
ws->hash = NULL;
|
ws->hash = NULL;
|
||||||
ws->peer_id = NULL;
|
ws->peer_id = NULL;
|
||||||
|
|
||||||
/* Minimum udp tracker packet size, also catches error */
|
/* Minimum udp tracker packet size, also catches error */
|
||||||
if( byte_count < 16 )
|
if( byte_count < 16 )
|
||||||
return;
|
return 1;
|
||||||
|
|
||||||
switch( ntohl( inpacket[2] ) ) {
|
switch( ntohl( inpacket[2] ) ) {
|
||||||
case 0: /* This is a connect action */
|
case 0: /* This is a connect action */
|
||||||
/* look for udp bittorrent magic id */
|
/* look for udp bittorrent magic id */
|
||||||
if( (ntohl(inpacket[0]) != 0x00000417) || (ntohl(inpacket[1]) != 0x27101980) )
|
if( (ntohl(inpacket[0]) != 0x00000417) || (ntohl(inpacket[1]) != 0x27101980) )
|
||||||
return;
|
return 1;
|
||||||
|
|
||||||
outpacket[0] = 0;
|
outpacket[0] = 0;
|
||||||
outpacket[1] = inpacket[3];
|
outpacket[1] = inpacket[3];
|
||||||
@ -65,7 +66,7 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
|
|||||||
case 1: /* This is an announce action */
|
case 1: /* This is an announce action */
|
||||||
/* Minimum udp announce packet size */
|
/* Minimum udp announce packet size */
|
||||||
if( byte_count < 98 )
|
if( byte_count < 98 )
|
||||||
return;
|
return 1;
|
||||||
|
|
||||||
/* We do only want to know, if it is zero */
|
/* We do only want to know, if it is zero */
|
||||||
left = inpacket[64/4] | inpacket[68/4];
|
left = inpacket[64/4] | inpacket[68/4];
|
||||||
@ -116,6 +117,7 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
|
|||||||
stats_issue_event( EVENT_SCRAPE, FLAG_UDP, scrape_count );
|
stats_issue_event( EVENT_SCRAPE, FLAG_UDP, scrape_count );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_init( ) {
|
void udp_init( ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user