From a973e38bb5249cbe4741e5c24ad97de796ebc1a2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 20 Feb 2010 15:36:25 +0000 Subject: [PATCH] (trunk libT) #2922 "announce's 'download' field should follow the de facto standard" -- added to trunk for 1.91 --- libtransmission/announcer.c | 57 +++++++++++++++++++------------------ libtransmission/announcer.h | 1 - libtransmission/peer-mgr.c | 41 +++++++++++--------------- 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/libtransmission/announcer.c b/libtransmission/announcer.c index 08c281b7f..763ddcb31 100644 --- a/libtransmission/announcer.c +++ b/libtransmission/announcer.c @@ -1034,25 +1034,6 @@ tr_announcerAddBytes( tr_torrent * tor, int type, uint32_t byteCount ) } } -void -tr_announcerSubtractBytes( tr_torrent * tor, int type, uint32_t byteCount ) -{ - int i, n; - tr_torrent_tiers * tiers; - - assert( tr_isTorrent( tor ) ); - assert( type==TR_ANN_UP || type==TR_ANN_DOWN || type==TR_ANN_CORRUPT ); - - tiers = tor->tiers; - n = tr_ptrArraySize( &tiers->tiers ); - for( i=0; itiers, i ); - uint64_t * setme = &tier->byteCounts[type]; - *setme -= MIN( *setme, byteCount ); - } -} - /*** **** ***/ @@ -1514,22 +1495,42 @@ getNextAnnounceEvent( tr_tier * tier ) assert( tier != NULL ); assert( tr_isTorrent( tier->tor ) ); - /* rule #1: if "stopped" is in the queue, ignore everything before it */ + /* special case #1: if "stopped" is in the queue, ignore everything before it */ events = (char**) tr_ptrArrayPeek( &tier->announceEvents, &n ); - for( i=0; pos<0 && i 0 ) ) + /* default: use the next in the queue */ + if( ( pos == -1 ) && ( n > 0 ) ) pos = 0; - /* rule #3: BEP 21: "In order to tell the tracker that a peer is a + /* special case #3: if there are duplicate requests in a row, skip to the last one */ + if( pos >= 0 ) { + for( i=pos+1; i=0 ? events[pos] : NULL; diff --git a/libtransmission/announcer.h b/libtransmission/announcer.h index ceeceaf99..e65e40b3e 100644 --- a/libtransmission/announcer.h +++ b/libtransmission/announcer.h @@ -93,7 +93,6 @@ void tr_announcerTorrentCompleted( tr_torrent * ); enum { TR_ANN_UP, TR_ANN_DOWN, TR_ANN_CORRUPT }; void tr_announcerAddBytes( tr_torrent *, int up_down_or_corrupt, uint32_t byteCount ); -void tr_announcerSubtractBytes( tr_torrent *, int up_down_or_corrupt, uint32_t byteCount ); time_t tr_announcerNextManualAnnounce( const tr_torrent * ); diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 7d0a2db62..ea0666d2c 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1186,7 +1186,6 @@ gotBadPiece( Torrent * t, tr_piece_index_t pieceIndex ) tor->downloadedCur -= MIN( tor->downloadedCur, byteCount ); tr_announcerAddBytes( tor, TR_ANN_CORRUPT, byteCount ); - tr_announcerSubtractBytes( tor, TR_ANN_DOWN, byteCount ); } static void @@ -1237,19 +1236,6 @@ peerSuggestedPiece( Torrent * t UNUSED, #endif } -static void -decrementDownloadedCount( tr_torrent * tor, uint32_t byteCount ) -{ - tor->downloadedCur -= MIN( tor->downloadedCur, byteCount ); - tr_announcerSubtractBytes( tor, TR_ANN_DOWN, byteCount ); -} - -static void -clientGotUnwantedBlock( tr_torrent * tor, tr_block_index_t block ) -{ - decrementDownloadedCount( tor, tr_torBlockCountBytes( tor, block ) ); -} - static void removeRequestFromTables( Torrent * t, tr_block_index_t block, const tr_peer * peer ) { @@ -1355,15 +1341,8 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt ) tr_torrentSetActivityDate( tor, now ); - /* only add this to downloadedCur if we got it from a peer -- - * webseeds shouldn't count against our ratio. As one tracker - * admin put it, "Those pieces are downloaded directly from the - * content distributor, not the peers, it is the tracker's job - * to manage the swarms, not the web server and does not fit - * into the jurisdiction of the tracker." */ - if( peer && e->wasPieceData ) { + if( e->wasPieceData ) { tor->downloadedCur += e->length; - tr_announcerAddBytes( tor, TR_ANN_DOWN, e->length ); tr_torrentSetDirty( tor ); } @@ -1398,17 +1377,18 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt ) tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset ); requestListRemove( t, block, peer ); + pieceListRemoveRequest( t, block ); if( tr_cpBlockIsComplete( &tor->completion, block ) ) { + /* we already have this block... */ + const uint32_t n = tr_torBlockCountBytes( tor, block ); + tor->downloadedCur -= MIN( tor->downloadedCur, n ); tordbg( t, "we have this block already..." ); - clientGotUnwantedBlock( tor, block ); - pieceListRemoveRequest( t, block ); } else { tr_cpBlockAdd( &tor->completion, block ); - pieceListRemoveRequest( t, block ); tr_torrentSetDirty( tor ); if( tr_cpPieceIsComplete( &tor->completion, e->pieceIndex ) ) @@ -1437,6 +1417,17 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt ) tr_peer ** peers; tr_file_index_t fileIndex; + /* only add this to downloadedCur if we got it from a peer -- + * webseeds shouldn't count against our ratio. As one tracker + * admin put it, "Those pieces are downloaded directly from the + * content distributor, not the peers, it is the tracker's job + * to manage the swarms, not the web server and does not fit + * into the jurisdiction of the tracker." */ + if( peer != NULL ) { + const uint32_t n = tr_torPieceCountBytes( tor, p ); + tr_announcerAddBytes( tor, TR_ANN_DOWN, n ); + } + peerCount = tr_ptrArraySize( &t->peers ); peers = (tr_peer**) tr_ptrArrayBase( &t->peers ); for( i=0; i