/* */ #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) {} BtChokeMessage* 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(const SharedHandle& peer, BtMessageDispatcher* disp) : peer(peer), disp(disp) {} virtual void update(size_t length, bool complete) { if(complete) { peer->amChoking(true); disp->doChokingAction(); } } SharedHandle peer; BtMessageDispatcher* disp; }; } // namespace ProgressUpdate* BtChokeMessage::getProgressUpdate() { return new ThisProgressUpdate(getPeer(), getBtMessageDispatcher()); } } // namespace aria2