mirror of
git://erdgeist.org/opentracker
synced 2025-01-11 15:30:07 +00:00
Prepare udp connection id generation and checking
This commit is contained in:
parent
65c3b24045
commit
8d00b1e039
30
ot_udp.c
30
ot_udp.c
@ -4,6 +4,7 @@
|
||||
/* System */
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Libowfat */
|
||||
#include "socket.h"
|
||||
@ -17,6 +18,24 @@
|
||||
static char static_inbuf[8192];
|
||||
static char static_outbuf[8192];
|
||||
|
||||
static const uint8_t g_static_connid[8] = { 0x23, 0x42, 0x05, 0x17, 0xde, 0x41, 0x50, 0xff };
|
||||
|
||||
static void udp_make_connectionid( uint32_t * connid, const char * remoteip ) {
|
||||
/* Touch unused variable */
|
||||
remoteip = remoteip;
|
||||
|
||||
/* Use a static secret for now */
|
||||
memcpy( connid, g_static_connid, 8 );
|
||||
}
|
||||
|
||||
static int udp_test_connectionid( const uint32_t * const connid, const char * remoteip ) {
|
||||
/* Touch unused variable */
|
||||
remoteip = remoteip;
|
||||
|
||||
/* Test against our static secret */
|
||||
return !memcmp( connid, g_static_connid, 8 );
|
||||
}
|
||||
|
||||
/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */
|
||||
void handle_udp4( int64 serversocket ) {
|
||||
ot_peer peer;
|
||||
@ -44,8 +63,9 @@ void handle_udp4( int64 serversocket ) {
|
||||
|
||||
switch( ntohl( inpacket[2] ) ) {
|
||||
case 0: /* This is a connect action */
|
||||
outpacket[0] = 0; outpacket[1] = inpacket[3];
|
||||
outpacket[2] = inpacket[0]; outpacket[3] = inpacket[1];
|
||||
outpacket[0] = 0;
|
||||
outpacket[1] = inpacket[3];
|
||||
udp_make_connectionid( outpacket + 2, remoteip );
|
||||
socket_send4( serversocket, static_outbuf, 16, remoteip, remoteport );
|
||||
stats_issue_event( EVENT_CONNECT, 0, 16 );
|
||||
break;
|
||||
@ -54,6 +74,9 @@ void handle_udp4( int64 serversocket ) {
|
||||
if( r < 98 )
|
||||
return;
|
||||
|
||||
if( !udp_test_connectionid( inpacket, remoteip ))
|
||||
fprintf( stderr, "UDP Connection id missmatch\n" );
|
||||
|
||||
numwant = 200;
|
||||
/* We do only want to know, if it is zero */
|
||||
left = inpacket[64/4] | inpacket[68/4];
|
||||
@ -93,6 +116,9 @@ void handle_udp4( int64 serversocket ) {
|
||||
break;
|
||||
|
||||
case 2: /* This is a scrape action */
|
||||
if( !udp_test_connectionid( inpacket, remoteip ))
|
||||
fprintf( stderr, "UDP Connection id missmatch\n" );
|
||||
|
||||
outpacket[0] = htonl( 2 ); /* scrape action */
|
||||
outpacket[1] = inpacket[12/4];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user