From afc7c5355e2a4766f0b16ddb8f004b2f9ea84253 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Sat, 25 Sep 2010 00:34:15 +0000 Subject: [PATCH] (libT) #3453:Torrent does not stop when set per torrent seed ratio is reached before torrent is completed (libT) #3578:Interested flag isn't cleared when transitioning from leeching to seeding --- libtransmission/peer-mgr.c | 24 ++++++++++++++++++++++++ libtransmission/peer-mgr.h | 2 ++ libtransmission/torrent.c | 17 ++++++++++++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 32b5f604d..5ca8d6a08 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -2384,6 +2384,30 @@ tr_peerMgrPeerStats( const tr_torrent * tor, *** **/ +void +tr_peerMgrClearInterest( tr_torrent * tor ) +{ + int i; + Torrent * t; + int peerCount; + + assert( tr_isTorrent( tor ) ); + + t = tor->torrentPeers; + + torrentLock( t ); + + peerCount = tr_ptrArraySize( &t->peers ); + + for( i=0; ipeers, i ); + tr_peerMsgsSetInterested( peer->msgs, FALSE ); + } + + torrentUnlock( t ); +} + /* do we still want this piece and does the peer have it? */ static tr_bool isPieceInteresting( const tr_torrent * tor, const tr_peer * peer, tr_piece_index_t index ) diff --git a/libtransmission/peer-mgr.h b/libtransmission/peer-mgr.h index 734b3db00..727f34766 100644 --- a/libtransmission/peer-mgr.h +++ b/libtransmission/peer-mgr.h @@ -234,6 +234,8 @@ int tr_peerGetPieceSpeed_Bps( const tr_peer * peer, uint64_t now, tr_direction direction ); +void tr_peerMgrClearInterest( tr_torrent * tor ); + /* @} */ #endif diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index fe6955ba4..70387824b 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -1599,8 +1599,10 @@ verifyTorrent( void * vtor ) /* if the torrent's running, stop it & set the restart-after-verify flag */ if( tor->startAfterVerify || tor->isRunning ) { + /* don't clobber isStopping */ + const tr_bool startAfter = tor->isStopping ? FALSE : TRUE; tr_torrentStop( tor ); - tor->startAfterVerify = TRUE; + tor->startAfterVerify = startAfter; } /* add the torrent to the recheck queue */ @@ -1847,7 +1849,6 @@ torrentCallScript( tr_torrent * tor, const char * script ) void tr_torrentRecheckCompleteness( tr_torrent * tor ) { - tr_bool wasRunning; tr_completeness completeness; assert( tr_isTorrent( tor ) ); @@ -1855,11 +1856,12 @@ tr_torrentRecheckCompleteness( tr_torrent * tor ) tr_torrentLock( tor ); completeness = tr_cpGetStatus( &tor->completion ); - wasRunning = tor->isRunning; if( completeness != tor->completeness ) { const int recentChange = tor->downloadedCur != 0; + const tr_bool wasLeeching = !tr_torrentIsSeed( tor ); + const tr_bool wasRunning = tor->isRunning; if( recentChange ) { @@ -1879,6 +1881,15 @@ tr_torrentRecheckCompleteness( tr_torrent * tor ) tor->doneDate = tor->anyDate = tr_time( ); } + if( wasLeeching && wasRunning ) + { + /* clear interested flag on all peers */ + tr_peerMgrClearInterest( tor ); + + /* if completeness was TR_LEECH then the seed limit check will have been skipped in bandwidthPulse */ + tr_torrentCheckSeedLimit( tor ); + } + if( tor->currentDir == tor->incompleteDir ) tr_torrentSetLocation( tor, tor->downloadDir, TRUE, NULL, NULL ); -- 2.40.0