~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/torrent.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <vector>
38
38
#include <set>
39
39
#include <list>
40
 
#include <iostream>
41
40
 
42
41
#ifdef _MSC_VER
43
42
#pragma warning(push, 1)
71
70
#include "libtorrent/hasher.hpp"
72
71
#include "libtorrent/assert.hpp"
73
72
#include "libtorrent/bitfield.hpp"
 
73
#include "libtorrent/aux_/session_impl.hpp"
74
74
 
75
75
#if TORRENT_COMPLETE_TYPES_REQUIRED
76
76
#include "libtorrent/peer_connection.hpp"
85
85
        class piece_manager;
86
86
        struct torrent_plugin;
87
87
        struct bitfield;
 
88
        struct announce_entry;
 
89
        struct tracker_request;
 
90
        struct add_torrent_params;
88
91
 
89
92
        namespace aux
90
93
        {
91
 
                struct session_impl;
92
94
                struct piece_checker_data;
93
95
        }
94
96
 
 
97
        struct web_seed_entry
 
98
        {
 
99
                std::string url;
 
100
                // http seeds are different from url seeds in the
 
101
                // protocol they use. http seeds follows the original
 
102
                // http seed spec. by John Hoffman
 
103
                enum type_t { url_seed, http_seed} type;
 
104
 
 
105
                web_seed_entry(std::string const& url_, type_t type_)
 
106
                        : url(url_), type(type_) {}
 
107
 
 
108
                bool operator==(web_seed_entry const& e) const
 
109
                { return url == e.url && type == e.type; }
 
110
 
 
111
                bool operator<(web_seed_entry const& e) const
 
112
                {
 
113
                        if (url < e.url) return true;
 
114
                        if (url > e.url) return false;
 
115
                        return type < e.type;
 
116
                }
 
117
        };
 
118
 
95
119
        namespace fs = boost::filesystem;
96
120
 
97
121
        // a torrent is a class that holds information
