1 // rTorrent - BitTorrent client 2 // Copyright (C) 2005-2011, Jari Sundell 3 // 4 // This program is free software; you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation; either version 2 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 // 18 // In addition, as a special exception, the copyright holders give 19 // permission to link the code of portions of this program with the 20 // OpenSSL library under certain conditions as described in each 21 // individual source file, and distribute linked combinations 22 // including the two. 23 // 24 // You must obey the GNU General Public License in all respects for 25 // all of the code used other than OpenSSL. If you modify file(s) 26 // with this exception, you may extend this exception to your version 27 // of the file(s), but you are not obligated to do so. If you do not 28 // wish to do so, delete this exception statement from your version. 29 // If you delete this exception statement from all source files in the 30 // program, then also delete it here. 31 // 32 // Contact: Jari Sundell <jaris@ifi.uio.no> 33 // 34 // Skomakerveien 33 35 // 3185 Skoppum, NORWAY 36 37 #ifndef RTORRENT_CORE_DOWNLOAD_H 38 #define RTORRENT_CORE_DOWNLOAD_H 39 40 #include <torrent/download.h> 41 #include <torrent/download_info.h> 42 #include <torrent/hash_string.h> 43 #include <torrent/tracker_list.h> 44 #include <torrent/data/file_list.h> 45 #include <torrent/peer/connection_list.h> 46 47 #include "globals.h" 48 49 namespace torrent { 50 class PeerList; 51 class TrackerList; 52 } 53 54 namespace core { 55 56 class Download { 57 public: 58 typedef torrent::Download download_type; 59 typedef torrent::FileList file_list_type; 60 typedef torrent::PeerList peer_list_type; 61 typedef torrent::TrackerList tracker_list_type; 62 typedef torrent::TrackerController tracker_controller_type; 63 typedef torrent::ConnectionList connection_list_type; 64 typedef download_type::ConnectionType connection_type; 65 66 static const int variable_hashing_stopped = 0; 67 static const int variable_hashing_initial = 1; 68 static const int variable_hashing_last = 2; 69 static const int variable_hashing_rehash = 3; 70 71 Download(download_type d); 72 ~Download(); 73 info()74 const torrent::DownloadInfo* info() const { return m_download.info(); } data()75 const torrent::download_data* data() const { return m_download.data(); } 76 main()77 torrent::DownloadMain* main() { return m_download.main(); } 78 is_open()79 bool is_open() const { return m_download.info()->is_open(); } is_active()80 bool is_active() const { return m_download.info()->is_active(); } is_done()81 bool is_done() const { return m_download.file_list()->is_done(); } is_downloading()82 bool is_downloading() const { return is_active() && !is_done(); } is_seeding()83 bool is_seeding() const { return is_active() && is_done(); } 84 85 // FIXME: Fixed a bug in libtorrent that caused is_hash_checked to 86 // return true when the torrent is closed. Remove this redundant 87 // test in the next milestone. is_hash_checked()88 bool is_hash_checked() const { return is_open() && m_download.is_hash_checked(); } is_hash_checking()89 bool is_hash_checking() const { return m_download.is_hash_checking(); } 90 is_hash_failed()91 bool is_hash_failed() const { return m_hashFailed; } set_hash_failed(bool v)92 void set_hash_failed(bool v) { m_hashFailed = v; } 93 download()94 download_type* download() { return &m_download; } c_download()95 const download_type* c_download() const { return &m_download; } 96 file_list()97 file_list_type* file_list() { return m_download.file_list(); } c_file_list()98 const file_list_type* c_file_list() const { return m_download.file_list(); } 99 peer_list()100 peer_list_type* peer_list() { return m_download.peer_list(); } c_peer_list()101 const peer_list_type* c_peer_list() const { return m_download.peer_list(); } 102 bencode()103 torrent::Object* bencode() { return m_download.bencode(); } 104 tracker_list()105 tracker_list_type* tracker_list() { return m_download.tracker_list(); } tracker_list_size()106 uint32_t tracker_list_size() const { return m_download.tracker_list()->size(); } 107 tracker_controller()108 tracker_controller_type* tracker_controller() { return m_download.tracker_controller(); } 109 connection_list()110 connection_list_type* connection_list() { return m_download.connection_list(); } 111 uint32_t connection_list_size() const; 112 message()113 const std::string& message() const { return m_message; } set_message(const std::string & msg)114 void set_message(const std::string& msg) { m_message = msg; } 115 116 void enable_udp_trackers(bool state); 117 118 uint32_t priority(); 119 void set_priority(uint32_t p); 120 resume_flags()121 uint32_t resume_flags() { return m_resumeFlags; } set_resume_flags(uint32_t flags)122 void set_resume_flags(uint32_t flags) { m_resumeFlags = flags; } 123 124 void set_root_directory(const std::string& path); 125 126 void set_throttle_name(const std::string& throttleName); 127 128 bool operator == (const std::string& str) const; 129 130 float distributed_copies() const; 131 132 // HACK: Choke group setting. group()133 unsigned int group() const { return m_group; } set_group(unsigned int g)134 void set_group(unsigned int g) { m_group = g; } 135 136 private: 137 Download(const Download&); 138 void operator () (const Download&); 139 140 void receive_tracker_msg(std::string msg); 141 142 void receive_chunk_failed(uint32_t idx); 143 144 // Store the FileList instance so we can use slots etc on it. 145 download_type m_download; 146 bool m_hashFailed; 147 std::string m_message; 148 uint32_t m_resumeFlags; 149 unsigned int m_group; 150 }; 151 152 inline bool 153 Download::operator == (const std::string& str) const { 154 return str.size() == torrent::HashString::size_data && *torrent::HashString::cast_from(str) == m_download.info()->hash(); 155 } 156 157 } 158 159 #endif 160