AdaptiveURISelector.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. SharedHandle<RequestGroup> _requestGroup;
  49. unsigned int _nbServerToEvaluate;
  50. unsigned int _nbConnections;
  51. Logger* _logger;
  52. std::string selectOne(const std::deque<std::string>& uris);
  53. void adjustLowestSpeedLimit(const std::deque<std::string>& uris,
  54. DownloadCommand* command) const;
  55. unsigned int getMaxDownloadSpeed(const std::deque<std::string>& uris) const;
  56. std::string getMaxDownloadSpeedUri(const std::deque<std::string>& uris) const;
  57. std::deque<std::string> getUrisBySpeed(const std::deque<std::string>& uris,
  58. unsigned int min) const;
  59. std::string selectRandomUri(const std::deque<std::string>& uris) const;
  60. std::string getFirstNotTestedUri(const std::deque<std::string>& uris) const;
  61. std::string getFirstToTestUri(const std::deque<std::string>& uris) const;
  62. SharedHandle<ServerStat> getServerStats(const std::string& uri) const;
  63. unsigned int getNbTestedServers(const std::deque<std::string>& uris) const;
  64. public:
  65. AdaptiveURISelector(const SharedHandle<ServerStatMan>& serverStatMan,
  66. const SharedHandle<RequestGroup>& requestGroup);
  67. virtual ~AdaptiveURISelector();
  68. virtual std::string select(std::deque<std::string>& uris);
  69. virtual void tuneDownloadCommand(const std::deque<std::string>& uris,
  70. DownloadCommand* command);
  71. virtual void resetCounters();
  72. };
  73. } // namespace aria2
  74. #endif // _D_ADAPTIVE_URI_SELECTOR_H_