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 "SharedHandle.h"
  40. namespace aria2 {
  41. class ServerStatMan;
  42. class RequestGroup;
  43. class ServerStat;
  44. class Logger;
  45. class AdaptiveURISelector:public URISelector {
  46. private:
  47. SharedHandle<ServerStatMan> serverStatMan_;
  48. // No need to delete requestGroup_
  49. RequestGroup* requestGroup_;
  50. unsigned int nbServerToEvaluate_;
  51. unsigned int nbConnections_;
  52. static const time_t MAX_TIMEOUT = 60;
  53. Logger* logger_;
  54. void mayRetryWithIncreasedTimeout(FileEntry* fileEntry);
  55. std::string selectOne(const std::deque<std::string>& uris);
  56. void adjustLowestSpeedLimit(const std::deque<std::string>& uris,
  57. DownloadCommand* command) const;
  58. unsigned int getMaxDownloadSpeed(const std::deque<std::string>& uris) const;
  59. std::string getMaxDownloadSpeedUri(const std::deque<std::string>& uris) const;
  60. std::deque<std::string> getUrisBySpeed(const std::deque<std::string>& uris,
  61. unsigned int min) const;
  62. std::string selectRandomUri(const std::deque<std::string>& uris) const;
  63. std::string getFirstNotTestedUri(const std::deque<std::string>& uris) const;
  64. std::string getFirstToTestUri(const std::deque<std::string>& uris) const;
  65. SharedHandle<ServerStat> getServerStats(const std::string& uri) const;
  66. unsigned int getNbTestedServers(const std::deque<std::string>& uris) const;
  67. std::string getBestMirror(const std::deque<std::string>& uris) const;
  68. public:
  69. AdaptiveURISelector(const SharedHandle<ServerStatMan>& serverStatMan,
  70. RequestGroup* requestGroup);
  71. virtual ~AdaptiveURISelector();
  72. virtual std::string select
  73. (FileEntry* fileEntry,
  74. const std::vector<std::pair<size_t, std::string> >& usedHosts);
  75. virtual void tuneDownloadCommand(const std::deque<std::string>& uris,
  76. DownloadCommand* command);
  77. virtual void resetCounters();
  78. };
  79. } // namespace aria2
  80. #endif // _D_ADAPTIVE_URI_SELECTOR_H_