From fa3b9a12c5faa0521efb2ed27f65ed6171f1fcd3 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sat, 14 Feb 2009 05:15:23 +0000 Subject: [PATCH] eta will now indicate time remaining to reach seed ratio when seeding --- libtransmission/torrent.c | 41 +++++++++++++++++++++++++--------- libtransmission/transmission.h | 4 ++-- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index b98f4dd5a..7ab4c7031 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -801,6 +801,7 @@ tr_torrentStat( tr_torrent * tor ) const tr_tracker_info * ti; int usableSeeds = 0; uint64_t now; + double downloadedForRatio, seedRatio; if( !tor ) return NULL; @@ -870,7 +871,6 @@ tr_torrentStat( tr_torrent * tor ) s->haveValid = tr_cpHaveValid( &tor->completion ); s->haveUnchecked = tr_cpHaveTotal( &tor->completion ) - s->haveValid; - if( usableSeeds > 0 ) { s->desiredAvailable = s->leftUntilDone; @@ -891,17 +891,36 @@ tr_torrentStat( tr_torrent * tor ) tr_bitfieldFree( peerPieces ); } - if( s->leftUntilDone > s->desiredAvailable ) - s->eta = TR_ETA_NOT_AVAIL; - else if( s->pieceDownloadSpeed < 0.1 ) - s->eta = TR_ETA_UNKNOWN; - else - s->eta = s->leftUntilDone / s->pieceDownloadSpeed / 1024.0; + downloadedForRatio = s->downloadedEver ? s->downloadedEver : s->haveValid; + s->ratio = tr_getRatio( s->uploadedEver, downloadedForRatio ); - s->ratio = tr_getRatio( - s->uploadedEver, - s->downloadedEver ? s->downloadedEver : s-> - haveValid ); + switch( s->activity ) + { + case TR_STATUS_DOWNLOAD: + if( s->leftUntilDone > s->desiredAvailable ) + s->eta = TR_ETA_NOT_AVAIL; + else if( s->pieceDownloadSpeed < 0.1 ) + s->eta = TR_ETA_UNKNOWN; + else + s->eta = s->leftUntilDone / s->pieceDownloadSpeed / 1024.0; + break; + + case TR_STATUS_SEED: + if( tr_torrentGetSeedRatio( tor, &seedRatio ) ) + { + if( s->pieceUploadSpeed < 0.1 ) + s->eta = TR_ETA_UNKNOWN; + else + s->eta = (downloadedForRatio * (seedRatio - s->ratio)) / s->pieceUploadSpeed / 1024.0; + } + else + s->eta = TR_ETA_NOT_AVAIL; + break; + + default: + s->eta = TR_ETA_NOT_AVAIL; + break; + } tr_torrentUnlock( tor ); diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index a296b40d6..01f39a6aa 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -1331,8 +1331,8 @@ typedef struct tr_stat #define TR_ETA_NOT_AVAIL -1 #define TR_ETA_UNKNOWN -2 - /** Estimated number of seconds left until the torrent is done, - or TR_ETA_NOT_AVAIL or TR_ETA_UNKNOWN */ + /** If downloading, estimated number of seconds left until the torrent is done. + If seeding, estimated number of seconds left until seed ratio is reached. */ int eta; /** Number of peers that the tracker says this torrent has */