/* */ #include "BtChokeMessage.h" #include "Peer.h" #include "BtMessageDispatcher.h" #include "BtRequestFactory.h" #include "SocketBuffer.h" namespace aria2 { const char BtChokeMessage::NAME[] = "choke"; BtChokeMessage::BtChokeMessage() : ZeroBtMessage{ID, NAME} {} std::unique_ptr BtChokeMessage::create(const unsigned char* data, size_t dataLength) { return ZeroBtMessage::create(data, dataLength); } void BtChokeMessage::doReceivedAction() { if (isMetadataGetMode()) { return; } getPeer()->peerChoking(true); getBtMessageDispatcher()->doChokedAction(); getBtRequestFactory()->doChokedAction(); } bool BtChokeMessage::sendPredicate() const { return !getPeer()->amChoking(); } namespace { struct ThisProgressUpdate : public ProgressUpdate { ThisProgressUpdate(std::shared_ptr peer, BtMessageDispatcher* disp) : peer(std::move(peer)), disp(disp) { } virtual void update(size_t length, bool complete) CXX11_OVERRIDE { if (complete) { peer->amChoking(true); disp->doChokingAction(); } } std::shared_ptr peer; BtMessageDispatcher* disp; }; } // namespace std::unique_ptr BtChokeMessage::getProgressUpdate() { return make_unique(getPeer(), getBtMessageDispatcher()); } } // namespace aria2