mirror of
https://github.com/aria2/aria2.git
synced 2024-12-29 14:14:53 +00:00
Made static create function of BtMessage subclass return raw pointer
This commit is contained in:
parent
ae2e4cb7ff
commit
215d1d3d0b
@ -44,7 +44,7 @@ const char BtAllowedFastMessage::NAME[] = "allowed fast";
|
||||
BtAllowedFastMessage::BtAllowedFastMessage(size_t index):
|
||||
IndexBtMessage(ID, NAME, index) {}
|
||||
|
||||
SharedHandle<BtAllowedFastMessage> BtAllowedFastMessage::create
|
||||
BtAllowedFastMessage* BtAllowedFastMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return IndexBtMessage::create<BtAllowedFastMessage>(data, dataLength);
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtAllowedFastMessage;
|
||||
|
||||
typedef SharedHandle<BtAllowedFastMessage> BtAllowedFastMessageHandle;
|
||||
|
||||
class BtAllowedFastMessage : public IndexBtMessage {
|
||||
public:
|
||||
BtAllowedFastMessage(size_t index = 0);
|
||||
@ -51,7 +47,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static SharedHandle<BtAllowedFastMessage> create
|
||||
static BtAllowedFastMessage* create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
@ -78,12 +78,12 @@ void BtBitfieldMessage::setBitfield
|
||||
memcpy(bitfield_, bitfield, bitfieldLength_);
|
||||
}
|
||||
|
||||
BtBitfieldMessageHandle
|
||||
BtBitfieldMessage*
|
||||
BtBitfieldMessage::create(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
bittorrent::assertPayloadLengthGreater(1,dataLength, NAME);
|
||||
bittorrent::assertID(ID, data, NAME);
|
||||
BtBitfieldMessageHandle message(new BtBitfieldMessage());
|
||||
BtBitfieldMessage* message(new BtBitfieldMessage());
|
||||
message->setBitfield(data+1, dataLength-1);
|
||||
return message;
|
||||
}
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtBitfieldMessage;
|
||||
|
||||
typedef SharedHandle<BtBitfieldMessage> BtBitfieldMessageHandle;
|
||||
|
||||
class BtBitfieldMessage : public SimpleBtMessage {
|
||||
private:
|
||||
unsigned char* bitfield_;
|
||||
@ -64,7 +60,7 @@ public:
|
||||
|
||||
size_t getBitfieldLength() const { return bitfieldLength_; }
|
||||
|
||||
static BtBitfieldMessageHandle create
|
||||
static BtBitfieldMessage* create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
@ -43,7 +43,7 @@ BtCancelMessage::BtCancelMessage
|
||||
(size_t index, int32_t begin, int32_t length)
|
||||
:RangeBtMessage(ID, NAME, index, begin, length) {}
|
||||
|
||||
SharedHandle<BtCancelMessage> BtCancelMessage::create
|
||||
BtCancelMessage* BtCancelMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return RangeBtMessage::create<BtCancelMessage>(data, dataLength);
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtCancelMessage;
|
||||
|
||||
typedef SharedHandle<BtCancelMessage> BtCancelMessageHandle;
|
||||
|
||||
class BtCancelMessage : public RangeBtMessage {
|
||||
public:
|
||||
BtCancelMessage(size_t index = 0, int32_t begin = 0, int32_t length = 0);
|
||||
@ -51,8 +47,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static BtCancelMessageHandle create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
static BtCancelMessage* create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
};
|
||||
|
@ -43,7 +43,7 @@ const char BtChokeMessage::NAME[] = "choke";
|
||||
|
||||
BtChokeMessage::BtChokeMessage():ZeroBtMessage(ID, NAME) {}
|
||||
|
||||
SharedHandle<BtChokeMessage> BtChokeMessage::create
|
||||
BtChokeMessage* BtChokeMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return ZeroBtMessage::create<BtChokeMessage>(data, dataLength);
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtChokeMessage;
|
||||
|
||||
typedef SharedHandle<BtChokeMessage> BtChokeMessageHandle;
|
||||
|
||||
class BtChokeMessage : public ZeroBtMessage {
|
||||
public:
|
||||
BtChokeMessage();
|
||||
@ -53,8 +49,7 @@ public:
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
static SharedHandle<BtChokeMessage> create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
static BtChokeMessage* create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual bool sendPredicate() const;
|
||||
|
||||
|
@ -96,7 +96,7 @@ std::string BtExtendedMessage::toString() const {
|
||||
return s;
|
||||
}
|
||||
|
||||
BtExtendedMessageHandle
|
||||
BtExtendedMessage*
|
||||
BtExtendedMessage::create(const SharedHandle<ExtensionMessageFactory>& factory,
|
||||
const SharedHandle<Peer>& peer,
|
||||
const unsigned char* data, size_t dataLength)
|
||||
@ -104,9 +104,9 @@ BtExtendedMessage::create(const SharedHandle<ExtensionMessageFactory>& factory,
|
||||
bittorrent::assertPayloadLengthGreater(1, dataLength, NAME);
|
||||
bittorrent::assertID(ID, data, NAME);
|
||||
assert(factory);
|
||||
ExtensionMessageHandle extmsg = factory->createMessage(data+1,
|
||||
dataLength-1);
|
||||
BtExtendedMessageHandle message(new BtExtendedMessage(extmsg));
|
||||
SharedHandle<ExtensionMessage> extmsg = factory->createMessage(data+1,
|
||||
dataLength-1);
|
||||
BtExtendedMessage* message(new BtExtendedMessage(extmsg));
|
||||
return message;
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,6 @@ namespace aria2 {
|
||||
class ExtensionMessage;
|
||||
class ExtensionMessageFactory;
|
||||
|
||||
class BtExtendedMessage;
|
||||
typedef SharedHandle<BtExtendedMessage> BtExtendedMessageHandle;
|
||||
|
||||
class BtExtendedMessage:public SimpleBtMessage
|
||||
{
|
||||
private:
|
||||
@ -59,7 +56,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static BtExtendedMessageHandle create
|
||||
static BtExtendedMessage* create
|
||||
(const SharedHandle<ExtensionMessageFactory>& factory,
|
||||
const SharedHandle<Peer>& peer,
|
||||
const unsigned char* data,
|
||||
|
@ -45,7 +45,7 @@ const char BtHaveAllMessage::NAME[] = "have all";
|
||||
|
||||
BtHaveAllMessage::BtHaveAllMessage():ZeroBtMessage(ID, NAME) {}
|
||||
|
||||
SharedHandle<BtHaveAllMessage> BtHaveAllMessage::create
|
||||
BtHaveAllMessage* BtHaveAllMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return ZeroBtMessage::create<BtHaveAllMessage>(data, dataLength);
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtHaveAllMessage;
|
||||
|
||||
typedef SharedHandle<BtHaveAllMessage> BtHaveAllMessageHandle;
|
||||
|
||||
class BtHaveAllMessage : public ZeroBtMessage {
|
||||
public:
|
||||
BtHaveAllMessage();
|
||||
@ -51,7 +47,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static SharedHandle<BtHaveAllMessage> create
|
||||
static BtHaveAllMessage* create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
@ -44,7 +44,7 @@ const char BtHaveMessage::NAME[] = "have";
|
||||
|
||||
BtHaveMessage::BtHaveMessage(size_t index):IndexBtMessage(ID, NAME, index) {}
|
||||
|
||||
SharedHandle<BtHaveMessage> BtHaveMessage::create
|
||||
BtHaveMessage* BtHaveMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return IndexBtMessage::create<BtHaveMessage>(data, dataLength);
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtHaveMessage;
|
||||
|
||||
typedef SharedHandle<BtHaveMessage> BtHaveMessageHandle;
|
||||
|
||||
class BtHaveMessage : public IndexBtMessage {
|
||||
public:
|
||||
BtHaveMessage(size_t index = 0);
|
||||
@ -51,8 +47,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static SharedHandle<BtHaveMessage> create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
static BtHaveMessage* create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
};
|
||||
|
@ -43,7 +43,7 @@ const char BtHaveNoneMessage::NAME[] = "have none";
|
||||
|
||||
BtHaveNoneMessage::BtHaveNoneMessage():ZeroBtMessage(ID, NAME) {}
|
||||
|
||||
SharedHandle<BtHaveNoneMessage> BtHaveNoneMessage::create
|
||||
BtHaveNoneMessage* BtHaveNoneMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return ZeroBtMessage::create<BtHaveNoneMessage>(data, dataLength);
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtHaveNoneMessage;
|
||||
|
||||
typedef SharedHandle<BtHaveNoneMessage> BtHaveNoneMessageHandle;
|
||||
|
||||
class BtHaveNoneMessage : public ZeroBtMessage {
|
||||
public:
|
||||
BtHaveNoneMessage();
|
||||
@ -51,7 +47,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static SharedHandle<BtHaveNoneMessage> create
|
||||
static BtHaveNoneMessage* create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
@ -44,7 +44,7 @@ BtInterestedMessage::BtInterestedMessage():ZeroBtMessage(ID, NAME) {}
|
||||
|
||||
BtInterestedMessage::~BtInterestedMessage() {}
|
||||
|
||||
SharedHandle<BtInterestedMessage> BtInterestedMessage::create
|
||||
BtInterestedMessage* BtInterestedMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return ZeroBtMessage::create<BtInterestedMessage>(data, dataLength);
|
||||
|
@ -42,8 +42,6 @@ namespace aria2 {
|
||||
class PeerStorage;
|
||||
class BtInterestedMessage;
|
||||
|
||||
typedef SharedHandle<BtInterestedMessage> BtInterestedMessageHandle;
|
||||
|
||||
class BtInterestedMessage : public ZeroBtMessage {
|
||||
private:
|
||||
SharedHandle<PeerStorage> peerStorage_;
|
||||
@ -55,7 +53,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static SharedHandle<BtInterestedMessage> create
|
||||
static BtInterestedMessage* create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
@ -44,7 +44,7 @@ BtNotInterestedMessage::BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {}
|
||||
|
||||
BtNotInterestedMessage::~BtNotInterestedMessage() {}
|
||||
|
||||
SharedHandle<BtNotInterestedMessage> BtNotInterestedMessage::create
|
||||
BtNotInterestedMessage* BtNotInterestedMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return ZeroBtMessage::create<BtNotInterestedMessage>(data, dataLength);
|
||||
|
@ -42,8 +42,6 @@ namespace aria2 {
|
||||
class PeerStorage;
|
||||
class BtNotInterestedMessage;
|
||||
|
||||
typedef SharedHandle<BtNotInterestedMessage> BtNotInterestedMessageHandle;
|
||||
|
||||
class BtNotInterestedMessage : public ZeroBtMessage {
|
||||
private:
|
||||
SharedHandle<PeerStorage> peerStorage_;
|
||||
@ -55,7 +53,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static SharedHandle<BtNotInterestedMessage> create
|
||||
static BtNotInterestedMessage* create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
@ -80,12 +80,12 @@ void BtPieceMessage::setMsgPayload(const unsigned char* data)
|
||||
data_ = data;
|
||||
}
|
||||
|
||||
BtPieceMessageHandle BtPieceMessage::create
|
||||
BtPieceMessage* BtPieceMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
bittorrent::assertPayloadLengthGreater(9, dataLength, NAME);
|
||||
bittorrent::assertID(ID, data, NAME);
|
||||
BtPieceMessageHandle message(new BtPieceMessage());
|
||||
BtPieceMessage* message(new BtPieceMessage());
|
||||
message->setIndex(bittorrent::getIntParam(data, 1));
|
||||
message->setBegin(bittorrent::getIntParam(data, 5));
|
||||
message->setBlockLength(dataLength-9);
|
||||
|
@ -40,12 +40,9 @@
|
||||
namespace aria2 {
|
||||
|
||||
class Piece;
|
||||
class BtPieceMessage;
|
||||
class DownloadContext;
|
||||
class PeerStorage;
|
||||
|
||||
typedef SharedHandle<BtPieceMessage> BtPieceMessageHandle;
|
||||
|
||||
class BtPieceMessage : public AbstractBtMessage {
|
||||
private:
|
||||
size_t index_;
|
||||
@ -97,8 +94,7 @@ public:
|
||||
|
||||
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
|
||||
|
||||
static BtPieceMessageHandle create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
static BtPieceMessage* create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
@ -111,7 +107,7 @@ public:
|
||||
virtual std::string toString() const;
|
||||
|
||||
virtual void onChokingEvent(const BtChokingEvent& event);
|
||||
|
||||
|
||||
virtual void onCancelSendingPieceEvent
|
||||
(const BtCancelSendingPieceEvent& event);
|
||||
};
|
||||
|
@ -61,13 +61,13 @@ BtPortMessage::BtPortMessage(uint16_t port)
|
||||
taskFactory_(0)
|
||||
{}
|
||||
|
||||
SharedHandle<BtPortMessage> BtPortMessage::create
|
||||
BtPortMessage* BtPortMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
bittorrent::assertPayloadLengthEqual(3, dataLength, NAME);
|
||||
bittorrent::assertID(ID, data, NAME);
|
||||
uint16_t port = bittorrent::getShortIntParam(data, 1);
|
||||
SharedHandle<BtPortMessage> message(new BtPortMessage(port));
|
||||
BtPortMessage* message(new BtPortMessage(port));
|
||||
return message;
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,7 @@ public:
|
||||
|
||||
uint16_t getPort() const { return port_; }
|
||||
|
||||
static SharedHandle<BtPortMessage> create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
static BtPortMessage* create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
|
@ -47,7 +47,7 @@ BtRejectMessage::BtRejectMessage
|
||||
(size_t index, int32_t begin, int32_t length):
|
||||
RangeBtMessage(ID, NAME, index, begin, length) {}
|
||||
|
||||
SharedHandle<BtRejectMessage> BtRejectMessage::create
|
||||
BtRejectMessage* BtRejectMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return RangeBtMessage::create<BtRejectMessage>(data, dataLength);
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtRejectMessage;
|
||||
|
||||
typedef SharedHandle<BtRejectMessage> BtRejectMessageHandle;
|
||||
|
||||
class BtRejectMessage : public RangeBtMessage {
|
||||
public:
|
||||
BtRejectMessage(size_t index = 0, int32_t begin = 0, int32_t length = 0);
|
||||
@ -51,8 +47,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static SharedHandle<BtRejectMessage> create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
static BtRejectMessage* create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
};
|
||||
|
@ -48,7 +48,7 @@ BtRequestMessage::BtRequestMessage
|
||||
RangeBtMessage(ID, NAME, index, begin, length),
|
||||
blockIndex_(blockIndex) {}
|
||||
|
||||
SharedHandle<BtRequestMessage> BtRequestMessage::create
|
||||
BtRequestMessage* BtRequestMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return RangeBtMessage::create<BtRequestMessage>(data, dataLength);
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtRequestMessage;
|
||||
|
||||
typedef SharedHandle<BtRequestMessage> BtRequestMessageHandle;
|
||||
|
||||
class BtRequestMessage : public RangeBtMessage {
|
||||
private:
|
||||
size_t blockIndex_;
|
||||
@ -59,7 +55,7 @@ public:
|
||||
size_t getBlockIndex() const { return blockIndex_; }
|
||||
void setBlockIndex(size_t blockIndex) { blockIndex_ = blockIndex; }
|
||||
|
||||
static SharedHandle<BtRequestMessage> create
|
||||
static BtRequestMessage* create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
@ -38,7 +38,7 @@ namespace aria2 {
|
||||
|
||||
const char BtSuggestPieceMessage::NAME[] = "suggest piece";
|
||||
|
||||
SharedHandle<BtSuggestPieceMessage> BtSuggestPieceMessage::create
|
||||
BtSuggestPieceMessage* BtSuggestPieceMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return IndexBtMessage::create<BtSuggestPieceMessage>(data, dataLength);
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtSuggestPieceMessage;
|
||||
|
||||
typedef SharedHandle<BtSuggestPieceMessage> BtSuggestPieceMessageHandle;
|
||||
|
||||
class BtSuggestPieceMessage : public IndexBtMessage {
|
||||
public:
|
||||
BtSuggestPieceMessage():IndexBtMessage(ID, NAME, 0) {}
|
||||
@ -51,7 +47,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static SharedHandle<BtSuggestPieceMessage> create
|
||||
static BtSuggestPieceMessage* create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction() {
|
||||
|
@ -41,7 +41,7 @@ const char BtUnchokeMessage::NAME[] = "unchoke";
|
||||
|
||||
BtUnchokeMessage::BtUnchokeMessage():ZeroBtMessage(ID, NAME) {}
|
||||
|
||||
SharedHandle<BtUnchokeMessage> BtUnchokeMessage::create
|
||||
BtUnchokeMessage* BtUnchokeMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return ZeroBtMessage::create<BtUnchokeMessage>(data, dataLength);
|
||||
|
@ -39,10 +39,6 @@
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class BtUnchokeMessage;
|
||||
|
||||
typedef SharedHandle<BtUnchokeMessage> BtUnchokeMessageHandle;
|
||||
|
||||
class BtUnchokeMessage : public ZeroBtMessage {
|
||||
private:
|
||||
static const size_t MESSAGE_LENGTH = 5;
|
||||
@ -53,7 +49,7 @@ public:
|
||||
|
||||
static const char NAME[];
|
||||
|
||||
static SharedHandle<BtUnchokeMessage> create
|
||||
static BtUnchokeMessage* create
|
||||
(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
@ -85,11 +85,11 @@ DefaultBtMessageFactory::DefaultBtMessageFactory():
|
||||
|
||||
DefaultBtMessageFactory::~DefaultBtMessageFactory() {}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createBtMessage
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
AbstractBtMessageHandle msg;
|
||||
SharedHandle<AbstractBtMessage> msg;
|
||||
if(dataLength == 0) {
|
||||
// keep-alive
|
||||
msg.reset(new BtKeepAliveMessage());
|
||||
@ -97,148 +97,139 @@ DefaultBtMessageFactory::createBtMessage
|
||||
uint8_t id = bittorrent::getId(data);
|
||||
switch(id) {
|
||||
case BtChokeMessage::ID:
|
||||
msg = BtChokeMessage::create(data, dataLength);
|
||||
msg.reset(BtChokeMessage::create(data, dataLength));
|
||||
break;
|
||||
case BtUnchokeMessage::ID:
|
||||
msg = BtUnchokeMessage::create(data, dataLength);
|
||||
msg.reset(BtUnchokeMessage::create(data, dataLength));
|
||||
break;
|
||||
case BtInterestedMessage::ID:
|
||||
{
|
||||
SharedHandle<BtInterestedMessage> m =
|
||||
BtInterestedMessage::create(data, dataLength);
|
||||
BtInterestedMessage* m = BtInterestedMessage::create(data, dataLength);
|
||||
m->setPeerStorage(peerStorage_);
|
||||
msg = m;
|
||||
msg.reset(m);
|
||||
}
|
||||
break;
|
||||
case BtNotInterestedMessage::ID:
|
||||
{
|
||||
SharedHandle<BtNotInterestedMessage> m =
|
||||
BtNotInterestedMessage* m =
|
||||
BtNotInterestedMessage::create(data, dataLength);
|
||||
m->setPeerStorage(peerStorage_);
|
||||
msg = m;
|
||||
msg.reset(m);
|
||||
}
|
||||
break;
|
||||
case BtHaveMessage::ID:
|
||||
msg = BtHaveMessage::create(data, dataLength);
|
||||
{
|
||||
if(!metadataGetMode_) {
|
||||
SharedHandle<BtMessageValidator> v
|
||||
(new IndexBtMessageValidator(static_cast<BtHaveMessage*>(msg.get()),
|
||||
downloadContext_->getNumPieces()));
|
||||
msg->setBtMessageValidator(v);
|
||||
}
|
||||
msg.reset(BtHaveMessage::create(data, dataLength));
|
||||
if(!metadataGetMode_) {
|
||||
SharedHandle<BtMessageValidator> v
|
||||
(new IndexBtMessageValidator(static_cast<BtHaveMessage*>(msg.get()),
|
||||
downloadContext_->getNumPieces()));
|
||||
msg->setBtMessageValidator(v);
|
||||
}
|
||||
break;
|
||||
case BtBitfieldMessage::ID:
|
||||
msg = BtBitfieldMessage::create(data, dataLength);
|
||||
{
|
||||
if(!metadataGetMode_) {
|
||||
SharedHandle<BtMessageValidator> v
|
||||
(new BtBitfieldMessageValidator
|
||||
(static_cast<BtBitfieldMessage*>(msg.get()),
|
||||
downloadContext_->getNumPieces()));
|
||||
msg->setBtMessageValidator(v);
|
||||
}
|
||||
msg.reset(BtBitfieldMessage::create(data, dataLength));
|
||||
if(!metadataGetMode_) {
|
||||
SharedHandle<BtMessageValidator> v
|
||||
(new BtBitfieldMessageValidator
|
||||
(static_cast<BtBitfieldMessage*>(msg.get()),
|
||||
downloadContext_->getNumPieces()));
|
||||
msg->setBtMessageValidator(v);
|
||||
}
|
||||
break;
|
||||
case BtRequestMessage::ID: {
|
||||
BtRequestMessageHandle temp = BtRequestMessage::create(data, dataLength);
|
||||
BtRequestMessage* m = BtRequestMessage::create(data, dataLength);
|
||||
if(!metadataGetMode_) {
|
||||
SharedHandle<BtMessageValidator> validator
|
||||
(new RangeBtMessageValidator
|
||||
(temp.get(),
|
||||
(m,
|
||||
downloadContext_->getNumPieces(),
|
||||
pieceStorage_->getPieceLength(temp->getIndex())));
|
||||
temp->setBtMessageValidator(validator);
|
||||
pieceStorage_->getPieceLength(m->getIndex())));
|
||||
m->setBtMessageValidator(validator);
|
||||
}
|
||||
msg = temp;
|
||||
msg.reset(m);
|
||||
break;
|
||||
}
|
||||
case BtCancelMessage::ID: {
|
||||
BtCancelMessageHandle temp = BtCancelMessage::create(data, dataLength);
|
||||
BtCancelMessage* m = BtCancelMessage::create(data, dataLength);
|
||||
if(!metadataGetMode_) {
|
||||
SharedHandle<BtMessageValidator> validator
|
||||
(new RangeBtMessageValidator
|
||||
(temp.get(),
|
||||
(m,
|
||||
downloadContext_->getNumPieces(),
|
||||
pieceStorage_->getPieceLength(temp->getIndex())));
|
||||
temp->setBtMessageValidator(validator);
|
||||
pieceStorage_->getPieceLength(m->getIndex())));
|
||||
m->setBtMessageValidator(validator);
|
||||
}
|
||||
msg = temp;
|
||||
msg.reset(m);
|
||||
break;
|
||||
}
|
||||
case BtPieceMessage::ID: {
|
||||
BtPieceMessageHandle temp = BtPieceMessage::create(data, dataLength);
|
||||
BtPieceMessage* m = BtPieceMessage::create(data, dataLength);
|
||||
if(!metadataGetMode_) {
|
||||
BtMessageValidatorHandle validator
|
||||
(new BtPieceMessageValidator
|
||||
(temp.get(),
|
||||
(m,
|
||||
downloadContext_->getNumPieces(),
|
||||
pieceStorage_->getPieceLength(temp->getIndex())));
|
||||
temp->setBtMessageValidator(validator);
|
||||
pieceStorage_->getPieceLength(m->getIndex())));
|
||||
m->setBtMessageValidator(validator);
|
||||
}
|
||||
temp->setDownloadContext(downloadContext_);
|
||||
temp->setPeerStorage(peerStorage_);
|
||||
msg = temp;
|
||||
m->setDownloadContext(downloadContext_);
|
||||
m->setPeerStorage(peerStorage_);
|
||||
msg.reset(m);
|
||||
break;
|
||||
}
|
||||
case BtHaveAllMessage::ID:
|
||||
msg = BtHaveAllMessage::create(data, dataLength);
|
||||
msg.reset(BtHaveAllMessage::create(data, dataLength));
|
||||
break;
|
||||
case BtHaveNoneMessage::ID:
|
||||
msg = BtHaveNoneMessage::create(data, dataLength);
|
||||
msg.reset(BtHaveNoneMessage::create(data, dataLength));
|
||||
break;
|
||||
case BtRejectMessage::ID: {
|
||||
BtRejectMessageHandle temp = BtRejectMessage::create(data, dataLength);
|
||||
BtRejectMessage* m = BtRejectMessage::create(data, dataLength);
|
||||
if(!metadataGetMode_) {
|
||||
SharedHandle<BtMessageValidator> validator
|
||||
(new RangeBtMessageValidator
|
||||
(temp.get(),
|
||||
(m,
|
||||
downloadContext_->getNumPieces(),
|
||||
pieceStorage_->getPieceLength(temp->getIndex())));
|
||||
temp->setBtMessageValidator(validator);
|
||||
pieceStorage_->getPieceLength(m->getIndex())));
|
||||
m->setBtMessageValidator(validator);
|
||||
}
|
||||
msg = temp;
|
||||
msg.reset(m);
|
||||
break;
|
||||
}
|
||||
case BtSuggestPieceMessage::ID: {
|
||||
BtSuggestPieceMessageHandle temp =
|
||||
BtSuggestPieceMessage* m =
|
||||
BtSuggestPieceMessage::create(data, dataLength);
|
||||
if(!metadataGetMode_) {
|
||||
SharedHandle<BtMessageValidator> validator
|
||||
(new IndexBtMessageValidator(temp.get(),
|
||||
downloadContext_->getNumPieces()));
|
||||
temp->setBtMessageValidator(validator);
|
||||
(new IndexBtMessageValidator(m, downloadContext_->getNumPieces()));
|
||||
m->setBtMessageValidator(validator);
|
||||
}
|
||||
msg = temp;
|
||||
msg.reset(m);
|
||||
break;
|
||||
}
|
||||
case BtAllowedFastMessage::ID: {
|
||||
BtAllowedFastMessageHandle temp =
|
||||
BtAllowedFastMessage::create(data, dataLength);
|
||||
BtAllowedFastMessage* m = BtAllowedFastMessage::create(data, dataLength);
|
||||
if(!metadataGetMode_) {
|
||||
SharedHandle<BtMessageValidator> validator
|
||||
(new IndexBtMessageValidator(temp.get(),
|
||||
downloadContext_->getNumPieces()));
|
||||
temp->setBtMessageValidator(validator);
|
||||
(new IndexBtMessageValidator(m, downloadContext_->getNumPieces()));
|
||||
m->setBtMessageValidator(validator);
|
||||
}
|
||||
msg = temp;
|
||||
msg.reset(m);
|
||||
break;
|
||||
}
|
||||
case BtPortMessage::ID: {
|
||||
SharedHandle<BtPortMessage> temp =
|
||||
BtPortMessage::create(data, dataLength);
|
||||
temp->setLocalNode(localNode_);
|
||||
temp->setRoutingTable(routingTable_);
|
||||
temp->setTaskQueue(taskQueue_);
|
||||
temp->setTaskFactory(taskFactory_);
|
||||
msg = temp;
|
||||
BtPortMessage* m = BtPortMessage::create(data, dataLength);
|
||||
m->setLocalNode(localNode_);
|
||||
m->setRoutingTable(routingTable_);
|
||||
m->setTaskQueue(taskQueue_);
|
||||
m->setTaskFactory(taskFactory_);
|
||||
msg.reset(m);
|
||||
break;
|
||||
}
|
||||
case BtExtendedMessage::ID: {
|
||||
if(peer_->isExtendedMessagingEnabled()) {
|
||||
msg = BtExtendedMessage::create(extensionMessageFactory_,
|
||||
peer_, data, dataLength);
|
||||
msg.reset(BtExtendedMessage::create(extensionMessageFactory_,
|
||||
peer_, data, dataLength));
|
||||
} else {
|
||||
throw DL_ABORT_EX("Received extended message from peer during"
|
||||
" a session with extended messaging disabled.");
|
||||
@ -249,12 +240,12 @@ DefaultBtMessageFactory::createBtMessage
|
||||
throw DL_ABORT_EX(fmt("Invalid message ID. id=%u", id));
|
||||
}
|
||||
}
|
||||
setCommonProperty(msg);
|
||||
setCommonProperty(msg.get());
|
||||
return msg;
|
||||
}
|
||||
|
||||
void DefaultBtMessageFactory::setCommonProperty
|
||||
(const AbstractBtMessageHandle& msg) {
|
||||
void DefaultBtMessageFactory::setCommonProperty(AbstractBtMessage* msg)
|
||||
{
|
||||
msg->setCuid(cuid_);
|
||||
msg->setPeer(peer_);
|
||||
msg->setPieceStorage(pieceStorage_);
|
||||
@ -277,7 +268,7 @@ DefaultBtMessageFactory::createHandshakeMessage
|
||||
(new BtHandshakeMessageValidator
|
||||
(msg.get(), bittorrent::getInfoHash(downloadContext_)));
|
||||
msg->setBtMessageValidator(validator);
|
||||
setCommonProperty(msg);
|
||||
setCommonProperty(msg.get());
|
||||
return msg;
|
||||
}
|
||||
|
||||
@ -292,181 +283,180 @@ DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* infoHash,
|
||||
(msg.get(), bittorrent::getInfoHash(downloadContext_)));
|
||||
msg->setBtMessageValidator(validator);
|
||||
msg->setDHTEnabled(dhtEnabled_);
|
||||
setCommonProperty(msg);
|
||||
setCommonProperty(msg.get());
|
||||
return msg;
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createRequestMessage
|
||||
(const SharedHandle<Piece>& piece, size_t blockIndex)
|
||||
{
|
||||
BtRequestMessageHandle msg
|
||||
BtRequestMessage* msg
|
||||
(new BtRequestMessage(piece->getIndex(),
|
||||
blockIndex*piece->getBlockLength(),
|
||||
piece->getBlockLength(blockIndex),
|
||||
blockIndex));
|
||||
SharedHandle<BtMessageValidator> validator
|
||||
(new RangeBtMessageValidator
|
||||
(msg.get(),
|
||||
(msg,
|
||||
downloadContext_->getNumPieces(),
|
||||
pieceStorage_->getPieceLength(msg->getIndex())));
|
||||
msg->setBtMessageValidator(validator);
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createCancelMessage
|
||||
(size_t index, int32_t begin, int32_t length)
|
||||
{
|
||||
BtCancelMessageHandle msg(new BtCancelMessage(index, begin, length));
|
||||
BtCancelMessage* msg(new BtCancelMessage(index, begin, length));
|
||||
SharedHandle<BtMessageValidator> validator
|
||||
(new RangeBtMessageValidator
|
||||
(msg.get(),
|
||||
(msg,
|
||||
downloadContext_->getNumPieces(),
|
||||
pieceStorage_->getPieceLength(index)));
|
||||
msg->setBtMessageValidator(validator);
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createPieceMessage
|
||||
(size_t index, int32_t begin, int32_t length)
|
||||
{
|
||||
BtPieceMessageHandle msg(new BtPieceMessage(index, begin, length));
|
||||
BtPieceMessage* msg(new BtPieceMessage(index, begin, length));
|
||||
BtMessageValidatorHandle validator
|
||||
(new BtPieceMessageValidator(msg.get(),
|
||||
(new BtPieceMessageValidator(msg,
|
||||
downloadContext_->getNumPieces(),
|
||||
pieceStorage_->getPieceLength(index)));
|
||||
msg->setBtMessageValidator(validator);
|
||||
msg->setDownloadContext(downloadContext_);
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createHaveMessage(size_t index)
|
||||
{
|
||||
BtHaveMessageHandle msg(new BtHaveMessage(index));
|
||||
BtHaveMessage* msg(new BtHaveMessage(index));
|
||||
SharedHandle<BtMessageValidator> v
|
||||
(new IndexBtMessageValidator(msg.get(), downloadContext_->getNumPieces()));
|
||||
(new IndexBtMessageValidator(msg, downloadContext_->getNumPieces()));
|
||||
msg->setBtMessageValidator(v);
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createChokeMessage()
|
||||
{
|
||||
BtChokeMessageHandle msg(new BtChokeMessage());
|
||||
BtChokeMessage* msg(new BtChokeMessage());
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createUnchokeMessage()
|
||||
{
|
||||
BtUnchokeMessageHandle msg(new BtUnchokeMessage());
|
||||
BtUnchokeMessage* msg(new BtUnchokeMessage());
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createInterestedMessage()
|
||||
{
|
||||
BtInterestedMessageHandle msg(new BtInterestedMessage());
|
||||
BtInterestedMessage* msg(new BtInterestedMessage());
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createNotInterestedMessage()
|
||||
{
|
||||
BtNotInterestedMessageHandle msg(new BtNotInterestedMessage());
|
||||
BtNotInterestedMessage* msg(new BtNotInterestedMessage());
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createBitfieldMessage()
|
||||
{
|
||||
BtBitfieldMessageHandle msg
|
||||
BtBitfieldMessage* msg
|
||||
(new BtBitfieldMessage(pieceStorage_->getBitfield(),
|
||||
pieceStorage_->getBitfieldLength()));
|
||||
SharedHandle<BtMessageValidator> v
|
||||
(new BtBitfieldMessageValidator(msg.get(),
|
||||
downloadContext_->getNumPieces()));
|
||||
(new BtBitfieldMessageValidator(msg, downloadContext_->getNumPieces()));
|
||||
msg->setBtMessageValidator(v);
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createKeepAliveMessage()
|
||||
{
|
||||
BtKeepAliveMessageHandle msg(new BtKeepAliveMessage());
|
||||
BtKeepAliveMessage* msg(new BtKeepAliveMessage());
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
}
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createHaveAllMessage()
|
||||
{
|
||||
BtHaveAllMessageHandle msg(new BtHaveAllMessage());
|
||||
BtHaveAllMessage* msg(new BtHaveAllMessage());
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createHaveNoneMessage()
|
||||
{
|
||||
BtHaveNoneMessageHandle msg(new BtHaveNoneMessage());
|
||||
BtHaveNoneMessage* msg(new BtHaveNoneMessage());
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createRejectMessage
|
||||
(size_t index, int32_t begin, int32_t length)
|
||||
{
|
||||
BtRejectMessageHandle msg(new BtRejectMessage(index, begin, length));
|
||||
BtRejectMessage* msg(new BtRejectMessage(index, begin, length));
|
||||
SharedHandle<BtMessageValidator> validator
|
||||
(new RangeBtMessageValidator
|
||||
(msg.get(),
|
||||
(msg,
|
||||
downloadContext_->getNumPieces(),
|
||||
pieceStorage_->getPieceLength(index)));
|
||||
msg->setBtMessageValidator(validator);
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createAllowedFastMessage(size_t index)
|
||||
{
|
||||
BtAllowedFastMessageHandle msg(new BtAllowedFastMessage(index));
|
||||
BtAllowedFastMessage* msg(new BtAllowedFastMessage(index));
|
||||
SharedHandle<BtMessageValidator> validator
|
||||
(new IndexBtMessageValidator(msg.get(), downloadContext_->getNumPieces()));
|
||||
(new IndexBtMessageValidator(msg, downloadContext_->getNumPieces()));
|
||||
msg->setBtMessageValidator(validator);
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createPortMessage(uint16_t port)
|
||||
{
|
||||
SharedHandle<BtPortMessage> msg(new BtPortMessage(port));
|
||||
BtPortMessage* msg(new BtPortMessage(port));
|
||||
setCommonProperty(msg);
|
||||
return msg;
|
||||
return SharedHandle<BtMessage>(msg);
|
||||
}
|
||||
|
||||
BtMessageHandle
|
||||
SharedHandle<BtMessage>
|
||||
DefaultBtMessageFactory::createBtExtendedMessage
|
||||
(const ExtensionMessageHandle& msg)
|
||||
{
|
||||
BtExtendedMessageHandle m(new BtExtendedMessage(msg));
|
||||
BtExtendedMessage* m(new BtExtendedMessage(msg));
|
||||
setCommonProperty(m);
|
||||
return m;
|
||||
return SharedHandle<BtMessage>(m);
|
||||
}
|
||||
|
||||
void DefaultBtMessageFactory::setTaskQueue(DHTTaskQueue* taskQueue)
|
||||
|
@ -71,7 +71,7 @@ private:
|
||||
PeerConnection* peerConnection_;
|
||||
|
||||
SharedHandle<ExtensionMessageFactory> extensionMessageFactory_;
|
||||
|
||||
|
||||
DHTNode* localNode_;
|
||||
|
||||
DHTRoutingTable* routingTable_;
|
||||
@ -82,7 +82,7 @@ private:
|
||||
|
||||
bool metadataGetMode_;
|
||||
|
||||
void setCommonProperty(const SharedHandle<AbstractBtMessage>& msg);
|
||||
void setCommonProperty(AbstractBtMessage* msg);
|
||||
public:
|
||||
DefaultBtMessageFactory();
|
||||
|
||||
@ -112,7 +112,7 @@ public:
|
||||
virtual SharedHandle<BtMessage> createChokeMessage();
|
||||
|
||||
virtual SharedHandle<BtMessage> createUnchokeMessage();
|
||||
|
||||
|
||||
virtual SharedHandle<BtMessage> createInterestedMessage();
|
||||
|
||||
virtual SharedHandle<BtMessage> createNotInterestedMessage();
|
||||
@ -120,7 +120,7 @@ public:
|
||||
virtual SharedHandle<BtMessage> createBitfieldMessage();
|
||||
|
||||
virtual SharedHandle<BtMessage> createKeepAliveMessage();
|
||||
|
||||
|
||||
virtual SharedHandle<BtMessage> createHaveAllMessage();
|
||||
|
||||
virtual SharedHandle<BtMessage> createHaveNoneMessage();
|
||||
@ -154,7 +154,7 @@ public:
|
||||
|
||||
void setBtMessageDispatcher
|
||||
(BtMessageDispatcher* dispatcher);
|
||||
|
||||
|
||||
void setBtRequestFactory(BtRequestFactory* factory);
|
||||
|
||||
void setPeerConnection(PeerConnection* connection);
|
||||
@ -165,7 +165,7 @@ public:
|
||||
void setLocalNode(DHTNode* localNode);
|
||||
|
||||
void setRoutingTable(DHTRoutingTable* routingTable);
|
||||
|
||||
|
||||
void setTaskQueue(DHTTaskQueue* taskQueue);
|
||||
|
||||
void setTaskFactory(DHTTaskFactory* taskFactory);
|
||||
@ -176,8 +176,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef SharedHandle<DefaultBtMessageFactory> DefaultBtMessageFactoryHandle;
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // D_DEFAULT_BT_MESSAGE_FACTORY_H
|
||||
|
@ -47,11 +47,11 @@ private:
|
||||
static const size_t MESSAGE_LENGTH = 9;
|
||||
protected:
|
||||
template<typename T>
|
||||
static SharedHandle<T> create(const unsigned char* data, size_t dataLength)
|
||||
static T* create(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
bittorrent::assertPayloadLengthEqual(5, dataLength, T::NAME);
|
||||
bittorrent::assertID(T::ID, data, T::NAME);
|
||||
SharedHandle<T> message(new T());
|
||||
T* message(new T());
|
||||
message->setIndex(bittorrent::getIntParam(data, 1));
|
||||
return message;
|
||||
}
|
||||
|
@ -49,12 +49,11 @@ private:
|
||||
static const size_t MESSAGE_LENGTH = 17;
|
||||
protected:
|
||||
template<typename T>
|
||||
static SharedHandle<T> create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
static T* create(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
bittorrent::assertPayloadLengthEqual(13, dataLength, T::NAME);
|
||||
bittorrent::assertID(T::ID, data, T::NAME);
|
||||
SharedHandle<T> message(new T());
|
||||
T* message(new T());
|
||||
message->setIndex(bittorrent::getIntParam(data, 1));
|
||||
message->setBegin(bittorrent::getIntParam(data, 5));
|
||||
message->setLength(bittorrent::getIntParam(data, 9));
|
||||
|
@ -45,11 +45,11 @@ private:
|
||||
static const size_t MESSAGE_LENGTH = 5;
|
||||
protected:
|
||||
template<typename T>
|
||||
static SharedHandle<T> create(const unsigned char* data, size_t dataLength)
|
||||
static T* create(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
bittorrent::assertPayloadLengthEqual(1, dataLength, T::NAME);
|
||||
bittorrent::assertID(T::ID, data, T::NAME);
|
||||
SharedHandle<T> message(new T());
|
||||
T* message(new T());
|
||||
return message;
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,8 @@ void BtAllowedFastMessageTest::testCreate() {
|
||||
unsigned char msg[9];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 5, 17);
|
||||
bittorrent::setIntParam(&msg[5], 12345);
|
||||
SharedHandle<BtAllowedFastMessage> pm = BtAllowedFastMessage::create(&msg[4], 5);
|
||||
SharedHandle<BtAllowedFastMessage> pm
|
||||
(BtAllowedFastMessage::create(&msg[4], 5));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)17, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
|
||||
|
||||
|
@ -44,7 +44,7 @@ void BtBitfieldMessageTest::testCreate() {
|
||||
unsigned char bitfield[2];
|
||||
memset(bitfield, 0xff, sizeof(bitfield));
|
||||
memcpy(&msg[5], bitfield, sizeof(bitfield));
|
||||
SharedHandle<BtBitfieldMessage> pm = BtBitfieldMessage::create(&msg[4], 3);
|
||||
SharedHandle<BtBitfieldMessage> pm(BtBitfieldMessage::create(&msg[4], 3));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)5, pm->getId());
|
||||
CPPUNIT_ASSERT(memcmp(bitfield, pm->getBitfield(), sizeof(bitfield)) == 0);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, pm->getBitfieldLength());
|
||||
@ -89,7 +89,7 @@ void BtBitfieldMessageTest::testDoReceivedAction() {
|
||||
msg.setPieceStorage(pieceStorage);
|
||||
unsigned char bitfield[] = { 0xff, 0xff };
|
||||
msg.setBitfield(bitfield, sizeof(bitfield));
|
||||
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("0000"), util::toHex(peer->getBitfield(),
|
||||
peer->getBitfieldLength()));
|
||||
msg.doReceivedAction();
|
||||
|
@ -58,7 +58,7 @@ void BtCancelMessageTest::testCreate() {
|
||||
bittorrent::setIntParam(&msg[5], 12345);
|
||||
bittorrent::setIntParam(&msg[9], 256);
|
||||
bittorrent::setIntParam(&msg[13], 1024);
|
||||
SharedHandle<BtCancelMessage> pm = BtCancelMessage::create(&msg[4], 13);
|
||||
SharedHandle<BtCancelMessage> pm(BtCancelMessage::create(&msg[4], 13));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)8, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
|
||||
|
@ -71,7 +71,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtChokeMessageTest);
|
||||
void BtChokeMessageTest::testCreate() {
|
||||
unsigned char msg[5];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 0);
|
||||
SharedHandle<BtChokeMessage> pm = BtChokeMessage::create(&msg[4], 1);
|
||||
SharedHandle<BtChokeMessage> pm(BtChokeMessage::create(&msg[4], 1));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)0, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
|
@ -45,11 +45,11 @@ void BtExtendedMessageTest::testCreate() {
|
||||
bittorrent::createPeerMessageString((unsigned char*)msg, sizeof(msg), 13, 20);
|
||||
msg[5] = 1; // Set dummy extended message ID 1
|
||||
memcpy(msg+6, payload.c_str(), payload.size());
|
||||
SharedHandle<BtExtendedMessage> pm = BtExtendedMessage::create(exmsgFactory,
|
||||
peer,
|
||||
&msg[4], 13);
|
||||
SharedHandle<BtExtendedMessage> pm(BtExtendedMessage::create(exmsgFactory,
|
||||
peer,
|
||||
&msg[4], 13));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)20, pm->getId());
|
||||
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
unsigned char msg[5];
|
||||
|
@ -38,7 +38,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtHaveAllMessageTest);
|
||||
void BtHaveAllMessageTest::testCreate() {
|
||||
unsigned char msg[5];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 14);
|
||||
SharedHandle<BtHaveAllMessage> pm = BtHaveAllMessage::create(&msg[4], 1);
|
||||
SharedHandle<BtHaveAllMessage> pm(BtHaveAllMessage::create(&msg[4], 1));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)14, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
|
@ -41,7 +41,7 @@ void BtHaveMessageTest::testCreate() {
|
||||
unsigned char msg[9];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 5, 4);
|
||||
bittorrent::setIntParam(&msg[5], 12345);
|
||||
SharedHandle<BtHaveMessage> pm = BtHaveMessage::create(&msg[4], 5);
|
||||
SharedHandle<BtHaveMessage> pm(BtHaveMessage::create(&msg[4], 5));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)4, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
|
||||
|
||||
|
@ -35,7 +35,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtHaveNoneMessageTest);
|
||||
void BtHaveNoneMessageTest::testCreate() {
|
||||
unsigned char msg[5];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 15);
|
||||
SharedHandle<BtHaveNoneMessage> pm = BtHaveNoneMessage::create(&msg[4], 1);
|
||||
SharedHandle<BtHaveNoneMessage> pm(BtHaveNoneMessage::create(&msg[4], 1));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)15, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
|
@ -33,7 +33,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtInterestedMessageTest);
|
||||
void BtInterestedMessageTest::testCreate() {
|
||||
unsigned char msg[5];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 2);
|
||||
BtInterestedMessageHandle pm = BtInterestedMessage::create(&msg[4], 1);
|
||||
SharedHandle<BtInterestedMessage> pm
|
||||
(BtInterestedMessage::create(&msg[4], 1));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)2, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
|
@ -33,7 +33,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtNotInterestedMessageTest);
|
||||
void BtNotInterestedMessageTest::testCreate() {
|
||||
unsigned char msg[5];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 3);
|
||||
BtNotInterestedMessageHandle pm = BtNotInterestedMessage::create(&msg[4], 1);
|
||||
SharedHandle<BtNotInterestedMessage> pm
|
||||
(BtNotInterestedMessage::create(&msg[4], 1));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)3, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
|
@ -110,7 +110,7 @@ void BtPieceMessageTest::testCreate() {
|
||||
bittorrent::setIntParam(&msg[5], 12345);
|
||||
bittorrent::setIntParam(&msg[9], 256);
|
||||
memcpy(&msg[13], data, sizeof(data));
|
||||
SharedHandle<BtPieceMessage> pm = BtPieceMessage::create(&msg[4], 11);
|
||||
SharedHandle<BtPieceMessage> pm(BtPieceMessage::create(&msg[4], 11));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)7, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
|
||||
|
@ -62,7 +62,7 @@ void BtPortMessageTest::testCreate() {
|
||||
unsigned char msg[7];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 3, 9);
|
||||
bittorrent::setShortIntParam(&msg[5], 12345);
|
||||
SharedHandle<BtPortMessage> pm = BtPortMessage::create(&msg[4], 3);
|
||||
SharedHandle<BtPortMessage> pm(BtPortMessage::create(&msg[4], 3));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)9, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)12345, pm->getPort());
|
||||
|
||||
|
@ -90,7 +90,7 @@ void BtRejectMessageTest::testCreate() {
|
||||
bittorrent::setIntParam(&msg[5], 12345);
|
||||
bittorrent::setIntParam(&msg[9], 256);
|
||||
bittorrent::setIntParam(&msg[13], 1024);
|
||||
SharedHandle<BtRejectMessage> pm = BtRejectMessage::create(&msg[4], 13);
|
||||
SharedHandle<BtRejectMessage> pm(BtRejectMessage::create(&msg[4], 13));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)16, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
|
||||
|
@ -132,7 +132,7 @@ void BtRequestMessageTest::testCreate() {
|
||||
bittorrent::setIntParam(&msg[5], 12345);
|
||||
bittorrent::setIntParam(&msg[9], 256);
|
||||
bittorrent::setIntParam(&msg[13], 1024);
|
||||
SharedHandle<BtRequestMessage> pm = BtRequestMessage::create(&msg[4], 13);
|
||||
SharedHandle<BtRequestMessage> pm(BtRequestMessage::create(&msg[4], 13));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)6, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
|
||||
|
@ -32,7 +32,8 @@ void BtSuggestPieceMessageTest::testCreate() {
|
||||
unsigned char msg[9];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 5, 13);
|
||||
bittorrent::setIntParam(&msg[5], 12345);
|
||||
SharedHandle<BtSuggestPieceMessage> pm = BtSuggestPieceMessage::create(&msg[4], 5);
|
||||
SharedHandle<BtSuggestPieceMessage> pm
|
||||
(BtSuggestPieceMessage::create(&msg[4], 5));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)13, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
|
||||
|
||||
|
@ -33,7 +33,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BtUnchokeMessageTest);
|
||||
void BtUnchokeMessageTest::testCreate() {
|
||||
unsigned char msg[5];
|
||||
bittorrent::createPeerMessageString(msg, sizeof(msg), 1, 1);
|
||||
SharedHandle<BtUnchokeMessage> pm = BtUnchokeMessage::create(&msg[4], 1);
|
||||
SharedHandle<BtUnchokeMessage> pm(BtUnchokeMessage::create(&msg[4], 1));
|
||||
CPPUNIT_ASSERT_EQUAL((uint8_t)1, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
|
Loading…
Reference in New Issue
Block a user