mirror of
https://github.com/transmission/transmission
synced 2025-03-12 15:14:12 +00:00
#917: when seeding, drop peers that have everything you have (instead of just dropping seeds)
This commit is contained in:
parent
967a253f93
commit
0f9ca34848
3 changed files with 27 additions and 3 deletions
|
@ -1727,11 +1727,20 @@ shouldPeerBeClosed( const Torrent * t, const tr_peer * peer, int peerCount )
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we're both seeds and it's been long enough for a pex exchange, close it */
|
/* if we're seeding and the peer has everything we have,
|
||||||
|
* and enough time has passed for a pex exchange, then disconnect */
|
||||||
if( 1 ) {
|
if( 1 ) {
|
||||||
const int clientIsSeed = tr_torrentIsSeed( tor );
|
const int clientIsSeed = tr_torrentIsSeed( tor );
|
||||||
const int peerIsSeed = atom->flags & ADDED_F_SEED_FLAG;
|
int peerHasEverything;
|
||||||
if( peerIsSeed && clientIsSeed && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30) ) ) {
|
if( atom->flags & ADDED_F_SEED_FLAG )
|
||||||
|
peerHasEverything = TRUE;
|
||||||
|
else {
|
||||||
|
tr_bitfield * tmp = tr_bitfieldDup( tr_cpPieceBitfield( tor->completion ) );
|
||||||
|
tr_bitfieldDifference( tmp, peer->have );
|
||||||
|
peerHasEverything = tr_bitfieldCountTrueBits( tmp ) == 0;
|
||||||
|
tr_bitfieldFree( tmp );
|
||||||
|
}
|
||||||
|
if( clientIsSeed && peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30) ) ) {
|
||||||
tordbg( t, "purging peer %s because we're both seeds", tr_peerIoAddrStr(&atom->addr,atom->port) );
|
tordbg( t, "purging peer %s because we're both seeds", tr_peerIoAddrStr(&atom->addr,atom->port) );
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -783,6 +783,20 @@ tr_bitfieldOr( tr_bitfield * a, const tr_bitfield * b )
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set 'a' to all the flags that were in 'a' but not 'b' */
|
||||||
|
void
|
||||||
|
tr_bitfieldDifference( tr_bitfield * a, const tr_bitfield * b )
|
||||||
|
{
|
||||||
|
uint8_t *ait;
|
||||||
|
const uint8_t *aend, *bit;
|
||||||
|
|
||||||
|
assert( a->len == b->len );
|
||||||
|
|
||||||
|
for( ait=a->bits, bit=b->bits, aend=ait+a->len; ait!=aend; )
|
||||||
|
*ait++ &= ~(*bit++);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
tr_bitfieldCountTrueBits( const tr_bitfield* b )
|
tr_bitfieldCountTrueBits( const tr_bitfield* b )
|
||||||
{
|
{
|
||||||
|
|
|
@ -189,6 +189,7 @@ int tr_bitfieldAdd( tr_bitfield*, size_t bit );
|
||||||
int tr_bitfieldRem( tr_bitfield*, size_t bit );
|
int tr_bitfieldRem( tr_bitfield*, size_t bit );
|
||||||
int tr_bitfieldAddRange( tr_bitfield *, size_t begin, size_t end );
|
int tr_bitfieldAddRange( tr_bitfield *, size_t begin, size_t end );
|
||||||
int tr_bitfieldRemRange ( tr_bitfield*, size_t begin, size_t end );
|
int tr_bitfieldRemRange ( tr_bitfield*, size_t begin, size_t end );
|
||||||
|
void tr_bitfieldDifference( tr_bitfield *, const tr_bitfield * );
|
||||||
|
|
||||||
int tr_bitfieldHas( const tr_bitfield*, size_t bit );
|
int tr_bitfieldHas( const tr_bitfield*, size_t bit );
|
||||||
int tr_bitfieldIsEmpty( const tr_bitfield* );
|
int tr_bitfieldIsEmpty( const tr_bitfield* );
|
||||||
|
|
Loading…
Add table
Reference in a new issue