2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Made protected member variable private. Added accessor funcs.
	* src/AbstractBtMessage.cc
	* src/AbstractBtMessage.h
	* src/BtAllowedFastMessage.cc
	* src/BtAllowedFastMessage.h
	* src/BtBitfieldMessage.cc
	* src/BtBitfieldMessage.h
	* src/BtCancelMessage.cc
	* src/BtCancelMessage.h
	* src/BtChokeMessage.cc
	* src/BtChokeMessage.h
	* src/BtExtendedMessage.cc
	* src/BtHaveAllMessage.cc
	* src/BtHaveAllMessage.h
	* src/BtHaveMessage.cc
	* src/BtHaveMessage.h
	* src/BtHaveNoneMessage.cc
	* src/BtHaveNoneMessage.h
	* src/BtInterestedMessage.cc
	* src/BtInterestedMessage.h
	* src/BtNotInterestedMessage.cc
	* src/BtNotInterestedMessage.h
	* src/BtPieceMessage.cc
	* src/BtPieceMessage.h
	* src/BtPortMessage.cc
	* src/BtPortMessage.h
	* src/BtRejectMessage.cc
	* src/BtRejectMessage.h
	* src/BtRequestMessage.cc
	* src/BtRequestMessage.h
	* src/BtUnchokeMessage.cc
	* src/BtUnchokeMessage.h
	* src/SimpleBtMessage.cc
	* src/SimpleBtMessage.h
pull/1/head
Tatsuhiro Tsujikawa 2010-06-11 11:48:22 +00:00
parent a68b29a31a
commit 812563bb6d
34 changed files with 440 additions and 304 deletions

View File

@ -1,3 +1,40 @@
2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Made protected member variable private. Added accessor funcs.
* src/AbstractBtMessage.cc
* src/AbstractBtMessage.h
* src/BtAllowedFastMessage.cc
* src/BtAllowedFastMessage.h
* src/BtBitfieldMessage.cc
* src/BtBitfieldMessage.h
* src/BtCancelMessage.cc
* src/BtCancelMessage.h
* src/BtChokeMessage.cc
* src/BtChokeMessage.h
* src/BtExtendedMessage.cc
* src/BtHaveAllMessage.cc
* src/BtHaveAllMessage.h
* src/BtHaveMessage.cc
* src/BtHaveMessage.h
* src/BtHaveNoneMessage.cc
* src/BtHaveNoneMessage.h
* src/BtInterestedMessage.cc
* src/BtInterestedMessage.h
* src/BtNotInterestedMessage.cc
* src/BtNotInterestedMessage.h
* src/BtPieceMessage.cc
* src/BtPieceMessage.h
* src/BtPortMessage.cc
* src/BtPortMessage.h
* src/BtRejectMessage.cc
* src/BtRejectMessage.h
* src/BtRequestMessage.cc
* src/BtRequestMessage.h
* src/BtUnchokeMessage.cc
* src/BtUnchokeMessage.h
* src/SimpleBtMessage.cc
* src/SimpleBtMessage.h
2010-06-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Made protected member variable private. Added accessor funcs.

View File

@ -43,57 +43,59 @@ namespace aria2 {
AbstractBtMessage::AbstractBtMessage(uint8_t id, const std::string& name):
BtMessage(id),
sendingInProgress(false),
invalidate(false),
uploading(false),
cuid(0),
_sendingInProgress(false),
_invalidate(false),
_uploading(false),
_cuid(0),
_name(name),
_metadataGetMode(false),
logger(LogFactory::getInstance())
_logger(LogFactory::getInstance())
{}
AbstractBtMessage::~AbstractBtMessage() {}
void AbstractBtMessage::setPeer(const SharedHandle<Peer>& peer)
{
this->peer = peer;
_peer = peer;
}
void AbstractBtMessage::validate()
{
if(validator.get()) {
validator->validate();
if(!_validator.isNull()) {
_validator->validate();
}
}
void
AbstractBtMessage::setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator) {
this->validator = validator;
_validator = validator;
}
void AbstractBtMessage::setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage)
void AbstractBtMessage::setPieceStorage
(const SharedHandle<PieceStorage>& pieceStorage)
{
this->pieceStorage = pieceStorage;
_pieceStorage = pieceStorage;
}
void AbstractBtMessage::setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dispatcher)
void AbstractBtMessage::setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher)
{
this->dispatcher = dispatcher;
_dispatcher = dispatcher;
}
void AbstractBtMessage::setPeerConnection(const WeakHandle<PeerConnection>& peerConnection)
{
this->peerConnection = peerConnection;
_peerConnection = peerConnection;
}
void AbstractBtMessage::setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory)
{
this->messageFactory = factory;
_messageFactory = factory;
}
void AbstractBtMessage::setBtRequestFactory(const WeakHandle<BtRequestFactory>& factory)
{
this->requestFactory = factory;
_requestFactory = factory;
}
} // namespace aria2

View File

