diff options
Diffstat (limited to 'opentracker.c')
-rw-r--r-- | opentracker.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/opentracker.c b/opentracker.c index 0ff0100..a1f0311 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -23,6 +23,7 @@ | |||
23 | 23 | ||
24 | static unsigned int ot_overall_connections = 0; | 24 | static unsigned int ot_overall_connections = 0; |
25 | static time_t ot_start_time; | 25 | static time_t ot_start_time; |
26 | static const unsigned int SUCCESS_HTTP_HEADER_LENGTH = 80; | ||
26 | 27 | ||
27 | static void carp(const char* routine) { | 28 | static void carp(const char* routine) { |
28 | buffer_puts(buffer_2,routine); | 29 | buffer_puts(buffer_2,routine); |
@@ -160,9 +161,9 @@ e400: | |||
160 | } | 161 | } |
161 | 162 | ||
162 | // Enough for http header + whole scrape string | 163 | // Enough for http header + whole scrape string |
163 | reply = malloc( 208 ); | 164 | reply = malloc( SUCCESS_HTTP_HEADER_LENGTH + 128 ); |
164 | if( reply ) | 165 | if( reply ) |
165 | reply_size = return_scrape_for_torrent( hash, 80 + reply ); | 166 | reply_size = return_scrape_for_torrent( hash, SUCCESS_HTTP_HEADER_LENGTH + reply ); |
166 | if( !reply || ( reply_size < 0 ) ) { | 167 | if( !reply || ( reply_size < 0 ) ) { |
167 | if( reply ) free( reply ); | 168 | if( reply ) free( reply ); |
168 | goto e500; | 169 | goto e500; |
@@ -251,10 +252,10 @@ e400: | |||
251 | 252 | ||
252 | if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) { | 253 | if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) { |
253 | remove_peer_from_torrent( hash, &peer ); | 254 | remove_peer_from_torrent( hash, &peer ); |
254 | reply = malloc( 106 ); | 255 | reply = malloc( SUCCESS_HTTP_HEADER_LENGTH + 26 ); |
255 | if( !reply ) | 256 | if( !reply ) |
256 | goto e500; | 257 | goto e500; |
257 | MEMMOVE( reply + 80, "d15:warning message4:Okaye", reply_size = 26 ); | 258 | MEMMOVE( reply + SUCCESS_HTTP_HEADER_LENGTH, "d15:warning message4:Okaye", reply_size = 26 ); |
258 | } else { | 259 | } else { |
259 | torrent = add_peer_to_torrent( hash, &peer ); | 260 | torrent = add_peer_to_torrent( hash, &peer ); |
260 | if( !torrent ) { | 261 | if( !torrent ) { |
@@ -262,9 +263,9 @@ e500: | |||
262 | httperror(h,"500 Internal Server Error","A server error has occured. Please retry later."); | 263 | httperror(h,"500 Internal Server Error","A server error has occured. Please retry later."); |
263 | goto bailout; | 264 | goto bailout; |
264 | } | 265 | } |
265 | reply = malloc( 80+numwant*6+128 ); // http header + peerlist + seeder, peers and lametta 80 + n*6+81 a.t.m. | 266 | reply = malloc( SUCCESS_HTTP_HEADER_LENGTH + numwant*6 + 128 ); // http header + peerlist + seeder, peers and lametta 80 + n*6+81 a.t.m. |
266 | if( reply ) | 267 | if( reply ) |
267 | reply_size = return_peers_for_torrent( torrent, numwant, 80 + reply ); | 268 | reply_size = return_peers_for_torrent( torrent, numwant, SUCCESS_HTTP_HEADER_LENGTH + reply ); |
268 | if( !reply || ( reply_size <= 0 ) ) { | 269 | if( !reply || ( reply_size <= 0 ) ) { |
269 | if( reply ) free( reply ); | 270 | if( reply ) free( reply ); |
270 | goto e500; | 271 | goto e500; |
@@ -274,11 +275,13 @@ e500: | |||
274 | case 11: | 275 | case 11: |
275 | if( byte_diff(data,11,"mrtg_scrape")) | 276 | if( byte_diff(data,11,"mrtg_scrape")) |
276 | goto e404; | 277 | goto e404; |
277 | reply = malloc( 256 ); | 278 | reply = malloc( SUCCESS_HTTP_HEADER_LENGTH + 128 ); |
278 | { | 279 | { |
279 | unsigned long seconds_elapsed = time( NULL ) - ot_start_time; | 280 | unsigned long seconds_elapsed = time( NULL ) - ot_start_time; |
280 | reply_size = sprintf( 80+reply, "%d\n%d\nUp: %ld seconds (%ld hours)\nPretuned by german engineers, currently handling %li connections per second.", | 281 | reply_size = sprintf( reply + SUCCESS_HTTP_HEADER_LENGTH, |
281 | ot_overall_connections, ot_overall_connections, seconds_elapsed, seconds_elapsed / 3600, ot_overall_connections / ( seconds_elapsed ? seconds_elapsed : 1 ) ); | 282 | "%d\n%d\nUp: %ld seconds (%ld hours)\nPretuned by german engineers, currently handling %li connections per second.", |
283 | ot_overall_connections, ot_overall_connections, seconds_elapsed, | ||
284 | seconds_elapsed / 3600, ot_overall_connections / ( seconds_elapsed ? seconds_elapsed : 1 ) ); | ||
282 | } | 285 | } |
283 | break; | 286 | break; |
284 | default: /* neither *scrape nor announce */ | 287 | default: /* neither *scrape nor announce */ |
@@ -288,9 +291,9 @@ e404: | |||
288 | } | 291 | } |
289 | 292 | ||
290 | if( reply && reply_size ) { | 293 | if( reply && reply_size ) { |
291 | MEMMOVE( reply, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: X \r\n\r\n", 80 ); | 294 | MEMMOVE( reply, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: X \r\n\r\n", SUCCESS_HTTP_HEADER_LENGTH ); |
292 | fmt_ulonglong( reply+59, (long long)reply_size ); | 295 | fmt_ulonglong( reply+59, (long long)reply_size ); |
293 | iob_addbuf_free(&h->iob, reply, 80+reply_size ); | 296 | iob_addbuf_free(&h->iob, reply, SUCCESS_HTTP_HEADER_LENGTH + reply_size ); |
294 | } | 297 | } |
295 | 298 | ||
296 | bailout: | 299 | bailout: |