From d2270852aff92870034a377878585cbad24ad35e Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Mon, 7 Mar 2011 04:48:46 +0000 Subject: [PATCH] (trunk libT) simpler implementation of the idea behind the code removed in r12108 and r12109. --- libtransmission/peer-mgr.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 579ea48bd..dd9b32297 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -2626,6 +2626,17 @@ tr_peerGetPieceSpeed_Bps( const tr_peer * peer, uint64_t now, tr_direction direc return peer->io ? tr_peerIoGetPieceSpeed_Bps( peer->io, now, direction ) : 0.0; } +static tr_bool +peerIsSeed( const tr_peer * peer ) +{ + if( peer->progress >= 1.0 ) + return TRUE; + + if( peer->atom && ( peer->atom->uploadOnly == UPLOAD_ONLY_YES ) ) + return TRUE; + + return FALSE; +} struct tr_peer_stat * tr_peerMgrPeerStats( const tr_torrent * tor, int * setmeCount ) @@ -2666,7 +2677,7 @@ tr_peerMgrPeerStats( const tr_torrent * tor, int * setmeCount ) stat->isIncoming = tr_peerIoIsIncoming( peer->io ); stat->isDownloadingFrom = clientIsDownloadingFrom( tor, peer ); stat->isUploadingTo = clientIsUploadingTo( peer ); - stat->isSeed = ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 ); + stat->isSeed = peerIsSeed( peer ); stat->blocksToPeer = tr_historyGet( &peer->blocksSentToPeer, now, CANCEL_HISTORY_SEC ); stat->blocksToClient = tr_historyGet( &peer->blocksSentToClient, now, CANCEL_HISTORY_SEC ); @@ -3135,7 +3146,7 @@ shouldPeerBeClosed( const Torrent * t, } /* disconnect if we're both seeds and enough time has passed for PEX */ - if( tr_torrentIsSeed( tor ) && ( peer->progress >= 1.0f ) ) + if( tr_torrentIsSeed( tor ) && peerIsSeed( peer ) ) return !tr_torrentAllowsPex(tor) || (now-atom->time>=30); /* disconnect if it's been too long since piece data has been transferred.