From 2afc4893bf802700a1decfff57673cefc861c7e7 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Wed, 3 Apr 2024 22:25:30 +0200 Subject: Prepare opentracker for dual stack capabilities --- ot_fullscrape.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'ot_fullscrape.c') diff --git a/ot_fullscrape.c b/ot_fullscrape.c index 5d115dc..d7d3518 100644 --- a/ot_fullscrape.c +++ b/ot_fullscrape.c @@ -82,7 +82,11 @@ void fullscrape_deliver( int64 sock, ot_tasktype tasktype ) { mutex_workqueue_pushtask( sock, tasktype ); } -static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_peerlist *peer_list, ot_hash *hash ) { +static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_torrent *torrent, ot_hash *hash ) { + size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; + size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; + size_t down_count = torrent->peer_list6->down_count + torrent->peer_list4->down_count; + switch( mode & TASK_TASK_MASK ) { case TASK_FULLSCRAPE: default: @@ -90,30 +94,30 @@ static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_peerlist *peer *r++='2'; *r++='0'; *r++=':'; memcpy( r, hash, sizeof(ot_hash) ); r += sizeof(ot_hash); /* push rest of the scrape string */ - r += sprintf( r, "d8:completei%zde10:downloadedi%zde10:incompletei%zdee", peer_list->seed_count, peer_list->down_count, peer_list->peer_count-peer_list->seed_count ); + r += sprintf( r, "d8:completei%zde10:downloadedi%zde10:incompletei%zdee", seed_count, down_count, peer_count-seed_count ); break; case TASK_FULLSCRAPE_TPB_ASCII: to_hex( r, *hash ); r+= 2 * sizeof(ot_hash); - r += sprintf( r, ":%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count ); + r += sprintf( r, ":%zd:%zd\n", seed_count, peer_count-seed_count ); break; case TASK_FULLSCRAPE_TPB_ASCII_PLUS: to_hex( r, *hash ); r+= 2 * sizeof(ot_hash); - r += sprintf( r, ":%zd:%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count, peer_list->down_count ); + r += sprintf( r, ":%zd:%zd:%zd\n", seed_count, peer_count-seed_count, down_count ); break; case TASK_FULLSCRAPE_TPB_BINARY: memcpy( r, *hash, sizeof(ot_hash) ); r += sizeof(ot_hash); - *(uint32_t*)(r+0) = htonl( (uint32_t) peer_list->seed_count ); - *(uint32_t*)(r+4) = htonl( (uint32_t)( peer_list->peer_count-peer_list->seed_count) ); + *(uint32_t*)(r+0) = htonl( (uint32_t) seed_count ); + *(uint32_t*)(r+4) = htonl( (uint32_t)( peer_count-seed_count) ); r+=8; break; case TASK_FULLSCRAPE_TPB_URLENCODED: r += fmt_urlencoded( r, (char *)*hash, 20 ); - r += sprintf( r, ":%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count ); + r += sprintf( r, ":%zd:%zd\n", seed_count, peer_count-seed_count ); break; case TASK_FULLSCRAPE_TRACKERSTATE: to_hex( r, *hash ); r+= 2 * sizeof(ot_hash); - r += sprintf( r, ":%zd:%zd\n", peer_list->base, peer_list->down_count ); + r += sprintf( r, ":%zd:%zd\n", torrent->peer_list6->base, down_count ); break; } return r; @@ -145,7 +149,7 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas /* For each torrent in this bucket.. */ for( i=0; isize; ++i ) { - r = fullscrape_write_one( mode, r, torrents[i].peer_list, &torrents[i].hash ); + r = fullscrape_write_one( mode, r, torrents+i, &torrents[i].hash ); if( r > re) { /* Allocate a fresh output buffer at the end of our buffers list */ @@ -210,7 +214,7 @@ static void fullscrape_make_gzip( int *iovec_entries, struct iovec **iovector, o /* For each torrent in this bucket.. */ for( i=0; isize; ++i ) { char compress_buffer[OT_SCRAPE_MAXENTRYLEN]; - r = fullscrape_write_one( mode, compress_buffer, torrents[i].peer_list, &torrents[i].hash ); + r = fullscrape_write_one( mode, compress_buffer, torrents+i, &torrents[i].hash ); strm.next_in = (uint8_t*)compress_buffer; strm.avail_in = r - compress_buffer; zres = deflate( &strm, Z_NO_FLUSH ); -- cgit v1.2.3