summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ot_mutex.c2
-rw-r--r--trackerlogic.c16
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 @@
26/* Our global all torrents list */ 26/* Our global all torrents list */
27static ot_vector all_torrents[OT_BUCKET_COUNT]; 27static ot_vector all_torrents[OT_BUCKET_COUNT];
28static pthread_mutex_t bucket_mutex[OT_BUCKET_COUNT]; 28static pthread_mutex_t bucket_mutex[OT_BUCKET_COUNT];
29static size_t g_torrent_count; 29static size_t g_torrent_count;
30 30
31/* Self pipe from opentracker.c */ 31/* Self pipe from opentracker.c */
32extern int g_self_pipe[2]; 32extern 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
278 char *r = reply; 278 char *r = reply;
279 size_t peer_size = peer_size_from_peer6(&ws->peer); 279 size_t peer_size = peer_size_from_peer6(&ws->peer);
280 ot_peerlist *peer_list = peer_size == OT_PEER_SIZE6 ? torrent->peer_list6 : torrent->peer_list4; 280 ot_peerlist *peer_list = peer_size == OT_PEER_SIZE6 ? torrent->peer_list6 : torrent->peer_list4;
281 size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count;
282 size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count;
281 283
282 if( amount > peer_list->peer_count ) 284 if( amount > peer_list->peer_count )
283 amount = peer_list->peer_count; 285 amount = peer_list->peer_count;
284 286
285 *(uint32_t*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); 287 *(uint32_t*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
286 *(uint32_t*)(r+4) = htonl( peer_list->peer_count - peer_list->seed_count ); 288 *(uint32_t*)(r+4) = htonl( peer_count - seed_count );
287 *(uint32_t*)(r+8) = htonl( peer_list->seed_count ); 289 *(uint32_t*)(r+8) = htonl( seed_count );
288 r += 12; 290 r += 12;
289 291
290 if( amount ) { 292 if( amount ) {
@@ -442,6 +444,7 @@ size_t remove_peer_from_torrent( PROTO_FLAG proto, struct ot_workstruct *ws ) {
442 ot_peerlist *peer_list = &dummy_list; 444 ot_peerlist *peer_list = &dummy_list;
443 size_t peer_size; /* initialized in next line */ 445 size_t peer_size; /* initialized in next line */
444 ot_peer const *peer_src = peer_from_peer6(&ws->peer, &peer_size); 446 ot_peer const *peer_src = peer_from_peer6(&ws->peer, &peer_size);
447 size_t peer_count, seed_count;
445 448
446#ifdef WANT_SYNC_LIVE 449#ifdef WANT_SYNC_LIVE
447 if( proto != FLAG_MCA ) { 450 if( proto != FLAG_MCA ) {
@@ -459,16 +462,19 @@ size_t remove_peer_from_torrent( PROTO_FLAG proto, struct ot_workstruct *ws ) {
459 } 462 }
460 } 463 }
461 464
465 peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count;
466 seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count;
467
462 if( proto == FLAG_TCP ) { 468 if( proto == FLAG_TCP ) {
463 int erval = OT_CLIENT_REQUEST_INTERVAL_RANDOM; 469 int erval = OT_CLIENT_REQUEST_INTERVAL_RANDOM;
464 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 ); 470 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 );
465 } 471 }
466 472
467 /* Handle UDP reply */ 473 /* Handle UDP reply */
468 if( proto == FLAG_UDP ) { 474 if( proto == FLAG_UDP ) {
469 ((uint32_t*)ws->reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); 475 ((uint32_t*)ws->reply)[2] = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
470 ((uint32_t*)ws->reply)[3] = htonl( peer_list->peer_count - peer_list->seed_count ); 476 ((uint32_t*)ws->reply)[3] = htonl( peer_count - seed_count );
471 ((uint32_t*)ws->reply)[4] = htonl( peer_list->seed_count); 477 ((uint32_t*)ws->reply)[4] = htonl( seed_count);
472 ws->reply_size = 20; 478 ws->reply_size = 20;
473 } 479 }
474 480