102
126
        {
103
127
        public:
104
128
 
105
 
                torrent(
106
 
                        aux::session_impl& ses
107
 
                        , boost::intrusive_ptr<torrent_info> tf
108
 
                        , fs::path const& save_path
109
 
                        , tcp::endpoint const& net_interface
110
 
                        , storage_mode_t m_storage_mode
111
 
                        , int block_size
112
 
                        , storage_constructor_type sc
113
 
                        , bool paused
114
 
                        , std::vector<char>* resume_data
115
 
                        , int seq
116
 
                        , bool auto_managed);
117
 
 
118
 
                // used with metadata-less torrents
119
 
                // (the metadata is downloaded from the peers)
120
 
                torrent(
121
 
                        aux::session_impl& ses
122
 
                        , char const* tracker_url
123
 
                        , sha1_hash const& info_hash
124
 
                        , char const* name
125
 
                        , fs::path const& save_path
126
 
                        , tcp::endpoint const& net_interface
127
 
                        , storage_mode_t m_storage_mode
128
 
                        , int block_size
129
 
                        , storage_constructor_type sc
130
 
                        , bool paused
131
 
                        , std::vector<char>* resume_data
132
 
                        , int seq
133
 
                        , bool auto_managed);
134
 
 
 
129
                torrent(aux::session_impl& ses, tcp::endpoint const& net_interface
 
130
                        , int block_size, int seq, add_torrent_params const& p);
135
131
                ~torrent();
136
132
 
137
133
#ifndef TORRENT_DISABLE_ENCRYPTION
163
159
                void on_resume_data_checked(int ret, disk_io_job const& j);
164
160
                void on_force_recheck(int ret, disk_io_job const& j);
165
161
                void on_piece_checked(int ret, disk_io_job const& j);
166
 
                void files_checked();
 
162
                void files_checked_lock();
 
163
                void files_checked(aux::session_impl::mutex_t::scoped_lock const&);
167
164
                void start_checking();
168
165
 
169
166
                void start_announcing();
170
167
                void stop_announcing();
171
168
 
 
169
                void send_upload_only();
 
170
 
 
171
                void set_upload_mode(bool b);
 
172
                bool upload_mode() const { return m_upload_mode; }
 
173
                bool is_upload_only() const
 
174
                { return (is_finished() || upload_mode()) && !super_seeding(); }
 
175
 
172
176
                int seed_rank(session_settings const& s) const;
173
177
 
 
178
                enum flags_t { overwrite_existing = 1 };
 
179
                void add_piece(int piece, char const* data, int flags = 0);
 
180
                void on_disk_write_complete(int ret, disk_io_job const& j
 
181
                        , peer_request p);
 
182
 
 
183
                struct read_piece_struct
 
184
                {
 
185
                        boost::shared_array<char> piece_data;
 
186
                        int blocks_left;
 
187
                        bool fail;
 
188
                };
 
189
                void read_piece(int piece);
 
190
                void on_disk_read_complete(int ret, disk_io_job const& j, peer_request r, read_piece_struct* rp);
 
191
 
174
192
                storage_mode_t storage_mode() const { return m_storage_mode; }
175
193
                storage_interface* get_storage()
176
194
                {
188
206
                torrent_status::state_t state() const { return m_state; }
189
207
                void set_state(torrent_status::state_t s);
190
208
 
191
 
                void clear_error();
192
 
 
193
209
                session_settings const& settings() const;
194
210
                
195
211
                aux::session_impl& session() { return m_ses; }
201
217
                void set_queue_position(int p);
202
218
                int queue_position() const { return m_sequence_number; }
203
219
 
204
 
                void second_tick(stat& accumulator, float tick_interval);
205
 
 
206
 
                // debug purpose only
207
 
                void print(std::ostream& os) const;
 
220
                void second_tick(stat& accumulator, int tick_interval_ms);
208
221
 
209
222
                std::string name() const;
210
223
 
211
224
                stat statistics() const { return m_stat; }
212
 
                void add_stats(stat const& s) { m_stat += s; }
 
225
                void add_stats(stat const& s);
213
226
                size_type bytes_left() const;
214
 
                boost::tuples::tuple<size_type, size_type> bytes_done() const;
 
227
                int block_bytes_wanted(piece_block const& p) const;
 
228
                void bytes_done(torrent_status& st) const;
215
229
                size_type quantized_bytes_done() const;
216
230
 
217
231
                void ip_filter_updated() { m_policy.ip_filter_updated(); }
218
232
 
219
 
                void set_error(std::string const& msg);
220
 
                bool has_error() const { return !m_error.empty(); }
 
233
                void handle_disk_error(disk_io_job const& j, peer_connection* c = 0);
 
234
                void clear_error();
 
235
                void set_error(error_code const& ec, std::string const& file);
 
236
                bool has_error() const { return m_error; }
 
237
 
 
238
                void flush_cache();
221
239
                void pause();
222
240
                void resume();
223
241
 
243
261
                bool is_piece_filtered(int index) const;
244
262
                void filtered_pieces(std::vector<bool>& bitmask) const;
245
263
                void filter_files(std::vector<bool> const& files);
 
264
#if !TORRENT_NO_FPU
246
265
                void file_progress(std::vector<float>& fp) const;
 
266
#endif
247
267
                // ============ end deprecation =============
248
268
 
249
269
                void piece_availability(std::vector<int>& avail) const;
260
280
                void prioritize_files(std::vector<int> const& files);
261
281
                void file_priorities(std::vector<int>&) const;
262
282
 
 
283
                void set_piece_deadline(int piece, int t, int flags);
263
284
                void update_piece_priorities();
264
285
 
265
286
                torrent_status status() const;
266
287
 
267
 
                void file_progress(std::vector<size_type>& fp) const;
 
288
                void file_progress(std::vector<size_type>& fp, int flags = 0) const;
268
289
 
269
290
                void use_interface(const char* net_interface);
270
291
                tcp::endpoint const& get_interface() const { return m_net_interface; }
271
292
                
272
 
                void connect_to_url_seed(std::string const& url);
 
293
                void connect_to_url_seed(web_seed_entry const& url);
273
294
                bool connect_to_peer(policy::peer* peerinfo);
274
295
 
275
 
                void set_ratio(float ratio)
276
 
                { TORRENT_ASSERT(ratio >= 0.0f); m_ratio = ratio; }
 
296
                void set_ratio(float r)
 
297
                { TORRENT_ASSERT(r >= 0.0f); m_ratio = r; }
277
298
 
278
299
                float ratio() const
279
300
                { return m_ratio; }
280
301
 
 
302
                int priority() const { return m_priority; }
 
303
                void set_priority(int prio)
 
304
                {
 
305
                        TORRENT_ASSERT(prio <= 255 && prio >= 0);
 
306
                        if (prio > 255) prio = 255;
 
307
                        else if (prio < 0) prio = 0;
 
308
                        m_priority = prio;
 
309
                }
 
310
 
281
311
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
282
312
                void resolve_countries(bool r)
283
313
                { m_resolve_countries = r; }
288
318
// --------------------------------------------
289
319
                // BANDWIDTH MANAGEMENT
290
320
 
291
 
                bandwidth_limit m_bandwidth_limit[2];
292
 
 
293
 
                void request_bandwidth(int channel
294
 
                        , boost::intrusive_ptr<peer_connection> const& p
295
 
                        , int max_block_size, int priority);
296
 
 
297
 
                void perform_bandwidth_request(int channel
298
 
                        , boost::intrusive_ptr<peer_connection> const& p
299
 
                        , int block_size, int priority);
300
 
                
301
 
                void expire_bandwidth(int channel, int amount);
302
 
                void assign_bandwidth(int channel, int amount, int blk);
303
 
                
 
321
                bandwidth_channel m_bandwidth_channel[2];
 
322
 
304
323
                int bandwidth_throttle(int channel) const;
305
324
 
306
 
                int max_assignable_bandwidth(int channel) const
307
 
                { return m_bandwidth_limit[channel].max_assignable(); }
308
 
 
309
 
                int bandwidth_queue_size(int channel) const;
310
 
 
311
325
// --------------------------------------------
312
326
                // PEER MANAGEMENT
313
327
                
314
328
                // add or remove a url that will be attempted for
315
329
                // finding the file(s) in this torrent.
316
 
                void add_url_seed(std::string const& url)
317
 
                { m_web_seeds.insert(url); }
 
330
                void add_web_seed(std::string const& url, web_seed_entry::type_t type)
 
331
                { m_web_seeds.insert(web_seed_entry(url, type)); }
318
332
        
319
 
                void remove_url_seed(std::string const& url)
320
 
                { m_web_seeds.erase(url); }
321
 
 
322
 
                void retry_url_seed(std::string const& url);
323
 
 
324
 
                std::set<std::string> url_seeds() const
 
333
                void remove_web_seed(std::string const& url, web_seed_entry::type_t type)
 
334
                { m_web_seeds.erase(web_seed_entry(url, type)); }
 
335
 
 
336
                void retry_web_seed(std::string const& url, web_seed_entry::type_t type, int retry = 0);
 
337
 
 
338
                std::set<web_seed_entry> web_seeds() const
325
339
                { return m_web_seeds; }
326
340
 
 
341
                std::set<std::string> web_seeds(web_seed_entry::type_t type) const;
 
342
 
327
343
                bool free_upload_slots() const
328
344
                { return m_num_uploads < m_max_uploads; }
329
345
 
330
 
                void choke_peer(peer_connection& c);
 
346
                bool choke_peer(peer_connection& c);
331
347
                bool unchoke_peer(peer_connection& c);
332
348
 
333
349
                // used by peer_connection to attach itself to a torrent
375
391
                // or when a failure occured
376
392
                virtual void tracker_response(
377
393
                        tracker_request const& r
378
 
                        , std::vector<peer_entry>& e, int interval
 
394
                        , address const& tracker_ip
 
395
                        , std::list<address> const& ip_list
 
396
                        , std::vector<peer_entry>& e, int interval, int min_interval
379
397
                        , int complete, int incomplete, address const& external_ip);
380
398
                virtual void tracker_request_timed_out(
381
399
                        tracker_request const& r);
382
400
                virtual void tracker_request_error(tracker_request const& r
383
 
                        , int response_code, const std::string& str);
 
401
                        , int response_code, const std::string& str, int retry_interval);
384
402
                virtual void tracker_warning(tracker_request const& req
385
403
                        , std::string const& msg);
386
404
                virtual void tracker_scrape_response(tracker_request const& req
402
420
                void force_tracker_request(ptime);
403
421
                void scrape_tracker();
404
422
                void announce_with_tracker(tracker_request::event_t e
405
 
                        = tracker_request::none);
 
423
                        = tracker_request::none
 
424
                        , address const& bind_interface = address_v4::any());
406
425
                ptime const& last_scrape() const { return m_last_scrape; }
407
426
 
408
427
#ifndef TORRENT_DISABLE_DHT
417
436
                // announce ourself at the last time we tried to announce
418
437
                const tcp::endpoint& current_tracker() const;
419
438
 
 
439
                announce_entry* find_tracker(tracker_request const& r);
 
440
 
420
441
// --------------------------------------------
421
442
                // PIECE MANAGEMENT
422
443
 
 
444
                void update_sparse_piece_prio(int piece, int cursor, int reverse_cursor);
 
445
 
 
446
                bool super_seeding() const
 
447
                { return m_super_seeding; }
 
448
                
 
449
                void super_seeding(bool on);
 
450
                int get_piece_to_super_seed(bitfield const&);
 
451
 
423
452
                // returns true if we have downloaded the given piece
424
453
                bool have_piece(int index) const
425
454
                {
426
455
                        return has_picker()?m_picker->have_piece(index):true;
427
456
                }
428
457
 
 
458
                // called when we learn that we have a piece
 
459
                // only once per piece
 
460
                void we_have(int index);
 
461
 
429
462
                int num_have() const
430
463
                {
431
464
                        return has_picker()
498
531
                int block_size() const { TORRENT_ASSERT(m_block_size > 0); return m_block_size; }
499
532
                peer_request to_req(piece_block const& p) const;
500
533
 
501
 
                void disconnect_all();
 
534
                void disconnect_all(error_code const& ec);
502
535
                int disconnect_peers(int num);
503
536
 
504
537
                // this is called wheh the torrent has completed
514
547
                // this is the asio callback that is called when a name
515
548
                // lookup for a WEB SEED is completed.
516
549
                void on_name_lookup(error_code const& e, tcp::resolver::iterator i
517
 
                        , std::string url, tcp::endpoint proxy);
 
550
                        , web_seed_entry url, tcp::endpoint proxy);
518
551
 
519
552
                // this is the asio callback that is called when a name
520
553
                // lookup for a proxy for a web seed is completed.
521
554
                void on_proxy_name_lookup(error_code const& e, tcp::resolver::iterator i
522
 
                        , std::string url);
 
555
                        , web_seed_entry url);
