From 16a5fa4073b7f2439e0b69423f813dfaf5c7bfb2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 23 Dec 2010 19:32:59 +0000 Subject: [PATCH] (trunk) #1408 "total downloading and seeding time per torrent" -- add patch to track how long a torrent has been seeding or downloading --- libtransmission/resume.c | 18 ++++++++++++++++++ libtransmission/resume.h | 4 +++- libtransmission/rpcimpl.c | 4 ++++ libtransmission/session.c | 28 +++++++++++++++++++++++----- libtransmission/torrent.c | 18 ++++++++++-------- libtransmission/torrent.h | 3 +++ libtransmission/transmission.h | 6 ++++++ 7 files changed, 67 insertions(+), 14 deletions(-) diff --git a/libtransmission/resume.c b/libtransmission/resume.c index c83b3954c..a1bccc2bc 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -51,6 +51,8 @@ #define KEY_SPEED_Bps "speed-Bps" #define KEY_USE_GLOBAL_SPEED_LIMIT "use-global-speed-limit" #define KEY_USE_SPEED_LIMIT "use-speed-limit" +#define KEY_TIME_SEEDING "seeding-time-seconds" +#define KEY_TIME_DOWNLOADING "downloading-time-seconds" #define KEY_SPEEDLIMIT_DOWN_SPEED "down-speed" #define KEY_SPEEDLIMIT_DOWN_MODE "down-mode" #define KEY_SPEEDLIMIT_UP_SPEED "up-speed" @@ -505,6 +507,8 @@ tr_torrentSaveResume( tr_torrent * tor ) return; tr_bencInitDict( &top, 50 ); /* arbitrary "big enough" number */ + tr_bencDictAddInt( &top, KEY_TIME_SEEDING, tor->secondsSeeding ); + tr_bencDictAddInt( &top, KEY_TIME_DOWNLOADING, tor->secondsDownloading ); tr_bencDictAddInt( &top, KEY_ACTIVITY_DATE, tor->activityDate ); tr_bencDictAddInt( &top, KEY_ADDED_DATE, tor->addedDate ); tr_bencDictAddInt( &top, KEY_CORRUPT, tor->corruptPrev + tor->corruptCur ); @@ -636,6 +640,20 @@ loadFromFile( tr_torrent * tor, fieldsLoaded |= TR_FR_ACTIVITY_DATE; } + if( ( fieldsToLoad & TR_FR_TIME_SEEDING ) + && tr_bencDictFindInt( &top, KEY_TIME_SEEDING, &i ) ) + { + tor->secondsSeeding = i; + fieldsLoaded |= TR_FR_TIME_SEEDING; + } + + if( ( fieldsToLoad & TR_FR_TIME_DOWNLOADING ) + && tr_bencDictFindInt( &top, KEY_TIME_DOWNLOADING, &i ) ) + { + tor->secondsDownloading = i; + fieldsLoaded |= TR_FR_TIME_DOWNLOADING; + } + if( ( fieldsToLoad & TR_FR_BANDWIDTH_PRIORITY ) && tr_bencDictFindInt( &top, KEY_BANDWIDTH_PRIORITY, &i ) && tr_isPriority( i ) ) diff --git a/libtransmission/resume.h b/libtransmission/resume.h index c7dbdd985..0e8cab7bd 100644 --- a/libtransmission/resume.h +++ b/libtransmission/resume.h @@ -36,7 +36,9 @@ enum TR_FR_DONE_DATE = ( 1 << 14 ), TR_FR_ACTIVITY_DATE = ( 1 << 15 ), TR_FR_RATIOLIMIT = ( 1 << 16 ), - TR_FR_IDLELIMIT = ( 1 << 17 ) + TR_FR_IDLELIMIT = ( 1 << 17 ), + TR_FR_TIME_SEEDING = ( 1 << 18 ), + TR_FR_TIME_DOWNLOADING = ( 1 << 19 ) }; /** diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 3a18ce99a..fc57dbd6a 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -594,6 +594,10 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key ) tr_bencDictAddInt( d, key, st->startDate ); else if( tr_streq( key, keylen, "status" ) ) tr_bencDictAddInt( d, key, st->activity ); + else if( tr_streq( key, keylen, "secondsDownloading" ) ) + tr_bencDictAddInt( d, key, st->secondsDownloading ); + else if( tr_streq( key, keylen, "secondsSeeding" ) ) + tr_bencDictAddInt( d, key, st->secondsSeeding ); else if( tr_streq( key, keylen, "trackers" ) ) addTrackers( inf, tr_bencDictAddList( d, key, inf->trackerCount ) ); else if( tr_streq( key, keylen, "trackerStats" ) ) { diff --git a/libtransmission/session.c b/libtransmission/session.c index 6af02bbb7..9b8d3553d 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -546,11 +546,34 @@ onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession ) const int min = 100; const int max = 999999; struct timeval tv; + tr_torrent * tor = NULL; tr_session * session = vsession; assert( tr_isSession( session ) ); assert( session->nowTimer != NULL ); + /** + *** tr_session things to do once per second + **/ + + tr_timeUpdate( time( NULL ) ); + + if( session->turtle.isClockEnabled ) + turtleCheckClock( session, &session->turtle ); + + while(( tor = tr_torrentNext( session, tor ))) { + if( tor->isRunning ) { + if( tr_torrentIsSeed( tor ) ) + ++tor->secondsSeeding; + else + ++tor->secondsDownloading; + } + } + + /** + *** Set the timer + **/ + /* schedule the next timer for right after the next second begins */ gettimeofday( &tv, NULL ); usec = 1000000 - tv.tv_usec; @@ -558,11 +581,6 @@ onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession ) if( usec < min ) usec = min; tr_timerAdd( session->nowTimer, 0, usec ); /* fprintf( stderr, "time %zu sec, %zu microsec\n", (size_t)tr_time(), (size_t)tv.tv_usec ); */ - - /* tr_session things to do once per second */ - tr_timeUpdate( tv.tv_sec ); - if( session->turtle.isClockEnabled ) - turtleCheckClock( session, &session->turtle ); } static void loadBlocklists( tr_session * session ); diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 8e493f157..02dc990cc 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -1160,14 +1160,16 @@ tr_torrentStat( tr_torrent * tor ) s->percentComplete = tr_cpPercentComplete ( &tor->completion ); s->metadataPercentComplete = tr_torrentGetMetadataPercent( tor ); - s->percentDone = tr_cpPercentDone ( &tor->completion ); - s->leftUntilDone = tr_cpLeftUntilDone( &tor->completion ); - s->sizeWhenDone = tr_cpSizeWhenDone ( &tor->completion ); - s->recheckProgress = s->activity == TR_STATUS_CHECK ? getVerifyProgress( tor ) : 0; - s->activityDate = tor->activityDate; - s->addedDate = tor->addedDate; - s->doneDate = tor->doneDate; - s->startDate = tor->startDate; + s->percentDone = tr_cpPercentDone ( &tor->completion ); + s->leftUntilDone = tr_cpLeftUntilDone( &tor->completion ); + s->sizeWhenDone = tr_cpSizeWhenDone ( &tor->completion ); + s->recheckProgress = s->activity == TR_STATUS_CHECK ? getVerifyProgress( tor ) : 0; + s->activityDate = tor->activityDate; + s->addedDate = tor->addedDate; + s->doneDate = tor->doneDate; + s->startDate = tor->startDate; + s->secondsSeeding = tor->secondsSeeding; + s->secondsDownloading = tor->secondsDownloading; if ((s->activity == TR_STATUS_DOWNLOAD || s->activity == TR_STATUS_SEED) && s->startDate != 0) s->idleSecs = difftime(tr_time(), MAX(s->startDate, s->activityDate)); diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index b2df8142d..649b27dc8 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -206,6 +206,9 @@ struct tr_torrent time_t startDate; time_t anyDate; + time_t secondsDownloading; + time_t secondsSeeding; + tr_torrent_metadata_func * metadata_func; void * metadata_func_user_data; diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 528c19e3a..060dfe4d9 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -1873,6 +1873,12 @@ typedef struct tr_stat -1 if activity is not seeding or downloading. */ int idleSecs; + /** Cumulative seconds the torrent's ever spent downloading */ + int secondsDownloading; + + /** Cumulative seconds the torrent's ever spent seeding */ + int secondsSeeding; + /** A torrent is considered finished if it has met its seed ratio. As a result, only paused torrents can be finished. */ tr_bool finished; -- 2.40.0