AdaptiveURISelector.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. * Copyright (C) 2008 Aurelien Lefebvre, Mandriva
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * In addition, as a special exception, the copyright holders give
  23. * permission to link the code of portions of this program with the
  24. * OpenSSL library under certain conditions as described in each
  25. * individual source file, and distribute linked combinations
  26. * including the two.
  27. * You must obey the GNU General Public License in all respects
  28. * for all of the code used other than OpenSSL. If you modify
  29. * file(s) with this exception, you may extend this exception to your
  30. * version of the file(s), but you are not obligated to do so. If you
  31. * do not wish to do so, delete this exception statement from your
  32. * version. If you delete this exception statement from all source
  33. * files in the program, then also delete it here.
  34. */
  35. /* copyright --> */
  36. #ifndef D_ADAPTIVE_URI_SELECTOR_H
  37. #define D_ADAPTIVE_URI_SELECTOR_H
  38. #include "URISelector.h"
  39. #include <memory>
  40. #include <chrono>
  41. namespace aria2 {
  42. class ServerStatMan;
  43. class RequestGroup;
  44. class ServerStat;
  45. class AdaptiveURISelector : public URISelector {
  46. private:
  47. std::shared_ptr<ServerStatMan> serverStatMan_;
  48. // No need to delete requestGroup_
  49. RequestGroup* requestGroup_;
  50. int nbServerToEvaluate_;
  51. int nbConnections_;
  52. void mayRetryWithIncreasedTimeout(FileEntry* fileEntry);
  53. std::string selectOne(const std::deque<std::string>& uris);
  54. void adjustLowestSpeedLimit(const std::deque<std::string>& uris,
  55. DownloadCommand* command) const;
  56. int getMaxDownloadSpeed(const std::deque<std::string>& uris) const;
  57. std::string getMaxDownloadSpeedUri(const std::deque<std::string>& uris) const;
  58. std::deque<std::string> getUrisBySpeed(const std::deque<std::string>& uris,
  59. int min) const;
  60. std::string selectRandomUri(const std::deque<std::string>& uris) const;
  61. std::string getFirstNotTestedUri(const std::deque<std::string>& uris) const;
  62. std::string getFirstToTestUri(const std::deque<std::string>& uris) const;
  63. std::shared_ptr<ServerStat> getServerStats(const std::string& uri) const;
  64. int getNbTestedServers(const std::deque<std::string>& uris) const;
  65. std::string getBestMirror(const std::deque<std::string>& uris) const;
  66. public:
  67. AdaptiveURISelector(std::shared_ptr<ServerStatMan> serverStatMan,
  68. RequestGroup* requestGroup);
  69. virtual ~AdaptiveURISelector();
  70. virtual std::string
  71. select(FileEntry* fileEntry,
  72. const std::vector<std::pair<size_t, std::string>>& usedHosts)
  73. CXX11_OVERRIDE;
  74. virtual void tuneDownloadCommand(const std::deque<std::string>& uris,
  75. DownloadCommand* command) CXX11_OVERRIDE;
  76. virtual void resetCounters() CXX11_OVERRIDE;
  77. };
  78. } // namespace aria2
  79. #endif // D_ADAPTIVE_URI_SELECTOR_H