1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-31 11:23:40 +00:00

(libT) #1474: lazy bitfields don't work quite right in 1.40

This commit is contained in:
Charles Kerr 2008-11-16 08:56:18 +00:00
parent 57b2ad5a28
commit 97e4efaa4d

View file

@ -1847,18 +1847,19 @@ sendBitfield( tr_peermsgs * msgs )
/** Lazy bitfields aren't a high priority or secure, so I'm opting for /** Lazy bitfields aren't a high priority or secure, so I'm opting for
speed over a truly random sample -- let's limit the pool size to speed over a truly random sample -- let's limit the pool size to
the first 1000 pieces so large torrents don't bog things down */ the first 1000 pieces so large torrents don't bog things down */
size_t poolSize = MIN( msgs->torrent->info.pieceCount, size_t poolSize;
1000 ); const size_t maxPoolSize = MIN( msgs->torrent->info.pieceCount, 1000 );
tr_piece_index_t * pool = tr_new( tr_piece_index_t, poolSize ); tr_piece_index_t * pool = tr_new( tr_piece_index_t, maxPoolSize );
/* build the pool */ /* build the pool */
for( i = 0; i < poolSize; ++i ) for( i=poolSize=0; i<maxPoolSize; ++i )
pool[i] = i; if( tr_bitfieldHas( field, i ) )
pool[poolSize++] = i;
/* pull random piece indices from the pool */ /* pull random piece indices from the pool */
while( ( poolSize > 0 ) && ( lazyCount < LAZY_PIECE_COUNT ) ) while( ( poolSize > 0 ) && ( lazyCount < LAZY_PIECE_COUNT ) )
{ {
const int pos = tr_cryptoWeakRandInt( poolSize ); const int pos = tr_cryptoWeakRandInt( poolSize );
const tr_piece_index_t piece = pool[pos]; const tr_piece_index_t piece = pool[pos];
tr_bitfieldRem( field, piece ); tr_bitfieldRem( field, piece );
lazyPieces[lazyCount++] = piece; lazyPieces[lazyCount++] = piece;