/* */ #include "BtChokeMessage.h" #include "PeerMessageUtil.h" #include "DlAbortEx.h" #include "message.h" #include "Peer.h" #include "BtMessageDispatcher.h" #include "BtRequestFactory.h" namespace aria2 { BtChokeMessageHandle BtChokeMessage::create(const unsigned char* data, int32_t dataLength) { if(dataLength != 1) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "choke", dataLength, 1); } int8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "choke", ID); } BtChokeMessageHandle chokeMessage = new BtChokeMessage(); return chokeMessage; } void BtChokeMessage::doReceivedAction() { peer->peerChoking(true); dispatcher->doChokedAction(); requestFactory->doChokedAction(); } bool BtChokeMessage::sendPredicate() const { return !peer->amChoking(); } int32_t BtChokeMessage::MESSAGE_LENGTH = 5; const unsigned char* BtChokeMessage::getMessage() { if(!msg) { /** * len --- 1, 4bytes * id --- 0, 1byte * total: 5bytes */ msg = new unsigned char[MESSAGE_LENGTH]; PeerMessageUtil::createPeerMessageString(msg, MESSAGE_LENGTH, 1, ID); } return msg; } int32_t BtChokeMessage::getMessageLength() { return MESSAGE_LENGTH; } void BtChokeMessage::onSendComplete() { peer->amChoking(true); dispatcher->doChokingAction(); } std::string BtChokeMessage::toString() const { return "choke"; } } // namespace aria2