aria2/src/TorrentConsoleDownloadEngine.h

63 lines
1.9 KiB
C
Raw Normal View History

2006-03-21 14:12:51 +00:00
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#ifndef _D_TORRENT_CONSOLE_DOWNLOAD_ENGINE_H_
#define _D_TORRENT_CONSOLE_DOWNLOAD_ENGINE_H_
#include "TorrentDownloadEngine.h"
class TorrentConsoleDownloadEngine : public TorrentDownloadEngine {
private:
/*
struct timeval cp;
long long int sessionDownloadSize;
long long int sessionUploadSize;
*/
struct timeval cp[2];
2006-03-31 15:41:27 +00:00
long long int sessionDownloadLengthArray[2];
long long int sessionUploadLengthArray[2];
2006-03-21 14:12:51 +00:00
int currentCp;
int downloadSpeed;
int uploadSpeed;
2006-04-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add the ability to download multi torrent into respective files directly: * src/DiskWriter.h (openFile): New function. (seek): Removed. * src/MultiDiskWriter.h: New class. * src/MultiDiskWriter.cc: New class. * src/AbstractDiskWriter.h (seek): Changed its scope from public to protected. (openFile): New function. * src/AbstractDiskWriter.cc (openFile): New function. * src/prefs.h (V_FALSE): New definition. (PREF_DIRECT_FILE_MAPPING): New definition. * src/TorrentMan.h (setupDiskWriter): New function. (setAllMultiFileRequestedState): New function. (onDownloadComplete): New function. * src/TorrentMan.cc : Included MultiDiskWriter.h (setupDiskWriter): New function. (getFilePath): Updated. (getTempFilePath): Updated. (getSegmentFilePath): Updated. (fixFilename): Updated. (deleteTempFile): Updated. (setAllMultiFileRequestedState): New function. (setFileEntriesToDownload): Use setAllMultiFileRequestedState(). (finishPartialDownloadingMode): Reset requested flags. (onDownloadComplete): New function. * src/main.cc: Added --direct-file-mapping option. Use TorretMan::setupDiskWriter(). * src/TorrentDownloadEngine.cc (afterEachIteration): Use TorrentMan:: onDownloadComplete(). To fix ETA bug: * src/Util.h (difftvsec): New function. * src/Util.cc (difftvsec): New function. * src/TorrentConsoleDownloadEngine.cc (calculateSpeed): Use int for the type of "elapsed" instead of long long int. (calculateStatistics): Use Util::difftvsec instead of Util::difftv. The updates of statistics takes place every 1 seconds. * src/TorrentConsoleDownloadEngine.h (lastElapsed): Changed its type. (calculateSpeed): Changed its argument signature. * src/PeerMessage.cc (toString): Fixed message.
2006-04-12 13:55:43 +00:00
int lastElapsed;
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.
2006-04-06 12:52:16 +00:00
long long int partialDownloadLengthDiff;
long long int partialTotalLength;
struct timeval startup;
long long int sessionDownloadLength;
int avgSpeed;
int eta;
long long int downloadLength;
long long int totalLength;
2006-03-21 14:12:51 +00:00
void printStatistics();
2006-04-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add the ability to download multi torrent into respective files directly: * src/DiskWriter.h (openFile): New function. (seek): Removed. * src/MultiDiskWriter.h: New class. * src/MultiDiskWriter.cc: New class. * src/AbstractDiskWriter.h (seek): Changed its scope from public to protected. (openFile): New function. * src/AbstractDiskWriter.cc (openFile): New function. * src/prefs.h (V_FALSE): New definition. (PREF_DIRECT_FILE_MAPPING): New definition. * src/TorrentMan.h (setupDiskWriter): New function. (setAllMultiFileRequestedState): New function. (onDownloadComplete): New function. * src/TorrentMan.cc : Included MultiDiskWriter.h (setupDiskWriter): New function. (getFilePath): Updated. (getTempFilePath): Updated. (getSegmentFilePath): Updated. (fixFilename): Updated. (deleteTempFile): Updated. (setAllMultiFileRequestedState): New function. (setFileEntriesToDownload): Use setAllMultiFileRequestedState(). (finishPartialDownloadingMode): Reset requested flags. (onDownloadComplete): New function. * src/main.cc: Added --direct-file-mapping option. Use TorretMan::setupDiskWriter(). * src/TorrentDownloadEngine.cc (afterEachIteration): Use TorrentMan:: onDownloadComplete(). To fix ETA bug: * src/Util.h (difftvsec): New function. * src/Util.cc (difftvsec): New function. * src/TorrentConsoleDownloadEngine.cc (calculateSpeed): Use int for the type of "elapsed" instead of long long int. (calculateStatistics): Use Util::difftvsec instead of Util::difftv. The updates of statistics takes place every 1 seconds. * src/TorrentConsoleDownloadEngine.h (lastElapsed): Changed its type. (calculateSpeed): Changed its argument signature. * src/PeerMessage.cc (toString): Fixed message.
2006-04-12 13:55:43 +00:00
int calculateSpeed(long long int sessionLength, int elapsed);
2006-03-21 14:12:51 +00:00
protected:
void initStatistics();
void calculateStatistics();
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.
2006-04-06 12:52:16 +00:00
void onPartialDownloadingCompletes();
2006-03-21 14:12:51 +00:00
public:
TorrentConsoleDownloadEngine();
~TorrentConsoleDownloadEngine();
};
#endif // _D_TORRENT_CONSOLE_DOWNLOAD_ENGINE_H_