523
556
 
524
557
                // this is called when the torrent has finished. i.e.
525
558
                // all the pieces we have not filtered have been downloaded.
594
627
                { return m_trackers; }
595
628
 
596
629
                void replace_trackers(std::vector<announce_entry> const& urls);
 
630
                void add_tracker(announce_entry const& url);
597
631
 
598
632
                torrent_handle get_handle();
599
633
 
613
647
// --------------------------------------------
614
648
                // RESOURCE MANAGEMENT
615
649
 
 
650
                void add_free_upload(int diff) { m_available_free_upload += diff; }
 
651
 
616
652
                void set_peer_upload_limit(tcp::endpoint ip, int limit);
617
653
                void set_peer_download_limit(tcp::endpoint ip, int limit);
618
654
 
647
683
                // to the checker thread for initial checking
648
684
                // of the storage.
649
685
                // a return value of false indicates an error
650
 
                bool set_metadata(lazy_entry const& metadata, std::string& error);
 
686
                bool set_metadata(char const* metadata_buf, int metadata_size);
651
687
 
652
688
                int sequence_number() const { return m_sequence_number; }
653
689
 
 
690
                bool seed_mode() const { return m_seed_mode; }
 
691
                void leave_seed_mode(bool seed)
 
692
                {
 
693
                        if (!m_seed_mode) return;
 
694
                        m_seed_mode = false;
 
695
                        // seed is false if we turned out not
 
696
                        // to be a seed after all
 
697
                        if (!seed) force_recheck();
 
698
                        m_num_verified = 0;
 
699
                        m_verified.free();
 
700
                }
 
