00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef TORRENT_TORRENT_HANDLE_HPP_INCLUDED
00034 #define TORRENT_TORRENT_HANDLE_HPP_INCLUDED
00035
00036 #include <vector>
00037
00038 #ifdef _MSC_VER
00039 #pragma warning(push, 1)
00040 #endif
00041
00042 #include <boost/date_time/posix_time/posix_time.hpp>
00043
00044 #ifdef _MSC_VER
00045 #pragma warning(pop)
00046 #endif
00047
00048 #include "libtorrent/peer_id.hpp"
00049 #include "libtorrent/peer_info.hpp"
00050 #include "libtorrent/piece_picker.hpp"
00051 #include "libtorrent/torrent_info.hpp"
00052 #include "libtorrent/config.hpp"
00053
00054 namespace libtorrent
00055 {
00056 namespace aux
00057 {
00058 struct session_impl;
00059 struct checker_impl;
00060 }
00061
00062 struct TORRENT_EXPORT duplicate_torrent: std::exception
00063 {
00064 virtual const char* what() const throw()
00065 { return "torrent already exists in session"; }
00066 };
00067
00068 struct TORRENT_EXPORT invalid_handle: std::exception
00069 {
00070 virtual const char* what() const throw()
00071 { return "invalid torrent handle used"; }
00072 };
00073
00074 struct TORRENT_EXPORT torrent_status
00075 {
00076 torrent_status()
00077 : state(queued_for_checking)
00078 , paused(false)
00079 , progress(0.f)
00080 , total_download(0)
00081 , total_upload(0)
00082 , total_payload_download(0)
00083 , total_payload_upload(0)
00084 , total_failed_bytes(0)
00085 , total_redundant_bytes(0)
00086 , download_rate(0)
00087 , upload_rate(0)
00088 , download_payload_rate(0)
00089 , upload_payload_rate(0)
00090 , num_peers(0)
00091 , num_complete(-1)
00092 , num_incomplete(-1)
00093 , pieces(0)
00094 , num_pieces(0)
00095 , total_done(0)
00096 , total_wanted_done(0)
00097 , total_wanted(0)
00098 , num_seeds(0)
00099 , distributed_copies(0.f)
00100 , block_size(0)
00101 {}
00102
00103 enum state_t
00104 {
00105 queued_for_checking,
00106 checking_files,
00107 connecting_to_tracker,
00108 downloading_metadata,
00109 downloading,
00110 finished,
00111 seeding,
00112 allocating
00113 };
00114
00115 state_t state;
00116 bool paused;
00117 float progress;
00118 boost::posix_time::time_duration next_announce;
00119 boost::posix_time::time_duration announce_interval;
00120
00121 std::string current_tracker;
00122
00123
00124
00125 size_type total_download;
00126 size_type total_upload;
00127
00128
00129 size_type total_payload_download;
00130 size_type total_payload_upload;
00131
00132
00133
00134 size_type total_failed_bytes;
00135
00136
00137
00138 size_type total_redundant_bytes;
00139
00140
00141
00142 float download_rate;
00143 float upload_rate;
00144
00145
00146
00147 float download_payload_rate;
00148 float upload_payload_rate;
00149
00150
00151
00152 int num_peers;
00153
00154
00155
00156
00157
00158
00159 int num_complete;
00160 int num_incomplete;
00161
00162 const std::vector<bool>* pieces;
00163
00164
00165
00166
00167 int num_pieces;
00168
00169
00170
00171
00172 size_type total_done;
00173
00174
00175
00176
00177 size_type total_wanted_done;
00178
00179
00180
00181
00182 size_type total_wanted;
00183
00184
00185
00186 int num_seeds;
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 float distributed_copies;
00197
00198
00199
00200
00201 int block_size;
00202 };
00203
00204 struct TORRENT_EXPORT partial_piece_info
00205 {
00206 enum { max_blocks_per_piece = piece_picker::max_blocks_per_piece };
00207 int piece_index;
00208 int blocks_in_piece;
00209 std::bitset<max_blocks_per_piece> requested_blocks;
00210 std::bitset<max_blocks_per_piece> finished_blocks;
00211 tcp::endpoint peer[max_blocks_per_piece];
00212 int num_downloads[max_blocks_per_piece];
00213 };
00214
00215 struct TORRENT_EXPORT torrent_handle
00216 {
00217 friend class invariant_access;
00218 friend struct aux::session_impl;
00219 friend class torrent;
00220
00221 torrent_handle(): m_ses(0), m_chk(0), m_info_hash(0) {}
00222
00223 void get_peer_info(std::vector<peer_info>& v) const;
00224 bool send_chat_message(tcp::endpoint ip, std::string message) const;
00225 torrent_status status() const;
00226 void get_download_queue(std::vector<partial_piece_info>& queue) const;
00227
00228
00229
00230
00231 void file_progress(std::vector<float>& progress);
00232
00233 std::vector<announce_entry> const& trackers() const;
00234 void replace_trackers(std::vector<announce_entry> const&) const;
00235
00236 void add_url_seed(std::string const& url);
00237
00238 bool has_metadata() const;
00239 const torrent_info& get_torrent_info() const;
00240 bool is_valid() const;
00241
00242 bool is_seed() const;
00243 bool is_paused() const;
00244 void pause() const;
00245 void resume() const;
00246
00247 void resolve_countries(bool r);
00248 bool resolve_countries() const;
00249
00250
00251
00252 void filter_piece(int index, bool filter) const;
00253 void filter_pieces(std::vector<bool> const& pieces) const;
00254 bool is_piece_filtered(int index) const;
00255 std::vector<bool> filtered_pieces() const;
00256
00257
00258
00259 void filter_files(std::vector<bool> const& files) const;
00260
00261
00262
00263 void use_interface(const char* net_interface) const;
00264
00265 entry write_resume_data() const;
00266
00267
00268
00269 void force_reannounce() const;
00270
00271
00272
00273
00274
00275 void force_reannounce(boost::posix_time::time_duration) const;
00276
00277
00278
00279
00280 std::string name() const;
00281
00282
00283
00284
00285
00286 void set_upload_limit(int limit) const;
00287 void set_download_limit(int limit) const;
00288 void set_sequenced_download_threshold(int threshold) const;
00289
00290 void set_peer_upload_limit(tcp::endpoint ip, int limit) const;
00291 void set_peer_download_limit(tcp::endpoint ip, int limit) const;
00292
00293
00294 void connect_peer(tcp::endpoint const& adr) const;
00295
00296
00297
00298 void set_ratio(float up_down_ratio) const;
00299
00300 boost::filesystem::path save_path() const;
00301
00302
00303 void set_max_uploads(int max_uploads) const;
00304
00305
00306 void set_max_connections(int max_connections) const;
00307
00308 void set_tracker_login(std::string const& name
00309 , std::string const& password) const;
00310
00311
00312 bool move_storage(boost::filesystem::path const& save_path) const;
00313
00314 const sha1_hash& info_hash() const
00315 { return m_info_hash; }
00316
00317 bool operator==(const torrent_handle& h) const
00318 { return m_info_hash == h.m_info_hash; }
00319
00320 bool operator!=(const torrent_handle& h) const
00321 { return m_info_hash != h.m_info_hash; }
00322
00323 bool operator<(const torrent_handle& h) const
00324 { return m_info_hash < h.m_info_hash; }
00325
00326 private:
00327
00328 torrent_handle(aux::session_impl* s,
00329 aux::checker_impl* c,
00330 const sha1_hash& h)
00331 : m_ses(s)
00332 , m_chk(c)
00333 , m_info_hash(h)
00334 {
00335 assert(m_ses != 0);
00336 }
00337
00338 #ifndef NDEBUG
00339 void check_invariant() const;
00340 #endif
00341
00342 aux::session_impl* m_ses;
00343 aux::checker_impl* m_chk;
00344 sha1_hash m_info_hash;
00345
00346 };
00347
00348
00349 }
00350
00351 #endif // TORRENT_TORRENT_HANDLE_HPP_INCLUDED