summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2009-09-02 02:18:36 +0000
committererdgeist <>2009-09-02 02:18:36 +0000
commit0bf88427c6c33f0aabc4e8374ed77542c4f18d2a (patch)
tree3290e11f0a5f95c3ffdb4d2d1d04bf0c05a7e366
parentc76814cfecbf2fabcc316e7f14f52766a8f59a45 (diff)
Add spotting woodpeckers, thanks to Vasya P. again
-rw-r--r--ot_http.c1
-rw-r--r--ot_mutex.h3
-rw-r--r--ot_stats.c55
-rw-r--r--ot_stats.h3
-rw-r--r--trackerlogic.c5
5 files changed, 40 insertions, 27 deletions
diff --git a/ot_http.c b/ot_http.c
index 6d29e9c..fa2ba76 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -172,6 +172,7 @@ static const ot_keywords keywords_mode[] =
172 { "s24s", TASK_STATS_SLASH24S }, { "tpbs", TASK_STATS_TPB }, { "herr", TASK_STATS_HTTPERRORS }, { "completed", TASK_STATS_COMPLETED }, 172 { "s24s", TASK_STATS_SLASH24S }, { "tpbs", TASK_STATS_TPB }, { "herr", TASK_STATS_HTTPERRORS }, { "completed", TASK_STATS_COMPLETED },
173 { "top10", TASK_STATS_TOP10 }, { "renew", TASK_STATS_RENEW }, { "syncs", TASK_STATS_SYNCS }, { "version", TASK_STATS_VERSION }, 173 { "top10", TASK_STATS_TOP10 }, { "renew", TASK_STATS_RENEW }, { "syncs", TASK_STATS_SYNCS }, { "version", TASK_STATS_VERSION },
174 { "everything", TASK_STATS_EVERYTHING }, { "statedump", TASK_FULLSCRAPE_TRACKERSTATE }, { "fulllog", TASK_STATS_FULLLOG }, 174 { "everything", TASK_STATS_EVERYTHING }, { "statedump", TASK_FULLSCRAPE_TRACKERSTATE }, { "fulllog", TASK_STATS_FULLLOG },
175 { "woodpeckers", TASK_STATS_WOODPECKERS},
175#ifdef WANT_LOG_NUMWANT 176#ifdef WANT_LOG_NUMWANT
176 { "numwants", TASK_STATS_NUMWANTS}, 177 { "numwants", TASK_STATS_NUMWANTS},
177#endif 178#endif
diff --git a/ot_mutex.h b/ot_mutex.h
index c88eed5..4df5244 100644
--- a/ot_mutex.h
+++ b/ot_mutex.h
@@ -41,7 +41,8 @@ typedef enum {
41 TASK_STATS_TOP10 = 0x0104, 41 TASK_STATS_TOP10 = 0x0104,
42 TASK_STATS_EVERYTHING = 0x0105, 42 TASK_STATS_EVERYTHING = 0x0105,
43 TASK_STATS_FULLLOG = 0x0106, 43 TASK_STATS_FULLLOG = 0x0106,
44 44 TASK_STATS_WOODPECKERS = 0x0107,
45
45 TASK_FULLSCRAPE = 0x0200, /* Default mode */ 46 TASK_FULLSCRAPE = 0x0200, /* Default mode */
46 TASK_FULLSCRAPE_TPB_BINARY = 0x0201, 47 TASK_FULLSCRAPE_TPB_BINARY = 0x0201,
47 TASK_FULLSCRAPE_TPB_ASCII = 0x0202, 48 TASK_FULLSCRAPE_TPB_ASCII = 0x0202,
diff --git a/ot_stats.c b/ot_stats.c
index 8e6a0c9..a7c01c6 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -181,7 +181,7 @@ static size_t stats_get_highscore_networks( stats_network_node *node, int depth,
181 return score; 181 return score;
182} 182}
183 183
184static size_t stats_return_busy_networks( char * reply, stats_network_node *tree, int amount ) { 184static size_t stats_return_busy_networks( char * reply, stats_network_node *tree, int amount, int limit ) {
185 ot_ip6 networks[amount]; 185 ot_ip6 networks[amount];
186 ot_ip6 node_value; 186 ot_ip6 node_value;
187 size_t scores[amount]; 187 size_t scores[amount];
@@ -192,9 +192,9 @@ static size_t stats_return_busy_networks( char * reply, stats_network_node *tree
192 memset( networks, 0, sizeof( networks ) ); 192 memset( networks, 0, sizeof( networks ) );
193 memset( node_value, 0, sizeof( node_value ) ); 193 memset( node_value, 0, sizeof( node_value ) );
194 194
195 stats_get_highscore_networks( tree, 0, node_value, scores, networks, amount, STATS_NETWORK_NODE_MAXDEPTH ); 195 stats_get_highscore_networks( tree, 0, node_value, scores, networks, amount, limit );
196 196
197 r += sprintf( r, "Networks, limit /%d:\n", STATS_NETWORK_NODE_MAXDEPTH+STATS_NETWORK_NODE_BITWIDTH ); 197 r += sprintf( r, "Networks, limit /%d:\n", limit+STATS_NETWORK_NODE_BITWIDTH );
198 for( i=amount-1; i>=0; --i) { 198 for( i=amount-1; i>=0; --i) {
199 if( scores[i] ) { 199 if( scores[i] ) {
200 r += sprintf( r, "%08zd: ", scores[i] ); 200 r += sprintf( r, "%08zd: ", scores[i] );
@@ -206,25 +206,7 @@ static size_t stats_return_busy_networks( char * reply, stats_network_node *tree
206 *r++ = '\n'; 206 *r++ = '\n';
207 } 207 }
208 } 208 }
209 209 *r++ = '\n';
210 memset( scores, 0, sizeof( scores ) );
211 memset( networks, 0, sizeof( networks ) );
212 memset( node_value, 0, sizeof( node_value ) );
213
214 stats_get_highscore_networks( tree, 0, node_value, scores, networks, amount, STATS_NETWORK_NODE_LIMIT );
215
216 r += sprintf( r, "\nNetworks, limit /%d:\n", STATS_NETWORK_NODE_LIMIT+STATS_NETWORK_NODE_BITWIDTH );
217 for( i=amount-1; i>=0; --i) {
218 if( scores[i] ) {
219 r += sprintf( r, "%08zd: ", scores[i] );
220#ifdef WANT_V6
221 r += fmt_ip6c( r, networks[i] );
222#else
223 r += fmt_ip4( r, networks[i] );
224#endif
225 *r++ = '\n';
226 }
227 }
228 210
229 return r - reply; 211 return r - reply;
230} 212}
@@ -262,7 +244,8 @@ static size_t stats_slash24s_txt( char *reply, size_t amount ) {
262 } 244 }
263 245
264 /* The tree is built. Now analyze */ 246 /* The tree is built. Now analyze */
265 r += stats_return_busy_networks( r, slash24s_network_counters_root, amount ); 247 r += stats_return_busy_networks( r, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_MAXDEPTH );
248 r += stats_return_busy_networks( r, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_LIMIT );
266 goto success; 249 goto success;
267 250
268bailout_unlock: 251bailout_unlock:
@@ -275,11 +258,25 @@ success:
275 return r-reply; 258 return r-reply;
276} 259}
277 260
261#ifdef WANT_SPOT_WOODPECKER
262static stats_network_node *stats_woodpeckers_tree;
263static pthread_mutex_t g_woodpeckers_mutex = PTHREAD_MUTEX_INITIALIZER;
264
265static size_t stats_return_woodpeckers( char * reply, int amount ) {
266 char * r = reply;
267
268 pthread_mutex_lock( &g_woodpeckers_mutex );
269 r += stats_return_busy_networks( r, stats_woodpeckers_tree, amount, STATS_NETWORK_NODE_MAXDEPTH );
270 pthread_mutex_unlock( &g_woodpeckers_mutex );
271 return r-reply;
272}
273
278typedef struct { 274typedef struct {
279 unsigned long long torrent_count; 275 unsigned long long torrent_count;
280 unsigned long long peer_count; 276 unsigned long long peer_count;
281 unsigned long long seed_count; 277 unsigned long long seed_count;
282} torrent_stats; 278} torrent_stats;
279#endif
283 280
284static int torrent_statter( ot_torrent *torrent, uintptr_t data ) { 281static int torrent_statter( ot_torrent *torrent, uintptr_t data ) {
285 torrent_stats *stats = (torrent_stats*)data; 282 torrent_stats *stats = (torrent_stats*)data;
@@ -611,6 +608,9 @@ static void stats_make( int *iovec_entries, struct iovec **iovector, ot_tasktype
611 case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 128 ); break; 608 case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 128 ); break;
612 case TASK_STATS_TOP10: r += stats_top10_txt( r ); break; 609 case TASK_STATS_TOP10: r += stats_top10_txt( r ); break;
613 case TASK_STATS_EVERYTHING: r += stats_return_everything( r ); break; 610 case TASK_STATS_EVERYTHING: r += stats_return_everything( r ); break;
611#ifdef WANT_SPOT_WOODPECKER
612 case TASK_STATS_WOODPECKERS: r += stats_return_woodpeckers( r, 128 ); break;
613#endif
614#ifdef WANT_FULLLOG_NETWORKS 614#ifdef WANT_FULLLOG_NETWORKS
615 case TASK_STATS_FULLLOG: stats_return_fulllog( iovec_entries, iovector, r ); 615 case TASK_STATS_FULLLOG: stats_return_fulllog( iovec_entries, iovector, r );
616 return; 616 return;
@@ -670,7 +670,7 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
670 case EVENT_FAILED: 670 case EVENT_FAILED:
671 ot_failed_request_counts[event_data]++; 671 ot_failed_request_counts[event_data]++;
672 break; 672 break;
673 case EVENT_RENEW: 673 case EVENT_RENEW:
674 ot_renewed[event_data]++; 674 ot_renewed[event_data]++;
675 break; 675 break;
676 case EVENT_SYNC: 676 case EVENT_SYNC:
@@ -679,6 +679,13 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
679 case EVENT_BUCKET_LOCKED: 679 case EVENT_BUCKET_LOCKED:
680 ot_overall_stall_count++; 680 ot_overall_stall_count++;
681 break; 681 break;
682#ifdef WANT_SPOT_WOODPECKER
683 case EVENT_WOODPECKER:
684 pthread_mutex_lock( &g_woodpeckers_mutex );
685 stat_increase_network_count( &stats_woodpeckers_tree, 0, event_data );
686 pthread_mutex_unlock( &g_woodpeckers_mutex );
687 break;
688#endif
682 default: 689 default:
683 break; 690 break;
684 } 691 }
diff --git a/ot_stats.h b/ot_stats.h
index ca6b57b..ffb5ad7 100644
--- a/ot_stats.h
+++ b/ot_stats.h
@@ -19,7 +19,8 @@ typedef enum {
19 EVENT_FULLSCRAPE_REQUEST_GZIP, 19 EVENT_FULLSCRAPE_REQUEST_GZIP,
20 EVENT_FULLSCRAPE, /* TCP only */ 20 EVENT_FULLSCRAPE, /* TCP only */
21 EVENT_FAILED, 21 EVENT_FAILED,
22 EVENT_BUCKET_LOCKED 22 EVENT_BUCKET_LOCKED,
23 EVENT_WOODPECKER
23} ot_status_event; 24} ot_status_event;
24 25
25enum { 26enum {
diff --git a/trackerlogic.c b/trackerlogic.c
index 18895ba..6ca1ad2 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -145,7 +145,10 @@ size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_
145 145
146 } else { 146 } else {
147 stats_issue_event( EVENT_RENEW, 0, OT_PEERTIME( peer_dest ) ); 147 stats_issue_event( EVENT_RENEW, 0, OT_PEERTIME( peer_dest ) );
148 148#ifdef WANT_SPOT_WOODPECKER
149 if( ( OT_PEERTIME(peer_dest) > 0 ) && ( OT_PEERTIME(peer_dest) < 20 ) )
150 stats_issue_event( EVENT_WOODPECKER, 0, (uintptr_t)peer );
151#endif
149#ifdef WANT_SYNC_LIVE 152#ifdef WANT_SYNC_LIVE
150 /* Won't live sync peers that come back too fast. Only exception: 153 /* Won't live sync peers that come back too fast. Only exception:
151 fresh "completed" reports */ 154 fresh "completed" reports */