summaryrefslogtreecommitdiff
path: root/ot_fullscrape.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2024-04-03 22:25:30 +0200
committerDirk Engling <erdgeist@erdgeist.org>2024-04-03 22:25:30 +0200
commit2afc4893bf802700a1decfff57673cefc861c7e7 (patch)
tree9a0817371ac05062dbcf25107fcf5a6481feccc0 /ot_fullscrape.c
parenteb8834f7783cb85ae825976425800cd4af711263 (diff)
Prepare opentracker for dual stack capabilities
Diffstat (limited to 'ot_fullscrape.c')
-rw-r--r--ot_fullscrape.c24
1 files changed, 14 insertions, 10 deletions
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 ) {
82 mutex_workqueue_pushtask( sock, tasktype ); 82 mutex_workqueue_pushtask( sock, tasktype );
83} 83}
84 84
85static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_peerlist *peer_list, ot_hash *hash ) { 85static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_torrent *torrent, ot_hash *hash ) {
86 size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count;
87 size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count;
88 size_t down_count = torrent->peer_list6->down_count + torrent->peer_list4->down_count;
89
86 switch( mode & TASK_TASK_MASK ) { 90 switch( mode & TASK_TASK_MASK ) {
87 case TASK_FULLSCRAPE: 91 case TASK_FULLSCRAPE:
88 default: 92 default:
@@ -90,30 +94,30 @@ static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_peerlist *peer
90 *r++='2'; *r++='0'; *r++=':'; 94 *r++='2'; *r++='0'; *r++=':';
91 memcpy( r, hash, sizeof(ot_hash) ); r += sizeof(ot_hash); 95 memcpy( r, hash, sizeof(ot_hash) ); r += sizeof(ot_hash);
92 /* push rest of the scrape string */ 96 /* push rest of the scrape string */
93 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 ); 97 r += sprintf( r, "d8:completei%zde10:downloadedi%zde10:incompletei%zdee", seed_count, down_count, peer_count-seed_count );
94 98
95 break; 99 break;
96 case TASK_FULLSCRAPE_TPB_ASCII: 100 case TASK_FULLSCRAPE_TPB_ASCII:
97 to_hex( r, *hash ); r+= 2 * sizeof(ot_hash); 101 to_hex( r, *hash ); r+= 2 * sizeof(ot_hash);
98 r += sprintf( r, ":%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count ); 102 r += sprintf( r, ":%zd:%zd\n", seed_count, peer_count-seed_count );
99 break; 103 break;
100 case TASK_FULLSCRAPE_TPB_ASCII_PLUS: 104 case TASK_FULLSCRAPE_TPB_ASCII_PLUS:
101 to_hex( r, *hash ); r+= 2 * sizeof(ot_hash); 105 to_hex( r, *hash ); r+= 2 * sizeof(ot_hash);
102 r += sprintf( r, ":%zd:%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count, peer_list->down_count ); 106 r += sprintf( r, ":%zd:%zd:%zd\n", seed_count, peer_count-seed_count, down_count );
103 break; 107 break;
104 case TASK_FULLSCRAPE_TPB_BINARY: 108 case TASK_FULLSCRAPE_TPB_BINARY:
105 memcpy( r, *hash, sizeof(ot_hash) ); r += sizeof(ot_hash); 109 memcpy( r, *hash, sizeof(ot_hash) ); r += sizeof(ot_hash);
106 *(uint32_t*)(r+0) = htonl( (uint32_t) peer_list->seed_count ); 110 *(uint32_t*)(r+0) = htonl( (uint32_t) seed_count );
107 *(uint32_t*)(r+4) = htonl( (uint32_t)( peer_list->peer_count-peer_list->seed_count) ); 111 *(uint32_t*)(r+4) = htonl( (uint32_t)( peer_count-seed_count) );
108 r+=8; 112 r+=8;
109 break; 113 break;
110 case TASK_FULLSCRAPE_TPB_URLENCODED: 114 case TASK_FULLSCRAPE_TPB_URLENCODED:
111 r += fmt_urlencoded( r, (char *)*hash, 20 ); 115 r += fmt_urlencoded( r, (char *)*hash, 20 );
112 r += sprintf( r, ":%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count ); 116 r += sprintf( r, ":%zd:%zd\n", seed_count, peer_count-seed_count );
113 break; 117 break;
114 case TASK_FULLSCRAPE_TRACKERSTATE: 118 case TASK_FULLSCRAPE_TRACKERSTATE:
115 to_hex( r, *hash ); r+= 2 * sizeof(ot_hash); 119 to_hex( r, *hash ); r+= 2 * sizeof(ot_hash);
116 r += sprintf( r, ":%zd:%zd\n", peer_list->base, peer_list->down_count ); 120 r += sprintf( r, ":%zd:%zd\n", torrent->peer_list6->base, down_count );
117 break; 121 break;
118 } 122 }
119 return r; 123 return r;
@@ -145,7 +149,7 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas
145 149
146 /* For each torrent in this bucket.. */ 150 /* For each torrent in this bucket.. */
147 for( i=0; i<torrents_list->size; ++i ) { 151 for( i=0; i<torrents_list->size; ++i ) {
148 r = fullscrape_write_one( mode, r, torrents[i].peer_list, &torrents[i].hash ); 152 r = fullscrape_write_one( mode, r, torrents+i, &torrents[i].hash );
149 153
150 if( r > re) { 154 if( r > re) {
151 /* Allocate a fresh output buffer at the end of our buffers list */ 155 /* 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
210 /* For each torrent in this bucket.. */ 214 /* For each torrent in this bucket.. */
211 for( i=0; i<torrents_list->size; ++i ) { 215 for( i=0; i<torrents_list->size; ++i ) {
212 char compress_buffer[OT_SCRAPE_MAXENTRYLEN]; 216 char compress_buffer[OT_SCRAPE_MAXENTRYLEN];
213 r = fullscrape_write_one( mode, compress_buffer, torrents[i].peer_list, &torrents[i].hash ); 217 r = fullscrape_write_one( mode, compress_buffer, torrents+i, &torrents[i].hash );
214 strm.next_in = (uint8_t*)compress_buffer; 218 strm.next_in = (uint8_t*)compress_buffer;
215 strm.avail_in = r - compress_buffer; 219 strm.avail_in = r - compress_buffer;
216 zres = deflate( &strm, Z_NO_FLUSH ); 220 zres = deflate( &strm, Z_NO_FLUSH );