mirror of https://github.com/aria2/aria2
2009-06-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten DownloadContext and removed SingleFileDownloadContext and BtContext and its derived classes. BitTorrent specific attributes are now set by DownloadContext::setAttribute() with key bittorrent::BITTORRENT. * src/AbstractBtMessage.cc * src/AbstractBtMessage.h * src/AbstractCommand.cc * src/AbstractCommand.h * src/AbstractProxyRequestCommand.cc * src/AbstractProxyResponseCommand.cc * src/ActivePeerConnectionCommand.cc * src/ActivePeerConnectionCommand.h * src/AnnounceList.cc * src/BtCheckIntegrityEntry.cc * src/BtConstants.h * src/BtContext.h: Removed * src/BtDependency.cc * src/BtExtendedMessage.cc * src/BtPieceMessage.cc * src/BtPieceMessage.h * src/BtPostDownloadHandler.cc * src/BtRegistry.cc * src/BtRegistry.h * src/BtSetup.cc * src/CheckIntegrityCommand.cc * src/CheckIntegrityEntry.cc * src/ChecksumCheckIntegrityEntry.cc * src/ConsoleStatCalc.cc * src/ContentTypeRequestGroupCriteria.cc * src/DHTGetPeersCommand.cc * src/DHTGetPeersCommand.h * src/DHTPeerLookupTask.cc * src/DHTPeerLookupTask.h * src/DHTTaskFactory.h * src/DHTTaskFactoryImpl.cc * src/DHTTaskFactoryImpl.h * src/DefaultBtAnnounce.cc * src/DefaultBtAnnounce.h * src/DefaultBtContext.cc: Removed * src/DefaultBtContext.h: Removed * src/DefaultBtInteractive.cc * src/DefaultBtInteractive.h * src/DefaultBtMessageDispatcher.cc * src/DefaultBtMessageDispatcher.h * src/DefaultBtMessageFactory.cc * src/DefaultBtMessageFactory.h * src/DefaultBtMessageReceiver.cc * src/DefaultBtMessageReceiver.h * src/DefaultBtProgressInfoFile.cc * src/DefaultBtRequestFactory.cc * src/DefaultBtRequestFactory.h * src/DefaultExtensionMessageFactory.cc * src/DefaultExtensionMessageFactory.h * src/DefaultPeerStorage.cc * src/DefaultPeerStorage.h * src/DefaultPieceStorage.cc * src/DefaultSegmentManFactory.cc * src/DiskAdaptor.cc * src/DiskAdaptor.h * src/DownloadContext.cc * src/DownloadContext.h * src/DownloadEngine.cc * src/DownloadEngineFactory.cc * src/DownloadHandler.cc * src/DownloadResult.h * src/FileAllocationCommand.cc * src/FileAllocationDispatcherCommand.cc * src/FileAllocationEntry.cc * src/FileEntry.h * src/FillRequestGroupCommand.cc * src/FtpDownloadCommand.cc * src/FtpFinishDownloadCommand.cc * src/FtpInitiateConnectionCommand.cc * src/FtpNegotiationCommand.cc * src/FtpTunnelRequestCommand.cc * src/FtpTunnelResponseCommand.cc * src/HandshakeExtensionMessage.cc * src/HandshakeExtensionMessage.h * src/HaveEraseCommand.cc * src/HttpDownloadCommand.cc * src/HttpInitiateConnectionCommand.cc * src/HttpProxyRequestCommand.cc * src/HttpProxyResponseCommand.cc * src/HttpRequest.cc * src/HttpRequest.h * src/HttpRequestCommand.cc * src/HttpResponseCommand.cc * src/HttpServerBodyCommand.cc * src/HttpServerCommand.cc * src/HttpSkipResponseCommand.cc * src/InitiateConnectionCommandFactory.cc * src/InitiatorMSEHandshakeCommand.cc * src/InitiatorMSEHandshakeCommand.h * src/IteratableChecksumValidator.cc * src/IteratableChecksumValidator.h * src/IteratableChunkChecksumValidator.cc * src/MSEHandshake.cc * src/MSEHandshake.h * src/Makefile.am * src/Makefile.in * src/Metalink2RequestGroup.cc * src/MetalinkPostDownloadHandler.cc * src/MultiDiskAdaptor.cc * src/MultiDiskAdaptor.h * src/MultiFileAllocationIterator.cc * src/MultiUrlRequestInfo.cc * src/PeerChokeCommand.cc * src/PeerChokeCommand.h * src/PeerInitiateConnectionCommand.cc * src/PeerInitiateConnectionCommand.h * src/PeerInteractionCommand.cc * src/PeerInteractionCommand.h * src/PeerReceiveHandshakeCommand.cc * src/PieceHashCheckIntegrityEntry.cc * src/RealtimeCommand.cc * src/ReceiverMSEHandshakeCommand.cc * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupEntry.cc * src/RequestGroupMan.cc * src/SeedCheckCommand.cc * src/SeedCheckCommand.h * src/SegmentMan.cc * src/ShareRatioSeedCriteria.h * src/SingleFileDownloadContext.cc: Removed * src/SingleFileDownloadContext.h: Removed * src/SleepCommand.cc * src/StreamCheckIntegrityEntry.cc * src/TrackerWatcherCommand.cc * src/TrackerWatcherCommand.h * src/UnknownLengthPieceStorage.cc * src/Util.cc * src/Util.h * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/main.cc * src/option_processing.cc * test/BitfieldManTest.cc * test/BittorrentHelperTest.cc * test/BtCancelMessageTest.cc * test/BtChokeMessageTest.cc * test/BtDependencyTest.cc * test/BtPieceMessageTest.cc * test/BtPostDownloadHandlerTest.cc * test/BtRegistryTest.cc * test/BtRejectMessageTest.cc * test/BtRequestMessageTest.cc * test/DHTPeerAnnounceStorageTest.cc * test/DefaultBtAnnounceTest.cc * test/DefaultBtContextTest.cc: Removed * test/DefaultBtMessageDispatcherTest.cc * test/DefaultBtMessageFactoryTest.cc * test/DefaultBtProgressInfoFileTest.cc * test/DefaultBtRequestFactoryTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/DefaultPeerStorageTest.cc * test/DefaultPieceStorageTest.cc * test/DirectDiskAdaptorTest.cc * test/DownloadContextTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/HandshakeExtensionMessageTest.cc * test/HttpRequestTest.cc * test/HttpResponseTest.cc * test/IteratableChecksumValidatorTest.cc * test/IteratableChunkChecksumValidatorTest.cc * test/MSEHandshakeTest.cc * test/Makefile.am * test/Makefile.in * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/MockBtContext.h: Removed * test/MockDHTTaskFactory.h * test/MockDownloadContext.h: Removed * test/MockPieceStorage.h * test/MultiDiskAdaptorTest.cc * test/MultiFileAllocationIteratorTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc * test/SegmentManTest.cc * test/ShareRatioSeedCriteriaTest.cc * test/SingleFileDownloadContextTest.cc: Removed * test/UtilTest.cc * test/XmlRpcMethodTest.ccpull/1/head
parent
90471d6805
commit
5699b67526
189
ChangeLog
189
ChangeLog
|
@ -1,3 +1,192 @@
|
||||||
|
2009-06-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Rewritten DownloadContext and removed SingleFileDownloadContext
|
||||||
|
and BtContext and its derived classes. BitTorrent specific
|
||||||
|
attributes are now set by DownloadContext::setAttribute() with key
|
||||||
|
bittorrent::BITTORRENT.
|
||||||
|
* src/AbstractBtMessage.cc
|
||||||
|
* src/AbstractBtMessage.h
|
||||||
|
* src/AbstractCommand.cc
|
||||||
|
* src/AbstractCommand.h
|
||||||
|
* src/AbstractProxyRequestCommand.cc
|
||||||
|
* src/AbstractProxyResponseCommand.cc
|
||||||
|
* src/ActivePeerConnectionCommand.cc
|
||||||
|
* src/ActivePeerConnectionCommand.h
|
||||||
|
* src/AnnounceList.cc
|
||||||
|
* src/BtCheckIntegrityEntry.cc
|
||||||
|
* src/BtConstants.h
|
||||||
|
* src/BtContext.h: Removed
|
||||||
|
* src/BtDependency.cc
|
||||||
|
* src/BtExtendedMessage.cc
|
||||||
|
* src/BtPieceMessage.cc
|
||||||
|
* src/BtPieceMessage.h
|
||||||
|
* src/BtPostDownloadHandler.cc
|
||||||
|
* src/BtRegistry.cc
|
||||||
|
* src/BtRegistry.h
|
||||||
|
* src/BtSetup.cc
|
||||||
|
* src/CheckIntegrityCommand.cc
|
||||||
|
* src/CheckIntegrityEntry.cc
|
||||||
|
* src/ChecksumCheckIntegrityEntry.cc
|
||||||
|
* src/ConsoleStatCalc.cc
|
||||||
|
* src/ContentTypeRequestGroupCriteria.cc
|
||||||
|
* src/DHTGetPeersCommand.cc
|
||||||
|
* src/DHTGetPeersCommand.h
|
||||||
|
* src/DHTPeerLookupTask.cc
|
||||||
|
* src/DHTPeerLookupTask.h
|
||||||
|
* src/DHTTaskFactory.h
|
||||||
|
* src/DHTTaskFactoryImpl.cc
|
||||||
|
* src/DHTTaskFactoryImpl.h
|
||||||
|
* src/DefaultBtAnnounce.cc
|
||||||
|
* src/DefaultBtAnnounce.h
|
||||||
|
* src/DefaultBtContext.cc: Removed
|
||||||
|
* src/DefaultBtContext.h: Removed
|
||||||
|
* src/DefaultBtInteractive.cc
|
||||||
|
* src/DefaultBtInteractive.h
|
||||||
|
* src/DefaultBtMessageDispatcher.cc
|
||||||
|
* src/DefaultBtMessageDispatcher.h
|
||||||
|
* src/DefaultBtMessageFactory.cc
|
||||||
|
* src/DefaultBtMessageFactory.h
|
||||||
|
* src/DefaultBtMessageReceiver.cc
|
||||||
|
* src/DefaultBtMessageReceiver.h
|
||||||
|
* src/DefaultBtProgressInfoFile.cc
|
||||||
|
* src/DefaultBtRequestFactory.cc
|
||||||
|
* src/DefaultBtRequestFactory.h
|
||||||
|
* src/DefaultExtensionMessageFactory.cc
|
||||||
|
* src/DefaultExtensionMessageFactory.h
|
||||||
|
* src/DefaultPeerStorage.cc
|
||||||
|
* src/DefaultPeerStorage.h
|
||||||
|
* src/DefaultPieceStorage.cc
|
||||||
|
* src/DefaultSegmentManFactory.cc
|
||||||
|
* src/DiskAdaptor.cc
|
||||||
|
* src/DiskAdaptor.h
|
||||||
|
* src/DownloadContext.cc
|
||||||
|
* src/DownloadContext.h
|
||||||
|
* src/DownloadEngine.cc
|
||||||
|
* src/DownloadEngineFactory.cc
|
||||||
|
* src/DownloadHandler.cc
|
||||||
|
* src/DownloadResult.h
|
||||||
|
* src/FileAllocationCommand.cc
|
||||||
|
* src/FileAllocationDispatcherCommand.cc
|
||||||
|
* src/FileAllocationEntry.cc
|
||||||
|
* src/FileEntry.h
|
||||||
|
* src/FillRequestGroupCommand.cc
|
||||||
|
* src/FtpDownloadCommand.cc
|
||||||
|
* src/FtpFinishDownloadCommand.cc
|
||||||
|
* src/FtpInitiateConnectionCommand.cc
|
||||||
|
* src/FtpNegotiationCommand.cc
|
||||||
|
* src/FtpTunnelRequestCommand.cc
|
||||||
|
* src/FtpTunnelResponseCommand.cc
|
||||||
|
* src/HandshakeExtensionMessage.cc
|
||||||
|
* src/HandshakeExtensionMessage.h
|
||||||
|
* src/HaveEraseCommand.cc
|
||||||
|
* src/HttpDownloadCommand.cc
|
||||||
|
* src/HttpInitiateConnectionCommand.cc
|
||||||
|
* src/HttpProxyRequestCommand.cc
|
||||||
|
* src/HttpProxyResponseCommand.cc
|
||||||
|
* src/HttpRequest.cc
|
||||||
|
* src/HttpRequest.h
|
||||||
|
* src/HttpRequestCommand.cc
|
||||||
|
* src/HttpResponseCommand.cc
|
||||||
|
* src/HttpServerBodyCommand.cc
|
||||||
|
* src/HttpServerCommand.cc
|
||||||
|
* src/HttpSkipResponseCommand.cc
|
||||||
|
* src/InitiateConnectionCommandFactory.cc
|
||||||
|
* src/InitiatorMSEHandshakeCommand.cc
|
||||||
|
* src/InitiatorMSEHandshakeCommand.h
|
||||||
|
* src/IteratableChecksumValidator.cc
|
||||||
|
* src/IteratableChecksumValidator.h
|
||||||
|
* src/IteratableChunkChecksumValidator.cc
|
||||||
|
* src/MSEHandshake.cc
|
||||||
|
* src/MSEHandshake.h
|
||||||
|
* src/Makefile.am
|
||||||
|
* src/Makefile.in
|
||||||
|
* src/Metalink2RequestGroup.cc
|
||||||
|
* src/MetalinkPostDownloadHandler.cc
|
||||||
|
* src/MultiDiskAdaptor.cc
|
||||||
|
* src/MultiDiskAdaptor.h
|
||||||
|
* src/MultiFileAllocationIterator.cc
|
||||||
|
* src/MultiUrlRequestInfo.cc
|
||||||
|
* src/PeerChokeCommand.cc
|
||||||
|
* src/PeerChokeCommand.h
|
||||||
|
* src/PeerInitiateConnectionCommand.cc
|
||||||
|
* src/PeerInitiateConnectionCommand.h
|
||||||
|
* src/PeerInteractionCommand.cc
|
||||||
|
* src/PeerInteractionCommand.h
|
||||||
|
* src/PeerReceiveHandshakeCommand.cc
|
||||||
|
* src/PieceHashCheckIntegrityEntry.cc
|
||||||
|
* src/RealtimeCommand.cc
|
||||||
|
* src/ReceiverMSEHandshakeCommand.cc
|
||||||
|
* src/RequestGroup.cc
|
||||||
|
* src/RequestGroup.h
|
||||||
|
* src/RequestGroupEntry.cc
|
||||||
|
* src/RequestGroupMan.cc
|
||||||
|
* src/SeedCheckCommand.cc
|
||||||
|
* src/SeedCheckCommand.h
|
||||||
|
* src/SegmentMan.cc
|
||||||
|
* src/ShareRatioSeedCriteria.h
|
||||||
|
* src/SingleFileDownloadContext.cc: Removed
|
||||||
|
* src/SingleFileDownloadContext.h: Removed
|
||||||
|
* src/SleepCommand.cc
|
||||||
|
* src/StreamCheckIntegrityEntry.cc
|
||||||
|
* src/TrackerWatcherCommand.cc
|
||||||
|
* src/TrackerWatcherCommand.h
|
||||||
|
* src/UnknownLengthPieceStorage.cc
|
||||||
|
* src/Util.cc
|
||||||
|
* src/Util.h
|
||||||
|
* src/XmlRpcMethodImpl.cc
|
||||||
|
* src/bittorrent_helper.cc
|
||||||
|
* src/bittorrent_helper.h
|
||||||
|
* src/download_helper.cc
|
||||||
|
* src/main.cc
|
||||||
|
* src/option_processing.cc
|
||||||
|
* test/BitfieldManTest.cc
|
||||||
|
* test/BittorrentHelperTest.cc
|
||||||
|
* test/BtCancelMessageTest.cc
|
||||||
|
* test/BtChokeMessageTest.cc
|
||||||
|
* test/BtDependencyTest.cc
|
||||||
|
* test/BtPieceMessageTest.cc
|
||||||
|
* test/BtPostDownloadHandlerTest.cc
|
||||||
|
* test/BtRegistryTest.cc
|
||||||
|
* test/BtRejectMessageTest.cc
|
||||||
|
* test/BtRequestMessageTest.cc
|
||||||
|
* test/DHTPeerAnnounceStorageTest.cc
|
||||||
|
* test/DefaultBtAnnounceTest.cc
|
||||||
|
* test/DefaultBtContextTest.cc: Removed
|
||||||
|
* test/DefaultBtMessageDispatcherTest.cc
|
||||||
|
* test/DefaultBtMessageFactoryTest.cc
|
||||||
|
* test/DefaultBtProgressInfoFileTest.cc
|
||||||
|
* test/DefaultBtRequestFactoryTest.cc
|
||||||
|
* test/DefaultExtensionMessageFactoryTest.cc
|
||||||
|
* test/DefaultPeerStorageTest.cc
|
||||||
|
* test/DefaultPieceStorageTest.cc
|
||||||
|
* test/DirectDiskAdaptorTest.cc
|
||||||
|
* test/DownloadContextTest.cc
|
||||||
|
* test/DownloadHandlerFactoryTest.cc
|
||||||
|
* test/DownloadHelperTest.cc
|
||||||
|
* test/HandshakeExtensionMessageTest.cc
|
||||||
|
* test/HttpRequestTest.cc
|
||||||
|
* test/HttpResponseTest.cc
|
||||||
|
* test/IteratableChecksumValidatorTest.cc
|
||||||
|
* test/IteratableChunkChecksumValidatorTest.cc
|
||||||
|
* test/MSEHandshakeTest.cc
|
||||||
|
* test/Makefile.am
|
||||||
|
* test/Makefile.in
|
||||||
|
* test/Metalink2RequestGroupTest.cc
|
||||||
|
* test/MetalinkPostDownloadHandlerTest.cc
|
||||||
|
* test/MockBtContext.h: Removed
|
||||||
|
* test/MockDHTTaskFactory.h
|
||||||
|
* test/MockDownloadContext.h: Removed
|
||||||
|
* test/MockPieceStorage.h
|
||||||
|
* test/MultiDiskAdaptorTest.cc
|
||||||
|
* test/MultiFileAllocationIteratorTest.cc
|
||||||
|
* test/RequestGroupManTest.cc
|
||||||
|
* test/RequestGroupTest.cc
|
||||||
|
* test/SegmentManTest.cc
|
||||||
|
* test/ShareRatioSeedCriteriaTest.cc
|
||||||
|
* test/SingleFileDownloadContextTest.cc: Removed
|
||||||
|
* test/UtilTest.cc
|
||||||
|
* test/XmlRpcMethodTest.cc
|
||||||
|
|
||||||
2009-06-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-06-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Added experimental support of WEB-Seeding for multi-file torrent.
|
Added experimental support of WEB-Seeding for multi-file torrent.
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "AbstractBtMessage.h"
|
#include "AbstractBtMessage.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "BtMessageValidator.h"
|
#include "BtMessageValidator.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
|
@ -73,11 +72,6 @@ AbstractBtMessage::setBtMessageValidator(const SharedHandle<BtMessageValidator>&
|
||||||
this->validator = validator;
|
this->validator = validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractBtMessage::setBtContext(const SharedHandle<BtContext>& btContext)
|
|
||||||
{
|
|
||||||
this->btContext = btContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AbstractBtMessage::setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage)
|
void AbstractBtMessage::setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage)
|
||||||
{
|
{
|
||||||
this->pieceStorage = pieceStorage;
|
this->pieceStorage = pieceStorage;
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
|
||||||
class PieceStorage;
|
class PieceStorage;
|
||||||
class Peer;
|
class Peer;
|
||||||
class BtMessageDispatcher;
|
class BtMessageDispatcher;
|
||||||
|
@ -60,8 +59,6 @@ protected:
|
||||||
|
|
||||||
std::string _name;
|
std::string _name;
|
||||||
|
|
||||||
SharedHandle<BtContext> btContext;
|
|
||||||
|
|
||||||
SharedHandle<PieceStorage> pieceStorage;
|
SharedHandle<PieceStorage> pieceStorage;
|
||||||
|
|
||||||
SharedHandle<Peer> peer;
|
SharedHandle<Peer> peer;
|
||||||
|
@ -137,13 +134,6 @@ public:
|
||||||
|
|
||||||
void setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator);
|
void setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator);
|
||||||
|
|
||||||
void setBtContext(const SharedHandle<BtContext>& btContext);
|
|
||||||
|
|
||||||
const SharedHandle<BtContext>& getBtContext() const
|
|
||||||
{
|
|
||||||
return btContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
|
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
|
||||||
|
|
||||||
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dispatcher);
|
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dispatcher);
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "RequestGroup.h"
|
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
|
@ -231,9 +230,9 @@ bool AbstractCommand::execute() {
|
||||||
|
|
||||||
void AbstractCommand::tryReserved() {
|
void AbstractCommand::tryReserved() {
|
||||||
_requestGroup->removeServerHost(cuid);
|
_requestGroup->removeServerHost(cuid);
|
||||||
if(_requestGroup->getDownloadContext()->getFileMode() == DownloadContext::SINGLE) {
|
if(_requestGroup->getDownloadContext()->getFileEntries().size() == 1) {
|
||||||
const SharedHandle<FileEntry>& entry =
|
const SharedHandle<FileEntry>& entry =
|
||||||
_requestGroup->getDownloadContext()->getFileEntries().front();
|
_requestGroup->getDownloadContext()->getFirstFileEntry();
|
||||||
// Don't create new command if currently file length is unknown
|
// Don't create new command if currently file length is unknown
|
||||||
// and there are no URI left. Because file length is unknown, we
|
// and there are no URI left. Because file length is unknown, we
|
||||||
// can assume that there are no in-flight request object.
|
// can assume that there are no in-flight request object.
|
||||||
|
|
|
@ -39,12 +39,12 @@
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "TimeA2.h"
|
#include "TimeA2.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
|
#include "RequestGroup.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class Request;
|
class Request;
|
||||||
class DownloadEngine;
|
class DownloadEngine;
|
||||||
class RequestGroup;
|
|
||||||
class Segment;
|
class Segment;
|
||||||
class Exception;
|
class Exception;
|
||||||
class SocketCore;
|
class SocketCore;
|
||||||
|
@ -122,6 +122,11 @@ protected:
|
||||||
const std::string& resolveProxyMethod(const std::string& protocol) const;
|
const std::string& resolveProxyMethod(const std::string& protocol) const;
|
||||||
|
|
||||||
const SharedHandle<Option>& getOption() const;
|
const SharedHandle<Option>& getOption() const;
|
||||||
|
|
||||||
|
const SharedHandle<DownloadContext>& getDownloadContext() const
|
||||||
|
{
|
||||||
|
return _requestGroup->getDownloadContext();
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
bool checkSocketIsReadable;
|
bool checkSocketIsReadable;
|
||||||
bool checkSocketIsWritable;
|
bool checkSocketIsWritable;
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include "CookieStorage.h"
|
#include "CookieStorage.h"
|
||||||
#include "AuthConfigFactory.h"
|
#include "AuthConfigFactory.h"
|
||||||
#include "AuthConfig.h"
|
#include "AuthConfig.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include "DlRetryEx.h"
|
#include "DlRetryEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "HttpHeader.h"
|
#include "HttpHeader.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
#include "PeerInitiateConnectionCommand.h"
|
#include "PeerInitiateConnectionCommand.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "BtRuntime.h"
|
#include "BtRuntime.h"
|
||||||
|
@ -48,6 +47,7 @@
|
||||||
#include "SocketCore.h"
|
#include "SocketCore.h"
|
||||||
#include "BtAnnounce.h"
|
#include "BtAnnounce.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -55,12 +55,10 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand
|
||||||
(int cuid,
|
(int cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
|
||||||
time_t interval)
|
time_t interval)
|
||||||
:
|
:
|
||||||
Command(cuid),
|
Command(cuid),
|
||||||
_requestGroup(requestGroup),
|
_requestGroup(requestGroup),
|
||||||
_btContext(btContext),
|
|
||||||
interval(interval),
|
interval(interval),
|
||||||
e(e),
|
e(e),
|
||||||
_numNewConnection(5)
|
_numNewConnection(5)
|
||||||
|
@ -130,7 +128,7 @@ void ActivePeerConnectionCommand::connectToPeer(const PeerHandle& peer)
|
||||||
peer->usedBy(e->newCUID());
|
peer->usedBy(e->newCUID());
|
||||||
PeerInitiateConnectionCommand* command =
|
PeerInitiateConnectionCommand* command =
|
||||||
new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer, e,
|
new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer, e,
|
||||||
_btContext, _btRuntime);
|
_btRuntime);
|
||||||
command->setPeerStorage(_peerStorage);
|
command->setPeerStorage(_peerStorage);
|
||||||
command->setPieceStorage(_pieceStorage);
|
command->setPieceStorage(_pieceStorage);
|
||||||
e->commands.push_back(command);
|
e->commands.push_back(command);
|
||||||
|
|
|
@ -44,7 +44,6 @@ namespace aria2 {
|
||||||
class RequestGroup;
|
class RequestGroup;
|
||||||
class DownloadEngine;
|
class DownloadEngine;
|
||||||
class Peer;
|
class Peer;
|
||||||
class BtContext;
|
|
||||||
class BtRuntime;
|
class BtRuntime;
|
||||||
class PieceStorage;
|
class PieceStorage;
|
||||||
class PeerStorage;
|
class PeerStorage;
|
||||||
|
@ -53,7 +52,6 @@ class BtAnnounce;
|
||||||
class ActivePeerConnectionCommand : public Command {
|
class ActivePeerConnectionCommand : public Command {
|
||||||
private:
|
private:
|
||||||
RequestGroup* _requestGroup;
|
RequestGroup* _requestGroup;
|
||||||
SharedHandle<BtContext> _btContext;
|
|
||||||
SharedHandle<BtRuntime> _btRuntime;
|
SharedHandle<BtRuntime> _btRuntime;
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
|
@ -67,7 +65,6 @@ public:
|
||||||
ActivePeerConnectionCommand(int cuid,
|
ActivePeerConnectionCommand(int cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const SharedHandle<BtContext>& btContext,
|
|
||||||
time_t interval);
|
time_t interval);
|
||||||
|
|
||||||
virtual ~ActivePeerConnectionCommand();
|
virtual ~ActivePeerConnectionCommand();
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
#include "SimpleRandomizer.h"
|
#include "SimpleRandomizer.h"
|
||||||
#include "bencode.h"
|
#include "bencode.h"
|
||||||
|
#include "Util.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ void AnnounceList::reconfigure(const BDE& announceList)
|
||||||
elemItr != elemList.listEnd(); ++elemItr) {
|
elemItr != elemList.listEnd(); ++elemItr) {
|
||||||
const BDE& data = *elemItr;
|
const BDE& data = *elemItr;
|
||||||
if(data.isString()) {
|
if(data.isString()) {
|
||||||
urls.push_back(data.s());
|
urls.push_back(Util::trim(data.s()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!urls.empty()) {
|
if(!urls.empty()) {
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,10 @@
|
||||||
|
|
||||||
typedef std::map<std::string, uint8_t> Extensions;
|
typedef std::map<std::string, uint8_t> Extensions;
|
||||||
|
|
||||||
|
#define INFO_HASH_LENGTH 20
|
||||||
|
|
||||||
|
#define PIECE_HASH_LENGTH 20
|
||||||
|
|
||||||
#define PEER_ID_LENGTH 20
|
#define PEER_ID_LENGTH 20
|
||||||
|
|
||||||
#define INFO_HASH_LENGTH 20
|
#define INFO_HASH_LENGTH 20
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
/* <!-- 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
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* 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 --> */
|
|
||||||
#ifndef _D_BT_CONTEXT_H_
|
|
||||||
#define _D_BT_CONTEXT_H_
|
|
||||||
|
|
||||||
#include "DownloadContext.h"
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
#include <deque>
|
|
||||||
|
|
||||||
#include "IntSequence.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
class AnnounceTier;
|
|
||||||
class RequestGroup;
|
|
||||||
|
|
||||||
class BtContext:public DownloadContext {
|
|
||||||
protected:
|
|
||||||
bool _private;
|
|
||||||
public:
|
|
||||||
BtContext():_private(false) {}
|
|
||||||
|
|
||||||
virtual ~BtContext() {}
|
|
||||||
|
|
||||||
virtual const unsigned char* getInfoHash() const = 0;
|
|
||||||
|
|
||||||
virtual size_t getInfoHashLength() const = 0;
|
|
||||||
|
|
||||||
virtual const std::string& getInfoHashAsString() const = 0;
|
|
||||||
|
|
||||||
virtual const std::deque<SharedHandle<AnnounceTier> >&
|
|
||||||
getAnnounceTiers() const = 0;
|
|
||||||
|
|
||||||
virtual void load(const std::string& torrentFile,
|
|
||||||
const std::string& overrideName = "") = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the peer id of localhost, 20 byte length
|
|
||||||
*/
|
|
||||||
virtual const unsigned char* getPeerId() = 0;
|
|
||||||
|
|
||||||
bool isPrivate() const
|
|
||||||
{
|
|
||||||
return _private;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void computeFastSet
|
|
||||||
(std::deque<size_t>& fastSet, const std::string& ipaddr, size_t fastSetSize) = 0;
|
|
||||||
|
|
||||||
virtual RequestGroup* getOwnerRequestGroup() = 0;
|
|
||||||
|
|
||||||
virtual std::deque<std::pair<std::string, uint16_t> >& getNodes() = 0;
|
|
||||||
|
|
||||||
virtual const std::string& getName() const = 0;
|
|
||||||
|
|
||||||
virtual void setFileFilter(IntSequence seq) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class BtContext;
|
|
||||||
typedef SharedHandle<BtContext> BtContextHandle;
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
||||||
|
|
||||||
#endif // _D_BT_CONTEXT_H_
|
|
|
@ -37,7 +37,7 @@
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "DefaultBtContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "RecoverableException.h"
|
#include "RecoverableException.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
|
@ -45,6 +45,8 @@
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
#include "DlAbortEx.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -62,39 +64,38 @@ bool BtDependency::resolve()
|
||||||
RequestGroupHandle dependee = _dependee;
|
RequestGroupHandle dependee = _dependee;
|
||||||
// cut reference here
|
// cut reference here
|
||||||
_dependee.reset();
|
_dependee.reset();
|
||||||
DefaultBtContextHandle btContext(new DefaultBtContext());
|
SharedHandle<DownloadContext> context(new DownloadContext());
|
||||||
btContext->setDir(_dependant->getDownloadContext()->getDir());
|
context->setDir(_dependant->getDownloadContext()->getDir());
|
||||||
try {
|
try {
|
||||||
DiskAdaptorHandle diskAdaptor = dependee->getPieceStorage()->getDiskAdaptor();
|
DiskAdaptorHandle diskAdaptor =
|
||||||
|
dependee->getPieceStorage()->getDiskAdaptor();
|
||||||
diskAdaptor->openExistingFile();
|
diskAdaptor->openExistingFile();
|
||||||
std::string content = Util::toString(diskAdaptor);
|
std::string content = Util::toString(diskAdaptor);
|
||||||
|
bittorrent::loadFromMemory
|
||||||
std::string overrideName;
|
(content, context, File(dependee->getFirstFilePath()).getBasename());
|
||||||
if(Util::startsWith(_dependant->getDownloadContext()->getActualBasePath(),
|
if(context->getFileEntries().size() !=
|
||||||
_dependant->getDownloadContext()->getDir())) {
|
_dependant->getDownloadContext()->getFileEntries().size()) {
|
||||||
overrideName =
|
throw DL_ABORT_EX("The number of file in torrent doesn't match to"
|
||||||
_dependant->getDownloadContext()->getActualBasePath().substr
|
" the dependant.");
|
||||||
(_dependant->getDownloadContext()->getDir().size());
|
|
||||||
if(Util::startsWith(overrideName, "/")) {
|
|
||||||
overrideName = overrideName.substr(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
btContext->loadFromMemory(content,
|
// Copy file path in _dependant's FileEntries to newly created
|
||||||
File(dependee->getFilePath()).getBasename(),
|
// context's FileEntries to endorse the path structure of
|
||||||
overrideName);
|
// _dependant.
|
||||||
if(_dependant->getOption()->defined(PREF_PEER_ID_PREFIX)) {
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator s =
|
||||||
btContext->setPeerIdPrefix
|
_dependant->getDownloadContext()->getFileEntries().begin(),
|
||||||
(_dependant->getOption()->get(PREF_PEER_ID_PREFIX));
|
d = context->getFileEntries().begin();
|
||||||
|
d != context->getFileEntries().end(); ++s, ++d) {
|
||||||
|
(*d)->setPath((*s)->getPath());
|
||||||
}
|
}
|
||||||
} catch(RecoverableException& e) {
|
} catch(RecoverableException& e) {
|
||||||
_logger->error(EX_EXCEPTION_CAUGHT, e);
|
_logger->error(EX_EXCEPTION_CAUGHT, e);
|
||||||
_logger->debug("BtDependency for GID#%d failed. Go without Bt.",
|
_logger->info("BtDependency for GID#%d failed. Go without Bt.",
|
||||||
_dependant->getGID());
|
_dependant->getGID());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
_logger->debug("Dependency resolved for GID#%d", _dependant->getGID());
|
_logger->debug("Dependency resolved for GID#%d", _dependant->getGID());
|
||||||
_dependant->setDownloadContext(btContext);
|
_dependant->setDownloadContext(context);
|
||||||
btContext->setOwnerRequestGroup(_dependant.get());
|
context->setOwnerRequestGroup(_dependant.get());
|
||||||
return true;
|
return true;
|
||||||
} else if(_dependee->getNumCommand() == 0) {
|
} else if(_dependee->getNumCommand() == 0) {
|
||||||
// _dependee's download failed.
|
// _dependee's download failed.
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
#include "ExtensionMessageFactory.h"
|
#include "ExtensionMessageFactory.h"
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
|
@ -47,13 +47,13 @@
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "Piece.h"
|
#include "Piece.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "BtMessageDispatcher.h"
|
#include "BtMessageDispatcher.h"
|
||||||
#include "BtMessageFactory.h"
|
#include "BtMessageFactory.h"
|
||||||
#include "BtRequestFactory.h"
|
#include "BtRequestFactory.h"
|
||||||
#include "PeerConnection.h"
|
#include "PeerConnection.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ void BtPieceMessage::doReceivedAction() {
|
||||||
peer->snubbing(false);
|
peer->snubbing(false);
|
||||||
peer->updateLatency(slot.getLatencyInMillis());
|
peer->updateLatency(slot.getLatencyInMillis());
|
||||||
PieceHandle piece = pieceStorage->getPiece(index);
|
PieceHandle piece = pieceStorage->getPiece(index);
|
||||||
off_t offset = (off_t)index*btContext->getPieceLength()+begin;
|
off_t offset = (off_t)index*_downloadContext->getPieceLength()+begin;
|
||||||
logger->debug(MSG_PIECE_RECEIVED,
|
logger->debug(MSG_PIECE_RECEIVED,
|
||||||
cuid, index, begin, blockLength, offset, slot.getBlockIndex());
|
cuid, index, begin, blockLength, offset, slot.getBlockIndex());
|
||||||
pieceStorage->getDiskAdaptor()->writeData(block, blockLength, offset);
|
pieceStorage->getDiskAdaptor()->writeData(block, blockLength, offset);
|
||||||
|
@ -143,7 +143,7 @@ void BtPieceMessage::send() {
|
||||||
getMessageHeader();
|
getMessageHeader();
|
||||||
peerConnection->sendMessage(msgHeader, getMessageHeaderLength());
|
peerConnection->sendMessage(msgHeader, getMessageHeaderLength());
|
||||||
off_t pieceDataOffset =
|
off_t pieceDataOffset =
|
||||||
(off_t)index*btContext->getPieceLength()+begin;
|
(off_t)index*_downloadContext->getPieceLength()+begin;
|
||||||
size_t writtenLength = sendPieceData(pieceDataOffset, blockLength);
|
size_t writtenLength = sendPieceData(pieceDataOffset, blockLength);
|
||||||
logger->debug("msglength = %lu bytes",
|
logger->debug("msglength = %lu bytes",
|
||||||
static_cast<unsigned long>(getMessageHeaderLength()+
|
static_cast<unsigned long>(getMessageHeaderLength()+
|
||||||
|
@ -176,12 +176,13 @@ bool BtPieceMessage::checkPieceHash(const PieceHandle& piece) {
|
||||||
if(piece->isHashCalculated()) {
|
if(piece->isHashCalculated()) {
|
||||||
logger->debug("Hash is available!! index=%lu",
|
logger->debug("Hash is available!! index=%lu",
|
||||||
static_cast<unsigned long>(piece->getIndex()));
|
static_cast<unsigned long>(piece->getIndex()));
|
||||||
return piece->getHashString() == btContext->getPieceHash(piece->getIndex());
|
return
|
||||||
|
piece->getHashString()==_downloadContext->getPieceHash(piece->getIndex());
|
||||||
} else {
|
} else {
|
||||||
off_t offset = (off_t)piece->getIndex()*btContext->getPieceLength();
|
off_t offset = (off_t)piece->getIndex()*_downloadContext->getPieceLength();
|
||||||
|
|
||||||
return MessageDigestHelper::staticSHA1Digest(pieceStorage->getDiskAdaptor(), offset, piece->getLength())
|
return MessageDigestHelper::staticSHA1Digest(pieceStorage->getDiskAdaptor(), offset, piece->getLength())
|
||||||
== btContext->getPieceHash(piece->getIndex());
|
== _downloadContext->getPieceHash(piece->getIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +204,7 @@ void BtPieceMessage::erasePieceOnDisk(const PieceHandle& piece) {
|
||||||
size_t BUFSIZE = 4096;
|
size_t BUFSIZE = 4096;
|
||||||
unsigned char buf[BUFSIZE];
|
unsigned char buf[BUFSIZE];
|
||||||
memset(buf, 0, BUFSIZE);
|
memset(buf, 0, BUFSIZE);
|
||||||
off_t offset = (off_t)piece->getIndex()*btContext->getPieceLength();
|
off_t offset = (off_t)piece->getIndex()*_downloadContext->getPieceLength();
|
||||||
div_t res = div(piece->getLength(), BUFSIZE);
|
div_t res = div(piece->getLength(), BUFSIZE);
|
||||||
for(int i = 0; i < res.quot; ++i) {
|
for(int i = 0; i < res.quot; ++i) {
|
||||||
pieceStorage->getDiskAdaptor()->writeData(buf, BUFSIZE, offset);
|
pieceStorage->getDiskAdaptor()->writeData(buf, BUFSIZE, offset);
|
||||||
|
@ -255,4 +256,10 @@ void BtPieceMessage::onCancelSendingPieceEvent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BtPieceMessage::setDownloadContext
|
||||||
|
(const SharedHandle<DownloadContext>& downloadContext)
|
||||||
|
{
|
||||||
|
_downloadContext = downloadContext;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace aria2 {
|
||||||
|
|
||||||
class Piece;
|
class Piece;
|
||||||
class BtPieceMessage;
|
class BtPieceMessage;
|
||||||
|
class DownloadContext;
|
||||||
|
|
||||||
typedef SharedHandle<BtPieceMessage> BtPieceMessageHandle;
|
typedef SharedHandle<BtPieceMessage> BtPieceMessageHandle;
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ private:
|
||||||
uint32_t blockLength;
|
uint32_t blockLength;
|
||||||
unsigned char* block;
|
unsigned char* block;
|
||||||
unsigned char* msgHeader;
|
unsigned char* msgHeader;
|
||||||
|
SharedHandle<DownloadContext> _downloadContext;
|
||||||
|
|
||||||
static size_t MESSAGE_HEADER_LENGTH;
|
static size_t MESSAGE_HEADER_LENGTH;
|
||||||
|
|
||||||
|
@ -100,6 +102,8 @@ public:
|
||||||
|
|
||||||
void setBlockLength(size_t blockLength) { this->blockLength = blockLength; }
|
void setBlockLength(size_t blockLength) { this->blockLength = blockLength; }
|
||||||
|
|
||||||
|
void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
|
||||||
|
|
||||||
static BtPieceMessageHandle create(const unsigned char* data, size_t dataLength);
|
static BtPieceMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||||
|
|
||||||
virtual void doReceivedAction();
|
virtual void doReceivedAction();
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "BtPostDownloadHandler.h"
|
#include "BtPostDownloadHandler.h"
|
||||||
#include "DefaultBtContext.h"
|
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
|
@ -45,6 +44,8 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "ContentTypeRequestGroupCriteria.h"
|
#include "ContentTypeRequestGroupCriteria.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ void BtPostDownloadHandler::getNextRequestGroups
|
||||||
{
|
{
|
||||||
const SharedHandle<Option>& op = requestGroup->getOption();
|
const SharedHandle<Option>& op = requestGroup->getOption();
|
||||||
_logger->debug("Generating RequestGroups for Torrent file %s",
|
_logger->debug("Generating RequestGroups for Torrent file %s",
|
||||||
requestGroup->getFilePath().c_str());
|
requestGroup->getFirstFilePath().c_str());
|
||||||
RequestGroupHandle rg(new RequestGroup(op, std::deque<std::string>()));
|
RequestGroupHandle rg(new RequestGroup(op, std::deque<std::string>()));
|
||||||
|
|
||||||
std::string content;
|
std::string content;
|
||||||
|
@ -76,14 +77,12 @@ void BtPostDownloadHandler::getNextRequestGroups
|
||||||
requestGroup->getPieceStorage()->getDiskAdaptor()->closeFile();
|
requestGroup->getPieceStorage()->getDiskAdaptor()->closeFile();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
DefaultBtContextHandle btContext(new DefaultBtContext());
|
SharedHandle<DownloadContext> context(new DownloadContext());
|
||||||
btContext->setDir(requestGroup->getDownloadContext()->getDir());
|
context->setDir(requestGroup->getDownloadContext()->getDir());
|
||||||
btContext->loadFromMemory(content, File(requestGroup->getFilePath()).getBasename());
|
bittorrent::loadFromMemory(content, context,
|
||||||
if(op->defined(PREF_PEER_ID_PREFIX)) {
|
File(requestGroup->getFirstFilePath()).getBasename());
|
||||||
btContext->setPeerIdPrefix(op->get(PREF_PEER_ID_PREFIX));
|
rg->setDownloadContext(context);
|
||||||
}
|
context->setOwnerRequestGroup(rg.get());
|
||||||
rg->setDownloadContext(btContext);
|
|
||||||
btContext->setOwnerRequestGroup(rg.get());
|
|
||||||
|
|
||||||
groups.push_back(rg);
|
groups.push_back(rg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "BtRegistry.h"
|
#include "BtRegistry.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "BtContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "BtAnnounce.h"
|
#include "BtAnnounce.h"
|
||||||
|
@ -43,10 +43,10 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
SharedHandle<BtContext>
|
SharedHandle<DownloadContext>
|
||||||
BtRegistry::getBtContext(const std::string& infoHash) const
|
BtRegistry::getDownloadContext(const std::string& infoHash) const
|
||||||
{
|
{
|
||||||
return get(infoHash)._btContext;
|
return get(infoHash)._downloadContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtRegistry::put(const std::string& infoHash, const BtObject& obj)
|
void BtRegistry::put(const std::string& infoHash, const BtObject& obj)
|
||||||
|
|
|
@ -49,23 +49,23 @@ class PieceStorage;
|
||||||
class BtAnnounce;
|
class BtAnnounce;
|
||||||
class BtRuntime;
|
class BtRuntime;
|
||||||
class BtProgressInfoFile;
|
class BtProgressInfoFile;
|
||||||
class BtContext;
|
class DownloadContext;
|
||||||
|
|
||||||
struct BtObject {
|
struct BtObject {
|
||||||
SharedHandle<BtContext> _btContext;
|
SharedHandle<DownloadContext> _downloadContext;
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
SharedHandle<BtAnnounce> _btAnnounce;
|
SharedHandle<BtAnnounce> _btAnnounce;
|
||||||
SharedHandle<BtRuntime> _btRuntime;
|
SharedHandle<BtRuntime> _btRuntime;
|
||||||
SharedHandle<BtProgressInfoFile> _btProgressInfoFile;
|
SharedHandle<BtProgressInfoFile> _btProgressInfoFile;
|
||||||
|
|
||||||
BtObject(const SharedHandle<BtContext>& btContext,
|
BtObject(const SharedHandle<DownloadContext>& downloadContext,
|
||||||
const SharedHandle<PieceStorage>& pieceStorage,
|
const SharedHandle<PieceStorage>& pieceStorage,
|
||||||
const SharedHandle<PeerStorage>& peerStorage,
|
const SharedHandle<PeerStorage>& peerStorage,
|
||||||
const SharedHandle<BtAnnounce>& btAnnounce,
|
const SharedHandle<BtAnnounce>& btAnnounce,
|
||||||
const SharedHandle<BtRuntime>& btRuntime,
|
const SharedHandle<BtRuntime>& btRuntime,
|
||||||
const SharedHandle<BtProgressInfoFile>& btProgressInfoFile):
|
const SharedHandle<BtProgressInfoFile>& btProgressInfoFile):
|
||||||
_btContext(btContext),
|
_downloadContext(downloadContext),
|
||||||
_pieceStorage(pieceStorage),
|
_pieceStorage(pieceStorage),
|
||||||
_peerStorage(peerStorage),
|
_peerStorage(peerStorage),
|
||||||
_btAnnounce(btAnnounce),
|
_btAnnounce(btAnnounce),
|
||||||
|
@ -76,7 +76,7 @@ struct BtObject {
|
||||||
|
|
||||||
bool isNull() const
|
bool isNull() const
|
||||||
{
|
{
|
||||||
return _btContext.isNull() &&
|
return _downloadContext.isNull() &&
|
||||||
_pieceStorage.isNull() &&
|
_pieceStorage.isNull() &&
|
||||||
_peerStorage.isNull() &&
|
_peerStorage.isNull() &&
|
||||||
_btAnnounce.isNull() &&
|
_btAnnounce.isNull() &&
|
||||||
|
@ -89,19 +89,21 @@ class BtRegistry {
|
||||||
private:
|
private:
|
||||||
std::map<std::string, BtObject> _pool;
|
std::map<std::string, BtObject> _pool;
|
||||||
public:
|
public:
|
||||||
SharedHandle<BtContext> getBtContext(const std::string& infoHash) const;
|
SharedHandle<DownloadContext>
|
||||||
|
getDownloadContext(const std::string& infoHash) const;
|
||||||
|
|
||||||
void put(const std::string& infoHash, const BtObject& obj);
|
void put(const std::string& infoHash, const BtObject& obj);
|
||||||
|
|
||||||
BtObject get(const std::string& infoHash) const;
|
BtObject get(const std::string& infoHash) const;
|
||||||
|
|
||||||
template<typename OutputIterator>
|
template<typename OutputIterator>
|
||||||
void getAllBtContext(OutputIterator dest)
|
OutputIterator getAllDownloadContext(OutputIterator dest)
|
||||||
{
|
{
|
||||||
for(std::map<std::string, BtObject>::const_iterator i = _pool.begin();
|
for(std::map<std::string, BtObject>::const_iterator i = _pool.begin();
|
||||||
i != _pool.end(); ++i) {
|
i != _pool.end(); ++i) {
|
||||||
*dest++ = (*i).second._btContext;
|
*dest++ = (*i).second._downloadContext;
|
||||||
}
|
}
|
||||||
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeAll();
|
void removeAll();
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
#include "BtProgressInfoFile.h"
|
#include "BtProgressInfoFile.h"
|
||||||
#include "BtAnnounce.h"
|
#include "BtAnnounce.h"
|
||||||
#include "BtRuntime.h"
|
#include "BtRuntime.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -68,11 +69,13 @@ void BtSetup::setup(std::deque<Command*>& commands,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const Option* option)
|
const Option* option)
|
||||||
{
|
{
|
||||||
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(requestGroup->getDownloadContext()));
|
if(!requestGroup->getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) {
|
||||||
if(btContext.isNull()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BtObject btObject = e->getBtRegistry()->get(btContext->getInfoHashAsString());
|
const BDE& torrentAttrs =
|
||||||
|
requestGroup->getDownloadContext()->getAttribute(bittorrent::BITTORRENT);
|
||||||
|
BtObject btObject =
|
||||||
|
e->getBtRegistry()->get(torrentAttrs[bittorrent::INFO_HASH].s());
|
||||||
SharedHandle<PieceStorage> pieceStorage = btObject._pieceStorage;
|
SharedHandle<PieceStorage> pieceStorage = btObject._pieceStorage;
|
||||||
SharedHandle<PeerStorage> peerStorage = btObject._peerStorage;
|
SharedHandle<PeerStorage> peerStorage = btObject._peerStorage;
|
||||||
SharedHandle<BtRuntime> btRuntime = btObject._btRuntime;
|
SharedHandle<BtRuntime> btRuntime = btObject._btRuntime;
|
||||||
|
@ -80,7 +83,7 @@ void BtSetup::setup(std::deque<Command*>& commands,
|
||||||
// commands
|
// commands
|
||||||
{
|
{
|
||||||
TrackerWatcherCommand* c =
|
TrackerWatcherCommand* c =
|
||||||
new TrackerWatcherCommand(e->newCUID(), requestGroup, e, btContext);
|
new TrackerWatcherCommand(e->newCUID(), requestGroup, e);
|
||||||
c->setPeerStorage(peerStorage);
|
c->setPeerStorage(peerStorage);
|
||||||
c->setPieceStorage(pieceStorage);
|
c->setPieceStorage(pieceStorage);
|
||||||
c->setBtRuntime(btRuntime);
|
c->setBtRuntime(btRuntime);
|
||||||
|
@ -90,7 +93,7 @@ void BtSetup::setup(std::deque<Command*>& commands,
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
PeerChokeCommand* c =
|
PeerChokeCommand* c =
|
||||||
new PeerChokeCommand(e->newCUID(), e, btContext);
|
new PeerChokeCommand(e->newCUID(), e);
|
||||||
c->setPeerStorage(peerStorage);
|
c->setPeerStorage(peerStorage);
|
||||||
c->setBtRuntime(btRuntime);
|
c->setBtRuntime(btRuntime);
|
||||||
|
|
||||||
|
@ -98,8 +101,7 @@ void BtSetup::setup(std::deque<Command*>& commands,
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ActivePeerConnectionCommand* c =
|
ActivePeerConnectionCommand* c =
|
||||||
new ActivePeerConnectionCommand(e->newCUID(), requestGroup, e, btContext,
|
new ActivePeerConnectionCommand(e->newCUID(), requestGroup, e, 10);
|
||||||
10);
|
|
||||||
c->setBtRuntime(btRuntime);
|
c->setBtRuntime(btRuntime);
|
||||||
c->setPieceStorage(pieceStorage);
|
c->setPieceStorage(pieceStorage);
|
||||||
c->setPeerStorage(peerStorage);
|
c->setPeerStorage(peerStorage);
|
||||||
|
@ -108,11 +110,11 @@ void BtSetup::setup(std::deque<Command*>& commands,
|
||||||
commands.push_back(c);
|
commands.push_back(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!btContext->isPrivate() && DHTSetup::initialized()) {
|
if(torrentAttrs[bittorrent::PRIVATE].i() == 0 && DHTSetup::initialized()) {
|
||||||
DHTRegistry::_peerAnnounceStorage->addPeerAnnounce(btContext->getInfoHash(),
|
DHTRegistry::_peerAnnounceStorage->addPeerAnnounce
|
||||||
peerStorage);
|
(torrentAttrs[bittorrent::INFO_HASH].uc(), peerStorage);
|
||||||
DHTGetPeersCommand* command =
|
DHTGetPeersCommand* command =
|
||||||
new DHTGetPeersCommand(e->newCUID(), requestGroup, e, btContext);
|
new DHTGetPeersCommand(e->newCUID(), requestGroup, e);
|
||||||
command->setTaskQueue(DHTRegistry::_taskQueue);
|
command->setTaskQueue(DHTRegistry::_taskQueue);
|
||||||
command->setTaskFactory(DHTRegistry::_taskFactory);
|
command->setTaskFactory(DHTRegistry::_taskFactory);
|
||||||
command->setBtRuntime(btRuntime);
|
command->setBtRuntime(btRuntime);
|
||||||
|
@ -129,7 +131,7 @@ void BtSetup::setup(std::deque<Command*>& commands,
|
||||||
if(ratio > 0.0) {
|
if(ratio > 0.0) {
|
||||||
SharedHandle<ShareRatioSeedCriteria> cri
|
SharedHandle<ShareRatioSeedCriteria> cri
|
||||||
(new ShareRatioSeedCriteria(option->getAsDouble(PREF_SEED_RATIO),
|
(new ShareRatioSeedCriteria(option->getAsDouble(PREF_SEED_RATIO),
|
||||||
btContext));
|
requestGroup->getDownloadContext()));
|
||||||
cri->setPieceStorage(pieceStorage);
|
cri->setPieceStorage(pieceStorage);
|
||||||
cri->setPeerStorage(peerStorage);
|
cri->setPeerStorage(peerStorage);
|
||||||
|
|
||||||
|
@ -138,7 +140,7 @@ void BtSetup::setup(std::deque<Command*>& commands,
|
||||||
}
|
}
|
||||||
if(unionCri->getSeedCriterion().size() > 0) {
|
if(unionCri->getSeedCriterion().size() > 0) {
|
||||||
SeedCheckCommand* c =
|
SeedCheckCommand* c =
|
||||||
new SeedCheckCommand(e->newCUID(), requestGroup, e, btContext, unionCri);
|
new SeedCheckCommand(e->newCUID(), requestGroup, e, unionCri);
|
||||||
c->setPieceStorage(pieceStorage);
|
c->setPieceStorage(pieceStorage);
|
||||||
c->setBtRuntime(btRuntime);
|
c->setBtRuntime(btRuntime);
|
||||||
commands.push_back(c);
|
commands.push_back(c);
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -62,13 +63,13 @@ bool CheckIntegrityCommand::executeInternal()
|
||||||
|
|
||||||
if(_requestGroup->downloadFinished()) {
|
if(_requestGroup->downloadFinished()) {
|
||||||
logger->notice(MSG_VERIFICATION_SUCCESSFUL,
|
logger->notice(MSG_VERIFICATION_SUCCESSFUL,
|
||||||
_requestGroup->getFilePath().c_str());
|
_requestGroup->getDownloadContext()->getBasePath().c_str());
|
||||||
std::deque<Command*> commands;
|
std::deque<Command*> commands;
|
||||||
_entry->onDownloadFinished(commands, _e);
|
_entry->onDownloadFinished(commands, _e);
|
||||||
_e->addCommand(commands);
|
_e->addCommand(commands);
|
||||||
} else {
|
} else {
|
||||||
logger->error(MSG_VERIFICATION_FAILED,
|
logger->error(MSG_VERIFICATION_FAILED,
|
||||||
_requestGroup->getFilePath().c_str());
|
_requestGroup->getDownloadContext()->getBasePath().c_str());
|
||||||
std::deque<Command*> commands;
|
std::deque<Command*> commands;
|
||||||
_entry->onDownloadIncomplete(commands,_e);
|
_entry->onDownloadIncomplete(commands,_e);
|
||||||
_e->addCommand(commands);
|
_e->addCommand(commands);
|
||||||
|
@ -86,7 +87,7 @@ bool CheckIntegrityCommand::handleException(Exception& e)
|
||||||
_e->_checkIntegrityMan->dropPickedEntry();
|
_e->_checkIntegrityMan->dropPickedEntry();
|
||||||
logger->error(MSG_FILE_VALIDATION_FAILURE, e, cuid);
|
logger->error(MSG_FILE_VALIDATION_FAILURE, e, cuid);
|
||||||
logger->error(MSG_DOWNLOAD_NOT_COMPLETE,
|
logger->error(MSG_DOWNLOAD_NOT_COMPLETE,
|
||||||
cuid, _requestGroup->getFilePath().c_str());
|
cuid, _requestGroup->getDownloadContext()->getBasePath().c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "FileAllocationEntry.h"
|
#include "FileAllocationEntry.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "ChecksumCheckIntegrityEntry.h"
|
#include "ChecksumCheckIntegrityEntry.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "SingleFileDownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
#include "IteratableChecksumValidator.h"
|
#include "IteratableChecksumValidator.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
|
@ -49,18 +49,15 @@ ChecksumCheckIntegrityEntry::~ChecksumCheckIntegrityEntry() {}
|
||||||
|
|
||||||
bool ChecksumCheckIntegrityEntry::isValidationReady()
|
bool ChecksumCheckIntegrityEntry::isValidationReady()
|
||||||
{
|
{
|
||||||
SingleFileDownloadContextHandle dctx
|
return !_requestGroup->getDownloadContext()->getChecksum().empty() &&
|
||||||
(dynamic_pointer_cast<SingleFileDownloadContext>(_requestGroup->getDownloadContext()));
|
!_requestGroup->getDownloadContext()->getChecksumHashAlgo().empty();
|
||||||
return !dctx.isNull() && dctx->getChecksum().size() > 0 &&
|
|
||||||
dctx->getChecksumHashAlgo().size() > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChecksumCheckIntegrityEntry::initValidator()
|
void ChecksumCheckIntegrityEntry::initValidator()
|
||||||
{
|
{
|
||||||
SingleFileDownloadContextHandle dctx
|
_validator.reset(new IteratableChecksumValidator
|
||||||
(dynamic_pointer_cast<SingleFileDownloadContext>(_requestGroup->getDownloadContext()));
|
(_requestGroup->getDownloadContext(),
|
||||||
_validator.reset(new IteratableChecksumValidator(dctx,
|
_requestGroup->getPieceStorage()));
|
||||||
_requestGroup->getPieceStorage()));
|
|
||||||
_validator->init();
|
_validator->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,9 @@
|
||||||
#include "CheckIntegrityMan.h"
|
#include "CheckIntegrityMan.h"
|
||||||
#include "CheckIntegrityEntry.h"
|
#include "CheckIntegrityEntry.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
# include "BtContext.h"
|
# include "bittorrent_helper.h"
|
||||||
# include "Peer.h"
|
# include "Peer.h"
|
||||||
# include "PeerStorage.h"
|
# include "PeerStorage.h"
|
||||||
# include "BtRegistry.h"
|
# include "BtRegistry.h"
|
||||||
|
@ -83,10 +84,8 @@ static void printProgress
|
||||||
<< "#" << rg->getGID() << " ";
|
<< "#" << rg->getGID() << " ";
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
SharedHandle<BtContext> btctx =
|
if(rg->getDownloadContext()->hasAttribute(bittorrent::BITTORRENT) &&
|
||||||
dynamic_pointer_cast<BtContext>(rg->getDownloadContext());
|
rg->downloadFinished()) {
|
||||||
|
|
||||||
if(!btctx.isNull() && rg->downloadFinished()) {
|
|
||||||
o << "SEEDING" << "(" << "ratio:";
|
o << "SEEDING" << "(" << "ratio:";
|
||||||
if(rg->getCompletedLength() > 0) {
|
if(rg->getCompletedLength() > 0) {
|
||||||
o << std::fixed << std::setprecision(1)
|
o << std::fixed << std::setprecision(1)
|
||||||
|
@ -114,9 +113,11 @@ static void printProgress
|
||||||
<< "CN:"
|
<< "CN:"
|
||||||
<< rg->getNumConnection();
|
<< rg->getNumConnection();
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
if(!btctx.isNull()) {
|
if(rg->getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) {
|
||||||
|
const BDE& torrentAttrs =
|
||||||
|
rg->getDownloadContext()->getAttribute(bittorrent::BITTORRENT);
|
||||||
SharedHandle<PeerStorage> ps =
|
SharedHandle<PeerStorage> ps =
|
||||||
e->getBtRegistry()->get(btctx->getInfoHashAsString())._peerStorage;
|
e->getBtRegistry()->get(torrentAttrs[bittorrent::INFO_HASH].s())._peerStorage;
|
||||||
std::deque<SharedHandle<Peer> > peers;
|
std::deque<SharedHandle<Peer> > peers;
|
||||||
ps->getActivePeers(peers);
|
ps->getActivePeers(peers);
|
||||||
o << " " << "SEED:"
|
o << " " << "SEED:"
|
||||||
|
@ -155,7 +156,7 @@ public:
|
||||||
{
|
{
|
||||||
const char SEP_CHAR = '-';
|
const char SEP_CHAR = '-';
|
||||||
printProgress(std::cout, rg, _e);
|
printProgress(std::cout, rg, _e);
|
||||||
const std::deque<SharedHandle<FileEntry> >& fileEntries =
|
const std::vector<SharedHandle<FileEntry> >& fileEntries =
|
||||||
rg->getDownloadContext()->getFileEntries();
|
rg->getDownloadContext()->getFileEntries();
|
||||||
std::cout << "\n"
|
std::cout << "\n"
|
||||||
<< "FILE: ";
|
<< "FILE: ";
|
||||||
|
|
|
@ -34,9 +34,9 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "ContentTypeRequestGroupCriteria.h"
|
#include "ContentTypeRequestGroupCriteria.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "SingleFileDownloadContext.h"
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -49,15 +49,15 @@ ContentTypeRequestGroupCriteria::~ContentTypeRequestGroupCriteria() {}
|
||||||
|
|
||||||
bool ContentTypeRequestGroupCriteria::match(const RequestGroup* requestGroup) const
|
bool ContentTypeRequestGroupCriteria::match(const RequestGroup* requestGroup) const
|
||||||
{
|
{
|
||||||
if(forwardMatch(requestGroup->getFilePath(), _extensions)) {
|
if(requestGroup->getDownloadContext()->getFileEntries().size() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(forwardMatch(requestGroup->getFirstFilePath(), _extensions)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
SingleFileDownloadContextHandle dctx(dynamic_pointer_cast<SingleFileDownloadContext>(requestGroup->getDownloadContext()));
|
return exactMatch
|
||||||
if(dctx.isNull()) {
|
(requestGroup->getDownloadContext()->getFirstFileEntry()->getContentType(),
|
||||||
return false;
|
_contentTypes);
|
||||||
} else {
|
|
||||||
return exactMatch(dctx->getContentType(), _contentTypes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,21 +40,20 @@
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "DHTNodeLookupEntry.h"
|
#include "DHTNodeLookupEntry.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "BtRuntime.h"
|
#include "BtRuntime.h"
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DHTGetPeersCommand::DHTGetPeersCommand(int32_t cuid,
|
DHTGetPeersCommand::DHTGetPeersCommand(int32_t cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e):
|
||||||
const BtContextHandle& ctx):
|
|
||||||
Command(cuid),
|
Command(cuid),
|
||||||
_requestGroup(requestGroup),
|
_requestGroup(requestGroup),
|
||||||
_btContext(ctx),
|
|
||||||
_e(e),
|
_e(e),
|
||||||
_numRetry(0),
|
_numRetry(0),
|
||||||
_lastGetPeerTime(0)
|
_lastGetPeerTime(0)
|
||||||
|
@ -76,9 +75,9 @@ bool DHTGetPeersCommand::execute()
|
||||||
((_numRetry > 0 && _lastGetPeerTime.elapsed(RETRY_INTERVAL)) ||
|
((_numRetry > 0 && _lastGetPeerTime.elapsed(RETRY_INTERVAL)) ||
|
||||||
_lastGetPeerTime.elapsed(GET_PEER_INTERVAL))) {
|
_lastGetPeerTime.elapsed(GET_PEER_INTERVAL))) {
|
||||||
logger->debug("Issuing PeerLookup for infoHash=%s",
|
logger->debug("Issuing PeerLookup for infoHash=%s",
|
||||||
_btContext->getInfoHashAsString().c_str());
|
bittorrent::getInfoHashString(_requestGroup->getDownloadContext()).c_str());
|
||||||
_task = _taskFactory->createPeerLookupTask(_btContext, _btRuntime,
|
_task = _taskFactory->createPeerLookupTask
|
||||||
_peerStorage);
|
(_requestGroup->getDownloadContext(), _btRuntime, _peerStorage);
|
||||||
_taskQueue->addPeriodicTask2(_task);
|
_taskQueue->addPeriodicTask2(_task);
|
||||||
} else if(!_task.isNull() && _task->finished()) {
|
} else if(!_task.isNull() && _task->finished()) {
|
||||||
_lastGetPeerTime.reset();
|
_lastGetPeerTime.reset();
|
||||||
|
|
|
@ -47,7 +47,6 @@ class DHTTaskFactory;
|
||||||
class DHTTask;
|
class DHTTask;
|
||||||
class DownloadEngine;
|
class DownloadEngine;
|
||||||
class RequestGroup;
|
class RequestGroup;
|
||||||
class BtContext;
|
|
||||||
class BtRuntime;
|
class BtRuntime;
|
||||||
class PeerStorage;
|
class PeerStorage;
|
||||||
|
|
||||||
|
@ -61,8 +60,6 @@ private:
|
||||||
|
|
||||||
RequestGroup* _requestGroup;
|
RequestGroup* _requestGroup;
|
||||||
|
|
||||||
SharedHandle<BtContext> _btContext;
|
|
||||||
|
|
||||||
SharedHandle<BtRuntime> _btRuntime;
|
SharedHandle<BtRuntime> _btRuntime;
|
||||||
|
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
|
@ -80,8 +77,7 @@ private:
|
||||||
Time _lastGetPeerTime;
|
Time _lastGetPeerTime;
|
||||||
public:
|
public:
|
||||||
DHTGetPeersCommand(int32_t cuid, RequestGroup* requestGroup,
|
DHTGetPeersCommand(int32_t cuid, RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e);
|
||||||
const SharedHandle<BtContext>& ctx);
|
|
||||||
|
|
||||||
virtual ~DHTGetPeersCommand();
|
virtual ~DHTGetPeersCommand();
|
||||||
|
|
||||||
|
|
|
@ -43,15 +43,15 @@
|
||||||
#include "DHTMessageCallback.h"
|
#include "DHTMessageCallback.h"
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
#include "BtRuntime.h"
|
#include "BtRuntime.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "DHTBucket.h"
|
#include "DHTBucket.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DHTPeerLookupTask::DHTPeerLookupTask(const SharedHandle<BtContext>& btContext):
|
DHTPeerLookupTask::DHTPeerLookupTask
|
||||||
DHTAbstractNodeLookupTask(btContext->getInfoHash()),
|
(const SharedHandle<DownloadContext>& downloadContext):
|
||||||
_ctx(btContext) {}
|
DHTAbstractNodeLookupTask(bittorrent::getInfoHash(downloadContext)) {}
|
||||||
|
|
||||||
void
|
void
|
||||||
DHTPeerLookupTask::getNodesFromMessage(std::deque<SharedHandle<DHTNode> >& nodes,
|
DHTPeerLookupTask::getNodesFromMessage(std::deque<SharedHandle<DHTNode> >& nodes,
|
||||||
|
@ -92,11 +92,11 @@ void DHTPeerLookupTask::onFinish()
|
||||||
if((*i)->_used) {
|
if((*i)->_used) {
|
||||||
const SharedHandle<DHTNode>& node = (*i)->_node;
|
const SharedHandle<DHTNode>& node = (*i)->_node;
|
||||||
SharedHandle<DHTMessage> m =
|
SharedHandle<DHTMessage> m =
|
||||||
_factory->createAnnouncePeerMessage(node,
|
_factory->createAnnouncePeerMessage
|
||||||
_ctx->getInfoHash(),
|
(node,
|
||||||
_btRuntime->getListenPort(),
|
_targetID, // this is infoHash
|
||||||
_tokenStorage[Util::toHex(node->getID(),
|
_btRuntime->getListenPort(),
|
||||||
DHT_ID_LENGTH)]);
|
_tokenStorage[Util::toHex(node->getID(), DHT_ID_LENGTH)]);
|
||||||
_dispatcher->addMessageToQueue(m);
|
_dispatcher->addMessageToQueue(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
class DownloadContext;
|
||||||
class Peer;
|
class Peer;
|
||||||
class PeerStorage;
|
class PeerStorage;
|
||||||
class BtRuntime;
|
class BtRuntime;
|
||||||
|
@ -51,13 +51,11 @@ private:
|
||||||
|
|
||||||
std::deque<SharedHandle<Peer> > _peers;
|
std::deque<SharedHandle<Peer> > _peers;
|
||||||
|
|
||||||
SharedHandle<BtContext> _ctx;
|
|
||||||
|
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
|
|
||||||
SharedHandle<BtRuntime> _btRuntime;
|
SharedHandle<BtRuntime> _btRuntime;
|
||||||
public:
|
public:
|
||||||
DHTPeerLookupTask(const SharedHandle<BtContext>& btContext);
|
DHTPeerLookupTask(const SharedHandle<DownloadContext>& downloadContext);
|
||||||
|
|
||||||
virtual void getNodesFromMessage(std::deque<SharedHandle<DHTNode> >& nodes,
|
virtual void getNodesFromMessage(std::deque<SharedHandle<DHTNode> >& nodes,
|
||||||
const SharedHandle<DHTMessage>& message);
|
const SharedHandle<DHTMessage>& message);
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
class DownloadContext;
|
||||||
class BtRuntime;
|
class BtRuntime;
|
||||||
class PeerStorage;
|
class PeerStorage;
|
||||||
class DHTTask;
|
class DHTTask;
|
||||||
|
@ -61,7 +61,7 @@ public:
|
||||||
virtual SharedHandle<DHTTask> createBucketRefreshTask() = 0;
|
virtual SharedHandle<DHTTask> createBucketRefreshTask() = 0;
|
||||||
|
|
||||||
virtual SharedHandle<DHTTask>
|
virtual SharedHandle<DHTTask>
|
||||||
createPeerLookupTask(const SharedHandle<BtContext>& ctx,
|
createPeerLookupTask(const SharedHandle<DownloadContext>& ctx,
|
||||||
const SharedHandle<BtRuntime>& btRuntime,
|
const SharedHandle<BtRuntime>& btRuntime,
|
||||||
const SharedHandle<PeerStorage>& peerStorage) = 0;
|
const SharedHandle<PeerStorage>& peerStorage) = 0;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@
|
||||||
#include "DHTReplaceNodeTask.h"
|
#include "DHTReplaceNodeTask.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "DHTNodeLookupEntry.h"
|
#include "DHTNodeLookupEntry.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
#include "BtRuntime.h"
|
#include "BtRuntime.h"
|
||||||
#include "DHTMessageCallback.h"
|
#include "DHTMessageCallback.h"
|
||||||
|
@ -85,7 +84,7 @@ DHTTaskFactoryImpl::createBucketRefreshTask()
|
||||||
|
|
||||||
SharedHandle<DHTTask>
|
SharedHandle<DHTTask>
|
||||||
DHTTaskFactoryImpl::createPeerLookupTask
|
DHTTaskFactoryImpl::createPeerLookupTask
|
||||||
(const SharedHandle<BtContext>& ctx,
|
(const SharedHandle<DownloadContext>& ctx,
|
||||||
const SharedHandle<BtRuntime>& btRuntime,
|
const SharedHandle<BtRuntime>& btRuntime,
|
||||||
const SharedHandle<PeerStorage>& peerStorage)
|
const SharedHandle<PeerStorage>& peerStorage)
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,7 +77,7 @@ public:
|
||||||
virtual SharedHandle<DHTTask> createBucketRefreshTask();
|
virtual SharedHandle<DHTTask> createBucketRefreshTask();
|
||||||
|
|
||||||
virtual SharedHandle<DHTTask>
|
virtual SharedHandle<DHTTask>
|
||||||
createPeerLookupTask(const SharedHandle<BtContext>& ctx,
|
createPeerLookupTask(const SharedHandle<DownloadContext>& ctx,
|
||||||
const SharedHandle<BtRuntime>& btRuntime,
|
const SharedHandle<BtRuntime>& btRuntime,
|
||||||
const SharedHandle<PeerStorage>& peerStorage);
|
const SharedHandle<PeerStorage>& peerStorage);
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "SimpleRandomizer.h"
|
#include "SimpleRandomizer.h"
|
||||||
#include "BtContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "BtRuntime.h"
|
#include "BtRuntime.h"
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
|
@ -51,19 +51,21 @@
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
#include "bencode.h"
|
#include "bencode.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DefaultBtAnnounce::DefaultBtAnnounce(const BtContextHandle& btContext,
|
DefaultBtAnnounce::DefaultBtAnnounce
|
||||||
const Option* option):
|
(const SharedHandle<DownloadContext>& downloadContext,
|
||||||
btContext(btContext),
|
const Option* option):
|
||||||
|
_downloadContext(downloadContext),
|
||||||
trackers(0),
|
trackers(0),
|
||||||
interval(DEFAULT_ANNOUNCE_INTERVAL),
|
interval(DEFAULT_ANNOUNCE_INTERVAL),
|
||||||
minInterval(DEFAULT_ANNOUNCE_INTERVAL),
|
minInterval(DEFAULT_ANNOUNCE_INTERVAL),
|
||||||
_userDefinedInterval(0),
|
_userDefinedInterval(0),
|
||||||
complete(0),
|
complete(0),
|
||||||
incomplete(0),
|
incomplete(0),
|
||||||
announceList(btContext->getAnnounceTiers()),
|
announceList(downloadContext->getAttribute(bittorrent::BITTORRENT)[bittorrent::ANNOUNCE_LIST]),
|
||||||
option(option),
|
option(option),
|
||||||
logger(LogFactory::getInstance()),
|
logger(LogFactory::getInstance()),
|
||||||
_randomizer(SimpleRandomizer::getInstance())
|
_randomizer(SimpleRandomizer::getInstance())
|
||||||
|
@ -145,10 +147,10 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
||||||
std::string url = announceList.getAnnounce();
|
std::string url = announceList.getAnnounce();
|
||||||
url += uriHasQuery(url) ? "&" : "?";
|
url += uriHasQuery(url) ? "&" : "?";
|
||||||
url += "info_hash=";
|
url += "info_hash=";
|
||||||
url += Util::torrentUrlencode(btContext->getInfoHash(),
|
url += Util::torrentUrlencode(bittorrent::getInfoHash(_downloadContext),
|
||||||
btContext->getInfoHashLength());
|
INFO_HASH_LENGTH);
|
||||||
url += "&peer_id=";
|
url += "&peer_id=";
|
||||||
url += Util::torrentUrlencode(btContext->getPeerId(), 20);
|
url += Util::torrentUrlencode(bittorrent::getStaticPeerId(), PEER_ID_LENGTH);
|
||||||
url += "&uploaded=";
|
url += "&uploaded=";
|
||||||
url += Util::uitos(stat.getSessionUploadLength());
|
url += Util::uitos(stat.getSessionUploadLength());
|
||||||
url += "&downloaded=";
|
url += "&downloaded=";
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
class DownloadContext;
|
||||||
class Option;
|
class Option;
|
||||||
class Logger;
|
class Logger;
|
||||||
class BtRuntime;
|
class BtRuntime;
|
||||||
|
@ -51,7 +51,7 @@ class Randomizer;
|
||||||
|
|
||||||
class DefaultBtAnnounce : public BtAnnounce {
|
class DefaultBtAnnounce : public BtAnnounce {
|
||||||
private:
|
private:
|
||||||
SharedHandle<BtContext> btContext;
|
SharedHandle<DownloadContext> _downloadContext;
|
||||||
unsigned int trackers;
|
unsigned int trackers;
|
||||||
Time prevAnnounceTime;
|
Time prevAnnounceTime;
|
||||||
time_t interval;
|
time_t interval;
|
||||||
|
@ -69,7 +69,7 @@ private:
|
||||||
SharedHandle<PieceStorage> pieceStorage;
|
SharedHandle<PieceStorage> pieceStorage;
|
||||||
SharedHandle<PeerStorage> peerStorage;
|
SharedHandle<PeerStorage> peerStorage;
|
||||||
public:
|
public:
|
||||||
DefaultBtAnnounce(const SharedHandle<BtContext>& btContext,
|
DefaultBtAnnounce(const SharedHandle<DownloadContext>& downloadContext,
|
||||||
const Option* option);
|
const Option* option);
|
||||||
|
|
||||||
virtual ~DefaultBtAnnounce();
|
virtual ~DefaultBtAnnounce();
|
||||||
|
|
|
@ -1,577 +0,0 @@
|
||||||
/* <!-- 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
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* 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 "DefaultBtContext.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <ostream>
|
|
||||||
#include <functional>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "DlAbortEx.h"
|
|
||||||
#include "Util.h"
|
|
||||||
#include "MessageDigestHelper.h"
|
|
||||||
#include "a2netcompat.h"
|
|
||||||
#include "AnnounceTier.h"
|
|
||||||
#include "SimpleRandomizer.h"
|
|
||||||
#include "LogFactory.h"
|
|
||||||
#include "Logger.h"
|
|
||||||
#include "FileEntry.h"
|
|
||||||
#include "message.h"
|
|
||||||
#include "PeerMessageUtil.h"
|
|
||||||
#include "StringFormat.h"
|
|
||||||
#include "A2STR.h"
|
|
||||||
#include "bencode.h"
|
|
||||||
#include "a2functional.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_NAME("name");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_NAME_UTF8("name.utf-8");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_FILES("files");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_LENGTH("length");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_PATH("path");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_PATH_UTF8("path.utf-8");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_INFO("info");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_PIECES("pieces");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_PIECE_LENGTH("piece length");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_PRIVATE("private");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_PRIVATE_ON("1");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_URL_LIST("url-list");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_ANNOUNCE("announce");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_ANNOUNCE_LIST("announce-list");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::C_NODES("nodes");
|
|
||||||
|
|
||||||
const std::string DefaultBtContext::DEFAULT_PEER_ID_PREFIX("-aria2-");
|
|
||||||
|
|
||||||
DefaultBtContext::DefaultBtContext():_peerIdPrefix(DEFAULT_PEER_ID_PREFIX),
|
|
||||||
_randomizer(SimpleRandomizer::getInstance()),
|
|
||||||
_ownerRequestGroup(0),
|
|
||||||
_logger(LogFactory::getInstance()) {}
|
|
||||||
|
|
||||||
DefaultBtContext::~DefaultBtContext() {}
|
|
||||||
|
|
||||||
std::string DefaultBtContext::generatePeerId() const {
|
|
||||||
std::string peerId = _peerIdPrefix;
|
|
||||||
peerId += Util::randomAlpha(20-_peerIdPrefix.size(), _randomizer);
|
|
||||||
if(peerId.size() > 20) {
|
|
||||||
peerId.erase(20);
|
|
||||||
}
|
|
||||||
return peerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsigned char* DefaultBtContext::getInfoHash() const {
|
|
||||||
return infoHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t DefaultBtContext::getInfoHashLength() const {
|
|
||||||
return INFO_HASH_LENGTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& DefaultBtContext::getInfoHashAsString() const {
|
|
||||||
return infoHashString;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::clear() {
|
|
||||||
memset(infoHash, 0, INFO_HASH_LENGTH);
|
|
||||||
infoHashString = A2STR::NIL;
|
|
||||||
pieceHashes.clear();
|
|
||||||
_fileEntries.clear();
|
|
||||||
totalLength = 0;
|
|
||||||
pieceLength = 0;
|
|
||||||
fileMode = BtContext::SINGLE;
|
|
||||||
numPieces = 0;
|
|
||||||
name = A2STR::NIL;
|
|
||||||
announceTiers.clear();
|
|
||||||
_private = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::extractPieceHash(const std::string& hashData,
|
|
||||||
size_t hashLength)
|
|
||||||
{
|
|
||||||
size_t numPieces = hashData.size()/hashLength;
|
|
||||||
for(size_t i = 0; i < numPieces; ++i) {
|
|
||||||
pieceHashes.push_back(Util::toHex(hashData.data()+i*hashLength,
|
|
||||||
hashLength));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::extractFileEntries(const BDE& infoDict,
|
|
||||||
const std::string& defaultName,
|
|
||||||
const std::string& overrideName,
|
|
||||||
const std::deque<std::string>& urlList)
|
|
||||||
{
|
|
||||||
if(overrideName.empty()) {
|
|
||||||
std::string nameKey;
|
|
||||||
if(infoDict.containsKey(C_NAME_UTF8)) {
|
|
||||||
nameKey = C_NAME_UTF8;
|
|
||||||
} else {
|
|
||||||
nameKey = C_NAME;
|
|
||||||
}
|
|
||||||
const BDE& nameData = infoDict[nameKey];
|
|
||||||
if(nameData.isString()) {
|
|
||||||
name = nameData.s();
|
|
||||||
} else {
|
|
||||||
name = strconcat(File(defaultName).getBasename(), ".file");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
name = overrideName;
|
|
||||||
}
|
|
||||||
const BDE& filesList = infoDict[C_FILES];
|
|
||||||
if(filesList.isList()) {
|
|
||||||
uint64_t length = 0;
|
|
||||||
off_t offset = 0;
|
|
||||||
// multi-file mode
|
|
||||||
fileMode = BtContext::MULTI;
|
|
||||||
for(BDE::List::const_iterator itr = filesList.listBegin();
|
|
||||||
itr != filesList.listEnd(); ++itr) {
|
|
||||||
const BDE& fileDict = *itr;
|
|
||||||
if(!fileDict.isDict()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const BDE& fileLengthData = fileDict[C_LENGTH];
|
|
||||||
if(!fileLengthData.isInteger()) {
|
|
||||||
throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
|
|
||||||
C_LENGTH.c_str()).str());
|
|
||||||
}
|
|
||||||
length += fileLengthData.i();
|
|
||||||
|
|
||||||
std::string pathKey;
|
|
||||||
if(fileDict.containsKey(C_PATH_UTF8)) {
|
|
||||||
pathKey = C_PATH_UTF8;
|
|
||||||
} else {
|
|
||||||
pathKey = C_PATH;
|
|
||||||
}
|
|
||||||
const BDE& pathList = fileDict[pathKey];
|
|
||||||
if(!pathList.isList() || pathList.empty()) {
|
|
||||||
throw DL_ABORT_EX("Path is empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> pathelem(pathList.size());
|
|
||||||
std::transform(pathList.listBegin(), pathList.listEnd(), pathelem.begin(),
|
|
||||||
std::mem_fun_ref(&BDE::s));
|
|
||||||
std::string path = name;
|
|
||||||
strappend(path, "/", Util::joinPath(pathelem.begin(), pathelem.end()));
|
|
||||||
// Split path with '/' again because each pathList element can
|
|
||||||
// contain "/" inside.
|
|
||||||
std::deque<std::string> elements;
|
|
||||||
Util::slice(elements, path, '/');
|
|
||||||
path = Util::joinPath(elements.begin(), elements.end());
|
|
||||||
|
|
||||||
std::deque<std::string> uris;
|
|
||||||
std::transform(urlList.begin(), urlList.end(), std::back_inserter(uris),
|
|
||||||
std::bind2nd(std::plus<std::string>(), "/"+path));
|
|
||||||
FileEntryHandle fileEntry(new FileEntry(strconcat(_dir, "/", path),
|
|
||||||
fileLengthData.i(),
|
|
||||||
offset, uris));
|
|
||||||
_fileEntries.push_back(fileEntry);
|
|
||||||
offset += fileEntry->getLength();
|
|
||||||
}
|
|
||||||
totalLength = length;
|
|
||||||
} else {
|
|
||||||
// single-file mode;
|
|
||||||
fileMode = BtContext::SINGLE;
|
|
||||||
const BDE& lengthData = infoDict[C_LENGTH];
|
|
||||||
if(!lengthData.isInteger()) {
|
|
||||||
throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
|
|
||||||
C_LENGTH.c_str()).str());
|
|
||||||
}
|
|
||||||
totalLength = lengthData.i();
|
|
||||||
// Slice path by '/' just in case nasty ".." is included in name
|
|
||||||
std::deque<std::string> pathelems;
|
|
||||||
Util::slice(pathelems, name, '/');
|
|
||||||
|
|
||||||
// For each uri in urlList, if it ends with '/', then
|
|
||||||
// concatenate name to it. Specification just says so.
|
|
||||||
std::deque<std::string> uris;
|
|
||||||
for(std::deque<std::string>::const_iterator i = urlList.begin();
|
|
||||||
i != urlList.end(); ++i) {
|
|
||||||
if(Util::endsWith(*i, "/")) {
|
|
||||||
uris.push_back((*i)+name);
|
|
||||||
} else {
|
|
||||||
uris.push_back(*i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedHandle<FileEntry> fileEntry
|
|
||||||
(new FileEntry(strconcat(_dir, "/",
|
|
||||||
Util::joinPath(pathelems.begin(),
|
|
||||||
pathelems.end())),
|
|
||||||
totalLength, 0, uris));
|
|
||||||
_fileEntries.push_back(fileEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::extractAnnounceURI(const BDE& announceData)
|
|
||||||
{
|
|
||||||
// Assumed announceData is string
|
|
||||||
std::deque<std::string> urls;
|
|
||||||
urls.push_back(Util::trim(announceData.s()));
|
|
||||||
announceTiers.push_back(AnnounceTierHandle(new AnnounceTier(urls)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::extractAnnounceList(const BDE& announceList)
|
|
||||||
{
|
|
||||||
// Assumed announceList is string
|
|
||||||
for(BDE::List::const_iterator itr = announceList.listBegin();
|
|
||||||
itr != announceList.listEnd(); ++itr) {
|
|
||||||
const BDE& elemList = *itr;
|
|
||||||
if(!elemList.isList()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
std::deque<std::string> urls;
|
|
||||||
for(BDE::List::const_iterator elemItr = elemList.listBegin();
|
|
||||||
elemItr != elemList.listEnd(); ++elemItr) {
|
|
||||||
const BDE& url = (*elemItr);
|
|
||||||
if(url.isString()) {
|
|
||||||
urls.push_back(Util::trim(url.s()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!urls.empty()) {
|
|
||||||
AnnounceTierHandle tier(new AnnounceTier(urls));
|
|
||||||
announceTiers.push_back(tier);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::extractAnnounce(const BDE& rootDict)
|
|
||||||
{
|
|
||||||
const BDE& announceList = rootDict[C_ANNOUNCE_LIST];
|
|
||||||
if(announceList.isList()) {
|
|
||||||
extractAnnounceList(announceList);
|
|
||||||
} else {
|
|
||||||
const BDE& announce = rootDict[C_ANNOUNCE];
|
|
||||||
if(announce.isString()) {
|
|
||||||
extractAnnounceURI(announce);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::extractUrlList(std::deque<std::string>& uris,
|
|
||||||
const BDE& bde)
|
|
||||||
{
|
|
||||||
if(bde.isList()) {
|
|
||||||
for(BDE::List::const_iterator itr = bde.listBegin();
|
|
||||||
itr != bde.listEnd(); ++itr) {
|
|
||||||
if((*itr).isString()) {
|
|
||||||
uris.push_back((*itr).s());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if(bde.isString()) {
|
|
||||||
uris.push_back(bde.s());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::extractNodes(const BDE& nodesList)
|
|
||||||
{
|
|
||||||
if(!nodesList.isList()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for(BDE::List::const_iterator i = nodesList.listBegin();
|
|
||||||
i != nodesList.listEnd(); ++i) {
|
|
||||||
const BDE& addrPairList = (*i);
|
|
||||||
if(!addrPairList.isList() || addrPairList.size() != 2) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const BDE& hostname = addrPairList[0];
|
|
||||||
if(!hostname.isString()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(Util::trim(hostname.s()).empty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const BDE& port = addrPairList[1];
|
|
||||||
if(!port.isInteger() || !(0 < port.i() && port.i() < 65536)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
_nodes.push_back(std::pair<std::string, uint16_t>(hostname.s(), port.i()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::loadFromMemory(const unsigned char* content,
|
|
||||||
size_t length,
|
|
||||||
const std::string& defaultName,
|
|
||||||
const std::string& overrideName)
|
|
||||||
{
|
|
||||||
processRootDictionary(bencode::decode(content, length), defaultName,
|
|
||||||
overrideName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::load(const std::string& torrentFile,
|
|
||||||
const std::string& overrideName) {
|
|
||||||
processRootDictionary(bencode::decodeFromFile(torrentFile), torrentFile,
|
|
||||||
overrideName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::processRootDictionary(const BDE& rootDict,
|
|
||||||
const std::string& defaultName,
|
|
||||||
const std::string& overrideName)
|
|
||||||
{
|
|
||||||
clear();
|
|
||||||
if(!rootDict.isDict()) {
|
|
||||||
throw DL_ABORT_EX("torrent file does not contain a root dictionary.");
|
|
||||||
}
|
|
||||||
const BDE& infoDict = rootDict[C_INFO];
|
|
||||||
if(!infoDict.isDict()) {
|
|
||||||
throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
|
|
||||||
C_INFO.c_str()).str());
|
|
||||||
}
|
|
||||||
// retrieve infoHash
|
|
||||||
std::string encodedInfoDict = bencode::encode(infoDict);
|
|
||||||
MessageDigestHelper::digest(infoHash, INFO_HASH_LENGTH,
|
|
||||||
MessageDigestContext::SHA1,
|
|
||||||
encodedInfoDict.data(),
|
|
||||||
encodedInfoDict.size());
|
|
||||||
infoHashString = Util::toHex(infoHash, INFO_HASH_LENGTH);
|
|
||||||
// calculate the number of pieces
|
|
||||||
const BDE& piecesData = infoDict[C_PIECES];
|
|
||||||
if(!piecesData.isString()) {
|
|
||||||
throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
|
|
||||||
C_PIECES.c_str()).str());
|
|
||||||
}
|
|
||||||
if(piecesData.s().empty()) {
|
|
||||||
throw DL_ABORT_EX("The length of piece hash is 0.");
|
|
||||||
}
|
|
||||||
numPieces = piecesData.s().size()/PIECE_HASH_LENGTH;
|
|
||||||
if(numPieces == 0) {
|
|
||||||
throw DL_ABORT_EX("The number of pieces is 0.");
|
|
||||||
}
|
|
||||||
// retrieve piece length
|
|
||||||
const BDE& pieceLengthData = infoDict[C_PIECE_LENGTH];
|
|
||||||
if(!pieceLengthData.isInteger()) {
|
|
||||||
throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
|
|
||||||
C_PIECE_LENGTH.c_str()).str());
|
|
||||||
}
|
|
||||||
pieceLength = pieceLengthData.i();
|
|
||||||
// retrieve piece hashes
|
|
||||||
extractPieceHash(piecesData.s(), PIECE_HASH_LENGTH);
|
|
||||||
// private flag
|
|
||||||
const BDE& privateData = infoDict[C_PRIVATE];
|
|
||||||
if(privateData.isInteger()) {
|
|
||||||
_private = (privateData.i() == 1);
|
|
||||||
}
|
|
||||||
// retrieve uri-list.
|
|
||||||
// This implemantation obeys HTTP-Seeding specification:
|
|
||||||
// see http://www.getright.com/seedtorrent.html
|
|
||||||
std::deque<std::string> urlList;
|
|
||||||
extractUrlList(urlList, rootDict[C_URL_LIST]);
|
|
||||||
|
|
||||||
// retrieve file entries
|
|
||||||
extractFileEntries(infoDict, defaultName, overrideName, urlList);
|
|
||||||
if((totalLength+pieceLength-1)/pieceLength != numPieces) {
|
|
||||||
throw DL_ABORT_EX("Too few/many piece hash.");
|
|
||||||
}
|
|
||||||
// retrieve announce
|
|
||||||
extractAnnounce(rootDict);
|
|
||||||
// retrieve nodes
|
|
||||||
extractNodes(rootDict[C_NODES]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& DefaultBtContext::getPieceHash(size_t index) const {
|
|
||||||
if(index < numPieces) {
|
|
||||||
return pieceHashes[index];
|
|
||||||
} else {
|
|
||||||
return A2STR::NIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t DefaultBtContext::getTotalLength() const {
|
|
||||||
return totalLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DefaultBtContext::knowsTotalLength() const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
BtContext::FILE_MODE DefaultBtContext::getFileMode() const {
|
|
||||||
return fileMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& DefaultBtContext::getPieceHashAlgo() const
|
|
||||||
{
|
|
||||||
return MessageDigestContext::SHA1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::deque<SharedHandle<AnnounceTier> >&
|
|
||||||
DefaultBtContext::getAnnounceTiers() const
|
|
||||||
{
|
|
||||||
return announceTiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& DefaultBtContext::getName() const {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t DefaultBtContext::getPieceLength() const {
|
|
||||||
return pieceLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t DefaultBtContext::getNumPieces() const {
|
|
||||||
return numPieces;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string DefaultBtContext::getActualBasePath() const
|
|
||||||
{
|
|
||||||
if(_fileEntries.size() == 1) {
|
|
||||||
return _fileEntries.front()->getPath();
|
|
||||||
} else {
|
|
||||||
return strconcat(_dir, "/", name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::computeFastSet
|
|
||||||
(std::deque<size_t>& fastSet, const std::string& ipaddr, size_t fastSetSize)
|
|
||||||
{
|
|
||||||
unsigned char compact[6];
|
|
||||||
if(!PeerMessageUtil::createcompact(compact, ipaddr, 0)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(numPieces < fastSetSize) {
|
|
||||||
fastSetSize = numPieces;
|
|
||||||
}
|
|
||||||
unsigned char tx[24];
|
|
||||||
memcpy(tx, compact, 4);
|
|
||||||
if((tx[0] & 0x80) == 0 || (tx[0] & 0x40) == 0) {
|
|
||||||
tx[2] = 0x00;
|
|
||||||
tx[3] = 0x00;
|
|
||||||
} else {
|
|
||||||
tx[3] = 0x00;
|
|
||||||
}
|
|
||||||
memcpy(tx+4, infoHash, 20);
|
|
||||||
unsigned char x[20];
|
|
||||||
MessageDigestHelper::digest(x, sizeof(x), MessageDigestContext::SHA1, tx, 24);
|
|
||||||
while(fastSet.size() < fastSetSize) {
|
|
||||||
for(size_t i = 0; i < 5 && fastSet.size() < fastSetSize; ++i) {
|
|
||||||
size_t j = i*4;
|
|
||||||
uint32_t ny;
|
|
||||||
memcpy(&ny, x+j, 4);
|
|
||||||
uint32_t y = ntohl(ny);
|
|
||||||
size_t index = y%numPieces;
|
|
||||||
if(std::find(fastSet.begin(), fastSet.end(), index) == fastSet.end()) {
|
|
||||||
fastSet.push_back(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unsigned char temp[20];
|
|
||||||
MessageDigestHelper::digest(temp, sizeof(temp), MessageDigestContext::SHA1, x, sizeof(x));
|
|
||||||
memcpy(x, temp, sizeof(x));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& o, const DefaultBtContext& ctx)
|
|
||||||
{
|
|
||||||
o << "*** BitTorrent File Information ***" << "\n";
|
|
||||||
o << "Mode: " << (ctx.getFileMode() == DownloadContext::SINGLE ? "Single File Torrent":"Multi File Torrent") << "\n";
|
|
||||||
o << "Announce:" << "\n";
|
|
||||||
AnnounceTiers tiers = ctx.getAnnounceTiers();
|
|
||||||
for(AnnounceTiers::const_iterator itr = tiers.begin(); itr != tiers.end(); ++itr) {
|
|
||||||
const AnnounceTierHandle& tier = *itr;
|
|
||||||
for(std::deque<std::string>::const_iterator uriItr = tier->urls.begin(); uriItr != tier->urls.end(); ++uriItr) {
|
|
||||||
o << " " << *uriItr;
|
|
||||||
}
|
|
||||||
o << "\n";
|
|
||||||
}
|
|
||||||
o << "Info Hash: " << ctx.getInfoHashAsString() << "\n";
|
|
||||||
o << "Piece Length: " << Util::abbrevSize(ctx.getPieceLength()) << "B\n";
|
|
||||||
o << "The Number of Pieces: " << ctx.getNumPieces() << "\n";
|
|
||||||
o << "Total Length: " << Util::abbrevSize(ctx.getTotalLength()) << "B\n";
|
|
||||||
if(ctx.getFileMode() == DownloadContext::MULTI) {
|
|
||||||
o << "Name: " << ctx.getName() << "\n";
|
|
||||||
}
|
|
||||||
Util::toStream(o, ctx.getFileEntries());
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::setRandomizer(const RandomizerHandle& randomizer)
|
|
||||||
{
|
|
||||||
_randomizer = randomizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::deque<std::pair<std::string, uint16_t> >&
|
|
||||||
DefaultBtContext::getNodes()
|
|
||||||
{
|
|
||||||
return _nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::setInfoHash(const unsigned char* infoHash)
|
|
||||||
{
|
|
||||||
memcpy(this->infoHash, infoHash, sizeof(this->infoHash));
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::setFilePathWithIndex
|
|
||||||
(size_t index, const std::string& path)
|
|
||||||
{
|
|
||||||
if(0 < index && index <= _fileEntries.size()) {
|
|
||||||
_fileEntries[index-1]->setPath(path);
|
|
||||||
} else {
|
|
||||||
throw DL_ABORT_EX(StringFormat("No such file with index=%u",
|
|
||||||
static_cast<unsigned int>(index)).str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtContext::setFileFilter(IntSequence seq)
|
|
||||||
{
|
|
||||||
std::deque<int32_t> fileIndexes = seq.flush();
|
|
||||||
std::sort(fileIndexes.begin(), fileIndexes.end());
|
|
||||||
fileIndexes.erase(std::unique(fileIndexes.begin(), fileIndexes.end()),
|
|
||||||
fileIndexes.end());
|
|
||||||
|
|
||||||
bool selectAll = fileIndexes.empty() || _fileEntries.size() == 1;
|
|
||||||
|
|
||||||
int32_t index = 1;
|
|
||||||
for(std::deque<SharedHandle<FileEntry> >::const_iterator i =
|
|
||||||
_fileEntries.begin(); i != _fileEntries.end(); ++i, ++index) {
|
|
||||||
(*i)->setRequested
|
|
||||||
(selectAll ||
|
|
||||||
std::binary_search(fileIndexes.begin(), fileIndexes.end(), index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
|
@ -1,232 +0,0 @@
|
||||||
/* <!-- 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
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* 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 --> */
|
|
||||||
#ifndef _D_DEFAULT_BT_CONTEXT_H_
|
|
||||||
#define _D_DEFAULT_BT_CONTEXT_H_
|
|
||||||
|
|
||||||
#include "BtContext.h"
|
|
||||||
|
|
||||||
#include <iosfwd>
|
|
||||||
|
|
||||||
#include "IntSequence.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
class Randomizer;
|
|
||||||
class Logger;
|
|
||||||
class BDE;
|
|
||||||
|
|
||||||
#define INFO_HASH_LENGTH 20
|
|
||||||
#define PIECE_HASH_LENGTH 20
|
|
||||||
|
|
||||||
class DefaultBtContext : public BtContext {
|
|
||||||
private:
|
|
||||||
unsigned char infoHash[INFO_HASH_LENGTH];
|
|
||||||
std::string infoHashString;
|
|
||||||
std::deque<std::string> pieceHashes;
|
|
||||||
FILE_MODE fileMode;
|
|
||||||
uint64_t totalLength;
|
|
||||||
size_t pieceLength;
|
|
||||||
std::string name;
|
|
||||||
size_t numPieces;
|
|
||||||
std::string peerId;
|
|
||||||
std::string _peerIdPrefix;
|
|
||||||
std::deque<SharedHandle<AnnounceTier> > announceTiers;
|
|
||||||
std::deque<std::pair<std::string, uint16_t> > _nodes;
|
|
||||||
SharedHandle<Randomizer> _randomizer;
|
|
||||||
|
|
||||||
RequestGroup* _ownerRequestGroup;
|
|
||||||
|
|
||||||
Logger* _logger;
|
|
||||||
|
|
||||||
static const std::string C_NAME;
|
|
||||||
|
|
||||||
static const std::string C_NAME_UTF8;
|
|
||||||
|
|
||||||
static const std::string C_FILES;
|
|
||||||
|
|
||||||
static const std::string C_LENGTH;
|
|
||||||
|
|
||||||
static const std::string C_PATH;
|
|
||||||
|
|
||||||
static const std::string C_PATH_UTF8;
|
|
||||||
|
|
||||||
static const std::string C_INFO;
|
|
||||||
|
|
||||||
static const std::string C_PIECES;
|
|
||||||
|
|
||||||
static const std::string C_PIECE_LENGTH;
|
|
||||||
|
|
||||||
static const std::string C_PRIVATE;
|
|
||||||
|
|
||||||
// This is just a string "1". Used as a value of "private" flag.
|
|
||||||
static const std::string C_PRIVATE_ON;
|
|
||||||
|
|
||||||
static const std::string C_URL_LIST;
|
|
||||||
|
|
||||||
static const std::string C_ANNOUNCE;
|
|
||||||
|
|
||||||
static const std::string C_ANNOUNCE_LIST;
|
|
||||||
|
|
||||||
static const std::string C_NODES;
|
|
||||||
|
|
||||||
void clear();
|
|
||||||
void extractPieceHash(const std::string& hashData, size_t hashLength);
|
|
||||||
void extractFileEntries(const BDE& infoDic,
|
|
||||||
const std::string& defaultName,
|
|
||||||
const std::string& overrideName,
|
|
||||||
const std::deque<std::string>& urlList);
|
|
||||||
void extractAnnounceURI(const BDE& announceData);
|
|
||||||
void extractAnnounceList(const BDE& announceListData);
|
|
||||||
void extractAnnounce(const BDE& rootDict);
|
|
||||||
|
|
||||||
void extractUrlList(std::deque<std::string>& uris, const BDE& obj);
|
|
||||||
|
|
||||||
void extractNodes(const BDE& nodes);
|
|
||||||
|
|
||||||
void processRootDictionary(const BDE& rootDic,
|
|
||||||
const std::string& defaultName,
|
|
||||||
const std::string& overrideName);
|
|
||||||
|
|
||||||
public:
|
|
||||||
DefaultBtContext();
|
|
||||||
virtual ~DefaultBtContext();
|
|
||||||
|
|
||||||
virtual const unsigned char* getInfoHash() const;
|
|
||||||
|
|
||||||
virtual size_t getInfoHashLength() const;
|
|
||||||
|
|
||||||
virtual const std::string& getInfoHashAsString() const;
|
|
||||||
|
|
||||||
virtual const std::string& getPieceHash(size_t index) const;
|
|
||||||
|
|
||||||
virtual const std::deque<std::string>& getPieceHashes() const
|
|
||||||
{
|
|
||||||
return pieceHashes;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual uint64_t getTotalLength() const;
|
|
||||||
|
|
||||||
virtual bool knowsTotalLength() const;
|
|
||||||
|
|
||||||
virtual FILE_MODE getFileMode() const;
|
|
||||||
|
|
||||||
virtual const std::string& getPieceHashAlgo() const;
|
|
||||||
|
|
||||||
virtual const std::deque<SharedHandle<AnnounceTier> >&
|
|
||||||
getAnnounceTiers() const;
|
|
||||||
|
|
||||||
// Note: Before calling load* function, call setDir() to specify
|
|
||||||
// directory. Setting directory after load* function doesn't change
|
|
||||||
// the output file path.
|
|
||||||
virtual void load(const std::string& torrentFile,
|
|
||||||
const std::string& overrideName = "");
|
|
||||||
|
|
||||||
void loadFromMemory(const unsigned char* content, size_t length,
|
|
||||||
const std::string& defaultName,
|
|
||||||
const std::string& overrideName = "");
|
|
||||||
|
|
||||||
void loadFromMemory(const std::string& context,
|
|
||||||
const std::string& defaultName,
|
|
||||||
const std::string& overrideName = "")
|
|
||||||
{
|
|
||||||
loadFromMemory(reinterpret_cast<const unsigned char*>(context.c_str()),
|
|
||||||
context.size(), defaultName, overrideName);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const std::string& getName() const;
|
|
||||||
|
|
||||||
virtual size_t getPieceLength() const;
|
|
||||||
|
|
||||||
virtual size_t getNumPieces() const;
|
|
||||||
|
|
||||||
virtual std::string getActualBasePath() const;
|
|
||||||
|
|
||||||
virtual const unsigned char* getPeerId() {
|
|
||||||
if(peerId.empty()) {
|
|
||||||
peerId = generatePeerId();
|
|
||||||
}
|
|
||||||
return reinterpret_cast<const unsigned char*>(peerId.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void computeFastSet
|
|
||||||
(std::deque<size_t>& fastSet, const std::string& ipaddr, size_t fastSetSize);
|
|
||||||
|
|
||||||
virtual RequestGroup* getOwnerRequestGroup()
|
|
||||||
{
|
|
||||||
return _ownerRequestGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::deque<std::pair<std::string, uint16_t> >& getNodes();
|
|
||||||
|
|
||||||
virtual void setFileFilter(IntSequence seq);
|
|
||||||
|
|
||||||
std::string generatePeerId() const;
|
|
||||||
|
|
||||||
void setPeerIdPrefix(const std::string& peerIdPrefix)
|
|
||||||
{
|
|
||||||
_peerIdPrefix = peerIdPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for unit test
|
|
||||||
void setInfoHash(const unsigned char* infoHash);
|
|
||||||
|
|
||||||
void setNumPieces(size_t numPieces)
|
|
||||||
{
|
|
||||||
this->numPieces = numPieces;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setOwnerRequestGroup(RequestGroup* owner)
|
|
||||||
{
|
|
||||||
_ownerRequestGroup = owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRandomizer(const SharedHandle<Randomizer>& randomizer);
|
|
||||||
|
|
||||||
// Sets file path for spcified index. index starts from 1. The index
|
|
||||||
// is the same used in BtContext::setFileFilter(). Please note that
|
|
||||||
// path is not the actual file path. The actual file path is
|
|
||||||
// getDir()+"/"+path.
|
|
||||||
void setFilePathWithIndex(size_t index, const std::string& path);
|
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& o, const DefaultBtContext& ctx);
|
|
||||||
|
|
||||||
static const std::string DEFAULT_PEER_ID_PREFIX;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef SharedHandle<DefaultBtContext> DefaultBtContextHandle;
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
||||||
|
|
||||||
#endif // _D_DEFAULT_BT_CONTEXT_H_
|
|
|
@ -54,7 +54,7 @@
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "Piece.h"
|
#include "Piece.h"
|
||||||
#include "BtContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
#include "BtRuntime.h"
|
#include "BtRuntime.h"
|
||||||
|
@ -68,13 +68,15 @@
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "RequestGroupMan.h"
|
#include "RequestGroupMan.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DefaultBtInteractive::DefaultBtInteractive
|
DefaultBtInteractive::DefaultBtInteractive
|
||||||
(const SharedHandle<BtContext>& btContext, const SharedHandle<Peer>& peer)
|
(const SharedHandle<DownloadContext>& downloadContext,
|
||||||
|
const SharedHandle<Peer>& peer)
|
||||||
:
|
:
|
||||||
_btContext(btContext),
|
_downloadContext(downloadContext),
|
||||||
peer(peer),
|
peer(peer),
|
||||||
logger(LogFactory::getInstance()),
|
logger(LogFactory::getInstance()),
|
||||||
allowedFastSetSize(10),
|
allowedFastSetSize(10),
|
||||||
|
@ -88,8 +90,8 @@ DefaultBtInteractive::~DefaultBtInteractive() {}
|
||||||
|
|
||||||
void DefaultBtInteractive::initiateHandshake() {
|
void DefaultBtInteractive::initiateHandshake() {
|
||||||
SharedHandle<BtMessage> message =
|
SharedHandle<BtMessage> message =
|
||||||
messageFactory->createHandshakeMessage(_btContext->getInfoHash(),
|
messageFactory->createHandshakeMessage
|
||||||
_btContext->getPeerId());
|
(bittorrent::getInfoHash(_downloadContext), bittorrent::getStaticPeerId());
|
||||||
dispatcher->addMessageToQueue(message);
|
dispatcher->addMessageToQueue(message);
|
||||||
dispatcher->sendMessages();
|
dispatcher->sendMessages();
|
||||||
}
|
}
|
||||||
|
@ -100,7 +102,7 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
|
||||||
if(message.isNull()) {
|
if(message.isNull()) {
|
||||||
return SharedHandle<BtMessage>();
|
return SharedHandle<BtMessage>();
|
||||||
}
|
}
|
||||||
if(memcmp(message->getPeerId(), _btContext->getPeerId(),
|
if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(),
|
||||||
PEER_ID_LENGTH) == 0) {
|
PEER_ID_LENGTH) == 0) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(StringFormat
|
(StringFormat
|
||||||
|
@ -187,9 +189,12 @@ void DefaultBtInteractive::addBitfieldMessageToQueue() {
|
||||||
|
|
||||||
void DefaultBtInteractive::addAllowedFastMessageToQueue() {
|
void DefaultBtInteractive::addAllowedFastMessageToQueue() {
|
||||||
if(peer->isFastExtensionEnabled()) {
|
if(peer->isFastExtensionEnabled()) {
|
||||||
std::deque<size_t> fastSet;
|
std::vector<size_t> fastSet;
|
||||||
_btContext->computeFastSet(fastSet, peer->ipaddr, allowedFastSetSize);
|
bittorrent::computeFastSet(fastSet, peer->ipaddr,
|
||||||
for(std::deque<size_t>::const_iterator itr = fastSet.begin();
|
_downloadContext->getNumPieces(),
|
||||||
|
bittorrent::getInfoHash(_downloadContext),
|
||||||
|
allowedFastSetSize);
|
||||||
|
for(std::vector<size_t>::const_iterator itr = fastSet.begin();
|
||||||
itr != fastSet.end(); ++itr) {
|
itr != fastSet.end(); ++itr) {
|
||||||
dispatcher->addMessageToQueue
|
dispatcher->addMessageToQueue
|
||||||
(messageFactory->createAllowedFastMessage(*itr));
|
(messageFactory->createAllowedFastMessage(*itr));
|
||||||
|
@ -239,7 +244,7 @@ size_t DefaultBtInteractive::receiveMessages() {
|
||||||
size_t msgcount = 0;
|
size_t msgcount = 0;
|
||||||
for(int i = 0; i < 50; ++i) {
|
for(int i = 0; i < 50; ++i) {
|
||||||
if(_requestGroupMan->doesOverallDownloadSpeedExceed() ||
|
if(_requestGroupMan->doesOverallDownloadSpeedExceed() ||
|
||||||
_btContext->getOwnerRequestGroup()->doesDownloadSpeedExceed()) {
|
_downloadContext->getOwnerRequestGroup()->doesDownloadSpeedExceed()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
BtMessageHandle message = btMessageReceiver->receiveMessage();
|
BtMessageHandle message = btMessageReceiver->receiveMessage();
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
class DownloadContext;
|
||||||
class BtRuntime;
|
class BtRuntime;
|
||||||
class PieceStorage;
|
class PieceStorage;
|
||||||
class PeerStorage;
|
class PeerStorage;
|
||||||
|
@ -97,7 +97,7 @@ class DefaultBtInteractive : public BtInteractive {
|
||||||
private:
|
private:
|
||||||
int32_t cuid;
|
int32_t cuid;
|
||||||
|
|
||||||
SharedHandle<BtContext> _btContext;
|
SharedHandle<DownloadContext> _downloadContext;
|
||||||
|
|
||||||
SharedHandle<BtRuntime> _btRuntime;
|
SharedHandle<BtRuntime> _btRuntime;
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ private:
|
||||||
void addPortMessageToQueue();
|
void addPortMessageToQueue();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DefaultBtInteractive(const SharedHandle<BtContext>& btContext,
|
DefaultBtInteractive(const SharedHandle<DownloadContext>& downloadContext,
|
||||||
const SharedHandle<Peer>& peer);
|
const SharedHandle<Peer>& peer);
|
||||||
|
|
||||||
virtual ~DefaultBtInteractive();
|
virtual ~DefaultBtInteractive();
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
#include "BtChokingEvent.h"
|
#include "BtChokingEvent.h"
|
||||||
#include "BtMessageFactory.h"
|
#include "BtMessageFactory.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "BtContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "BtMessage.h"
|
#include "BtMessage.h"
|
||||||
|
@ -87,7 +87,7 @@ void DefaultBtMessageDispatcher::sendMessages() {
|
||||||
messageQueue.pop_front();
|
messageQueue.pop_front();
|
||||||
if(msg->isUploading() && !msg->isSendingInProgress()) {
|
if(msg->isUploading() && !msg->isSendingInProgress()) {
|
||||||
if(_requestGroupMan->doesOverallUploadSpeedExceed() ||
|
if(_requestGroupMan->doesOverallUploadSpeedExceed() ||
|
||||||
btContext->getOwnerRequestGroup()->doesUploadSpeedExceed()) {
|
_downloadContext->getOwnerRequestGroup()->doesUploadSpeedExceed()) {
|
||||||
tempQueue.push_back(msg);
|
tempQueue.push_back(msg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -412,9 +412,10 @@ void DefaultBtMessageDispatcher::setPeer(const SharedHandle<Peer>& peer)
|
||||||
this->peer = peer;
|
this->peer = peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtMessageDispatcher::setBtContext(const BtContextHandle& btContext)
|
void DefaultBtMessageDispatcher::setDownloadContext
|
||||||
|
(const SharedHandle<DownloadContext>& downloadContext)
|
||||||
{
|
{
|
||||||
this->btContext = btContext;
|
_downloadContext = downloadContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtMessageDispatcher::setPieceStorage
|
void DefaultBtMessageDispatcher::setPieceStorage
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
class DownloadContext;
|
||||||
class PeerStorage;
|
class PeerStorage;
|
||||||
class PieceStorage;
|
class PieceStorage;
|
||||||
class BtMessage;
|
class BtMessage;
|
||||||
|
@ -55,7 +55,7 @@ private:
|
||||||
int32_t cuid;
|
int32_t cuid;
|
||||||
std::deque<SharedHandle<BtMessage> > messageQueue;
|
std::deque<SharedHandle<BtMessage> > messageQueue;
|
||||||
std::deque<RequestSlot> requestSlots;
|
std::deque<RequestSlot> requestSlots;
|
||||||
SharedHandle<BtContext> btContext;
|
SharedHandle<DownloadContext> _downloadContext;
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
WeakHandle<BtMessageFactory> messageFactory;
|
WeakHandle<BtMessageFactory> messageFactory;
|
||||||
|
@ -116,7 +116,7 @@ public:
|
||||||
|
|
||||||
void setPeer(const SharedHandle<Peer>& peer);
|
void setPeer(const SharedHandle<Peer>& peer);
|
||||||
|
|
||||||
void setBtContext(const SharedHandle<BtContext>& btContext);
|
void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
|
||||||
|
|
||||||
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
|
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
|
||||||
|
|
||||||
|
|
|
@ -61,11 +61,12 @@
|
||||||
#include "ExtensionMessage.h"
|
#include "ExtensionMessage.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "Piece.h"
|
#include "Piece.h"
|
||||||
#include "BtContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "ExtensionMessageFactory.h"
|
#include "ExtensionMessageFactory.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
|
||||||
{
|
{
|
||||||
SharedHandle<BtMessageValidator> v
|
SharedHandle<BtMessageValidator> v
|
||||||
(new IndexBtMessageValidator((BtHaveMessage*)msg.get(),
|
(new IndexBtMessageValidator((BtHaveMessage*)msg.get(),
|
||||||
btContext->getNumPieces()));
|
_downloadContext->getNumPieces()));
|
||||||
msg->setBtMessageValidator(v);
|
msg->setBtMessageValidator(v);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -121,7 +122,7 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
|
||||||
{
|
{
|
||||||
SharedHandle<BtMessageValidator> v
|
SharedHandle<BtMessageValidator> v
|
||||||
(new BtBitfieldMessageValidator((BtBitfieldMessage*)msg.get(),
|
(new BtBitfieldMessageValidator((BtBitfieldMessage*)msg.get(),
|
||||||
btContext->getNumPieces()));
|
_downloadContext->getNumPieces()));
|
||||||
msg->setBtMessageValidator(v);
|
msg->setBtMessageValidator(v);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -130,7 +131,7 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
|
||||||
SharedHandle<BtMessageValidator> validator
|
SharedHandle<BtMessageValidator> validator
|
||||||
(new RangeBtMessageValidator
|
(new RangeBtMessageValidator
|
||||||
(temp.get(),
|
(temp.get(),
|
||||||
btContext->getNumPieces(),
|
_downloadContext->getNumPieces(),
|
||||||
_pieceStorage->getPieceLength(temp->getIndex())));
|
_pieceStorage->getPieceLength(temp->getIndex())));
|
||||||
temp->setBtMessageValidator(validator);
|
temp->setBtMessageValidator(validator);
|
||||||
msg = temp;
|
msg = temp;
|
||||||
|
@ -141,7 +142,7 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
|
||||||
SharedHandle<BtMessageValidator> validator
|
SharedHandle<BtMessageValidator> validator
|
||||||
(new RangeBtMessageValidator
|
(new RangeBtMessageValidator
|
||||||
(temp.get(),
|
(temp.get(),
|
||||||
btContext->getNumPieces(),
|
_downloadContext->getNumPieces(),
|
||||||
_pieceStorage->getPieceLength(temp->getIndex())));
|
_pieceStorage->getPieceLength(temp->getIndex())));
|
||||||
temp->setBtMessageValidator(validator);
|
temp->setBtMessageValidator(validator);
|
||||||
msg = temp;
|
msg = temp;
|
||||||
|
@ -151,9 +152,10 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
|
||||||
BtPieceMessageHandle temp = BtPieceMessage::create(data, dataLength);
|
BtPieceMessageHandle temp = BtPieceMessage::create(data, dataLength);
|
||||||
BtMessageValidatorHandle validator
|
BtMessageValidatorHandle validator
|
||||||
(new BtPieceMessageValidator(temp.get(),
|
(new BtPieceMessageValidator(temp.get(),
|
||||||
btContext->getNumPieces(),
|
_downloadContext->getNumPieces(),
|
||||||
_pieceStorage->getPieceLength(temp->getIndex())));
|
_pieceStorage->getPieceLength(temp->getIndex())));
|
||||||
temp->setBtMessageValidator(validator);
|
temp->setBtMessageValidator(validator);
|
||||||
|
temp->setDownloadContext(_downloadContext);
|
||||||
msg = temp;
|
msg = temp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +170,7 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
|
||||||
SharedHandle<BtMessageValidator> validator
|
SharedHandle<BtMessageValidator> validator
|
||||||
(new RangeBtMessageValidator
|
(new RangeBtMessageValidator
|
||||||
(temp.get(),
|
(temp.get(),
|
||||||
btContext->getNumPieces(),
|
_downloadContext->getNumPieces(),
|
||||||
_pieceStorage->getPieceLength(temp->getIndex())));
|
_pieceStorage->getPieceLength(temp->getIndex())));
|
||||||
temp->setBtMessageValidator(validator);
|
temp->setBtMessageValidator(validator);
|
||||||
msg = temp;
|
msg = temp;
|
||||||
|
@ -177,7 +179,8 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
|
||||||
case BtSuggestPieceMessage::ID: {
|
case BtSuggestPieceMessage::ID: {
|
||||||
BtSuggestPieceMessageHandle temp = BtSuggestPieceMessage::create(data, dataLength);
|
BtSuggestPieceMessageHandle temp = BtSuggestPieceMessage::create(data, dataLength);
|
||||||
SharedHandle<BtMessageValidator> validator
|
SharedHandle<BtMessageValidator> validator
|
||||||
(new IndexBtMessageValidator(temp.get(), btContext->getNumPieces()));
|
(new IndexBtMessageValidator(temp.get(),
|
||||||
|
_downloadContext->getNumPieces()));
|
||||||
temp->setBtMessageValidator(validator);
|
temp->setBtMessageValidator(validator);
|
||||||
msg = temp;
|
msg = temp;
|
||||||
break;
|
break;
|
||||||
|
@ -185,7 +188,8 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
|
||||||
case BtAllowedFastMessage::ID: {
|
case BtAllowedFastMessage::ID: {
|
||||||
BtAllowedFastMessageHandle temp = BtAllowedFastMessage::create(data, dataLength);
|
BtAllowedFastMessageHandle temp = BtAllowedFastMessage::create(data, dataLength);
|
||||||
SharedHandle<BtMessageValidator> validator
|
SharedHandle<BtMessageValidator> validator
|
||||||
(new IndexBtMessageValidator(temp.get(), btContext->getNumPieces()));
|
(new IndexBtMessageValidator(temp.get(),
|
||||||
|
_downloadContext->getNumPieces()));
|
||||||
temp->setBtMessageValidator(validator);
|
temp->setBtMessageValidator(validator);
|
||||||
msg = temp;
|
msg = temp;
|
||||||
break;
|
break;
|
||||||
|
@ -219,7 +223,6 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
|
||||||
void DefaultBtMessageFactory::setCommonProperty(const AbstractBtMessageHandle& msg) {
|
void DefaultBtMessageFactory::setCommonProperty(const AbstractBtMessageHandle& msg) {
|
||||||
msg->setCuid(cuid);
|
msg->setCuid(cuid);
|
||||||
msg->setPeer(peer);
|
msg->setPeer(peer);
|
||||||
msg->setBtContext(btContext);
|
|
||||||
msg->setPieceStorage(_pieceStorage);
|
msg->setPieceStorage(_pieceStorage);
|
||||||
msg->setBtMessageDispatcher(dispatcher);
|
msg->setBtMessageDispatcher(dispatcher);
|
||||||
msg->setBtRequestFactory(requestFactory);
|
msg->setBtRequestFactory(requestFactory);
|
||||||
|
@ -232,8 +235,8 @@ DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* data, size_
|
||||||
{
|
{
|
||||||
SharedHandle<BtHandshakeMessage> msg = BtHandshakeMessage::create(data, dataLength);
|
SharedHandle<BtHandshakeMessage> msg = BtHandshakeMessage::create(data, dataLength);
|
||||||
BtMessageValidatorHandle validator
|
BtMessageValidatorHandle validator
|
||||||
(new BtHandshakeMessageValidator(msg.get(),
|
(new BtHandshakeMessageValidator
|
||||||
btContext->getInfoHash()));
|
(msg.get(), bittorrent::getInfoHash(_downloadContext)));
|
||||||
msg->setBtMessageValidator(validator);
|
msg->setBtMessageValidator(validator);
|
||||||
setCommonProperty(msg);
|
setCommonProperty(msg);
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -245,8 +248,8 @@ DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* infoHash,
|
||||||
{
|
{
|
||||||
SharedHandle<BtHandshakeMessage> msg(new BtHandshakeMessage(infoHash, peerId));
|
SharedHandle<BtHandshakeMessage> msg(new BtHandshakeMessage(infoHash, peerId));
|
||||||
BtMessageValidatorHandle validator
|
BtMessageValidatorHandle validator
|
||||||
(new BtHandshakeMessageValidator(msg.get(),
|
(new BtHandshakeMessageValidator
|
||||||
btContext->getInfoHash()));
|
(msg.get(), bittorrent::getInfoHash(_downloadContext)));
|
||||||
msg->setBtMessageValidator(validator);
|
msg->setBtMessageValidator(validator);
|
||||||
msg->setDHTEnabled(_dhtEnabled);
|
msg->setDHTEnabled(_dhtEnabled);
|
||||||
setCommonProperty(msg);
|
setCommonProperty(msg);
|
||||||
|
@ -264,7 +267,7 @@ DefaultBtMessageFactory::createRequestMessage(const PieceHandle& piece, size_t b
|
||||||
SharedHandle<BtMessageValidator> validator
|
SharedHandle<BtMessageValidator> validator
|
||||||
(new RangeBtMessageValidator
|
(new RangeBtMessageValidator
|
||||||
(msg.get(),
|
(msg.get(),
|
||||||
btContext->getNumPieces(),
|
_downloadContext->getNumPieces(),
|
||||||
_pieceStorage->getPieceLength(msg->getIndex())));
|
_pieceStorage->getPieceLength(msg->getIndex())));
|
||||||
msg->setBtMessageValidator(validator);
|
msg->setBtMessageValidator(validator);
|
||||||
setCommonProperty(msg);
|
setCommonProperty(msg);
|
||||||
|
@ -278,7 +281,7 @@ DefaultBtMessageFactory::createCancelMessage(size_t index, uint32_t begin, size_
|
||||||
SharedHandle<BtMessageValidator> validator
|
SharedHandle<BtMessageValidator> validator
|
||||||
(new RangeBtMessageValidator
|
(new RangeBtMessageValidator
|
||||||
(msg.get(),
|
(msg.get(),
|
||||||
btContext->getNumPieces(),
|
_downloadContext->getNumPieces(),
|
||||||
_pieceStorage->getPieceLength(index)));
|
_pieceStorage->getPieceLength(index)));
|
||||||
msg->setBtMessageValidator(validator);
|
msg->setBtMessageValidator(validator);
|
||||||
setCommonProperty(msg);
|
setCommonProperty(msg);
|
||||||
|
@ -291,9 +294,10 @@ DefaultBtMessageFactory::createPieceMessage(size_t index, uint32_t begin, size_t
|
||||||
BtPieceMessageHandle msg(new BtPieceMessage(index, begin, length));
|
BtPieceMessageHandle msg(new BtPieceMessage(index, begin, length));
|
||||||
BtMessageValidatorHandle validator
|
BtMessageValidatorHandle validator
|
||||||
(new BtPieceMessageValidator(msg.get(),
|
(new BtPieceMessageValidator(msg.get(),
|
||||||
btContext->getNumPieces(),
|
_downloadContext->getNumPieces(),
|
||||||
_pieceStorage->getPieceLength(index)));
|
_pieceStorage->getPieceLength(index)));
|
||||||
msg->setBtMessageValidator(validator);
|
msg->setBtMessageValidator(validator);
|
||||||
|
msg->setDownloadContext(_downloadContext);
|
||||||
setCommonProperty(msg);
|
setCommonProperty(msg);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -303,7 +307,7 @@ DefaultBtMessageFactory::createHaveMessage(size_t index)
|
||||||
{
|
{
|
||||||
BtHaveMessageHandle msg(new BtHaveMessage(index));
|
BtHaveMessageHandle msg(new BtHaveMessage(index));
|
||||||
SharedHandle<BtMessageValidator> v
|
SharedHandle<BtMessageValidator> v
|
||||||
(new IndexBtMessageValidator(msg.get(), btContext->getNumPieces()));
|
(new IndexBtMessageValidator(msg.get(), _downloadContext->getNumPieces()));
|
||||||
msg->setBtMessageValidator(v);
|
msg->setBtMessageValidator(v);
|
||||||
setCommonProperty(msg);
|
setCommonProperty(msg);
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -349,7 +353,7 @@ DefaultBtMessageFactory::createBitfieldMessage()
|
||||||
_pieceStorage->getBitfieldLength()));
|
_pieceStorage->getBitfieldLength()));
|
||||||
SharedHandle<BtMessageValidator> v
|
SharedHandle<BtMessageValidator> v
|
||||||
(new BtBitfieldMessageValidator(msg.get(),
|
(new BtBitfieldMessageValidator(msg.get(),
|
||||||
btContext->getNumPieces()));
|
_downloadContext->getNumPieces()));
|
||||||
msg->setBtMessageValidator(v);
|
msg->setBtMessageValidator(v);
|
||||||
setCommonProperty(msg);
|
setCommonProperty(msg);
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -386,7 +390,7 @@ DefaultBtMessageFactory::createRejectMessage(size_t index, uint32_t begin, size_
|
||||||
SharedHandle<BtMessageValidator> validator
|
SharedHandle<BtMessageValidator> validator
|
||||||
(new RangeBtMessageValidator
|
(new RangeBtMessageValidator
|
||||||
(msg.get(),
|
(msg.get(),
|
||||||
btContext->getNumPieces(),
|
_downloadContext->getNumPieces(),
|
||||||
_pieceStorage->getPieceLength(index)));
|
_pieceStorage->getPieceLength(index)));
|
||||||
msg->setBtMessageValidator(validator);
|
msg->setBtMessageValidator(validator);
|
||||||
setCommonProperty(msg);
|
setCommonProperty(msg);
|
||||||
|
@ -398,7 +402,7 @@ DefaultBtMessageFactory::createAllowedFastMessage(size_t index)
|
||||||
{
|
{
|
||||||
BtAllowedFastMessageHandle msg(new BtAllowedFastMessage(index));
|
BtAllowedFastMessageHandle msg(new BtAllowedFastMessage(index));
|
||||||
SharedHandle<BtMessageValidator> validator
|
SharedHandle<BtMessageValidator> validator
|
||||||
(new IndexBtMessageValidator(msg.get(), btContext->getNumPieces()));
|
(new IndexBtMessageValidator(msg.get(), _downloadContext->getNumPieces()));
|
||||||
msg->setBtMessageValidator(validator);
|
msg->setBtMessageValidator(validator);
|
||||||
setCommonProperty(msg);
|
setCommonProperty(msg);
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -435,9 +439,10 @@ void DefaultBtMessageFactory::setPeer(const SharedHandle<Peer>& peer)
|
||||||
this->peer = peer;
|
this->peer = peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtMessageFactory::setBtContext(const SharedHandle<BtContext>& btContext)
|
void DefaultBtMessageFactory::setDownloadContext
|
||||||
|
(const SharedHandle<DownloadContext>& downloadContext)
|
||||||
{
|
{
|
||||||
this->btContext = btContext;
|
_downloadContext = downloadContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtMessageFactory::setPieceStorage
|
void DefaultBtMessageFactory::setPieceStorage
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
class DownloadContext;
|
||||||
class PieceStorage;
|
class PieceStorage;
|
||||||
class PeerStorage;
|
class PeerStorage;
|
||||||
class Peer;
|
class Peer;
|
||||||
|
@ -56,7 +56,7 @@ class DHTTaskFactory;
|
||||||
class DefaultBtMessageFactory : public BtMessageFactory {
|
class DefaultBtMessageFactory : public BtMessageFactory {
|
||||||
private:
|
private:
|
||||||
int32_t cuid;
|
int32_t cuid;
|
||||||
SharedHandle<BtContext> btContext;
|
SharedHandle<DownloadContext> _downloadContext;
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
SharedHandle<Peer> peer;
|
SharedHandle<Peer> peer;
|
||||||
|
@ -134,7 +134,7 @@ public:
|
||||||
|
|
||||||
void setPeer(const SharedHandle<Peer>& peer);
|
void setPeer(const SharedHandle<Peer>& peer);
|
||||||
|
|
||||||
void setBtContext(const SharedHandle<BtContext>& btContext);
|
void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
|
||||||
|
|
||||||
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
|
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
|
||||||
|
|
||||||
|
|
|
@ -38,13 +38,14 @@
|
||||||
|
|
||||||
#include "BtHandshakeMessage.h"
|
#include "BtHandshakeMessage.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "BtContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "PeerConnection.h"
|
#include "PeerConnection.h"
|
||||||
#include "BtMessageDispatcher.h"
|
#include "BtMessageDispatcher.h"
|
||||||
#include "BtMessageFactory.h"
|
#include "BtMessageFactory.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -71,7 +72,8 @@ DefaultBtMessageReceiver::receiveHandshake(bool quickReply)
|
||||||
if(!handshakeSent && quickReply && dataLength >= 48) {
|
if(!handshakeSent && quickReply && dataLength >= 48) {
|
||||||
handshakeSent = true;
|
handshakeSent = true;
|
||||||
// check info_hash
|
// check info_hash
|
||||||
if(memcmp(btContext->getInfoHash(), &data[28], INFO_HASH_LENGTH) == 0) {
|
if(memcmp(bittorrent::getInfoHash(_downloadContext), &data[28],
|
||||||
|
INFO_HASH_LENGTH) == 0) {
|
||||||
sendHandshake();
|
sendHandshake();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,8 +94,8 @@ DefaultBtMessageReceiver::receiveAndSendHandshake()
|
||||||
|
|
||||||
void DefaultBtMessageReceiver::sendHandshake() {
|
void DefaultBtMessageReceiver::sendHandshake() {
|
||||||
SharedHandle<BtMessage> msg =
|
SharedHandle<BtMessage> msg =
|
||||||
messageFactory->createHandshakeMessage(btContext->getInfoHash(),
|
messageFactory->createHandshakeMessage
|
||||||
btContext->getPeerId());
|
(bittorrent::getInfoHash(_downloadContext), bittorrent::getStaticPeerId());
|
||||||
dispatcher->addMessageToQueue(msg);
|
dispatcher->addMessageToQueue(msg);
|
||||||
dispatcher->sendMessages();
|
dispatcher->sendMessages();
|
||||||
}
|
}
|
||||||
|
@ -114,9 +116,10 @@ BtMessageHandle DefaultBtMessageReceiver::receiveMessage() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtMessageReceiver::setBtContext(const SharedHandle<BtContext>& btContext)
|
void DefaultBtMessageReceiver::setDownloadContext
|
||||||
|
(const SharedHandle<DownloadContext>& downloadContext)
|
||||||
{
|
{
|
||||||
this->btContext = btContext;
|
_downloadContext = downloadContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtMessageReceiver::setPeer(const SharedHandle<Peer>& peer)
|
void DefaultBtMessageReceiver::setPeer(const SharedHandle<Peer>& peer)
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
class DownloadContext;
|
||||||
class Peer;
|
class Peer;
|
||||||
class PeerConnection;
|
class PeerConnection;
|
||||||
class BtMessageDispatcher;
|
class BtMessageDispatcher;
|
||||||
|
@ -50,7 +50,7 @@ class DefaultBtMessageReceiver : public BtMessageReceiver {
|
||||||
private:
|
private:
|
||||||
int32_t cuid;
|
int32_t cuid;
|
||||||
bool handshakeSent;
|
bool handshakeSent;
|
||||||
SharedHandle<BtContext> btContext;
|
SharedHandle<DownloadContext> _downloadContext;
|
||||||
SharedHandle<Peer> peer;
|
SharedHandle<Peer> peer;
|
||||||
WeakHandle<PeerConnection> peerConnection;
|
WeakHandle<PeerConnection> peerConnection;
|
||||||
WeakHandle<BtMessageDispatcher> dispatcher;
|
WeakHandle<BtMessageDispatcher> dispatcher;
|
||||||
|
@ -77,7 +77,7 @@ public:
|
||||||
return cuid;
|
return cuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBtContext(const SharedHandle<BtContext>& btContext);
|
void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
|
||||||
|
|
||||||
void setPeer(const SharedHandle<Peer>& peer);
|
void setPeer(const SharedHandle<Peer>& peer);
|
||||||
|
|
||||||
|
|
|
@ -38,13 +38,8 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "BtContext.h"
|
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "Piece.h"
|
#include "Piece.h"
|
||||||
#ifdef ENABLE_BITTORRENT
|
|
||||||
#include "PeerStorage.h"
|
|
||||||
#include "BtRuntime.h"
|
|
||||||
#endif // ENABLE_BITTORRENT
|
|
||||||
#include "BitfieldMan.h"
|
#include "BitfieldMan.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "TransferStat.h"
|
#include "TransferStat.h"
|
||||||
|
@ -59,6 +54,12 @@
|
||||||
#include "DownloadFailureException.h"
|
#include "DownloadFailureException.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "array_fun.h"
|
#include "array_fun.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
#ifdef ENABLE_BITTORRENT
|
||||||
|
# include "PeerStorage.h"
|
||||||
|
# include "BtRuntime.h"
|
||||||
|
# include "bittorrent_helper.h"
|
||||||
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -67,13 +68,13 @@ const std::string DefaultBtProgressInfoFile::V0001("0001");
|
||||||
|
|
||||||
static std::string createFilename(const SharedHandle<DownloadContext>& dctx)
|
static std::string createFilename(const SharedHandle<DownloadContext>& dctx)
|
||||||
{
|
{
|
||||||
std::string t = dctx->getActualBasePath();
|
std::string t = dctx->getBasePath();
|
||||||
t += ".aria2";
|
t += ".aria2";
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultBtProgressInfoFile::DefaultBtProgressInfoFile
|
DefaultBtProgressInfoFile::DefaultBtProgressInfoFile
|
||||||
(const DownloadContextHandle& dctx,
|
(const SharedHandle<DownloadContext>& dctx,
|
||||||
const PieceStorageHandle& pieceStorage,
|
const PieceStorageHandle& pieceStorage,
|
||||||
const Option* option):
|
const Option* option):
|
||||||
_dctx(dctx),
|
_dctx(dctx),
|
||||||
|
@ -123,13 +124,12 @@ void DefaultBtProgressInfoFile::save() {
|
||||||
if(torrentDownload) {
|
if(torrentDownload) {
|
||||||
// infoHashLength:
|
// infoHashLength:
|
||||||
// length: 32 bits
|
// length: 32 bits
|
||||||
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(_dctx));
|
const unsigned char* infoHash = bittorrent::getInfoHash(_dctx);
|
||||||
uint32_t infoHashLengthNL = htonl(btContext->getInfoHashLength());
|
uint32_t infoHashLengthNL = htonl(INFO_HASH_LENGTH);
|
||||||
o.write(reinterpret_cast<const char*>(&infoHashLengthNL),
|
o.write(reinterpret_cast<const char*>(&infoHashLengthNL),
|
||||||
sizeof(infoHashLengthNL));
|
sizeof(infoHashLengthNL));
|
||||||
// infoHash:
|
// infoHash:
|
||||||
o.write(reinterpret_cast<const char*>(btContext->getInfoHash()),
|
o.write(reinterpret_cast<const char*>(infoHash), INFO_HASH_LENGTH);
|
||||||
btContext->getInfoHashLength());
|
|
||||||
} else {
|
} else {
|
||||||
// infoHashLength:
|
// infoHashLength:
|
||||||
// length: 32 bits
|
// length: 32 bits
|
||||||
|
@ -240,15 +240,16 @@ void DefaultBtProgressInfoFile::load()
|
||||||
array_ptr<unsigned char> savedInfoHash(new unsigned char[infoHashLength]);
|
array_ptr<unsigned char> savedInfoHash(new unsigned char[infoHashLength]);
|
||||||
in.read(reinterpret_cast<char*>
|
in.read(reinterpret_cast<char*>
|
||||||
(static_cast<unsigned char*>(savedInfoHash)), infoHashLength);
|
(static_cast<unsigned char*>(savedInfoHash)), infoHashLength);
|
||||||
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(_dctx));
|
if(infoHashCheckEnabled) {
|
||||||
if(infoHashCheckEnabled &&
|
const unsigned char* infoHash = bittorrent::getInfoHash(_dctx);
|
||||||
Util::toHex(savedInfoHash, infoHashLength) !=
|
if(infoHashLength != INFO_HASH_LENGTH ||
|
||||||
btContext->getInfoHashAsString()) {
|
memcmp(savedInfoHash, infoHash, INFO_HASH_LENGTH) != 0) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(StringFormat("info hash mismatch. expected: %s, actual: %s",
|
(StringFormat("info hash mismatch. expected: %s, actual: %s",
|
||||||
btContext->getInfoHashAsString().c_str(),
|
Util::toHex(infoHash, INFO_HASH_LENGTH).c_str(),
|
||||||
Util::toHex(savedInfoHash,
|
Util::toHex(savedInfoHash, infoHashLength).c_str()
|
||||||
infoHashLength).c_str()).str());
|
).str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Piece.h"
|
#include "Piece.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "BtMessageDispatcher.h"
|
#include "BtMessageDispatcher.h"
|
||||||
#include "BtMessageFactory.h"
|
#include "BtMessageFactory.h"
|
||||||
|
@ -235,11 +234,6 @@ void DefaultBtRequestFactory::getTargetPieceIndexes
|
||||||
mem_fun_sh(&Piece::getIndex));
|
mem_fun_sh(&Piece::getIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtRequestFactory::setBtContext(const SharedHandle<BtContext>& btContext)
|
|
||||||
{
|
|
||||||
this->btContext = btContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultBtRequestFactory::setPieceStorage
|
void DefaultBtRequestFactory::setPieceStorage
|
||||||
(const SharedHandle<PieceStorage>& pieceStorage)
|
(const SharedHandle<PieceStorage>& pieceStorage)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
|
||||||
class PieceStorage;
|
class PieceStorage;
|
||||||
class Peer;
|
class Peer;
|
||||||
class BtMessageDispatcher;
|
class BtMessageDispatcher;
|
||||||
|
@ -50,7 +49,6 @@ class Logger;
|
||||||
class DefaultBtRequestFactory : public BtRequestFactory {
|
class DefaultBtRequestFactory : public BtRequestFactory {
|
||||||
private:
|
private:
|
||||||
int32_t cuid;
|
int32_t cuid;
|
||||||
SharedHandle<BtContext> btContext;
|
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
SharedHandle<Peer> peer;
|
SharedHandle<Peer> peer;
|
||||||
WeakHandle<BtMessageDispatcher> dispatcher;
|
WeakHandle<BtMessageDispatcher> dispatcher;
|
||||||
|
@ -96,8 +94,6 @@ public:
|
||||||
this->cuid = cuid;
|
this->cuid = cuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBtContext(const SharedHandle<BtContext>& btContext);
|
|
||||||
|
|
||||||
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
|
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
|
||||||
|
|
||||||
void setPeer(const SharedHandle<Peer>& peer);
|
void setPeer(const SharedHandle<Peer>& peer);
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "DefaultExtensionMessageFactory.h"
|
#include "DefaultExtensionMessageFactory.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "HandshakeExtensionMessage.h"
|
#include "HandshakeExtensionMessage.h"
|
||||||
|
@ -50,10 +49,8 @@ DefaultExtensionMessageFactory::DefaultExtensionMessageFactory():
|
||||||
_logger(LogFactory::getInstance()) {}
|
_logger(LogFactory::getInstance()) {}
|
||||||
|
|
||||||
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory
|
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory
|
||||||
(const BtContextHandle& btContext,
|
(const PeerHandle& peer,
|
||||||
const PeerHandle& peer,
|
|
||||||
const SharedHandle<ExtensionMessageRegistry>& registry):
|
const SharedHandle<ExtensionMessageRegistry>& registry):
|
||||||
_btContext(btContext),
|
|
||||||
_peer(peer),
|
_peer(peer),
|
||||||
_registry(registry),
|
_registry(registry),
|
||||||
_logger(LogFactory::getInstance()) {}
|
_logger(LogFactory::getInstance()) {}
|
||||||
|
@ -67,7 +64,6 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
|
||||||
if(extensionMessageID == 0) {
|
if(extensionMessageID == 0) {
|
||||||
// handshake
|
// handshake
|
||||||
HandshakeExtensionMessageHandle m = HandshakeExtensionMessage::create(data, length);
|
HandshakeExtensionMessageHandle m = HandshakeExtensionMessage::create(data, length);
|
||||||
m->setBtContext(_btContext);
|
|
||||||
m->setPeer(_peer);
|
m->setPeer(_peer);
|
||||||
return m;
|
return m;
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,11 +87,6 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultExtensionMessageFactory::setBtContext(const BtContextHandle& btContext)
|
|
||||||
{
|
|
||||||
_btContext = btContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DefaultExtensionMessageFactory::setPeerStorage
|
void DefaultExtensionMessageFactory::setPeerStorage
|
||||||
(const SharedHandle<PeerStorage>& peerStorage)
|
(const SharedHandle<PeerStorage>& peerStorage)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
|
||||||
class PeerStorage;
|
class PeerStorage;
|
||||||
class Peer;
|
class Peer;
|
||||||
class Logger;
|
class Logger;
|
||||||
|
@ -47,8 +46,6 @@ class ExtensionMessageRegistry;
|
||||||
|
|
||||||
class DefaultExtensionMessageFactory:public ExtensionMessageFactory {
|
class DefaultExtensionMessageFactory:public ExtensionMessageFactory {
|
||||||
private:
|
private:
|
||||||
SharedHandle<BtContext> _btContext;
|
|
||||||
|
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
|
|
||||||
SharedHandle<Peer> _peer;
|
SharedHandle<Peer> _peer;
|
||||||
|
@ -61,8 +58,7 @@ public:
|
||||||
DefaultExtensionMessageFactory();
|
DefaultExtensionMessageFactory();
|
||||||
|
|
||||||
DefaultExtensionMessageFactory
|
DefaultExtensionMessageFactory
|
||||||
(const SharedHandle<BtContext>& btContext,
|
(const SharedHandle<Peer>& peer,
|
||||||
const SharedHandle<Peer>& peer,
|
|
||||||
const SharedHandle<ExtensionMessageRegistry>& registry);
|
const SharedHandle<ExtensionMessageRegistry>& registry);
|
||||||
|
|
||||||
virtual ~DefaultExtensionMessageFactory();
|
virtual ~DefaultExtensionMessageFactory();
|
||||||
|
@ -70,8 +66,6 @@ public:
|
||||||
virtual SharedHandle<ExtensionMessage>
|
virtual SharedHandle<ExtensionMessage>
|
||||||
createMessage(const unsigned char* data, size_t length);
|
createMessage(const unsigned char* data, size_t length);
|
||||||
|
|
||||||
void setBtContext(const SharedHandle<BtContext>& btContext);
|
|
||||||
|
|
||||||
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
|
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
|
||||||
|
|
||||||
void setPeer(const SharedHandle<Peer>& peer);
|
void setPeer(const SharedHandle<Peer>& peer);
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "a2time.h"
|
#include "a2time.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "BtRuntime.h"
|
#include "BtRuntime.h"
|
||||||
#include "BtSeederStateChoke.h"
|
#include "BtSeederStateChoke.h"
|
||||||
#include "BtLeecherStateChoke.h"
|
#include "BtLeecherStateChoke.h"
|
||||||
|
@ -51,9 +50,7 @@ namespace aria2 {
|
||||||
|
|
||||||
static const int MAX_PEER_LIST_SIZE = 1024;
|
static const int MAX_PEER_LIST_SIZE = 1024;
|
||||||
|
|
||||||
DefaultPeerStorage::DefaultPeerStorage(const BtContextHandle& btContext,
|
DefaultPeerStorage::DefaultPeerStorage(const Option* option):
|
||||||
const Option* option):
|
|
||||||
btContext(btContext),
|
|
||||||
option(option),
|
option(option),
|
||||||
logger(LogFactory::getInstance()),
|
logger(LogFactory::getInstance()),
|
||||||
removedPeerSessionDownloadLength(0),
|
removedPeerSessionDownloadLength(0),
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
|
||||||
class Option;
|
class Option;
|
||||||
class Logger;
|
class Logger;
|
||||||
class BtRuntime;
|
class BtRuntime;
|
||||||
|
@ -53,7 +52,6 @@ class PieceStorage;
|
||||||
|
|
||||||
class DefaultPeerStorage : public PeerStorage {
|
class DefaultPeerStorage : public PeerStorage {
|
||||||
private:
|
private:
|
||||||
SharedHandle<BtContext> btContext;
|
|
||||||
SharedHandle<BtRuntime> _btRuntime;
|
SharedHandle<BtRuntime> _btRuntime;
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
const Option* option;
|
const Option* option;
|
||||||
|
@ -73,8 +71,7 @@ private:
|
||||||
|
|
||||||
bool isPeerAlreadyAdded(const SharedHandle<Peer>& peer);
|
bool isPeerAlreadyAdded(const SharedHandle<Peer>& peer);
|
||||||
public:
|
public:
|
||||||
DefaultPeerStorage(const SharedHandle<BtContext>& btContext,
|
DefaultPeerStorage(const Option* option);
|
||||||
const Option* option);
|
|
||||||
|
|
||||||
virtual ~DefaultPeerStorage();
|
virtual ~DefaultPeerStorage();
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DefaultPieceStorage::DefaultPieceStorage
|
DefaultPieceStorage::DefaultPieceStorage
|
||||||
(const DownloadContextHandle& downloadContext, const Option* option):
|
(const SharedHandle<DownloadContext>& downloadContext, const Option* option):
|
||||||
downloadContext(downloadContext),
|
downloadContext(downloadContext),
|
||||||
bitfieldMan(BitfieldManFactory::getFactoryInstance()->
|
bitfieldMan(BitfieldManFactory::getFactoryInstance()->
|
||||||
createBitfieldMan(downloadContext->getPieceLength(),
|
createBitfieldMan(downloadContext->getPieceLength(),
|
||||||
|
@ -421,10 +421,10 @@ size_t DefaultPieceStorage::getInFlightPieceCompletedLength() const
|
||||||
// not unittested
|
// not unittested
|
||||||
void DefaultPieceStorage::setupFileFilter()
|
void DefaultPieceStorage::setupFileFilter()
|
||||||
{
|
{
|
||||||
const std::deque<SharedHandle<FileEntry> >& fileEntries =
|
const std::vector<SharedHandle<FileEntry> >& fileEntries =
|
||||||
downloadContext->getFileEntries();
|
downloadContext->getFileEntries();
|
||||||
bool allSelected = true;
|
bool allSelected = true;
|
||||||
for(std::deque<SharedHandle<FileEntry> >::const_iterator i =
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||||
if(!(*i)->isRequested()) {
|
if(!(*i)->isRequested()) {
|
||||||
allSelected = false;
|
allSelected = false;
|
||||||
|
@ -434,7 +434,7 @@ void DefaultPieceStorage::setupFileFilter()
|
||||||
if(allSelected) {
|
if(allSelected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(std::deque<SharedHandle<FileEntry> >::const_iterator i =
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||||
if((*i)->isRequested()) {
|
if((*i)->isRequested()) {
|
||||||
bitfieldMan->addFilter((*i)->getOffset(), (*i)->getLength());
|
bitfieldMan->addFilter((*i)->getOffset(), (*i)->getLength());
|
||||||
|
@ -465,11 +465,12 @@ bool DefaultPieceStorage::allDownloadFinished()
|
||||||
// not unittested
|
// not unittested
|
||||||
void DefaultPieceStorage::initStorage()
|
void DefaultPieceStorage::initStorage()
|
||||||
{
|
{
|
||||||
if(downloadContext->getFileMode() == DownloadContext::SINGLE) {
|
if(downloadContext->getFileEntries().size() == 1) {
|
||||||
logger->debug("Instantiating DirectDiskAdaptor");
|
logger->debug("Instantiating DirectDiskAdaptor");
|
||||||
DirectDiskAdaptorHandle directDiskAdaptor(new DirectDiskAdaptor());
|
DirectDiskAdaptorHandle directDiskAdaptor(new DirectDiskAdaptor());
|
||||||
directDiskAdaptor->setTotalLength(downloadContext->getTotalLength());
|
directDiskAdaptor->setTotalLength(downloadContext->getTotalLength());
|
||||||
directDiskAdaptor->setFileEntries(downloadContext->getFileEntries());
|
directDiskAdaptor->setFileEntries(downloadContext->getFileEntries().begin(),
|
||||||
|
downloadContext->getFileEntries().end());
|
||||||
|
|
||||||
DiskWriterHandle writer =
|
DiskWriterHandle writer =
|
||||||
_diskWriterFactory->newDiskWriter(directDiskAdaptor->getFilePath());
|
_diskWriterFactory->newDiskWriter(directDiskAdaptor->getFilePath());
|
||||||
|
@ -480,10 +481,10 @@ void DefaultPieceStorage::initStorage()
|
||||||
directDiskAdaptor->setDiskWriter(writer);
|
directDiskAdaptor->setDiskWriter(writer);
|
||||||
this->diskAdaptor = directDiskAdaptor;
|
this->diskAdaptor = directDiskAdaptor;
|
||||||
} else {
|
} else {
|
||||||
// file mode == DownloadContext::MULTI
|
|
||||||
logger->debug("Instantiating MultiDiskAdaptor");
|
logger->debug("Instantiating MultiDiskAdaptor");
|
||||||
MultiDiskAdaptorHandle multiDiskAdaptor(new MultiDiskAdaptor());
|
MultiDiskAdaptorHandle multiDiskAdaptor(new MultiDiskAdaptor());
|
||||||
multiDiskAdaptor->setFileEntries(downloadContext->getFileEntries());
|
multiDiskAdaptor->setFileEntries(downloadContext->getFileEntries().begin(),
|
||||||
|
downloadContext->getFileEntries().end());
|
||||||
if(option->getAsBool(PREF_ENABLE_DIRECT_IO)) {
|
if(option->getAsBool(PREF_ENABLE_DIRECT_IO)) {
|
||||||
multiDiskAdaptor->allowDirectIO();
|
multiDiskAdaptor->allowDirectIO();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,9 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
SegmentManHandle
|
SegmentManHandle
|
||||||
DefaultSegmentManFactory::createNewInstance(const DownloadContextHandle& dctx,
|
DefaultSegmentManFactory::createNewInstance
|
||||||
const PieceStorageHandle& ps)
|
(const SharedHandle<DownloadContext>& dctx,
|
||||||
|
const PieceStorageHandle& ps)
|
||||||
{
|
{
|
||||||
SegmentManHandle segmentMan(new SegmentMan(_option, dctx, ps));
|
SegmentManHandle segmentMan(new SegmentMan(_option, dctx, ps));
|
||||||
return segmentMan;
|
return segmentMan;
|
||||||
|
|
|
@ -47,8 +47,4 @@ DiskAdaptor::DiskAdaptor():
|
||||||
|
|
||||||
DiskAdaptor::~DiskAdaptor() {}
|
DiskAdaptor::~DiskAdaptor() {}
|
||||||
|
|
||||||
void DiskAdaptor::setFileEntries(const FileEntries& fileEntries) {
|
|
||||||
this->fileEntries = fileEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "BinaryStream.h"
|
#include "BinaryStream.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <deque>
|
#include <vector>
|
||||||
|
|
||||||
#include "TimeA2.h"
|
#include "TimeA2.h"
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class FileAllocationIterator;
|
||||||
|
|
||||||
class DiskAdaptor:public BinaryStream {
|
class DiskAdaptor:public BinaryStream {
|
||||||
protected:
|
protected:
|
||||||
std::deque<SharedHandle<FileEntry> > fileEntries;
|
std::vector<SharedHandle<FileEntry> > fileEntries;
|
||||||
#ifdef HAVE_POSIX_FALLOCATE
|
#ifdef HAVE_POSIX_FALLOCATE
|
||||||
bool _fallocate;
|
bool _fallocate;
|
||||||
#endif // HAVE_POSIX_FALLOCATE
|
#endif // HAVE_POSIX_FALLOCATE
|
||||||
|
@ -73,9 +73,13 @@ public:
|
||||||
|
|
||||||
virtual uint64_t size() = 0;
|
virtual uint64_t size() = 0;
|
||||||
|
|
||||||
void setFileEntries(const std::deque<SharedHandle<FileEntry> >& fileEntries);
|
template<typename InputIterator>
|
||||||
|
void setFileEntries(InputIterator first, InputIterator last)
|
||||||
|
{
|
||||||
|
fileEntries.assign(first, last);
|
||||||
|
}
|
||||||
|
|
||||||
const std::deque<SharedHandle<FileEntry> >& getFileEntries() const
|
const std::vector<SharedHandle<FileEntry> >& getFileEntries() const
|
||||||
{
|
{
|
||||||
return fileEntries;
|
return fileEntries;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,29 +37,30 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
|
#include "StringFormat.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DownloadContext::DownloadContext():
|
DownloadContext::DownloadContext():
|
||||||
_dir("."),
|
_dir("."),
|
||||||
|
_pieceLength(0),
|
||||||
|
_knowsTotalLength(true),
|
||||||
|
_ownerRequestGroup(0),
|
||||||
_downloadStartTime(0),
|
_downloadStartTime(0),
|
||||||
_downloadStopTime(_downloadStartTime) {}
|
_downloadStopTime(_downloadStartTime) {}
|
||||||
|
|
||||||
DownloadContext::~DownloadContext() {}
|
DownloadContext::DownloadContext(size_t pieceLength,
|
||||||
|
uint64_t totalLength,
|
||||||
void DownloadContext::setDir(const std::string& dir)
|
const std::string& path):
|
||||||
|
_dir("."),
|
||||||
|
_pieceLength(pieceLength),
|
||||||
|
_knowsTotalLength(true),
|
||||||
|
_ownerRequestGroup(0),
|
||||||
|
_downloadStartTime(0),
|
||||||
|
_downloadStopTime(_downloadStartTime)
|
||||||
{
|
{
|
||||||
_dir = dir;
|
SharedHandle<FileEntry> fileEntry(new FileEntry(path, totalLength, 0));
|
||||||
}
|
_fileEntries.push_back(fileEntry);
|
||||||
|
|
||||||
SharedHandle<Signature> DownloadContext::getSignature() const
|
|
||||||
{
|
|
||||||
return _signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownloadContext::setSignature(const SharedHandle<Signature>& signature)
|
|
||||||
{
|
|
||||||
_signature = signature;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadContext::resetDownloadStartTime()
|
void DownloadContext::resetDownloadStartTime()
|
||||||
|
@ -94,7 +95,7 @@ DownloadContext::findFileEntryByOffset(off_t offset) const
|
||||||
|
|
||||||
SharedHandle<FileEntry> obj(new FileEntry());
|
SharedHandle<FileEntry> obj(new FileEntry());
|
||||||
obj->setOffset(offset);
|
obj->setOffset(offset);
|
||||||
std::deque<SharedHandle<FileEntry> >::const_iterator i =
|
std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||||
std::upper_bound(_fileEntries.begin(), _fileEntries.end(), obj);
|
std::upper_bound(_fileEntries.begin(), _fileEntries.end(), obj);
|
||||||
if(i != _fileEntries.end() && (*i)->getOffset() == offset) {
|
if(i != _fileEntries.end() && (*i)->getOffset() == offset) {
|
||||||
return *i;
|
return *i;
|
||||||
|
@ -103,4 +104,65 @@ DownloadContext::findFileEntryByOffset(off_t offset) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DownloadContext::setFilePathWithIndex
|
||||||
|
(size_t index, const std::string& path)
|
||||||
|
{
|
||||||
|
if(0 < index && index <= _fileEntries.size()) {
|
||||||
|
_fileEntries[index-1]->setPath(path);
|
||||||
|
} else {
|
||||||
|
throw DL_ABORT_EX(StringFormat("No such file with index=%u",
|
||||||
|
static_cast<unsigned int>(index)).str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadContext::setFileFilter(IntSequence seq)
|
||||||
|
{
|
||||||
|
std::deque<int32_t> fileIndexes = seq.flush();
|
||||||
|
std::sort(fileIndexes.begin(), fileIndexes.end());
|
||||||
|
fileIndexes.erase(std::unique(fileIndexes.begin(), fileIndexes.end()),
|
||||||
|
fileIndexes.end());
|
||||||
|
|
||||||
|
bool selectAll = fileIndexes.empty() || _fileEntries.size() == 1;
|
||||||
|
|
||||||
|
int32_t index = 1;
|
||||||
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||||
|
_fileEntries.begin(); i != _fileEntries.end(); ++i, ++index) {
|
||||||
|
(*i)->setRequested
|
||||||
|
(selectAll ||
|
||||||
|
std::binary_search(fileIndexes.begin(), fileIndexes.end(), index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadContext::ensureAttrs()
|
||||||
|
{
|
||||||
|
if(_attrs.isNone()) {
|
||||||
|
_attrs = BDE::dict();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadContext::setAttribute(const std::string& key, const BDE& value)
|
||||||
|
{
|
||||||
|
ensureAttrs();
|
||||||
|
_attrs[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
BDE& DownloadContext::getAttribute(const std::string& key)
|
||||||
|
{
|
||||||
|
ensureAttrs();
|
||||||
|
if(_attrs.containsKey(key)) {
|
||||||
|
return _attrs[key];
|
||||||
|
} else {
|
||||||
|
throw DL_ABORT_EX(StringFormat("No attribute named %s", key.c_str()).str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DownloadContext::hasAttribute(const std::string& key) const
|
||||||
|
{
|
||||||
|
if(_attrs.isNone()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return _attrs.containsKey(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -37,80 +37,194 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <deque>
|
#include <vector>
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "Signature.h"
|
#include "Signature.h"
|
||||||
#include "TimeA2.h"
|
#include "TimeA2.h"
|
||||||
|
#include "A2STR.h"
|
||||||
|
#include "BDE.h"
|
||||||
|
#include "IntSequence.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class FileEntry;
|
class FileEntry;
|
||||||
|
class RequestGroup;
|
||||||
|
|
||||||
class DownloadContext
|
class DownloadContext
|
||||||
{
|
{
|
||||||
protected:
|
private:
|
||||||
std::deque<SharedHandle<FileEntry> > _fileEntries;
|
std::vector<SharedHandle<FileEntry> > _fileEntries;
|
||||||
|
|
||||||
std::string _dir;
|
std::string _dir;
|
||||||
private:
|
|
||||||
|
std::vector<std::string> _pieceHashes;
|
||||||
|
|
||||||
|
size_t _pieceLength;
|
||||||
|
|
||||||
|
std::string _pieceHashAlgo;
|
||||||
|
|
||||||
|
std::string _checksum;
|
||||||
|
|
||||||
|
std::string _checksumHashAlgo;
|
||||||
|
|
||||||
|
std::string _basePath;
|
||||||
|
|
||||||
|
bool _knowsTotalLength;
|
||||||
|
|
||||||
|
RequestGroup* _ownerRequestGroup;
|
||||||
|
|
||||||
|
BDE _attrs;
|
||||||
|
|
||||||
Time _downloadStartTime;
|
Time _downloadStartTime;
|
||||||
|
|
||||||
Time _downloadStopTime;
|
Time _downloadStopTime;
|
||||||
|
|
||||||
SharedHandle<Signature> _signature;
|
SharedHandle<Signature> _signature;
|
||||||
|
|
||||||
|
void ensureAttrs();
|
||||||
public:
|
public:
|
||||||
DownloadContext();
|
DownloadContext();
|
||||||
|
|
||||||
virtual ~DownloadContext();
|
// Convenient constructor that creates single file download.
|
||||||
|
DownloadContext(size_t pieceLength,
|
||||||
|
uint64_t totalLength,
|
||||||
|
const std::string& path = A2STR::NIL);
|
||||||
|
|
||||||
enum FILE_MODE {
|
const std::string& getPieceHash(size_t index) const
|
||||||
SINGLE,
|
{
|
||||||
MULTI
|
if(index < _pieceHashes.size()) {
|
||||||
};
|
return _pieceHashes[index];
|
||||||
|
} else {
|
||||||
virtual const std::string& getPieceHash(size_t index) const = 0;
|
return A2STR::NIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual const std::deque<std::string>& getPieceHashes() const = 0;
|
const std::vector<std::string>& getPieceHashes() const
|
||||||
|
{
|
||||||
|
return _pieceHashes;
|
||||||
|
}
|
||||||
|
|
||||||
virtual uint64_t getTotalLength() const = 0;
|
template<typename InputIterator>
|
||||||
|
void setPieceHashes(InputIterator first, InputIterator last)
|
||||||
|
{
|
||||||
|
_pieceHashes.assign(first, last);
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool knowsTotalLength() const = 0;
|
uint64_t getTotalLength() const
|
||||||
|
{
|
||||||
|
if(_fileEntries.empty()) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return _fileEntries.back()->getLastOffset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual FILE_MODE getFileMode() const = 0;
|
bool knowsTotalLength() const { return _knowsTotalLength; }
|
||||||
|
|
||||||
const std::deque<SharedHandle<FileEntry> >& getFileEntries() const
|
void markTotalLengthIsUnknown() { _knowsTotalLength = false; }
|
||||||
|
|
||||||
|
const std::vector<SharedHandle<FileEntry> >& getFileEntries() const
|
||||||
{
|
{
|
||||||
return _fileEntries;
|
return _fileEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t getPieceLength() const = 0;
|
const SharedHandle<FileEntry>& getFirstFileEntry() const
|
||||||
|
|
||||||
virtual size_t getNumPieces() const = 0;
|
|
||||||
|
|
||||||
virtual const std::string& getPieceHashAlgo() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an actual file path.
|
|
||||||
* If this contains a single file entry, then returns its file path,
|
|
||||||
* for example, "/tmp/downloads/aria2.txt"
|
|
||||||
* If this contains multiple file entries(i,e /tmp/downloads/aria2.txt,
|
|
||||||
* /tmp/downloads/aria2.bin), then returns its base dir path,
|
|
||||||
* for example, "/tmp/downloads"
|
|
||||||
*/
|
|
||||||
virtual std::string getActualBasePath() const = 0;
|
|
||||||
|
|
||||||
const std::string& getDir() const
|
|
||||||
{
|
{
|
||||||
return _dir;
|
assert(!_fileEntries.empty());
|
||||||
|
return _fileEntries[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDir(const std::string& dir);
|
template<typename InputIterator>
|
||||||
|
void setFileEntries(InputIterator first, InputIterator last)
|
||||||
|
{
|
||||||
|
_fileEntries.assign(first, last);
|
||||||
|
}
|
||||||
|
|
||||||
SharedHandle<Signature> getSignature() const;
|
size_t getPieceLength() const { return _pieceLength; }
|
||||||
|
|
||||||
void setSignature(const SharedHandle<Signature>& signature);
|
void setPieceLength(size_t length) { _pieceLength = length; }
|
||||||
|
|
||||||
|
size_t getNumPieces() const
|
||||||
|
{
|
||||||
|
if(_pieceLength == 0) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
assert(!_fileEntries.empty());
|
||||||
|
return (_fileEntries.back()->getLastOffset()+_pieceLength-1)/_pieceLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& getPieceHashAlgo() const { return _pieceHashAlgo; }
|
||||||
|
|
||||||
|
void setPieceHashAlgo(const std::string& algo)
|
||||||
|
{
|
||||||
|
_pieceHashAlgo = algo;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& getChecksum() const { return _checksum; }
|
||||||
|
|
||||||
|
void setChecksum(const std::string& checksum)
|
||||||
|
{
|
||||||
|
_checksum = checksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& getChecksumHashAlgo() const { return _checksumHashAlgo; }
|
||||||
|
|
||||||
|
void setChecksumHashAlgo(const std::string& algo)
|
||||||
|
{
|
||||||
|
_checksumHashAlgo = algo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The representative path name for this context. It is used as a
|
||||||
|
// part of .aria2 control file. If _basePath is set, returns
|
||||||
|
// _basePath. Otherwise, the first FileEntry's getFilePath() is
|
||||||
|
// returned.
|
||||||
|
const std::string& getBasePath() const
|
||||||
|
{
|
||||||
|
if(_basePath.empty()) {
|
||||||
|
assert(!_fileEntries.empty());
|
||||||
|
return getFirstFileEntry()->getPath();
|
||||||
|
} else {
|
||||||
|
return _basePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBasePath(const std::string& basePath) { _basePath = basePath; }
|
||||||
|
|
||||||
|
const std::string& getDir() const { return _dir; }
|
||||||
|
|
||||||
|
void setDir(const std::string& dir) { _dir = dir; }
|
||||||
|
|
||||||
|
SharedHandle<Signature> getSignature() const { return _signature; }
|
||||||
|
|
||||||
|
void setSignature(const SharedHandle<Signature>& signature)
|
||||||
|
{
|
||||||
|
_signature = signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestGroup* getOwnerRequestGroup() { return _ownerRequestGroup; }
|
||||||
|
|
||||||
|
void setOwnerRequestGroup(RequestGroup* owner)
|
||||||
|
{
|
||||||
|
_ownerRequestGroup = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFileFilter(IntSequence seq);
|
||||||
|
|
||||||
|
// Sets file path for spcified index. index starts from 1. The index
|
||||||
|
// is the same used in setFileFilter(). Please note that path is
|
||||||
|
// not the actual file path. The actual file path is
|
||||||
|
// getDir()+"/"+path.
|
||||||
|
void setFilePathWithIndex(size_t index, const std::string& path);
|
||||||
|
|
||||||
|
void setAttribute(const std::string& key, const BDE& value);
|
||||||
|
|
||||||
|
BDE& getAttribute(const std::string& key);
|
||||||
|
|
||||||
|
bool hasAttribute(const std::string& key) const;
|
||||||
|
|
||||||
void resetDownloadStartTime();
|
void resetDownloadStartTime();
|
||||||
|
|
||||||
|
@ -123,8 +237,6 @@ public:
|
||||||
SharedHandle<FileEntry> findFileEntryByOffset(off_t offset) const;
|
SharedHandle<FileEntry> findFileEntryByOffset(off_t offset) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<DownloadContext> DownloadContextHandle;
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_DOWNLOAD_CONTEXT_H_
|
#endif // _D_DOWNLOAD_CONTEXT_H_
|
||||||
|
|
|
@ -65,14 +65,15 @@
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "FileAllocationEntry.h"
|
#include "FileAllocationEntry.h"
|
||||||
#include "CheckIntegrityEntry.h"
|
#include "CheckIntegrityEntry.h"
|
||||||
|
|
||||||
#include "BtRegistry.h"
|
|
||||||
#include "BtContext.h"
|
|
||||||
#include "PeerStorage.h"
|
|
||||||
#include "PieceStorage.h"
|
|
||||||
#include "BtAnnounce.h"
|
|
||||||
#include "BtRuntime.h"
|
|
||||||
#include "BtProgressInfoFile.h"
|
#include "BtProgressInfoFile.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
#ifdef ENABLE_BITTORRENT
|
||||||
|
# include "BtRegistry.h"
|
||||||
|
# include "PeerStorage.h"
|
||||||
|
# include "PieceStorage.h"
|
||||||
|
# include "BtAnnounce.h"
|
||||||
|
# include "BtRuntime.h"
|
||||||
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
#include "DownloadResult.h"
|
#include "DownloadResult.h"
|
||||||
#include "ServerStatMan.h"
|
#include "ServerStatMan.h"
|
||||||
#include "a2io.h"
|
#include "a2io.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
#ifdef HAVE_EPOLL
|
#ifdef HAVE_EPOLL
|
||||||
# include "EpollEventPoll.h"
|
# include "EpollEventPoll.h"
|
||||||
#endif // HAVE_EPOLL
|
#endif // HAVE_EPOLL
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "RequestGroupCriteria.h"
|
#include "RequestGroupCriteria.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <deque>
|
#include <vector>
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
|
@ -64,7 +64,7 @@ public:
|
||||||
|
|
||||||
int32_t gid;
|
int32_t gid;
|
||||||
|
|
||||||
std::deque<SharedHandle<FileEntry> > fileEntries;
|
std::vector<SharedHandle<FileEntry> > fileEntries;
|
||||||
|
|
||||||
bool inMemoryDownload;
|
bool inMemoryDownload;
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public:
|
||||||
RESULT result;
|
RESULT result;
|
||||||
|
|
||||||
DownloadResult(int32_t gid,
|
DownloadResult(int32_t gid,
|
||||||
const std::deque<SharedHandle<FileEntry> >& fileEntries,
|
const std::vector<SharedHandle<FileEntry> >& fileEntries,
|
||||||
bool inMemoryDownload,
|
bool inMemoryDownload,
|
||||||
uint64_t totalLength,
|
uint64_t totalLength,
|
||||||
const std::string& uri,
|
const std::string& uri,
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -78,7 +79,8 @@ bool FileAllocationCommand::handleException(Exception& e)
|
||||||
{
|
{
|
||||||
_e->_fileAllocationMan->dropPickedEntry();
|
_e->_fileAllocationMan->dropPickedEntry();
|
||||||
logger->error(MSG_FILE_ALLOCATION_FAILURE, e, cuid);
|
logger->error(MSG_FILE_ALLOCATION_FAILURE, e, cuid);
|
||||||
logger->error(MSG_DOWNLOAD_NOT_COMPLETE, cuid, _requestGroup->getFilePath().c_str());
|
logger->error(MSG_DOWNLOAD_NOT_COMPLETE, cuid,
|
||||||
|
_requestGroup->getDownloadContext()->getBasePath().c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "FileAllocationCommand.h"
|
#include "FileAllocationCommand.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ private:
|
||||||
bool requested;
|
bool requested;
|
||||||
std::deque<SharedHandle<Request> > _requestPool;
|
std::deque<SharedHandle<Request> > _requestPool;
|
||||||
std::deque<SharedHandle<Request> > _inFlightRequests;
|
std::deque<SharedHandle<Request> > _inFlightRequests;
|
||||||
|
std::string _contentType;
|
||||||
public:
|
public:
|
||||||
FileEntry():length(0), offset(0), extracted(false), requested(false) {}
|
FileEntry():length(0), offset(0), extracted(false), requested(false) {}
|
||||||
|
|
||||||
|
@ -128,6 +129,13 @@ public:
|
||||||
// Inserts _uris and _spentUris into uris.
|
// Inserts _uris and _spentUris into uris.
|
||||||
void getUris(std::deque<std::string>& uris) const;
|
void getUris(std::deque<std::string>& uris) const;
|
||||||
|
|
||||||
|
void setContentType(const std::string& contentType)
|
||||||
|
{
|
||||||
|
_contentType = contentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& getContentType() const { return _contentType; }
|
||||||
|
|
||||||
std::string selectUri(const SharedHandle<URISelector>& uriSelector);
|
std::string selectUri(const SharedHandle<URISelector>& uriSelector);
|
||||||
|
|
||||||
// If pooled Request object is available, one of them is removed
|
// If pooled Request object is available, one of them is removed
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "RecoverableException.h"
|
#include "RecoverableException.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "FtpFinishDownloadCommand.h"
|
#include "FtpFinishDownloadCommand.h"
|
||||||
#include "FtpConnection.h"
|
#include "FtpConnection.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#include "SocketCore.h"
|
#include "SocketCore.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "HttpConnection.h"
|
#include "HttpConnection.h"
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Segment.h"
|
#include "Segment.h"
|
||||||
#include "SingleFileDownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "DefaultBtProgressInfoFile.h"
|
#include "DefaultBtProgressInfoFile.h"
|
||||||
#include "RequestGroupMan.h"
|
#include "RequestGroupMan.h"
|
||||||
#include "DownloadFailureException.h"
|
#include "DownloadFailureException.h"
|
||||||
|
@ -328,17 +328,17 @@ bool FtpNegotiationCommand::sendSize() {
|
||||||
|
|
||||||
bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
||||||
{
|
{
|
||||||
SingleFileDownloadContextHandle dctx =
|
|
||||||
dynamic_pointer_cast<SingleFileDownloadContext>(_requestGroup->getDownloadContext());
|
|
||||||
dctx->setTotalLength(totalLength);
|
|
||||||
_fileEntry->setLength(totalLength);
|
_fileEntry->setLength(totalLength);
|
||||||
dctx->setFilename
|
if(getOption()->get(PREF_OUT).empty()) {
|
||||||
(strconcat(dctx->getDir(), "/", Util::urldecode(req->getFile())));
|
_fileEntry->setPath
|
||||||
|
(strconcat(getDownloadContext()->getDir(),
|
||||||
|
"/", Util::urldecode(req->getFile())));
|
||||||
|
}
|
||||||
_requestGroup->preDownloadProcessing();
|
_requestGroup->preDownloadProcessing();
|
||||||
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
||||||
throw DOWNLOAD_FAILURE_EXCEPTION
|
throw DOWNLOAD_FAILURE_EXCEPTION
|
||||||
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
|
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
|
||||||
_requestGroup->getFilePath().c_str()).str());
|
_requestGroup->getFirstFilePath().c_str()).str());
|
||||||
}
|
}
|
||||||
if(totalLength == 0) {
|
if(totalLength == 0) {
|
||||||
|
|
||||||
|
@ -361,7 +361,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
||||||
|
|
||||||
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||||
_requestGroup->getGID(),
|
_requestGroup->getGID(),
|
||||||
_requestGroup->getFilePath().c_str());
|
_requestGroup->getFirstFilePath().c_str());
|
||||||
|
|
||||||
poolConnection();
|
poolConnection();
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
||||||
_requestGroup->initPieceStorage();
|
_requestGroup->initPieceStorage();
|
||||||
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
|
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
|
||||||
|
|
||||||
if(dctx->knowsTotalLength()) {
|
if(getDownloadContext()->knowsTotalLength()) {
|
||||||
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
||||||
poolConnection();
|
poolConnection();
|
||||||
return false;
|
return false;
|
||||||
|
@ -400,7 +400,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
||||||
|
|
||||||
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||||
_requestGroup->getGID(),
|
_requestGroup->getGID(),
|
||||||
_requestGroup->getFilePath().c_str());
|
_requestGroup->getFirstFilePath().c_str());
|
||||||
|
|
||||||
poolConnection();
|
poolConnection();
|
||||||
|
|
||||||
|
@ -444,10 +444,7 @@ bool FtpNegotiationCommand::recvSize() {
|
||||||
// command, resuming and segmented downloading are disabled when the first
|
// command, resuming and segmented downloading are disabled when the first
|
||||||
// contacted FTP server doesn't support it.
|
// contacted FTP server doesn't support it.
|
||||||
if(_requestGroup->getPieceStorage().isNull()) {
|
if(_requestGroup->getPieceStorage().isNull()) {
|
||||||
SingleFileDownloadContextHandle dctx =
|
getDownloadContext()->markTotalLengthIsUnknown();
|
||||||
dynamic_pointer_cast<SingleFileDownloadContext>
|
|
||||||
(_requestGroup->getDownloadContext());
|
|
||||||
dctx->markTotalLengthIsUnknown();
|
|
||||||
return onFileSizeDetermined(0);
|
return onFileSizeDetermined(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "FtpTunnelResponseCommand.h"
|
#include "FtpTunnelResponseCommand.h"
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "HttpRequest.h"
|
#include "HttpRequest.h"
|
||||||
#include "Segment.h"
|
#include "Segment.h"
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "HandshakeExtensionMessage.h"
|
#include "HandshakeExtensionMessage.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
|
@ -107,11 +106,6 @@ void HandshakeExtensionMessage::setPeer(const PeerHandle& peer)
|
||||||
_peer = peer;
|
_peer = peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandshakeExtensionMessage::setBtContext(const BtContextHandle& btContext)
|
|
||||||
{
|
|
||||||
_btContext = btContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t HandshakeExtensionMessage::getExtensionMessageID(const std::string& name) const
|
uint8_t HandshakeExtensionMessage::getExtensionMessageID(const std::string& name) const
|
||||||
{
|
{
|
||||||
std::map<std::string, uint8_t>::const_iterator i = _extensions.find(name);
|
std::map<std::string, uint8_t>::const_iterator i = _extensions.find(name);
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
|
||||||
class Peer;
|
class Peer;
|
||||||
class Logger;
|
class Logger;
|
||||||
class HandshakeExtensionMessage;
|
class HandshakeExtensionMessage;
|
||||||
|
@ -57,8 +56,6 @@ private:
|
||||||
|
|
||||||
std::map<std::string, uint8_t> _extensions;
|
std::map<std::string, uint8_t> _extensions;
|
||||||
|
|
||||||
SharedHandle<BtContext> _btContext;
|
|
||||||
|
|
||||||
SharedHandle<Peer> _peer;
|
SharedHandle<Peer> _peer;
|
||||||
|
|
||||||
Logger* _logger;
|
Logger* _logger;
|
||||||
|
@ -120,8 +117,6 @@ public:
|
||||||
|
|
||||||
void setPeer(const SharedHandle<Peer>& peer);
|
void setPeer(const SharedHandle<Peer>& peer);
|
||||||
|
|
||||||
void setBtContext(const SharedHandle<BtContext>& btContext);
|
|
||||||
|
|
||||||
static HandshakeExtensionMessageHandle create(const unsigned char* data,
|
static HandshakeExtensionMessageHandle create(const unsigned char* data,
|
||||||
size_t dataLength);
|
size_t dataLength);
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "RequestGroupMan.h"
|
#include "RequestGroupMan.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
#include "HttpResponse.h"
|
#include "HttpResponse.h"
|
||||||
#include "HttpHeader.h"
|
#include "HttpHeader.h"
|
||||||
#include "Range.h"
|
#include "Range.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "HttpProxyResponseCommand.h"
|
#include "HttpProxyResponseCommand.h"
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "HttpRequest.h"
|
#include "HttpRequest.h"
|
||||||
#include "Segment.h"
|
#include "Segment.h"
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,7 @@ namespace aria2 {
|
||||||
|
|
||||||
const std::string HttpRequest::USER_AGENT("aria2");
|
const std::string HttpRequest::USER_AGENT("aria2");
|
||||||
|
|
||||||
HttpRequest::HttpRequest():entityLength(0),
|
HttpRequest::HttpRequest():_contentEncodingEnabled(true),
|
||||||
_contentEncodingEnabled(true),
|
|
||||||
userAgent(USER_AGENT)
|
userAgent(USER_AGENT)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -83,7 +82,8 @@ off_t HttpRequest::getEndByte() const
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
if(request->isPipeliningEnabled()) {
|
if(request->isPipeliningEnabled()) {
|
||||||
return _fileEntry->gtoloff(segment->getPosition()+segment->getLength()-1);
|
off_t endByte = _fileEntry->gtoloff(segment->getPosition()+segment->getLength()-1);
|
||||||
|
return std::min(endByte, _fileEntry->getLastOffset()-1);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,8 @@ RangeHandle HttpRequest::getRange() const
|
||||||
if(segment.isNull()) {
|
if(segment.isNull()) {
|
||||||
return SharedHandle<Range>(new Range());
|
return SharedHandle<Range>(new Range());
|
||||||
} else {
|
} else {
|
||||||
return SharedHandle<Range>(new Range(getStartByte(), getEndByte(), entityLength));
|
return SharedHandle<Range>(new Range(getStartByte(), getEndByte(),
|
||||||
|
_fileEntry->getLength()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +108,9 @@ bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const
|
||||||
}
|
}
|
||||||
if((getStartByte() == range->getStartByte()) &&
|
if((getStartByte() == range->getStartByte()) &&
|
||||||
((getEndByte() == 0) ||
|
((getEndByte() == 0) ||
|
||||||
((getEndByte() > 0) && (getEndByte() == range->getEndByte()))) &&
|
(getEndByte() == range->getEndByte())) &&
|
||||||
((entityLength == 0) ||
|
((_fileEntry->getLength() == 0) ||
|
||||||
((entityLength > 0) && (entityLength == range->getEntityLength())))) {
|
(_fileEntry->getLength() == range->getEntityLength()))) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
|
@ -64,8 +65,6 @@ private:
|
||||||
|
|
||||||
SharedHandle<Segment> segment;
|
SharedHandle<Segment> segment;
|
||||||
|
|
||||||
uint64_t entityLength;
|
|
||||||
|
|
||||||
bool _contentEncodingEnabled;
|
bool _contentEncodingEnabled;
|
||||||
|
|
||||||
std::string userAgent;
|
std::string userAgent;
|
||||||
|
@ -97,17 +96,10 @@ public:
|
||||||
|
|
||||||
void setRequest(const SharedHandle<Request>& request);
|
void setRequest(const SharedHandle<Request>& request);
|
||||||
|
|
||||||
/**
|
|
||||||
* entityLength is used in isRangeSatisfied() method.
|
|
||||||
*/
|
|
||||||
void setEntityLength(uint64_t entityLength)
|
|
||||||
{
|
|
||||||
this->entityLength = entityLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t getEntityLength() const
|
uint64_t getEntityLength() const
|
||||||
{
|
{
|
||||||
return entityLength;
|
assert(!_fileEntry.isNull());
|
||||||
|
return _fileEntry->getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& getHost() const
|
const std::string& getHost() const
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
#include "CookieStorage.h"
|
#include "CookieStorage.h"
|
||||||
#include "AuthConfigFactory.h"
|
#include "AuthConfigFactory.h"
|
||||||
#include "AuthConfig.h"
|
#include "AuthConfig.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -89,7 +90,6 @@ createHttpRequest(const SharedHandle<Request>& req,
|
||||||
httpRequest->setRequest(req);
|
httpRequest->setRequest(req);
|
||||||
httpRequest->setFileEntry(fileEntry);
|
httpRequest->setFileEntry(fileEntry);
|
||||||
httpRequest->setSegment(segment);
|
httpRequest->setSegment(segment);
|
||||||
httpRequest->setEntityLength(fileEntry->getLength());
|
|
||||||
httpRequest->addHeader(option->get(PREF_HEADER));
|
httpRequest->addHeader(option->get(PREF_HEADER));
|
||||||
httpRequest->setCookieStorage(cookieStorage);
|
httpRequest->setCookieStorage(cookieStorage);
|
||||||
httpRequest->setAuthConfigFactory(authConfigFactory);
|
httpRequest->setAuthConfigFactory(authConfigFactory);
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "HttpResponseCommand.h"
|
#include "HttpResponseCommand.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
#include "SingleFileDownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "ServerHost.h"
|
#include "ServerHost.h"
|
||||||
|
@ -136,18 +136,20 @@ bool HttpResponseCommand::executeInternal()
|
||||||
}
|
}
|
||||||
if(_requestGroup->getPieceStorage().isNull()) {
|
if(_requestGroup->getPieceStorage().isNull()) {
|
||||||
uint64_t totalLength = httpResponse->getEntityLength();
|
uint64_t totalLength = httpResponse->getEntityLength();
|
||||||
SingleFileDownloadContextHandle dctx =
|
|
||||||
dynamic_pointer_cast<SingleFileDownloadContext>(_requestGroup->getDownloadContext());
|
|
||||||
dctx->setTotalLength(totalLength);
|
|
||||||
_fileEntry->setLength(totalLength);
|
_fileEntry->setLength(totalLength);
|
||||||
dctx->setFilename
|
// We assume that in this context
|
||||||
(strconcat(dctx->getDir(), "/", httpResponse->determinFilename()));
|
// DownloadContext::getFileEntries().size() == 1
|
||||||
dctx->setContentType(httpResponse->getContentType());
|
if(getOption()->get(PREF_OUT).empty()) {
|
||||||
|
_fileEntry->setPath
|
||||||
|
(strconcat(getDownloadContext()->getDir(),
|
||||||
|
"/", httpResponse->determinFilename()));
|
||||||
|
}
|
||||||
|
_fileEntry->setContentType(httpResponse->getContentType());
|
||||||
_requestGroup->preDownloadProcessing();
|
_requestGroup->preDownloadProcessing();
|
||||||
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
||||||
throw DOWNLOAD_FAILURE_EXCEPTION
|
throw DOWNLOAD_FAILURE_EXCEPTION
|
||||||
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
|
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
|
||||||
_requestGroup->getFilePath().c_str()).str());
|
_requestGroup->getFirstFilePath().c_str()).str());
|
||||||
}
|
}
|
||||||
// update last modified time
|
// update last modified time
|
||||||
updateLastModifiedTime(httpResponse->getLastModifiedTime());
|
updateLastModifiedTime(httpResponse->getLastModifiedTime());
|
||||||
|
@ -156,13 +158,13 @@ bool HttpResponseCommand::executeInternal()
|
||||||
// assume we can do segmented downloading
|
// assume we can do segmented downloading
|
||||||
if(totalLength == 0 || shouldInflateContentEncoding(httpResponse)) {
|
if(totalLength == 0 || shouldInflateContentEncoding(httpResponse)) {
|
||||||
// we ignore content-length when inflate is required
|
// we ignore content-length when inflate is required
|
||||||
dctx->setTotalLength(0);
|
_fileEntry->setLength(0);
|
||||||
if(req->getMethod() == Request::METHOD_GET &&
|
if(req->getMethod() == Request::METHOD_GET &&
|
||||||
(totalLength != 0 ||
|
(totalLength != 0 ||
|
||||||
!httpResponse->getHttpHeader()->defined(HttpHeader::CONTENT_LENGTH))){
|
!httpResponse->getHttpHeader()->defined(HttpHeader::CONTENT_LENGTH))){
|
||||||
// dctx->knowsTotalLength() == true only when server says the
|
// DownloadContext::knowsTotalLength() == true only when
|
||||||
// size of file is 0 explicitly.
|
// server says the size of file is 0 explicitly.
|
||||||
dctx->markTotalLengthIsUnknown();
|
getDownloadContext()->markTotalLengthIsUnknown();
|
||||||
}
|
}
|
||||||
return handleOtherEncoding(httpResponse);
|
return handleOtherEncoding(httpResponse);
|
||||||
} else {
|
} else {
|
||||||
|
@ -241,7 +243,7 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpRe
|
||||||
|
|
||||||
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||||
_requestGroup->getGID(),
|
_requestGroup->getGID(),
|
||||||
_requestGroup->getFilePath().c_str());
|
_requestGroup->getFirstFilePath().c_str());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -249,7 +251,7 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpRe
|
||||||
DownloadCommand* command = 0;
|
DownloadCommand* command = 0;
|
||||||
try {
|
try {
|
||||||
_requestGroup->loadAndOpenFile(infoFile);
|
_requestGroup->loadAndOpenFile(infoFile);
|
||||||
File file(_requestGroup->getFilePath());
|
File file(_requestGroup->getFirstFilePath());
|
||||||
|
|
||||||
SegmentHandle segment = _requestGroup->getSegmentMan()->getSegment(cuid, 0);
|
SegmentHandle segment = _requestGroup->getSegmentMan()->getSegment(cuid, 0);
|
||||||
// pipelining requires implicit range specified. But the request for
|
// pipelining requires implicit range specified. But the request for
|
||||||
|
@ -335,7 +337,7 @@ bool HttpResponseCommand::handleOtherEncoding(const HttpResponseHandle& httpResp
|
||||||
|
|
||||||
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||||
_requestGroup->getGID(),
|
_requestGroup->getGID(),
|
||||||
_requestGroup->getFilePath().c_str());
|
_requestGroup->getFirstFilePath().c_str());
|
||||||
|
|
||||||
poolConnection();
|
poolConnection();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include "XmlRpcMethod.h"
|
#include "XmlRpcMethod.h"
|
||||||
#include "XmlRpcMethodFactory.h"
|
#include "XmlRpcMethodFactory.h"
|
||||||
#include "XmlRpcResponse.h"
|
#include "XmlRpcResponse.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include "CookieStorage.h"
|
#include "CookieStorage.h"
|
||||||
#include "AuthConfigFactory.h"
|
#include "AuthConfigFactory.h"
|
||||||
#include "AuthConfig.h"
|
#include "AuthConfig.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "SocketCore.h"
|
#include "SocketCore.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "PeerConnection.h"
|
#include "PeerConnection.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "BtRuntime.h"
|
#include "BtRuntime.h"
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
|
@ -52,6 +51,8 @@
|
||||||
#include "ARC4Encryptor.h"
|
#include "ARC4Encryptor.h"
|
||||||
#include "ARC4Decryptor.h"
|
#include "ARC4Decryptor.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -60,13 +61,11 @@ InitiatorMSEHandshakeCommand::InitiatorMSEHandshakeCommand
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
const SharedHandle<Peer>& p,
|
const SharedHandle<Peer>& p,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const SharedHandle<BtContext>& btContext,
|
|
||||||
const SharedHandle<BtRuntime>& btRuntime,
|
const SharedHandle<BtRuntime>& btRuntime,
|
||||||
const SharedHandle<SocketCore>& s):
|
const SharedHandle<SocketCore>& s):
|
||||||
|
|
||||||
PeerAbstractCommand(cuid, p, e, s),
|
PeerAbstractCommand(cuid, p, e, s),
|
||||||
_requestGroup(requestGroup),
|
_requestGroup(requestGroup),
|
||||||
_btContext(btContext),
|
|
||||||
_btRuntime(btRuntime),
|
_btRuntime(btRuntime),
|
||||||
_sequence(INITIATOR_SEND_KEY),
|
_sequence(INITIATOR_SEND_KEY),
|
||||||
_mseHandshake(new MSEHandshake(cuid, socket, getOption().get()))
|
_mseHandshake(new MSEHandshake(cuid, socket, getOption().get()))
|
||||||
|
@ -114,7 +113,8 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
|
||||||
break;
|
break;
|
||||||
case INITIATOR_WAIT_KEY: {
|
case INITIATOR_WAIT_KEY: {
|
||||||
if(_mseHandshake->receivePublicKey()) {
|
if(_mseHandshake->receivePublicKey()) {
|
||||||
_mseHandshake->initCipher(_btContext->getInfoHash());
|
_mseHandshake->initCipher
|
||||||
|
(bittorrent::getInfoHash(_requestGroup->getDownloadContext()));;
|
||||||
if(_mseHandshake->sendInitiatorStep2()) {
|
if(_mseHandshake->sendInitiatorStep2()) {
|
||||||
_sequence = INITIATOR_FIND_VC_MARKER;
|
_sequence = INITIATOR_FIND_VC_MARKER;
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,11 +151,11 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
|
||||||
_mseHandshake->getDecryptor());
|
_mseHandshake->getDecryptor());
|
||||||
}
|
}
|
||||||
PeerInteractionCommand* c =
|
PeerInteractionCommand* c =
|
||||||
new PeerInteractionCommand(cuid, _requestGroup, peer, e, _btContext,
|
new PeerInteractionCommand
|
||||||
_btRuntime, _pieceStorage,
|
(cuid, _requestGroup, peer, e, _btRuntime, _pieceStorage,
|
||||||
socket,
|
socket,
|
||||||
PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE,
|
PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE,
|
||||||
peerConnection);
|
peerConnection);
|
||||||
c->setPeerStorage(_peerStorage);
|
c->setPeerStorage(_peerStorage);
|
||||||
e->commands.push_back(c);
|
e->commands.push_back(c);
|
||||||
return true;
|
return true;
|
||||||
|
@ -176,7 +176,7 @@ bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
|
||||||
peer->usedBy(e->newCUID());
|
peer->usedBy(e->newCUID());
|
||||||
PeerInitiateConnectionCommand* command =
|
PeerInitiateConnectionCommand* command =
|
||||||
new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer,
|
new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer,
|
||||||
e, _btContext, _btRuntime);
|
e, _btRuntime);
|
||||||
command->setPeerStorage(_peerStorage);
|
command->setPeerStorage(_peerStorage);
|
||||||
command->setPieceStorage(_pieceStorage);
|
command->setPieceStorage(_pieceStorage);
|
||||||
e->commands.push_back(command);
|
e->commands.push_back(command);
|
||||||
|
@ -187,7 +187,7 @@ bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
|
||||||
logger->info("CUID#%d - Retry using legacy BitTorrent handshake.", cuid);
|
logger->info("CUID#%d - Retry using legacy BitTorrent handshake.", cuid);
|
||||||
PeerInitiateConnectionCommand* command =
|
PeerInitiateConnectionCommand* command =
|
||||||
new PeerInitiateConnectionCommand(cuid, _requestGroup, peer, e,
|
new PeerInitiateConnectionCommand(cuid, _requestGroup, peer, e,
|
||||||
_btContext, _btRuntime, false);
|
_btRuntime, false);
|
||||||
command->setPeerStorage(_peerStorage);
|
command->setPeerStorage(_peerStorage);
|
||||||
command->setPieceStorage(_pieceStorage);
|
command->setPieceStorage(_pieceStorage);
|
||||||
e->commands.push_back(command);
|
e->commands.push_back(command);
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class RequestGroup;
|
class RequestGroup;
|
||||||
class BtContext;
|
|
||||||
class PeerStorage;
|
class PeerStorage;
|
||||||
class PieceStorage;
|
class PieceStorage;
|
||||||
class BtRuntime;
|
class BtRuntime;
|
||||||
|
@ -61,8 +60,6 @@ public:
|
||||||
private:
|
private:
|
||||||
RequestGroup* _requestGroup;
|
RequestGroup* _requestGroup;
|
||||||
|
|
||||||
SharedHandle<BtContext> _btContext;
|
|
||||||
|
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
|
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
|
@ -79,13 +76,13 @@ protected:
|
||||||
virtual void onAbort();
|
virtual void onAbort();
|
||||||
virtual bool exitBeforeExecute();
|
virtual bool exitBeforeExecute();
|
||||||
public:
|
public:
|
||||||
InitiatorMSEHandshakeCommand(int32_t cuid,
|
InitiatorMSEHandshakeCommand
|
||||||
RequestGroup* requestGroup,
|
(int32_t cuid,
|
||||||
const SharedHandle<Peer>& peer,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
const SharedHandle<Peer>& peer,
|
||||||
const SharedHandle<BtContext>& btContext,
|
DownloadEngine* e,
|
||||||
const SharedHandle<BtRuntime>& btRuntime,
|
const SharedHandle<BtRuntime>& btRuntime,
|
||||||
const SharedHandle<SocketCore>& s);
|
const SharedHandle<SocketCore>& s);
|
||||||
|
|
||||||
virtual ~InitiatorMSEHandshakeCommand();
|
virtual ~InitiatorMSEHandshakeCommand();
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "SingleFileDownloadContext.h"
|
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "messageDigest.h"
|
#include "messageDigest.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
|
@ -46,14 +45,16 @@
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
#include "BitfieldMan.h"
|
#include "BitfieldMan.h"
|
||||||
|
#include "DownloadContext.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
#define BUFSIZE (256*1024)
|
#define BUFSIZE (256*1024)
|
||||||
#define ALIGNMENT 512
|
#define ALIGNMENT 512
|
||||||
|
|
||||||
IteratableChecksumValidator::IteratableChecksumValidator(const SingleFileDownloadContextHandle& dctx,
|
IteratableChecksumValidator::IteratableChecksumValidator
|
||||||
const PieceStorageHandle& pieceStorage):
|
(const SharedHandle<DownloadContext>& dctx,
|
||||||
|
const PieceStorageHandle& pieceStorage):
|
||||||
_dctx(dctx),
|
_dctx(dctx),
|
||||||
_pieceStorage(pieceStorage),
|
_pieceStorage(pieceStorage),
|
||||||
_currentOffset(0),
|
_currentOffset(0),
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class SingleFileDownloadContext;
|
class DownloadContext;
|
||||||
class PieceStorage;
|
class PieceStorage;
|
||||||
class Logger;
|
class Logger;
|
||||||
class MessageDigestContext;
|
class MessageDigestContext;
|
||||||
|
@ -47,7 +47,7 @@ class MessageDigestContext;
|
||||||
class IteratableChecksumValidator:public IteratableValidator
|
class IteratableChecksumValidator:public IteratableValidator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SharedHandle<SingleFileDownloadContext> _dctx;
|
SharedHandle<DownloadContext> _dctx;
|
||||||
|
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ private:
|
||||||
unsigned char* _buffer;
|
unsigned char* _buffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IteratableChecksumValidator(const SharedHandle<SingleFileDownloadContext>& dctx,
|
IteratableChecksumValidator(const SharedHandle<DownloadContext>& dctx,
|
||||||
const SharedHandle<PieceStorage>& pieceStorage);
|
const SharedHandle<PieceStorage>& pieceStorage);
|
||||||
|
|
||||||
virtual ~IteratableChecksumValidator();
|
virtual ~IteratableChecksumValidator();
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace aria2 {
|
||||||
#define ALIGNMENT 512
|
#define ALIGNMENT 512
|
||||||
|
|
||||||
IteratableChunkChecksumValidator::
|
IteratableChunkChecksumValidator::
|
||||||
IteratableChunkChecksumValidator(const DownloadContextHandle& dctx,
|
IteratableChunkChecksumValidator(const SharedHandle<DownloadContext>& dctx,
|
||||||
const PieceStorageHandle& pieceStorage):
|
const PieceStorageHandle& pieceStorage):
|
||||||
_dctx(dctx),
|
_dctx(dctx),
|
||||||
_pieceStorage(pieceStorage),
|
_pieceStorage(pieceStorage),
|
||||||
|
@ -153,7 +153,7 @@ std::string IteratableChunkChecksumValidator::digest(off_t offset, size_t length
|
||||||
curoffset);
|
curoffset);
|
||||||
if(r == 0 || r < static_cast<size_t>(woffset)) {
|
if(r == 0 || r < static_cast<size_t>(woffset)) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(StringFormat(EX_FILE_READ, _dctx->getActualBasePath().c_str(),
|
(StringFormat(EX_FILE_READ, _dctx->getBasePath().c_str(),
|
||||||
strerror(errno)).str());
|
strerror(errno)).str());
|
||||||
}
|
}
|
||||||
size_t wlength;
|
size_t wlength;
|
||||||
|
|
|
@ -50,10 +50,11 @@
|
||||||
#include "MessageDigestHelper.h"
|
#include "MessageDigestHelper.h"
|
||||||
#include "SimpleRandomizer.h"
|
#include "SimpleRandomizer.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "BtContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
|
#include "bittorrent_helper.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -435,7 +436,7 @@ bool MSEHandshake::findReceiverHashMarker()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MSEHandshake::receiveReceiverHashAndPadCLength
|
bool MSEHandshake::receiveReceiverHashAndPadCLength
|
||||||
(const std::deque<SharedHandle<BtContext> >& btContexts)
|
(const std::deque<SharedHandle<DownloadContext> >& downloadContexts)
|
||||||
{
|
{
|
||||||
size_t r = 20+VC_LENGTH+CRYPTO_BITFIELD_LENGTH+2/*PadC length*/-_rbufLength;
|
size_t r = 20+VC_LENGTH+CRYPTO_BITFIELD_LENGTH+2/*PadC length*/-_rbufLength;
|
||||||
if(r > receiveNBytes(r)) {
|
if(r > receiveNBytes(r)) {
|
||||||
|
@ -444,22 +445,23 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
|
||||||
// resolve info hash
|
// resolve info hash
|
||||||
// pointing to the position of HASH('req2', SKEY) xor HASH('req3', S)
|
// pointing to the position of HASH('req2', SKEY) xor HASH('req3', S)
|
||||||
unsigned char* rbufptr = _rbuf;
|
unsigned char* rbufptr = _rbuf;
|
||||||
SharedHandle<BtContext> btContext;
|
SharedHandle<DownloadContext> downloadContext;
|
||||||
for(std::deque<SharedHandle<BtContext> >::const_iterator i = btContexts.begin();
|
for(std::deque<SharedHandle<DownloadContext> >::const_iterator i =
|
||||||
i != btContexts.end(); ++i) {
|
downloadContexts.begin(); i != downloadContexts.end(); ++i) {
|
||||||
unsigned char md[20];
|
unsigned char md[20];
|
||||||
createReq23Hash(md, (*i)->getInfoHash());
|
const BDE& torrentAttrs = (*i)->getAttribute(bittorrent::BITTORRENT);
|
||||||
|
createReq23Hash(md, torrentAttrs[bittorrent::INFO_HASH].uc());
|
||||||
if(memcmp(md, rbufptr, sizeof(md)) == 0) {
|
if(memcmp(md, rbufptr, sizeof(md)) == 0) {
|
||||||
_logger->debug("CUID#%d - info hash found: %s", _cuid, (*i)->getInfoHashAsString().c_str());
|
_logger->debug("CUID#%d - info hash found: %s", _cuid,
|
||||||
btContext = *i;
|
Util::toHex(torrentAttrs[bittorrent::INFO_HASH].s()).c_str());
|
||||||
|
downloadContext = *i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(btContext.isNull()) {
|
if(downloadContext.isNull()) {
|
||||||
throw DL_ABORT_EX("Unknown info hash.");
|
throw DL_ABORT_EX("Unknown info hash.");
|
||||||
}
|
}
|
||||||
initCipher(btContext->getInfoHash());
|
initCipher(bittorrent::getInfoHash(downloadContext));
|
||||||
|
|
||||||
// decrypt VC
|
// decrypt VC
|
||||||
rbufptr += 20;
|
rbufptr += 20;
|
||||||
verifyVC(rbufptr);
|
verifyVC(rbufptr);
|
||||||
|
|
|
@ -51,7 +51,7 @@ class SocketCore;
|
||||||
class DHKeyExchange;
|
class DHKeyExchange;
|
||||||
class ARC4Encryptor;
|
class ARC4Encryptor;
|
||||||
class ARC4Decryptor;
|
class ARC4Decryptor;
|
||||||
class BtContext;
|
class DownloadContext;
|
||||||
|
|
||||||
class MSEHandshake {
|
class MSEHandshake {
|
||||||
public:
|
public:
|
||||||
|
@ -158,7 +158,7 @@ public:
|
||||||
bool findReceiverHashMarker();
|
bool findReceiverHashMarker();
|
||||||
|
|
||||||
bool receiveReceiverHashAndPadCLength
|
bool receiveReceiverHashAndPadCLength
|
||||||
(const std::deque<SharedHandle<BtContext> >& btContexts);
|
(const std::deque<SharedHandle<DownloadContext> >& downloadContexts);
|
||||||
|
|
||||||
bool receiveReceiverIALength();
|
bool receiveReceiverIALength();
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,6 @@ SRCS = Socket.h\
|
||||||
ByteArrayDiskWriterFactory.cc ByteArrayDiskWriterFactory.h\
|
ByteArrayDiskWriterFactory.cc ByteArrayDiskWriterFactory.h\
|
||||||
ServerHost.cc ServerHost.h\
|
ServerHost.cc ServerHost.h\
|
||||||
DownloadContext.cc DownloadContext.h\
|
DownloadContext.cc DownloadContext.h\
|
||||||
SingleFileDownloadContext.cc SingleFileDownloadContext.h\
|
|
||||||
TimedHaltCommand.cc TimedHaltCommand.h\
|
TimedHaltCommand.cc TimedHaltCommand.h\
|
||||||
CUIDCounter.h\
|
CUIDCounter.h\
|
||||||
DNSCache.h\
|
DNSCache.h\
|
||||||
|
@ -294,8 +293,6 @@ SRCS += PeerMessageUtil.cc PeerMessageUtil.h\
|
||||||
PeerListProcessor.h\
|
PeerListProcessor.h\
|
||||||
AnnounceTier.h\
|
AnnounceTier.h\
|
||||||
AnnounceList.h AnnounceList.cc\
|
AnnounceList.h AnnounceList.cc\
|
||||||
BtContext.h\
|
|
||||||
DefaultBtContext.cc DefaultBtContext.h\
|
|
||||||
PeerStorage.h\
|
PeerStorage.h\
|
||||||
DefaultPeerStorage.cc DefaultPeerStorage.h\
|
DefaultPeerStorage.cc DefaultPeerStorage.h\
|
||||||
BtAnnounce.cc BtAnnounce.h\
|
BtAnnounce.cc BtAnnounce.h\
|
||||||
|
@ -436,7 +433,8 @@ SRCS += PeerMessageUtil.cc PeerMessageUtil.h\
|
||||||
RangeBtMessageValidator.h\
|
RangeBtMessageValidator.h\
|
||||||
IndexBtMessageValidator.h\
|
IndexBtMessageValidator.h\
|
||||||
ExtensionMessageRegistry.h\
|
ExtensionMessageRegistry.h\
|
||||||
bencode.cc bencode.h
|
bencode.cc bencode.h\
|
||||||
|
bittorrent_helper.cc bittorrent_helper.h
|
||||||
endif # ENABLE_BITTORRENT
|
endif # ENABLE_BITTORRENT
|
||||||
|
|
||||||
if ENABLE_METALINK
|
if ENABLE_METALINK
|
||||||
|
|
|
@ -89,8 +89,6 @@ bin_PROGRAMS = aria2c$(EXEEXT)
|
||||||
@ENABLE_BITTORRENT_TRUE@ PeerListProcessor.h\
|
@ENABLE_BITTORRENT_TRUE@ PeerListProcessor.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ AnnounceTier.h\
|
@ENABLE_BITTORRENT_TRUE@ AnnounceTier.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ AnnounceList.h AnnounceList.cc\
|
@ENABLE_BITTORRENT_TRUE@ AnnounceList.h AnnounceList.cc\
|
||||||
@ENABLE_BITTORRENT_TRUE@ BtContext.h\
|
|
||||||
@ENABLE_BITTORRENT_TRUE@ DefaultBtContext.cc DefaultBtContext.h\
|
|
||||||
@ENABLE_BITTORRENT_TRUE@ PeerStorage.h\
|
@ENABLE_BITTORRENT_TRUE@ PeerStorage.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorage.cc DefaultPeerStorage.h\
|
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorage.cc DefaultPeerStorage.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ BtAnnounce.cc BtAnnounce.h\
|
@ENABLE_BITTORRENT_TRUE@ BtAnnounce.cc BtAnnounce.h\
|
||||||
|
@ -231,7 +229,8 @@ bin_PROGRAMS = aria2c$(EXEEXT)
|
||||||
@ENABLE_BITTORRENT_TRUE@ RangeBtMessageValidator.h\
|
@ENABLE_BITTORRENT_TRUE@ RangeBtMessageValidator.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ IndexBtMessageValidator.h\
|
@ENABLE_BITTORRENT_TRUE@ IndexBtMessageValidator.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ ExtensionMessageRegistry.h\
|
@ENABLE_BITTORRENT_TRUE@ ExtensionMessageRegistry.h\
|
||||||
@ENABLE_BITTORRENT_TRUE@ bencode.cc bencode.h
|
@ENABLE_BITTORRENT_TRUE@ bencode.cc bencode.h\
|
||||||
|
@ENABLE_BITTORRENT_TRUE@ bittorrent_helper.cc bittorrent_helper.h
|
||||||
|
|
||||||
@ENABLE_METALINK_TRUE@am__append_14 = Metalinker.cc Metalinker.h\
|
@ENABLE_METALINK_TRUE@am__append_14 = Metalinker.cc Metalinker.h\
|
||||||
@ENABLE_METALINK_TRUE@ MetalinkEntry.cc MetalinkEntry.h\
|
@ENABLE_METALINK_TRUE@ MetalinkEntry.cc MetalinkEntry.h\
|
||||||
|
@ -400,11 +399,10 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
||||||
PeerConnection.cc PeerConnection.h ByteArrayDiskWriter.cc \
|
PeerConnection.cc PeerConnection.h ByteArrayDiskWriter.cc \
|
||||||
ByteArrayDiskWriter.h ByteArrayDiskWriterFactory.cc \
|
ByteArrayDiskWriter.h ByteArrayDiskWriterFactory.cc \
|
||||||
ByteArrayDiskWriterFactory.h ServerHost.cc ServerHost.h \
|
ByteArrayDiskWriterFactory.h ServerHost.cc ServerHost.h \
|
||||||
DownloadContext.cc DownloadContext.h \
|
DownloadContext.cc DownloadContext.h TimedHaltCommand.cc \
|
||||||
SingleFileDownloadContext.cc SingleFileDownloadContext.h \
|
TimedHaltCommand.h CUIDCounter.h DNSCache.h DownloadResult.h \
|
||||||
TimedHaltCommand.cc TimedHaltCommand.h CUIDCounter.h \
|
Sequence.h IntSequence.h PostDownloadHandler.h \
|
||||||
DNSCache.h DownloadResult.h Sequence.h IntSequence.h \
|
PreDownloadHandler.h SingletonHolder.h \
|
||||||
PostDownloadHandler.h PreDownloadHandler.h SingletonHolder.h \
|
|
||||||
TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
|
TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
|
||||||
a2netcompat.h a2time.h array_fun.h help_tags.h prefs.cc \
|
a2netcompat.h a2time.h array_fun.h help_tags.h prefs.cc \
|
||||||
prefs.h usage_text.h ProtocolDetector.cc ProtocolDetector.h \
|
prefs.h usage_text.h ProtocolDetector.cc ProtocolDetector.h \
|
||||||
|
@ -466,8 +464,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
||||||
TimeSeedCriteria.h ShareRatioSeedCriteria.h \
|
TimeSeedCriteria.h ShareRatioSeedCriteria.h \
|
||||||
UnionSeedCriteria.h SeedCheckCommand.cc SeedCheckCommand.h \
|
UnionSeedCriteria.h SeedCheckCommand.cc SeedCheckCommand.h \
|
||||||
PeerListProcessor.h AnnounceTier.h AnnounceList.h \
|
PeerListProcessor.h AnnounceTier.h AnnounceList.h \
|
||||||
AnnounceList.cc BtContext.h DefaultBtContext.cc \
|
AnnounceList.cc PeerStorage.h DefaultPeerStorage.cc \
|
||||||
DefaultBtContext.h PeerStorage.h DefaultPeerStorage.cc \
|
|
||||||
DefaultPeerStorage.h BtAnnounce.cc BtAnnounce.h \
|
DefaultPeerStorage.h BtAnnounce.cc BtAnnounce.h \
|
||||||
DefaultBtAnnounce.cc DefaultBtAnnounce.h BtRuntime.h \
|
DefaultBtAnnounce.cc DefaultBtAnnounce.h BtRuntime.h \
|
||||||
BtMessage.h AbstractBtMessage.cc AbstractBtMessage.h \
|
BtMessage.h AbstractBtMessage.cc AbstractBtMessage.h \
|
||||||
|
@ -564,9 +561,9 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
||||||
IndexBtMessage.cc IndexBtMessage.h ZeroBtMessage.cc \
|
IndexBtMessage.cc IndexBtMessage.h ZeroBtMessage.cc \
|
||||||
ZeroBtMessage.h RangeBtMessageValidator.h \
|
ZeroBtMessage.h RangeBtMessageValidator.h \
|
||||||
IndexBtMessageValidator.h ExtensionMessageRegistry.h \
|
IndexBtMessageValidator.h ExtensionMessageRegistry.h \
|
||||||
bencode.cc bencode.h Metalinker.cc Metalinker.h \
|
bencode.cc bencode.h bittorrent_helper.cc bittorrent_helper.h \
|
||||||
MetalinkEntry.cc MetalinkEntry.h MetalinkResource.cc \
|
Metalinker.cc Metalinker.h MetalinkEntry.cc MetalinkEntry.h \
|
||||||
MetalinkResource.h MetalinkProcessor.h \
|
MetalinkResource.cc MetalinkResource.h MetalinkProcessor.h \
|
||||||
MetalinkParserController.cc MetalinkParserController.h \
|
MetalinkParserController.cc MetalinkParserController.h \
|
||||||
MetalinkParserStateMachine.cc MetalinkParserStateMachine.h \
|
MetalinkParserStateMachine.cc MetalinkParserStateMachine.h \
|
||||||
MetalinkParserState.h InitialMetalinkParserState.cc \
|
MetalinkParserState.h InitialMetalinkParserState.cc \
|
||||||
|
@ -638,7 +635,6 @@ am__objects_6 =
|
||||||
@ENABLE_BITTORRENT_TRUE@ PeerChokeCommand.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ PeerChokeCommand.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ SeedCheckCommand.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ SeedCheckCommand.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ AnnounceList.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ AnnounceList.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ DefaultBtContext.$(OBJEXT) \
|
|
||||||
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorage.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorage.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ BtAnnounce.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ BtAnnounce.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ DefaultBtAnnounce.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ DefaultBtAnnounce.$(OBJEXT) \
|
||||||
|
@ -734,7 +730,8 @@ am__objects_6 =
|
||||||
@ENABLE_BITTORRENT_TRUE@ RangeBtMessage.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ RangeBtMessage.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ IndexBtMessage.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ IndexBtMessage.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ ZeroBtMessage.$(OBJEXT) \
|
@ENABLE_BITTORRENT_TRUE@ ZeroBtMessage.$(OBJEXT) \
|
||||||
@ENABLE_BITTORRENT_TRUE@ bencode.$(OBJEXT)
|
@ENABLE_BITTORRENT_TRUE@ bencode.$(OBJEXT) \
|
||||||
|
@ENABLE_BITTORRENT_TRUE@ bittorrent_helper.$(OBJEXT)
|
||||||
@ENABLE_METALINK_TRUE@am__objects_14 = Metalinker.$(OBJEXT) \
|
@ENABLE_METALINK_TRUE@am__objects_14 = Metalinker.$(OBJEXT) \
|
||||||
@ENABLE_METALINK_TRUE@ MetalinkEntry.$(OBJEXT) \
|
@ENABLE_METALINK_TRUE@ MetalinkEntry.$(OBJEXT) \
|
||||||
@ENABLE_METALINK_TRUE@ MetalinkResource.$(OBJEXT) \
|
@ENABLE_METALINK_TRUE@ MetalinkResource.$(OBJEXT) \
|
||||||
|
@ -833,10 +830,9 @@ am__objects_26 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
|
||||||
MultiFileAllocationIterator.$(OBJEXT) PeerConnection.$(OBJEXT) \
|
MultiFileAllocationIterator.$(OBJEXT) PeerConnection.$(OBJEXT) \
|
||||||
ByteArrayDiskWriter.$(OBJEXT) \
|
ByteArrayDiskWriter.$(OBJEXT) \
|
||||||
ByteArrayDiskWriterFactory.$(OBJEXT) ServerHost.$(OBJEXT) \
|
ByteArrayDiskWriterFactory.$(OBJEXT) ServerHost.$(OBJEXT) \
|
||||||
DownloadContext.$(OBJEXT) SingleFileDownloadContext.$(OBJEXT) \
|
DownloadContext.$(OBJEXT) TimedHaltCommand.$(OBJEXT) \
|
||||||
TimedHaltCommand.$(OBJEXT) prefs.$(OBJEXT) \
|
prefs.$(OBJEXT) ProtocolDetector.$(OBJEXT) \
|
||||||
ProtocolDetector.$(OBJEXT) StringFormat.$(OBJEXT) \
|
StringFormat.$(OBJEXT) HttpSkipResponseCommand.$(OBJEXT) \
|
||||||
HttpSkipResponseCommand.$(OBJEXT) \
|
|
||||||
InitiateConnectionCommand.$(OBJEXT) \
|
InitiateConnectionCommand.$(OBJEXT) \
|
||||||
FtpFinishDownloadCommand.$(OBJEXT) A2STR.$(OBJEXT) \
|
FtpFinishDownloadCommand.$(OBJEXT) A2STR.$(OBJEXT) \
|
||||||
RarestPieceSelector.$(OBJEXT) ChunkedDecoder.$(OBJEXT) \
|
RarestPieceSelector.$(OBJEXT) ChunkedDecoder.$(OBJEXT) \
|
||||||
|
@ -1157,11 +1153,10 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
|
||||||
PeerConnection.cc PeerConnection.h ByteArrayDiskWriter.cc \
|
PeerConnection.cc PeerConnection.h ByteArrayDiskWriter.cc \
|
||||||
ByteArrayDiskWriter.h ByteArrayDiskWriterFactory.cc \
|
ByteArrayDiskWriter.h ByteArrayDiskWriterFactory.cc \
|
||||||
ByteArrayDiskWriterFactory.h ServerHost.cc ServerHost.h \
|
ByteArrayDiskWriterFactory.h ServerHost.cc ServerHost.h \
|
||||||
DownloadContext.cc DownloadContext.h \
|
DownloadContext.cc DownloadContext.h TimedHaltCommand.cc \
|
||||||
SingleFileDownloadContext.cc SingleFileDownloadContext.h \
|
TimedHaltCommand.h CUIDCounter.h DNSCache.h DownloadResult.h \
|
||||||
TimedHaltCommand.cc TimedHaltCommand.h CUIDCounter.h \
|
Sequence.h IntSequence.h PostDownloadHandler.h \
|
||||||
DNSCache.h DownloadResult.h Sequence.h IntSequence.h \
|
PreDownloadHandler.h SingletonHolder.h \
|
||||||
PostDownloadHandler.h PreDownloadHandler.h SingletonHolder.h \
|
|
||||||
TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
|
TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
|
||||||
a2netcompat.h a2time.h array_fun.h help_tags.h prefs.cc \
|
a2netcompat.h a2time.h array_fun.h help_tags.h prefs.cc \
|
||||||
prefs.h usage_text.h ProtocolDetector.cc ProtocolDetector.h \
|
prefs.h usage_text.h ProtocolDetector.cc ProtocolDetector.h \
|
||||||
|
@ -1393,7 +1388,6 @@ distclean-compile:
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DHTUtil.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DHTUtil.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultAuthResolver.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultAuthResolver.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtAnnounce.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtAnnounce.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtContext.Po@am__quote@
|
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtInteractive.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtInteractive.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtMessageDispatcher.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtMessageDispatcher.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtMessageFactory.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtMessageFactory.Po@am__quote@
|
||||||
|
@ -1541,7 +1535,6 @@ distclean-compile:
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleLogger.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleLogger.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleRandomizer.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleRandomizer.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SingleFileAllocationIterator.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SingleFileAllocationIterator.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SingleFileDownloadContext.Po@am__quote@
|
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SizeMetalinkParserState.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SizeMetalinkParserState.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SkipTagMetalinkParserState.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SkipTagMetalinkParserState.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SleepCommand.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SleepCommand.Po@am__quote@
|
||||||
|
@ -1578,6 +1571,7 @@ distclean-compile:
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ZeroBtMessage.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ZeroBtMessage.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asctime_r.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asctime_r.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bencode.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bencode.Po@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bittorrent_helper.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/download_helper.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/download_helper.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gai_strerror.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gai_strerror.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getaddrinfo.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getaddrinfo.Po@am__quote@
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "SingleFileDownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "MetalinkHelper.h"
|
#include "MetalinkHelper.h"
|
||||||
#include "BinaryStream.h"
|
#include "BinaryStream.h"
|
||||||
#include "MemoryBufferPreDownloadHandler.h"
|
#include "MemoryBufferPreDownloadHandler.h"
|
||||||
|
@ -170,10 +170,11 @@ Metalink2RequestGroup::createRequestGroup
|
||||||
std::deque<std::string> uris;
|
std::deque<std::string> uris;
|
||||||
uris.push_back((*itr)->url);
|
uris.push_back((*itr)->url);
|
||||||
torrentRg.reset(new RequestGroup(option, uris));
|
torrentRg.reset(new RequestGroup(option, uris));
|
||||||
SharedHandle<SingleFileDownloadContext> dctx
|
SharedHandle<DownloadContext> dctx
|
||||||
(new SingleFileDownloadContext(option->getAsInt(PREF_SEGMENT_SIZE),
|
(new DownloadContext(option->getAsInt(PREF_SEGMENT_SIZE),
|
||||||
0,
|
0,
|
||||||
A2STR::NIL));
|
A2STR::NIL));
|
||||||
|
// Since torrent is downloaded in memory, setting dir has no effect.
|
||||||
//dctx->setDir(_option->get(PREF_DIR));
|
//dctx->setDir(_option->get(PREF_DIR));
|
||||||
torrentRg->setDownloadContext(dctx);
|
torrentRg->setDownloadContext(dctx);
|
||||||
torrentRg->clearPreDowloadHandler();
|
torrentRg->clearPreDowloadHandler();
|
||||||
|
@ -208,11 +209,10 @@ Metalink2RequestGroup::createRequestGroup
|
||||||
#else
|
#else
|
||||||
pieceLength = option->getAsInt(PREF_SEGMENT_SIZE);
|
pieceLength = option->getAsInt(PREF_SEGMENT_SIZE);
|
||||||
#endif // ENABLE_MESSAGE_DIGEST
|
#endif // ENABLE_MESSAGE_DIGEST
|
||||||
SharedHandle<SingleFileDownloadContext> dctx
|
SharedHandle<DownloadContext> dctx
|
||||||
(new SingleFileDownloadContext
|
(new DownloadContext
|
||||||
(pieceLength,
|
(pieceLength,
|
||||||
entry->getLength(),
|
entry->getLength(),
|
||||||
A2STR::NIL,
|
|
||||||
strconcat(option->get(PREF_DIR), "/", entry->file->getPath())));
|
strconcat(option->get(PREF_DIR), "/", entry->file->getPath())));
|
||||||
dctx->setDir(option->get(PREF_DIR));
|
dctx->setDir(option->get(PREF_DIR));
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
|
@ -222,7 +222,8 @@ Metalink2RequestGroup::createRequestGroup
|
||||||
dctx->setChecksumHashAlgo(entry->checksum->getAlgo());
|
dctx->setChecksumHashAlgo(entry->checksum->getAlgo());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dctx->setPieceHashes(entry->chunkChecksum->getChecksums());
|
dctx->setPieceHashes(entry->chunkChecksum->getChecksums().begin(),
|
||||||
|
entry->chunkChecksum->getChecksums().end());
|
||||||
dctx->setPieceHashAlgo(entry->chunkChecksum->getAlgo());
|
dctx->setPieceHashAlgo(entry->chunkChecksum->getAlgo());
|
||||||
}
|
}
|
||||||
#endif // ENABLE_MESSAGE_DIGEST
|
#endif // ENABLE_MESSAGE_DIGEST
|
||||||
|
|
|
@ -62,7 +62,7 @@ void MetalinkPostDownloadHandler::getNextRequestGroups
|
||||||
RequestGroup* requestGroup)
|
RequestGroup* requestGroup)
|
||||||
{
|
{
|
||||||
_logger->debug("Generating RequestGroups for Metalink file %s",
|
_logger->debug("Generating RequestGroups for Metalink file %s",
|
||||||
requestGroup->getFilePath().c_str());
|
requestGroup->getFirstFilePath().c_str());
|
||||||
SharedHandle<DiskAdaptor> diskAdaptor = requestGroup->getPieceStorage()->getDiskAdaptor();
|
SharedHandle<DiskAdaptor> diskAdaptor = requestGroup->getPieceStorage()->getDiskAdaptor();
|
||||||
try {
|
try {
|
||||||
diskAdaptor->openExistingFile();
|
diskAdaptor->openExistingFile();
|
||||||
|
|
|
@ -166,7 +166,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(std::deque<SharedHandle<FileEntry> >::const_iterator i =
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||||
diskWriterEntries.push_back
|
diskWriterEntries.push_back
|
||||||
(createDiskWriterEntry(*i, (*i)->isRequested()));
|
(createDiskWriterEntry(*i, (*i)->isRequested()));
|
||||||
|
@ -176,9 +176,9 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
||||||
|
|
||||||
// TODO Currently, pieceLength == 0 is used for unit testing only.
|
// TODO Currently, pieceLength == 0 is used for unit testing only.
|
||||||
if(pieceLength > 0) {
|
if(pieceLength > 0) {
|
||||||
std::deque<SharedHandle<DiskWriterEntry> >::iterator done =
|
std::vector<SharedHandle<DiskWriterEntry> >::iterator done =
|
||||||
diskWriterEntries.begin();
|
diskWriterEntries.begin();
|
||||||
for(std::deque<SharedHandle<DiskWriterEntry> >::iterator itr =
|
for(std::vector<SharedHandle<DiskWriterEntry> >::iterator itr =
|
||||||
diskWriterEntries.begin(); itr != diskWriterEntries.end();) {
|
diskWriterEntries.begin(); itr != diskWriterEntries.end();) {
|
||||||
const SharedHandle<FileEntry>& fileEntry = (*itr)->getFileEntry();
|
const SharedHandle<FileEntry>& fileEntry = (*itr)->getFileEntry();
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
||||||
off_t pieceStartOffset =
|
off_t pieceStartOffset =
|
||||||
(fileEntry->getOffset()/pieceLength)*pieceLength;
|
(fileEntry->getOffset()/pieceLength)*pieceLength;
|
||||||
if(itr != diskWriterEntries.begin()) {
|
if(itr != diskWriterEntries.begin()) {
|
||||||
for(std::deque<SharedHandle<DiskWriterEntry> >::iterator i =
|
for(std::vector<SharedHandle<DiskWriterEntry> >::iterator i =
|
||||||
itr-1; true; --i) {
|
itr-1; true; --i) {
|
||||||
const SharedHandle<FileEntry>& fileEntry = (*i)->getFileEntry();
|
const SharedHandle<FileEntry>& fileEntry = (*i)->getFileEntry();
|
||||||
if(pieceStartOffset <= fileEntry->getOffset() ||
|
if(pieceStartOffset <= fileEntry->getOffset() ||
|
||||||
|
@ -240,7 +240,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DefaultDiskWriterFactory dwFactory;
|
DefaultDiskWriterFactory dwFactory;
|
||||||
for(std::deque<SharedHandle<DiskWriterEntry> >::iterator i =
|
for(std::vector<SharedHandle<DiskWriterEntry> >::iterator i =
|
||||||
diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
|
diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
|
||||||
if((*i)->needsFileAllocation() ||
|
if((*i)->needsFileAllocation() ||
|
||||||
dwreq.find((*i)->getFileEntry()->getPath()) != dwreq.end() ||
|
dwreq.find((*i)->getFileEntry()->getPath()) != dwreq.end() ||
|
||||||
|
@ -260,7 +260,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
||||||
|
|
||||||
void MultiDiskAdaptor::mkdir() const
|
void MultiDiskAdaptor::mkdir() const
|
||||||
{
|
{
|
||||||
for(std::deque<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
||||||
diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
|
diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
|
||||||
(*i)->getFileEntry()->setupDir();
|
(*i)->getFileEntry()->setupDir();
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ void MultiDiskAdaptor::openIfNot
|
||||||
// Cache is full.
|
// Cache is full.
|
||||||
// Choose one DiskWriterEntry randomly and close it.
|
// Choose one DiskWriterEntry randomly and close it.
|
||||||
size_t index = SimpleRandomizer::getInstance()->getRandomNumber(numOpened);
|
size_t index = SimpleRandomizer::getInstance()->getRandomNumber(numOpened);
|
||||||
std::deque<SharedHandle<DiskWriterEntry> >::iterator i =
|
std::vector<SharedHandle<DiskWriterEntry> >::iterator i =
|
||||||
_openedDiskWriterEntries.begin();
|
_openedDiskWriterEntries.begin();
|
||||||
std::advance(i, index);
|
std::advance(i, index);
|
||||||
(*i)->closeFile();
|
(*i)->closeFile();
|
||||||
|
@ -443,7 +443,7 @@ ssize_t MultiDiskAdaptor::readData(unsigned char* data, size_t len, off_t offset
|
||||||
|
|
||||||
bool MultiDiskAdaptor::fileExists()
|
bool MultiDiskAdaptor::fileExists()
|
||||||
{
|
{
|
||||||
for(std::deque<SharedHandle<FileEntry> >::iterator i =
|
for(std::vector<SharedHandle<FileEntry> >::iterator i =
|
||||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||||
if((*i)->exists()) {
|
if((*i)->exists()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -455,10 +455,9 @@ bool MultiDiskAdaptor::fileExists()
|
||||||
uint64_t MultiDiskAdaptor::size()
|
uint64_t MultiDiskAdaptor::size()
|
||||||
{
|
{
|
||||||
uint64_t size = 0;
|
uint64_t size = 0;
|
||||||
for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin();
|
for(std::vector<SharedHandle<FileEntry> >::iterator i =
|
||||||
itr != diskWriterEntries.end(); ++itr) {
|
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||||
openIfNot(*itr, &DiskWriterEntry::openFile);
|
size += File((*i)->getPath()).size();
|
||||||
size += (*itr)->size();
|
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
@ -496,7 +495,7 @@ void MultiDiskAdaptor::disableReadOnly()
|
||||||
|
|
||||||
void MultiDiskAdaptor::cutTrailingGarbage()
|
void MultiDiskAdaptor::cutTrailingGarbage()
|
||||||
{
|
{
|
||||||
for(std::deque<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
||||||
diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
|
diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
|
||||||
uint64_t length = (*i)->getFileEntry()->getLength();
|
uint64_t length = (*i)->getFileEntry()->getLength();
|
||||||
if(File((*i)->getFilePath()).size() > length) {
|
if(File((*i)->getFilePath()).size() > length) {
|
||||||
|
@ -515,7 +514,7 @@ void MultiDiskAdaptor::setMaxOpenFiles(size_t maxOpenFiles)
|
||||||
size_t MultiDiskAdaptor::utime(const Time& actime, const Time& modtime)
|
size_t MultiDiskAdaptor::utime(const Time& actime, const Time& modtime)
|
||||||
{
|
{
|
||||||
size_t numOK = 0;
|
size_t numOK = 0;
|
||||||
for(std::deque<SharedHandle<FileEntry> >::const_iterator i =
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||||
if((*i)->isRequested()) {
|
if((*i)->isRequested()) {
|
||||||
File f((*i)->getPath());
|
File f((*i)->getPath());
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue