From 99b615b3b8d8fa6b85b06e562cf9c3ff7ad42c37 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sun, 1 Jul 2012 02:00:02 +0000 Subject: [PATCH] (trunk libT) #4931 "Wrong peer percentages for magnetized transfers" -- fixed. tr_peerUpdateProgress() is guessing at the progress size, but when we don't have the data size yet that guess isn't very good. Add boundary clamps on the peer.progress field. --- libtransmission/peer-mgr.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index dc04d1799..a1beb6ff1 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -2494,11 +2494,21 @@ tr_peerUpdateProgress( tr_torrent * tor, tr_peer * peer ) const float true_count = tr_bitfieldCountTrueBits( have ); if( tr_torrentHasMetadata( tor ) ) + { peer->progress = true_count / tor->info.pieceCount; + } else /* without pieceCount, this result is only a best guess... */ + { peer->progress = true_count / ( have->bit_count + 1 ); + } } + /* clamp the progress range */ + if ( peer->progress < 0.0 ) + peer->progress = 0.0; + if ( peer->progress > 1.0 ) + peer->progress = 1.0; + if( peer->atom && ( peer->progress >= 1.0 ) ) atomSetSeed( tor->torrentPeers, peer->atom ); }