701
                bool all_verified() const
 
702
                { return m_num_verified == m_torrent_file->num_pieces(); }
 
703
                bool verified_piece(int piece) const
 
704
                {
 
705
                        TORRENT_ASSERT(piece < int(m_verified.size()));
 
706
                        TORRENT_ASSERT(piece >= 0);
 
707
                        return m_verified.get_bit(piece);
 
708
                }
 
709
                void verified(int piece)
 
710
                {
 
711
                        TORRENT_ASSERT(piece < int(m_verified.size()));
 
712
                        TORRENT_ASSERT(piece >= 0);
 
713
                        TORRENT_ASSERT(m_verified.get_bit(piece) == false);
 
714
                        ++m_num_verified;
 
715
                        m_verified.set_bit(piece);
 
716
                }
 
717
 
 
718
                bool add_merkle_nodes(std::map<int, sha1_hash> const& n, int piece);
 
719
 
 
720
                // this is called once periodically for torrents
 
721
                // that are not private
 
722
                void lsd_announce();
 
723
 
654
724
        private:
655
725
 
656
726
                void on_files_deleted(int ret, disk_io_job const& j);
660
730
                void on_storage_moved(int ret, disk_io_job const& j);
661
731
                void on_save_resume_data(int ret, disk_io_job const& j);
