Changeset 12531


Ignore:
Timestamp:
Jul 2, 2011, 1:20:17 PM (10 years ago)
Author:
jordan
Message:

(trunk libT) #4336 "availablility nonsense" -- fix bug in tr_cpMissingBytesInPiece() introduced last week by r12515 for #4332. Add assertions to the nightly build to watch for regressions of this fix.

The bug was that I fixed #4332's off-by-one improperly in tr_cpMissingBlocksInPiece(). The piece's last block has to be calculated separately because its byte size may be different than the other blocks, The mistake in r12515 was that the last block could wind up being counted twice.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r12515 r12531  
    1010 * $Id$
    1111 */
     12
     13#include <assert.h>
    1214
    1315#include "transmission.h"
     
    214216        size_t haveBytes = 0;
    215217        tr_block_index_t f, l;
     218        const size_t pieceByteSize = tr_torPieceCountBytes( cp->tor, piece );
    216219        tr_torGetPieceBlockRange( cp->tor, piece, &f, &l );
    217         haveBytes = tr_bitfieldCountRange( &cp->blockBitfield, f, l+1 );
    218         haveBytes *= cp->tor->blockSize;
    219         if( tr_bitfieldHas( &cp->blockBitfield, l ) )
     220        if( f != l ) {
     221            /* nb: we don't pass the usual l+1 here to tr_bitfieldCountRange().
     222               It's faster to handle the last block separately because its size
     223               needs to be checked separately. */
     224            haveBytes = tr_bitfieldCountRange( &cp->blockBitfield, f, l );
     225            haveBytes *= cp->tor->blockSize;
     226        }
     227        if( tr_bitfieldHas( &cp->blockBitfield, l ) ) /* handle the last block */
    220228            haveBytes += tr_torBlockCountBytes( cp->tor, l );
    221         return tr_torPieceCountBytes( cp->tor, piece ) - haveBytes;
     229        assert(  haveBytes <= pieceByteSize );
     230        return pieceByteSize - haveBytes;
    222231    }
    223232}
  • trunk/libtransmission/peer-mgr.c

    r12426 r12531  
    25582558}
    25592559
    2560 /* count how many pieces we want that connected peers have */
     2560/* count how many bytes we want that connected peers have */
    25612561uint64_t
    25622562tr_peerMgrGetDesiredAvailable( const tr_torrent * tor )
     
    25952595            desiredAvailable += tr_cpMissingBytesInPiece( &t->tor->completion, i );
    25962596
     2597    assert( desiredAvailable <= tor->info.totalSize );
    25972598    return desiredAvailable;
    25982599}
  • trunk/libtransmission/torrent.c

    r12503 r12531  
    12621262    tr_torrentUnlock( tor );
    12631263
     1264    /* test some of the constraints */
     1265    assert( s->sizeWhenDone <= tor->info.totalSize );
     1266    assert( s->leftUntilDone <= s->sizeWhenDone );
     1267    assert( s->desiredAvailable <= s->leftUntilDone );
    12641268    return s;
    12651269}
Note: See TracChangeset for help on using the changeset viewer.