From 18a746b89dadf4c5f8ed8b4feec71bcc4d4f3980 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 7 Apr 2024 21:29:36 +0200 Subject: report full peer and seed count for both address families --- ot_mutex.c | 2 +- trackerlogic.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ot_mutex.c b/ot_mutex.c index 6457f29..497b1af 100644 --- a/ot_mutex.c +++ b/ot_mutex.c @@ -26,7 +26,7 @@ /* Our global all torrents list */ static ot_vector all_torrents[OT_BUCKET_COUNT]; static pthread_mutex_t bucket_mutex[OT_BUCKET_COUNT]; -static size_t g_torrent_count; +static size_t g_torrent_count; /* Self pipe from opentracker.c */ extern int g_self_pipe[2]; diff --git a/trackerlogic.c b/trackerlogic.c index 11113d2..075c0d9 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -278,13 +278,15 @@ static size_t return_peers_for_torrent_udp( struct ot_workstruct * ws, ot_torren char *r = reply; size_t peer_size = peer_size_from_peer6(&ws->peer); ot_peerlist *peer_list = peer_size == OT_PEER_SIZE6 ? torrent->peer_list6 : torrent->peer_list4; + 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; if( amount > peer_list->peer_count ) amount = peer_list->peer_count; *(uint32_t*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); - *(uint32_t*)(r+4) = htonl( peer_list->peer_count - peer_list->seed_count ); - *(uint32_t*)(r+8) = htonl( peer_list->seed_count ); + *(uint32_t*)(r+4) = htonl( peer_count - seed_count ); + *(uint32_t*)(r+8) = htonl( seed_count ); r += 12; if( amount ) { @@ -442,6 +444,7 @@ size_t remove_peer_from_torrent( PROTO_FLAG proto, struct ot_workstruct *ws ) { ot_peerlist *peer_list = &dummy_list; size_t peer_size; /* initialized in next line */ ot_peer const *peer_src = peer_from_peer6(&ws->peer, &peer_size); + size_t peer_count, seed_count; #ifdef WANT_SYNC_LIVE if( proto != FLAG_MCA ) { @@ -459,16 +462,19 @@ size_t remove_peer_from_torrent( PROTO_FLAG proto, struct ot_workstruct *ws ) { } } + peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; + seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; + if( proto == FLAG_TCP ) { int erval = OT_CLIENT_REQUEST_INTERVAL_RANDOM; - ws->reply_size = sprintf( ws->reply, "d8:completei%zde10:incompletei%zde8:intervali%ie12:min intervali%ie%s0:e", peer_list->seed_count, peer_list->peer_count - peer_list->seed_count, erval, erval / 2, peer_size == OT_PEER_SIZE6 ? PEERS_BENCODED6 : PEERS_BENCODED4 ); + ws->reply_size = sprintf( ws->reply, "d8:completei%zde10:incompletei%zde8:intervali%ie12:min intervali%ie%s0:e", seed_count, peer_count - seed_count, erval, erval / 2, peer_size == OT_PEER_SIZE6 ? PEERS_BENCODED6 : PEERS_BENCODED4 ); } /* Handle UDP reply */ if( proto == FLAG_UDP ) { ((uint32_t*)ws->reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); - ((uint32_t*)ws->reply)[3] = htonl( peer_list->peer_count - peer_list->seed_count ); - ((uint32_t*)ws->reply)[4] = htonl( peer_list->seed_count); + ((uint32_t*)ws->reply)[3] = htonl( peer_count - seed_count ); + ((uint32_t*)ws->reply)[4] = htonl( seed_count); ws->reply_size = 20; } -- cgit v1.2.3