Changeset 5759


Ignore:
Timestamp:
May 6, 2008, 7:06:46 PM (14 years ago)
Author:
charles
Message:

#917: when seeding, drop peers that have everything you have (instead of just dropping seeds)

Location:
trunk/libtransmission
Files:
3 edited

Legend:

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

    r5723 r5759  
    17281728    }
    17291729
    1730     /* if we're both seeds and it's been long enough for a pex exchange, close it */
     1730    /* if we're seeding and the peer has everything we have,
     1731     * and enough time has passed for a pex exchange, then disconnect */
    17311732    if( 1 ) {
    17321733        const int clientIsSeed = tr_torrentIsSeed( tor );
    1733         const int peerIsSeed = atom->flags & ADDED_F_SEED_FLAG;
    1734         if( peerIsSeed && clientIsSeed && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30) ) ) {
     1734        int peerHasEverything;
     1735        if( atom->flags & ADDED_F_SEED_FLAG )
     1736            peerHasEverything = TRUE;
     1737        else {
     1738            tr_bitfield * tmp = tr_bitfieldDup( tr_cpPieceBitfield( tor->completion ) );
     1739            tr_bitfieldDifference( tmp, peer->have );
     1740            peerHasEverything = tr_bitfieldCountTrueBits( tmp ) == 0;
     1741            tr_bitfieldFree( tmp );
     1742        }
     1743        if( clientIsSeed && peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30) ) ) {
    17351744            tordbg( t, "purging peer %s because we're both seeds", tr_peerIoAddrStr(&atom->addr,atom->port) );
    17361745            return TRUE;
  • trunk/libtransmission/utils.c

    r5723 r5759  
    784784}
    785785
     786/* set 'a' to all the flags that were in 'a' but not 'b' */
     787void
     788tr_bitfieldDifference( tr_bitfield * a, const tr_bitfield * b )
     789{
     790    uint8_t *ait;
     791    const uint8_t *aend, *bit;
     792
     793    assert( a->len == b->len );
     794
     795    for( ait=a->bits, bit=b->bits, aend=ait+a->len; ait!=aend; )
     796        *ait++ &= ~(*bit++);
     797}
     798
     799
    786800size_t
    787801tr_bitfieldCountTrueBits( const tr_bitfield* b )
  • trunk/libtransmission/utils.h

    r5723 r5759  
    190190int  tr_bitfieldAddRange( tr_bitfield *, size_t begin, size_t end );
    191191int  tr_bitfieldRemRange ( tr_bitfield*, size_t begin, size_t end );
     192void tr_bitfieldDifference( tr_bitfield *, const tr_bitfield * );
    192193
    193194int    tr_bitfieldHas( const tr_bitfield*, size_t bit );
Note: See TracChangeset for help on using the changeset viewer.