diff options
author | erdgeist <> | 2009-01-13 22:41:17 +0000 |
---|---|---|
committer | erdgeist <> | 2009-01-13 22:41:17 +0000 |
commit | 131211b4daf83b7c594337f4e7c71e4711094d71 (patch) | |
tree | 63dc942c426103c01d61aa15959a81df91f2d4e1 /ot_udp.c | |
parent | 779d6c235ff8fe5284fd10dc82a9b99e7fa38d06 (diff) |
V6
Diffstat (limited to 'ot_udp.c')
-rw-r--r-- | ot_udp.c | 28 |
1 files changed, 14 insertions, 14 deletions
@@ -19,15 +19,15 @@ | |||
19 | 19 | ||
20 | static const uint8_t g_static_connid[8] = { 0x23, 0x42, 0x05, 0x17, 0xde, 0x41, 0x50, 0xff }; | 20 | static const uint8_t g_static_connid[8] = { 0x23, 0x42, 0x05, 0x17, 0xde, 0x41, 0x50, 0xff }; |
21 | 21 | ||
22 | static void udp_make_connectionid( uint32_t * connid, const char * remoteip ) { | 22 | static void udp_make_connectionid( uint32_t * connid, const ot_ip6 remoteip ) { |
23 | /* Touch unused variable */ | 23 | /* Touch unused variable */ |
24 | (void)remoteip; | 24 | (void)remoteip; |
25 | 25 | ||
26 | /* Use a static secret for now */ | 26 | /* Use a static secret for now */ |
27 | memmove( connid, g_static_connid, 8 ); | 27 | memcpy( connid, g_static_connid, 8 ); |
28 | } | 28 | } |
29 | 29 | ||
30 | static int udp_test_connectionid( const uint32_t * const connid, const char * remoteip ) { | 30 | static int udp_test_connectionid( const uint32_t * const connid, const ot_ip6 remoteip ) { |
31 | /* Touch unused variable */ | 31 | /* Touch unused variable */ |
32 | (void)remoteip; | 32 | (void)remoteip; |
33 | 33 | ||
@@ -36,19 +36,19 @@ static int udp_test_connectionid( const uint32_t * const connid, const char * re | |||
36 | } | 36 | } |
37 | 37 | ||
38 | /* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */ | 38 | /* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */ |
39 | void handle_udp4( int64 serversocket, struct ot_workstruct *ws ) { | 39 | void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { |
40 | ot_peer peer; | 40 | ot_peer peer; |
41 | ot_hash *hash = NULL; | 41 | ot_hash *hash = NULL; |
42 | char remoteip[4]; | 42 | ot_ip6 remoteip; |
43 | uint32_t *inpacket = (uint32_t*)ws->inbuf; | 43 | uint32_t *inpacket = (uint32_t*)ws->inbuf; |
44 | uint32_t *outpacket = (uint32_t*)ws->outbuf; | 44 | uint32_t *outpacket = (uint32_t*)ws->outbuf; |
45 | uint32_t numwant, left, event; | 45 | uint32_t numwant, left, event, scopeid; |
46 | uint16_t port, remoteport; | 46 | uint16_t port, remoteport; |
47 | size_t r, r_out; | 47 | size_t r, r_out; |
48 | 48 | ||
49 | r = socket_recv4( serversocket, ws->inbuf, ws->inbuf_size, remoteip, &remoteport); | 49 | r = socket_recv6( serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport, &scopeid ); |
50 | 50 | ||
51 | stats_issue_event( EVENT_ACCEPT, FLAG_UDP, ntohl(*(uint32_t*)remoteip) ); | 51 | stats_issue_event( EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip ); |
52 | stats_issue_event( EVENT_READ, FLAG_UDP, r ); | 52 | stats_issue_event( EVENT_READ, FLAG_UDP, r ); |
53 | 53 | ||
54 | /* Minimum udp tracker packet size, also catches error */ | 54 | /* Minimum udp tracker packet size, also catches error */ |
@@ -65,7 +65,7 @@ void handle_udp4( int64 serversocket, struct ot_workstruct *ws ) { | |||
65 | outpacket[1] = inpacket[3]; | 65 | outpacket[1] = inpacket[3]; |
66 | udp_make_connectionid( outpacket + 2, remoteip ); | 66 | udp_make_connectionid( outpacket + 2, remoteip ); |
67 | 67 | ||
68 | socket_send4( serversocket, ws->outbuf, 16, remoteip, remoteport ); | 68 | socket_send6( serversocket, ws->outbuf, 16, remoteip, remoteport, 0 ); |
69 | stats_issue_event( EVENT_CONNECT, FLAG_UDP, 16 ); | 69 | stats_issue_event( EVENT_CONNECT, FLAG_UDP, 16 ); |
70 | break; | 70 | break; |
71 | case 1: /* This is an announce action */ | 71 | case 1: /* This is an announce action */ |
@@ -103,11 +103,11 @@ void handle_udp4( int64 serversocket, struct ot_workstruct *ws ) { | |||
103 | outpacket[1] = inpacket[12/4]; | 103 | outpacket[1] = inpacket[12/4]; |
104 | 104 | ||
105 | if( OT_PEERFLAG( &peer ) & PEER_FLAG_STOPPED ) /* Peer is gone. */ | 105 | if( OT_PEERFLAG( &peer ) & PEER_FLAG_STOPPED ) /* Peer is gone. */ |
106 | r = remove_peer_from_torrent( hash, &peer, ws->outbuf, FLAG_UDP ); | 106 | r = remove_peer_from_torrent( *hash, &peer, ws->outbuf, FLAG_UDP ); |
107 | else | 107 | else |
108 | r = 8 + add_peer_to_torrent_and_return_peers( hash, &peer, FLAG_UDP, numwant, ((char*)outpacket) + 8 ); | 108 | r = 8 + add_peer_to_torrent_and_return_peers( *hash, &peer, FLAG_UDP, numwant, ((char*)outpacket) + 8 ); |
109 | 109 | ||
110 | socket_send4( serversocket, ws->outbuf, r, remoteip, remoteport ); | 110 | socket_send6( serversocket, ws->outbuf, r, remoteip, remoteport, 0 ); |
111 | stats_issue_event( EVENT_ANNOUNCE, FLAG_UDP, r ); | 111 | stats_issue_event( EVENT_ANNOUNCE, FLAG_UDP, r ); |
112 | break; | 112 | break; |
113 | 113 | ||
@@ -119,9 +119,9 @@ void handle_udp4( int64 serversocket, struct ot_workstruct *ws ) { | |||
119 | outpacket[1] = inpacket[12/4]; | 119 | outpacket[1] = inpacket[12/4]; |
120 | 120 | ||
121 | for( r_out = 0; ( r_out * 20 < r - 16) && ( r_out <= 74 ); r_out++ ) | 121 | for( r_out = 0; ( r_out * 20 < r - 16) && ( r_out <= 74 ); r_out++ ) |
122 | return_udp_scrape_for_torrent( (ot_hash*)( ((char*)inpacket) + 16 + 20 * r_out ), ((char*)outpacket) + 8 + 12 * r_out ); | 122 | return_udp_scrape_for_torrent( *(ot_hash*)( ((char*)inpacket) + 16 + 20 * r_out ), ((char*)outpacket) + 8 + 12 * r_out ); |
123 | 123 | ||
124 | socket_send4( serversocket, ws->outbuf, 8 + 12 * r_out, remoteip, remoteport ); | 124 | socket_send6( serversocket, ws->outbuf, 8 + 12 * r_out, remoteip, remoteport, 0 ); |
125 | stats_issue_event( EVENT_SCRAPE, FLAG_UDP, r ); | 125 | stats_issue_event( EVENT_SCRAPE, FLAG_UDP, r ); |
126 | break; | 126 | break; |
127 | } | 127 | } |