From caa41702712add1ccc5b98224f5f3c40224c4380 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 28 Oct 2007 19:42:47 +0000 Subject: [PATCH] #426 0.91rc1: if pex is disabled on a stopped torrent, pressing "resume" causes pex to be re-enabled. (reported by pea) --- libtransmission/fastresume.c | 30 ++++++++++++++++++++++++++++-- libtransmission/fastresume.h | 1 + libtransmission/peer-mgr.c | 6 +++--- libtransmission/torrent.c | 4 ++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/libtransmission/fastresume.c b/libtransmission/fastresume.c index e6d8980e0..c305afdfd 100644 --- a/libtransmission/fastresume.c +++ b/libtransmission/fastresume.c @@ -522,8 +522,33 @@ fastResumeLoadOld( tr_torrent * tor, return ret; } +static uint64_t +internalIdToPublicBitfield( uint8_t id ) +{ + uint64_t ret = 0; + + switch( id ) + { + case FR_ID_PROGRESS_SLOTS: ret = 0; break; + case FR_ID_DOWNLOADED: ret = TR_FR_DOWNLOADED; break; + case FR_ID_UPLOADED: ret = TR_FR_UPLOADED; break; + case FR_ID_PEERS_OLD: ret = TR_FR_PEERS; break; + case FR_ID_PROGRESS: ret = TR_FR_PROGRESS; break; + case FR_ID_PRIORITY: ret = TR_FR_PRIORITY; break; + case FR_ID_SPEED: ret = TR_FR_SPEEDLIMIT; break; + case FR_ID_RUN: ret = TR_FR_RUN; break; + case FR_ID_CORRUPT: ret = TR_FR_CORRUPT; break; + case FR_ID_PEERS: ret = TR_FR_PEERS; break; + case FR_ID_DESTINATION: ret = TR_FR_DESTINATION; break; + case FR_ID_PEX: ret = TR_FR_PEX; break; + } + + return ret; +} + static uint64_t fastResumeLoadImpl ( tr_torrent * tor, + uint64_t fieldsToLoad, tr_bitfield * uncheckedPieces, const char * destination, int argIsFallback ) @@ -574,7 +599,7 @@ fastResumeLoadImpl ( tr_torrent * tor, /* read each block of data */ while( 1 == fread( &id, 1, 1, file ) && 1 == fread( &len, 4, 1, file ) ) { - switch( id ) + if( fieldsToLoad & internalIdToPublicBitfield( id ) ) switch( id ) { case FR_ID_PROGRESS: /* read progress data */ @@ -773,11 +798,12 @@ fastResumeLoadImpl ( tr_torrent * tor, uint64_t tr_fastResumeLoad( tr_torrent * tor, + uint64_t fieldsToLoad, tr_bitfield * uncheckedPieces, const char * destination, int argIsFallback ) { - const uint64_t ret = fastResumeLoadImpl( tor, uncheckedPieces, destination, argIsFallback ); + const uint64_t ret = fastResumeLoadImpl( tor, fieldsToLoad, uncheckedPieces, destination, argIsFallback ); if( ! ( ret & TR_FR_PROGRESS ) ) tr_bitfieldAddRange( uncheckedPieces, 0, tor->info.pieceCount ); diff --git a/libtransmission/fastresume.h b/libtransmission/fastresume.h index c27808e18..fa1db37d4 100644 --- a/libtransmission/fastresume.h +++ b/libtransmission/fastresume.h @@ -45,6 +45,7 @@ enum * Returns a bitwise-or'ed set of the data loaded from fastresume */ uint64_t tr_fastResumeLoad( tr_torrent * tor, + uint64_t fieldsToLoad, struct tr_bitfield * uncheckedPieces, const char * destination, int destinationIsFallback ); diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 7b80e95ec..d2b87aeba 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1363,15 +1363,14 @@ tr_peerMgrPeerStats( const tr_peerMgr * manager, { int i, size; const Torrent * t; - const tr_peer ** peers; + tr_peer ** peers; tr_peer_stat * ret; assert( manager != NULL ); managerLock( (tr_peerMgr*)manager ); t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); - peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &size ); - + peers = getConnectedPeers( (Torrent*)t, &size ); ret = tr_new0( tr_peer_stat, size ); for( i=0; iinfo.pieceCount ); - loaded = tr_fastResumeLoad( tor, uncheckedPieces, destination, destinationIsFallback ); + loaded = tr_fastResumeLoad( tor, ~0, uncheckedPieces, destination, destinationIsFallback ); assert( tor->destination != NULL ); /* the `paused' flag has highest precedence... @@ -1030,7 +1030,7 @@ tr_torrentStart( tr_torrent * tor ) { if( !tor->uncheckedPieces ) tor->uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount ); - tr_fastResumeLoad( tor, tor->uncheckedPieces, tor->destination, FALSE ); + tr_fastResumeLoad( tor, TR_FR_PROGRESS, tor->uncheckedPieces, tor->destination, FALSE ); tor->isRunning = 1; tr_ioRecheckAdd( tor, checkAndStartCB ); }