diff --git a/opentracker.c b/opentracker.c index 6858f37..35482e4 100644 --- a/opentracker.c +++ b/opentracker.c @@ -270,7 +270,7 @@ e500: httperror(h,"500 Internal Server Error","A server error has occured. Please retry later."); goto bailout; } - reply = malloc( numwant*6+64 ); // peerlist + seeder, peers and lametta + reply = malloc( numwant*6+128 ); // peerlist + seeder, peers and lametta n*6+81 a.t.m. if( reply ) reply_size = return_peers_for_torrent( torrent, numwant, reply ); if( !reply || ( reply_size < 0 ) ) { diff --git a/trackerlogic.c b/trackerlogic.c index 0207fad..7b5b94a 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -193,11 +193,14 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) { // size_t return_peers_for_torrent( ot_torrent *torrent, unsigned long amount, char *reply ) { char *r = reply; - unsigned long peer_count, index; + unsigned long peer_count, seed_count, index; signed long pool_offset = -1, pool_index = 0; signed long wert = -1; - for( peer_count=index=0; indexpeer_list->peers[index].size; + for( peer_count=seed_count=index=0; indexpeer_list->peers[index].size; + seed_count += torrent->peer_list->seed_count[index]; + } if( peer_count < amount ) amount = peer_count; r += FORMAT_FORMAT_STRING( r, "d5:peers%li:",6*amount ); @@ -215,7 +218,8 @@ size_t return_peers_for_torrent( ot_torrent *torrent, unsigned long amount, char MEMMOVE( r, ((ot_peer*)torrent->peer_list->peers[pool_index].data) + pool_offset, 6 ); r += 6; } - *r++ = 'e'; + r += FORMAT_FORMAT_STRING( r, "8:completei%lie10:incompletei%lie8:intervali60ee", seed_count, peer_count-seed_count ); + return r - reply; }