@ -50,71 +50,106 @@ class BtMessageValidator;
class Logger;
class AbstractBtMessage : public BtMessage {
protected:
bool sendingInProgress;
bool invalidate;
bool uploading;
cuid_t cuid;
private:
bool _sendingInProgress;
bool _invalidate;
bool _uploading;
cuid_t _cuid;
std::string _name;
SharedHandle<PieceStorage> pieceStorage;
SharedHandle<PieceStorage> _pieceStorage;
SharedHandle<Peer> peer;
SharedHandle<Peer> _peer;
WeakHandle<BtMessageDispatcher> dispatcher;
WeakHandle<BtMessageDispatcher> _dispatcher;
WeakHandle<BtMessageFactory> messageFactory;
WeakHandle<BtMessageFactory> _messageFactory;
WeakHandle<BtRequestFactory> requestFactory;
WeakHandle<BtRequestFactory> _requestFactory;
WeakHandle<PeerConnection> peerConnection;
WeakHandle<PeerConnection> _peerConnection;
SharedHandle<BtMessageValidator> validator;
SharedHandle<BtMessageValidator> _validator;
bool _metadataGetMode;
Logger* logger;
Logger* _logger;
protected:
Logger* getLogger() const
{
return _logger;
}
const SharedHandle<PieceStorage>& getPieceStorage() const
{
return _pieceStorage;
}
const WeakHandle<PeerConnection>& getPeerConnection() const
{
return _peerConnection;
}
const WeakHandle<BtMessageDispatcher>& getBtMessageDispatcher() const
{
return _dispatcher;
}
const WeakHandle<BtRequestFactory>& getBtRequestFactory() const
{
return _requestFactory;
}
const WeakHandle<BtMessageFactory>& getBtMessageFactory() const
{
return _messageFactory;
}
bool isMetadataGetMode() const
{
return _metadataGetMode;
}
public:
AbstractBtMessage(uint8_t id, const std::string& name);
virtual ~AbstractBtMessage();
virtual bool isSendingInProgress() {
return sendingInProgress;
return _sendingInProgress;
}
void setSendingInProgress(bool sendingInProgress) {
this->sendingInProgress = sendingInProgress;
_sendingInProgress = sendingInProgress;
}
virtual bool isInvalidate() {
return invalidate;
return _invalidate;
}
void setInvalidate(bool invalidate) {
this->invalidate = invalidate;
_invalidate = invalidate;
}
virtual bool isUploading() {
return uploading;
return _uploading;
}
void setUploading(bool uploading) {
this->uploading = uploading;
_uploading = uploading;
}
cuid_t getCuid() const {
return cuid;
return _cuid;
}
void setCuid(cuid_t cuid) {
this->cuid = cuid;
_cuid = cuid;
}
const SharedHandle<Peer>& getPeer() const
{
return peer;
return _peer;
}
void setPeer(const SharedHandle<Peer>& peer);
@ -137,7 +172,8 @@ public:
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dispatcher);
void setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher);
void setPeerConnection(const WeakHandle<PeerConnection>& peerConnection);

View File

@ -41,6 +41,9 @@ namespace aria2 {
const std::string BtAllowedFastMessage::NAME("allowed fast");
BtAllowedFastMessage::BtAllowedFastMessage(size_t index):
IndexBtMessage(ID, NAME, index) {}
SharedHandle<BtAllowedFastMessage> BtAllowedFastMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -48,19 +51,19 @@ SharedHandle<BtAllowedFastMessage> BtAllowedFastMessage::create
}
void BtAllowedFastMessage::doReceivedAction() {
if(!peer->isFastExtensionEnabled()) {
if(!getPeer()->isFastExtensionEnabled()) {
throw DL_ABORT_EX
(StringFormat("%s received while fast extension is disabled",
toString().c_str()).str());
}
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
peer->addPeerAllowedIndex(getIndex());
getPeer()->addPeerAllowedIndex(getIndex());
}
void BtAllowedFastMessage::onSendComplete() {
peer->addAmAllowedIndex(getIndex());
getPeer()->addAmAllowedIndex(getIndex());
}
} // namespace aria2

View File

