diff options
Diffstat (limited to 'ot_stats.c')
| -rw-r--r-- | ot_stats.c | 23 |
1 files changed, 6 insertions, 17 deletions
| @@ -23,6 +23,7 @@ | |||
| 23 | 23 | ||
| 24 | /* Opentracker */ | 24 | /* Opentracker */ |
| 25 | #include "ot_accesslist.h" | 25 | #include "ot_accesslist.h" |
| 26 | #include "ot_hex.h" | ||
| 26 | #include "ot_iovec.h" | 27 | #include "ot_iovec.h" |
| 27 | #include "ot_mutex.h" | 28 | #include "ot_mutex.h" |
| 28 | #include "ot_stats.h" | 29 | #include "ot_stats.h" |
| @@ -295,18 +296,6 @@ static int torrent_statter(ot_torrent *torrent, uintptr_t data) { | |||
| 295 | } | 296 | } |
| 296 | 297 | ||
| 297 | /* Converter function from memory to human readable hex strings */ | 298 | /* Converter function from memory to human readable hex strings */ |
| 298 | static char *to_hex(char *d, uint8_t *s) { | ||
| 299 | char *m = "0123456789ABCDEF"; | ||
| 300 | char *t = d; | ||
| 301 | char *e = d + 40; | ||
| 302 | while (d < e) { | ||
| 303 | *d++ = m[*s >> 4]; | ||
| 304 | *d++ = m[*s++ & 15]; | ||
| 305 | } | ||
| 306 | *d = 0; | ||
| 307 | return t; | ||
| 308 | } | ||
| 309 | |||
| 310 | typedef struct { | 299 | typedef struct { |
| 311 | size_t val; | 300 | size_t val; |
| 312 | ot_hash hash; | 301 | ot_hash hash; |
| @@ -361,15 +350,15 @@ size_t stats_top_txt(char *reply, size_t amount) { | |||
| 361 | r += sprintf(r, "Top %zd torrents by peers:\n", amount); | 350 | r += sprintf(r, "Top %zd torrents by peers:\n", amount); |
| 362 | for (idx = 0; idx < amount; ++idx) | 351 | for (idx = 0; idx < amount; ++idx) |
| 363 | if (top100c[idx].val) | 352 | if (top100c[idx].val) |
| 364 | 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)); |
| 365 | r += sprintf(r, "Top %zd torrents by seeds:\n", amount); | 354 | r += sprintf(r, "Top %zd torrents by seeds:\n", amount); |
| 366 | for (idx = 0; idx < amount; ++idx) | 355 | for (idx = 0; idx < amount; ++idx) |
| 367 | if (top100s[idx].val) | 356 | if (top100s[idx].val) |
| 368 | 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)); |
| 369 | r += sprintf(r, "Top %zd torrents by leechers:\n", amount); | 358 | r += sprintf(r, "Top %zd torrents by leechers:\n", amount); |
| 370 | for (idx = 0; idx < amount; ++idx) | 359 | for (idx = 0; idx < amount; ++idx) |
| 371 | if (top100l[idx].val) | 360 | if (top100l[idx].val) |
| 372 | 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)); |
| 373 | 362 | ||
| 374 | return r - reply; | 363 | return r - reply; |
| 375 | } | 364 | } |
| @@ -667,9 +656,9 @@ void stats_issue_event(ot_status_event event, PROTO_FLAG proto, uintptr_t event_ | |||
| 667 | localtime_r(&ttt, &time_now); | 656 | localtime_r(&ttt, &time_now); |
| 668 | strftime(timestring, sizeof(timestring), "%FT%T%z", &time_now); | 657 | strftime(timestring, sizeof(timestring), "%FT%T%z", &time_now); |
| 669 | 658 | ||
| 670 | to_hex(hash_hex, *ws->hash); | 659 | hex_fromhash(hash_hex, *ws->hash); |
| 671 | if (ws->peer_id) | 660 | if (ws->peer_id) |
| 672 | to_hex(peerid_hex, (uint8_t *)ws->peer_id); | 661 | hex_fromhash(peerid_hex, (uint8_t *)ws->peer_id); |
| 673 | else { | 662 | else { |
| 674 | *peerid_hex = 0; | 663 | *peerid_hex = 0; |
| 675 | } | 664 | } |
