|
|
|
@ -320,7 +320,7 @@ typedef struct {
|
|
|
|
|
/* Fetches stats from tracker */
|
|
|
|
|
size_t stats_top_txt(char *reply, int amount) {
|
|
|
|
|
size_t j;
|
|
|
|
|
ot_record top100s[100], top100c[100];
|
|
|
|
|
ot_record top100s[100], top100c[100], top100l[100];
|
|
|
|
|
char *r = reply, hex_out[42];
|
|
|
|
|
int idx, bucket;
|
|
|
|
|
|
|
|
|
@ -336,6 +336,7 @@ size_t stats_top_txt(char *reply, int amount) {
|
|
|
|
|
ot_torrent *torrent = (ot_torrent *)(torrents_list->data) + j;
|
|
|
|
|
size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count;
|
|
|
|
|
size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count;
|
|
|
|
|
size_t leech_count = peer_count - seed_count;
|
|
|
|
|
idx = amount - 1;
|
|
|
|
|
while ((idx >= 0) && (peer_count > top100c[idx].val))
|
|
|
|
|
--idx;
|
|
|
|
@ -352,6 +353,14 @@ size_t stats_top_txt(char *reply, int amount) {
|
|
|
|
|
memcpy(&top100s[idx].hash, &torrent->hash, sizeof(ot_hash));
|
|
|
|
|
top100s[idx].val = seed_count;
|
|
|
|
|
}
|
|
|
|
|
idx = amount - 1;
|
|
|
|
|
while ((idx >= 0) && (leech_count > top100l[idx].val))
|
|
|
|
|
--idx;
|
|
|
|
|
if (idx++ != amount - 1) {
|
|
|
|
|
memmove(top100l + idx + 1, top100l + idx, (amount - 1 - idx) * sizeof(ot_record));
|
|
|
|
|
memcpy(&top100l[idx].hash, &torrent->hash, sizeof(ot_hash));
|
|
|
|
|
top100l[idx].val = leech_count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mutex_bucket_unlock(bucket, 0);
|
|
|
|
|
if (!g_opentracker_running)
|
|
|
|
@ -366,6 +375,10 @@ size_t stats_top_txt(char *reply, int amount) {
|
|
|
|
|
for (idx = 0; idx < amount; ++idx)
|
|
|
|
|
if (top100s[idx].val)
|
|
|
|
|
r += sprintf(r, "\t%zd\t%s\n", top100s[idx].val, to_hex(hex_out, top100s[idx].hash));
|
|
|
|
|
r += sprintf(r, "Top %d torrents by leechers:\n", amount);
|
|
|
|
|
for (idx = 0; idx < amount; ++idx)
|
|
|
|
|
if (top100l[idx].val)
|
|
|
|
|
r += sprintf(r, "\t%zd\t%s\n", top100l[idx].val, to_hex(hex_out, top100l[idx].hash));
|
|
|
|
|
|
|
|
|
|
return r - reply;
|
|
|
|
|
}
|
|
|
|
|