(trunk libT) code cleanup: after r10346, we don't need to keep the per-torrent cancel/block histories anymore

This commit is contained in:
Charles Kerr 2010-03-10 15:55:00 +00:00
parent 3aa3ec7d14
commit 1d8d9d8447
4 changed files with 12 additions and 40 deletions

View File

@ -85,7 +85,7 @@ enum
/** how long we'll let requests we've made linger before we cancel them */
REQUEST_TTL_SECS = 60,
HISTORY_SEC = TORRENT_DOWNLOAD_CONGESTION_HISTORY_SEC
CANCEL_HISTORY_SEC = 120
};
@ -346,10 +346,10 @@ peerConstructor( struct peer_atom * atom )
peer->atom = atom;
atom->peer = peer;
peer->blocksSentToClient = tr_historyNew( HISTORY_SEC, 1 );
peer->blocksSentToPeer = tr_historyNew( HISTORY_SEC, 1 );
peer->cancelsSentToClient = tr_historyNew( HISTORY_SEC, 1 );
peer->cancelsSentToPeer = tr_historyNew( HISTORY_SEC, 1 );
peer->blocksSentToClient = tr_historyNew( CANCEL_HISTORY_SEC, 1 );
peer->blocksSentToPeer = tr_historyNew( CANCEL_HISTORY_SEC, 1 );
peer->cancelsSentToClient = tr_historyNew( CANCEL_HISTORY_SEC, 1 );
peer->cancelsSentToPeer = tr_historyNew( CANCEL_HISTORY_SEC, 1 );
return peer;
}
@ -1149,7 +1149,6 @@ refillUpkeep( int foo UNUSED, short bar UNUSED, void * vmgr )
for( it=cancel, end=it+cancelCount; it!=end; ++it ) {
if( ( it->peer != NULL ) && ( it->peer->msgs != NULL ) ) {
tr_historyAdd( it->peer->cancelsSentToPeer, now_msec, 1 );
tr_historyAdd( tor->cancelsSentToPeer, now_msec, 1 );
tr_peerMsgsCancel( it->peer->msgs, it->block );
decrementPendingReqCount( it );
}
@ -1381,16 +1380,13 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
case TR_PEER_CLIENT_GOT_BLOCK:
{
tr_torrent * tor = t->tor;
uint64_t now_msec;
tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset );
requestListRemove( t, block, peer );
pieceListRemoveRequest( t, block );
now_msec = tr_date( );
tr_historyAdd( tor->blocksSentToClient, now_msec, 1 );
if( peer != NULL )
tr_historyAdd( peer->blocksSentToClient, now_msec, 1 );
tr_historyAdd( peer->blocksSentToClient, tr_date( ), 1 );
if( tr_cpBlockIsComplete( &tor->completion, block ) )
{
@ -2268,10 +2264,10 @@ tr_peerMgrPeerStats( const tr_torrent * tor,
stat->isUploadingTo = clientIsUploadingTo( peer );
stat->isSeed = ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 );
stat->blocksToPeer = tr_historyGet( peer->blocksSentToPeer, now, HISTORY_SEC*1000 );
stat->blocksToClient = tr_historyGet( peer->blocksSentToClient, now, HISTORY_SEC*1000 );
stat->cancelsToPeer = tr_historyGet( peer->cancelsSentToPeer, now, HISTORY_SEC*1000 );
stat->cancelsToClient = tr_historyGet( peer->cancelsSentToClient, now, HISTORY_SEC*1000 );
stat->blocksToPeer = tr_historyGet( peer->blocksSentToPeer, now, CANCEL_HISTORY_SEC*1000 );
stat->blocksToClient = tr_historyGet( peer->blocksSentToClient, now, CANCEL_HISTORY_SEC*1000 );
stat->cancelsToPeer = tr_historyGet( peer->cancelsSentToPeer, now, CANCEL_HISTORY_SEC*1000 );
stat->cancelsToClient = tr_historyGet( peer->cancelsSentToClient, now, CANCEL_HISTORY_SEC*1000 );
stat->pendingReqsToPeer = peer->pendingReqsToPeer;
stat->pendingReqsToClient = peer->pendingReqsToClient;

View File

@ -1439,12 +1439,10 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
{
int i;
struct peer_request r;
const uint64_t now_msec = tr_date( );
tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.index );
tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.offset );
tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.length );
tr_historyAdd( msgs->torrent->blocksSentToClient, now_msec, 1 );
tr_historyAdd( msgs->peer->cancelsSentToClient, now_msec, 1 );
tr_historyAdd( msgs->peer->cancelsSentToClient, tr_date( ), 1 );
dbgmsg( msgs, "got a Cancel %u:%u->%u", r.index, r.offset, r.length );
for( i=0; i<msgs->peer->pendingReqsToClient; ++i ) {
@ -1926,15 +1924,13 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now )
}
else
{
const uint64_t now_msec = tr_date( );
dbgmsg( msgs, "sending block %u:%u->%u", req.index, req.offset, req.length );
EVBUFFER_LENGTH(out) += req.length;
assert( EVBUFFER_LENGTH( out ) == msglen );
tr_peerIoWriteBuf( io, out, TRUE );
bytesWritten += EVBUFFER_LENGTH( out );
msgs->clientSentAnythingAt = now;
tr_historyAdd( msgs->torrent->blocksSentToClient, now_msec, 1 );
tr_historyAdd( msgs->peer->blocksSentToPeer, now_msec, 1 );
tr_historyAdd( msgs->peer->blocksSentToPeer, tr_date( ), 1 );
}
evbuffer_free( out );