662
732
                void on_file_renamed(int ret, disk_io_job const& j);
 
733
                void on_cache_flushed(int ret, disk_io_job const& j);
663
734
 
664
735
                void on_piece_verified(int ret, disk_io_job const& j
665
736
                        , boost::function<void(int)> f);
666
737
        
667
 
                void try_next_tracker(tracker_request const& req);
668
738
                int prioritize_tracker(int tracker_index);
 
739
                int deprioritize_tracker(int tracker_index);
 
740
 
669
741
                void on_country_lookup(error_code const& error, tcp::resolver::iterator i
670
742
                        , boost::intrusive_ptr<peer_connection> p) const;
671
743
                bool request_bandwidth_from_session(int channel) const;
672
744
 
673
745
                void update_peer_interest(bool was_finished);
 
746
                void prioritize_udp_trackers();
674
747
 
675
748
                void queue_torrent_check();
676
749
                void dequeue_torrent_check();
681
754
                // does not count when the torrent is stopped or paused
682
755
                time_duration m_active_time;
683
756
 
 
757
                // total time we've been finished with this torrent
 
758
                // does not count when the torrent is stopped or paused
 
759
                time_duration m_finished_time;
 
760
 
684
761
                // total time we've been available as a seed on this torrent
685
762
                // does not count when the torrent is stopped or paused
686
763
                time_duration m_seeding_time;
700
777
                // one of the trackers in this torrent
701
778
                ptime m_last_scrape;
702
779
 
 
780
                // the time when we switched to upload mode
 
781
                ptime m_upload_mode_time;
 
782
 
703
783
                boost::intrusive_ptr<torrent_info> m_torrent_file;
704
784
 
705
785
                void parse_response(const entry& e, std::vector<peer_entry>& peer_list);
729
809
                // the object.
730
810
                piece_manager* m_storage;
731
811
 
732
 
                // the time of next tracker announce
733
 
                ptime m_next_tracker_announce;
734
 
 
735
812
#ifdef TORRENT_DEBUG
736
813
        public:
737
814
#endif
742
819
 
743
820
                // The list of web seeds in this torrent. Seeds
744
821
                // with fatal errors are removed from the set
745
 
                std::set<std::string> m_web_seeds;
 
822
                std::set<web_seed_entry> m_web_seeds;
746
823
 
747
824
                // a list of web seeds that have failed and are
748
825
                // waiting to be retried
749
 
                std::map<std::string, ptime> m_web_seeds_next_retry;
 
826
                std::map<web_seed_entry, ptime> m_web_seeds_next_retry;
750
827
                
751
828
                // urls of the web seeds that we are currently
752
829
                // resolving the address for
753
 
                std::set<std::string> m_resolving_web_seeds;
 
830
                std::set<web_seed_entry> m_resolving_web_seeds;
754
831
 
755
832
#ifndef TORRENT_DISABLE_EXTENSIONS
756
833
                typedef std::list<boost::shared_ptr<torrent_plugin> > extension_list_t;
760
837
                // used to resolve the names of web seeds
761
838
                mutable tcp::resolver m_host_resolver;
762
839
                
 
840
#ifndef TORRENT_DISABLE_DHT
763
841
                // this announce timer is used both
764
842
                // by Local service discovery and
765
843
                // by the DHT.
766
 
                deadline_timer m_lsd_announce_timer;
 
844
                deadline_timer m_dht_announce_timer;
 
845
#endif
767
846
 
768
847
                // used for tracker announces
769
848
                deadline_timer m_tracker_timer;
770
849
 
771
 
                void restart_tracker_timer(ptime announce_at);
 
850
                void update_tracker_timer();
772
851
 
773
852
                static void on_tracker_announce_disp(boost::weak_ptr<torrent> p
774
853
                        , error_code const& e);
775
854
 
776
855
                void on_tracker_announce();
