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