|
|
@ -320,7 +320,7 @@ typedef struct {
|
|
|
|
/* Fetches stats from tracker */
|
|
|
|
/* Fetches stats from tracker */
|
|
|
|
size_t stats_top_txt(char *reply, int amount) {
|
|
|
|
size_t stats_top_txt(char *reply, int amount) {
|
|
|
|
size_t j;
|
|
|
|
size_t j;
|
|
|
|
ot_record top100s[100], top100c[100];
|
|
|
|
ot_record top100s[100], top100c[100], top100l[100];
|
|
|
|
char *r = reply, hex_out[42];
|
|
|
|
char *r = reply, hex_out[42];
|
|
|
|
int idx, bucket;
|
|
|
|
int idx, bucket;
|
|
|
|
|
|
|
|
|
|
|
@ -331,12 +331,13 @@ size_t stats_top_txt(char *reply, int amount) {
|
|
|
|
byte_zero(top100c, sizeof(top100c));
|
|
|
|
byte_zero(top100c, sizeof(top100c));
|
|
|
|
|
|
|
|
|
|
|
|
for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) {
|
|
|
|
for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) {
|
|
|
|
ot_vector *torrents_list = mutex_bucket_lock(bucket);
|
|
|
|
ot_vector *torrents_list = mutex_bucket_lock(bucket);
|
|
|
|
for (j = 0; j < torrents_list->size; ++j) {
|
|
|
|
for (j = 0; j < torrents_list->size; ++j) {
|
|
|
|
ot_torrent *torrent = (ot_torrent *)(torrents_list->data) + j;
|
|
|
|
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 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 seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count;
|
|
|
|
idx = amount - 1;
|
|
|
|
size_t leech_count = peer_count - seed_count;
|
|
|
|
|
|
|
|
idx = amount - 1;
|
|
|
|
while ((idx >= 0) && (peer_count > top100c[idx].val))
|
|
|
|
while ((idx >= 0) && (peer_count > top100c[idx].val))
|
|
|
|
--idx;
|
|
|
|
--idx;
|
|
|
|
if (idx++ != amount - 1) {
|
|
|
|
if (idx++ != amount - 1) {
|
|
|
@ -352,6 +353,14 @@ size_t stats_top_txt(char *reply, int amount) {
|
|
|
|
memcpy(&top100s[idx].hash, &torrent->hash, sizeof(ot_hash));
|
|
|
|
memcpy(&top100s[idx].hash, &torrent->hash, sizeof(ot_hash));
|
|
|
|
top100s[idx].val = seed_count;
|
|
|
|
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);
|
|
|
|
mutex_bucket_unlock(bucket, 0);
|
|
|
|
if (!g_opentracker_running)
|
|
|
|
if (!g_opentracker_running)
|
|
|
@ -366,6 +375,10 @@ size_t stats_top_txt(char *reply, int amount) {
|
|
|
|
for (idx = 0; idx < amount; ++idx)
|
|
|
|
for (idx = 0; idx < amount; ++idx)
|
|
|
|
if (top100s[idx].val)
|
|
|
|
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, "\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;
|
|
|
|
return r - reply;
|
|
|
|
}
|
|
|
|
}
|
|
|
|