/* */ #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_(nullptr) { } 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(std::shared_ptr peer) : peer(std::move(peer)) {} virtual void update(size_t length, bool complete) CXX11_OVERRIDE { if (complete) { peer->amInterested(true); } } std::shared_ptr peer; }; } // namespace std::unique_ptr BtInterestedMessage::getProgressUpdate() { return make_unique(getPeer()); } void BtInterestedMessage::setPeerStorage(PeerStorage* peerStorage) { peerStorage_ = peerStorage; } } // namespace aria2