mirror of
https://github.com/aria2/aria2.git
synced 2024-11-27 03:54:21 +08:00
Use raw pointers to PieceStorage, PeerStorage and DownloadContxt for BtMessages
This commit is contained in:
parent
09c597fbb8
commit
1a299c4d7c
@ -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<BtMessageValidato
|
||||
validator_ = validator;
|
||||
}
|
||||
|
||||
void AbstractBtMessage::setPieceStorage
|
||||
(const std::shared_ptr<PieceStorage>& pieceStorage)
|
||||
void AbstractBtMessage::setPieceStorage(PieceStorage* pieceStorage)
|
||||
{
|
||||
pieceStorage_ = pieceStorage;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ private:
|
||||
|
||||
const char* name_;
|
||||
|
||||
std::shared_ptr<PieceStorage> pieceStorage_;
|
||||
PieceStorage* pieceStorage_;
|
||||
|
||||
std::shared_ptr<Peer> peer_;
|
||||
|
||||
@ -72,7 +72,7 @@ private:
|
||||
|
||||
bool metadataGetMode_;
|
||||
protected:
|
||||
const std::shared_ptr<PieceStorage>& getPieceStorage() const
|
||||
PieceStorage* getPieceStorage() const
|
||||
{
|
||||
return pieceStorage_;
|
||||
}
|
||||
@ -153,7 +153,7 @@ public:
|
||||
|
||||
void setBtMessageValidator(const std::shared_ptr<BtMessageValidator>& validator);
|
||||
|
||||
void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
|
||||
void setPieceStorage(PieceStorage* pieceStorage);
|
||||
|
||||
void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);
|
||||
|
||||
|
@ -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>& peerStorage)
|
||||
void BtInterestedMessage::setPeerStorage(PeerStorage* peerStorage)
|
||||
{
|
||||
peerStorage_ = peerStorage;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class BtInterestedMessage;
|
||||
|
||||
class BtInterestedMessage : public ZeroBtMessage {
|
||||
private:
|
||||
std::shared_ptr<PeerStorage> peerStorage_;
|
||||
PeerStorage* peerStorage_;
|
||||
public:
|
||||
BtInterestedMessage();
|
||||
virtual ~BtInterestedMessage();
|
||||
@ -62,7 +62,7 @@ public:
|
||||
|
||||
virtual ProgressUpdate* getProgressUpdate();
|
||||
|
||||
void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
|
||||
void setPeerStorage(PeerStorage* peerStorage);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
@ -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>& peerStorage)
|
||||
void BtNotInterestedMessage::setPeerStorage(PeerStorage* peerStorage)
|
||||
{
|
||||
peerStorage_ = peerStorage;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class BtNotInterestedMessage;
|
||||
|
||||
class BtNotInterestedMessage : public ZeroBtMessage {
|
||||
private:
|
||||
std::shared_ptr<PeerStorage> peerStorage_;
|
||||
PeerStorage* peerStorage_;
|
||||
public:
|
||||
BtNotInterestedMessage();
|
||||
virtual ~BtNotInterestedMessage();
|
||||
@ -62,7 +62,7 @@ public:
|
||||
|
||||
virtual ProgressUpdate* getProgressUpdate();
|
||||
|
||||
void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
|
||||
void setPeerStorage(PeerStorage* peerStorage);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
@ -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>& downloadContext)
|
||||
void BtPieceMessage::setDownloadContext(DownloadContext* downloadContext)
|
||||
{
|
||||
downloadContext_ = downloadContext;
|
||||
}
|
||||
|
||||
void BtPieceMessage::setPeerStorage
|
||||
(const std::shared_ptr<PeerStorage>& peerStorage)
|
||||
void BtPieceMessage::setPeerStorage(PeerStorage* peerStorage)
|
||||
{
|
||||
peerStorage_ = peerStorage;
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ private:
|
||||
int32_t begin_;
|
||||
int32_t blockLength_;
|
||||
const unsigned char* data_;
|
||||
std::shared_ptr<DownloadContext> downloadContext_;
|
||||
std::shared_ptr<PeerStorage> 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>& downloadContext);
|
||||
void setDownloadContext(DownloadContext* downloadContext);
|
||||
|
||||
void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
|
||||
void setPeerStorage(PeerStorage* peerStorage);
|
||||
|
||||
static BtPieceMessage* create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
|
@ -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>& peer)
|
||||
}
|
||||
|
||||
void DefaultBtMessageFactory::setDownloadContext
|
||||
(const std::shared_ptr<DownloadContext>& downloadContext)
|
||||
(DownloadContext* downloadContext)
|
||||
{
|
||||
downloadContext_ = downloadContext;
|
||||
}
|
||||
|
||||
void DefaultBtMessageFactory::setPieceStorage
|
||||
(const std::shared_ptr<PieceStorage>& pieceStorage)
|
||||
void DefaultBtMessageFactory::setPieceStorage(PieceStorage* pieceStorage)
|
||||
{
|
||||
pieceStorage_ = pieceStorage;
|
||||
}
|
||||
|
||||
void DefaultBtMessageFactory::setPeerStorage
|
||||
(const std::shared_ptr<PeerStorage>& peerStorage)
|
||||
void DefaultBtMessageFactory::setPeerStorage(PeerStorage* peerStorage)
|
||||
{
|
||||
peerStorage_ = peerStorage;
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ class DHTTaskFactory;
|
||||
class DefaultBtMessageFactory : public BtMessageFactory {
|
||||
private:
|
||||
cuid_t cuid_;
|
||||
std::shared_ptr<DownloadContext> downloadContext_;
|
||||
std::shared_ptr<PieceStorage> pieceStorage_;
|
||||
std::shared_ptr<PeerStorage> peerStorage_;
|
||||
DownloadContext* downloadContext_;
|
||||
PieceStorage* pieceStorage_;
|
||||
PeerStorage* peerStorage_;
|
||||
std::shared_ptr<Peer> peer_;
|
||||
|
||||
bool dhtEnabled_;
|
||||
@ -137,11 +137,11 @@ public:
|
||||
|
||||
void setPeer(const std::shared_ptr<Peer>& peer);
|
||||
|
||||
void setDownloadContext(const std::shared_ptr<DownloadContext>& downloadContext);
|
||||
void setDownloadContext(DownloadContext* downloadContext);
|
||||
|
||||
void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
|
||||
void setPieceStorage(PieceStorage* pieceStorage);
|
||||
|
||||
void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
|
||||
void setPeerStorage(PeerStorage* peerStorage);
|
||||
|
||||
void setCuid(cuid_t cuid)
|
||||
{
|
||||
|
@ -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) {
|
||||
|
@ -623,13 +623,23 @@ void loadFromMemory(const std::shared_ptr<ValueBase>& torrent,
|
||||
|
||||
std::shared_ptr<TorrentAttribute> getTorrentAttrs
|
||||
(const std::shared_ptr<DownloadContext>& dctx)
|
||||
{
|
||||
return getTorrentAttrs(dctx.get());
|
||||
}
|
||||
|
||||
std::shared_ptr<TorrentAttribute> getTorrentAttrs(DownloadContext* dctx)
|
||||
{
|
||||
return std::static_pointer_cast<TorrentAttribute>
|
||||
(dctx->getAttribute(CTX_ATTR_BT));
|
||||
}
|
||||
|
||||
const unsigned char*
|
||||
getInfoHash(const std::shared_ptr<DownloadContext>& dctx)
|
||||
const unsigned char* getInfoHash
|
||||
(const std::shared_ptr<DownloadContext>& dctx)
|
||||
{
|
||||
return getInfoHash(dctx.get());
|
||||
}
|
||||
|
||||
const unsigned char* getInfoHash(DownloadContext* dctx)
|
||||
{
|
||||
return reinterpret_cast<const unsigned char*>
|
||||
(getTorrentAttrs(dctx)->infoHash.data());
|
||||
@ -637,6 +647,12 @@ getInfoHash(const std::shared_ptr<DownloadContext>& dctx)
|
||||
|
||||
std::string
|
||||
getInfoHashString(const std::shared_ptr<DownloadContext>& dctx)
|
||||
{
|
||||
return getInfoHashString(dctx.get());
|
||||
}
|
||||
|
||||
std::string
|
||||
getInfoHashString(DownloadContext* dctx)
|
||||
{
|
||||
return util::toHex(getTorrentAttrs(dctx)->infoHash);
|
||||
}
|
||||
|
@ -149,16 +149,19 @@ void computeFastSet
|
||||
(std::vector<size_t>& fastSet, const std::string& ipaddr,
|
||||
size_t numPieces, const unsigned char* infoHash, size_t fastSetSize);
|
||||
|
||||
std::shared_ptr<TorrentAttribute> getTorrentAttrs(DownloadContext* dctx);
|
||||
std::shared_ptr<TorrentAttribute> getTorrentAttrs
|
||||
(const std::shared_ptr<DownloadContext>& dctx);
|
||||
|
||||
// Returns the value associated with INFO_HASH key in BITTORRENT
|
||||
// attribute.
|
||||
const unsigned char*
|
||||
getInfoHash(const std::shared_ptr<DownloadContext>& downloadContext);
|
||||
const unsigned char* getInfoHash(DownloadContext* downloadContext);
|
||||
const unsigned char* getInfoHash
|
||||
(const std::shared_ptr<DownloadContext>& downloadContext);
|
||||
|
||||
std::string
|
||||
getInfoHashString(const std::shared_ptr<DownloadContext>& downloadContext);
|
||||
std::string getInfoHashString(DownloadContext* downloadContext);
|
||||
std::string getInfoHashString
|
||||
(const std::shared_ptr<DownloadContext>& downloadContext);
|
||||
|
||||
// Returns 8bytes unsigned integer located at offset pos. The integer
|
||||
// in msg is network byte order. This function converts it into host
|
||||
|
@ -85,8 +85,8 @@ void BtBitfieldMessageTest::testDoReceivedAction() {
|
||||
peer->allocateSessionResource(16*1024, 16*16*1024);
|
||||
BtBitfieldMessage msg;
|
||||
msg.setPeer(peer);
|
||||
std::shared_ptr<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
||||
msg.setPieceStorage(pieceStorage);
|
||||
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||
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<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
||||
msg.setPieceStorage(pieceStorage);
|
||||
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||
msg.setPieceStorage(pieceStorage.get());
|
||||
unsigned char bitfield[] = { 0x00 };
|
||||
msg.setBitfield(bitfield, sizeof(bitfield));
|
||||
|
||||
|
@ -74,8 +74,8 @@ void BtHaveAllMessageTest::testDoReceivedAction() {
|
||||
peer->allocateSessionResource(16*1024, 256*1024);
|
||||
peer->setFastExtensionEnabled(true);
|
||||
msg.setPeer(peer);
|
||||
std::shared_ptr<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
||||
msg.setPieceStorage(pieceStorage);
|
||||
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||
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<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
||||
msg.setPieceStorage(pieceStorage);
|
||||
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||
msg.setPieceStorage(pieceStorage.get());
|
||||
|
||||
pieceStorage->setDownloadFinished(true);
|
||||
|
||||
|
@ -80,8 +80,8 @@ void BtHaveMessageTest::testDoReceivedAction() {
|
||||
BtHaveMessage msg;
|
||||
msg.setIndex(1);
|
||||
msg.setPeer(peer);
|
||||
std::shared_ptr<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
||||
msg.setPieceStorage(pieceStorage);
|
||||
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||
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<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
||||
msg.setPieceStorage(pieceStorage);
|
||||
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||
msg.setPieceStorage(pieceStorage.get());
|
||||
|
||||
// peer is not seeder and client have not completed download
|
||||
msg.doReceivedAction();
|
||||
|
@ -71,9 +71,9 @@ void BtInterestedMessageTest::testDoReceivedAction() {
|
||||
peer->allocateSessionResource(1024, 1024*1024);
|
||||
msg.setPeer(peer);
|
||||
|
||||
std::shared_ptr<MockPeerStorage> peerStorage(new MockPeerStorage());
|
||||
auto peerStorage = make_unique<MockPeerStorage>();
|
||||
|
||||
msg.setPeerStorage(peerStorage);
|
||||
msg.setPeerStorage(peerStorage.get());
|
||||
|
||||
CPPUNIT_ASSERT(!peer->peerInterested());
|
||||
msg.doReceivedAction();
|
||||
|
@ -70,11 +70,11 @@ void BtNotInterestedMessageTest::testDoReceivedAction() {
|
||||
peer->allocateSessionResource(1024, 1024*1024);
|
||||
peer->peerInterested(true);
|
||||
|
||||
std::shared_ptr<MockPeerStorage> peerStorage(new MockPeerStorage());
|
||||
auto peerStorage = make_unique<MockPeerStorage>();
|
||||
|
||||
BtNotInterestedMessage msg;
|
||||
msg.setPeer(peer);
|
||||
msg.setPeerStorage(peerStorage);
|
||||
msg.setPeerStorage(peerStorage.get());
|
||||
|
||||
CPPUNIT_ASSERT(peer->peerInterested());
|
||||
msg.doReceivedAction();
|
||||
|
@ -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());
|
||||
|
@ -117,7 +117,7 @@ public:
|
||||
msg->setBlockIndex(2);
|
||||
msg->setBtMessageDispatcher(dispatcher_.get());
|
||||
msg->setBtMessageFactory(messageFactory_.get());
|
||||
msg->setPieceStorage(pieceStorage_);
|
||||
msg->setPieceStorage(pieceStorage_.get());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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_);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user