mirror of https://github.com/aria2/aria2
Use raw pointers to PieceStorage, PeerStorage and DownloadContxt for BtMessages
parent
09c597fbb8
commit
1a299c4d7c
|
@ -45,6 +45,7 @@ AbstractBtMessage::AbstractBtMessage(uint8_t id, const char* name)
|
||||||
uploading_(false),
|
uploading_(false),
|
||||||
cuid_(0),
|
cuid_(0),
|
||||||
name_(name),
|
name_(name),
|
||||||
|
pieceStorage_(0),
|
||||||
dispatcher_(0),
|
dispatcher_(0),
|
||||||
messageFactory_(0),
|
messageFactory_(0),
|
||||||
requestFactory_(0),
|
requestFactory_(0),
|
||||||
|
@ -71,8 +72,7 @@ AbstractBtMessage::setBtMessageValidator(const std::shared_ptr<BtMessageValidato
|
||||||
validator_ = validator;
|
validator_ = validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractBtMessage::setPieceStorage
|
void AbstractBtMessage::setPieceStorage(PieceStorage* pieceStorage)
|
||||||
(const std::shared_ptr<PieceStorage>& pieceStorage)
|
|
||||||
{
|
{
|
||||||
pieceStorage_ = pieceStorage;
|
pieceStorage_ = pieceStorage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ private:
|
||||||
|
|
||||||
const char* name_;
|
const char* name_;
|
||||||
|
|
||||||
std::shared_ptr<PieceStorage> pieceStorage_;
|
PieceStorage* pieceStorage_;
|
||||||
|
|
||||||
std::shared_ptr<Peer> peer_;
|
std::shared_ptr<Peer> peer_;
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ private:
|
||||||
|
|
||||||
bool metadataGetMode_;
|
bool metadataGetMode_;
|
||||||
protected:
|
protected:
|
||||||
const std::shared_ptr<PieceStorage>& getPieceStorage() const
|
PieceStorage* getPieceStorage() const
|
||||||
{
|
{
|
||||||
return pieceStorage_;
|
return pieceStorage_;
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ public:
|
||||||
|
|
||||||
void setBtMessageValidator(const std::shared_ptr<BtMessageValidator>& validator);
|
void setBtMessageValidator(const std::shared_ptr<BtMessageValidator>& validator);
|
||||||
|
|
||||||
void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
|
void setPieceStorage(PieceStorage* pieceStorage);
|
||||||
|
|
||||||
void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);
|
void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,10 @@ namespace aria2 {
|
||||||
|
|
||||||
const char BtInterestedMessage::NAME[] = "interested";
|
const char BtInterestedMessage::NAME[] = "interested";
|
||||||
|
|
||||||
BtInterestedMessage::BtInterestedMessage():ZeroBtMessage(ID, NAME) {}
|
BtInterestedMessage::BtInterestedMessage()
|
||||||
|
: ZeroBtMessage(ID, NAME),
|
||||||
|
peerStorage_(0)
|
||||||
|
{}
|
||||||
|
|
||||||
BtInterestedMessage::~BtInterestedMessage() {}
|
BtInterestedMessage::~BtInterestedMessage() {}
|
||||||
|
|
||||||
|
@ -86,8 +89,7 @@ ProgressUpdate* BtInterestedMessage::getProgressUpdate()
|
||||||
return new ThisProgressUpdate(getPeer());
|
return new ThisProgressUpdate(getPeer());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtInterestedMessage::setPeerStorage
|
void BtInterestedMessage::setPeerStorage(PeerStorage* peerStorage)
|
||||||
(const std::shared_ptr<PeerStorage>& peerStorage)
|
|
||||||
{
|
{
|
||||||
peerStorage_ = peerStorage;
|
peerStorage_ = peerStorage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ class BtInterestedMessage;
|
||||||
|
|
||||||
class BtInterestedMessage : public ZeroBtMessage {
|
class BtInterestedMessage : public ZeroBtMessage {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<PeerStorage> peerStorage_;
|
PeerStorage* peerStorage_;
|
||||||
public:
|
public:
|
||||||
BtInterestedMessage();
|
BtInterestedMessage();
|
||||||
virtual ~BtInterestedMessage();
|
virtual ~BtInterestedMessage();
|
||||||
|
@ -62,7 +62,7 @@ public:
|
||||||
|
|
||||||
virtual ProgressUpdate* getProgressUpdate();
|
virtual ProgressUpdate* getProgressUpdate();
|
||||||
|
|
||||||
void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
|
void setPeerStorage(PeerStorage* peerStorage);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -41,7 +41,10 @@ namespace aria2 {
|
||||||
|
|
||||||
const char BtNotInterestedMessage::NAME[] = "not interested";
|
const char BtNotInterestedMessage::NAME[] = "not interested";
|
||||||
|
|
||||||
BtNotInterestedMessage::BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {}
|
BtNotInterestedMessage::BtNotInterestedMessage()
|
||||||
|
: ZeroBtMessage(ID, NAME),
|
||||||
|
peerStorage_(0)
|
||||||
|
{}
|
||||||
|
|
||||||
BtNotInterestedMessage::~BtNotInterestedMessage() {}
|
BtNotInterestedMessage::~BtNotInterestedMessage() {}
|
||||||
|
|
||||||
|
@ -86,8 +89,7 @@ ProgressUpdate* BtNotInterestedMessage::getProgressUpdate()
|
||||||
return new ThisProgressUpdate(getPeer());
|
return new ThisProgressUpdate(getPeer());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtNotInterestedMessage::setPeerStorage
|
void BtNotInterestedMessage::setPeerStorage(PeerStorage* peerStorage)
|
||||||
(const std::shared_ptr<PeerStorage>& peerStorage)
|
|
||||||
{
|
{
|
||||||
peerStorage_ = peerStorage;
|
peerStorage_ = peerStorage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ class BtNotInterestedMessage;
|
||||||
|
|
||||||
class BtNotInterestedMessage : public ZeroBtMessage {
|
class BtNotInterestedMessage : public ZeroBtMessage {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<PeerStorage> peerStorage_;
|
PeerStorage* peerStorage_;
|
||||||
public:
|
public:
|
||||||
BtNotInterestedMessage();
|
BtNotInterestedMessage();
|
||||||
virtual ~BtNotInterestedMessage();
|
virtual ~BtNotInterestedMessage();
|
||||||
|
@ -62,7 +62,7 @@ public:
|
||||||
|
|
||||||
virtual ProgressUpdate* getProgressUpdate();
|
virtual ProgressUpdate* getProgressUpdate();
|
||||||
|
|
||||||
void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
|
void setPeerStorage(PeerStorage* peerStorage);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -71,7 +71,9 @@ BtPieceMessage::BtPieceMessage
|
||||||
index_(index),
|
index_(index),
|
||||||
begin_(begin),
|
begin_(begin),
|
||||||
blockLength_(blockLength),
|
blockLength_(blockLength),
|
||||||
data_(0)
|
data_(0),
|
||||||
|
downloadContext_(0),
|
||||||
|
peerStorage_(0)
|
||||||
{
|
{
|
||||||
setUploading(true);
|
setUploading(true);
|
||||||
}
|
}
|
||||||
|
@ -334,14 +336,12 @@ void BtPieceMessage::onCancelSendingPieceEvent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtPieceMessage::setDownloadContext
|
void BtPieceMessage::setDownloadContext(DownloadContext* downloadContext)
|
||||||
(const std::shared_ptr<DownloadContext>& downloadContext)
|
|
||||||
{
|
{
|
||||||
downloadContext_ = downloadContext;
|
downloadContext_ = downloadContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtPieceMessage::setPeerStorage
|
void BtPieceMessage::setPeerStorage(PeerStorage* peerStorage)
|
||||||
(const std::shared_ptr<PeerStorage>& peerStorage)
|
|
||||||
{
|
{
|
||||||
peerStorage_ = peerStorage;
|
peerStorage_ = peerStorage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,8 @@ private:
|
||||||
int32_t begin_;
|
int32_t begin_;
|
||||||
int32_t blockLength_;
|
int32_t blockLength_;
|
||||||
const unsigned char* data_;
|
const unsigned char* data_;
|
||||||
std::shared_ptr<DownloadContext> downloadContext_;
|
DownloadContext* downloadContext_;
|
||||||
std::shared_ptr<PeerStorage> peerStorage_;
|
PeerStorage* peerStorage_;
|
||||||
|
|
||||||
static size_t MESSAGE_HEADER_LENGTH;
|
static size_t MESSAGE_HEADER_LENGTH;
|
||||||
|
|
||||||
|
@ -88,9 +88,9 @@ public:
|
||||||
|
|
||||||
void setBlockLength(int32_t blockLength) { blockLength_ = blockLength; }
|
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);
|
static BtPieceMessage* create(const unsigned char* data, size_t dataLength);
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,9 @@ namespace aria2 {
|
||||||
|
|
||||||
DefaultBtMessageFactory::DefaultBtMessageFactory():
|
DefaultBtMessageFactory::DefaultBtMessageFactory():
|
||||||
cuid_(0),
|
cuid_(0),
|
||||||
|
downloadContext_(0),
|
||||||
|
pieceStorage_(0),
|
||||||
|
peerStorage_(0),
|
||||||
dhtEnabled_(false),
|
dhtEnabled_(false),
|
||||||
dispatcher_(0),
|
dispatcher_(0),
|
||||||
requestFactory_(0),
|
requestFactory_(0),
|
||||||
|
@ -439,19 +442,17 @@ void DefaultBtMessageFactory::setPeer(const std::shared_ptr<Peer>& peer)
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtMessageFactory::setDownloadContext
|
void DefaultBtMessageFactory::setDownloadContext
|
||||||
(const std::shared_ptr<DownloadContext>& downloadContext)
|
(DownloadContext* downloadContext)
|
||||||
{
|
{
|
||||||
downloadContext_ = downloadContext;
|
downloadContext_ = downloadContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtMessageFactory::setPieceStorage
|
void DefaultBtMessageFactory::setPieceStorage(PieceStorage* pieceStorage)
|
||||||
(const std::shared_ptr<PieceStorage>& pieceStorage)
|
|
||||||
{
|
{
|
||||||
pieceStorage_ = pieceStorage;
|
pieceStorage_ = pieceStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtMessageFactory::setPeerStorage
|
void DefaultBtMessageFactory::setPeerStorage(PeerStorage* peerStorage)
|
||||||
(const std::shared_ptr<PeerStorage>& peerStorage)
|
|
||||||
{
|
{
|
||||||
peerStorage_ = peerStorage;
|
peerStorage_ = peerStorage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,9 +57,9 @@ class DHTTaskFactory;
|
||||||
class DefaultBtMessageFactory : public BtMessageFactory {
|
class DefaultBtMessageFactory : public BtMessageFactory {
|
||||||
private:
|
private:
|
||||||
cuid_t cuid_;
|
cuid_t cuid_;
|
||||||
std::shared_ptr<DownloadContext> downloadContext_;
|
DownloadContext* downloadContext_;
|
||||||
std::shared_ptr<PieceStorage> pieceStorage_;
|
PieceStorage* pieceStorage_;
|
||||||
std::shared_ptr<PeerStorage> peerStorage_;
|
PeerStorage* peerStorage_;
|
||||||
std::shared_ptr<Peer> peer_;
|
std::shared_ptr<Peer> peer_;
|
||||||
|
|
||||||
bool dhtEnabled_;
|
bool dhtEnabled_;
|
||||||
|
@ -137,11 +137,11 @@ public:
|
||||||
|
|
||||||
void setPeer(const std::shared_ptr<Peer>& peer);
|
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)
|
void setCuid(cuid_t cuid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -147,9 +147,9 @@ PeerInteractionCommand::PeerInteractionCommand
|
||||||
|
|
||||||
DefaultBtMessageFactory* factoryPtr(new DefaultBtMessageFactory());
|
DefaultBtMessageFactory* factoryPtr(new DefaultBtMessageFactory());
|
||||||
factoryPtr->setCuid(cuid);
|
factoryPtr->setCuid(cuid);
|
||||||
factoryPtr->setDownloadContext(requestGroup_->getDownloadContext());
|
factoryPtr->setDownloadContext(requestGroup_->getDownloadContext().get());
|
||||||
factoryPtr->setPieceStorage(pieceStorage);
|
factoryPtr->setPieceStorage(pieceStorage.get());
|
||||||
factoryPtr->setPeerStorage(peerStorage);
|
factoryPtr->setPeerStorage(peerStorage.get());
|
||||||
factoryPtr->setExtensionMessageFactory(extensionMessageFactory);
|
factoryPtr->setExtensionMessageFactory(extensionMessageFactory);
|
||||||
factoryPtr->setPeer(getPeer());
|
factoryPtr->setPeer(getPeer());
|
||||||
if(family == AF_INET) {
|
if(family == AF_INET) {
|
||||||
|
|
|
@ -623,13 +623,23 @@ void loadFromMemory(const std::shared_ptr<ValueBase>& torrent,
|
||||||
|
|
||||||
std::shared_ptr<TorrentAttribute> getTorrentAttrs
|
std::shared_ptr<TorrentAttribute> getTorrentAttrs
|
||||||
(const std::shared_ptr<DownloadContext>& dctx)
|
(const std::shared_ptr<DownloadContext>& dctx)
|
||||||
|
{
|
||||||
|
return getTorrentAttrs(dctx.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<TorrentAttribute> getTorrentAttrs(DownloadContext* dctx)
|
||||||
{
|
{
|
||||||
return std::static_pointer_cast<TorrentAttribute>
|
return std::static_pointer_cast<TorrentAttribute>
|
||||||
(dctx->getAttribute(CTX_ATTR_BT));
|
(dctx->getAttribute(CTX_ATTR_BT));
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char*
|
const unsigned char* getInfoHash
|
||||||
getInfoHash(const std::shared_ptr<DownloadContext>& dctx)
|
(const std::shared_ptr<DownloadContext>& dctx)
|
||||||
|
{
|
||||||
|
return getInfoHash(dctx.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
const unsigned char* getInfoHash(DownloadContext* dctx)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<const unsigned char*>
|
return reinterpret_cast<const unsigned char*>
|
||||||
(getTorrentAttrs(dctx)->infoHash.data());
|
(getTorrentAttrs(dctx)->infoHash.data());
|
||||||
|
@ -637,6 +647,12 @@ getInfoHash(const std::shared_ptr<DownloadContext>& dctx)
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
getInfoHashString(const std::shared_ptr<DownloadContext>& dctx)
|
getInfoHashString(const std::shared_ptr<DownloadContext>& dctx)
|
||||||
|
{
|
||||||
|
return getInfoHashString(dctx.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
getInfoHashString(DownloadContext* dctx)
|
||||||
{
|
{
|
||||||
return util::toHex(getTorrentAttrs(dctx)->infoHash);
|
return util::toHex(getTorrentAttrs(dctx)->infoHash);
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,16 +149,19 @@ void computeFastSet
|
||||||
(std::vector<size_t>& fastSet, const std::string& ipaddr,
|
(std::vector<size_t>& fastSet, const std::string& ipaddr,
|
||||||
size_t numPieces, const unsigned char* infoHash, size_t fastSetSize);
|
size_t numPieces, const unsigned char* infoHash, size_t fastSetSize);
|
||||||
|
|
||||||
|
std::shared_ptr<TorrentAttribute> getTorrentAttrs(DownloadContext* dctx);
|
||||||
std::shared_ptr<TorrentAttribute> getTorrentAttrs
|
std::shared_ptr<TorrentAttribute> getTorrentAttrs
|
||||||
(const std::shared_ptr<DownloadContext>& dctx);
|
(const std::shared_ptr<DownloadContext>& dctx);
|
||||||
|
|
||||||
// Returns the value associated with INFO_HASH key in BITTORRENT
|
// Returns the value associated with INFO_HASH key in BITTORRENT
|
||||||
// attribute.
|
// attribute.
|
||||||
const unsigned char*
|
const unsigned char* getInfoHash(DownloadContext* downloadContext);
|
||||||
getInfoHash(const std::shared_ptr<DownloadContext>& downloadContext);
|
const unsigned char* getInfoHash
|
||||||
|
(const std::shared_ptr<DownloadContext>& downloadContext);
|
||||||
|
|
||||||
std::string
|
std::string getInfoHashString(DownloadContext* downloadContext);
|
||||||
getInfoHashString(const std::shared_ptr<DownloadContext>& downloadContext);
|
std::string getInfoHashString
|
||||||
|
(const std::shared_ptr<DownloadContext>& downloadContext);
|
||||||
|
|
||||||
// Returns 8bytes unsigned integer located at offset pos. The integer
|
// Returns 8bytes unsigned integer located at offset pos. The integer
|
||||||
// in msg is network byte order. This function converts it into host
|
// 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);
|
peer->allocateSessionResource(16*1024, 16*16*1024);
|
||||||
BtBitfieldMessage msg;
|
BtBitfieldMessage msg;
|
||||||
msg.setPeer(peer);
|
msg.setPeer(peer);
|
||||||
std::shared_ptr<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||||
msg.setPieceStorage(pieceStorage);
|
msg.setPieceStorage(pieceStorage.get());
|
||||||
unsigned char bitfield[] = { 0xff, 0xff };
|
unsigned char bitfield[] = { 0xff, 0xff };
|
||||||
msg.setBitfield(bitfield, sizeof(bitfield));
|
msg.setBitfield(bitfield, sizeof(bitfield));
|
||||||
|
|
||||||
|
@ -103,8 +103,8 @@ void BtBitfieldMessageTest::testDoReceivedAction_goodByeSeeder()
|
||||||
peer->allocateSessionResource(1024, 1024);
|
peer->allocateSessionResource(1024, 1024);
|
||||||
BtBitfieldMessage msg;
|
BtBitfieldMessage msg;
|
||||||
msg.setPeer(peer);
|
msg.setPeer(peer);
|
||||||
std::shared_ptr<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||||
msg.setPieceStorage(pieceStorage);
|
msg.setPieceStorage(pieceStorage.get());
|
||||||
unsigned char bitfield[] = { 0x00 };
|
unsigned char bitfield[] = { 0x00 };
|
||||||
msg.setBitfield(bitfield, sizeof(bitfield));
|
msg.setBitfield(bitfield, sizeof(bitfield));
|
||||||
|
|
||||||
|
|
|
@ -74,8 +74,8 @@ void BtHaveAllMessageTest::testDoReceivedAction() {
|
||||||
peer->allocateSessionResource(16*1024, 256*1024);
|
peer->allocateSessionResource(16*1024, 256*1024);
|
||||||
peer->setFastExtensionEnabled(true);
|
peer->setFastExtensionEnabled(true);
|
||||||
msg.setPeer(peer);
|
msg.setPeer(peer);
|
||||||
std::shared_ptr<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||||
msg.setPieceStorage(pieceStorage);
|
msg.setPieceStorage(pieceStorage.get());
|
||||||
|
|
||||||
msg.doReceivedAction();
|
msg.doReceivedAction();
|
||||||
|
|
||||||
|
@ -96,8 +96,8 @@ void BtHaveAllMessageTest::testDoReceivedAction_goodByeSeeder()
|
||||||
peer->allocateSessionResource(1024, 1024);
|
peer->allocateSessionResource(1024, 1024);
|
||||||
peer->setFastExtensionEnabled(true);
|
peer->setFastExtensionEnabled(true);
|
||||||
msg.setPeer(peer);
|
msg.setPeer(peer);
|
||||||
std::shared_ptr<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||||
msg.setPieceStorage(pieceStorage);
|
msg.setPieceStorage(pieceStorage.get());
|
||||||
|
|
||||||
pieceStorage->setDownloadFinished(true);
|
pieceStorage->setDownloadFinished(true);
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,8 @@ void BtHaveMessageTest::testDoReceivedAction() {
|
||||||
BtHaveMessage msg;
|
BtHaveMessage msg;
|
||||||
msg.setIndex(1);
|
msg.setIndex(1);
|
||||||
msg.setPeer(peer);
|
msg.setPeer(peer);
|
||||||
std::shared_ptr<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||||
msg.setPieceStorage(pieceStorage);
|
msg.setPieceStorage(pieceStorage.get());
|
||||||
|
|
||||||
CPPUNIT_ASSERT(!peer->hasPiece(msg.getIndex()));
|
CPPUNIT_ASSERT(!peer->hasPiece(msg.getIndex()));
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ void BtHaveMessageTest::testDoReceivedAction_goodByeSeeder()
|
||||||
BtHaveMessage msg;
|
BtHaveMessage msg;
|
||||||
msg.setIndex(0);
|
msg.setIndex(0);
|
||||||
msg.setPeer(peer);
|
msg.setPeer(peer);
|
||||||
std::shared_ptr<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
auto pieceStorage = make_unique<MockPieceStorage>();
|
||||||
msg.setPieceStorage(pieceStorage);
|
msg.setPieceStorage(pieceStorage.get());
|
||||||
|
|
||||||
// peer is not seeder and client have not completed download
|
// peer is not seeder and client have not completed download
|
||||||
msg.doReceivedAction();
|
msg.doReceivedAction();
|
||||||
|
|
|
@ -71,9 +71,9 @@ void BtInterestedMessageTest::testDoReceivedAction() {
|
||||||
peer->allocateSessionResource(1024, 1024*1024);
|
peer->allocateSessionResource(1024, 1024*1024);
|
||||||
msg.setPeer(peer);
|
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());
|
CPPUNIT_ASSERT(!peer->peerInterested());
|
||||||
msg.doReceivedAction();
|
msg.doReceivedAction();
|
||||||
|
|
|
@ -70,11 +70,11 @@ void BtNotInterestedMessageTest::testDoReceivedAction() {
|
||||||
peer->allocateSessionResource(1024, 1024*1024);
|
peer->allocateSessionResource(1024, 1024*1024);
|
||||||
peer->peerInterested(true);
|
peer->peerInterested(true);
|
||||||
|
|
||||||
std::shared_ptr<MockPeerStorage> peerStorage(new MockPeerStorage());
|
auto peerStorage = make_unique<MockPeerStorage>();
|
||||||
|
|
||||||
BtNotInterestedMessage msg;
|
BtNotInterestedMessage msg;
|
||||||
msg.setPeer(peer);
|
msg.setPeer(peer);
|
||||||
msg.setPeerStorage(peerStorage);
|
msg.setPeerStorage(peerStorage.get());
|
||||||
|
|
||||||
CPPUNIT_ASSERT(peer->peerInterested());
|
CPPUNIT_ASSERT(peer->peerInterested());
|
||||||
msg.doReceivedAction();
|
msg.doReceivedAction();
|
||||||
|
|
|
@ -88,7 +88,7 @@ public:
|
||||||
msg->setIndex(1);
|
msg->setIndex(1);
|
||||||
msg->setBegin(1024);
|
msg->setBegin(1024);
|
||||||
msg->setBlockLength(16*1024);
|
msg->setBlockLength(16*1024);
|
||||||
msg->setDownloadContext(dctx_);
|
msg->setDownloadContext(dctx_.get());
|
||||||
msg->setPeer(peer);
|
msg->setPeer(peer);
|
||||||
msg->setBtMessageDispatcher(btMessageDispatcher.get());
|
msg->setBtMessageDispatcher(btMessageDispatcher.get());
|
||||||
msg->setBtMessageFactory(btMessageFactory_.get());
|
msg->setBtMessageFactory(btMessageFactory_.get());
|
||||||
|
|
|
@ -117,7 +117,7 @@ public:
|
||||||
msg->setBlockIndex(2);
|
msg->setBlockIndex(2);
|
||||||
msg->setBtMessageDispatcher(dispatcher_.get());
|
msg->setBtMessageDispatcher(dispatcher_.get());
|
||||||
msg->setBtMessageFactory(messageFactory_.get());
|
msg->setBtMessageFactory(messageFactory_.get());
|
||||||
msg->setPieceStorage(pieceStorage_);
|
msg->setPieceStorage(pieceStorage_.get());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
exmsgFactory_.reset(new MockExtensionMessageFactory());
|
exmsgFactory_.reset(new MockExtensionMessageFactory());
|
||||||
|
|
||||||
factory_.reset(new DefaultBtMessageFactory());
|
factory_.reset(new DefaultBtMessageFactory());
|
||||||
factory_->setDownloadContext(dctx_);
|
factory_->setDownloadContext(dctx_.get());
|
||||||
factory_->setPeer(peer_);
|
factory_->setPeer(peer_);
|
||||||
factory_->setExtensionMessageFactory(exmsgFactory_);
|
factory_->setExtensionMessageFactory(exmsgFactory_);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue