2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
#include "DefaultBtProgressInfoFile.h"
|
2008-11-03 06:49:02 +00:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
#include "Option.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
#include "Exception.h"
|
2008-11-13 15:08:52 +00:00
|
|
|
#include "MockPieceStorage.h"
|
2007-09-01 16:10:30 +00:00
|
|
|
#include "prefs.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "Piece.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "array_fun.h"
|
|
|
|
#ifdef ENABLE_BITTORRENT
|
|
|
|
# include "MockPeerStorage.h"
|
|
|
|
# include "BtRuntime.h"
|
|
|
|
# include "bittorrent_helper.h"
|
|
|
|
#endif // ENABLE_BITTORRENT
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
|
|
|
|
class DefaultBtProgressInfoFileTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DefaultBtProgressInfoFileTest);
|
2008-05-20 00:42:34 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
CPPUNIT_TEST(testSave);
|
2007-10-11 16:58:24 +00:00
|
|
|
CPPUNIT_TEST(testLoad);
|
2009-02-06 16:49:24 +00:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
2008-08-24 09:43:45 +00:00
|
|
|
CPPUNIT_TEST(testLoad_compat);
|
2009-02-06 16:49:24 +00:00
|
|
|
#endif // !WORDS_BIGENDIAN
|
2008-05-20 00:42:34 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
|
|
|
CPPUNIT_TEST(testSave_nonBt);
|
2007-10-11 16:58:24 +00:00
|
|
|
CPPUNIT_TEST(testLoad_nonBt);
|
2009-02-06 16:49:24 +00:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
2008-08-24 09:43:45 +00:00
|
|
|
CPPUNIT_TEST(testLoad_nonBt_compat);
|
2009-02-06 16:49:24 +00:00
|
|
|
#endif // !WORDS_BIGENDIAN
|
2007-11-13 10:10:11 +00:00
|
|
|
CPPUNIT_TEST(testLoad_nonBt_pieceLengthShorter);
|
2008-05-05 10:10:15 +00:00
|
|
|
CPPUNIT_TEST(testUpdateFilename);
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2008-05-20 00:42:34 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_BITTORRENT
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> dctx_;
|
2008-11-03 06:49:02 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<MockPeerStorage> peerStorage_;
|
2008-11-03 06:49:02 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<BtRuntime> btRuntime_;
|
2008-05-20 00:42:34 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<MockPieceStorage> pieceStorage_;
|
|
|
|
std::shared_ptr<Option> option_;
|
|
|
|
std::shared_ptr<BitfieldMan> bitfield_;
|
2012-10-01 14:52:22 +00:00
|
|
|
public:
|
2012-06-25 14:35:24 +00:00
|
|
|
void initializeMembers(int32_t pieceLength, int64_t totalLength)
|
2007-11-13 10:10:11 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
option_.reset(new Option());
|
2010-12-02 13:38:36 +00:00
|
|
|
option_->put(PREF_DIR, A2_TEST_OUT_DIR);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
bitfield_.reset(new BitfieldMan(pieceLength, totalLength));
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_.reset(new MockPieceStorage());
|
|
|
|
pieceStorage_->setBitfield(bitfield_.get());
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-05-20 00:42:34 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
|
|
|
static unsigned char infoHash[] = {
|
|
|
|
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
|
|
|
|
0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
};
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
dctx_.reset(new DownloadContext());
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<TorrentAttribute> torrentAttrs(new TorrentAttribute());
|
2010-06-18 14:47:09 +00:00
|
|
|
torrentAttrs->infoHash = std::string(vbegin(infoHash), vend(infoHash));
|
2012-09-22 08:37:30 +00:00
|
|
|
dctx_->setAttribute(CTX_ATTR_BT, torrentAttrs);
|
2013-06-21 16:10:38 +00:00
|
|
|
const std::shared_ptr<FileEntry> fileEntries[] = {
|
|
|
|
std::shared_ptr<FileEntry>(new FileEntry("/path/to/file",totalLength,0))
|
2009-06-28 10:37:15 +00:00
|
|
|
};
|
2010-06-21 13:51:56 +00:00
|
|
|
dctx_->setFileEntries(vbegin(fileEntries), vend(fileEntries));
|
|
|
|
dctx_->setPieceLength(pieceLength);
|
|
|
|
peerStorage_.reset(new MockPeerStorage());
|
|
|
|
btRuntime_.reset(new BtRuntime());
|
2008-05-20 00:42:34 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
|
2008-11-13 15:08:52 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
void testSave();
|
2007-10-11 16:58:24 +00:00
|
|
|
void testLoad();
|
2009-02-06 16:49:24 +00:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
2008-08-24 09:43:45 +00:00
|
|
|
void testLoad_compat();
|
2009-02-06 16:49:24 +00:00
|
|
|
#endif // !WORDS_BIGENDIAN
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2007-10-11 16:58:24 +00:00
|
|
|
void testSave_nonBt();
|
|
|
|
void testLoad_nonBt();
|
2009-02-06 16:49:24 +00:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
2008-08-24 09:43:45 +00:00
|
|
|
void testLoad_nonBt_compat();
|
2009-02-06 16:49:24 +00:00
|
|
|
#endif // !WORDS_BIGENDIAN
|
2007-11-13 10:10:11 +00:00
|
|
|
void testLoad_nonBt_pieceLengthShorter();
|
2008-05-05 10:10:15 +00:00
|
|
|
void testUpdateFilename();
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
};
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
#undef BLOCK_LENGTH
|
|
|
|
#define BLOCK_LENGTH 256
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtProgressInfoFileTest);
|
|
|
|
|
2008-05-20 00:42:34 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
|
|
|
|
2008-11-18 11:28:04 +00:00
|
|
|
// Because load.aria2 is made for little endian systems, exclude
|
|
|
|
// testLoad_compat() for big endian systems.
|
|
|
|
#ifndef WORDS_BIGENDIAN
|
2008-08-24 09:43:45 +00:00
|
|
|
void DefaultBtProgressInfoFileTest::testLoad_compat()
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2007-11-13 10:10:11 +00:00
|
|
|
initializeMembers(1024, 81920);
|
2010-12-02 13:38:36 +00:00
|
|
|
dctx_->setBasePath(A2_TEST_DIR"/load");
|
2007-11-13 10:10:11 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
DefaultBtProgressInfoFile infoFile(dctx_, pieceStorage_, option_.get());
|
|
|
|
infoFile.setBtRuntime(btRuntime_);
|
|
|
|
infoFile.setPeerStorage(peerStorage_);
|
2008-11-03 06:49:02 +00:00
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(A2_TEST_DIR"/load.aria2"),
|
|
|
|
infoFile.getFilename());
|
2007-09-01 16:10:30 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
infoFile.load();
|
2007-09-01 16:10:30 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
// check the contents of objects
|
2007-09-01 16:10:30 +00:00
|
|
|
|
2008-08-24 09:43:45 +00:00
|
|
|
// total length
|
2012-06-25 14:35:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)81920, dctx_->getTotalLength());
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
// upload length
|
2012-06-25 14:35:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)1024, btRuntime_->getUploadLengthAtStartup());
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
// bitfield
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
|
2010-06-21 13:51:56 +00:00
|
|
|
util::toHex(bitfield_->getBitfield(),
|
|
|
|
bitfield_->getBitfieldLength()));
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
// the number of in-flight pieces
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2,
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->countInFlightPiece());
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
// piece index 1
|
2013-06-21 16:10:38 +00:00
|
|
|
std::vector<std::shared_ptr<Piece> > inFlightPieces;
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->getInFlightPieces(inFlightPieces);
|
2008-08-24 09:43:45 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> piece1 = inFlightPieces[0];
|
2008-08-24 09:43:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
|
2011-12-07 15:03:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1024, piece1->getLength());
|
2008-08-24 09:43:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(),
|
2010-01-05 16:01:46 +00:00
|
|
|
piece1->getBitfieldLength()));
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
// piece index 2
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> piece2 = inFlightPieces[1];
|
2008-08-24 09:43:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
2011-12-07 15:03:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(512, piece2->getLength());
|
2008-08-24 09:43:45 +00:00
|
|
|
}
|
2008-11-18 11:28:04 +00:00
|
|
|
#endif // !WORDS_BIGENDIAN
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
void DefaultBtProgressInfoFileTest::testLoad()
|
|
|
|
{
|
|
|
|
initializeMembers(1024, 81920);
|
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
dctx_->setBasePath(A2_TEST_DIR"/load-v0001");
|
2008-08-24 09:43:45 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
DefaultBtProgressInfoFile infoFile(dctx_, pieceStorage_, option_.get());
|
2010-12-02 13:38:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(A2_TEST_DIR"/load-v0001.aria2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
infoFile.getFilename());
|
2010-06-21 13:51:56 +00:00
|
|
|
infoFile.setBtRuntime(btRuntime_);
|
|
|
|
infoFile.setPeerStorage(peerStorage_);
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
infoFile.load();
|
|
|
|
|
|
|
|
// check the contents of objects
|
|
|
|
|
|
|
|
// total length
|
2012-06-25 14:35:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)81920, dctx_->getTotalLength());
|
2008-08-24 09:43:45 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
// upload length
|
2012-06-25 14:35:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)1024, btRuntime_->getUploadLengthAtStartup());
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
// bitfield
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
|
2010-06-21 13:51:56 +00:00
|
|
|
util::toHex(bitfield_->getBitfield(),
|
|
|
|
bitfield_->getBitfieldLength()));
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
// the number of in-flight pieces
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2,
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->countInFlightPiece());
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
// piece index 1
|
2013-06-21 16:10:38 +00:00
|
|
|
std::vector<std::shared_ptr<Piece> > inFlightPieces;
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->getInFlightPieces(inFlightPieces);
|
2008-05-11 14:42:34 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> piece1 = inFlightPieces[0];
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
|
2011-12-07 15:03:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1024, piece1->getLength());
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(),
|
2010-01-05 16:01:46 +00:00
|
|
|
piece1->getBitfieldLength()));
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
// piece index 2
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> piece2 = inFlightPieces[1];
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
2011-12-07 15:03:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(512, piece2->getLength());
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
|
2008-05-20 00:42:34 +00:00
|
|
|
void DefaultBtProgressInfoFileTest::testSave()
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2007-11-13 10:10:11 +00:00
|
|
|
initializeMembers(1024, 81920);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
dctx_->setBasePath(A2_TEST_OUT_DIR"/save-temp");
|
2012-10-25 14:33:45 +00:00
|
|
|
dctx_->getNetStat().updateUploadLength(768);
|
|
|
|
btRuntime_->setUploadLengthAtStartup(256);
|
2010-06-21 13:51:56 +00:00
|
|
|
bitfield_->setAllBit();
|
|
|
|
bitfield_->unsetBit(79);
|
|
|
|
pieceStorage_->setCompletedLength(80896);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> p1(new Piece(1, 1024));
|
|
|
|
std::shared_ptr<Piece> p2(new Piece(2, 512));
|
|
|
|
std::vector<std::shared_ptr<Piece> > inFlightPieces;
|
2007-10-11 16:58:24 +00:00
|
|
|
inFlightPieces.push_back(p1);
|
|
|
|
inFlightPieces.push_back(p2);
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->addInFlightPiece(inFlightPieces);
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
DefaultBtProgressInfoFile infoFile(dctx_, pieceStorage_, option_.get());
|
|
|
|
infoFile.setBtRuntime(btRuntime_);
|
|
|
|
infoFile.setPeerStorage(peerStorage_);
|
2008-11-03 06:49:02 +00:00
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(A2_TEST_OUT_DIR"/save-temp.aria2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
infoFile.getFilename());
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
infoFile.save();
|
2008-05-20 00:42:34 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
// read and validate
|
2009-02-13 11:28:42 +00:00
|
|
|
std::ifstream in(infoFile.getFilename().c_str(), std::ios::binary);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
//in.exceptions(ios::failbit);
|
2007-09-01 16:10:30 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
unsigned char version[2];
|
|
|
|
in.read((char*)version, sizeof(version));
|
2008-08-24 09:43:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0001"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::toHex(version, sizeof(version)));
|
2007-09-01 16:10:30 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
unsigned char extension[4];
|
|
|
|
in.read((char*)extension, sizeof(extension));
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("00000001"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::toHex(extension, sizeof(extension)));
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t infoHashLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
|
2008-08-24 09:43:45 +00:00
|
|
|
infoHashLength = ntohl(infoHashLength);
|
2008-05-20 00:42:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)20, infoHashLength);
|
|
|
|
|
|
|
|
unsigned char infoHashRead[20];
|
|
|
|
in.read((char*)infoHashRead, sizeof(infoHashRead));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("112233445566778899aabbccddeeff00ffffffff"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::toHex(infoHashRead, sizeof(infoHashRead)));
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t pieceLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&pieceLength, sizeof(pieceLength));
|
2008-08-24 09:43:45 +00:00
|
|
|
pieceLength = ntohl(pieceLength);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength);
|
2008-05-20 00:42:34 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint64_t totalLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&totalLength, sizeof(totalLength));
|
2008-08-24 09:43:45 +00:00
|
|
|
totalLength = ntoh64(totalLength);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint64_t uploadLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&uploadLength, sizeof(uploadLength));
|
2008-08-24 09:43:45 +00:00
|
|
|
uploadLength = ntoh64(uploadLength);
|
2008-05-20 00:42:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)1024, uploadLength);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t bitfieldLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&bitfieldLength, sizeof(bitfieldLength));
|
2008-08-24 09:43:45 +00:00
|
|
|
bitfieldLength = ntohl(bitfieldLength);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)10, bitfieldLength);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
unsigned char bitfieldRead[10];
|
|
|
|
in.read((char*)bitfieldRead, sizeof(bitfieldRead));
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::toHex(bitfieldRead, sizeof(bitfieldRead)));
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t numInFlightPiece;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&numInFlightPiece, sizeof(numInFlightPiece));
|
2008-08-24 09:43:45 +00:00
|
|
|
numInFlightPiece = ntohl(numInFlightPiece);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)2, numInFlightPiece);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
// piece index 1
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t index1;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&index1, sizeof(index1));
|
2008-08-24 09:43:45 +00:00
|
|
|
index1 = ntohl(index1);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)1, index1);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t pieceLength1;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&pieceLength1, sizeof(pieceLength1));
|
2008-08-24 09:43:45 +00:00
|
|
|
pieceLength1 = ntohl(pieceLength1);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength1);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t pieceBitfieldLength1;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&pieceBitfieldLength1, sizeof(pieceBitfieldLength1));
|
2008-08-24 09:43:45 +00:00
|
|
|
pieceBitfieldLength1 = ntohl(pieceBitfieldLength1);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)1, pieceBitfieldLength1);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
unsigned char pieceBitfield1[1];
|
|
|
|
in.read((char*)pieceBitfield1, sizeof(pieceBitfield1));
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("00"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::toHex(pieceBitfield1, sizeof(pieceBitfield1)));
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
// piece index 2
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t index2;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&index2, sizeof(index2));
|
2008-08-24 09:43:45 +00:00
|
|
|
index2 = ntohl(index2);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)2, index2);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t pieceLength2;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&pieceLength2, sizeof(pieceLength2));
|
2008-08-24 09:43:45 +00:00
|
|
|
pieceLength2 = ntohl(pieceLength2);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)512, pieceLength2);
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
|
2008-05-20 00:42:34 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
|
|
|
|
2008-11-18 11:28:04 +00:00
|
|
|
// Because load-nonBt.aria2 is made for little endian systems, exclude
|
|
|
|
// testLoad_nonBt_compat() for big endian systems.
|
|
|
|
#ifndef WORDS_BIGENDIAN
|
2008-08-24 09:43:45 +00:00
|
|
|
void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat()
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2007-11-13 10:10:11 +00:00
|
|
|
initializeMembers(1024, 81920);
|
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> dctx
|
2010-12-02 13:38:36 +00:00
|
|
|
(new DownloadContext(1024, 81920, A2_TEST_DIR"/load-nonBt"));
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
DefaultBtProgressInfoFile infoFile(dctx, pieceStorage_, option_.get());
|
2008-11-03 06:49:02 +00:00
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(A2_TEST_DIR"/load-nonBt.aria2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
infoFile.getFilename());
|
2008-05-20 00:42:34 +00:00
|
|
|
infoFile.load();
|
|
|
|
|
|
|
|
// check the contents of objects
|
|
|
|
|
2008-08-24 09:43:45 +00:00
|
|
|
// total length
|
2012-06-25 14:35:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)81920, dctx->getTotalLength());
|
2008-08-24 09:43:45 +00:00
|
|
|
|
2008-05-20 00:42:34 +00:00
|
|
|
// bitfield
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
|
2010-06-21 13:51:56 +00:00
|
|
|
util::toHex(bitfield_->getBitfield(),
|
|
|
|
bitfield_->getBitfieldLength()));
|
2008-05-20 00:42:34 +00:00
|
|
|
|
|
|
|
// the number of in-flight pieces
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2,
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->countInFlightPiece());
|
2008-05-20 00:42:34 +00:00
|
|
|
|
|
|
|
// piece index 1
|
2013-06-21 16:10:38 +00:00
|
|
|
std::vector<std::shared_ptr<Piece> > inFlightPieces;
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->getInFlightPieces(inFlightPieces);
|
2008-05-20 00:42:34 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> piece1 = inFlightPieces[0];
|
2008-05-20 00:42:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
|
2011-12-07 15:03:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1024, piece1->getLength());
|
2008-05-20 00:42:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(),
|
2010-01-05 16:01:46 +00:00
|
|
|
piece1->getBitfieldLength()));
|
2008-05-20 00:42:34 +00:00
|
|
|
|
|
|
|
// piece index 2
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> piece2 = inFlightPieces[1];
|
2008-05-20 00:42:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
2011-12-07 15:03:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(512, piece2->getLength());
|
2008-08-24 09:43:45 +00:00
|
|
|
}
|
2008-11-18 11:28:04 +00:00
|
|
|
#endif // !WORDS_BIGENDIAN
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
void DefaultBtProgressInfoFileTest::testLoad_nonBt()
|
|
|
|
{
|
|
|
|
initializeMembers(1024, 81920);
|
2008-05-20 00:42:34 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> dctx
|
2010-12-02 13:38:36 +00:00
|
|
|
(new DownloadContext(1024, 81920, A2_TEST_DIR"/load-nonBt-v0001"));
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
DefaultBtProgressInfoFile infoFile(dctx, pieceStorage_, option_.get());
|
2008-11-13 15:08:52 +00:00
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(A2_TEST_DIR"/load-nonBt-v0001.aria2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
infoFile.getFilename());
|
2008-08-24 09:43:45 +00:00
|
|
|
infoFile.load();
|
|
|
|
|
|
|
|
// check the contents of objects
|
|
|
|
|
|
|
|
// total length
|
2012-06-25 14:35:24 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)81920, dctx->getTotalLength());
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
// bitfield
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
|
2010-06-21 13:51:56 +00:00
|
|
|
util::toHex(bitfield_->getBitfield(),
|
|
|
|
bitfield_->getBitfieldLength()));
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
// the number of in-flight pieces
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2,
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->countInFlightPiece());
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
// piece index 1
|
2013-06-21 16:10:38 +00:00
|
|
|
std::vector<std::shared_ptr<Piece> > inFlightPieces;
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->getInFlightPieces(inFlightPieces);
|
2008-08-24 09:43:45 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> piece1 = inFlightPieces[0];
|
2008-08-24 09:43:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
|
2011-12-07 15:03:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1024, piece1->getLength());
|
2008-08-24 09:43:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
|
2009-10-22 15:09:00 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(),
|
2010-01-05 16:01:46 +00:00
|
|
|
piece1->getBitfieldLength()));
|
2008-08-24 09:43:45 +00:00
|
|
|
|
|
|
|
// piece index 2
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> piece2 = inFlightPieces[1];
|
2008-08-24 09:43:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
2011-12-07 15:03:25 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(512, piece2->getLength());
|
2008-05-20 00:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter()
|
|
|
|
{
|
|
|
|
initializeMembers(512, 81920);
|
2010-09-11 12:48:03 +00:00
|
|
|
option_->put(PREF_ALLOW_PIECE_LENGTH_CHANGE, A2_V_TRUE);
|
2008-05-20 00:42:34 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> dctx
|
2010-12-02 13:38:36 +00:00
|
|
|
(new DownloadContext(512, 81920, A2_TEST_DIR"/load-nonBt-v0001"));
|
2008-05-20 00:42:34 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
DefaultBtProgressInfoFile infoFile(dctx, pieceStorage_, option_.get());
|
2008-11-03 06:49:02 +00:00
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(A2_TEST_DIR"/load-nonBt-v0001.aria2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
infoFile.getFilename());
|
2008-05-20 00:42:34 +00:00
|
|
|
infoFile.load();
|
|
|
|
|
|
|
|
// check the contents of objects
|
|
|
|
|
|
|
|
// bitfield
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffffffffffffffffffffffc"),
|
2010-06-21 13:51:56 +00:00
|
|
|
util::toHex(bitfield_->getBitfield(),
|
|
|
|
bitfield_->getBitfieldLength()));
|
2008-05-20 00:42:34 +00:00
|
|
|
|
|
|
|
// the number of in-flight pieces
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0,
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->countInFlightPiece());
|
2008-05-20 00:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtProgressInfoFileTest::testSave_nonBt()
|
|
|
|
{
|
|
|
|
initializeMembers(1024, 81920);
|
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> dctx
|
2010-12-02 13:38:36 +00:00
|
|
|
(new DownloadContext(1024, 81920, A2_TEST_OUT_DIR"/save-temp"));
|
2008-05-20 00:42:34 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
bitfield_->setAllBit();
|
|
|
|
bitfield_->unsetBit(79);
|
|
|
|
pieceStorage_->setCompletedLength(80896);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Piece> p1(new Piece(1, 1024));
|
|
|
|
std::shared_ptr<Piece> p2(new Piece(2, 512));
|
|
|
|
std::vector<std::shared_ptr<Piece> > inFlightPieces;
|
2007-10-11 16:58:24 +00:00
|
|
|
inFlightPieces.push_back(p1);
|
|
|
|
inFlightPieces.push_back(p2);
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_->addInFlightPiece(inFlightPieces);
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
DefaultBtProgressInfoFile infoFile(dctx, pieceStorage_, option_.get());
|
2008-11-03 06:49:02 +00:00
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(A2_TEST_OUT_DIR"/save-temp.aria2"),
|
2010-01-05 16:01:46 +00:00
|
|
|
infoFile.getFilename());
|
2007-09-01 16:10:30 +00:00
|
|
|
|
|
|
|
infoFile.save();
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2007-09-01 16:10:30 +00:00
|
|
|
// read and validate
|
2009-02-13 11:28:42 +00:00
|
|
|
std::ifstream in(infoFile.getFilename().c_str(), std::ios::binary);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
//in.exceptions(ios::failbit);
|
|
|
|
|
|
|
|
unsigned char version[2];
|
|
|
|
in.read((char*)version, sizeof(version));
|
2008-08-24 09:43:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0001"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::toHex(version, sizeof(version)));
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
unsigned char extension[4];
|
|
|
|
in.read((char*)extension, sizeof(extension));
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("00000000"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::toHex(extension, sizeof(extension)));
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t infoHashLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
|
2008-08-24 09:43:45 +00:00
|
|
|
infoHashLength = ntohl(infoHashLength);
|
2008-05-20 00:42:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)0, infoHashLength);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t pieceLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&pieceLength, sizeof(pieceLength));
|
2008-08-24 09:43:45 +00:00
|
|
|
pieceLength = ntohl(pieceLength);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength);
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint64_t totalLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&totalLength, sizeof(totalLength));
|
2008-08-24 09:43:45 +00:00
|
|
|
totalLength = ntoh64(totalLength);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint64_t uploadLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&uploadLength, sizeof(uploadLength));
|
2008-08-24 09:43:45 +00:00
|
|
|
uploadLength = ntoh64(uploadLength);
|
2008-05-20 00:42:34 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint64_t)0, uploadLength);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t bitfieldLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&bitfieldLength, sizeof(bitfieldLength));
|
2008-08-24 09:43:45 +00:00
|
|
|
bitfieldLength = ntohl(bitfieldLength);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)10, bitfieldLength);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2007-09-01 16:10:30 +00:00
|
|
|
unsigned char bitfieldRead[10];
|
|
|
|
in.read((char*)bitfieldRead, sizeof(bitfieldRead));
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::toHex(bitfieldRead, sizeof(bitfieldRead)));
|
2007-09-01 16:10:30 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t numInFlightPiece;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&numInFlightPiece, sizeof(numInFlightPiece));
|
2008-08-24 09:43:45 +00:00
|
|
|
numInFlightPiece = ntohl(numInFlightPiece);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)2, numInFlightPiece);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
// piece index 1
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t index1;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&index1, sizeof(index1));
|
2008-08-24 09:43:45 +00:00
|
|
|
index1 = ntohl(index1);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)1, index1);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t pieceLength1;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&pieceLength1, sizeof(pieceLength1));
|
2008-08-24 09:43:45 +00:00
|
|
|
pieceLength1 = ntohl(pieceLength1);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength1);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t pieceBitfieldLength1;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&pieceBitfieldLength1, sizeof(pieceBitfieldLength1));
|
2008-08-24 09:43:45 +00:00
|
|
|
pieceBitfieldLength1 = ntohl(pieceBitfieldLength1);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)1, pieceBitfieldLength1);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
unsigned char pieceBitfield1[1];
|
|
|
|
in.read((char*)pieceBitfield1, sizeof(pieceBitfield1));
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("00"),
|
2010-01-05 16:01:46 +00:00
|
|
|
util::toHex(pieceBitfield1, sizeof(pieceBitfield1)));
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
// piece index 2
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t index2;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&index2, sizeof(index2));
|
2008-08-24 09:43:45 +00:00
|
|
|
index2 = ntohl(index2);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)2, index2);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
uint32_t pieceLength2;
|
2007-10-11 16:58:24 +00:00
|
|
|
in.read((char*)&pieceLength2, sizeof(pieceLength2));
|
2008-08-24 09:43:45 +00:00
|
|
|
pieceLength2 = ntohl(pieceLength2);
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint32_t)512, pieceLength2);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-05-05 10:10:15 +00:00
|
|
|
void DefaultBtProgressInfoFileTest::testUpdateFilename()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> dctx
|
2010-12-02 13:38:36 +00:00
|
|
|
(new DownloadContext(1024, 81920, A2_TEST_DIR"/file1"));
|
2008-05-05 10:10:15 +00:00
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
DefaultBtProgressInfoFile infoFile(dctx, std::shared_ptr<MockPieceStorage>(), 0);
|
2008-11-13 15:08:52 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2010-06-21 13:51:56 +00:00
|
|
|
infoFile.setBtRuntime(btRuntime_);
|
|
|
|
infoFile.setPeerStorage(peerStorage_);
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2008-11-03 06:49:02 +00:00
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(A2_TEST_DIR"/file1.aria2"),
|
|
|
|
infoFile.getFilename());
|
2008-05-05 10:10:15 +00:00
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
dctx->getFirstFileEntry()->setPath(A2_TEST_DIR"/file1.1");
|
2008-05-05 10:10:15 +00:00
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(A2_TEST_DIR"/file1.aria2"),
|
|
|
|
infoFile.getFilename());
|
2008-05-05 10:10:15 +00:00
|
|
|
|
|
|
|
infoFile.updateFilename();
|
|
|
|
|
2010-12-02 13:38:36 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(A2_TEST_DIR"/file1.1.aria2"),
|
|
|
|
infoFile.getFilename());
|
2008-05-05 10:10:15 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|