777
856
 
778
 
                static void on_lsd_announce_disp(boost::weak_ptr<torrent> p
779
 
                        , error_code const& e);
780
 
 
781
 
                // this is called once every 5 minutes for torrents
782
 
                // that are not private
783
 
                void on_lsd_announce();
 
857
                void dht_announce();
784
858
 
785
859
#ifndef TORRENT_DISABLE_DHT
786
860
                static void on_dht_announce_response_disp(boost::weak_ptr<torrent> t
787
861
                        , std::vector<tcp::endpoint> const& peers);
788
862
                void on_dht_announce_response(std::vector<tcp::endpoint> const& peers);
789
863
                bool should_announce_dht() const;
 
864
                void on_dht_announce(error_code const& e);
790
865
 
791
866
                // the time when the DHT was last announced of our
792
867
                // presence on this torrent
805
880
 
806
881
                std::vector<boost::uint8_t> m_file_priority;
807
882
 
 
883
                // this vector contains the number of bytes completely
 
884
                // downloaded (as in passed-hash-check) in each file.
 
885
                // this lets us trigger on individual files completing
 
886
                std::vector<size_type> m_file_progress;
 
887
 
808
888
                boost::scoped_ptr<piece_picker> m_picker;
809
889
 
810
 
                // the queue of peer_connections that want more bandwidth
811
 
                typedef std::deque<bw_queue_entry<peer_connection, torrent> > queue_t;
812
 
                queue_t m_bandwidth_queue[2];
813
 
 
814
890
                std::vector<announce_entry> m_trackers;
815
891
                // this is an index into m_trackers
816
892
 
 
893
                struct time_critical_piece
 
894
                {
 
895
                        // when this piece was first requested
 
896
                        ptime first_requested;
 
897
                        // when this piece was last requested
 
898
                        ptime last_requested;
 
899
                        // by what time we want this piece
 
900
                        ptime deadline;
 
901
                        // 1 = send alert with piece data when available
 
902
                        int flags;
 
903
                        // how many peers it's been requested from
 
904
                        int peers;
 
905
                        // the piece index
 
906
                        int piece;
 
907
                        bool operator<(time_critical_piece const& rhs) const
 
908
                        { return deadline < rhs.deadline; }
 
909
                };
 
910
 
 
911
                void remove_time_critical_piece(int piece, bool finished = false);
 
912
                void remove_time_critical_pieces(std::vector<int> const& priority);
 
913
                void request_time_critical_pieces();
 
914
 
 
915
                // this list is sorted by time_critical_piece::deadline
 
916
                std::list<time_critical_piece> m_time_critical_pieces;
 
917
 
 
918
                // the average time it takes to download one time critical piece
 
919
                time_duration m_average_piece_time;
 
920
                // the average piece download time deviation
 
921
                time_duration m_piece_time_deviation;
 
922
 
817
923
                // the number of bytes that has been
818
924
                // downloaded that failed the hash-test
819
925
                size_type m_total_failed_bytes;
820
926
                size_type m_total_redundant_bytes;
821
927
 
 
928
                // the number of bytes of padding files
 
929
                int m_padding;
 
930
 
822
931
                std::string m_username;
823
932
                std::string m_password;
824
933
 
828
937
 
829
938
                fs::path m_save_path;
830
939
 
 
940
                // each bit represents a piece. a set bit means
 
941
                // the piece has had its hash verified. This
 
942
                // is only used in seed mode (when m_seed_mode
 
943
                // is true)
 
944
                bitfield m_verified;
 
945
                // m_num_verified = m_verified.count()
 
946
                int m_num_verified;
 
947
 
 
948
                // free download we have got that hasn't
 
949
                // been distributed yet.
 
950
                size_type m_available_free_upload;
 
951
 
831
952
                // determines the storage state for this torrent.
832
953
                storage_mode_t m_storage_mode;
833
954
 
834
 
                // the state of this torrent (queued, checking, downloading)
 
955
                // the state of this torrent (queued, checking, downloading, etc.)
835
956
                torrent_status::state_t m_state;
836
957
 
837
 
                // if there's an error on this torrent, this is the
838
 
                // error message
839
 
                std::string m_error;
 
958
                // set if there's an error on this torrent
 
959
                error_code m_error;
 
960
                // if the error ocurred on a file, this is the file
 
961
                std::string m_error_file;
840
962
 
