/* */ #ifndef D_DEFAULT_BT_MESSAGE_DISPATCHER_H #define D_DEFAULT_BT_MESSAGE_DISPATCHER_H #include "BtMessageDispatcher.h" #include #include "a2time.h" #include "Command.h" namespace aria2 { class DownloadContext; class PeerStorage; class PieceStorage; class BtMessage; class BtMessageFactory; class Peer; class Piece; class RequestGroupMan; class PeerConnection; class DefaultBtMessageDispatcher : public BtMessageDispatcher { private: cuid_t cuid_; std::deque > messageQueue_; std::deque> requestSlots_; DownloadContext* downloadContext_; PeerStorage* peerStorage_; PieceStorage* pieceStorage_; PeerConnection* peerConnection_; BtMessageFactory* messageFactory_; std::shared_ptr peer_; RequestGroupMan* requestGroupMan_; time_t requestTimeout_; public: DefaultBtMessageDispatcher(); virtual ~DefaultBtMessageDispatcher(); virtual void addMessageToQueue(std::unique_ptr btMessage); virtual void sendMessages(); // For unit tests without PeerConnection void sendMessagesInternal(); virtual void doCancelSendingPieceAction (size_t index, int32_t begin, int32_t length); virtual void doCancelSendingPieceAction(const std::shared_ptr& piece); virtual void doAbortOutstandingRequestAction(const std::shared_ptr& piece); virtual void doChokedAction(); virtual void doChokingAction(); virtual void checkRequestSlotAndDoNecessaryThing(); virtual bool isSendingInProgress(); virtual size_t countMessageInQueue() { return messageQueue_.size(); } virtual size_t countOutstandingRequest() { return requestSlots_.size(); } virtual bool isOutstandingRequest(size_t index, size_t blockIndex); virtual const RequestSlot* getOutstandingRequest (size_t index, int32_t begin, int32_t length); virtual void removeOutstandingRequest(const RequestSlot* slot); virtual void addOutstandingRequest(std::unique_ptr requestSlot); virtual size_t countOutstandingUpload(); const std::deque>& getMessageQueue() const { return messageQueue_; } const std::deque>& getRequestSlots() const { return requestSlots_; } void setPeer(const std::shared_ptr& peer); void setDownloadContext(DownloadContext* downloadContext); void setPieceStorage(PieceStorage* pieceStorage); void setPeerStorage(PeerStorage* peerStorage); void setBtMessageFactory(BtMessageFactory* factory); void setRequestGroupMan(RequestGroupMan* rgman); void setCuid(cuid_t cuid) { cuid_ = cuid; } void setRequestTimeout(time_t requestTimeout) { requestTimeout_ = requestTimeout; } void setPeerConnection(PeerConnection* peerConnection) { peerConnection_ = peerConnection; } }; } // namespace aria2 #endif // D_DEFAULT_BT_MESSAGE_DISPATCHER_H