diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-04-06 12:52:16 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-04-06 12:52:16 +0000 |
| commit | 9a52be6a29369cb7ac97c20c11218b16c2a648dd (patch) | |
| tree | 8f6abdedda606fb320d8874f383430677d1a2d18 /src/TorrentConsoleDownloadEngine.cc | |
| parent | 7228402dadd541e3bea0b939d17c36202180012a (diff) | |
2006-04-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To print ETA:
* src/TorrentDownloadEngine.cc (afterEachIteration): Added
download
completion handling when dealing with
TorrentMan::isPartialDownloadingMode() == true.
* src/TorrentDownloadEngine.h (onPartialDownloadingCompletes):
New function.
* src/TorrentConsoleDownloadEngine.h (startup): New variable.
(sessionDownloadLength): New variable.
(avgSpeed): New variable.
(eta): New variable.
* src/TorrentConsoleDownloadEngine.cc (initStatistics):
Initialized
new variables: eta, avgSpeed, startup.
(calculateSpeed): Calculate average speed and ETA.
(printStatistics): Added ETA.
* src/Util.h (secfmt): New function.
* src/Util.cc (secfmt): New function.
2006-04-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To detect "keep alive" flooding:
* src/PeerInteractionCommand.h (keepAliveCount): New variable
* src/PeerInteractionCommand.cc (Constructor): Initialized new
variable: keepAliveCount.
(detectMessageFlooding): Added "keep alive" flooding detection.
(receiveMessage): Increase keepAliveCount when "keep alive"
message
received.
To add the ability to download only specified files in
multi-file
torrent:
* src/BitfieldMan.h (filterBitfield): New variable.
(filterEnabled): New variable.
(setFilterBit): New function.
(enableFilter): New function.
(disableFilter): New function.
(isFilterEnabled): New function.
(getFilteredTotalLength): New function.
(getCompletedLength): New function.
* src/BitfieldMan.cc (Constructor): Initialized new variable:
filterBitfield, filterEnabled.
(CopyConstructor): Added filterBitfield and filterEnabled.
(operator==): Added filterBitfield and filterEnabled.
(Destructor): Added filterBitfield.
(getMissingIndex): Use filterBitfield.
(getMissingUnusedIndex): Use filterBitfield.
(getFirstMissingUnusedIndex): Use filterBitfield.
(getFirstMissingUnusedIndex): Use filterBitfield.
(getAllMissingIndexes): Use filterBitfield.
(countMissingBlock): Use filterBitfield.
(countBlock): Use filterBitfield.
(setBitInternal): Added new argument on.
(setUseBit): Use setBitInternal.
(unsetUseBit): Use setBitInternal.
(setBit): Use setBitInternal.
(unsetBit): Use setBitInternal.
(isAllBitSet): Use filterBitfield.
(setFilterBit): New function.
(addFilter): New function.
(enableFilter): New function.
(disableFilter): New function.
(clearFilter): New function.
(isFilterEnabled): New function.
(getFilteredTotalLength): New function.
(getCompletedLength): New function.
* src/TorrentMan.h [FileEntry](Constructor): Updated signature.
Initalized newly added variables.
[FileEntry](offset): New variable.
[FileEntry](extracted): New variable.
[FileEntry](requested): New variable.
(readFileEntry): New function.
(option): New variable.
(splitMultiFile): Removed const qualifier.
(fixFilename): Removed const qualifier.
(readFileEntryFromMetaInfoFile): New function.
(finishPartialDownloadingMode): New function.
(isPartialDownloadingMode): New function.
(setFileEntriesToDownload): New function.
(getCompletedLength): New function.
(getPartialTotalLength): New function.
* src/TorrentMan.cc (readFileEntry): New function.
(setup): Use readFileEntry. If no-preallocation option is
specified,
use DefaultDiskWriter.
(readFileEntryFromMetaInfoFile): New function.
(fixFilename): Removed const qualifier.
(splitMultiFile): Removed const qualifier.
(setFileEntriesToDownload): New function.
(isPartialDownloadingMode): New function.
(finishPartialDownloadingMode): New function.
(getCompletedLength): New function.
(getPartialTotalLength): New function.
* src/TorrentConsoleDownloadEngine.h
(partialDownloadLengthDiff):
New variable.
(partialTotalLength): New variable.
(downloadLength): New variable.
(totalLength): New variable.
* src/TorrentConsoleDownloadEngine.cc
(onPartialDownloadingCompletes):
Added log.
(initStatistics): Initialized new variables:
partialDownloadLengthDiff,
partialTotalLength, downloadLength, totalLength.
(calculate): Calculate downloadLength and totalLength.
* src/prefs.h :New definition PREF_NO_PREALLOCATION
* src/main.cc (addCommand): Changed argument signature.
(main): Added new variable: args. Added new option
"torrent-show-files"
"no-preallocation". Usage is not updated yet.
2006-04-02 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/PeerMessage.cc (setBitfield): Fixed invalid memory
de-allocation.
Diffstat (limited to 'src/TorrentConsoleDownloadEngine.cc')
| -rw-r--r-- | src/TorrentConsoleDownloadEngine.cc | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/src/TorrentConsoleDownloadEngine.cc b/src/TorrentConsoleDownloadEngine.cc index 9bf6adb8..8ae62910 100644 --- a/src/TorrentConsoleDownloadEngine.cc +++ b/src/TorrentConsoleDownloadEngine.cc @@ -26,21 +26,26 @@ TorrentConsoleDownloadEngine::TorrentConsoleDownloadEngine() {} TorrentConsoleDownloadEngine::~TorrentConsoleDownloadEngine() {} +void TorrentConsoleDownloadEngine::onPartialDownloadingCompletes() { + printf("Download of specified files has completed. Continue normal download operation.\n"); +} + void TorrentConsoleDownloadEngine::printStatistics() { printf("\r "); printf("\r"); if(torrentMan->downloadComplete()) { printf("Download Completed "); } else { - printf("%s/%sB %d%% DW:%.2f", - Util::llitos(torrentMan->getDownloadLength(), true).c_str(), - Util::llitos(torrentMan->getTotalLength(), true).c_str(), - (torrentMan->getTotalLength() == 0 ? - 0 : (int)((torrentMan->getDownloadLength()*100)/torrentMan->getTotalLength())), - downloadSpeed/1000.0); + printf("%s/%sB %d%% %s D:%.2f", + Util::llitos(downloadLength, true).c_str(), + Util::llitos(totalLength, true).c_str(), + (totalLength == 0 ? + 0 : (int)((downloadLength*100)/totalLength)), + avgSpeed == 0 ? "-" : Util::secfmt(eta).c_str(), + downloadSpeed/1024.0); } - printf(" UP:%.2f(%s) %dpeers", - uploadSpeed/1000.0, + printf(" U:%.2f(%s) %dpeers", + uploadSpeed/1024.0, Util::llitos(torrentMan->getUploadLength(), true).c_str(), torrentMan->connections); fflush(stdout); @@ -52,11 +57,21 @@ void TorrentConsoleDownloadEngine::initStatistics() { lastElapsed = 0; gettimeofday(&cp[0], NULL); gettimeofday(&cp[1], NULL); + gettimeofday(&startup, NULL); sessionDownloadLengthArray[0] = 0; sessionDownloadLengthArray[1] = 0; sessionUploadLengthArray[0] = 0; sessionUploadLengthArray[1] = 0; currentCp = 0; + eta = 0; + avgSpeed = 0; + sessionDownloadLength = 0; + downloadLength = 0; + totalLength = 0; + if(torrentMan->isPartialDownloadingMode()) { + partialDownloadLengthDiff = torrentMan->getDownloadLength()-torrentMan->getCompletedLength(); + partialTotalLength = torrentMan->getPartialTotalLength(); + } } int TorrentConsoleDownloadEngine::calculateSpeed(long long int sessionLength, long long int elapsed) { @@ -74,12 +89,28 @@ void TorrentConsoleDownloadEngine::calculateStatistics() { sessionDownloadLengthArray[1] += torrentMan->getDeltaDownloadLength(); sessionUploadLengthArray[1] += torrentMan->getDeltaUploadLength(); + sessionDownloadLength += torrentMan->getDeltaDownloadLength(); + downloadSpeed = calculateSpeed(sessionDownloadLengthArray[currentCp], elapsed); uploadSpeed = calculateSpeed(sessionUploadLengthArray[currentCp], elapsed); torrentMan->resetDeltaDownloadLength(); torrentMan->resetDeltaUploadLength(); + if(torrentMan->isPartialDownloadingMode()) { + downloadLength = torrentMan->getDownloadLength()-partialDownloadLengthDiff; + totalLength = partialTotalLength; + } else { + downloadLength = torrentMan->getDownloadLength(); + totalLength = torrentMan->getTotalLength(); + } + + avgSpeed = calculateSpeed(sessionDownloadLength, + Util::difftv(now, startup)); + if(avgSpeed != 0) { + eta = (totalLength-downloadLength)/avgSpeed; + } + if(elapsed-lastElapsed >= 1000000) { printStatistics(); lastElapsed = elapsed; |
