diff options
author | erdgeist <> | 2007-11-06 01:28:40 +0000 |
---|---|---|
committer | erdgeist <> | 2007-11-06 01:28:40 +0000 |
commit | a859ae78e5e32b9ba616be4ed07f9ec7fba04903 (patch) | |
tree | 4d1070c0cdc8d958cb99c854557ad49b65dda295 /opentracker.c | |
parent | 3bf7878833de2551606d9cb98b13cf224eb2f6fc (diff) |
Cleaned up stats return format. Also reflect APPI changes due to MT code in trackerlogic.{c,h}
Diffstat (limited to 'opentracker.c')
-rw-r--r-- | opentracker.c | 126 |
1 files changed, 54 insertions, 72 deletions
diff --git a/opentracker.c b/opentracker.c index 013441a..00fe65f 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -230,7 +230,7 @@ static void httpresponse( const int64 s, char *data _DEBUG_HTTPERROR_PARAM( size | |||
230 | ot_peer peer; | 230 | ot_peer peer; |
231 | ot_torrent *torrent; | 231 | ot_torrent *torrent; |
232 | ot_hash *hash = NULL; | 232 | ot_hash *hash = NULL; |
233 | int numwant, tmp, scanon, mode, scrape_count; | 233 | int numwant, tmp, scanon, mode; |
234 | unsigned short port = htons(6881); | 234 | unsigned short port = htons(6881); |
235 | time_t t; | 235 | time_t t; |
236 | ssize_t len; | 236 | ssize_t len; |
@@ -306,7 +306,7 @@ LOG_TO_STDERR( "sync: %d.%d.%d.%d\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); | |||
306 | if( !byte_diff( data, 2, "sc" ) ) goto SCRAPE_WORKAROUND; | 306 | if( !byte_diff( data, 2, "sc" ) ) goto SCRAPE_WORKAROUND; |
307 | if( byte_diff(data,5,"stats")) HTTPERROR_404; | 307 | if( byte_diff(data,5,"stats")) HTTPERROR_404; |
308 | scanon = 1; | 308 | scanon = 1; |
309 | mode = STATS_MRTG; | 309 | mode = STATS_PEERS; |
310 | 310 | ||
311 | while( scanon ) { | 311 | while( scanon ) { |
312 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { | 312 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { |
@@ -319,8 +319,10 @@ LOG_TO_STDERR( "sync: %d.%d.%d.%d\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); | |||
319 | continue; | 319 | continue; |
320 | } | 320 | } |
321 | if( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) != 4 ) HTTPERROR_400_PARAM; | 321 | if( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) != 4 ) HTTPERROR_400_PARAM; |
322 | if( !byte_diff(data,4,"mrtg")) | 322 | if( !byte_diff(data,4,"peer")) |
323 | mode = STATS_MRTG; | 323 | mode = STATS_PEERS; |
324 | else if( !byte_diff(data,4,"conn")) | ||
325 | mode = STATS_CONNS; | ||
324 | else if( !byte_diff(data,4,"top5")) | 326 | else if( !byte_diff(data,4,"top5")) |
325 | mode = STATS_TOP5; | 327 | mode = STATS_TOP5; |
326 | else if( !byte_diff(data,4,"fscr")) | 328 | else if( !byte_diff(data,4,"fscr")) |
@@ -333,68 +335,58 @@ LOG_TO_STDERR( "sync: %d.%d.%d.%d\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); | |||
333 | mode = STATS_UDP; | 335 | mode = STATS_UDP; |
334 | else if( !byte_diff(data,4,"s24s")) | 336 | else if( !byte_diff(data,4,"s24s")) |
335 | mode = STATS_SLASH24S; | 337 | mode = STATS_SLASH24S; |
336 | else if( !byte_diff(data,4,"s24S")) | ||
337 | mode = STATS_SLASH24S_OLD; | ||
338 | else | 338 | else |
339 | HTTPERROR_400_PARAM; | 339 | HTTPERROR_400_PARAM; |
340 | } | 340 | } |
341 | } | 341 | } |
342 | 342 | ||
343 | switch( mode) | 343 | switch( mode) |
344 | { | 344 | { |
345 | case STATS_DMEM: | 345 | case STATS_DMEM: |
346 | LOG_TO_STDERR( "stats: %d.%d.%d.%d - mode: dmem\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); | 346 | if( !( reply_size = return_memstat_for_tracker( &reply ) ) ) HTTPERROR_500; |
347 | 347 | return sendmmapdata( s, reply, reply_size ); | |
348 | if( !( reply_size = return_memstat_for_tracker( &reply ) ) ) HTTPERROR_500; | ||
349 | return sendmmapdata( s, reply, reply_size ); | ||
350 | |||
351 | case STATS_UDP: | ||
352 | t = time( NULL ) - ot_start_time; | ||
353 | reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, | ||
354 | "%llu\n%llu\n%i seconds (%i hours)\nopentracker udp4 stats.", | ||
355 | ot_overall_udp_connections, ot_overall_udp_successfulannounces, (int)t, (int)(t / 3600) ); | ||
356 | break; | ||
357 | 348 | ||
358 | case STATS_TCP: | 349 | case STATS_CONNS: |
359 | t = time( NULL ) - ot_start_time; | 350 | t = time( NULL ) - ot_start_time; |
360 | reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, | 351 | reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, |
361 | "%llu\n%llu\n%i seconds (%i hours)\nopentracker tcp4 stats.", | 352 | "%llu\n%llu\n%i seconds (%i hours)\nopentracker - Pretuned by german engineers, currently handling %llu connections per second.", |
362 | ot_overall_tcp_connections, ot_overall_tcp_successfulannounces, (int)t, (int)(t / 3600) ); | 353 | ot_overall_tcp_connections+ot_overall_udp_connections, ot_overall_tcp_successfulannounces+ot_overall_udp_successfulannounces, (int)t, (int)(t / 3600), (ot_overall_tcp_connections+ot_overall_udp_connections) / ( (unsigned int)t ? (unsigned int)t : 1 ) ); |
363 | break; | 354 | break; |
355 | case STATS_UDP: | ||
356 | t = time( NULL ) - ot_start_time; | ||
357 | reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, | ||
358 | "%llu\n%llu\n%i seconds (%i hours)\nopentracker udp4 stats.", | ||
359 | ot_overall_udp_connections, ot_overall_udp_successfulannounces, (int)t, (int)(t / 3600) ); | ||
360 | break; | ||
364 | 361 | ||
365 | default: | 362 | case STATS_TCP: |
366 | case STATS_MRTG: | 363 | t = time( NULL ) - ot_start_time; |
367 | /* Enough for http header + whole scrape string */ | 364 | reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, |
368 | if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500; | 365 | "%llu\n%llu\n%i seconds (%i hours)\nopentracker tcp4 stats.", |
369 | break; | 366 | ot_overall_tcp_connections, ot_overall_tcp_successfulannounces, (int)t, (int)(t / 3600) ); |
367 | break; | ||
370 | 368 | ||
371 | case STATS_FULLSCRAPE: | 369 | default: |
372 | t = time( NULL ) - ot_start_time; | 370 | case STATS_PEERS: |
373 | reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, | 371 | /* Enough for http header + whole scrape string */ |
374 | "%llu\n%llu\n%i seconds (%i hours)\nopentracker full scrape stats.", | 372 | if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500; |
375 | ot_full_scrape_count * 1000, ot_full_scrape_size, (int)t, (int)(t / 3600) ); | 373 | break; |
376 | break; | ||
377 | 374 | ||
378 | case STATS_SLASH24S: | 375 | case STATS_FULLSCRAPE: |
379 | { | 376 | t = time( NULL ) - ot_start_time; |
380 | LOG_TO_STDERR( "stats: %d.%d.%d.%d - mode: s24s\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); | 377 | reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, |
378 | "%llu\n%llu\n%i seconds (%i hours)\nopentracker full scrape stats.", | ||
379 | ot_full_scrape_count * 1000, ot_full_scrape_size, (int)t, (int)(t / 3600) ); | ||
380 | break; | ||
381 | 381 | ||
382 | case STATS_SLASH24S: | ||
383 | { | ||
382 | ot_dword diff; struct timeval tv1, tv2; gettimeofday( &tv1, NULL ); | 384 | ot_dword diff; struct timeval tv1, tv2; gettimeofday( &tv1, NULL ); |
383 | if( !( reply_size = return_stats_for_slash24s( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 16 ) ) ) HTTPERROR_500; | 385 | if( !( reply_size = return_stats_for_slash24s( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 16 ) ) ) HTTPERROR_500; |
384 | gettimeofday( &tv2, NULL ); diff = ( tv2.tv_sec - tv1.tv_sec ) * 1000000 + tv2.tv_usec - tv1.tv_usec; | 386 | gettimeofday( &tv2, NULL ); diff = ( tv2.tv_sec - tv1.tv_sec ) * 1000000 + tv2.tv_usec - tv1.tv_usec; |
385 | reply_size += sprintf( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf + reply_size, "Time taken: %u\n", diff ); | 387 | reply_size += sprintf( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf + reply_size, "Time taken: %u\n", diff ); |
386 | break; | 388 | } |
387 | } | 389 | break; |
388 | case STATS_SLASH24S_OLD: | ||
389 | { | ||
390 | LOG_TO_STDERR( "stats: %d.%d.%d.%d - mode: s24s old\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); | ||
391 | |||
392 | ot_dword diff; struct timeval tv1, tv2; gettimeofday( &tv1, NULL ); | ||
393 | if( !( reply_size = return_stats_for_slash24s_old( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 16 ) ) ) HTTPERROR_500; | ||
394 | gettimeofday( &tv2, NULL ); diff = ( tv2.tv_sec - tv1.tv_sec ) * 1000000 + tv2.tv_usec - tv1.tv_usec; | ||
395 | reply_size += sprintf( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf + reply_size, "Time taken: %u\n", diff ); | ||
396 | break; | ||
397 | } | ||
398 | } | 390 | } |
399 | break; | 391 | break; |
400 | 392 | ||
@@ -432,12 +424,12 @@ SCRAPE_WORKAROUND: | |||
432 | } | 424 | } |
433 | 425 | ||
434 | scanon = 1; | 426 | scanon = 1; |
435 | scrape_count = 0; | 427 | numwant = 0; |
436 | while( scanon ) { | 428 | while( scanon ) { |
437 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { | 429 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { |
438 | case -2: scanon = 0; break; /* TERMINATOR */ | 430 | case -2: scanon = 0; break; /* TERMINATOR */ |
439 | case -1: | 431 | case -1: |
440 | if( scrape_count ) | 432 | if( numwant ) |
441 | goto UTORRENT1600_WORKAROUND; | 433 | goto UTORRENT1600_WORKAROUND; |
442 | HTTPERROR_400_PARAM; /* PARSE ERROR */ | 434 | HTTPERROR_400_PARAM; /* PARSE ERROR */ |
443 | default: scan_urlencoded_skipvalue( &c ); break; | 435 | default: scan_urlencoded_skipvalue( &c ); break; |
@@ -453,8 +445,8 @@ SCRAPE_WORKAROUND: | |||
453 | #endif | 445 | #endif |
454 | HTTPERROR_400_PARAM; | 446 | HTTPERROR_400_PARAM; |
455 | } | 447 | } |
456 | if( scrape_count < OT_MAXMULTISCRAPE_COUNT ) | 448 | if( numwant < OT_MAXMULTISCRAPE_COUNT ) |
457 | memmove( multiscrape_buf + scrape_count++, data, sizeof(ot_hash) ); | 449 | memmove( multiscrape_buf + numwant++, data, sizeof(ot_hash) ); |
458 | break; | 450 | break; |
459 | } | 451 | } |
460 | } | 452 | } |
@@ -462,10 +454,10 @@ SCRAPE_WORKAROUND: | |||
462 | UTORRENT1600_WORKAROUND: | 454 | UTORRENT1600_WORKAROUND: |
463 | 455 | ||
464 | /* No info_hash found? Inform user */ | 456 | /* No info_hash found? Inform user */ |
465 | if( !scrape_count ) HTTPERROR_400_PARAM; | 457 | if( !numwant ) HTTPERROR_400_PARAM; |
466 | 458 | ||
467 | /* Enough for http header + whole scrape string */ | 459 | /* Enough for http header + whole scrape string */ |
468 | if( !( reply_size = return_tcp_scrape_for_torrent( multiscrape_buf, scrape_count, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) ) HTTPERROR_500; | 460 | if( !( reply_size = return_tcp_scrape_for_torrent( multiscrape_buf, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) ) HTTPERROR_500; |
469 | 461 | ||
470 | ot_overall_tcp_successfulannounces++; | 462 | ot_overall_tcp_successfulannounces++; |
471 | break; | 463 | break; |
@@ -568,20 +560,10 @@ ANNOUNCE_WORKAROUND: | |||
568 | reply_size = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 ); | 560 | reply_size = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 ); |
569 | else { | 561 | else { |
570 | torrent = add_peer_to_torrent( hash, &peer, 0 ); | 562 | torrent = add_peer_to_torrent( hash, &peer, 0 ); |
571 | if( !torrent || !( reply_size = return_peers_for_torrent( torrent, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 ) ) ) HTTPERROR_500; | 563 | if( !torrent || !( reply_size = return_peers_for_torrent( hash, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 ) ) ) HTTPERROR_500; |
572 | } | 564 | } |
573 | ot_overall_tcp_successfulannounces++; | 565 | ot_overall_tcp_successfulannounces++; |
574 | break; | 566 | break; |
575 | case 11: | ||
576 | if( *data == 'a' ) goto ANNOUNCE_WORKAROUND; | ||
577 | if( !byte_diff( data, 2, "sc" ) ) goto SCRAPE_WORKAROUND; | ||
578 | if( byte_diff( data, 11, "mrtg_scrape" ) ) HTTPERROR_404; | ||
579 | |||
580 | t = time( NULL ) - ot_start_time; | ||
581 | reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, | ||
582 | "%llu\n%llu\n%i seconds (%i hours)\nopentracker - Pretuned by german engineers, currently handling %llu connections per second.", | ||
583 | ot_overall_tcp_connections+ot_overall_udp_connections, ot_overall_tcp_successfulannounces+ot_overall_udp_successfulannounces, (int)t, (int)(t / 3600), (ot_overall_tcp_connections+ot_overall_udp_connections) / ( (unsigned int)t ? (unsigned int)t : 1 ) ); | ||
584 | break; | ||
585 | default: | 567 | default: |
586 | if( ( *data == 'a' ) || ( *data == '?' ) ) goto ANNOUNCE_WORKAROUND; | 568 | if( ( *data == 'a' ) || ( *data == '?' ) ) goto ANNOUNCE_WORKAROUND; |
587 | if( !byte_diff( data, 2, "sc" ) ) goto SCRAPE_WORKAROUND; | 569 | if( !byte_diff( data, 2, "sc" ) ) goto SCRAPE_WORKAROUND; |
@@ -612,7 +594,7 @@ ANNOUNCE_WORKAROUND: | |||
612 | static void signal_handler( int s ) { | 594 | static void signal_handler( int s ) { |
613 | if( s == SIGINT ) { | 595 | if( s == SIGINT ) { |
614 | signal( SIGINT, SIG_IGN); | 596 | signal( SIGINT, SIG_IGN); |
615 | deinit_logic(); | 597 | trackerlogic_deinit(); |
616 | exit( 0 ); | 598 | exit( 0 ); |
617 | } else if( s == SIGALRM ) { | 599 | } else if( s == SIGALRM ) { |
618 | g_now = time(NULL); | 600 | g_now = time(NULL); |
@@ -815,7 +797,7 @@ static void handle_udp4( int64 serversocket ) { | |||
815 | if( !torrent ) | 797 | if( !torrent ) |
816 | return; /* XXX maybe send error */ | 798 | return; /* XXX maybe send error */ |
817 | 799 | ||
818 | r = 8 + return_peers_for_torrent( torrent, numwant, static_outbuf + 8, 0 ); | 800 | r = 8 + return_peers_for_torrent( hash, numwant, static_outbuf + 8, 0 ); |
819 | } | 801 | } |
820 | 802 | ||
821 | socket_send4( serversocket, static_outbuf, r, remoteip, remoteport ); | 803 | socket_send4( serversocket, static_outbuf, r, remoteip, remoteport ); |
@@ -991,7 +973,7 @@ int main( int argc, char **argv ) { | |||
991 | signal( SIGINT, signal_handler ); | 973 | signal( SIGINT, signal_handler ); |
992 | signal( SIGALRM, signal_handler ); | 974 | signal( SIGALRM, signal_handler ); |
993 | 975 | ||
994 | if( init_logic( serverdir ) == -1 ) | 976 | if( trackerlogic_init( serverdir ) == -1 ) |
995 | panic( "Logic not started" ); | 977 | panic( "Logic not started" ); |
996 | 978 | ||
997 | g_now = ot_start_time = time( NULL ); | 979 | g_now = ot_start_time = time( NULL ); |