/* */ #include "HaveAllMessage.h" #include "DlAbortEx.h" #include "PeerInteraction.h" #include "PeerMessageUtil.h" HaveAllMessage::HaveAllMessage() {} HaveAllMessage::~HaveAllMessage() {} HaveAllMessage* HaveAllMessage::create(const char* data, int dataLength) { if(dataLength != 1) { throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "have all", dataLength, 1); } int id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx("invalid ID=%d for %s. It should be %d.", id, "have all", ID); } HaveAllMessage* haveAllMessage = new HaveAllMessage(); return haveAllMessage; } void HaveAllMessage::receivedAction() { if(!peer->isFastExtensionEnabled()) { throw new DlAbortEx("%s received while fast extension is disabled", toString().c_str()); } peer->setAllBitfield(); } const char* HaveAllMessage::getMessage() { if(!inProgress) { /** * len --- 1, 4bytes * id --- 14, 1byte * total: 5bytes */ PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, ID); } return msg; } int HaveAllMessage::getMessageLength() { return sizeof(msg); } void HaveAllMessage::check() const {} string HaveAllMessage::toString() const { return "have all"; }