DefaultBtAnnounce.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #ifndef D_DEFAULT_BT_ANNOUNCE_H
  36. #define D_DEFAULT_BT_ANNOUNCE_H
  37. #include "BtAnnounce.h"
  38. #include "TimerA2.h"
  39. #include "AnnounceList.h"
  40. namespace aria2 {
  41. class DownloadContext;
  42. class Option;
  43. class BtRuntime;
  44. class PieceStorage;
  45. class PeerStorage;
  46. class Randomizer;
  47. class DefaultBtAnnounce : public BtAnnounce {
  48. private:
  49. DownloadContext* downloadContext_;
  50. int trackers_;
  51. Timer prevAnnounceTimer_;
  52. std::chrono::seconds interval_;
  53. std::chrono::seconds minInterval_;
  54. std::chrono::seconds userDefinedInterval_;
  55. int complete_;
  56. int incomplete_;
  57. AnnounceList announceList_;
  58. std::string trackerId_;
  59. const Option* option_;
  60. Randomizer* randomizer_;
  61. std::shared_ptr<BtRuntime> btRuntime_;
  62. std::shared_ptr<PieceStorage> pieceStorage_;
  63. std::shared_ptr<PeerStorage> peerStorage_;
  64. uint16_t tcpPort_;
  65. bool adjustAnnounceList();
  66. public:
  67. DefaultBtAnnounce(DownloadContext* downloadContext, const Option* option);
  68. virtual ~DefaultBtAnnounce();
  69. void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
  70. const std::shared_ptr<BtRuntime>& getBtRuntime() const { return btRuntime_; }
  71. void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
  72. const std::shared_ptr<PieceStorage>& getPieceStorage() const
  73. {
  74. return pieceStorage_;
  75. }
  76. void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
  77. const std::shared_ptr<PeerStorage>& getPeerStorage() const
  78. {
  79. return peerStorage_;
  80. }
  81. bool isDefaultAnnounceReady();
  82. bool isStoppedAnnounceReady();
  83. bool isCompletedAnnounceReady();
  84. virtual bool isAnnounceReady() CXX11_OVERRIDE;
  85. virtual std::string getAnnounceUrl() CXX11_OVERRIDE;
  86. virtual std::shared_ptr<UDPTrackerRequest>
  87. createUDPTrackerRequest(const std::string& remoteAddr, uint16_t remotePort,
  88. uint16_t localPort) CXX11_OVERRIDE;
  89. virtual void announceStart() CXX11_OVERRIDE;
  90. virtual void announceSuccess() CXX11_OVERRIDE;
  91. virtual void announceFailure() CXX11_OVERRIDE;
  92. virtual bool isAllAnnounceFailed() CXX11_OVERRIDE;
  93. virtual void resetAnnounce() CXX11_OVERRIDE;
  94. virtual void
  95. processAnnounceResponse(const unsigned char* trackerResponse,
  96. size_t trackerResponseLength) CXX11_OVERRIDE;
  97. virtual void processUDPTrackerResponse(
  98. const std::shared_ptr<UDPTrackerRequest>& req) CXX11_OVERRIDE;
  99. virtual bool noMoreAnnounce() CXX11_OVERRIDE;
  100. virtual void shuffleAnnounce() CXX11_OVERRIDE;
  101. virtual void
  102. overrideMinInterval(std::chrono::seconds interval) CXX11_OVERRIDE;
  103. virtual void setTcpPort(uint16_t port) CXX11_OVERRIDE { tcpPort_ = port; }
  104. void setRandomizer(Randomizer* randomizer);
  105. const std::chrono::seconds& getInterval() const { return interval_; }
  106. const std::chrono::seconds& getMinInterval() const { return minInterval_; }
  107. int getComplete() const { return complete_; }
  108. int getIncomplete() const { return incomplete_; }
  109. const std::string& getTrackerID() const { return trackerId_; }
  110. void setUserDefinedInterval(std::chrono::seconds interval)
  111. {
  112. userDefinedInterval_ = std::move(interval);
  113. }
  114. };
  115. } // namespace aria2
  116. #endif // D_DEFAULT_BT_ANNOUNCE_H