summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2007-12-15 17:11:43 +0000
committererdgeist <>2007-12-15 17:11:43 +0000
commit8d00b1e039938c13d47c116827f74211a2d89838 (patch)
treefb647f624ba0da7b4977da6b4d0bd5c605fff6a3
parent65c3b2404560b976bfeff0db190c97d4b9487644 (diff)
Prepare udp connection id generation and checking
-rw-r--r--ot_udp.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/ot_udp.c b/ot_udp.c
index 56b5f44..f34d08f 100644
--- a/ot_udp.c
+++ b/ot_udp.c
@@ -4,6 +4,7 @@
4/* System */ 4/* System */
5#include <string.h> 5#include <string.h>
6#include <arpa/inet.h> 6#include <arpa/inet.h>
7#include <stdio.h>
7 8
8/* Libowfat */ 9/* Libowfat */
9#include "socket.h" 10#include "socket.h"
@@ -17,6 +18,24 @@
17static char static_inbuf[8192]; 18static char static_inbuf[8192];
18static char static_outbuf[8192]; 19static char static_outbuf[8192];
19 20
21static const uint8_t g_static_connid[8] = { 0x23, 0x42, 0x05, 0x17, 0xde, 0x41, 0x50, 0xff };
22
23static void udp_make_connectionid( uint32_t * connid, const char * remoteip ) {
24 /* Touch unused variable */
25 remoteip = remoteip;
26
27 /* Use a static secret for now */
28 memcpy( connid, g_static_connid, 8 );
29}
30
31static int udp_test_connectionid( const uint32_t * const connid, const char * remoteip ) {
32 /* Touch unused variable */
33 remoteip = remoteip;
34
35 /* Test against our static secret */
36 return !memcmp( connid, g_static_connid, 8 );
37}
38
20/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */ 39/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */
21void handle_udp4( int64 serversocket ) { 40void handle_udp4( int64 serversocket ) {
22 ot_peer peer; 41 ot_peer peer;
@@ -44,8 +63,9 @@ void handle_udp4( int64 serversocket ) {
44 63
45 switch( ntohl( inpacket[2] ) ) { 64 switch( ntohl( inpacket[2] ) ) {
46 case 0: /* This is a connect action */ 65 case 0: /* This is a connect action */
47 outpacket[0] = 0; outpacket[1] = inpacket[3]; 66 outpacket[0] = 0;
48 outpacket[2] = inpacket[0]; outpacket[3] = inpacket[1]; 67 outpacket[1] = inpacket[3];
68 udp_make_connectionid( outpacket + 2, remoteip );
49 socket_send4( serversocket, static_outbuf, 16, remoteip, remoteport ); 69 socket_send4( serversocket, static_outbuf, 16, remoteip, remoteport );
50 stats_issue_event( EVENT_CONNECT, 0, 16 ); 70 stats_issue_event( EVENT_CONNECT, 0, 16 );
51 break; 71 break;
@@ -54,6 +74,9 @@ void handle_udp4( int64 serversocket ) {
54 if( r < 98 ) 74 if( r < 98 )
55 return; 75 return;
56 76
77 if( !udp_test_connectionid( inpacket, remoteip ))
78 fprintf( stderr, "UDP Connection id missmatch\n" );
79
57 numwant = 200; 80 numwant = 200;
58 /* We do only want to know, if it is zero */ 81 /* We do only want to know, if it is zero */
59 left = inpacket[64/4] | inpacket[68/4]; 82 left = inpacket[64/4] | inpacket[68/4];
@@ -93,6 +116,9 @@ void handle_udp4( int64 serversocket ) {
93 break; 116 break;
94 117
95 case 2: /* This is a scrape action */ 118 case 2: /* This is a scrape action */
119 if( !udp_test_connectionid( inpacket, remoteip ))
120 fprintf( stderr, "UDP Connection id missmatch\n" );
121
96 outpacket[0] = htonl( 2 ); /* scrape action */ 122 outpacket[0] = htonl( 2 ); /* scrape action */
97 outpacket[1] = inpacket[12/4]; 123 outpacket[1] = inpacket[12/4];
98 124