3 Copyright (c) 2003, Arvid Norberg
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #ifndef TORRENT_TORRENT_HPP_INCLUDE
34 #define TORRENT_TORRENT_HPP_INCLUDE
43 #pragma warning(push, 1)
46 #include <boost/limits.hpp>
47 #include <boost/filesystem/path.hpp>
48 #include <boost/tuple/tuple.hpp>
49 #include <boost/enable_shared_from_this.hpp>
50 #include <boost/scoped_ptr.hpp>
51 #include <boost/intrusive_ptr.hpp>
57 #include "libtorrent/torrent_handle.hpp"
58 #include "libtorrent/entry.hpp"
59 #include "libtorrent/torrent_info.hpp"
60 #include "libtorrent/socket.hpp"
61 #include "libtorrent/policy.hpp"
62 #include "libtorrent/tracker_manager.hpp"
63 #include "libtorrent/stat.hpp"
64 #include "libtorrent/alert.hpp"
65 #include "libtorrent/piece_picker.hpp"
66 #include "libtorrent/config.hpp"
67 #include "libtorrent/escape_string.hpp"
68 #include "libtorrent/bandwidth_limit.hpp"
69 #include "libtorrent/bandwidth_queue_entry.hpp"
70 #include "libtorrent/storage.hpp"
71 #include "libtorrent/hasher.hpp"
72 #include "libtorrent/assert.hpp"
73 #include "libtorrent/bitfield.hpp"
77 #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
82 struct torrent_plugin
;
88 struct piece_checker_data
;
91 namespace fs
= boost::filesystem
;
93 // a torrent is a class that holds information
94 // for a specific download. It updates itself against
96 class TORRENT_EXPORT torrent
: public request_callback
97 , public boost::enable_shared_from_this
<torrent
>
102 aux::session_impl
& ses
103 , boost::intrusive_ptr
<torrent_info
> tf
104 , fs::path
const& save_path
105 , tcp::endpoint
const& net_interface
106 , storage_mode_t m_storage_mode
108 , storage_constructor_type sc
110 , std::vector
<char>* resume_data
112 , bool auto_managed
);
114 // used with metadata-less torrents
115 // (the metadata is downloaded from the peers)
117 aux::session_impl
& ses
118 , char const* tracker_url
119 , sha1_hash
const& info_hash
121 , fs::path
const& save_path
122 , tcp::endpoint
const& net_interface
123 , storage_mode_t m_storage_mode
125 , storage_constructor_type sc
127 , std::vector
<char>* resume_data
129 , bool auto_managed
);
133 void parse_resume_data(std::vector
<char>* resume_data
);
135 // starts the announce timer
138 #ifndef TORRENT_DISABLE_EXTENSIONS
139 void add_extension(boost::shared_ptr
<torrent_plugin
>);
140 void add_extension(boost::function
<boost::shared_ptr
<torrent_plugin
>(torrent
*, void*)> const& ext
145 bool has_peer(peer_connection
* p
) const
146 { return m_connections
.find(p
) != m_connections
.end(); }
149 // this is called when the torrent has metadata.
150 // it will initialize the storage and the piece-picker
153 void on_resume_data_checked(int ret
, disk_io_job
const& j
);
154 void on_force_recheck(int ret
, disk_io_job
const& j
);
155 void on_piece_checked(int ret
, disk_io_job
const& j
);
156 void files_checked();
157 void start_checking();
159 void start_announcing();
160 void stop_announcing();
162 int seed_rank(session_settings
const& s
) const;
164 storage_mode_t
storage_mode() const { return m_storage_mode
; }
165 // this will flag the torrent as aborted. The main
166 // loop in session_impl will check for this state
167 // on all torrents once every second, and take
168 // the necessary actions then.
170 bool is_aborted() const { return m_abort
; }
172 torrent_status::state_t
state() const { return m_state
; }
173 void set_state(torrent_status::state_t s
);
177 session_settings
const& settings() const;
179 aux::session_impl
& session() { return m_ses
; }
181 void set_sequential_download(bool sd
);
182 bool is_sequential_download() const
183 { return m_sequential_download
; }
185 void set_queue_position(int p
);
186 int queue_position() const { return m_sequence_number
; }
188 void second_tick(stat
& accumulator
, float tick_interval
);
190 // debug purpose only
191 void print(std::ostream
& os
) const;
193 std::string
name() const;
195 stat
statistics() const { return m_stat
; }
196 void add_stats(stat
const& s
) { m_stat
+= s
; }
197 size_type
bytes_left() const;
198 boost::tuples::tuple
<size_type
, size_type
> bytes_done() const;
199 size_type
quantized_bytes_done() const;
201 void ip_filter_updated() { m_policy
.ip_filter_updated(); }
203 void set_error(std::string
const& msg
) { m_error
= msg
; }
204 bool has_error() const { return !m_error
.empty(); }
211 bool is_paused() const;
212 bool is_torrent_paused() const { return m_paused
; }
213 void force_recheck();
214 void save_resume_data();
216 bool is_auto_managed() const { return m_auto_managed
; }
217 void auto_managed(bool a
);
221 // ============ start deprecation =============
222 void filter_piece(int index
, bool filter
);
223 void filter_pieces(std::vector
<bool> const& bitmask
);
224 bool is_piece_filtered(int index
) const;
225 void filtered_pieces(std::vector
<bool>& bitmask
) const;
226 void filter_files(std::vector
<bool> const& files
);
227 void file_progress(std::vector
<float>& fp
) const;
228 // ============ end deprecation =============
230 void piece_availability(std::vector
<int>& avail
) const;
232 void set_piece_priority(int index
, int priority
);
233 int piece_priority(int index
) const;
235 void prioritize_pieces(std::vector
<int> const& pieces
);
236 void piece_priorities(std::vector
<int>&) const;
238 void set_file_priority(int index
, int priority
);
239 int file_priority(int index
) const;
241 void prioritize_files(std::vector
<int> const& files
);
242 void file_priorities(std::vector
<int>&) const;
244 void update_piece_priorities();
246 torrent_status
status() const;
248 void file_progress(std::vector
<size_type
>& fp
) const;
250 void use_interface(const char* net_interface
);
251 tcp::endpoint
const& get_interface() const { return m_net_interface
; }
253 void connect_to_url_seed(std::string
const& url
);
254 bool connect_to_peer(policy::peer
* peerinfo
);
256 void set_ratio(float ratio
)
257 { TORRENT_ASSERT(ratio
>= 0.0f
); m_ratio
= ratio
; }
262 #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
263 void resolve_countries(bool r
)
264 { m_resolve_countries
= r
; }
266 bool resolving_countries() const { return m_resolve_countries
; }
269 // --------------------------------------------
270 // BANDWIDTH MANAGEMENT
272 bandwidth_limit m_bandwidth_limit
[2];
274 void request_bandwidth(int channel
275 , boost::intrusive_ptr
<peer_connection
> const& p
276 , int max_block_size
, int priority
);
278 void perform_bandwidth_request(int channel
279 , boost::intrusive_ptr
<peer_connection
> const& p
280 , int block_size
, int priority
);
282 void expire_bandwidth(int channel
, int amount
);
283 void assign_bandwidth(int channel
, int amount
, int blk
);
285 int bandwidth_throttle(int channel
) const;
287 int max_assignable_bandwidth(int channel
) const
288 { return m_bandwidth_limit
[channel
].max_assignable(); }
290 int bandwidth_queue_size(int channel
) const;
292 // --------------------------------------------
295 // add or remove a url that will be attempted for
296 // finding the file(s) in this torrent.
297 void add_url_seed(std::string
const& url
)
298 { m_web_seeds
.insert(url
); }
300 void remove_url_seed(std::string
const& url
)
301 { m_web_seeds
.erase(url
); }
303 void retry_url_seed(std::string
const& url
);
305 std::set
<std::string
> url_seeds() const
306 { return m_web_seeds
; }
308 bool free_upload_slots() const
309 { return m_num_uploads
< m_max_uploads
; }
311 void choke_peer(peer_connection
& c
);
312 bool unchoke_peer(peer_connection
& c
);
314 // used by peer_connection to attach itself to a torrent
315 // since incoming connections don't know what torrent
316 // they're a part of until they have received an info_hash.
317 // false means attach failed
318 bool attach_peer(peer_connection
* p
);
320 // this will remove the peer and make sure all
321 // the pieces it had have their reference counter
322 // decreased in the piece_picker
323 void remove_peer(peer_connection
* p
);
325 void cancel_block(piece_block block
);
327 bool want_more_peers() const;
328 bool try_connect_peer();
329 void give_connect_points(int points
);
331 // the number of peers that belong to this torrent
332 int num_peers() const { return (int)m_connections
.size(); }
333 int num_seeds() const;
335 typedef std::set
<peer_connection
*>::iterator peer_iterator
;
336 typedef std::set
<peer_connection
*>::const_iterator const_peer_iterator
;
338 const_peer_iterator
begin() const { return m_connections
.begin(); }
339 const_peer_iterator
end() const { return m_connections
.end(); }
341 peer_iterator
begin() { return m_connections
.begin(); }
342 peer_iterator
end() { return m_connections
.end(); }
344 void resolve_peer_country(boost::intrusive_ptr
<peer_connection
> const& p
) const;
346 void get_full_peer_list(std::vector
<peer_list_entry
>& v
) const;
347 void get_peer_info(std::vector
<peer_info
>& v
);
348 void get_download_queue(std::vector
<partial_piece_info
>& queue
);
350 // --------------------------------------------
351 // TRACKER MANAGEMENT
353 // these are callbacks called by the tracker_connection instance
354 // (either http_tracker_connection or udp_tracker_connection)
355 // when this torrent got a response from its tracker request
356 // or when a failure occured
357 virtual void tracker_response(
358 tracker_request
const& r
359 , std::vector
<peer_entry
>& e
, int interval
360 , int complete
, int incomplete
, address
const& external_ip
);
361 virtual void tracker_request_timed_out(
362 tracker_request
const& r
);
363 virtual void tracker_request_error(tracker_request
const& r
364 , int response_code
, const std::string
& str
);
365 virtual void tracker_warning(tracker_request
const& req
366 , std::string
const& msg
);
367 virtual void tracker_scrape_response(tracker_request
const& req
368 , int complete
, int incomplete
, int downloaded
);
370 // if no password and username is set
371 // this will return an empty string, otherwise
372 // it will concatenate the login and password
373 // ready to be sent over http (but without
375 std::string
tracker_login() const;
377 // returns the absolute time when the next tracker
378 // announce will take place.
379 ptime
next_announce() const;
381 // forcefully sets next_announce to the current time
382 void force_tracker_request();
383 void force_tracker_request(ptime
);
384 void scrape_tracker();
385 void announce_with_tracker(tracker_request::event_t e
386 = tracker_request::none
);
387 ptime
const& last_scrape() const { return m_last_scrape
; }
389 // sets the username and password that will be sent to
391 void set_tracker_login(std::string
const& name
, std::string
const& pw
);
393 // the tcp::endpoint of the tracker that we managed to
394 // announce ourself at the last time we tried to announce
395 const tcp::endpoint
& current_tracker() const;
397 // --------------------------------------------
400 // returns true if we have downloaded the given piece
401 bool have_piece(int index
) const
403 return has_picker()?m_picker
->have_piece(index
):true;
409 ?m_picker
->num_have()
410 :m_torrent_file
->num_pieces();
413 // when we get a have message, this is called for that piece
414 void peer_has(int index
)
418 TORRENT_ASSERT(!is_seed());
419 m_picker
->inc_refcount(index
);
424 TORRENT_ASSERT(is_seed());
429 // when we get a bitfield message, this is called for that piece
430 void peer_has(bitfield
const& bits
)
434 TORRENT_ASSERT(!is_seed());
435 m_picker
->inc_refcount(bits
);
440 TORRENT_ASSERT(is_seed());
449 TORRENT_ASSERT(!is_seed());
450 m_picker
->inc_refcount_all();
455 TORRENT_ASSERT(is_seed());
460 void peer_lost(int index
)
464 TORRENT_ASSERT(!is_seed());
465 m_picker
->dec_refcount(index
);
470 TORRENT_ASSERT(is_seed());
475 int block_size() const { TORRENT_ASSERT(m_block_size
> 0); return m_block_size
; }
476 peer_request
to_req(piece_block
const& p
);
478 void disconnect_all();
479 int disconnect_peers(int num
);
481 // this is called wheh the torrent has completed
482 // the download. It will post an event, disconnect
483 // all seeds and let the tracker know we're finished.
486 // this is the asio callback that is called when a name
487 // lookup for a PEER is completed.
488 void on_peer_name_lookup(error_code
const& e
, tcp::resolver::iterator i
491 // this is the asio callback that is called when a name
492 // lookup for a WEB SEED is completed.
493 void on_name_lookup(error_code
const& e
, tcp::resolver::iterator i
494 , std::string url
, tcp::endpoint proxy
);
496 // this is the asio callback that is called when a name
497 // lookup for a proxy for a web seed is completed.
498 void on_proxy_name_lookup(error_code
const& e
, tcp::resolver::iterator i
501 // this is called when the torrent has finished. i.e.
502 // all the pieces we have not filtered have been downloaded.
503 // If no pieces are filtered, this is called first and then
504 // completed() is called immediately after it.
507 // This is the opposite of finished. It is called if we used
508 // to be finished but enabled some files for download so that
509 // we wasn't finished anymore.
510 void resume_download();
512 void async_verify_piece(int piece_index
, boost::function
<void(int)> const&);
514 // this is called from the peer_connection
515 // each time a piece has failed the hash
517 void piece_finished(int index
, int passed_hash_check
);
519 // piece_passed is called when a piece passes the hash check
520 // this will tell all peers that we just got his piece
521 // and also let the piece picker know that we have this piece
522 // so it wont pick it for download
523 void piece_passed(int index
);
525 // piece_failed is called when a piece fails the hash check
526 void piece_failed(int index
);
528 // this will restore the piece picker state for a piece
529 // by re marking all the requests to blocks in this piece
530 // that are still outstanding in peers' download queues.
531 // this is done when a piece fails
532 void restore_piece_state(int index
);
534 void add_redundant_bytes(int b
);
535 void add_failed_bytes(int b
);
537 // this is true if we have all the pieces
540 return valid_metadata()
542 || m_state
== torrent_status::seeding
543 || m_picker
->num_have() == m_picker
->num_pieces());
546 // this is true if we have all the pieces that we want
547 bool is_finished() const
549 if (is_seed()) return true;
550 return valid_metadata() && m_torrent_file
->num_pieces()
551 - m_picker
->num_have() - m_picker
->num_filtered() == 0;
554 fs::path
save_path() const;
555 alert_manager
& alerts() const;
556 piece_picker
& picker()
558 TORRENT_ASSERT(m_picker
.get());
561 bool has_picker() const
563 return m_picker
.get() != 0;
565 policy
& get_policy() { return m_policy
; }
566 piece_manager
& filesystem();
567 torrent_info
const& torrent_file() const
568 { return *m_torrent_file
; }
570 std::vector
<announce_entry
> const& trackers() const
571 { return m_trackers
; }
573 void replace_trackers(std::vector
<announce_entry
> const& urls
);
575 torrent_handle
get_handle();
577 void write_resume_data(entry
& rd
) const;
578 void read_resume_data(lazy_entry
const& rd
);
581 #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
582 virtual void debug_log(const std::string
& line
);
587 void check_invariant() const;
590 // --------------------------------------------
591 // RESOURCE MANAGEMENT
593 void set_peer_upload_limit(tcp::endpoint ip
, int limit
);
594 void set_peer_download_limit(tcp::endpoint ip
, int limit
);
596 void set_upload_limit(int limit
);
597 int upload_limit() const;
598 void set_download_limit(int limit
);
599 int download_limit() const;
601 void set_max_uploads(int limit
);
602 int max_uploads() const { return m_max_uploads
; }
603 void set_max_connections(int limit
);
604 int max_connections() const { return m_max_connections
; }
606 void move_storage(fs::path
const& save_path
);
608 // renames the file with the given index to the new name
609 // the name may include a directory path
610 // returns false on failure
611 bool rename_file(int index
, std::string
const& name
);
613 // unless this returns true, new connections must wait
614 // with their initialization.
615 bool ready_for_connections() const
616 { return m_connections_initialized
; }
617 bool valid_metadata() const
618 { return m_torrent_file
->is_valid(); }
619 bool are_files_checked() const
620 { return m_files_checked
; }
622 // parses the info section from the given
623 // bencoded tree and moves the torrent
624 // to the checker thread for initial checking
626 // a return value of false indicates an error
627 bool set_metadata(lazy_entry
const& metadata
, std::string
& error
);
629 int sequence_number() const { return m_sequence_number
; }
633 void on_files_deleted(int ret
, disk_io_job
const& j
);
634 void on_files_released(int ret
, disk_io_job
const& j
);
635 void on_torrent_paused(int ret
, disk_io_job
const& j
);
636 void on_storage_moved(int ret
, disk_io_job
const& j
);
637 void on_save_resume_data(int ret
, disk_io_job
const& j
);
638 void on_file_renamed(int ret
, disk_io_job
const& j
);
640 void on_piece_verified(int ret
, disk_io_job
const& j
641 , boost::function
<void(int)> f
);
643 void try_next_tracker(tracker_request
const& req
);
644 int prioritize_tracker(int tracker_index
);
645 void on_country_lookup(error_code
const& error
, tcp::resolver::iterator i
646 , boost::intrusive_ptr
<peer_connection
> p
) const;
647 bool request_bandwidth_from_session(int channel
) const;
649 void update_peer_interest(bool was_finished
);
653 // total time we've been available on this torrent
654 // does not count when the torrent is stopped or paused
655 time_duration m_active_time
;
657 // total time we've been available as a seed on this torrent
658 // does not count when the torrent is stopped or paused
659 time_duration m_seeding_time
;
661 // all time totals of uploaded and downloaded payload
662 // stored in resume data
663 size_type m_total_uploaded
;
664 size_type m_total_downloaded
;
666 // if this torrent is running, this was the time
667 // when it was started. This is used to have a
668 // bias towards keeping seeding torrents that
669 // recently was started, to avoid oscillation
672 // the last time we initiated a scrape request to
673 // one of the trackers in this torrent
676 boost::intrusive_ptr
<torrent_info
> m_torrent_file
;
678 void parse_response(const entry
& e
, std::vector
<peer_entry
>& peer_list
);
680 // if this pointer is 0, the torrent is in
681 // a state where the metadata hasn't been
683 // the piece_manager keeps the torrent object
684 // alive by holding a shared_ptr to it and
685 // the torrent keeps the piece manager alive
686 // with this intrusive_ptr. This cycle is
687 // broken when torrent::abort() is called
688 // Then the torrent releases the piece_manager
689 // and when the piece_manager is complete with all
690 // outstanding disk io jobs (that keeps
691 // the piece_manager alive) it will destruct
692 // and release the torrent file. The reason for
693 // this is that the torrent_info is used by
694 // the piece_manager, and stored in the
695 // torrent, so the torrent cannot destruct
696 // before the piece_manager.
697 boost::intrusive_ptr
<piece_manager
> m_owning_storage
;
699 // this is a weak (non owninig) pointer to
700 // the piece_manager. This is used after the torrent
701 // has been aborted, and it can no longer own
703 piece_manager
* m_storage
;
705 // the time of next tracker announce
706 ptime m_next_tracker_announce
;
711 std::set
<peer_connection
*> m_connections
;
716 // The list of web seeds in this torrent. Seeds
717 // with fatal errors are removed from the set
718 std::set
<std::string
> m_web_seeds
;
720 // a list of web seeds that have failed and are
721 // waiting to be retried
722 std::map
<std::string
, ptime
> m_web_seeds_next_retry
;
724 // urls of the web seeds that we are currently
725 // resolving the address for
726 std::set
<std::string
> m_resolving_web_seeds
;
728 #ifndef TORRENT_DISABLE_EXTENSIONS
729 typedef std::list
<boost::shared_ptr
<torrent_plugin
> > extension_list_t
;
730 extension_list_t m_extensions
;
733 // used to resolve the names of web seeds
734 mutable tcp::resolver m_host_resolver
;
736 // this announce timer is used both
737 // by Local service discovery and
739 deadline_timer m_lsd_announce_timer
;
741 // used for tracker announces
742 deadline_timer m_tracker_timer
;
744 void restart_tracker_timer(ptime announce_at
);
746 static void on_tracker_announce_disp(boost::weak_ptr
<torrent
> p
747 , error_code
const& e
);
749 void on_tracker_announce();
751 static void on_lsd_announce_disp(boost::weak_ptr
<torrent
> p
752 , error_code
const& e
);
754 // this is called once every 5 minutes for torrents
755 // that are not private
756 void on_lsd_announce();
758 #ifndef TORRENT_DISABLE_DHT
759 static void on_dht_announce_response_disp(boost::weak_ptr
<torrent
> t
760 , std::vector
<tcp::endpoint
> const& peers
);
761 void on_dht_announce_response(std::vector
<tcp::endpoint
> const& peers
);
762 bool should_announce_dht() const;
764 // the time when the DHT was last announced of our
765 // presence on this torrent
766 ptime m_last_dht_announce
;
769 // this is the upload and download statistics for the whole torrent.
770 // it's updated from all its peers once every second.
771 libtorrent::stat m_stat
;
773 // -----------------------------
775 // a back reference to the session
776 // this torrent belongs to.
777 aux::session_impl
& m_ses
;
779 std::vector
<boost::uint8_t> m_file_priority
;
781 boost::scoped_ptr
<piece_picker
> m_picker
;
783 // the queue of peer_connections that want more bandwidth
784 typedef std::deque
<bw_queue_entry
<peer_connection
, torrent
> > queue_t
;
785 queue_t m_bandwidth_queue
[2];
787 std::vector
<announce_entry
> m_trackers
;
788 // this is an index into m_trackers
790 // the number of bytes that has been
791 // downloaded that failed the hash-test
792 size_type m_total_failed_bytes
;
793 size_type m_total_redundant_bytes
;
795 std::string m_username
;
796 std::string m_password
;
798 // the network interface all outgoing connections
799 // are opened through
800 tcp::endpoint m_net_interface
;
802 fs::path m_save_path
;
804 // determines the storage state for this torrent.
805 storage_mode_t m_storage_mode
;
807 // the state of this torrent (queued, checking, downloading)
808 torrent_status::state_t m_state
;
810 // if there's an error on this torrent, this is the
814 // used if there is any resume data
815 std::vector
<char> m_resume_data
;
816 lazy_entry m_resume_entry
;
818 // if the torrent is started without metadata, it may
819 // still be given a name until the metadata is received
820 // once the metadata is received this field will no
821 // longer be used and will be reset
822 boost::scoped_ptr
<std::string
> m_name
;
824 session_settings
const& m_settings
;
826 storage_constructor_type m_storage_constructor
;
830 // the upload/download ratio that each peer
831 // tries to maintain.
835 // the maximum number of uploads for this torrent
838 // the number of unchoked peers in this torrent
841 // the maximum number of connections for this torrent
842 int m_max_connections
;
844 // the size of a request block
845 // each piece is divided into these
846 // blocks when requested
849 // -----------------------------
850 // DATA FROM TRACKER RESPONSE
852 // the scrape data from the tracker response, this
853 // is optional and may be -1.
858 // this is the amount downloaded when this torrent
860 // total_done - m_initial_done <= total_payload_download
861 size_type m_initial_done
;
863 // this is the deficit counter in the Deficit Round Robin
864 // used to determine which torrent gets the next
865 // connection attempt. See:
866 // http://www.ecs.umass.edu/ece/wolf/courses/ECE697J/papers/DRR.pdf
867 // The quanta assigned to each torrent depends on the torrents
868 // priority, whether it's seed and the number of connected
869 // peers it has. This has the effect that some torrents
870 // will have more connection attempts than other. Each
871 // connection attempt costs 100 points from the deficit
872 // counter. points are deducted in try_connect_peer and
873 // increased in give_connect_points. Outside of the
874 // torrent object, these points are called connect_points.
875 int m_deficit_counter
;
877 // the number number of seconds between requests
879 boost::int16_t m_duration
;
881 // the sequence number for this torrent, this is a
882 // monotonically increasing number for each added torrent
883 boost::int16_t m_sequence_number
;
885 // the index to the last tracker that worked
886 boost::int8_t m_last_working_tracker
;
888 // the tracker that is currently (or was last)
890 boost::int8_t m_currently_trying_tracker
;
892 // the number of connection attempts that has
893 // failed in a row, this is currently used to
894 // determine the timeout until next try.
895 boost::int8_t m_failed_trackers
;
897 // this is a counter that is decreased every
898 // second, and when it reaches 0, the policy::pulse()
899 // is called and the time scaler is reset to 10.
900 boost::int8_t m_time_scaler
;
902 // is set to true when the torrent has
906 // is true if this torrent has been paused
909 // if this is true, libtorrent may pause and resume
910 // this torrent depending on queuing rules. Torrents
911 // started with auto_managed flag set may be added in
912 // a paused state in case there are no available
914 bool m_auto_managed
:1;
916 #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
917 // this is true while there is a country
918 // resolution in progress. To avoid flodding
919 // the DNS request queue, only one ip is resolved
921 mutable bool m_resolving_country
:1;
923 // this is true if the user has enabled
924 // country resolution in this torrent
925 bool m_resolve_countries
:1;
928 // in case the piece picker hasn't been constructed
929 // when this settings is set, this variable will keep
930 // its value until the piece picker is created
931 bool m_sequential_download
:1;
933 // is false by default and set to
934 // true when the first tracker reponse
936 bool m_got_tracker_response
:1;
938 // this is set to false as long as the connections
939 // of this torrent hasn't been initialized. If we
940 // have metadata from the start, connections are
941 // initialized immediately, if we didn't have metadata,
942 // they are initialized right after files_checked().
943 // valid_resume_data() will return false as long as
944 // the connections aren't initialized, to avoid
945 // them from altering the piece-picker before it
946 // has been initialized with files_checked().
947 bool m_connections_initialized
:1;
949 // is set to true every time there is an incoming
950 // connection to this torrent
951 bool m_has_incoming
:1;
953 // this is set to true when the files are checked
954 // before the files are checked, we don't try to
956 bool m_files_checked
:1;
958 // this is true while tracker announcing is enabled
959 // is is disabled while paused and checking files
962 // this is true if event start has been sent to the tracker
965 // this is true if event completed has been sent to the tracker
966 bool m_complete_sent
:1;
969 inline ptime
torrent::next_announce() const
971 return m_next_tracker_announce
;
974 inline void torrent::force_tracker_request()
976 if (!is_paused()) announce_with_tracker();
979 inline void torrent::force_tracker_request(ptime t
)
981 if (!is_paused()) restart_tracker_timer(t
);
984 inline void torrent::set_tracker_login(
985 std::string
const& name
986 , std::string
const& pw
)
994 #endif // TORRENT_TORRENT_HPP_INCLUDED