(trunk libT) if we're a partial seed and the peer has everything we have, disconnect.

This commit is contained in:
Jordan Lee 2011-02-24 01:50:35 +00:00
parent 1319d9c99b
commit f4992d885c
3 changed files with 24 additions and 1 deletions

View File

@ -159,6 +159,28 @@ tr_bitsetCountRange( const tr_bitset * b, const size_t begin, const size_t end )
return tr_bitfieldCountRange( &b->bitfield, begin, end );
}
/* return true if "b" is equal to, or a superset of, "set" */
tr_bool
tr_bitsetHasSet( const tr_bitset * b, const tr_bitset * set )
{
const uint8_t * bit = b->bitfield.bits;
const uint8_t * bend = bit + b->bitfield.byteCount;
const uint8_t * sit = set->bitfield.bits;
const uint8_t * send = sit + set->bitfield.byteCount;
if( b->haveAll || set->haveAll )
return b->haveAll;
if( b->haveNone || set->haveNone )
return set->haveNone;
for( ; bit!=bend && sit!=send; ++bit, ++sit )
if( ( *bit & *sit ) != *sit )
return FALSE;
return TRUE;
}
double
tr_bitsetPercent( const tr_bitset * b )
{

View File

@ -54,6 +54,7 @@ void tr_bitsetToBenc( const tr_bitset * bitset, struct tr_benc * benc );
double tr_bitsetPercent( const tr_bitset * b );
tr_bool tr_bitsetHas( const tr_bitset * b, const size_t nth );
tr_bool tr_bitsetHasSet( const tr_bitset * b, const tr_bitset * compare );
size_t tr_bitsetCountRange( const tr_bitset * b, const size_t begin, const size_t end );
void tr_bitsetOr( tr_bitfield * a, const tr_bitset * b );

View File

@ -3109,7 +3109,7 @@ shouldPeerBeClosed( const Torrent * t,
/* if we're seeding and the peer has everything we have,
* and enough time has passed for a pex exchange, then disconnect */
if( tr_torrentIsSeed( tor ) && ( peer->progress >= 1.0f ) )
if( tr_torrentIsSeed( tor ) && tr_bitsetHasSet( &peer->have, tr_cpBlockBitset( &tor->completion ) ) )
return !tr_torrentAllowsPex(tor) || (now-atom->time>=30);
/* disconnect if it's been too long since piece data has been transferred.