841
963
                // used if there is any resume data
842
964
                std::vector<char> m_resume_data;
857
979
 
858
980
                storage_constructor_type m_storage_constructor;
859
981
 
860
 
                float m_progress;
 
982
                int m_progress_ppm;
861
983
 
862
984
                // the upload/download ratio that each peer
863
985
                // tries to maintain.
906
1028
                // torrent object, these points are called connect_points.
907
1029
                int m_deficit_counter;
908
1030
 
909
 
                // the number number of seconds between requests
910
 
                // from the tracker
911
 
                boost::int16_t m_duration;
912
 
 
913
1031
                // the sequence number for this torrent, this is a
914
1032
                // monotonically increasing number for each added torrent
915
1033
                boost::int16_t m_sequence_number;
917
1035
                // the index to the last tracker that worked
918
1036
                boost::int8_t m_last_working_tracker;
919
1037
 
920
 
                // the tracker that is currently (or was last)
921
 
                // tried
922
 
                boost::int8_t m_currently_trying_tracker;
923
 
 
924
1038
                // the number of connection attempts that has
925
1039
                // failed in a row, this is currently used to
926
1040
                // determine the timeout until next try.
931
1045
                // is called and the time scaler is reset to 10.
932
1046
                boost::int8_t m_time_scaler;
933
1047
 
 
1048
                // this is the priority of the torrent. The higher
 
1049
                // the value is, the more bandwidth is assigned to
 
1050
                // the torrent's peers
 
1051
                boost::uint8_t m_priority;
 
1052
 
934
1053
                // is set to true when the torrent has
935
1054
                // been aborted.
936
1055
                bool m_abort:1;
938
1057
                // is true if this torrent has been paused
939
1058
                bool m_paused:1;
940
1059
 
 
1060
                // set to true when this torrent may not download anything
 
1061
                bool m_upload_mode:1;
 
1062
 
941
1063
                // if this is true, libtorrent may pause and resume
942
1064
                // this torrent depending on queuing rules. Torrents
943
1065
                // started with auto_managed flag set may be added in
978
1100
                // has been initialized with files_checked().
979
1101
                bool m_connections_initialized:1;
980
1102
 
 
1103
                // if this is true, we're currently super seeding this
 
1104
                // torrent.
 
1105
                bool m_super_seeding:1;
 
1106
 
981
1107
                // is set to true every time there is an incoming
982
1108
                // connection to this torrent
983
1109
                bool m_has_incoming:1;
995
1121
                // is is disabled while paused and checking files
996
1122
                bool m_announcing:1;
997
1123
 
998
 
                // this is true if event start has been sent to the tracker
999
 
                bool m_start_sent:1;
1000
 
 
1001
 
                // this is true if event completed has been sent to the tracker
1002
 
                bool m_complete_sent:1;
 
1124
                // this is true while the tracker deadline timer
 
1125
                // is in use. i.e. one or more trackers are waiting
 
1126
                // for a reannounce
 
1127
                bool m_waiting_tracker:1;
 
1128
 
 
1129
                // this means we haven't verified the file content
 
1130
                // of the files we're seeding. the m_verified bitfield
 
1131
                // indicates which pieces have been verified and which
 
1132
                // haven't
 
1133
                bool m_seed_mode:1;
 
1134
 
 
1135
                // this is set when we don't want to load seed_mode,
 
1136
                // paused or auto_managed from the resume data
 
1137
                bool m_override_resume_data:1;
1003
1138
        };
1004
 
 
1005
 
        inline ptime torrent::next_announce() const
1006
 
        {
1007
 
                return m_next_tracker_announce;
1008
 
        }
1009
 
 
1010
 
        inline void torrent::force_tracker_request()
1011
 
        {
1012
 
                if (!is_paused()) announce_with_tracker();
1013
 
        }
1014
 
 
1015
 
        inline void torrent::force_tracker_request(ptime t)
1016
 
        {
1017
 
                if (!is_paused()) restart_tracker_timer(t);
1018
 
        }
1019
 
 
1020
 
        inline void torrent::set_tracker_login(
1021
 
                std::string const& name
1022
 
                , std::string const& pw)
1023
 
        {
1024
 
                m_username = name;
1025
 
                m_password = pw;
1026
 
        }
1027
 
 
1028
1139
}
1029
1140
 
1030
1141
#endif // TORRENT_TORRENT_HPP_INCLUDED