Ignore:
Timestamp:
Oct 25, 2008, 3:19:46 PM (13 years ago)
Author:
charles
Message:

(libT) minor code cleanup for r6954

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r6954 r6957  
    631631    uint32_t         piece;
    632632    uint32_t         peerCount;
    633     int              missingBlockCount;
    634633    int              random;
    635634    int              pendingRequestCount;
     635    int              missingBlockCount;
    636636};
    637637
     
    684684    /* make a list of the pieces that we want but don't have */
    685685    for( i = 0; i < inf->pieceCount; ++i )
    686         if( !tor->info.pieces[i].dnd && !tr_cpPieceIsComplete( tor->completion, i ) )
     686        if( !tor->info.pieces[i].dnd
     687                && !tr_cpPieceIsComplete( tor->completion, i ) )
    687688            pool[poolSize++] = i;
    688689
    689     /* sort the pool from most interesting to least... */
     690    /* sort the pool by which to request next */
    690691    if( poolSize > 1 )
    691692    {
     
    703704            setme->peerCount = 0;
    704705            setme->random = tr_cryptoWeakRandInt( INT_MAX );
    705             setme->missingBlockCount = tr_cpMissingBlocksInPiece( tor->completion, piece );
    706706            setme->pendingRequestCount = getPieceRequests( t, piece );
     707            setme->missingBlockCount
     708                         = tr_cpMissingBlocksInPiece( tor->completion, piece );
    707709
    708710            for( k = 0; k < peerCount; ++k )
    709711            {
    710712                const tr_peer * peer = peers[k];
    711                 if( peer->peerIsInterested && !peer->clientIsChoked
    712                   && tr_bitfieldHas( peer->have, piece ) )
     713                if( peer->peerIsInterested
     714                        && !peer->clientIsChoked
     715                        && tr_bitfieldHas( peer->have, piece ) )
    713716                    ++setme->peerCount;
    714717            }
     
    780783blockIteratorFree( struct tr_blockIterator * i )
    781784{
     785    tr_free( i->blocks );
    782786    tr_free( i->pieces );
    783     tr_free( i->blocks );
    784787    tr_free( i );
    785788}
     
    800803        /* Get a list of peers we're downloading from.
    801804           Pick a different starting point each time so all peers
    802            get a chance at the first blocks in the queue */
     805           get a chance at being the first in line */
    803806        const int fencepost = tr_cryptoWeakRandInt( peerCount );
    804807        int i = fencepost;
     
    815818}
    816819
     820static uint32_t
     821getBlockOffsetInPiece( const tr_torrent * tor, uint64_t b )
     822{
     823    const uint64_t piecePos = tor->info.pieceSize * tr_torBlockPiece( tor, b );
     824    const uint64_t blockPos = tor->blockSize * b;
     825    assert( blockPos >= piecePos );
     826    return (uint32_t)( blockPos - piecePos );
     827}
     828
    817829static int
    818830refillPulse( void * vtorrent )
     
    848860
    849861        const tr_piece_index_t index = tr_torBlockPiece( tor, block );
    850         const uint32_t begin = (block * tor->blockSize) - (index * tor->info.pieceSize);
     862        const uint32_t offset = getBlockOffsetInPiece( tor, block );
    851863        const uint32_t length = tr_torBlockCountBytes( tor, block );
    852864
    853         assert( tr_torrentReqIsValid( tor, index, begin, length ) );
    854         assert( _tr_block( tor, index, begin ) == block );
    855         assert( begin < tr_torPieceCountBytes( tor, index ) );
    856         assert( (begin + length) <= tr_torPieceCountBytes( tor, index ) );
     865        assert( tr_torrentReqIsValid( tor, index, offset, length ) );
     866        assert( _tr_block( tor, index, offset ) == block );
     867        assert( offset < tr_torPieceCountBytes( tor, index ) );
     868        assert( (offset + length) <= tr_torPieceCountBytes( tor, index ) );
    857869
    858870        /* find a peer who can ask for this block */
    859871        for( j=0; !handled && j<peerCount; )
    860872        {
    861             const int val = tr_peerMsgsAddRequest( peers[j]->msgs, index, begin, length );
     873            const int val = tr_peerMsgsAddRequest( peers[j]->msgs,
     874                                                   index, offset, length );
    862875            switch( val )
    863876            {
     
    886899        for( j=0; !handled && j<webseedCount; )
    887900        {
    888             const tr_addreq_t val = tr_webseedAddRequest( webseeds[j], index, begin, length );
     901            const tr_addreq_t val = tr_webseedAddRequest( webseeds[j],
     902                                                          index, offset, length );
    889903            switch( val )
    890904            {
Note: See TracChangeset for help on using the changeset viewer.