summaryrefslogtreecommitdiff
path: root/trackerlogic.c
diff options
context:
space:
mode:
Diffstat (limited to 'trackerlogic.c')
-rw-r--r--trackerlogic.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/trackerlogic.c b/trackerlogic.c
index 18e8cf5..a2cd1ab 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -269,7 +269,7 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) {
269 * RANDOM may return huge values 269 * RANDOM may return huge values
270 * does not yet check not to return self 270 * does not yet check not to return self
271*/ 271*/
272size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply ) { 272size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp ) {
273 char *r = reply; 273 char *r = reply;
274 size_t peer_count, seed_count, index; 274 size_t peer_count, seed_count, index;
275 275
@@ -295,7 +295,15 @@ size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply
295 } 295 }
296 if( peer_count < amount ) amount = peer_count; 296 if( peer_count < amount ) amount = peer_count;
297 297
298 r += sprintf( r, "d8:completei%zde10:incompletei%zde8:intervali%ie5:peers%zd:", seed_count, peer_count-seed_count, OT_CLIENT_REQUEST_INTERVAL_RANDOM, 6*amount ); 298 if( is_tcp )
299 r += sprintf( r, "d8:completei%zde10:incompletei%zde8:intervali%ie5:peers%zd:", seed_count, peer_count-seed_count, OT_CLIENT_REQUEST_INTERVAL_RANDOM, 6*amount );
300 else {
301 *(unsigned long*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
302 *(unsigned long*)(r+4) = htonl( peer_count );
303 *(unsigned long*)(r+8) = htonl( seed_count );
304 r += 12;
305 }
306
299 if( amount ) { 307 if( amount ) {
300 unsigned int pool_offset, pool_index = 0;; 308 unsigned int pool_offset, pool_index = 0;;
301 unsigned int shifted_pc = peer_count; 309 unsigned int shifted_pc = peer_count;
@@ -327,7 +335,8 @@ size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply
327 r += 6; 335 r += 6;
328 } 336 }
329 } 337 }
330 *r++ = 'e'; 338 if( is_tcp )
339 *r++ = 'e';
331 340
332 return r - reply; 341 return r - reply;
333} 342}