@ -45,8 +45,7 @@ typedef SharedHandle<BtAllowedFastMessage> BtAllowedFastMessageHandle;
class BtAllowedFastMessage : public IndexBtMessage {
public:
BtAllowedFastMessage(size_t index = 0)
:IndexBtMessage(ID, NAME, index) {}
BtAllowedFastMessage(size_t index = 0);
static const uint8_t ID = 17;

View File

@ -49,15 +49,34 @@ namespace aria2 {
const std::string BtBitfieldMessage::NAME("bitfield");
void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, size_t bitfieldLength) {
if(this->bitfield == bitfield) {
BtBitfieldMessage::BtBitfieldMessage():SimpleBtMessage(ID, NAME),
_bitfield(0),
_bitfieldLength(0)
{}
BtBitfieldMessage::BtBitfieldMessage
(const unsigned char* bitfield, size_t bitfieldLength):
SimpleBtMessage(ID, NAME),
_bitfield(0),
_bitfieldLength(0)
{
setBitfield(bitfield, bitfieldLength);
}
BtBitfieldMessage::~BtBitfieldMessage()
{
delete [] _bitfield;
}
void BtBitfieldMessage::setBitfield
(const unsigned char* bitfield, size_t bitfieldLength) {
if(_bitfield == bitfield) {
return;
}
delete [] this->bitfield;
this->bitfieldLength = bitfieldLength;
this->bitfield = new unsigned char[this->bitfieldLength];
memcpy(this->bitfield, bitfield, this->bitfieldLength);
delete [] _bitfield;
_bitfieldLength = bitfieldLength;
_bitfield = new unsigned char[_bitfieldLength];
memcpy(_bitfield, bitfield, _bitfieldLength);
}
BtBitfieldMessageHandle
@ -71,12 +90,13 @@ BtBitfieldMessage::create(const unsigned char* data, size_t dataLength)
}
void BtBitfieldMessage::doReceivedAction() {
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
pieceStorage->updatePieceStats(bitfield, bitfieldLength, peer->getBitfield());
peer->setBitfield(bitfield, bitfieldLength);
if(peer->isSeeder() && pieceStorage->downloadFinished()) {
getPieceStorage()->updatePieceStats(_bitfield, _bitfieldLength,
getPeer()->getBitfield());
getPeer()->setBitfield(_bitfield, _bitfieldLength);
if(getPeer()->isSeeder() && getPieceStorage()->downloadFinished()) {
throw DL_ABORT_EX(MSG_GOOD_BYE_SEEDER);
}
}
@ -88,19 +108,19 @@ unsigned char* BtBitfieldMessage::createMessage() {
* bitfield --- bitfield, len bytes
* total: 5+len bytes
*/
const size_t msgLength = 5+bitfieldLength;
const size_t msgLength = 5+_bitfieldLength;
unsigned char* msg = new unsigned char[msgLength];
bittorrent::createPeerMessageString(msg, msgLength, 1+bitfieldLength, ID);
memcpy(msg+5, bitfield, bitfieldLength);
bittorrent::createPeerMessageString(msg, msgLength, 1+_bitfieldLength, ID);
memcpy(msg+5, _bitfield, _bitfieldLength);
return msg;
}
size_t BtBitfieldMessage::getMessageLength() {
return 5+bitfieldLength;
return 5+_bitfieldLength;
}
std::string BtBitfieldMessage::toString() const {
return strconcat(NAME, " ", util::toHex(bitfield, bitfieldLength));
return strconcat(NAME, " ", util::toHex(_bitfield, _bitfieldLength));
}
} // namespace aria2

View File

@ -45,29 +45,14 @@ typedef SharedHandle<BtBitfieldMessage> BtBitfieldMessageHandle;
class BtBitfieldMessage : public SimpleBtMessage {
private:
unsigned char* bitfield;
size_t bitfieldLength;
void init() {
bitfield = 0;
bitfieldLength = 0;
}
unsigned char* _bitfield;
size_t _bitfieldLength;
public:
BtBitfieldMessage():SimpleBtMessage(ID, NAME)
{
init();
}
BtBitfieldMessage();
BtBitfieldMessage(const unsigned char* bitfield,
size_t bitfieldLength):SimpleBtMessage(ID, NAME)
{
init();
setBitfield(bitfield, bitfieldLength);
}
BtBitfieldMessage(const unsigned char* bitfield, size_t bitfieldLength);
virtual ~BtBitfieldMessage() {
delete [] bitfield;
}
virtual ~BtBitfieldMessage();
static const uint8_t ID = 5;
@ -75,11 +60,12 @@ public:
void setBitfield(const unsigned char* bitfield, size_t bitfieldLength);
const unsigned char* getBitfield() const { return bitfield; }
const unsigned char* getBitfield() const { return _bitfield; }
size_t getBitfieldLength() const { return bitfieldLength; }
size_t getBitfieldLength() const { return _bitfieldLength; }
static BtBitfieldMessageHandle create(const unsigned char* data, size_t dataLength);
static BtBitfieldMessageHandle create
(const unsigned char* data, size_t dataLength);
virtual void doReceivedAction();

View File

@ -39,6 +39,10 @@ namespace aria2 {
const std::string BtCancelMessage::NAME("cancel");
BtCancelMessage::BtCancelMessage
(size_t index, uint32_t begin, size_t length)
:RangeBtMessage(ID, NAME, index, begin, length) {}
SharedHandle<BtCancelMessage> BtCancelMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -47,10 +51,11 @@ SharedHandle<BtCancelMessage> BtCancelMessage::create
void BtCancelMessage::doReceivedAction()
{
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
dispatcher->doCancelSendingPieceAction(getIndex(), getBegin(), getLength());
getBtMessageDispatcher()->doCancelSendingPieceAction
(getIndex(), getBegin(), getLength());
}
} // namespace aria2

View File

@ -45,14 +45,14 @@ typedef SharedHandle<BtCancelMessage> BtCancelMessageHandle;
class BtCancelMessage : public RangeBtMessage {
public:
BtCancelMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0)
:RangeBtMessage(ID, NAME, index, begin, length) {}
BtCancelMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0);
static const int8_t ID = 8;
static const std::string NAME;
static BtCancelMessageHandle create(const unsigned char* data, size_t dataLength);
static BtCancelMessageHandle create
(const unsigned char* data, size_t dataLength);
virtual void doReceivedAction();
};

View File

@ -41,6 +41,8 @@ namespace aria2 {
const std::string BtChokeMessage::NAME("choke");
BtChokeMessage::BtChokeMessage():ZeroBtMessage(ID, NAME) {}
SharedHandle<BtChokeMessage> BtChokeMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -49,23 +51,23 @@ SharedHandle<BtChokeMessage> BtChokeMessage::create
void BtChokeMessage::doReceivedAction()
{
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
peer->peerChoking(true);
dispatcher->doChokedAction();
requestFactory->doChokedAction();
getPeer()->peerChoking(true);
getBtMessageDispatcher()->doChokedAction();
getBtRequestFactory()->doChokedAction();
}
bool BtChokeMessage::sendPredicate() const
{
return !peer->amChoking();
return !getPeer()->amChoking();
}
void BtChokeMessage::onSendComplete()
{
peer->amChoking(true);
dispatcher->doChokingAction();
getPeer()->amChoking(true);
getBtMessageDispatcher()->doChokingAction();
}
} // namespace aria2

View File

@ -45,7 +45,7 @@ typedef SharedHandle<BtChokeMessage> BtChokeMessageHandle;
class BtChokeMessage : public ZeroBtMessage {
public:
BtChokeMessage():ZeroBtMessage(ID, NAME) {}
BtChokeMessage();
static const uint8_t ID = 0;

View File

@ -85,7 +85,7 @@ size_t BtExtendedMessage::getMessageLength() {
bool BtExtendedMessage::sendPredicate() const
{
return peer->isExtendedMessagingEnabled();
return getPeer()->isExtendedMessagingEnabled();
}
std::string BtExtendedMessage::toString() const {

View File

@ -43,6 +43,8 @@ namespace aria2 {
const std::string BtHaveAllMessage::NAME("have all");
BtHaveAllMessage::BtHaveAllMessage():ZeroBtMessage(ID, NAME) {}
SharedHandle<BtHaveAllMessage> BtHaveAllMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -51,19 +53,20 @@ SharedHandle<BtHaveAllMessage> BtHaveAllMessage::create
void BtHaveAllMessage::doReceivedAction()
{
if(!peer->isFastExtensionEnabled()) {
if(!getPeer()->isFastExtensionEnabled()) {
throw DL_ABORT_EX
(StringFormat("%s received while fast extension is disabled",
toString().c_str()).str());
}
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
pieceStorage->subtractPieceStats(peer->getBitfield(),
peer->getBitfieldLength());
peer->setAllBitfield();
pieceStorage->addPieceStats(peer->getBitfield(), peer->getBitfieldLength());
if(peer->isSeeder() && pieceStorage->downloadFinished()) {
getPieceStorage()->subtractPieceStats(getPeer()->getBitfield(),
getPeer()->getBitfieldLength());
getPeer()->setAllBitfield();
getPieceStorage()->addPieceStats
(getPeer()->getBitfield(), getPeer()->getBitfieldLength());
if(getPeer()->isSeeder() && getPieceStorage()->downloadFinished()) {
throw DL_ABORT_EX(MSG_GOOD_BYE_SEEDER);
}
}

View File

@ -45,7 +45,7 @@ typedef SharedHandle<BtHaveAllMessage> BtHaveAllMessageHandle;
class BtHaveAllMessage : public ZeroBtMessage {
public:
BtHaveAllMessage():ZeroBtMessage(ID, NAME) {}
BtHaveAllMessage();
static const uint8_t ID = 14;

View File

@ -42,6 +42,8 @@ namespace aria2 {
const std::string BtHaveMessage::NAME("have");
BtHaveMessage::BtHaveMessage(size_t index):IndexBtMessage(ID, NAME, index) {}
SharedHandle<BtHaveMessage> BtHaveMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -50,12 +52,12 @@ SharedHandle<BtHaveMessage> BtHaveMessage::create
void BtHaveMessage::doReceivedAction()
{
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
peer->updateBitfield(getIndex(), 1);
pieceStorage->addPieceStats(getIndex());
if(peer->isSeeder() && pieceStorage->downloadFinished()) {
getPeer()->updateBitfield(getIndex(), 1);
getPieceStorage()->addPieceStats(getIndex());
if(getPeer()->isSeeder() && getPieceStorage()->downloadFinished()) {
throw DL_ABORT_EX(MSG_GOOD_BYE_SEEDER);
}
}

View File

@ -45,7 +45,7 @@ typedef SharedHandle<BtHaveMessage> BtHaveMessageHandle;
class BtHaveMessage : public IndexBtMessage {
public:
BtHaveMessage(size_t index = 0):IndexBtMessage(ID, NAME, index) {}
BtHaveMessage(size_t index = 0);
static const uint8_t ID = 4;

View File

@ -41,6 +41,8 @@ namespace aria2 {
const std::string BtHaveNoneMessage::NAME("have none");
BtHaveNoneMessage::BtHaveNoneMessage():ZeroBtMessage(ID, NAME) {}
SharedHandle<BtHaveNoneMessage> BtHaveNoneMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -49,7 +51,7 @@ SharedHandle<BtHaveNoneMessage> BtHaveNoneMessage::create
void BtHaveNoneMessage::doReceivedAction()
{
if(!peer->isFastExtensionEnabled()) {
if(!getPeer()->isFastExtensionEnabled()) {
throw DL_ABORT_EX
(StringFormat("%s received while fast extension is disabled",
toString().c_str()).str());

View File

@ -45,7 +45,8 @@ typedef SharedHandle<BtHaveNoneMessage> BtHaveNoneMessageHandle;
class BtHaveNoneMessage : public ZeroBtMessage {
public:
BtHaveNoneMessage():ZeroBtMessage(ID, NAME) {}
BtHaveNoneMessage();
static const uint8_t ID = 15;
static const std::string NAME;

View File

@ -40,6 +40,8 @@ namespace aria2 {
const std::string BtInterestedMessage::NAME("interested");
BtInterestedMessage::BtInterestedMessage():ZeroBtMessage(ID, NAME) {}
SharedHandle<BtInterestedMessage> BtInterestedMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -48,22 +50,22 @@ SharedHandle<BtInterestedMessage> BtInterestedMessage::create
void BtInterestedMessage::doReceivedAction()
{
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
peer->peerInterested(true);
if(!peer->amChoking()) {
getPeer()->peerInterested(true);
if(!getPeer()->amChoking()) {
_peerStorage->executeChoke();
}
}
bool BtInterestedMessage::sendPredicate() const
{
return !peer->amInterested();
return !getPeer()->amInterested();
}
void BtInterestedMessage::onSendComplete() {
peer->amInterested(true);
getPeer()->amInterested(true);
}
void BtInterestedMessage::setPeerStorage

View File

@ -48,7 +48,7 @@ class BtInterestedMessage : public ZeroBtMessage {
private:
SharedHandle<PeerStorage> _peerStorage;
public:
BtInterestedMessage():ZeroBtMessage(ID, NAME) {}
BtInterestedMessage();
static const uint8_t ID = 2;

View File

@ -40,6 +40,8 @@ namespace aria2 {
const std::string BtNotInterestedMessage::NAME("not interested");
BtNotInterestedMessage::BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {}
SharedHandle<BtNotInterestedMessage> BtNotInterestedMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -48,22 +50,22 @@ SharedHandle<BtNotInterestedMessage> BtNotInterestedMessage::create
void BtNotInterestedMessage::doReceivedAction()
{
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
peer->peerInterested(false);
if(!peer->amChoking()) {
getPeer()->peerInterested(false);
if(!getPeer()->amChoking()) {
_peerStorage->executeChoke();
}
}
bool BtNotInterestedMessage::sendPredicate() const
{
return peer->amInterested();
return getPeer()->amInterested();
}
void BtNotInterestedMessage::onSendComplete() {
peer->amInterested(false);
getPeer()->amInterested(false);
}
void BtNotInterestedMessage::setPeerStorage

View File

@ -48,7 +48,7 @@ class BtNotInterestedMessage : public ZeroBtMessage {
private:
SharedHandle<PeerStorage> _peerStorage;
public:
BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {}
BtNotInterestedMessage();
static const uint8_t ID = 3;

View File

@ -59,14 +59,33 @@ namespace aria2 {
const std::string BtPieceMessage::NAME("piece");
BtPieceMessage::BtPieceMessage
(size_t index, uint32_t begin, size_t blockLength):
AbstractBtMessage(ID, NAME),
_index(index),
_begin(begin),
_blockLength(blockLength),
_block(0),
_rawData(0)
{
setUploading(true);
}
BtPieceMessage::~BtPieceMessage()
{
delete [] _rawData;
}
void BtPieceMessage::setRawMessage(unsigned char* data)
{
delete [] _rawData;
_rawData = data;
this->block = data+9;
_block = data+9;
}
BtPieceMessageHandle BtPieceMessage::create(const unsigned char* data, size_t dataLength) {
BtPieceMessageHandle BtPieceMessage::create
(const unsigned char* data, size_t dataLength)
{
bittorrent::assertPayloadLengthGreater(9, dataLength, NAME);
bittorrent::assertID(ID, data, NAME);
BtPieceMessageHandle message(new BtPieceMessage());
@ -76,32 +95,34 @@ BtPieceMessageHandle BtPieceMessage::create(const unsigned char* data, size_t da
return message;
}
void BtPieceMessage::doReceivedAction() {
if(_metadataGetMode) {
void BtPieceMessage::doReceivedAction()
{
if(isMetadataGetMode()) {
return;
}
RequestSlot slot = dispatcher->getOutstandingRequest(index,
begin,
blockLength);
peer->updateDownloadLength(blockLength);
RequestSlot slot = getBtMessageDispatcher()->getOutstandingRequest
(_index, _begin, _blockLength);
getPeer()->updateDownloadLength(_blockLength);
if(!RequestSlot::isNull(slot)) {
peer->snubbing(false);
SharedHandle<Piece> piece = pieceStorage->getPiece(index);
off_t offset = (off_t)index*_downloadContext->getPieceLength()+begin;
if(logger->debug()) {
logger->debug(MSG_PIECE_RECEIVED,
util::itos(cuid).c_str(), index, begin, blockLength, offset,
slot.getBlockIndex());
getPeer()->snubbing(false);
SharedHandle<Piece> piece = getPieceStorage()->getPiece(_index);
off_t offset = (off_t)_index*_downloadContext->getPieceLength()+_begin;
if(getLogger()->debug()) {
getLogger()->debug(MSG_PIECE_RECEIVED,
util::itos(getCuid()).c_str(),
_index, _begin, _blockLength, offset,
slot.getBlockIndex());
}
pieceStorage->getDiskAdaptor()->writeData(block, blockLength, offset);
getPieceStorage()->getDiskAdaptor()->writeData
(_block, _blockLength, offset);
piece->completeBlock(slot.getBlockIndex());
if(logger->debug()) {
logger->debug(MSG_PIECE_BITFIELD, util::itos(cuid).c_str(),
util::toHex(piece->getBitfield(),
piece->getBitfieldLength()).c_str());
if(getLogger()->debug()) {
getLogger()->debug(MSG_PIECE_BITFIELD, util::itos(getCuid()).c_str(),
util::toHex(piece->getBitfield(),
piece->getBitfieldLength()).c_str());
}
piece->updateHash(begin, block, blockLength);
dispatcher->removeOutstandingRequest(slot);
piece->updateHash(_begin, _block, _blockLength);
getBtMessageDispatcher()->removeOutstandingRequest(slot);
if(piece->pieceComplete()) {
if(checkPieceHash(piece)) {
onNewPiece(piece);
@ -110,9 +131,9 @@ void BtPieceMessage::doReceivedAction() {
}
}
} else {
if(logger->debug()) {
logger->debug("CUID#%s - RequestSlot not found, index=%d, begin=%d",
util::itos(cuid).c_str(), index, begin);
if(getLogger()->debug()) {
getLogger()->debug("CUID#%s - RequestSlot not found, index=%d, begin=%d",
util::itos(getCuid()).c_str(), _index, _begin);
}
}
}
@ -130,156 +151,169 @@ unsigned char* BtPieceMessage::createMessageHeader()
*/
unsigned char* msgHeader = new unsigned char[MESSAGE_HEADER_LENGTH];
bittorrent::createPeerMessageString(msgHeader, MESSAGE_HEADER_LENGTH,
9+blockLength, ID);
bittorrent::setIntParam(&msgHeader[5], index);
bittorrent::setIntParam(&msgHeader[9], begin);
9+_blockLength, ID);
bittorrent::setIntParam(&msgHeader[5], _index);
bittorrent::setIntParam(&msgHeader[9], _begin);
return msgHeader;
}
size_t BtPieceMessage::getMessageHeaderLength() {
size_t BtPieceMessage::getMessageHeaderLength()
{
return MESSAGE_HEADER_LENGTH;
}
void BtPieceMessage::send() {
if(invalidate) {
void BtPieceMessage::send()
{
if(isInvalidate()) {
return;
}
size_t writtenLength;
if(!sendingInProgress) {
if(logger->info()) {
logger->info(MSG_SEND_PEER_MESSAGE,
util::itos(cuid).c_str(), peer->ipaddr.c_str(), peer->port,
toString().c_str());
if(!isSendingInProgress()) {
if(getLogger()->info()) {
getLogger()->info(MSG_SEND_PEER_MESSAGE,
util::itos(getCuid()).c_str(),
getPeer()->ipaddr.c_str(), getPeer()->port,
toString().c_str());
}
unsigned char* msgHdr = createMessageHeader();
size_t msgHdrLen = getMessageHeaderLength();
if(logger->debug()) {
logger->debug("msglength = %lu bytes",
static_cast<unsigned long>(msgHdrLen+blockLength));
if(getLogger()->debug()) {
getLogger()->debug("msglength = %lu bytes",
static_cast<unsigned long>(msgHdrLen+_blockLength));
}
peerConnection->pushBytes(msgHdr, msgHdrLen);
peerConnection->sendPendingData();
getPeerConnection()->pushBytes(msgHdr, msgHdrLen);
getPeerConnection()->sendPendingData();
off_t pieceDataOffset =
(off_t)index*_downloadContext->getPieceLength()+begin;
writtenLength = sendPieceData(pieceDataOffset, blockLength);
(off_t)_index*_downloadContext->getPieceLength()+_begin;
writtenLength = sendPieceData(pieceDataOffset, _blockLength);
} else {
writtenLength = peerConnection->sendPendingData();
writtenLength = getPeerConnection()->sendPendingData();
}
peer->updateUploadLength(writtenLength);
sendingInProgress = !peerConnection->sendBufferIsEmpty();
getPeer()->updateUploadLength(writtenLength);
setSendingInProgress(!getPeerConnection()->sendBufferIsEmpty());
}
size_t BtPieceMessage::sendPieceData(off_t offset, size_t length) const {
size_t BtPieceMessage::sendPieceData(off_t offset, size_t length) const
{
assert(length <= 16*1024);
unsigned char* buf = new unsigned char[length];
ssize_t r;
try {
r = pieceStorage->getDiskAdaptor()->readData(buf, length, offset);
r = getPieceStorage()->getDiskAdaptor()->readData(buf, length, offset);
} catch(RecoverableException& e) {
delete [] buf;
throw;
}
if(r == static_cast<ssize_t>(length)) {
peerConnection->pushBytes(buf, length);
return peerConnection->sendPendingData();
getPeerConnection()->pushBytes(buf, length);
return getPeerConnection()->sendPendingData();
} else {
throw DL_ABORT_EX(EX_DATA_READ);
}
}
std::string BtPieceMessage::toString() const {
return strconcat(NAME, " index=", util::itos(index), ", begin=",
util::itos(begin), ", length=", util::itos(blockLength));
std::string BtPieceMessage::toString() const
{
return strconcat(NAME, " index=", util::itos(_index), ", begin=",
util::itos(_begin), ", length=", util::itos(_blockLength));
}
bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece) {
bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
{
if(piece->isHashCalculated()) {
if(logger->debug()) {
logger->debug("Hash is available!! index=%lu",
static_cast<unsigned long>(piece->getIndex()));
if(getLogger()->debug()) {
getLogger()->debug("Hash is available!! index=%lu",
static_cast<unsigned long>(piece->getIndex()));
}
return
piece->getHashString()==_downloadContext->getPieceHash(piece->getIndex());
} else {
off_t offset = (off_t)piece->getIndex()*_downloadContext->getPieceLength();
return MessageDigestHelper::staticSHA1Digest(pieceStorage->getDiskAdaptor(), offset, piece->getLength())
return MessageDigestHelper::staticSHA1Digest
(getPieceStorage()->getDiskAdaptor(), offset, piece->getLength())
== _downloadContext->getPieceHash(piece->getIndex());
}
}
void BtPieceMessage::onNewPiece(const SharedHandle<Piece>& piece) {
if(logger->info()) {
logger->info(MSG_GOT_NEW_PIECE, util::itos(cuid).c_str(),piece->getIndex());
void BtPieceMessage::onNewPiece(const SharedHandle<Piece>& piece)
{
if(getLogger()->info()) {
getLogger()->info(MSG_GOT_NEW_PIECE,
util::itos(getCuid()).c_str(), piece->getIndex());
}
pieceStorage->completePiece(piece);
pieceStorage->advertisePiece(cuid, piece->getIndex());
getPieceStorage()->completePiece(piece);
getPieceStorage()->advertisePiece(getCuid(), piece->getIndex());
}
void BtPieceMessage::onWrongPiece(const SharedHandle<Piece>& piece) {
if(logger->info()) {
logger->info(MSG_GOT_WRONG_PIECE,
util::itos(cuid).c_str(), piece->getIndex());
void BtPieceMessage::onWrongPiece(const SharedHandle<Piece>& piece)
{
if(getLogger()->info()) {
getLogger()->info(MSG_GOT_WRONG_PIECE,
util::itos(getCuid()).c_str(), piece->getIndex());
}
erasePieceOnDisk(piece);
piece->clearAllBlock();
piece->destroyHashContext();
requestFactory->removeTargetPiece(piece);
getBtRequestFactory()->removeTargetPiece(piece);
}
void BtPieceMessage::erasePieceOnDisk(const SharedHandle<Piece>& piece) {
void BtPieceMessage::erasePieceOnDisk(const SharedHandle<Piece>& piece)
{
size_t BUFSIZE = 4096;
unsigned char buf[BUFSIZE];
memset(buf, 0, BUFSIZE);
off_t offset = (off_t)piece->getIndex()*_downloadContext->getPieceLength();
div_t res = div(piece->getLength(), BUFSIZE);
for(int i = 0; i < res.quot; ++i) {
pieceStorage->getDiskAdaptor()->writeData(buf, BUFSIZE, offset);
getPieceStorage()->getDiskAdaptor()->writeData(buf, BUFSIZE, offset);
offset += BUFSIZE;
}
if(res.rem > 0) {
pieceStorage->getDiskAdaptor()->writeData(buf, res.rem, offset);
getPieceStorage()->getDiskAdaptor()->writeData(buf, res.rem, offset);
}
}
void BtPieceMessage::onChokingEvent(const BtChokingEvent& event)
{
if(!invalidate &&
!sendingInProgress &&
!peer->isInAmAllowedIndexSet(index)) {
if(logger->debug()) {
logger->debug(MSG_REJECT_PIECE_CHOKED,
util::itos(cuid).c_str(), index, begin, blockLength);
if(!isInvalidate() &&
!isSendingInProgress() &&
!getPeer()->isInAmAllowedIndexSet(_index)) {
if(getLogger()->debug()) {
getLogger()->debug(MSG_REJECT_PIECE_CHOKED,
util::itos(getCuid()).c_str(),
_index, _begin, _blockLength);
}
if(peer->isFastExtensionEnabled()) {
BtMessageHandle rej = messageFactory->createRejectMessage(index,
begin,
blockLength);
dispatcher->addMessageToQueue(rej);
if(getPeer()->isFastExtensionEnabled()) {
BtMessageHandle rej =
getBtMessageFactory()->createRejectMessage
(_index, _begin, _blockLength);
getBtMessageDispatcher()->addMessageToQueue(rej);
}
invalidate = true;
setInvalidate(true);
}
}
void BtPieceMessage::onCancelSendingPieceEvent
(const BtCancelSendingPieceEvent& event)
{
if(!invalidate &&
!sendingInProgress &&
index == event.getIndex() &&
begin == event.getBegin() &&
blockLength == event.getLength()) {
if(logger->debug()) {
logger->debug(MSG_REJECT_PIECE_CANCEL,
util::itos(cuid).c_str(), index, begin, blockLength);
if(!isInvalidate() &&
!isSendingInProgress() &&
_index == event.getIndex() &&
_begin == event.getBegin() &&
_blockLength == event.getLength()) {
if(getLogger()->debug()) {
getLogger()->debug(MSG_REJECT_PIECE_CANCEL,
util::itos(getCuid()).c_str(),
_index, _begin, _blockLength);
}
if(peer->isFastExtensionEnabled()) {
BtMessageHandle rej = messageFactory->createRejectMessage(index,
begin,
blockLength);
dispatcher->addMessageToQueue(rej);
if(getPeer()->isFastExtensionEnabled()) {
BtMessageHandle rej =
getBtMessageFactory()->createRejectMessage
(_index, _begin, _blockLength);
getBtMessageDispatcher()->addMessageToQueue(rej);
}
invalidate = true;
setInvalidate(true);
}
}

View File

@ -47,10 +47,10 @@ typedef SharedHandle<BtPieceMessage> BtPieceMessageHandle;
class BtPieceMessage : public AbstractBtMessage {
private:
size_t index;
uint32_t begin;
uint32_t blockLength;
unsigned char* block;
size_t _index;
uint32_t _begin;
uint32_t _blockLength;
unsigned char* _block;
unsigned char* _rawData;
SharedHandle<DownloadContext> _downloadContext;
@ -66,47 +66,37 @@ private:
size_t sendPieceData(off_t offset, size_t length) const;
public:
BtPieceMessage(size_t index = 0, uint32_t begin = 0, size_t blockLength = 0)
:AbstractBtMessage(ID, NAME),
index(index),
begin(begin),
blockLength(blockLength),
block(0),
_rawData(0)
{
uploading = true;
}
BtPieceMessage(size_t index = 0, uint32_t begin = 0, size_t blockLength = 0);
virtual ~BtPieceMessage() {
delete [] _rawData;
}
virtual ~BtPieceMessage();
static const uint8_t ID = 7;
static const std::string NAME;
size_t getIndex() const { return index; }
size_t getIndex() const { return _index; }
void setIndex(size_t index) { this->index = index; }
void setIndex(size_t index) { _index = index; }
uint32_t getBegin() const { return begin; }
uint32_t getBegin() const { return _begin; }
void setBegin(uint32_t begin) { this->begin = begin; }
void setBegin(uint32_t begin) { _begin = begin; }
const unsigned char* getBlock() const { return block; }
const unsigned char* getBlock() const { return _block; }
size_t getBlockLength() const { return blockLength; }
size_t getBlockLength() const { return _blockLength; }
// Stores raw message data. After this function call, this object
// has ownership of data. Caller must not be free or alter data.
// Member block is pointed to block starting position in data.
void setRawMessage(unsigned char* data);
void setBlockLength(size_t blockLength) { this->blockLength = blockLength; }
void setBlockLength(size_t blockLength) { _blockLength = blockLength; }
void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
static BtPieceMessageHandle create(const unsigned char* data, size_t dataLength);
static BtPieceMessageHandle create
(const unsigned char* data, size_t dataLength);
virtual void doReceivedAction();

View File

@ -68,15 +68,15 @@ void BtPortMessage::doReceivedAction()
{
if(!_taskFactory.isNull() && !_taskQueue.isNull()) {
if(_port == 0) {
if(logger->debug()) {
logger->debug("Ignored port 0.");
if(getLogger()->debug()) {
getLogger()->debug("Ignored port 0.");
}
return;
}
// node id is random at this point. When ping reply received, new DHTNode
// instance created with proper node ID and is added to a routing table.
SharedHandle<DHTNode> node(new DHTNode());
node->setIPAddress(peer->ipaddr);
node->setIPAddress(getPeer()->ipaddr);
node->setPort(_port);
{
SharedHandle<DHTTask> task = _taskFactory->createPingTask(node);
@ -84,11 +84,13 @@ void BtPortMessage::doReceivedAction()
}
if(_routingTable->countBucket() == 1) {
// initiate bootstrap
logger->info("Dispatch node_lookup since too few buckets.");
_taskQueue->addImmediateTask(_taskFactory->createNodeLookupTask(_localNode->getID()));
getLogger()->info("Dispatch node_lookup since too few buckets.");
_taskQueue->addImmediateTask
(_taskFactory->createNodeLookupTask(_localNode->getID()));
}
} else {
logger->info("DHT port message received while localhost didn't declare support it.");
getLogger()->info
("DHT port message received while localhost didn't declare support it.");
}
}

View File

@ -65,7 +65,8 @@ public:
uint16_t getPort() const { return _port; }
static SharedHandle<BtPortMessage> create(const unsigned char* data, size_t dataLength);
static SharedHandle<BtPortMessage> create
(const unsigned char* data, size_t dataLength);
virtual void doReceivedAction();

View File

@ -43,6 +43,10 @@ namespace aria2 {
const std::string BtRejectMessage::NAME("reject");
BtRejectMessage::BtRejectMessage
(size_t index, uint32_t begin, size_t length):
RangeBtMessage(ID, NAME, index, begin, length) {}
SharedHandle<BtRejectMessage> BtRejectMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -51,22 +55,23 @@ SharedHandle<BtRejectMessage> BtRejectMessage::create
void BtRejectMessage::doReceivedAction()
{
if(!peer->isFastExtensionEnabled()) {
if(!getPeer()->isFastExtensionEnabled()) {
throw DL_ABORT_EX
(StringFormat("%s received while fast extension is disabled.",
toString().c_str()).str());
}
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
// TODO Current implementation does not close a connection even if
// a request for this reject message has never sent.
RequestSlot slot =
dispatcher->getOutstandingRequest(getIndex(), getBegin(), getLength());
getBtMessageDispatcher()->getOutstandingRequest
(getIndex(), getBegin(), getLength());
if(RequestSlot::isNull(slot)) {
//throw DL_ABORT_EX("reject received, but it is not in the request slots.");
} else {
dispatcher->removeOutstandingRequest(slot);
getBtMessageDispatcher()->removeOutstandingRequest(slot);
}
}

View File

@ -45,8 +45,7 @@ typedef SharedHandle<BtRejectMessage> BtRejectMessageHandle;
class BtRejectMessage : public RangeBtMessage {
public:
BtRejectMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0)
:RangeBtMessage(ID, NAME, index, begin, length) {}
BtRejectMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0);
static const uint8_t ID = 16;

View File

@ -43,6 +43,11 @@ namespace aria2 {
const std::string BtRequestMessage::NAME("request");
BtRequestMessage::BtRequestMessage
(size_t index, uint32_t begin, uint32_t length, size_t blockIndex):
RangeBtMessage(ID, NAME, index, begin, length),
_blockIndex(blockIndex) {}
SharedHandle<BtRequestMessage> BtRequestMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -51,22 +56,23 @@ SharedHandle<BtRequestMessage> BtRequestMessage::create
void BtRequestMessage::doReceivedAction()
{
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
if(pieceStorage->hasPiece(getIndex()) &&
(!peer->amChoking() ||
(peer->amChoking() && peer->isInAmAllowedIndexSet(getIndex())))) {
BtMessageHandle msg = messageFactory->createPieceMessage(getIndex(),
getBegin(),
getLength());
dispatcher->addMessageToQueue(msg);
if(getPieceStorage()->hasPiece(getIndex()) &&
(!getPeer()->amChoking() ||
(getPeer()->amChoking() &&
getPeer()->isInAmAllowedIndexSet(getIndex())))) {
BtMessageHandle msg =
getBtMessageFactory()->createPieceMessage
(getIndex(), getBegin(), getLength());
getBtMessageDispatcher()->addMessageToQueue(msg);
} else {
if(peer->isFastExtensionEnabled()) {
BtMessageHandle msg = messageFactory->createRejectMessage(getIndex(),
getBegin(),
getLength());
dispatcher->addMessageToQueue(msg);
if(getPeer()->isFastExtensionEnabled()) {
BtMessageHandle msg =
getBtMessageFactory()->createRejectMessage
(getIndex(), getBegin(), getLength());
getBtMessageDispatcher()->addMessageToQueue(msg);
}
}
}
@ -74,16 +80,16 @@ void BtRequestMessage::doReceivedAction()
void BtRequestMessage::onQueued()
{
RequestSlot requestSlot(getIndex(), getBegin(), getLength(), _blockIndex,
pieceStorage->getPiece(getIndex()));
dispatcher->addOutstandingRequest(requestSlot);
getPieceStorage()->getPiece(getIndex()));
getBtMessageDispatcher()->addOutstandingRequest(requestSlot);
}
void BtRequestMessage::onAbortOutstandingRequestEvent
(const BtAbortOutstandingRequestEvent& event)
{
if(getIndex() == event.getPiece()->getIndex() &&
!invalidate && !sendingInProgress) {
invalidate = true;
!isInvalidate() && !isSendingInProgress()) {
setInvalidate(true);
}
}

View File

@ -46,14 +46,11 @@ typedef SharedHandle<BtRequestMessage> BtRequestMessageHandle;
class BtRequestMessage : public RangeBtMessage {
private:
size_t _blockIndex;
public:
BtRequestMessage(size_t index = 0,
uint32_t begin = 0,
uint32_t length = 0,
size_t blockIndex = 0)
:RangeBtMessage(ID, NAME, index, begin, length),
_blockIndex(blockIndex) {}
size_t blockIndex = 0);
static const uint8_t ID = 6;

View File

@ -39,6 +39,8 @@ namespace aria2 {
const std::string BtUnchokeMessage::NAME("unchoke");
BtUnchokeMessage::BtUnchokeMessage():ZeroBtMessage(ID, NAME) {}
SharedHandle<BtUnchokeMessage> BtUnchokeMessage::create
(const unsigned char* data, size_t dataLength)
{
@ -47,19 +49,19 @@ SharedHandle<BtUnchokeMessage> BtUnchokeMessage::create
void BtUnchokeMessage::doReceivedAction()
{
if(_metadataGetMode) {
if(isMetadataGetMode()) {
return;
}
peer->peerChoking(false);
getPeer()->peerChoking(false);
}
bool BtUnchokeMessage::sendPredicate() const
{
return peer->amChoking();
return getPeer()->amChoking();
}
void BtUnchokeMessage::onSendComplete() {
peer->amChoking(false);
getPeer()->amChoking(false);
}
} // namespace aria2

View File

@ -47,7 +47,7 @@ class BtUnchokeMessage : public ZeroBtMessage {
private:
static const size_t MESSAGE_LENGTH = 5;
public:
BtUnchokeMessage():ZeroBtMessage(ID, NAME) {}
BtUnchokeMessage();
static const uint8_t ID = 1;

View File

@ -44,32 +44,32 @@ namespace aria2 {
SimpleBtMessage::SimpleBtMessage(uint8_t id, const std::string& name):
AbstractBtMessage(id, name) {}
SimpleBtMessage::~SimpleBtMessage() {}
void SimpleBtMessage::send() {
if(invalidate) {
if(isInvalidate()) {
return;
}
if(!sendPredicate() && !sendingInProgress) {
if(!sendPredicate() && !isSendingInProgress()) {
return;
}
if(!sendingInProgress) {
if(logger->info()) {
logger->info(MSG_SEND_PEER_MESSAGE,
util::itos(cuid).c_str(),
peer->ipaddr.c_str(), peer->port, toString().c_str());
if(!isSendingInProgress()) {
if(getLogger()->info()) {
getLogger()->info(MSG_SEND_PEER_MESSAGE,
util::itos(getCuid()).c_str(),
getPeer()->ipaddr.c_str(),
getPeer()->port,
toString().c_str());
}
unsigned char* msg = createMessage();
size_t msgLength = getMessageLength();
if(logger->debug()) {
logger->debug("msglength = %lu bytes",
static_cast<unsigned long>(msgLength));
if(getLogger()->debug()) {
getLogger()->debug("msglength = %lu bytes",
static_cast<unsigned long>(msgLength));
}
peerConnection->pushBytes(msg, msgLength);
getPeerConnection()->pushBytes(msg, msgLength);
}
peerConnection->sendPendingData();
sendingInProgress = !peerConnection->sendBufferIsEmpty();
if(!sendingInProgress) {
getPeerConnection()->sendPendingData();
setSendingInProgress(!getPeerConnection()->sendBufferIsEmpty());
if(!isSendingInProgress()) {
onSendComplete();
}
}

View File

@ -43,8 +43,6 @@ class SimpleBtMessage : public AbstractBtMessage {
public:
SimpleBtMessage(uint8_t id, const std::string& name);
virtual ~SimpleBtMessage();
virtual void send();
virtual unsigned char* createMessage() = 0;