View File

@ -610,7 +610,6 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor )
const char * dir;
static int nextUniqueId = 1;
tr_session * session = tr_ctorGetSession( ctor );
const int sec = TORRENT_DOWNLOAD_CONGESTION_HISTORY_SEC;
assert( session != NULL );
@ -620,11 +619,6 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor )
tor->uniqueId = nextUniqueId++;
tor->magicNumber = TORRENT_MAGIC_NUMBER;
tor->blocksSentToClient = tr_historyNew( sec, 1 );
tor->blocksSentToPeer = tr_historyNew( sec, 1 );
tor->cancelsSentToClient = tr_historyNew( sec, 1 );
tor->cancelsSentToPeer = tr_historyNew( sec, 1 );
tr_sha1( tor->obfuscatedHash, "req2", 4,
tor->info.hash, SHA_DIGEST_LENGTH,
NULL );
@ -1297,11 +1291,6 @@ freeTorrent( tr_torrent * tor )
tr_bitfieldDestruct( &tor->checkedPieces );
tr_historyFree( tor->blocksSentToClient );
tr_historyFree( tor->blocksSentToPeer );
tr_historyFree( tor->cancelsSentToClient );
tr_historyFree( tor->cancelsSentToPeer );
tr_free( tor->downloadDir );
tr_free( tor->incompleteDir );
tr_free( tor->peer_id );

View File

@ -18,7 +18,6 @@
#define TR_TORRENT_H 1
#include "completion.h" /* tr_completion */
#include "history.h" /* tr_recentHistory */
#include "session.h" /* tr_sessionLock(), tr_sessionUnlock() */
#include "utils.h" /* TR_GNUC_PRINTF */
@ -176,12 +175,6 @@ struct tr_torrent
* This pointer will be equal to downloadDir or incompleteDir */
const char * currentDir;
tr_recentHistory * blocksSentToClient;
tr_recentHistory * blocksSentToPeer;
tr_recentHistory * cancelsSentToClient;
tr_recentHistory * cancelsSentToPeer;
/* How many bytes we ask for per request */
uint32_t blockSize;
tr_block_index_t blockCount;
@ -350,8 +343,6 @@ static inline tr_bool tr_torrentIsPieceChecked( const tr_torrent * tor,
enum
{
TORRENT_DOWNLOAD_CONGESTION_HISTORY_SEC = 120,
TORRENT_MAGIC_NUMBER = 95549
};