diff --git a/src/AbstractBtMessage.cc b/src/AbstractBtMessage.cc index f4fef342..d1c76a7e 100644 --- a/src/AbstractBtMessage.cc +++ b/src/AbstractBtMessage.cc @@ -45,6 +45,7 @@ AbstractBtMessage::AbstractBtMessage(uint8_t id, const char* name) uploading_(false), cuid_(0), name_(name), + pieceStorage_(0), dispatcher_(0), messageFactory_(0), requestFactory_(0), @@ -71,8 +72,7 @@ AbstractBtMessage::setBtMessageValidator(const std::shared_ptr& pieceStorage) +void AbstractBtMessage::setPieceStorage(PieceStorage* pieceStorage) { pieceStorage_ = pieceStorage; } diff --git a/src/AbstractBtMessage.h b/src/AbstractBtMessage.h index 49a1b2ed..c37ad69f 100644 --- a/src/AbstractBtMessage.h +++ b/src/AbstractBtMessage.h @@ -56,7 +56,7 @@ private: const char* name_; - std::shared_ptr pieceStorage_; + PieceStorage* pieceStorage_; std::shared_ptr peer_; @@ -72,7 +72,7 @@ private: bool metadataGetMode_; protected: - const std::shared_ptr& getPieceStorage() const + PieceStorage* getPieceStorage() const { return pieceStorage_; } @@ -153,7 +153,7 @@ public: void setBtMessageValidator(const std::shared_ptr& validator); - void setPieceStorage(const std::shared_ptr& pieceStorage); + void setPieceStorage(PieceStorage* pieceStorage); void setBtMessageDispatcher(BtMessageDispatcher* dispatcher); diff --git a/src/BtInterestedMessage.cc b/src/BtInterestedMessage.cc index e70b79b4..e4e92e63 100644 --- a/src/BtInterestedMessage.cc +++ b/src/BtInterestedMessage.cc @@ -41,7 +41,10 @@ namespace aria2 { const char BtInterestedMessage::NAME[] = "interested"; -BtInterestedMessage::BtInterestedMessage():ZeroBtMessage(ID, NAME) {} +BtInterestedMessage::BtInterestedMessage() + : ZeroBtMessage(ID, NAME), + peerStorage_(0) +{} BtInterestedMessage::~BtInterestedMessage() {} @@ -86,8 +89,7 @@ ProgressUpdate* BtInterestedMessage::getProgressUpdate() return new ThisProgressUpdate(getPeer()); } -void BtInterestedMessage::setPeerStorage -(const std::shared_ptr& peerStorage) +void BtInterestedMessage::setPeerStorage(PeerStorage* peerStorage) { peerStorage_ = peerStorage; } diff --git a/src/BtInterestedMessage.h b/src/BtInterestedMessage.h index 392086f3..0f794126 100644 --- a/src/BtInterestedMessage.h +++ b/src/BtInterestedMessage.h @@ -44,7 +44,7 @@ class BtInterestedMessage; class BtInterestedMessage : public ZeroBtMessage { private: - std::shared_ptr peerStorage_; + PeerStorage* peerStorage_; public: BtInterestedMessage(); virtual ~BtInterestedMessage(); @@ -62,7 +62,7 @@ public: virtual ProgressUpdate* getProgressUpdate(); - void setPeerStorage(const std::shared_ptr& peerStorage); + void setPeerStorage(PeerStorage* peerStorage); }; } // namespace aria2 diff --git a/src/BtNotInterestedMessage.cc b/src/BtNotInterestedMessage.cc index eca078d5..dcd9b810 100644 --- a/src/BtNotInterestedMessage.cc +++ b/src/BtNotInterestedMessage.cc @@ -41,7 +41,10 @@ namespace aria2 { const char BtNotInterestedMessage::NAME[] = "not interested"; -BtNotInterestedMessage::BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {} +BtNotInterestedMessage::BtNotInterestedMessage() + : ZeroBtMessage(ID, NAME), + peerStorage_(0) +{} BtNotInterestedMessage::~BtNotInterestedMessage() {} @@ -86,8 +89,7 @@ ProgressUpdate* BtNotInterestedMessage::getProgressUpdate() return new ThisProgressUpdate(getPeer()); } -void BtNotInterestedMessage::setPeerStorage -(const std::shared_ptr& peerStorage) +void BtNotInterestedMessage::setPeerStorage(PeerStorage* peerStorage) { peerStorage_ = peerStorage; } diff --git a/src/BtNotInterestedMessage.h b/src/BtNotInterestedMessage.h index 0a1f4fd7..d356a802 100644 --- a/src/BtNotInterestedMessage.h +++ b/src/BtNotInterestedMessage.h @@ -44,7 +44,7 @@ class BtNotInterestedMessage; class BtNotInterestedMessage : public ZeroBtMessage { private: - std::shared_ptr peerStorage_; + PeerStorage* peerStorage_; public: BtNotInterestedMessage(); virtual ~BtNotInterestedMessage(); @@ -62,7 +62,7 @@ public: virtual ProgressUpdate* getProgressUpdate(); - void setPeerStorage(const std::shared_ptr& peerStorage); + void setPeerStorage(PeerStorage* peerStorage); }; } // namespace aria2 diff --git a/src/BtPieceMessage.cc b/src/BtPieceMessage.cc index c0abf66b..ec39043e 100644 --- a/src/BtPieceMessage.cc +++ b/src/BtPieceMessage.cc @@ -71,7 +71,9 @@ BtPieceMessage::BtPieceMessage index_(index), begin_(begin), blockLength_(blockLength), - data_(0) + data_(0), + downloadContext_(0), + peerStorage_(0) { setUploading(true); } @@ -334,14 +336,12 @@ void BtPieceMessage::onCancelSendingPieceEvent } } -void BtPieceMessage::setDownloadContext -(const std::shared_ptr& downloadContext) +void BtPieceMessage::setDownloadContext(DownloadContext* downloadContext) { downloadContext_ = downloadContext; } -void BtPieceMessage::setPeerStorage -(const std::shared_ptr& peerStorage) +void BtPieceMessage::setPeerStorage(PeerStorage* peerStorage) { peerStorage_ = peerStorage; } diff --git a/src/BtPieceMessage.h b/src/BtPieceMessage.h index d6488ba2..41dcfb46 100644 --- a/src/BtPieceMessage.h +++ b/src/BtPieceMessage.h @@ -49,8 +49,8 @@ private: int32_t begin_; int32_t blockLength_; const unsigned char* data_; - std::shared_ptr downloadContext_; - std::shared_ptr peerStorage_; + DownloadContext* downloadContext_; + PeerStorage* peerStorage_; static size_t MESSAGE_HEADER_LENGTH; @@ -88,9 +88,9 @@ public: void setBlockLength(int32_t blockLength) { blockLength_ = blockLength; } - void setDownloadContext(const std::shared_ptr& downloadContext); + void setDownloadContext(DownloadContext* downloadContext); - void setPeerStorage(const std::shared_ptr& peerStorage); + void setPeerStorage(PeerStorage* peerStorage); static BtPieceMessage* create(const unsigned char* data, size_t dataLength); diff --git a/src/DefaultBtMessageFactory.cc b/src/DefaultBtMessageFactory.cc index 6abe6445..ad2a3cc8 100644 --- a/src/DefaultBtMessageFactory.cc +++ b/src/DefaultBtMessageFactory.cc @@ -72,6 +72,9 @@ namespace aria2 { DefaultBtMessageFactory::DefaultBtMessageFactory(): cuid_(0), + downloadContext_(0), + pieceStorage_(0), + peerStorage_(0), dhtEnabled_(false), dispatcher_(0), requestFactory_(0), @@ -439,19 +442,17 @@ void DefaultBtMessageFactory::setPeer(const std::shared_ptr& peer) } void DefaultBtMessageFactory::setDownloadContext -(const std::shared_ptr& downloadContext) +(DownloadContext* downloadContext) { downloadContext_ = downloadContext; } -void DefaultBtMessageFactory::setPieceStorage -(const std::shared_ptr& pieceStorage) +void DefaultBtMessageFactory::setPieceStorage(PieceStorage* pieceStorage) { pieceStorage_ = pieceStorage; } -void DefaultBtMessageFactory::setPeerStorage -(const std::shared_ptr& peerStorage) +void DefaultBtMessageFactory::setPeerStorage(PeerStorage* peerStorage) { peerStorage_ = peerStorage; } diff --git a/src/DefaultBtMessageFactory.h b/src/DefaultBtMessageFactory.h index df9c08d7..cad09116 100644 --- a/src/DefaultBtMessageFactory.h +++ b/src/DefaultBtMessageFactory.h @@ -57,9 +57,9 @@ class DHTTaskFactory; class DefaultBtMessageFactory : public BtMessageFactory { private: cuid_t cuid_; - std::shared_ptr downloadContext_; - std::shared_ptr pieceStorage_; - std::shared_ptr peerStorage_; + DownloadContext* downloadContext_; + PieceStorage* pieceStorage_; + PeerStorage* peerStorage_; std::shared_ptr peer_; bool dhtEnabled_; @@ -137,11 +137,11 @@ public: void setPeer(const std::shared_ptr& peer); - void setDownloadContext(const std::shared_ptr& downloadContext); + void setDownloadContext(DownloadContext* downloadContext); - void setPieceStorage(const std::shared_ptr& pieceStorage); + void setPieceStorage(PieceStorage* pieceStorage); - void setPeerStorage(const std::shared_ptr& peerStorage); + void setPeerStorage(PeerStorage* peerStorage); void setCuid(cuid_t cuid) { diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index 5d762023..c9e118c3 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -147,9 +147,9 @@ PeerInteractionCommand::PeerInteractionCommand DefaultBtMessageFactory* factoryPtr(new DefaultBtMessageFactory()); factoryPtr->setCuid(cuid); - factoryPtr->setDownloadContext(requestGroup_->getDownloadContext()); - factoryPtr->setPieceStorage(pieceStorage); - factoryPtr->setPeerStorage(peerStorage); + factoryPtr->setDownloadContext(requestGroup_->getDownloadContext().get()); + factoryPtr->setPieceStorage(pieceStorage.get()); + factoryPtr->setPeerStorage(peerStorage.get()); factoryPtr->setExtensionMessageFactory(extensionMessageFactory); factoryPtr->setPeer(getPeer()); if(family == AF_INET) { diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc index 4850ea56..07e9259f 100644 --- a/src/bittorrent_helper.cc +++ b/src/bittorrent_helper.cc @@ -623,13 +623,23 @@ void loadFromMemory(const std::shared_ptr& torrent, std::shared_ptr getTorrentAttrs (const std::shared_ptr& dctx) +{ + return getTorrentAttrs(dctx.get()); +} + +std::shared_ptr getTorrentAttrs(DownloadContext* dctx) { return std::static_pointer_cast (dctx->getAttribute(CTX_ATTR_BT)); } -const unsigned char* -getInfoHash(const std::shared_ptr& dctx) +const unsigned char* getInfoHash +(const std::shared_ptr& dctx) +{ + return getInfoHash(dctx.get()); +} + +const unsigned char* getInfoHash(DownloadContext* dctx) { return reinterpret_cast (getTorrentAttrs(dctx)->infoHash.data()); @@ -637,6 +647,12 @@ getInfoHash(const std::shared_ptr& dctx) std::string getInfoHashString(const std::shared_ptr& dctx) +{ + return getInfoHashString(dctx.get()); +} + +std::string +getInfoHashString(DownloadContext* dctx) { return util::toHex(getTorrentAttrs(dctx)->infoHash); } diff --git a/src/bittorrent_helper.h b/src/bittorrent_helper.h index d26d3af1..74d983f7 100644 --- a/src/bittorrent_helper.h +++ b/src/bittorrent_helper.h @@ -149,16 +149,19 @@ void computeFastSet (std::vector& fastSet, const std::string& ipaddr, size_t numPieces, const unsigned char* infoHash, size_t fastSetSize); +std::shared_ptr getTorrentAttrs(DownloadContext* dctx); std::shared_ptr getTorrentAttrs (const std::shared_ptr& dctx); // Returns the value associated with INFO_HASH key in BITTORRENT // attribute. -const unsigned char* -getInfoHash(const std::shared_ptr& downloadContext); +const unsigned char* getInfoHash(DownloadContext* downloadContext); +const unsigned char* getInfoHash +(const std::shared_ptr& downloadContext); -std::string -getInfoHashString(const std::shared_ptr& downloadContext); +std::string getInfoHashString(DownloadContext* downloadContext); +std::string getInfoHashString +(const std::shared_ptr& downloadContext); // Returns 8bytes unsigned integer located at offset pos. The integer // in msg is network byte order. This function converts it into host diff --git a/test/BtBitfieldMessageTest.cc b/test/BtBitfieldMessageTest.cc index 475c8a46..9331b94b 100644 --- a/test/BtBitfieldMessageTest.cc +++ b/test/BtBitfieldMessageTest.cc @@ -85,8 +85,8 @@ void BtBitfieldMessageTest::testDoReceivedAction() { peer->allocateSessionResource(16*1024, 16*16*1024); BtBitfieldMessage msg; msg.setPeer(peer); - std::shared_ptr pieceStorage(new MockPieceStorage()); - msg.setPieceStorage(pieceStorage); + auto pieceStorage = make_unique(); + msg.setPieceStorage(pieceStorage.get()); unsigned char bitfield[] = { 0xff, 0xff }; msg.setBitfield(bitfield, sizeof(bitfield)); @@ -103,8 +103,8 @@ void BtBitfieldMessageTest::testDoReceivedAction_goodByeSeeder() peer->allocateSessionResource(1024, 1024); BtBitfieldMessage msg; msg.setPeer(peer); - std::shared_ptr pieceStorage(new MockPieceStorage()); - msg.setPieceStorage(pieceStorage); + auto pieceStorage = make_unique(); + msg.setPieceStorage(pieceStorage.get()); unsigned char bitfield[] = { 0x00 }; msg.setBitfield(bitfield, sizeof(bitfield)); diff --git a/test/BtHaveAllMessageTest.cc b/test/BtHaveAllMessageTest.cc index 0b6a9e92..5e8987c6 100644 --- a/test/BtHaveAllMessageTest.cc +++ b/test/BtHaveAllMessageTest.cc @@ -74,8 +74,8 @@ void BtHaveAllMessageTest::testDoReceivedAction() { peer->allocateSessionResource(16*1024, 256*1024); peer->setFastExtensionEnabled(true); msg.setPeer(peer); - std::shared_ptr pieceStorage(new MockPieceStorage()); - msg.setPieceStorage(pieceStorage); + auto pieceStorage = make_unique(); + msg.setPieceStorage(pieceStorage.get()); msg.doReceivedAction(); @@ -96,8 +96,8 @@ void BtHaveAllMessageTest::testDoReceivedAction_goodByeSeeder() peer->allocateSessionResource(1024, 1024); peer->setFastExtensionEnabled(true); msg.setPeer(peer); - std::shared_ptr pieceStorage(new MockPieceStorage()); - msg.setPieceStorage(pieceStorage); + auto pieceStorage = make_unique(); + msg.setPieceStorage(pieceStorage.get()); pieceStorage->setDownloadFinished(true); diff --git a/test/BtHaveMessageTest.cc b/test/BtHaveMessageTest.cc index 15072e24..9e78ee9f 100644 --- a/test/BtHaveMessageTest.cc +++ b/test/BtHaveMessageTest.cc @@ -80,8 +80,8 @@ void BtHaveMessageTest::testDoReceivedAction() { BtHaveMessage msg; msg.setIndex(1); msg.setPeer(peer); - std::shared_ptr pieceStorage(new MockPieceStorage()); - msg.setPieceStorage(pieceStorage); + auto pieceStorage = make_unique(); + msg.setPieceStorage(pieceStorage.get()); CPPUNIT_ASSERT(!peer->hasPiece(msg.getIndex())); @@ -97,8 +97,8 @@ void BtHaveMessageTest::testDoReceivedAction_goodByeSeeder() BtHaveMessage msg; msg.setIndex(0); msg.setPeer(peer); - std::shared_ptr pieceStorage(new MockPieceStorage()); - msg.setPieceStorage(pieceStorage); + auto pieceStorage = make_unique(); + msg.setPieceStorage(pieceStorage.get()); // peer is not seeder and client have not completed download msg.doReceivedAction(); diff --git a/test/BtInterestedMessageTest.cc b/test/BtInterestedMessageTest.cc index 0cf47318..1dc5e5a7 100644 --- a/test/BtInterestedMessageTest.cc +++ b/test/BtInterestedMessageTest.cc @@ -71,9 +71,9 @@ void BtInterestedMessageTest::testDoReceivedAction() { peer->allocateSessionResource(1024, 1024*1024); msg.setPeer(peer); - std::shared_ptr peerStorage(new MockPeerStorage()); + auto peerStorage = make_unique(); - msg.setPeerStorage(peerStorage); + msg.setPeerStorage(peerStorage.get()); CPPUNIT_ASSERT(!peer->peerInterested()); msg.doReceivedAction(); diff --git a/test/BtNotInterestedMessageTest.cc b/test/BtNotInterestedMessageTest.cc index 01c1727e..181c5665 100644 --- a/test/BtNotInterestedMessageTest.cc +++ b/test/BtNotInterestedMessageTest.cc @@ -70,11 +70,11 @@ void BtNotInterestedMessageTest::testDoReceivedAction() { peer->allocateSessionResource(1024, 1024*1024); peer->peerInterested(true); - std::shared_ptr peerStorage(new MockPeerStorage()); + auto peerStorage = make_unique(); BtNotInterestedMessage msg; msg.setPeer(peer); - msg.setPeerStorage(peerStorage); + msg.setPeerStorage(peerStorage.get()); CPPUNIT_ASSERT(peer->peerInterested()); msg.doReceivedAction(); diff --git a/test/BtPieceMessageTest.cc b/test/BtPieceMessageTest.cc index fc88fc84..d758d53c 100644 --- a/test/BtPieceMessageTest.cc +++ b/test/BtPieceMessageTest.cc @@ -88,7 +88,7 @@ public: msg->setIndex(1); msg->setBegin(1024); msg->setBlockLength(16*1024); - msg->setDownloadContext(dctx_); + msg->setDownloadContext(dctx_.get()); msg->setPeer(peer); msg->setBtMessageDispatcher(btMessageDispatcher.get()); msg->setBtMessageFactory(btMessageFactory_.get()); diff --git a/test/BtRequestMessageTest.cc b/test/BtRequestMessageTest.cc index 623851e4..b56dce54 100644 --- a/test/BtRequestMessageTest.cc +++ b/test/BtRequestMessageTest.cc @@ -117,7 +117,7 @@ public: msg->setBlockIndex(2); msg->setBtMessageDispatcher(dispatcher_.get()); msg->setBtMessageFactory(messageFactory_.get()); - msg->setPieceStorage(pieceStorage_); + msg->setPieceStorage(pieceStorage_.get()); } }; diff --git a/test/DefaultBtMessageFactoryTest.cc b/test/DefaultBtMessageFactoryTest.cc index 94f6d87f..cf4c6954 100644 --- a/test/DefaultBtMessageFactoryTest.cc +++ b/test/DefaultBtMessageFactoryTest.cc @@ -40,7 +40,7 @@ public: exmsgFactory_.reset(new MockExtensionMessageFactory()); factory_.reset(new DefaultBtMessageFactory()); - factory_->setDownloadContext(dctx_); + factory_->setDownloadContext(dctx_.get()); factory_->setPeer(peer_); factory_->setExtensionMessageFactory(exmsgFactory_); }