Browse Source

Add spotting woodpeckers, thanks to Vasya P. again

erdgeist 12 years ago
parent
commit
0bf88427c6
  1. 1
      ot_http.c
  2. 3
      ot_mutex.h
  3. 55
      ot_stats.c
  4. 3
      ot_stats.h
  5. 5
      trackerlogic.c

1
ot_http.c

@ -172,6 +172,7 @@ static const ot_keywords keywords_mode[] =
{ "s24s", TASK_STATS_SLASH24S }, { "tpbs", TASK_STATS_TPB }, { "herr", TASK_STATS_HTTPERRORS }, { "completed", TASK_STATS_COMPLETED },
{ "top10", TASK_STATS_TOP10 }, { "renew", TASK_STATS_RENEW }, { "syncs", TASK_STATS_SYNCS }, { "version", TASK_STATS_VERSION },
{ "everything", TASK_STATS_EVERYTHING }, { "statedump", TASK_FULLSCRAPE_TRACKERSTATE }, { "fulllog", TASK_STATS_FULLLOG },
{ "woodpeckers", TASK_STATS_WOODPECKERS},
#ifdef WANT_LOG_NUMWANT
{ "numwants", TASK_STATS_NUMWANTS},
#endif

3
ot_mutex.h

@ -41,7 +41,8 @@ typedef enum {
TASK_STATS_TOP10 = 0x0104,
TASK_STATS_EVERYTHING = 0x0105,
TASK_STATS_FULLLOG = 0x0106,
TASK_STATS_WOODPECKERS = 0x0107,
TASK_FULLSCRAPE = 0x0200, /* Default mode */
TASK_FULLSCRAPE_TPB_BINARY = 0x0201,
TASK_FULLSCRAPE_TPB_ASCII = 0x0202,

55
ot_stats.c

@ -181,7 +181,7 @@ static size_t stats_get_highscore_networks( stats_network_node *node, int depth,
return score;
}
static size_t stats_return_busy_networks( char * reply, stats_network_node *tree, int amount ) {
static size_t stats_return_busy_networks( char * reply, stats_network_node *tree, int amount, int limit ) {
ot_ip6 networks[amount];
ot_ip6 node_value;
size_t scores[amount];
@ -192,9 +192,9 @@ static size_t stats_return_busy_networks( char * reply, stats_network_node *tree
memset( networks, 0, sizeof( networks ) );
memset( node_value, 0, sizeof( node_value ) );
stats_get_highscore_networks( tree, 0, node_value, scores, networks, amount, STATS_NETWORK_NODE_MAXDEPTH );
stats_get_highscore_networks( tree, 0, node_value, scores, networks, amount, limit );
r += sprintf( r, "Networks, limit /%d:\n", STATS_NETWORK_NODE_MAXDEPTH+STATS_NETWORK_NODE_BITWIDTH );
r += sprintf( r, "Networks, limit /%d:\n", limit+STATS_NETWORK_NODE_BITWIDTH );
for( i=amount-1; i>=0; --i) {
if( scores[i] ) {
r += sprintf( r, "%08zd: ", scores[i] );
@ -206,25 +206,7 @@ static size_t stats_return_busy_networks( char * reply, stats_network_node *tree
*r++ = '\n';
}
}
memset( scores, 0, sizeof( scores ) );
memset( networks, 0, sizeof( networks ) );
memset( node_value, 0, sizeof( node_value ) );
stats_get_highscore_networks( tree, 0, node_value, scores, networks, amount, STATS_NETWORK_NODE_LIMIT );
r += sprintf( r, "\nNetworks, limit /%d:\n", STATS_NETWORK_NODE_LIMIT+STATS_NETWORK_NODE_BITWIDTH );
for( i=amount-1; i>=0; --i) {
if( scores[i] ) {
r += sprintf( r, "%08zd: ", scores[i] );
#ifdef WANT_V6
r += fmt_ip6c( r, networks[i] );
#else
r += fmt_ip4( r, networks[i] );
#endif
*r++ = '\n';
}
}
*r++ = '\n';
return r - reply;
}
@ -262,7 +244,8 @@ static size_t stats_slash24s_txt( char *reply, size_t amount ) {
}
/* The tree is built. Now analyze */
r += stats_return_busy_networks( r, slash24s_network_counters_root, amount );
r += stats_return_busy_networks( r, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_MAXDEPTH );
r += stats_return_busy_networks( r, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_LIMIT );
goto success;
bailout_unlock:
@ -275,11 +258,25 @@ success:
return r-reply;
}
#ifdef WANT_SPOT_WOODPECKER
static stats_network_node *stats_woodpeckers_tree;
static pthread_mutex_t g_woodpeckers_mutex = PTHREAD_MUTEX_INITIALIZER;
static size_t stats_return_woodpeckers( char * reply, int amount ) {
char * r = reply;
pthread_mutex_lock( &g_woodpeckers_mutex );
r += stats_return_busy_networks( r, stats_woodpeckers_tree, amount, STATS_NETWORK_NODE_MAXDEPTH );
pthread_mutex_unlock( &g_woodpeckers_mutex );
return r-reply;
}
typedef struct {
unsigned long long torrent_count;
unsigned long long peer_count;
unsigned long long seed_count;
} torrent_stats;
#endif
static int torrent_statter( ot_torrent *torrent, uintptr_t data ) {
torrent_stats *stats = (torrent_stats*)data;
@ -611,6 +608,9 @@ static void stats_make( int *iovec_entries, struct iovec **iovector, ot_tasktype
case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 128 ); break;
case TASK_STATS_TOP10: r += stats_top10_txt( r ); break;
case TASK_STATS_EVERYTHING: r += stats_return_everything( r ); break;
#ifdef WANT_SPOT_WOODPECKER
case TASK_STATS_WOODPECKERS: r += stats_return_woodpeckers( r, 128 ); break;
#endif
#ifdef WANT_FULLLOG_NETWORKS
case TASK_STATS_FULLLOG: stats_return_fulllog( iovec_entries, iovector, r );
return;
@ -670,7 +670,7 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
case EVENT_FAILED:
ot_failed_request_counts[event_data]++;
break;
case EVENT_RENEW:
case EVENT_RENEW:
ot_renewed[event_data]++;
break;
case EVENT_SYNC:
@ -679,6 +679,13 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
case EVENT_BUCKET_LOCKED:
ot_overall_stall_count++;
break;
#ifdef WANT_SPOT_WOODPECKER
case EVENT_WOODPECKER:
pthread_mutex_lock( &g_woodpeckers_mutex );
stat_increase_network_count( &stats_woodpeckers_tree, 0, event_data );
pthread_mutex_unlock( &g_woodpeckers_mutex );
break;
#endif
default:
break;
}

3
ot_stats.h

@ -19,7 +19,8 @@ typedef enum {
EVENT_FULLSCRAPE_REQUEST_GZIP,
EVENT_FULLSCRAPE, /* TCP only */
EVENT_FAILED,
EVENT_BUCKET_LOCKED
EVENT_BUCKET_LOCKED,
EVENT_WOODPECKER
} ot_status_event;
enum {

5
trackerlogic.c

@ -145,7 +145,10 @@ size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_
} else {
stats_issue_event( EVENT_RENEW, 0, OT_PEERTIME( peer_dest ) );
#ifdef WANT_SPOT_WOODPECKER
if( ( OT_PEERTIME(peer_dest) > 0 ) && ( OT_PEERTIME(peer_dest) < 20 ) )
stats_issue_event( EVENT_WOODPECKER, 0, (uintptr_t)peer );
#endif
#ifdef WANT_SYNC_LIVE
/* Won't live sync peers that come back too fast. Only exception:
fresh "completed" reports */

Loading…
Cancel
Save