/* */ #include "BtNotInterestedMessage.h" #include "PeerMessageUtil.h" #include "DlAbortEx.h" #include "message.h" BtNotInterestedMessageHandle BtNotInterestedMessage::create(const unsigned char* data, int32_t dataLength) { if(dataLength != 1) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "not interested", dataLength, 1); } int8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "not interested", ID); } BtNotInterestedMessageHandle message = new BtNotInterestedMessage(); return message; } void BtNotInterestedMessage::doReceivedAction() { peer->peerInterested = false; } bool BtNotInterestedMessage::sendPredicate() const { return peer->amInterested; } int32_t BtNotInterestedMessage::MESSAGE_LENGTH = 5; const unsigned char* BtNotInterestedMessage::getMessage() { if(!msg) { /** * len --- 1, 4bytes * id --- 3, 1byte * total: 5bytes */ msg = new unsigned char[MESSAGE_LENGTH]; PeerMessageUtil::createPeerMessageString(msg, MESSAGE_LENGTH, 1, ID); } return msg; } int32_t BtNotInterestedMessage::getMessageLength() { return MESSAGE_LENGTH; } void BtNotInterestedMessage::onSendComplete() { peer->amInterested = false; } string BtNotInterestedMessage::toString() const { return "not interested"; }