/* */ #ifndef D_DEFAULT_BT_ANNOUNCE_H #define D_DEFAULT_BT_ANNOUNCE_H #include "BtAnnounce.h" #include "TimerA2.h" #include "AnnounceList.h" namespace aria2 { class DownloadContext; class Option; class BtRuntime; class PieceStorage; class PeerStorage; class Randomizer; class DefaultBtAnnounce : public BtAnnounce { private: DownloadContext* downloadContext_; int trackers_; Timer prevAnnounceTimer_; std::chrono::seconds interval_; std::chrono::seconds minInterval_; std::chrono::seconds userDefinedInterval_; int complete_; int incomplete_; AnnounceList announceList_; std::string trackerId_; const Option* option_; Randomizer* randomizer_; std::shared_ptr btRuntime_; std::shared_ptr pieceStorage_; std::shared_ptr peerStorage_; uint16_t tcpPort_; bool adjustAnnounceList(); public: DefaultBtAnnounce(DownloadContext* downloadContext, const Option* option); virtual ~DefaultBtAnnounce(); void setBtRuntime(const std::shared_ptr& btRuntime); const std::shared_ptr& getBtRuntime() const { return btRuntime_; } void setPieceStorage(const std::shared_ptr& pieceStorage); const std::shared_ptr& getPieceStorage() const { return pieceStorage_; } void setPeerStorage(const std::shared_ptr& peerStorage); const std::shared_ptr& getPeerStorage() const { return peerStorage_; } bool isDefaultAnnounceReady(); bool isStoppedAnnounceReady(); bool isCompletedAnnounceReady(); virtual bool isAnnounceReady() CXX11_OVERRIDE; virtual std::string getAnnounceUrl() CXX11_OVERRIDE; virtual std::shared_ptr createUDPTrackerRequest(const std::string& remoteAddr, uint16_t remotePort, uint16_t localPort) CXX11_OVERRIDE; virtual void announceStart() CXX11_OVERRIDE; virtual void announceSuccess() CXX11_OVERRIDE; virtual void announceFailure() CXX11_OVERRIDE; virtual bool isAllAnnounceFailed() CXX11_OVERRIDE; virtual void resetAnnounce() CXX11_OVERRIDE; virtual void processAnnounceResponse(const unsigned char* trackerResponse, size_t trackerResponseLength) CXX11_OVERRIDE; virtual void processUDPTrackerResponse( const std::shared_ptr& req) CXX11_OVERRIDE; virtual bool noMoreAnnounce() CXX11_OVERRIDE; virtual void shuffleAnnounce() CXX11_OVERRIDE; virtual void overrideMinInterval(std::chrono::seconds interval) CXX11_OVERRIDE; virtual void setTcpPort(uint16_t port) CXX11_OVERRIDE { tcpPort_ = port; } void setRandomizer(Randomizer* randomizer); const std::chrono::seconds& getInterval() const { return interval_; } const std::chrono::seconds& getMinInterval() const { return minInterval_; } int getComplete() const { return complete_; } int getIncomplete() const { return incomplete_; } const std::string& getTrackerID() const { return trackerId_; } void setUserDefinedInterval(std::chrono::seconds interval) { userDefinedInterval_ = std::move(interval); } }; } // namespace aria2 #endif // D_DEFAULT_BT_ANNOUNCE_H