diff options
author | erdgeist <> | 2009-01-15 23:01:36 +0000 |
---|---|---|
committer | erdgeist <> | 2009-01-15 23:01:36 +0000 |
commit | 66c906d5d3c100e5fe1e6f088bd1ea17c5831894 (patch) | |
tree | 33eb4f386d14327277689e66143d5e607b3eef98 /ot_udp.c | |
parent | 4ced0484abae55546e04954b3dafad46f9db348a (diff) |
Add comments, rename our struct http_data h to cookie, all clientsockets to sock, all size_t from socket_recvs to byte_count. Make signal handler set default handler for the second SIGINT
Diffstat (limited to 'ot_udp.c')
-rw-r--r-- | ot_udp.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -44,15 +44,15 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { | |||
44 | uint32_t *outpacket = (uint32_t*)ws->outbuf; | 44 | uint32_t *outpacket = (uint32_t*)ws->outbuf; |
45 | uint32_t numwant, left, event, scopeid; | 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 byte_count, scrape_count; |
48 | 48 | ||
49 | r = socket_recv6( serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport, &scopeid ); | 49 | byte_count = socket_recv6( serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport, &scopeid ); |
50 | 50 | ||
51 | stats_issue_event( EVENT_ACCEPT, FLAG_UDP, (uintptr_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, byte_count ); |
53 | 53 | ||
54 | /* Minimum udp tracker packet size, also catches error */ | 54 | /* Minimum udp tracker packet size, also catches error */ |
55 | if( r < 16 ) | 55 | if( byte_count < 16 ) |
56 | return; | 56 | return; |
57 | 57 | ||
58 | switch( ntohl( inpacket[2] ) ) { | 58 | switch( ntohl( inpacket[2] ) ) { |
@@ -70,7 +70,7 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { | |||
70 | break; | 70 | break; |
71 | case 1: /* This is an announce action */ | 71 | case 1: /* This is an announce action */ |
72 | /* Minimum udp announce packet size */ | 72 | /* Minimum udp announce packet size */ |
73 | if( r < 98 ) | 73 | if( byte_count < 98 ) |
74 | return; | 74 | return; |
75 | 75 | ||
76 | if( !udp_test_connectionid( inpacket, remoteip )) | 76 | if( !udp_test_connectionid( inpacket, remoteip )) |
@@ -103,12 +103,12 @@ void handle_udp6( 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 | byte_count = 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 | byte_count = 8 + add_peer_to_torrent_and_return_peers( *hash, &peer, FLAG_UDP, numwant, ((char*)outpacket) + 8 ); |
109 | 109 | ||
110 | socket_send6( serversocket, ws->outbuf, r, remoteip, remoteport, 0 ); | 110 | socket_send6( serversocket, ws->outbuf, byte_count, remoteip, remoteport, 0 ); |
111 | stats_issue_event( EVENT_ANNOUNCE, FLAG_UDP, r ); | 111 | stats_issue_event( EVENT_ANNOUNCE, FLAG_UDP, byte_count ); |
112 | break; | 112 | break; |
113 | 113 | ||
114 | case 2: /* This is a scrape action */ | 114 | case 2: /* This is a scrape action */ |
@@ -118,11 +118,11 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { | |||
118 | outpacket[0] = htonl( 2 ); /* scrape action */ | 118 | outpacket[0] = htonl( 2 ); /* scrape action */ |
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( scrape_count = 0; ( scrape_count * 20 < byte_count - 16) && ( scrape_count <= 74 ); scrape_count++ ) |
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 * scrape_count ), ((char*)outpacket) + 8 + 12 * scrape_count ); |
123 | 123 | ||
124 | socket_send6( serversocket, ws->outbuf, 8 + 12 * r_out, remoteip, remoteport, 0 ); | 124 | socket_send6( serversocket, ws->outbuf, 8 + 12 * scrape_count, remoteip, remoteport, 0 ); |
125 | stats_issue_event( EVENT_SCRAPE, FLAG_UDP, r ); | 125 | stats_issue_event( EVENT_SCRAPE, FLAG_UDP, scrape_count ); |
126 | break; | 126 | break; |
127 | } | 127 | } |
128 | } | 128 | } |