You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.2 KiB

  1. #ifndef RTORRENT_CORE_MANAGER_H
  2. #define RTORRENT_CORE_MANAGER_H
  3. #include <iosfwd>
  4. #include <memory>
  5. #include <vector>
  6. #include <torrent/utils/log_buffer.h>
  7. #include <torrent/connection_manager.h>
  8. #include <torrent/object.h>
  9. #include "download_list.h"
  10. #include "range_map.h"
  11. namespace torrent {
  12. class Bencode;
  13. }
  14. namespace utils {
  15. class FileStatusCache;
  16. }
  17. namespace core {
  18. class DownloadStore;
  19. class HttpQueue;
  20. typedef std::map<std::string, torrent::ThrottlePair> ThrottleMap;
  21. class View;
  22. class Manager {
  23. public:
  24. typedef DownloadList::iterator DListItr;
  25. typedef utils::FileStatusCache FileStatusCache;
  26. Manager();
  27. ~Manager();
  28. DownloadList* download_list() { return m_download_list.get(); }
  29. DownloadStore* download_store() { return m_download_store.get(); }
  30. FileStatusCache* file_status_cache() { return m_file_status_cache.get(); }
  31. HttpQueue* http_queue() { return m_http_queue.get(); }
  32. View* hashing_view() { return m_hashingView; }
  33. void set_hashing_view(View* v);
  34. torrent::log_buffer* log_important() { return m_log_important.get(); }
  35. torrent::log_buffer* log_complete() { return m_log_complete.get(); }
  36. ThrottleMap& throttles() { return m_throttles; }
  37. torrent::ThrottlePair get_throttle(const std::string& name);
  38. int64_t retrieve_throttle_value(const torrent::Object::string_type& name, bool rate, bool up);
  39. // Use custom throttle for the given range of IP addresses.
  40. void set_address_throttle(uint32_t begin, uint32_t end, torrent::ThrottlePair throttles);
  41. torrent::ThrottlePair get_address_throttle(const sockaddr* addr);
  42. void cleanup();
  43. void listen_open();
  44. void set_bind_address(const std::string& addr);
  45. void set_bind_inet_address(const std::string& addr);
  46. void set_bind_inet6_address(const std::string& addr);
  47. void set_local_address(const std::string& addr);
  48. void set_proxy_address(const std::string& addr);
  49. void shutdown(bool force);
  50. void push_log(const char* msg);
  51. void push_log_std(const std::string& msg) { m_log_important->lock_and_push_log(msg.c_str(), msg.size(), 0); m_log_complete->lock_and_push_log(msg.c_str(), msg.size(), 0); }
  52. void push_log_complete(const std::string& msg) { m_log_complete->lock_and_push_log(msg.c_str(), msg.size(), 0); }
  53. void handshake_log(const sockaddr* sa, int msg, int err, const torrent::HashString* hash);
  54. static const int create_start = 0x1;
  55. static const int create_tied = 0x2;
  56. static const int create_quiet = 0x4;
  57. static const int create_raw_data = 0x8;
  58. typedef std::vector<std::string> command_list_type;
  59. // Temporary, find a better place for this.
  60. void try_create_download(const std::string& uri, int flags, const command_list_type& commands);
  61. void try_create_download_expand(const std::string& uri, int flags, command_list_type commands = command_list_type());
  62. void try_create_download_from_meta_download(torrent::Object* bencode, const std::string& metafile);
  63. private:
  64. typedef RangeMap<uint32_t, torrent::ThrottlePair> AddressThrottleMap;
  65. void create_http(const std::string& uri);
  66. void create_final(std::istream* s);
  67. void initialize_bencode(Download* d);
  68. void receive_http_failed(std::string msg);
  69. void receive_hashing_changed();
  70. std::unique_ptr<DownloadList> m_download_list;
  71. std::unique_ptr<DownloadStore> m_download_store;
  72. std::unique_ptr<FileStatusCache> m_file_status_cache;
  73. std::unique_ptr<HttpQueue> m_http_queue;
  74. View* m_hashingView{};
  75. ThrottleMap m_throttles;
  76. AddressThrottleMap m_addressThrottles;
  77. torrent::log_buffer_ptr m_log_important;
  78. torrent::log_buffer_ptr m_log_complete;
  79. };
  80. // Meh, cleanup.
  81. extern void receive_tracker_dump(const std::string& url, const char* data, size_t size);
  82. }
  83. #endif