diff options
Diffstat (limited to 'ot_stats.c')
| -rw-r--r-- | ot_stats.c | 32 |
1 files changed, 9 insertions, 23 deletions
| @@ -4,13 +4,11 @@ | |||
| 4 | $id$ */ | 4 | $id$ */ |
| 5 | 5 | ||
| 6 | /* System */ | 6 | /* System */ |
| 7 | #include <arpa/inet.h> | ||
| 8 | #include <inttypes.h> | 7 | #include <inttypes.h> |
| 9 | #include <pthread.h> | 8 | #include <pthread.h> |
| 10 | #include <stdio.h> | 9 | #include <stdio.h> |
| 11 | #include <stdlib.h> | 10 | #include <stdlib.h> |
| 12 | #include <string.h> | 11 | #include <string.h> |
| 13 | #include <sys/mman.h> | ||
| 14 | #include <sys/types.h> | 12 | #include <sys/types.h> |
| 15 | #include <sys/uio.h> | 13 | #include <sys/uio.h> |
| 16 | #include <unistd.h> | 14 | #include <unistd.h> |
| @@ -19,13 +17,13 @@ | |||
| 19 | #endif | 17 | #endif |
| 20 | 18 | ||
| 21 | /* Libowfat */ | 19 | /* Libowfat */ |
| 22 | #include "byte.h" | ||
| 23 | #include "io.h" | 20 | #include "io.h" |
| 24 | #include "ip4.h" | 21 | #include "ip4.h" |
| 25 | #include "ip6.h" | 22 | #include "ip6.h" |
| 26 | 23 | ||
| 27 | /* Opentracker */ | 24 | /* Opentracker */ |
| 28 | #include "ot_accesslist.h" | 25 | #include "ot_accesslist.h" |
| 26 | #include "ot_hex.h" | ||
| 29 | #include "ot_iovec.h" | 27 | #include "ot_iovec.h" |
| 30 | #include "ot_mutex.h" | 28 | #include "ot_mutex.h" |
| 31 | #include "ot_stats.h" | 29 | #include "ot_stats.h" |
| @@ -298,18 +296,6 @@ static int torrent_statter(ot_torrent *torrent, uintptr_t data) { | |||
| 298 | } | 296 | } |
| 299 | 297 | ||
| 300 | /* Converter function from memory to human readable hex strings */ | 298 | /* Converter function from memory to human readable hex strings */ |
| 301 | static char *to_hex(char *d, uint8_t *s) { | ||
| 302 | char *m = "0123456789ABCDEF"; | ||
| 303 | char *t = d; | ||
| 304 | char *e = d + 40; | ||
| 305 | while (d < e) { | ||
| 306 | *d++ = m[*s >> 4]; | ||
| 307 | *d++ = m[*s++ & 15]; | ||
| 308 | } | ||
| 309 | *d = 0; | ||
| 310 | return t; | ||
| 311 | } | ||
| 312 | |||
| 313 | typedef struct { | 299 | typedef struct { |
| 314 | size_t val; | 300 | size_t val; |
| 315 | ot_hash hash; | 301 | ot_hash hash; |
| @@ -339,9 +325,9 @@ size_t stats_top_txt(char *reply, size_t amount) { | |||
| 339 | if (amount > 100) | 325 | if (amount > 100) |
| 340 | amount = 100; | 326 | amount = 100; |
| 341 | 327 | ||
| 342 | byte_zero(top100s, sizeof(top100s)); | 328 | memset(top100s, 0, sizeof(top100s)); |
| 343 | byte_zero(top100c, sizeof(top100c)); | 329 | memset(top100c, 0, sizeof(top100c)); |
| 344 | byte_zero(top100l, sizeof(top100l)); | 330 | memset(top100l, 0, sizeof(top100l)); |
| 345 | 331 | ||
| 346 | /* Iterate over complete torrent list */ | 332 | /* Iterate over complete torrent list */ |
| 347 | for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { | 333 | for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { |
| @@ -364,15 +350,15 @@ size_t stats_top_txt(char *reply, size_t amount) { | |||
| 364 | r += sprintf(r, "Top %zd torrents by peers:\n", amount); | 350 | r += sprintf(r, "Top %zd torrents by peers:\n", amount); |
| 365 | for (idx = 0; idx < amount; ++idx) | 351 | for (idx = 0; idx < amount; ++idx) |
| 366 | if (top100c[idx].val) | 352 | if (top100c[idx].val) |
| 367 | r += sprintf(r, "\t%zd\t%s\n", top100c[idx].val, to_hex(hex_out, top100c[idx].hash)); | 353 | r += sprintf(r, "\t%zd\t%s\n", top100c[idx].val, hex_fromhash(hex_out, top100c[idx].hash)); |
| 368 | r += sprintf(r, "Top %zd torrents by seeds:\n", amount); | 354 | r += sprintf(r, "Top %zd torrents by seeds:\n", amount); |
| 369 | for (idx = 0; idx < amount; ++idx) | 355 | for (idx = 0; idx < amount; ++idx) |
| 370 | if (top100s[idx].val) | 356 | if (top100s[idx].val) |
| 371 | r += sprintf(r, "\t%zd\t%s\n", top100s[idx].val, to_hex(hex_out, top100s[idx].hash)); | 357 | r += sprintf(r, "\t%zd\t%s\n", top100s[idx].val, hex_fromhash(hex_out, top100s[idx].hash)); |
| 372 | r += sprintf(r, "Top %zd torrents by leechers:\n", amount); | 358 | r += sprintf(r, "Top %zd torrents by leechers:\n", amount); |
| 373 | for (idx = 0; idx < amount; ++idx) | 359 | for (idx = 0; idx < amount; ++idx) |
| 374 | if (top100l[idx].val) | 360 | if (top100l[idx].val) |
| 375 | r += sprintf(r, "\t%zd\t%s\n", top100l[idx].val, to_hex(hex_out, top100l[idx].hash)); | 361 | r += sprintf(r, "\t%zd\t%s\n", top100l[idx].val, hex_fromhash(hex_out, top100l[idx].hash)); |
| 376 | 362 | ||
| 377 | return r - reply; | 363 | return r - reply; |
| 378 | } | 364 | } |
| @@ -670,9 +656,9 @@ void stats_issue_event(ot_status_event event, PROTO_FLAG proto, uintptr_t event_ | |||
| 670 | localtime_r(&ttt, &time_now); | 656 | localtime_r(&ttt, &time_now); |
| 671 | strftime(timestring, sizeof(timestring), "%FT%T%z", &time_now); | 657 | strftime(timestring, sizeof(timestring), "%FT%T%z", &time_now); |
| 672 | 658 | ||
| 673 | to_hex(hash_hex, *ws->hash); | 659 | hex_fromhash(hash_hex, *ws->hash); |
| 674 | if (ws->peer_id) | 660 | if (ws->peer_id) |
| 675 | to_hex(peerid_hex, (uint8_t *)ws->peer_id); | 661 | hex_fromhash(peerid_hex, (uint8_t *)ws->peer_id); |
| 676 | else { | 662 | else { |
| 677 | *peerid_hex = 0; | 663 | *peerid_hex = 0; |
| 678 | } | 664 | } |
