diff --git a/libtransmission/fastresume.h b/libtransmission/fastresume.h index b0cc47eaa..bb44a854c 100644 --- a/libtransmission/fastresume.h +++ b/libtransmission/fastresume.h @@ -125,6 +125,7 @@ static void fastResumeSave( tr_io_t * io ) int version = 1; char * path; uint8_t * buf; + uint64_t total; buf = malloc( FR_PROGRESS_LEN( tor ) ); @@ -161,8 +162,10 @@ static void fastResumeSave( tr_io_t * io ) free( buf ); /* Write download and upload totals */ - fastResumeWriteData( FR_ID_DOWNLOADED, &tor->downloaded, 8, 1, file ); - fastResumeWriteData( FR_ID_UPLOADED, &tor->uploaded, 8, 1, file ); + total = tor->downloadedCur + tor->downloadedPrev; + fastResumeWriteData( FR_ID_DOWNLOADED, &total, 8, 1, file ); + total = tor->uploadedCur + tor->uploadedPrev; + fastResumeWriteData( FR_ID_UPLOADED, &total, 8, 1, file ); fclose( file ); @@ -333,7 +336,7 @@ static int fastResumeLoad( tr_io_t * io ) /* read download total */ if( 8 == len) { - if( 1 != fread( &tor->downloaded, 8, 1, file ) ) + if( 1 != fread( &tor->downloadedPrev, 8, 1, file ) ) { fclose( file ); return 1; @@ -346,7 +349,7 @@ static int fastResumeLoad( tr_io_t * io ) /* read upload total */ if( 8 == len) { - if( 1 != fread( &tor->uploaded, 8, 1, file ) ) + if( 1 != fread( &tor->uploadedPrev, 8, 1, file ) ) { fclose( file ); return 1; diff --git a/libtransmission/internal.h b/libtransmission/internal.h index 84d81d738..f368fafa1 100644 --- a/libtransmission/internal.h +++ b/libtransmission/internal.h @@ -181,8 +181,10 @@ struct tr_torrent_s tr_peer_t * peers[TR_MAX_PEER_COUNT]; uint64_t date; - uint64_t downloaded; - uint64_t uploaded; + uint64_t downloadedCur; + uint64_t downloadedPrev; + uint64_t uploadedCur; + uint64_t uploadedPrev; tr_stat_t stats[2]; int statCur; diff --git a/libtransmission/peer.c b/libtransmission/peer.c index 2019289d5..e50b97e81 100644 --- a/libtransmission/peer.c +++ b/libtransmission/peer.c @@ -431,9 +431,9 @@ writeBegin: tr_rcTransferred( tor->upload, ret ); tr_rcTransferred( tor->globalUpload, ret ); - tor->uploaded += ret; - peer->outTotal += ret; - peer->outDate = tr_date(); + tor->uploadedCur += ret; + peer->outTotal += ret; + peer->outDate = tr_date(); /* In case this block is done, you may have messages pending. Send them before we start the next block */ diff --git a/libtransmission/peerparse.h b/libtransmission/peerparse.h index afa0087bb..cf94ad856 100644 --- a/libtransmission/peerparse.h +++ b/libtransmission/peerparse.h @@ -272,7 +272,7 @@ static inline int parsePiece( tr_torrent_t * tor, tr_peer_t * peer, return 1; } - tor->downloaded += r->length; + tor->downloadedCur += r->length; block = tr_block( r->index, r->begin ); if( tr_cpBlockIsComplete( tor->completion, block ) ) diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index d06ab1e40..55c64fe52 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -51,9 +51,6 @@ struct tr_tracker_s int bindPort; int newPort; - - uint64_t download; - uint64_t upload; }; static tr_http_t * getQuery ( tr_tracker_t * tc ); @@ -78,9 +75,6 @@ tr_tracker_t * tr_trackerInit( tr_torrent_t * tor ) tc->bindPort = *(tor->bindPort); tc->newPort = -1; - tc->download = tor->downloaded; - tc->upload = tor->uploaded; - return tc; } @@ -243,9 +237,8 @@ static tr_http_t * getQuery( tr_tracker_t * tc ) uint64_t down; uint64_t up; - assert( tor->downloaded >= tc->download && tor->uploaded >= tc->upload ); - down = tor->downloaded - tc->download; - up = tor->uploaded - tc->upload; + down = tor->downloadedCur; + up = tor->uploadedCur; if( tc->started ) { event = "&event=started"; @@ -479,8 +472,6 @@ nodict: else if( 0 < tc->newPort ) { tc->started = 1; - tc->download = tor->downloaded; - tc->upload = tor->uploaded; } cleanup: diff --git a/libtransmission/transmission.c b/libtransmission/transmission.c index a0846f9fc..f0560165c 100644 --- a/libtransmission/transmission.c +++ b/libtransmission/transmission.c @@ -392,6 +392,11 @@ void tr_torrentStart( tr_torrent_t * tor ) torrentReallyStop( tor ); } + tor->downloadedPrev += tor->downloadedCur; + tor->downloadedCur = 0; + tor->uploadedPrev += tor->uploadedCur; + tor->uploadedCur = 0; + tor->status = TR_STATUS_CHECK; tor->tracker = tr_trackerInit( tor ); @@ -540,8 +545,8 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor ) (float) inf->totalSize / s->rateDownload / 1024.0; } - s->downloaded = tor->downloaded; - s->uploaded = tor->uploaded; + s->downloaded = tor->downloadedCur + tor->downloadedPrev; + s->uploaded = tor->uploadedCur + tor->uploadedPrev; tr_lockUnlock( &tor->lock );