|
diff --git a/ot_http.c b/ot_http.c index a789f0d..e4486fc 100644 --- a/ ot_http.c+++ b/ ot_http.c |
| @@ -581,11 +581,11 @@ static ssize_t http_handle_announce(const int64 sock, struct ot_workstruct * |
| 581 | len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); |
581 | len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); |
| 582 | if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp)) |
582 | if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp)) |
| 583 | HTTPERROR_400_PARAM; |
583 | HTTPERROR_400_PARAM; |
| |
584 | if (tmp < 0) |
| |
585 | tmp = 50; |
| |
586 | if (tmp > 200) |
| |
587 | tmp = 200; |
| 584 | numwant = tmp; |
588 | numwant = tmp; |
| 585 | if (numwant < 0) |
| |
| 586 | numwant = 50; |
| |
| 587 | if (numwant > 200) |
| |
| 588 | numwant = 200; |
| |
| 589 | break; |
589 | break; |
| 590 | case 5: /* matched "compact" */ |
590 | case 5: /* matched "compact" */ |
| 591 | len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); |
591 | len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); |
|
|
|
| @@ -190,7 +190,7 @@ static size_t stats_get_highscore_networks(stats_network_node *node, int depth, |
| 190 | return score; |
190 | return score; |
| 191 | } |
191 | } |
| 192 | |
192 | |
| 193 | static size_t stats_return_busy_networks(char *reply, stats_network_node *tree, int amount, int limit) { |
193 | static size_t stats_return_busy_networks(char *reply, stats_network_node *tree, size_t amount, int limit) { |
| 194 | ot_ip6 networks[amount]; |
194 | ot_ip6 networks[amount]; |
| 195 | ot_ip6 node_value; |
195 | ot_ip6 node_value; |
| 196 | size_t scores[amount]; |
196 | size_t scores[amount]; |
| @@ -204,14 +204,14 @@ static size_t stats_return_busy_networks(char *reply, stats_network_node *tree, |
| 204 | stats_get_highscore_networks(tree, 0, node_value, scores, networks, amount, limit); |
204 | stats_get_highscore_networks(tree, 0, node_value, scores, networks, amount, limit); |
| 205 | |
205 | |
| 206 | r += sprintf(r, "Networks, limit /%d:\n", limit + STATS_NETWORK_NODE_BITWIDTH); |
206 | r += sprintf(r, "Networks, limit /%d:\n", limit + STATS_NETWORK_NODE_BITWIDTH); |
| 207 | for (i = amount - 1; i >= 0; --i) { |
207 | for (i = amount; i > 0; --i) { |
| 208 | if (scores[i]) { |
208 | if (scores[i - 1]) { |
| 209 | r += sprintf(r, "%08zd: ", scores[i]); |
209 | r += sprintf(r, "%08zd: ", scores[i - 1]); |
| 210 | // #ifdef WANT_V6 |
210 | // #ifdef WANT_V6 |
| 211 | r += fmt_ip6c(r, networks[i]); |
211 | r += fmt_ip6c(r, networks[i - 1]); |
| 212 | #if 0 |
212 | #if 0 |
| 213 | // XXX |
213 | // XXX |
| 214 | r += fmt_ip4( r, networks[i]); |
214 | r += fmt_ip4( r, networks[i - 1]); |
| 215 | #endif |
215 | #endif |
| 216 | *r++ = '\n'; |
216 | *r++ = '\n'; |
| 217 | } |
217 | } |
| @@ -315,6 +315,21 @@ typedef struct { |
| 315 | ot_hash hash; |
315 | ot_hash hash; |
| 316 | } ot_record; |
316 | } ot_record; |
| 317 | |
317 | |
| |
318 | static inline void stats_insert_into_highscore(size_t val, ot_record* list, size_t amount, ot_hash* hash) { |
| |
319 | size_t i; |
| |
320 | for (i = 0; (i < amount) && (list[i].val > val); ++i) |
| |
321 | {} |
| |
322 | /* if we score better than a record in the list, we need to make room in the high |
| |
323 | score array by moving lower scoring entries up */ |
| |
324 | if (i < amount) { |
| |
325 | memmove(list + i + 1, list + i, (amount - i - 1) * sizeof(ot_record)); |
| |
326 | |
| |
327 | memcpy(&list[i].hash, hash, sizeof(ot_hash)); |
| |
328 | list[i].val = val; |
| |
329 | } |
| |
330 | } |
| |
331 | |
| |
332 | |
| 318 | /* Fetches stats from tracker */ |
333 | /* Fetches stats from tracker */ |
| 319 | size_t stats_top_txt(char *reply, size_t amount) { |
334 | size_t stats_top_txt(char *reply, size_t amount) { |
| 320 | size_t j, idx, bucket; |
335 | size_t j, idx, bucket; |
| @@ -328,6 +343,7 @@ size_t stats_top_txt(char *reply, size_t amount) { |
| 328 | byte_zero(top100c, sizeof(top100c)); |
343 | byte_zero(top100c, sizeof(top100c)); |
| 329 | byte_zero(top100l, sizeof(top100l)); |
344 | byte_zero(top100l, sizeof(top100l)); |
| 330 | |
345 | |
| |
346 | /* Iterate over complete torrent list */ |
| 331 | for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { |
347 | for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { |
| 332 | ot_vector *torrents_list = mutex_bucket_lock(bucket); |
348 | ot_vector *torrents_list = mutex_bucket_lock(bucket); |
| 333 | for (j = 0; j < torrents_list->size; ++j) { |
349 | for (j = 0; j < torrents_list->size; ++j) { |
| @@ -335,30 +351,10 @@ size_t stats_top_txt(char *reply, size_t amount) { |
| 335 | size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; |
351 | size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; |
| 336 | size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; |
352 | size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; |
| 337 | size_t leech_count = peer_count - seed_count; |
353 | size_t leech_count = peer_count - seed_count; |
| 338 | idx = amount - 1; |
354 | |
| 339 | while ((idx >= 0) && (peer_count > top100c[idx].val)) |
355 | stats_insert_into_highscore(peer_count, top100c, amount, &torrent->hash); |
| 340 | --idx; |
356 | stats_insert_into_highscore(seed_count, top100s, amount, &torrent->hash); |
| 341 | if (idx++ != amount - 1) { |
357 | stats_insert_into_highscore(leech_count, top100l, amount, &torrent->hash); |
| 342 | memmove(top100c + idx + 1, top100c + idx, (amount - 1 - idx) * sizeof(ot_record)); |
| |
| 343 | memcpy(&top100c[idx].hash, &torrent->hash, sizeof(ot_hash)); |
| |
| 344 | top100c[idx].val = peer_count; |
| |
| 345 | } |
| |
| 346 | idx = amount - 1; |
| |
| 347 | while ((idx >= 0) && (seed_count > top100s[idx].val)) |
| |
| 348 | --idx; |
| |
| 349 | if (idx++ != amount - 1) { |
| |
| 350 | memmove(top100s + idx + 1, top100s + idx, (amount - 1 - idx) * sizeof(ot_record)); |
| |
| 351 | memcpy(&top100s[idx].hash, &torrent->hash, sizeof(ot_hash)); |
| |
| 352 | top100s[idx].val = seed_count; |
| |
| 353 | } |
| |
| 354 | idx = amount - 1; |
| |
| 355 | while ((idx >= 0) && (leech_count > top100l[idx].val)) |
| |
| 356 | --idx; |
| |
| 357 | if (idx++ != amount - 1) { |
| |
| 358 | memmove(top100l + idx + 1, top100l + idx, (amount - 1 - idx) * sizeof(ot_record)); |
| |
| 359 | memcpy(&top100l[idx].hash, &torrent->hash, sizeof(ot_hash)); |
| |
| 360 | top100l[idx].val = leech_count; |
| |
| 361 | } |
| |
| 362 | } |
358 | } |
| 363 | mutex_bucket_unlock(bucket, 0); |
359 | mutex_bucket_unlock(bucket, 0); |
| 364 | if (!g_opentracker_running) |
360 | if (!g_opentracker_running) |
|