AdaptiveURISelector.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. namespace aria2 {
  41. class ServerStatMan;
  42. class RequestGroup;
  43. class ServerStat;
  44. class AdaptiveURISelector:public URISelector {
  45. private:
  46. std::shared_ptr<ServerStatMan> serverStatMan_;
  47. // No need to delete requestGroup_
  48. RequestGroup* requestGroup_;
  49. int nbServerToEvaluate_;
  50. int nbConnections_;
  51. static const time_t MAX_TIMEOUT = 60;
  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(const std::shared_ptr<ServerStatMan>& serverStatMan,
  68. RequestGroup* requestGroup);
  69. virtual ~AdaptiveURISelector();
  70. virtual std::string select
  71. (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)
  76. CXX11_OVERRIDE;
  77. virtual void resetCounters() CXX11_OVERRIDE;
  78. };
  79. } // namespace aria2
  80. #endif // D_ADAPTIVE_URI_SELECTOR_H