Changeset 2297


Ignore:
Timestamp:
Jul 6, 2007, 4:17:37 PM (15 years ago)
Author:
charles
Message:

fix endgame bugs

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer.c

    r2296 r2297  
    155155    /* The pieces that the peer has */
    156156    tr_bitfield_t     * bitfield;
     157
     158    /* blocks we've requested from this peer */
     159    tr_bitfield_t     * reqfield;
    157160    int                 pieceCount;
    158161    float               progress;
     
    232235tr_peer_t * tr_peerInit( struct in_addr addr, in_port_t port, int s, int from )
    233236{
    234     tr_peer_t * peer = peerInit();
     237    tr_peer_t * peer;
    235238
    236239    assert( 0 <= from && TR_PEER_FROM__MAX > from );
     240
     241    peer              = tr_new0( tr_peer_t, 1 );
     242    peertreeInit( &peer->sentPeers );
     243    peer->amChoking   = TRUE;
     244    peer->peerChoking = TRUE;
     245    peer->date        = tr_date();
     246    peer->keepAlive   = peer->date;
     247    peer->download    = tr_rcInit();
     248    peer->upload      = tr_rcInit();
    237249
    238250    peer->outRequestMax = peer->outRequestAlloc = 2;
     
    276288    tr_bitfieldFree( peer->blamefield );
    277289    tr_bitfieldFree( peer->banfield );
     290    tr_bitfieldFree( peer->reqfield );
    278291    tr_free( peer->inRequests );
    279292    tr_free( peer->outRequests );
     
    622635        if( endgame ) /* endgame -- request everything we don't already have */
    623636        {
    624             const tr_bitfield_t * blocks = tr_cpBlockBitfield( tor->completion );
    625             for( i=0; i<tor->blockCount && peer->inRequestCount<peer->inRequestMax; ++i ) {
    626                 if( tr_bitfieldHas( blocks, i ) )
    627                     sendRequest( tor, peer, i );
     637            for( i=0; i<tor->blockCount && peer->inRequestCount<peer->inRequestMax; ++i )
     638            {
     639                if( !isBlockInteresting( tor, peer, i ) )
     640                    continue;
     641                if( tr_bitfieldHas( peer->reqfield, i ) ) /* we've already asked them for it */
     642                    continue;
     643                if( !peer->reqfield )
     644                    peer->reqfield = tr_bitfieldNew( tor->blockCount );
     645                tr_bitfieldAdd( peer->reqfield, i );
     646                sendRequest( tor, peer, i );
    628647            }
    629648        }
  • trunk/libtransmission/peerutils.h

    r2233 r2297  
    2525static void updateInterest( tr_torrent_t * tor, tr_peer_t * peer );
    2626
    27 /***********************************************************************
    28  * peerInit
    29  ***********************************************************************
    30  * Allocates a new tr_peer_t and returns a pointer to it.
    31  **********************************************************************/
    32 static tr_peer_t * peerInit()
    33 {
    34     tr_peer_t * peer;
    35 
    36     peer              = calloc( sizeof( tr_peer_t ), 1 );
    37     peertreeInit( &peer->sentPeers );
    38     peer->amChoking   = 1;
    39     peer->peerChoking = 1;
    40     peer->date        = tr_date();
    41     peer->keepAlive   = peer->date;
    42     peer->download    = tr_rcInit();
    43     peer->upload      = tr_rcInit();
    44 
    45     return peer;
    46 }
    4727
    4828static int peerCmp( tr_peer_t * peer1, tr_peer_t * peer2 )
     
    190170                               int                   piece )
    191171{
     172    if( tr_cpPieceIsComplete( tor->completion, piece ) ) /* we already have it */
     173        return 0;
     174
    192175    if( tor->info.pieces[piece].priority == TR_PRI_DND ) /* we don't want it */
    193176        return 0;
     
    199182        return 0;
    200183
    201     if( tr_cpPieceIsComplete( tor->completion, piece ) ) /* we already have it */
     184    return 1;
     185}
     186
     187static int isBlockInteresting( const tr_torrent_t  * tor,
     188                               const tr_peer_t     * peer,
     189                               int                   block )
     190{
     191    if( !isPieceInteresting( tor, peer, tr_blockPiece( block ) ) ) /* is piece interesting? */
     192        return 0;
     193
     194    if( tr_cpBlockIsComplete( tor->completion, block )) /* we already have it */
    202195        return 0;
    203196
  • trunk/libtransmission/utils.c

    r2259 r2297  
    496496    if ( bitfield == NULL ) return 0;
    497497    assert( bit / 8u < bitfield->len );
    498     return ( bitfield->bits[ bit/8u ] & bitmask[bit%8] );
     498    return ( bitfield->bits[ bit/8u ] & bitmask[bit%8] ) != 0;
    499499}
    500500
Note: See TracChangeset for help on using the changeset viewer.