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
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
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
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "FileEntry.h"
|
2009-06-23 15:35:45 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
2009-06-29 08:42:58 +00:00
|
|
|
#include <algorithm>
|
2009-06-23 15:35:45 +00:00
|
|
|
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2009-06-23 15:35:45 +00:00
|
|
|
#include "URISelector.h"
|
2009-06-29 08:42:58 +00:00
|
|
|
#include "LogFactory.h"
|
2010-03-06 08:29:53 +00:00
|
|
|
#include "wallclock.h"
|
2010-07-15 13:49:02 +00:00
|
|
|
#include "a2algo.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
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
FileEntry::FileEntry(const std::string& path,
|
2010-01-05 16:01:46 +00:00
|
|
|
uint64_t length,
|
|
|
|
off_t offset,
|
2010-02-28 12:30:11 +00:00
|
|
|
const std::vector<std::string>& uris):
|
2010-06-21 13:51:56 +00:00
|
|
|
path_(path), uris_(uris.begin(), uris.end()), length_(length),
|
|
|
|
offset_(offset),
|
|
|
|
requested_(true),
|
2010-07-14 11:39:05 +00:00
|
|
|
uniqueProtocol_(false),
|
|
|
|
maxConnectionPerServer_(1),
|
2010-07-11 14:17:05 +00:00
|
|
|
lastFasterReplace_(0),
|
2010-06-21 13:51:56 +00:00
|
|
|
logger_(LogFactory::getInstance()) {}
|
2009-06-29 08:42:58 +00:00
|
|
|
|
|
|
|
FileEntry::FileEntry():
|
2010-06-21 13:51:56 +00:00
|
|
|
length_(0), offset_(0), requested_(false),
|
2010-07-14 11:39:05 +00:00
|
|
|
uniqueProtocol_(false),
|
|
|
|
maxConnectionPerServer_(1),
|
2010-06-21 13:51:56 +00:00
|
|
|
logger_(LogFactory::getInstance()) {}
|
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
|
|
|
|
|
|
|
FileEntry::~FileEntry() {}
|
|
|
|
|
2009-03-09 15:10:26 +00:00
|
|
|
void FileEntry::setupDir()
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
util::mkdirs(File(path_).getDirname());
|
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
|
|
|
|
|
|
|
FileEntry& FileEntry::operator=(const FileEntry& entry)
|
|
|
|
{
|
|
|
|
if(this != &entry) {
|
2010-06-21 13:51:56 +00:00
|
|
|
path_ = entry.path_;
|
|
|
|
length_ = entry.length_;
|
|
|
|
offset_ = entry.offset_;
|
|
|
|
requested_ = entry.requested_;
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2007-11-21 16:14:40 +00:00
|
|
|
|
|
|
|
bool FileEntry::operator<(const FileEntry& fileEntry) const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return offset_ < fileEntry.offset_;
|
2007-11-21 16:14:40 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2009-03-11 15:37:40 +00:00
|
|
|
bool FileEntry::exists() const
|
|
|
|
{
|
|
|
|
return File(getPath()).exists();
|
|
|
|
}
|
|
|
|
|
2009-06-23 15:35:45 +00:00
|
|
|
off_t FileEntry::gtoloff(off_t goff) const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
assert(offset_ <= goff);
|
|
|
|
return goff-offset_;
|
2009-06-23 15:35:45 +00:00
|
|
|
}
|
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
void FileEntry::getUris(std::vector<std::string>& uris) const
|
2009-06-23 15:35:45 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
uris.insert(uris.end(), spentUris_.begin(), spentUris_.end());
|
|
|
|
uris.insert(uris.end(), uris_.begin(), uris_.end());
|
2009-06-23 15:35:45 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 14:02:24 +00:00
|
|
|
template<typename InputIterator, typename OutputIterator>
|
|
|
|
static OutputIterator
|
|
|
|
enumerateInFlightHosts
|
|
|
|
(InputIterator first, InputIterator last, OutputIterator out)
|
2009-06-29 16:43:41 +00:00
|
|
|
{
|
2010-07-31 14:02:24 +00:00
|
|
|
Request r;
|
2009-06-29 16:43:41 +00:00
|
|
|
for(; first != last; ++first) {
|
2010-07-31 14:02:24 +00:00
|
|
|
r.setUri((*first)->getUri());
|
|
|
|
*out++ = r.getHost();
|
2009-06-29 16:43:41 +00:00
|
|
|
}
|
2010-07-31 14:02:24 +00:00
|
|
|
return out;
|
2009-06-29 16:43:41 +00:00
|
|
|
}
|
|
|
|
|
2009-06-23 15:35:45 +00:00
|
|
|
SharedHandle<Request>
|
2009-07-01 14:11:04 +00:00
|
|
|
FileEntry::getRequest
|
|
|
|
(const SharedHandle<URISelector>& selector,
|
2010-07-14 11:39:05 +00:00
|
|
|
bool uriReuse,
|
2010-07-15 13:49:02 +00:00
|
|
|
const std::vector<std::pair<size_t, std::string> >& usedHosts,
|
2009-07-01 14:11:04 +00:00
|
|
|
const std::string& referer,
|
|
|
|
const std::string& method)
|
2009-06-23 15:35:45 +00:00
|
|
|
{
|
|
|
|
SharedHandle<Request> req;
|
2010-08-31 11:17:38 +00:00
|
|
|
if(requestPool_.empty()) {
|
|
|
|
std::vector<std::string> inFlightHosts;
|
|
|
|
enumerateInFlightHosts(inFlightRequests_.begin(), inFlightRequests_.end(),
|
|
|
|
std::back_inserter(inFlightHosts));
|
|
|
|
for(int g = 0; g < 2; ++g) {
|
|
|
|
std::vector<std::string> pending;
|
|
|
|
std::vector<std::string> ignoreHost;
|
|
|
|
while(1) {
|
|
|
|
std::string uri = selector->select(this, usedHosts);
|
|
|
|
if(uri.empty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
req.reset(new Request());
|
|
|
|
if(req->setUri(uri)) {
|
|
|
|
if(std::count(inFlightHosts.begin(),
|
|
|
|
inFlightHosts.end(),req->getHost())
|
|
|
|
>= static_cast<int>(maxConnectionPerServer_)) {
|
|
|
|
pending.push_back(uri);
|
|
|
|
ignoreHost.push_back(req->getHost());
|
|
|
|
req.reset();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
req->setReferer(referer);
|
|
|
|
req->setMethod(method);
|
|
|
|
spentUris_.push_back(uri);
|
|
|
|
inFlightRequests_.push_back(req);
|
|
|
|
break;
|
|
|
|
} else {
|
2010-07-14 11:39:05 +00:00
|
|
|
req.reset();
|
2010-01-05 16:01:46 +00:00
|
|
|
}
|
2010-08-31 11:17:38 +00:00
|
|
|
}
|
|
|
|
uris_.insert(uris_.begin(), pending.begin(), pending.end());
|
|
|
|
if(g == 0 && uriReuse && req.isNull() && uris_.size() == pending.size()) {
|
|
|
|
// Reuse URIs other than ones in pending
|
|
|
|
reuseUri(ignoreHost);
|
2010-07-14 14:10:33 +00:00
|
|
|
} else {
|
2010-08-31 11:17:38 +00:00
|
|
|
break;
|
2010-07-14 14:10:33 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-31 11:17:38 +00:00
|
|
|
} else {
|
|
|
|
req = requestPool_.front();
|
|
|
|
requestPool_.pop_front();
|
|
|
|
inFlightRequests_.push_back(req);
|
|
|
|
if(logger_->debug()) {
|
|
|
|
logger_->debug("Picked up from pool: %s", req->getUri().c_str());
|
2009-06-23 15:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-29 16:43:41 +00:00
|
|
|
return req;
|
2009-06-23 15:35:45 +00:00
|
|
|
}
|
|
|
|
|
2009-06-29 15:18:21 +00:00
|
|
|
SharedHandle<Request>
|
|
|
|
FileEntry::findFasterRequest(const SharedHandle<Request>& base)
|
|
|
|
{
|
2010-07-11 14:17:05 +00:00
|
|
|
const int startupIdleTime = 10;
|
|
|
|
if(requestPool_.empty() ||
|
|
|
|
lastFasterReplace_.difference(global::wallclock) < startupIdleTime) {
|
2009-06-29 15:18:21 +00:00
|
|
|
return SharedHandle<Request>();
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
const SharedHandle<PeerStat>& fastest = requestPool_.front()->getPeerStat();
|
2009-06-29 15:18:21 +00:00
|
|
|
if(fastest.isNull()) {
|
|
|
|
return SharedHandle<Request>();
|
|
|
|
}
|
|
|
|
const SharedHandle<PeerStat>& basestat = base->getPeerStat();
|
2009-07-11 15:57:06 +00:00
|
|
|
// TODO hard coded value. See PREF_STARTUP_IDLE_TIME
|
2009-06-29 15:18:21 +00:00
|
|
|
if(basestat.isNull() ||
|
2010-03-06 08:29:53 +00:00
|
|
|
(basestat->getDownloadStartTime().
|
|
|
|
difference(global::wallclock) >= startupIdleTime &&
|
2009-06-29 15:18:21 +00:00
|
|
|
fastest->getAvgDownloadSpeed()*0.8 > basestat->calculateDownloadSpeed())){
|
2009-07-11 15:57:06 +00:00
|
|
|
// TODO we should consider that "fastest" is very slow.
|
2010-06-21 13:51:56 +00:00
|
|
|
SharedHandle<Request> fastestRequest = requestPool_.front();
|
|
|
|
requestPool_.pop_front();
|
|
|
|
inFlightRequests_.push_back(fastestRequest);
|
2010-07-11 14:17:05 +00:00
|
|
|
lastFasterReplace_.reset();
|
2009-06-29 15:18:21 +00:00
|
|
|
return fastestRequest;
|
|
|
|
}
|
|
|
|
return SharedHandle<Request>();
|
|
|
|
}
|
|
|
|
|
|
|
|
class RequestFaster {
|
|
|
|
public:
|
|
|
|
bool operator()(const SharedHandle<Request>& lhs,
|
2010-01-05 16:01:46 +00:00
|
|
|
const SharedHandle<Request>& rhs) const
|
2009-06-29 15:18:21 +00:00
|
|
|
{
|
|
|
|
if(lhs->getPeerStat().isNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(rhs->getPeerStat().isNull()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return
|
|
|
|
lhs->getPeerStat()->getAvgDownloadSpeed() > rhs->getPeerStat()->getAvgDownloadSpeed();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void FileEntry::storePool(const SharedHandle<Request>& request)
|
|
|
|
{
|
|
|
|
const SharedHandle<PeerStat>& peerStat = request->getPeerStat();
|
|
|
|
if(!peerStat.isNull()) {
|
|
|
|
// We need to calculate average download speed here in order to
|
|
|
|
// store Request in the right position in the pool.
|
|
|
|
peerStat->calculateAvgDownloadSpeed();
|
|
|
|
}
|
|
|
|
std::deque<SharedHandle<Request> >::iterator i =
|
2010-06-21 13:51:56 +00:00
|
|
|
std::lower_bound(requestPool_.begin(), requestPool_.end(), request,
|
2010-01-05 16:01:46 +00:00
|
|
|
RequestFaster());
|
2010-06-21 13:51:56 +00:00
|
|
|
requestPool_.insert(i, request);
|
2009-06-29 15:18:21 +00:00
|
|
|
}
|
|
|
|
|
2009-06-23 15:35:45 +00:00
|
|
|
void FileEntry::poolRequest(const SharedHandle<Request>& request)
|
|
|
|
{
|
|
|
|
removeRequest(request);
|
2010-03-06 14:21:43 +00:00
|
|
|
if(!request->removalRequested()) {
|
|
|
|
storePool(request);
|
|
|
|
}
|
2009-06-23 15:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileEntry::removeRequest(const SharedHandle<Request>& request)
|
|
|
|
{
|
|
|
|
for(std::deque<SharedHandle<Request> >::iterator i =
|
2010-06-21 13:51:56 +00:00
|
|
|
inFlightRequests_.begin(), eoi = inFlightRequests_.end();
|
2010-02-28 16:04:52 +00:00
|
|
|
i != eoi; ++i) {
|
2009-06-23 15:35:45 +00:00
|
|
|
if((*i).get() == request.get()) {
|
2010-06-21 13:51:56 +00:00
|
|
|
inFlightRequests_.erase(i);
|
2009-06-23 15:35:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-29 08:42:58 +00:00
|
|
|
void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
|
|
|
|
{
|
|
|
|
std::deque<std::string> newURIs;
|
|
|
|
Request req;
|
2010-06-21 13:51:56 +00:00
|
|
|
for(std::deque<std::string>::const_iterator itr = uris_.begin(),
|
|
|
|
eoi = uris_.end(); itr != eoi; ++itr) {
|
2009-06-29 08:42:58 +00:00
|
|
|
if(((*itr).find(hostname) == std::string::npos) ||
|
2010-03-07 10:36:42 +00:00
|
|
|
(req.setUri(*itr) && (req.getHost() != hostname))) {
|
2009-06-29 08:42:58 +00:00
|
|
|
newURIs.push_back(*itr);
|
|
|
|
}
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(logger_->debug()) {
|
|
|
|
logger_->debug("Removed %d duplicate hostname URIs for path=%s",
|
|
|
|
uris_.size()-newURIs.size(), getPath().c_str());
|
2010-02-09 12:20:20 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
uris_ = newURIs;
|
2009-06-29 08:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileEntry::removeIdenticalURI(const std::string& uri)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
uris_.erase(std::remove(uris_.begin(), uris_.end(), uri), uris_.end());
|
2009-06-29 08:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileEntry::addURIResult(std::string uri, downloadresultcode::RESULT result)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
uriResults_.push_back(URIResult(uri, result));
|
2009-06-29 08:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class FindURIResultByResult {
|
|
|
|
private:
|
2010-06-21 13:51:56 +00:00
|
|
|
downloadresultcode::RESULT r_;
|
2009-06-29 08:42:58 +00:00
|
|
|
public:
|
2010-06-21 13:51:56 +00:00
|
|
|
FindURIResultByResult(downloadresultcode::RESULT r):r_(r) {}
|
2009-06-29 08:42:58 +00:00
|
|
|
|
|
|
|
bool operator()(const URIResult& uriResult) const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return uriResult.getResult() == r_;
|
2009-06-29 08:42:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void FileEntry::extractURIResult
|
|
|
|
(std::deque<URIResult>& res, downloadresultcode::RESULT r)
|
|
|
|
{
|
|
|
|
std::deque<URIResult>::iterator i =
|
2010-06-21 13:51:56 +00:00
|
|
|
std::stable_partition(uriResults_.begin(), uriResults_.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
FindURIResultByResult(r));
|
2010-06-21 13:51:56 +00:00
|
|
|
std::copy(uriResults_.begin(), i, std::back_inserter(res));
|
|
|
|
uriResults_.erase(uriResults_.begin(), i);
|
2009-06-29 08:42:58 +00:00
|
|
|
}
|
|
|
|
|
2010-07-14 11:39:05 +00:00
|
|
|
void FileEntry::reuseUri(const std::vector<std::string>& ignore)
|
2009-07-04 13:36:56 +00:00
|
|
|
{
|
2010-07-14 11:39:05 +00:00
|
|
|
if(logger_->debug()) {
|
|
|
|
for(std::vector<std::string>::const_iterator i = ignore.begin(),
|
|
|
|
eoi = ignore.end(); i != eoi; ++i) {
|
|
|
|
logger_->debug("ignore host=%s", (*i).c_str());
|
|
|
|
}
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
std::deque<std::string> uris = spentUris_;
|
2009-07-04 13:36:56 +00:00
|
|
|
std::sort(uris.begin(), uris.end());
|
|
|
|
uris.erase(std::unique(uris.begin(), uris.end()), uris.end());
|
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
std::vector<std::string> errorUris(uriResults_.size());
|
|
|
|
std::transform(uriResults_.begin(), uriResults_.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
errorUris.begin(), std::mem_fun_ref(&URIResult::getURI));
|
2009-07-04 13:36:56 +00:00
|
|
|
std::sort(errorUris.begin(), errorUris.end());
|
|
|
|
errorUris.erase(std::unique(errorUris.begin(), errorUris.end()),
|
2010-01-05 16:01:46 +00:00
|
|
|
errorUris.end());
|
2010-07-14 11:39:05 +00:00
|
|
|
if(logger_->debug()) {
|
|
|
|
for(std::vector<std::string>::const_iterator i = errorUris.begin(),
|
|
|
|
eoi = errorUris.end(); i != eoi; ++i) {
|
|
|
|
logger_->debug("error URI=%s", (*i).c_str());
|
|
|
|
}
|
|
|
|
}
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> reusableURIs;
|
2009-07-04 13:36:56 +00:00
|
|
|
std::set_difference(uris.begin(), uris.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
errorUris.begin(), errorUris.end(),
|
|
|
|
std::back_inserter(reusableURIs));
|
2010-07-14 11:39:05 +00:00
|
|
|
std::vector<std::string>::iterator insertionPoint = reusableURIs.begin();
|
|
|
|
Request req;
|
|
|
|
for(std::vector<std::string>::iterator i = reusableURIs.begin(),
|
|
|
|
eoi = reusableURIs.end(); i != eoi; ++i) {
|
|
|
|
req.setUri(*i);
|
|
|
|
if(std::find(ignore.begin(), ignore.end(), req.getHost()) == ignore.end()) {
|
|
|
|
if(i != insertionPoint) {
|
|
|
|
*insertionPoint = *i;
|
|
|
|
}
|
|
|
|
++insertionPoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reusableURIs.erase(insertionPoint, reusableURIs.end());
|
2009-07-04 13:36:56 +00:00
|
|
|
size_t ininum = reusableURIs.size();
|
2010-06-21 13:51:56 +00:00
|
|
|
if(logger_->debug()) {
|
|
|
|
logger_->debug("Found %u reusable URIs", static_cast<unsigned int>(ininum));
|
2010-03-08 14:34:32 +00:00
|
|
|
for(std::vector<std::string>::const_iterator i = reusableURIs.begin(),
|
|
|
|
eoi = reusableURIs.end(); i != eoi; ++i) {
|
2010-06-21 13:51:56 +00:00
|
|
|
logger_->debug("URI=%s", (*i).c_str());
|
2010-03-08 14:34:32 +00:00
|
|
|
}
|
2010-02-09 12:20:20 +00:00
|
|
|
}
|
2010-07-14 11:39:05 +00:00
|
|
|
uris_.insert(uris_.end(), reusableURIs.begin(), reusableURIs.end());
|
2009-07-04 13:36:56 +00:00
|
|
|
}
|
|
|
|
|
2009-07-05 09:10:08 +00:00
|
|
|
void FileEntry::releaseRuntimeResource()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
requestPool_.clear();
|
|
|
|
inFlightRequests_.clear();
|
2009-07-05 09:10:08 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 14:21:43 +00:00
|
|
|
template<typename InputIterator, typename T>
|
|
|
|
static InputIterator findRequestByUri
|
|
|
|
(InputIterator first, InputIterator last, const T& uri)
|
|
|
|
{
|
|
|
|
for(; first != last; ++first) {
|
2010-03-07 10:36:42 +00:00
|
|
|
if(!(*first)->removalRequested() && (*first)->getUri() == uri) {
|
2010-03-06 14:21:43 +00:00
|
|
|
return first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileEntry::removeUri(const std::string& uri)
|
|
|
|
{
|
|
|
|
std::deque<std::string>::iterator itr =
|
2010-06-21 13:51:56 +00:00
|
|
|
std::find(spentUris_.begin(), spentUris_.end(), uri);
|
|
|
|
if(itr == spentUris_.end()) {
|
|
|
|
itr = std::find(uris_.begin(), uris_.end(), uri);
|
|
|
|
if(itr == uris_.end()) {
|
2010-03-06 14:21:43 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
uris_.erase(itr);
|
2010-03-06 14:21:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
spentUris_.erase(itr);
|
2010-03-06 14:21:43 +00:00
|
|
|
SharedHandle<Request> req;
|
|
|
|
std::deque<SharedHandle<Request> >::iterator riter =
|
2010-06-21 13:51:56 +00:00
|
|
|
findRequestByUri(inFlightRequests_.begin(), inFlightRequests_.end(), uri);
|
|
|
|
if(riter == inFlightRequests_.end()) {
|
|
|
|
riter = findRequestByUri(requestPool_.begin(), requestPool_.end(), uri);
|
|
|
|
if(riter == requestPool_.end()) {
|
2010-03-06 14:21:43 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
req = *riter;
|
2010-06-21 13:51:56 +00:00
|
|
|
requestPool_.erase(riter);
|
2010-03-06 14:21:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
req = *riter;
|
|
|
|
}
|
|
|
|
req->requestRemoval();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-20 11:42:33 +00:00
|
|
|
std::string FileEntry::getBasename() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return File(path_).getBasename();
|
2010-06-20 11:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string FileEntry::getDirname() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return File(path_).getDirname();
|
2010-06-20 11:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t FileEntry::setUris(const std::vector<std::string>& uris)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
uris_.clear();
|
2010-06-20 11:42:33 +00:00
|
|
|
return addUris(uris.begin(), uris.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileEntry::addUri(const std::string& uri)
|
|
|
|
{
|
|
|
|
if(Request().setUri(uri)) {
|
2010-06-21 13:51:56 +00:00
|
|
|
uris_.push_back(uri);
|
2010-06-20 11:42:33 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileEntry::insertUri(const std::string& uri, size_t pos)
|
|
|
|
{
|
|
|
|
if(Request().setUri(uri)) {
|
2010-06-21 13:51:56 +00:00
|
|
|
pos = std::min(pos, uris_.size());
|
|
|
|
uris_.insert(uris_.begin()+pos, uri);
|
2010-06-20 11:42:33 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|