/* */ #include "BtInterestedMessage.h" #include "Peer.h" #include "PeerStorage.h" #include "SocketBuffer.h" namespace aria2 { const char BtInterestedMessage::NAME[] = "interested"; BtInterestedMessage::BtInterestedMessage() : ZeroBtMessage(ID, NAME), peerStorage_(0) {} BtInterestedMessage::~BtInterestedMessage() {} std::unique_ptr BtInterestedMessage::create (const unsigned char* data, size_t dataLength) { return ZeroBtMessage::create(data, dataLength); } void BtInterestedMessage::doReceivedAction() { if(isMetadataGetMode()) { return; } getPeer()->peerInterested(true); if(!getPeer()->amChoking()) { peerStorage_->executeChoke(); } } bool BtInterestedMessage::sendPredicate() const { return !getPeer()->amInterested(); } namespace { struct ThisProgressUpdate : public ProgressUpdate { ThisProgressUpdate(const std::shared_ptr& peer) : peer(peer) {} virtual void update(size_t length, bool complete) { if(complete) { peer->amInterested(true); } } std::shared_ptr peer; }; } // namespace ProgressUpdate* BtInterestedMessage::getProgressUpdate() { return new ThisProgressUpdate(getPeer()); } void BtInterestedMessage::setPeerStorage(PeerStorage* peerStorage) { peerStorage_ = peerStorage; } } // namespace aria2