#1429 (libT) cleaner handling of the special case where the upload or download speed limit is zero
This commit is contained in:
parent
19403b0d7f
commit
c8b51fb734
|
@ -1891,6 +1891,7 @@ rechoke( Torrent * t )
|
|||
int i, peerCount, size, unchokedInterested;
|
||||
tr_peer ** peers = getConnectedPeers( t, &peerCount );
|
||||
struct ChokeData * choke = tr_new0( struct ChokeData, peerCount );
|
||||
const int chokeAll = !tr_torrentPieceTransferIsAllowed( t->tor, TR_CLIENT_TO_PEER );
|
||||
|
||||
assert( torrentIsLocked( t ) );
|
||||
|
||||
|
@ -1900,8 +1901,9 @@ rechoke( Torrent * t )
|
|||
tr_peer * peer = peers[i];
|
||||
if( peer->progress >= 1.0 ) /* choke all seeds */
|
||||
tr_peerMsgsSetChoke( peer->msgs, TRUE );
|
||||
else
|
||||
{
|
||||
else if( chokeAll )
|
||||
tr_peerMsgsSetChoke( peer->msgs, TRUE );
|
||||
else {
|
||||
struct ChokeData * n = &choke[size++];
|
||||
n->peer = peer;
|
||||
n->isInterested = peer->peerIsInterested;
|
||||
|
@ -2503,8 +2505,10 @@ allocateBandwidth( tr_peerMgr * mgr,
|
|||
|
||||
for( i = 0; i < torrentCount; ++i )
|
||||
{
|
||||
Torrent * t = torrents[i];
|
||||
Torrent * t = torrents[i];
|
||||
const size_t used = countPeerBandwidth( t->peers, direction );
|
||||
tr_speedlimit speedMode;
|
||||
|
||||
countHandshakeBandwidth( t->outgoingHandshakes, direction );
|
||||
|
||||
/* remember this torrent's bytes used */
|
||||
|
@ -2513,8 +2517,15 @@ allocateBandwidth( tr_peerMgr * mgr,
|
|||
/* add this torrent's bandwidth use to allBytesUsed */
|
||||
allBytesUsed += used;
|
||||
|
||||
/* if piece data is disallowed, don't bother limiting bandwidth --
|
||||
* we won't be asking for, or sending out, any pieces */
|
||||
if( !tr_torrentPieceTransferIsAllowed( t->tor, direction ) )
|
||||
speedMode = TR_SPEEDLIMIT_UNLIMITED;
|
||||
else
|
||||
speedMode = tr_torrentGetSpeedMode( t->tor, direction );
|
||||
|
||||
/* process the torrent's peers based on its speed mode */
|
||||
switch( tr_torrentGetSpeedMode( t->tor, direction ) )
|
||||
switch( speedMode )
|
||||
{
|
||||
case TR_SPEEDLIMIT_UNLIMITED:
|
||||
givePeersUnlimitedBandwidth( t->peers, direction );
|
||||
|
|
|
@ -542,6 +542,9 @@ isPeerInteresting( const tr_peermsgs * msgs )
|
|||
if( clientIsSeed )
|
||||
return FALSE;
|
||||
|
||||
if( !tr_torrentPieceTransferIsAllowed( msgs->torrent, TR_PEER_TO_CLIENT ) )
|
||||
return FALSE;
|
||||
|
||||
torrent = msgs->torrent;
|
||||
bitfield = tr_cpPieceBitfield( torrent->completion );
|
||||
|
||||
|
@ -810,6 +813,8 @@ pumpRequestQueue( tr_peermsgs * msgs, const time_t now )
|
|||
return;
|
||||
if( msgs->info->clientIsChoked )
|
||||
return;
|
||||
if( !tr_torrentPieceTransferIsAllowed( msgs->torrent, TR_PEER_TO_CLIENT ) )
|
||||
return;
|
||||
|
||||
while( ( count < max ) && reqListPop( &msgs->clientWillAskFor, &req ) )
|
||||
{
|
||||
|
|
|
@ -146,7 +146,7 @@ tr_torrentSetSpeedMode( tr_torrent * tor,
|
|||
tr_speedlimit mode )
|
||||
{
|
||||
tr_speedlimit * limit = direction == TR_UP ? &tor->uploadLimitMode
|
||||
: &tor->downloadLimitMode;
|
||||
: &tor->downloadLimitMode;
|
||||
|
||||
*limit = mode;
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ tr_torrentGetSpeedMode( const tr_torrent * tor,
|
|||
tr_direction direction )
|
||||
{
|
||||
return direction == TR_UP ? tor->uploadLimitMode
|
||||
: tor->downloadLimitMode;
|
||||
: tor->downloadLimitMode;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -194,6 +194,34 @@ tr_torrentGetSpeedLimit( const tr_torrent * tor,
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
tr_torrentPieceTransferIsAllowed( const tr_torrent * tor,
|
||||
tr_direction direction )
|
||||
{
|
||||
int isEnabled = FALSE;
|
||||
|
||||
switch( tr_torrentGetSpeedMode( tor, direction ) )
|
||||
{
|
||||
case TR_SPEEDLIMIT_GLOBAL:
|
||||
isEnabled = tr_sessionGetSpeedLimit( tor->session, direction ) > 0;
|
||||
break;
|
||||
|
||||
case TR_SPEEDLIMIT_SINGLE:
|
||||
isEnabled = tr_torrentGetSpeedLimit( tor, direction ) > 0;
|
||||
break;
|
||||
|
||||
case TR_SPEEDLIMIT_UNLIMITED:
|
||||
isEnabled = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
assert( 0 && "unhandled speed mode" );
|
||||
break;
|
||||
}
|
||||
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
|
|
@ -81,6 +81,9 @@ tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session * session,
|
|||
|
||||
int tr_torrentAllowsPex( const tr_torrent * );
|
||||
|
||||
int tr_torrentPieceTransferIsAllowed( const tr_torrent * torrent,
|
||||
tr_direction direction );
|
||||
|
||||
/* get the index of this piece's first block */
|
||||
#define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\
|
||||
( tor )->blockCountInPiece )
|
||||
|
|
Loading…
Reference in New Issue