/* */ #include "BtInterestedMessage.h" #include "PeerMessageUtil.h" #include "DlAbortEx.h" BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data, uint32_t dataLength) { if(dataLength != 1) { throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "interested", dataLength, 1); } uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx("invalid ID=%d for %s. It should be %d.", id, "interested", ID); } BtInterestedMessageHandle message = new BtInterestedMessage(); return message; } void BtInterestedMessage::doReceivedAction() { peer->peerInterested = true; } bool BtInterestedMessage::sendPredicate() const { return !peer->amInterested; } uint32_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; } uint32_t BtInterestedMessage::getMessageLength() { return MESSAGE_LENGTH; } void BtInterestedMessage::onSendComplete() { peer->amInterested = true; } string BtInterestedMessage::toString() const { return "interested"; }