forked from premiere/premiere-libtorrent
remove ghost torrent/torrent eviction feature. (#1214)
remove ghost torrent/torrent eviction feature. It was very complex and did not solve the problem very well
This commit is contained in:
parent
9cdf0ee50c
commit
c18c12a144
|
@ -1,3 +1,4 @@
|
|||
* remove torrent eviction/ghost torrent feature
|
||||
* include target in DHT lookups, when queried from the session
|
||||
* improve support for HTTP redirects for web seeds
|
||||
* use string_view in entry interface
|
||||
|
|
|
@ -114,7 +114,9 @@ void bind_torrent_status()
|
|||
.def_readonly("need_save_resume", &torrent_status::need_save_resume)
|
||||
.def_readonly("ip_filter_applies", &torrent_status::ip_filter_applies)
|
||||
.def_readonly("moving_storage", &torrent_status::moving_storage)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
.def_readonly("is_loaded", &torrent_status::is_loaded)
|
||||
#endif
|
||||
.def_readonly("announcing_to_trackers", &torrent_status::announcing_to_trackers)
|
||||
.def_readonly("announcing_to_lsd", &torrent_status::announcing_to_lsd)
|
||||
.def_readonly("announcing_to_dht", &torrent_status::announcing_to_dht)
|
||||
|
|
|
@ -314,10 +314,9 @@ void torrent_view::print_torrent(lt::torrent_status const& s, bool selected)
|
|||
else if (s.current_tracker.empty())
|
||||
progress_bar_color = col_green;
|
||||
|
||||
pos += std::snprintf(str + pos, sizeof(str) - pos, "%s%c%-3s %-50s %s%s %s (%s) "
|
||||
pos += std::snprintf(str + pos, sizeof(str) - pos, "%s%-3s %-50s %s%s %s (%s) "
|
||||
"%s (%s) %5d:%-5d %s %s %c"
|
||||
, selection
|
||||
, s.is_loaded ? 'L' : ' '
|
||||
, queue_pos
|
||||
, name.c_str()
|
||||
, progress_bar(s.progress_ppm / 1000, 35, progress_bar_color, '-', '#', torrent_state(s)).c_str()
|
||||
|
@ -357,7 +356,6 @@ bool torrent_view::show_torrent(lt::torrent_status const& st)
|
|||
case torrents_queued: return st.paused && st.auto_managed;
|
||||
case torrents_stopped: return st.paused && !st.auto_managed;
|
||||
case torrents_checking: return st.state == lt::torrent_status::checking_files;
|
||||
case torrents_loaded: return st.is_loaded;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ struct torrent_view
|
|||
torrents_queued,
|
||||
torrents_stopped,
|
||||
torrents_checking,
|
||||
torrents_loaded,
|
||||
|
||||
torrents_max
|
||||
};
|
||||
|
|
|
@ -576,23 +576,6 @@ namespace libtorrent
|
|||
|
||||
int next_port() const;
|
||||
|
||||
// load the specified torrent, also
|
||||
// pick the least recently used torrent and unload it, unless
|
||||
// t is the least recently used, then the next least recently
|
||||
// used is picked
|
||||
// returns true if the torrent was loaded successfully
|
||||
bool load_torrent(torrent* t) override;
|
||||
|
||||
// bump t to the top of the list of least recently used. i.e.
|
||||
// make it the most recently used. This is done every time
|
||||
// an action is performed that required the torrent to be
|
||||
// loaded, indicating activity
|
||||
void bump_torrent(torrent* t, bool back = true) override;
|
||||
|
||||
// evict torrents until there's space for one new torrent,
|
||||
void evict_torrents_except(torrent* ignore);
|
||||
void evict_torrent(torrent* t) override;
|
||||
|
||||
void deferred_submit_jobs() override;
|
||||
|
||||
char* allocate_buffer() override;
|
||||
|
@ -822,12 +805,6 @@ namespace libtorrent
|
|||
torrent_map m_obfuscated_torrents;
|
||||
#endif
|
||||
|
||||
// this is an LRU for torrents. It's used to determine
|
||||
// which torrents should be loaded into RAM and which ones
|
||||
// shouldn't. Each torrent that's loaded is part of this
|
||||
// list.
|
||||
linked_list<torrent> m_torrent_lru;
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
//deprecated in 1.2
|
||||
std::map<std::string, std::shared_ptr<torrent>> m_uuids;
|
||||
|
|
|
@ -161,8 +161,6 @@ namespace libtorrent { namespace aux
|
|||
virtual bool has_connection(peer_connection* p) const = 0;
|
||||
virtual void insert_peer(std::shared_ptr<peer_connection> const& c) = 0;
|
||||
|
||||
virtual void evict_torrent(torrent* t) = 0;
|
||||
|
||||
virtual void remove_torrent(torrent_handle const& h, int options = 0) = 0;
|
||||
virtual void remove_torrent_impl(std::shared_ptr<torrent> tptr, int options) = 0;
|
||||
|
||||
|
@ -209,14 +207,6 @@ namespace libtorrent { namespace aux
|
|||
virtual std::uint16_t listen_port() const = 0;
|
||||
virtual std::uint16_t ssl_listen_port() const = 0;
|
||||
|
||||
// load the specified torrent. also evict one torrent, except
|
||||
// for the one specified, if we are at the limit of loaded torrents
|
||||
virtual bool load_torrent(torrent* t) = 0;
|
||||
|
||||
// bump the specified torrent to make it the most recently used one
|
||||
// in the torrent LRU (i.e. the least likely to get unloaded)
|
||||
virtual void bump_torrent(torrent* t, bool back = true) = 0;
|
||||
|
||||
// ask for which interface and port to bind outgoing peer connections on
|
||||
virtual tcp::endpoint bind_outgoing_socket(socket_type& s, address const&
|
||||
remote_address, error_code& ec) const = 0;
|
||||
|
|
|
@ -334,15 +334,6 @@ namespace libtorrent
|
|||
// enum members
|
||||
virtual void on_state(int /*s*/) {}
|
||||
|
||||
// called when the torrent is unloaded from RAM
|
||||
// and loaded again, respectively
|
||||
// unload is called right before the torrent is
|
||||
// unloaded and load is called right after it's
|
||||
// loaded. i.e. the full torrent state is available
|
||||
// when these callbacks are called.
|
||||
virtual void on_unload() {}
|
||||
virtual void on_load() {}
|
||||
|
||||
// called every time policy::add_peer is called
|
||||
// src is a bitmask of which sources this peer
|
||||
// has been seen from. flags is a bitmask of:
|
||||
|
|
|
@ -328,10 +328,6 @@ namespace libtorrent
|
|||
// IP filter applied to them.
|
||||
non_filter_torrents,
|
||||
|
||||
// counters related to evicting torrents
|
||||
num_loaded_torrents,
|
||||
num_pinned_torrents,
|
||||
|
||||
// these counter indices deliberately
|
||||
// match the order of socket type IDs
|
||||
// defined in socket_type.hpp.
|
||||
|
|
|
@ -578,9 +578,6 @@ namespace libtorrent
|
|||
|
||||
storage_interface* get_storage_impl() { return m_storage.get(); }
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
void assert_torrent_refcount() const;
|
||||
#endif
|
||||
private:
|
||||
|
||||
// if error is set and return value is 'no_error' or 'need_full_check'
|
||||
|
|
|
@ -283,7 +283,6 @@ namespace libtorrent
|
|||
, public request_callback
|
||||
, public peer_class_set
|
||||
, public std::enable_shared_from_this<torrent>
|
||||
, public list_node<torrent> // used for torrent activity LRU
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -326,25 +325,6 @@ namespace libtorrent
|
|||
// it will initialize the storage and the piece-picker
|
||||
void init();
|
||||
|
||||
// called every time we actually need the torrent_info
|
||||
// object to be fully loaded. If it isn't, this triggers
|
||||
// loading it from disk
|
||||
// the return value indicates success. If it failed to
|
||||
// load, the torrent will be set to an error state and
|
||||
// return false
|
||||
bool need_loaded();
|
||||
|
||||
// unload the torrent file to save memory
|
||||
void unload();
|
||||
// returns true if parsed successfully
|
||||
bool load(std::vector<char>& buffer);
|
||||
|
||||
// pinned torrents may not be unloaded
|
||||
bool is_pinned() const { return m_pinned; }
|
||||
void set_pinned(bool p);
|
||||
bool is_loaded() const { return m_torrent_file->is_loaded(); }
|
||||
bool should_be_loaded() const { return m_should_be_loaded; }
|
||||
|
||||
// find the peer that introduced us to the given endpoint. This is
|
||||
// used when trying to holepunch. We need the introducer so that we
|
||||
// can send a rendezvous connect message
|
||||
|
@ -1073,10 +1053,6 @@ namespace libtorrent
|
|||
m_links[aux::session_interface::torrent_state_updates].clear();
|
||||
}
|
||||
|
||||
void dec_refcount(char const* purpose);
|
||||
void inc_refcount(char const* purpose);
|
||||
int refcount() const { return m_refcount; }
|
||||
|
||||
void inc_num_connecting()
|
||||
{ ++m_num_connecting; }
|
||||
void dec_num_connecting()
|
||||
|
@ -1361,11 +1337,6 @@ namespace libtorrent
|
|||
// the number of pieces we completed the check of
|
||||
int m_num_checked_pieces = 0;
|
||||
|
||||
// the number of async. operations that need this torrent
|
||||
// loaded in RAM. having a refcount > 0 prevents it from
|
||||
// being unloaded.
|
||||
int m_refcount = 0;
|
||||
|
||||
// if the error ocurred on a file, this is the index of that file
|
||||
// there are a few special cases, when this is negative. See
|
||||
// set_error()
|
||||
|
@ -1584,16 +1555,6 @@ namespace libtorrent
|
|||
// more blocks to disk!
|
||||
bool m_deleted:1;
|
||||
|
||||
// pinned torrents are locked in RAM and won't be unloaded
|
||||
// in favor of more active torrents. When the torrent is added,
|
||||
// the user may choose to initialize this to 1, in which case
|
||||
// it will never be unloaded from RAM
|
||||
bool m_pinned:1;
|
||||
|
||||
// when this is false, we should unload the torrent as soon
|
||||
// as the no other async. job needs the torrent loaded
|
||||
bool m_should_be_loaded:1;
|
||||
|
||||
// ----
|
||||
|
||||
// the timestamp of the last piece passed for this torrent specified in
|
||||
|
@ -1654,24 +1615,6 @@ namespace libtorrent
|
|||
bool m_outstanding_check_files = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct torrent_ref_holder
|
||||
{
|
||||
torrent_ref_holder(torrent* t, char const* p)
|
||||
: m_torrent(t)
|
||||
, m_purpose(p)
|
||||
{
|
||||
if (m_torrent) m_torrent->inc_refcount(m_purpose);
|
||||
}
|
||||
|
||||
~torrent_ref_holder()
|
||||
{
|
||||
if (m_torrent) m_torrent->dec_refcount(m_purpose);
|
||||
}
|
||||
torrent* m_torrent;
|
||||
char const* m_purpose;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TORRENT_TORRENT_HPP_INCLUDED
|
||||
|
|
|
@ -1101,6 +1101,7 @@ namespace libtorrent
|
|||
void set_download_limit(int limit) const;
|
||||
int download_limit() const;
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
// A pinned torrent may not be unloaded by libtorrent. When the dynamic
|
||||
// loading and unloading of torrents is enabled (by setting a load
|
||||
// function on the session), this can be used to exempt certain torrents
|
||||
|
@ -1116,6 +1117,7 @@ namespace libtorrent
|
|||
// see dynamic-loading-of-torrent-files_.
|
||||
//
|
||||
void set_pinned(bool p) const;
|
||||
#endif
|
||||
|
||||
// ``set_sequential_download()`` enables or disables *sequential
|
||||
// download*. When enabled, the piece picker will pick pieces in sequence
|
||||
|
|
|
@ -501,10 +501,15 @@ namespace libtorrent
|
|||
// if a large file ends up being copied from one drive to another.
|
||||
bool moving_storage;
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
// true if this torrent is loaded into RAM. A torrent can be started
|
||||
// and still not loaded into RAM, in case it has not had any peers interested in it
|
||||
// yet. Torrents are loaded on demand.
|
||||
bool is_loaded;
|
||||
#else
|
||||
// hidden
|
||||
bool deprecated_is_loaded;
|
||||
#endif
|
||||
|
||||
// these are set to true if this torrent is allowed to announce to the
|
||||
// respective peer source. Whether they are true or false is determined by
|
||||
|
|
|
@ -1463,12 +1463,6 @@ namespace libtorrent
|
|||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
TORRENT_ASSERT(r.length <= m_disk_cache.block_size());
|
||||
TORRENT_ASSERT(r.length <= 16 * 1024);
|
||||
|
||||
|
@ -1583,12 +1577,6 @@ namespace libtorrent
|
|||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
TORRENT_ASSERT(r.length <= m_disk_cache.block_size());
|
||||
TORRENT_ASSERT(r.length <= 16 * 1024);
|
||||
|
||||
|
@ -1690,12 +1678,6 @@ namespace libtorrent
|
|||
void disk_io_thread::async_hash(piece_manager* storage, int piece, int flags
|
||||
, std::function<void(disk_io_job const*)> handler, void* requester)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
disk_io_job* j = allocate_job(disk_io_job::hash);
|
||||
j->storage = storage->shared_from_this();
|
||||
j->piece = piece;
|
||||
|
@ -1735,12 +1717,6 @@ namespace libtorrent
|
|||
void disk_io_thread::async_move_storage(piece_manager* storage, std::string const& p, int flags
|
||||
, std::function<void(disk_io_job const*)> handler)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
disk_io_job* j = allocate_job(disk_io_job::move_storage);
|
||||
j->storage = storage->shared_from_this();
|
||||
j->buffer.string = allocate_string_copy(p.c_str());
|
||||
|
@ -1764,12 +1740,6 @@ namespace libtorrent
|
|||
, int const options
|
||||
, std::function<void(disk_io_job const*)> handler)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
// remove cache blocks belonging to this torrent
|
||||
jobqueue_t completed_jobs;
|
||||
|
||||
|
@ -1817,12 +1787,6 @@ namespace libtorrent
|
|||
, std::vector<std::string>& links
|
||||
, std::function<void(disk_io_job const*)> handler)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
std::vector<std::string>* links_vector
|
||||
= new std::vector<std::string>();
|
||||
links_vector->swap(links);
|
||||
|
@ -1839,12 +1803,6 @@ namespace libtorrent
|
|||
void disk_io_thread::async_rename_file(piece_manager* storage, int index, std::string const& name
|
||||
, std::function<void(disk_io_job const*)> handler)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
disk_io_job* j = allocate_job(disk_io_job::rename_file);
|
||||
j->storage = storage->shared_from_this();
|
||||
j->piece = index;
|
||||
|
@ -1892,12 +1850,6 @@ namespace libtorrent
|
|||
void disk_io_thread::async_cache_piece(piece_manager* storage, int piece
|
||||
, std::function<void(disk_io_job const*)> handler)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
disk_io_job* j = allocate_job(disk_io_job::cache_piece);
|
||||
j->storage = storage->shared_from_this();
|
||||
j->piece = piece;
|
||||
|
@ -1909,12 +1861,6 @@ namespace libtorrent
|
|||
void disk_io_thread::async_finalize_file(piece_manager* storage, int file
|
||||
, std::function<void(disk_io_job const*)> handler)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
disk_io_job* j = allocate_job(disk_io_job::finalize_file);
|
||||
j->storage = storage->shared_from_this();
|
||||
j->piece = file;
|
||||
|
@ -1927,12 +1873,6 @@ namespace libtorrent
|
|||
void disk_io_thread::async_flush_piece(piece_manager* storage, int piece
|
||||
, std::function<void(disk_io_job const*)> handler)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
disk_io_job* j = allocate_job(disk_io_job::flush_piece);
|
||||
j->storage = storage->shared_from_this();
|
||||
j->piece = piece;
|
||||
|
@ -1953,12 +1893,6 @@ namespace libtorrent
|
|||
, std::vector<std::uint8_t> const& prios
|
||||
, std::function<void(disk_io_job const*)> handler)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
std::vector<std::uint8_t>* p = new std::vector<std::uint8_t>(prios);
|
||||
|
||||
disk_io_job* j = allocate_job(disk_io_job::file_priority);
|
||||
|
@ -2009,12 +1943,6 @@ namespace libtorrent
|
|||
void disk_io_thread::async_clear_piece(piece_manager* storage, int index
|
||||
, std::function<void(disk_io_job const*)> handler)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// the caller must increment the torrent refcount before
|
||||
// issuing an async disk request
|
||||
storage->assert_torrent_refcount();
|
||||
#endif
|
||||
|
||||
disk_io_job* j = allocate_job(disk_io_job::clear_piece);
|
||||
j->storage = storage->shared_from_this();
|
||||
j->piece = index;
|
||||
|
|
|
@ -2830,12 +2830,6 @@ namespace libtorrent
|
|||
|
||||
if (t->is_deleted()) return;
|
||||
|
||||
if (!t->need_loaded())
|
||||
{
|
||||
t->add_redundant_bytes(p.length, waste_reason::piece_unknown);
|
||||
return;
|
||||
}
|
||||
t->inc_refcount("async_write");
|
||||
m_disk_thread.async_write(&t->storage(), p, std::move(data)
|
||||
, std::bind(&peer_connection::on_disk_write_complete
|
||||
, self(), _1, p, t));
|
||||
|
@ -2974,9 +2968,6 @@ namespace libtorrent
|
|||
, peer_request p, std::shared_ptr<torrent> t)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
torrent_ref_holder h(t.get(), "async_write");
|
||||
if (t) t->dec_refcount("async_write");
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
if (should_log(peer_log_alert::info))
|
||||
{
|
||||
|
@ -5096,8 +5087,6 @@ namespace libtorrent
|
|||
#endif
|
||||
// this means we're in seed mode and we haven't yet
|
||||
// verified this piece (r.piece)
|
||||
if (!t->need_loaded()) return;
|
||||
t->inc_refcount("async_seed_hash");
|
||||
m_disk_thread.async_hash(&t->storage(), r.piece, 0
|
||||
, std::bind(&peer_connection::on_seed_mode_hashed, self(), _1)
|
||||
, this);
|
||||
|
@ -5129,13 +5118,11 @@ namespace libtorrent
|
|||
sent_a_piece = true;
|
||||
|
||||
// the callback function may be called immediately, instead of being posted
|
||||
if (!t->need_loaded()) return;
|
||||
|
||||
TORRENT_ASSERT(t->valid_metadata());
|
||||
TORRENT_ASSERT(r.piece >= 0);
|
||||
TORRENT_ASSERT(r.piece < t->torrent_file().num_pieces());
|
||||
|
||||
t->inc_refcount("async_read");
|
||||
m_disk_thread.async_read(&t->storage(), r
|
||||
, std::bind(&peer_connection::on_disk_read_complete
|
||||
, self(), _1, r, clock_type::now()), this);
|
||||
|
@ -5161,8 +5148,6 @@ namespace libtorrent
|
|||
INVARIANT_CHECK;
|
||||
|
||||
std::shared_ptr<torrent> t = m_torrent.lock();
|
||||
torrent_ref_holder h(t.get(), "async_seed_hash");
|
||||
if (t) t->dec_refcount("async_seed_hash");
|
||||
|
||||
TORRENT_ASSERT(m_outstanding_piece_verification > 0);
|
||||
--m_outstanding_piece_verification;
|
||||
|
@ -5177,8 +5162,6 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
// we're using the piece hashes here, we need the torrent to be loaded
|
||||
if (!t->need_loaded()) return;
|
||||
|
||||
if (!m_settings.get_bool(settings_pack::disable_hash_checks)
|
||||
&& sha1_hash(j->d.piece_hash) != t->torrent_file().hash_for_piece(j->piece))
|
||||
{
|
||||
|
@ -5235,9 +5218,6 @@ namespace libtorrent
|
|||
m_reading_bytes -= r.length;
|
||||
|
||||
std::shared_ptr<torrent> t = m_torrent.lock();
|
||||
torrent_ref_holder h(t.get(), "async_read");
|
||||
if (t) t->dec_refcount("async_read");
|
||||
|
||||
if (j->ret < 0)
|
||||
{
|
||||
if (!t)
|
||||
|
|
|
@ -1211,155 +1211,6 @@ namespace aux {
|
|||
? &m_download_rate : &m_upload_rate;
|
||||
}
|
||||
|
||||
// the back argument determines whether this bump causes the torrent
|
||||
// to be the most recently used or the least recently used. Putting
|
||||
// the torrent at the back of the queue makes it the most recently
|
||||
// used and the least likely to be evicted. This is the default.
|
||||
// if back is false, the torrent is moved to the front of the queue,
|
||||
// and made the most likely to be evicted. This is used for torrents
|
||||
// that are paused, to give up their slot among the loaded torrents
|
||||
void session_impl::bump_torrent(torrent* t, bool back)
|
||||
{
|
||||
if (t->is_aborted()) return;
|
||||
|
||||
bool new_torrent = false;
|
||||
|
||||
// if t is the only torrent in the LRU list, both
|
||||
// its prev and next links will be nullptr, even though
|
||||
// it's already in the list. Cover this case by also
|
||||
// checking to see if it's the first item
|
||||
if (t->next != nullptr || t->prev != nullptr || m_torrent_lru.front() == t)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
torrent* i = m_torrent_lru.front();
|
||||
while (i != nullptr && i != t) i = i->next;
|
||||
TORRENT_ASSERT(i == t);
|
||||
#endif
|
||||
|
||||
// this torrent is in the list already.
|
||||
// first remove it
|
||||
m_torrent_lru.erase(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
new_torrent = true;
|
||||
}
|
||||
|
||||
// pinned torrents should not be part of the LRU, since
|
||||
// the LRU is only used to evict torrents
|
||||
if (t->is_pinned()) return;
|
||||
|
||||
if (back)
|
||||
m_torrent_lru.push_back(t);
|
||||
else
|
||||
m_torrent_lru.push_front(t);
|
||||
|
||||
if (new_torrent) evict_torrents_except(t);
|
||||
}
|
||||
|
||||
void session_impl::evict_torrent(torrent* t)
|
||||
{
|
||||
TORRENT_ASSERT(!t->is_pinned());
|
||||
|
||||
// if there's no user-load function set, we cannot evict
|
||||
// torrents. The feature is not enabled
|
||||
if (!m_user_load_torrent) return;
|
||||
|
||||
// if it's already evicted, there's nothing to do
|
||||
if (!t->is_loaded() || !t->should_be_loaded()) return;
|
||||
|
||||
TORRENT_ASSERT(t->next != nullptr || t->prev != nullptr || m_torrent_lru.front() == t);
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
torrent* i = m_torrent_lru.front();
|
||||
while (i != nullptr && i != t) i = i->next;
|
||||
TORRENT_ASSERT(i == t);
|
||||
#endif
|
||||
|
||||
int loaded_limit = m_settings.get_int(settings_pack::active_loaded_limit);
|
||||
|
||||
// 0 means unlimited, never evict anything
|
||||
if (loaded_limit == 0) return;
|
||||
|
||||
if (m_torrent_lru.size() > loaded_limit)
|
||||
{
|
||||
// just evict the torrent
|
||||
m_stats_counters.inc_stats_counter(counters::torrent_evicted_counter);
|
||||
TORRENT_ASSERT(t->is_pinned() == false);
|
||||
t->unload();
|
||||
m_torrent_lru.erase(t);
|
||||
return;
|
||||
}
|
||||
|
||||
// move this torrent to be the first to be evicted whenever
|
||||
// another torrent need its slot
|
||||
bump_torrent(t, false);
|
||||
}
|
||||
|
||||
void session_impl::evict_torrents_except(torrent* ignore)
|
||||
{
|
||||
if (!m_user_load_torrent) return;
|
||||
|
||||
int loaded_limit = m_settings.get_int(settings_pack::active_loaded_limit);
|
||||
|
||||
// 0 means unlimited, never evict anything
|
||||
if (loaded_limit == 0) return;
|
||||
|
||||
// if the torrent we're ignoring (i.e. making room for), allow
|
||||
// one more torrent in the list.
|
||||
if (ignore->next != nullptr || ignore->prev != nullptr || m_torrent_lru.front() == ignore)
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
torrent* i = m_torrent_lru.front();
|
||||
while (i != nullptr && i != ignore) i = i->next;
|
||||
TORRENT_ASSERT(i == ignore);
|
||||
#endif
|
||||
++loaded_limit;
|
||||
}
|
||||
|
||||
while (m_torrent_lru.size() >= loaded_limit)
|
||||
{
|
||||
// we're at the limit of loaded torrents. Find the least important
|
||||
// torrent and unload it. This is done with an LRU.
|
||||
torrent* i = m_torrent_lru.front();
|
||||
|
||||
if (i == ignore)
|
||||
{
|
||||
i = i->next;
|
||||
if (i == nullptr) break;
|
||||
}
|
||||
m_stats_counters.inc_stats_counter(counters::torrent_evicted_counter);
|
||||
TORRENT_ASSERT(i->is_pinned() == false);
|
||||
i->unload();
|
||||
m_torrent_lru.erase(i);
|
||||
}
|
||||
}
|
||||
|
||||
bool session_impl::load_torrent(torrent* t)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
evict_torrents_except(t);
|
||||
|
||||
// we wouldn't be loading the torrent if it was already
|
||||
// in the LRU (and loaded)
|
||||
TORRENT_ASSERT(t->next == nullptr && t->prev == nullptr && m_torrent_lru.front() != t);
|
||||
TORRENT_ASSERT(m_user_load_torrent);
|
||||
|
||||
// now, load t into RAM
|
||||
std::vector<char> buffer;
|
||||
error_code ec;
|
||||
m_user_load_torrent(t->info_hash(), buffer, ec);
|
||||
if (ec)
|
||||
{
|
||||
t->set_error(ec, torrent_status::error_file_metadata);
|
||||
t->pause(false);
|
||||
return false;
|
||||
}
|
||||
bool ret = t->load(buffer);
|
||||
if (ret) bump_torrent(t);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void session_impl::deferred_submit_jobs()
|
||||
{
|
||||
if (m_deferred_submit_disk_jobs) return;
|
||||
|
@ -4379,8 +4230,6 @@ namespace aux {
|
|||
#else
|
||||
TORRENT_UNUSED(uuid);
|
||||
#endif
|
||||
|
||||
TORRENT_ASSERT(m_torrents.size() >= m_torrent_lru.size());
|
||||
}
|
||||
|
||||
void session_impl::set_queue_position(torrent* me, int p)
|
||||
|
@ -4789,8 +4638,6 @@ namespace aux {
|
|||
|
||||
m_torrents.insert(std::make_pair(params.info_hash, torrent_ptr));
|
||||
|
||||
TORRENT_ASSERT(m_torrents.size() >= m_torrent_lru.size());
|
||||
|
||||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||
static char const req2[4] = {'r', 'e', 'q', '2'};
|
||||
hasher h(req2);
|
||||
|
@ -4800,12 +4647,6 @@ namespace aux {
|
|||
m_obfuscated_torrents.insert(std::make_pair(h.final(), torrent_ptr));
|
||||
#endif
|
||||
|
||||
if (torrent_ptr->is_pinned() == false)
|
||||
{
|
||||
evict_torrents_except(torrent_ptr.get());
|
||||
bump_torrent(torrent_ptr.get());
|
||||
}
|
||||
|
||||
// if this insert made the hash grow, the iterators became invalid
|
||||
// we need to reset them
|
||||
if (m_torrents.load_factor() < load_factor)
|
||||
|
@ -5137,12 +4978,6 @@ namespace aux {
|
|||
}
|
||||
}
|
||||
|
||||
if (m_torrent_lru.size() > 0
|
||||
&& (t.prev != nullptr || t.next != nullptr || m_torrent_lru.front() == &t))
|
||||
m_torrent_lru.erase(&t);
|
||||
|
||||
TORRENT_ASSERT(t.prev == nullptr && t.next == nullptr);
|
||||
|
||||
tptr->update_gauge();
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
|
@ -5157,8 +4992,6 @@ namespace aux {
|
|||
|
||||
m_torrents.erase(i);
|
||||
|
||||
TORRENT_ASSERT(m_torrents.size() >= m_torrent_lru.size());
|
||||
|
||||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||
static char const req2[4] = {'r', 'e', 'q', '2'};
|
||||
hasher h(req2);
|
||||
|
@ -5951,22 +5784,6 @@ namespace aux {
|
|||
fclose(f);
|
||||
}
|
||||
#endif
|
||||
|
||||
// clear the torrent LRU. We do this to avoid having the torrent
|
||||
// destructor assert because it's still linked into the lru list
|
||||
#if TORRENT_USE_ASSERTS
|
||||
list_node<torrent>* i = m_torrent_lru.get_all();
|
||||
// clear the prev and next pointers in all torrents
|
||||
// to avoid the assert when destructing them
|
||||
while (i)
|
||||
{
|
||||
list_node<torrent>* tmp = i;
|
||||
i = i->next;
|
||||
tmp->next = nullptr;
|
||||
tmp->prev = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
|
@ -6834,8 +6651,6 @@ namespace aux {
|
|||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
TORRENT_ASSERT(m_torrents.size() >= m_torrent_lru.size());
|
||||
|
||||
if (m_settings.get_int(settings_pack::unchoke_slots_limit) < 0
|
||||
&& m_settings.get_int(settings_pack::choking_algorithm) == settings_pack::fixed_slots_choker)
|
||||
TORRENT_ASSERT(m_stats_counters[counters::num_unchoke_slots] == (std::numeric_limits<int>::max)());
|
||||
|
@ -6850,16 +6665,6 @@ namespace aux {
|
|||
}
|
||||
}
|
||||
|
||||
std::unordered_set<torrent*> unique_torrents;
|
||||
for (list_iterator<torrent> i = m_torrent_lru.iterate(); i.get(); i.next())
|
||||
{
|
||||
torrent* t = i.get();
|
||||
TORRENT_ASSERT(t->is_loaded());
|
||||
TORRENT_ASSERT(unique_torrents.count(t) == 0);
|
||||
unique_torrents.insert(t);
|
||||
}
|
||||
TORRENT_ASSERT(unique_torrents.size() == m_torrent_lru.size());
|
||||
|
||||
int torrent_state_gauges[counters::num_error_torrents - counters::num_checking_torrents + 1];
|
||||
memset(torrent_state_gauges, 0, sizeof(torrent_state_gauges));
|
||||
|
||||
|
|
|
@ -219,10 +219,6 @@ namespace libtorrent
|
|||
// IP filter applied to them.
|
||||
METRIC(ses, non_filter_torrents)
|
||||
|
||||
// the number of torrents that are currently loaded
|
||||
METRIC(ses, num_loaded_torrents)
|
||||
METRIC(ses, num_pinned_torrents)
|
||||
|
||||
// these count the number of times a piece has passed the
|
||||
// hash check, the number of times a piece was successfully
|
||||
// written to disk and the number of total possible pieces
|
||||
|
|
|
@ -1484,17 +1484,6 @@ namespace libtorrent
|
|||
|
||||
piece_manager::~piece_manager() = default;
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
void piece_manager::assert_torrent_refcount() const
|
||||
{
|
||||
if (!m_torrent) return;
|
||||
// sorry about this layer violation, but it's
|
||||
// quite convenient to make sure the torrent won't
|
||||
// get unloaded under our feet later
|
||||
TORRENT_ASSERT(static_cast<torrent*>(m_torrent.get())->refcount() > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int piece_manager::check_no_fastresume(storage_error& ec)
|
||||
{
|
||||
if (!m_storage->settings().get_bool(settings_pack::no_recheck_incomplete_resume))
|
||||
|
|
319
src/torrent.cpp
319
src/torrent.cpp
|
@ -214,8 +214,6 @@ namespace libtorrent
|
|||
, m_is_active_finished(false)
|
||||
, m_ssl_torrent(false)
|
||||
, m_deleted(false)
|
||||
, m_pinned((p.flags & add_torrent_params::flag_pinned) != 0)
|
||||
, m_should_be_loaded(true)
|
||||
, m_auto_managed((p.flags & add_torrent_params::flag_auto_managed) != 0)
|
||||
, m_current_gauge_state(no_gauge_state)
|
||||
, m_moving_storage(false)
|
||||
|
@ -230,11 +228,6 @@ namespace libtorrent
|
|||
// TODO: 2 p should probably be moved in here
|
||||
m_add_torrent_params.reset(new add_torrent_params(p));
|
||||
|
||||
if (m_pinned)
|
||||
inc_stats_counter(counters::num_pinned_torrents);
|
||||
|
||||
inc_stats_counter(counters::num_loaded_torrents);
|
||||
|
||||
#if TORRENT_USE_UNC_PATHS
|
||||
m_save_path = canonicalize_path(m_save_path);
|
||||
#endif
|
||||
|
@ -668,17 +661,7 @@ namespace libtorrent
|
|||
if (!m_name && !m_url.empty()) m_name.reset(new std::string(m_url));
|
||||
#endif
|
||||
|
||||
// if we don't have metadata, make this torrent pinned. The
|
||||
// client may unpin it once we have metadata and it has had
|
||||
// a chance to save it on the metadata_received_alert
|
||||
if (!valid_metadata())
|
||||
{
|
||||
if (!m_pinned && m_refcount == 0)
|
||||
inc_stats_counter(counters::num_pinned_torrents);
|
||||
|
||||
m_pinned = true;
|
||||
}
|
||||
else
|
||||
if (valid_metadata())
|
||||
{
|
||||
inc_stats_counter(counters::num_total_pieces_added
|
||||
, m_torrent_file->num_pieces());
|
||||
|
@ -808,7 +791,6 @@ namespace libtorrent
|
|||
torrent::~torrent()
|
||||
{
|
||||
TORRENT_ASSERT(m_abort);
|
||||
TORRENT_ASSERT(prev == nullptr && next == nullptr);
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
for (int i = 0; i < aux::session_interface::num_torrent_lists; ++i)
|
||||
|
@ -818,14 +800,6 @@ namespace libtorrent
|
|||
}
|
||||
#endif
|
||||
|
||||
TORRENT_ASSERT(m_refcount == 0);
|
||||
|
||||
if (m_pinned)
|
||||
inc_stats_counter(counters::num_pinned_torrents, -1);
|
||||
|
||||
if (is_loaded())
|
||||
inc_stats_counter(counters::num_loaded_torrents, -1);
|
||||
|
||||
// The invariant can't be maintained here, since the torrent
|
||||
// is being destructed, all weak references to it have been
|
||||
// reset, which means that all its peers already have an
|
||||
|
@ -882,17 +856,9 @@ namespace libtorrent
|
|||
r.piece = piece;
|
||||
r.start = 0;
|
||||
rp->blocks_left = blocks_in_piece;
|
||||
if (!need_loaded())
|
||||
{
|
||||
rp->piece_data.reset();
|
||||
m_ses.alerts().emplace_alert<read_piece_alert>(
|
||||
get_handle(), r.piece, rp->piece_data, 0);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < blocks_in_piece; ++i, r.start += block_size())
|
||||
{
|
||||
r.length = (std::min)(piece_size - r.start, block_size());
|
||||
inc_refcount("read_piece");
|
||||
m_ses.disk_thread().async_read(&storage(), r
|
||||
, std::bind(&torrent::on_disk_read_complete
|
||||
, shared_from_this(), _1, r, rp), reinterpret_cast<void*>(1));
|
||||
|
@ -1162,9 +1128,6 @@ namespace libtorrent
|
|||
, std::shared_ptr<read_piece_struct> rp)
|
||||
{
|
||||
// hold a reference until this function returns
|
||||
torrent_ref_holder h(this, "read_piece");
|
||||
|
||||
dec_refcount("read_piece");
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
disk_buffer_holder buffer(m_ses, *j);
|
||||
|
@ -1284,13 +1247,6 @@ namespace libtorrent
|
|||
}
|
||||
std::memcpy(buffer.get(), data + p.start, p.length);
|
||||
|
||||
if (!need_loaded())
|
||||
{
|
||||
// failed to load .torrent file
|
||||
picker().dec_refcount(piece, nullptr);
|
||||
return;
|
||||
}
|
||||
inc_refcount("add_piece");
|
||||
m_stats_counters.inc_stats_counter(counters::queued_write_bytes, p.length);
|
||||
m_ses.disk_thread().async_write(&storage(), p, std::move(buffer)
|
||||
, std::bind(&torrent::on_disk_write_complete
|
||||
|
@ -1327,10 +1283,6 @@ namespace libtorrent
|
|||
void torrent::on_disk_write_complete(disk_io_job const* j
|
||||
, peer_request p)
|
||||
{
|
||||
// hold a reference until this function returns
|
||||
torrent_ref_holder h(this, "add_piece");
|
||||
|
||||
dec_refcount("add_piece");
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
schedule_storage_tick();
|
||||
|
@ -1709,7 +1661,6 @@ namespace libtorrent
|
|||
debug_log("init torrent: %s", torrent_file().name().c_str());
|
||||
#endif
|
||||
|
||||
if (!need_loaded()) return;
|
||||
TORRENT_ASSERT(valid_metadata());
|
||||
TORRENT_ASSERT(m_torrent_file->num_files() > 0);
|
||||
TORRENT_ASSERT(m_torrent_file->total_size() >= 0);
|
||||
|
@ -1882,8 +1833,6 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
if (!need_loaded()) return;
|
||||
|
||||
if (num_pad_files > 0)
|
||||
m_picker->set_num_pad_files(num_pad_files);
|
||||
|
||||
|
@ -1943,7 +1892,6 @@ namespace libtorrent
|
|||
}
|
||||
#endif // TORRENT_DISABLE_MUTABLE_TORRENTS
|
||||
|
||||
inc_refcount("check_fastresume");
|
||||
// async_check_files will gut links
|
||||
#if TORRENT_USE_ASSERTS
|
||||
TORRENT_ASSERT(m_outstanding_check_files == false);
|
||||
|
@ -1961,152 +1909,6 @@ namespace libtorrent
|
|||
|
||||
maybe_done_flushing();
|
||||
}
|
||||
|
||||
bool torrent::need_loaded()
|
||||
{
|
||||
m_should_be_loaded = true;
|
||||
|
||||
// if we don't have the metadata yet, pretend the file is loaded
|
||||
if (!m_torrent_file->is_valid()
|
||||
|| m_torrent_file->is_loaded())
|
||||
{
|
||||
// bump this torrent to the top of the torrent LRU of
|
||||
// which torrents are most active
|
||||
m_ses.bump_torrent(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// load the specified torrent and also evict one torrent,
|
||||
// except for the one specified. if we're not at our limit
|
||||
// yet, no torrent is evicted
|
||||
return m_ses.load_torrent(this);
|
||||
}
|
||||
|
||||
void torrent::dec_refcount(char const* purpose)
|
||||
{
|
||||
TORRENT_UNUSED(purpose);
|
||||
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
TORRENT_ASSERT(m_refcount > 0);
|
||||
--m_refcount;
|
||||
if (m_refcount == 0)
|
||||
{
|
||||
if (!m_pinned)
|
||||
inc_stats_counter(counters::num_pinned_torrents, -1);
|
||||
|
||||
if (m_should_be_loaded == false)
|
||||
unload();
|
||||
}
|
||||
}
|
||||
|
||||
void torrent::inc_refcount(char const* purpose)
|
||||
{
|
||||
TORRENT_UNUSED(purpose);
|
||||
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
TORRENT_ASSERT(is_loaded());
|
||||
++m_refcount;
|
||||
if (!m_pinned && m_refcount == 1)
|
||||
inc_stats_counter(counters::num_pinned_torrents);
|
||||
}
|
||||
|
||||
void torrent::set_pinned(bool p)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
if (m_pinned == p) return;
|
||||
m_pinned = p;
|
||||
|
||||
if (m_refcount == 0)
|
||||
inc_stats_counter(counters::num_pinned_torrents, p ? 1 : -1);
|
||||
|
||||
// if the torrent was just un-pinned, we need to insert
|
||||
// it into the LRU
|
||||
m_ses.bump_torrent(this, true);
|
||||
}
|
||||
|
||||
bool torrent::load(std::vector<char>& buffer)
|
||||
{
|
||||
error_code ec;
|
||||
m_torrent_file->load(&buffer[0], int(buffer.size()), ec);
|
||||
if (ec)
|
||||
{
|
||||
set_error(ec, torrent_status::error_file_metadata);
|
||||
return false;
|
||||
}
|
||||
|
||||
state_updated();
|
||||
|
||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||
// create the extensions again
|
||||
|
||||
// TODO: should we store add_torrent_params::userdata
|
||||
// in torrent just to have it available here?
|
||||
//m_ses.add_extensions_to_torrent(shared_from_this(), nullptr);
|
||||
|
||||
// and call on_load() on them
|
||||
for (auto const& e : m_extensions)
|
||||
{
|
||||
TORRENT_TRY {
|
||||
e->on_load();
|
||||
} TORRENT_CATCH (std::exception const&) {}
|
||||
}
|
||||
#endif
|
||||
|
||||
inc_stats_counter(counters::num_loaded_torrents);
|
||||
|
||||
construct_storage();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// this is called when this torrent hasn't been active in long enough
|
||||
// to warrant swapping it out, in favor of a more active torrent.
|
||||
void torrent::unload()
|
||||
{
|
||||
TORRENT_ASSERT(is_loaded());
|
||||
|
||||
// pinned torrents are not allowed to be swapped out
|
||||
TORRENT_ASSERT(!m_pinned);
|
||||
|
||||
m_should_be_loaded = false;
|
||||
|
||||
// make sure it's not unloaded in the middle of some operation that uses it
|
||||
if (m_refcount > 0) return;
|
||||
|
||||
// call on_unload() on extensions
|
||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||
for (auto const& e : m_extensions)
|
||||
{
|
||||
TORRENT_TRY {
|
||||
e->on_unload();
|
||||
} TORRENT_CATCH (std::exception const&) {}
|
||||
}
|
||||
|
||||
// also remove extensions and re-instantiate them when the torrent is loaded again
|
||||
// they end up using a significant amount of memory
|
||||
// TODO: there may be peer extensions relying on the torrent extension
|
||||
// still being alive. Only do this if there are no peers. And when the last peer
|
||||
// is disconnected, if the torrent is unloaded, clear the extensions
|
||||
// m_extensions.clear();
|
||||
#endif
|
||||
|
||||
// someone else holds a reference to the torrent_info
|
||||
// make the torrent release its reference to it,
|
||||
// after making a copy and then unloading that version
|
||||
// as soon as the user is done with its copy of torrent_info
|
||||
// it will be freed, and we'll have the unloaded version left
|
||||
if (!m_torrent_file.unique())
|
||||
m_torrent_file = std::make_shared<torrent_info>(*m_torrent_file);
|
||||
|
||||
m_torrent_file->unload();
|
||||
inc_stats_counter(counters::num_loaded_torrents, -1);
|
||||
|
||||
m_storage.reset();
|
||||
|
||||
state_updated();
|
||||
}
|
||||
|
||||
bt_peer_connection* torrent::find_introducer(tcp::endpoint const& ep) const
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||
|
@ -2145,7 +1947,6 @@ namespace libtorrent
|
|||
void torrent::on_resume_data_checked(disk_io_job const* j)
|
||||
{
|
||||
// hold a reference until this function returns
|
||||
torrent_ref_holder h(this, "check_fastresume");
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
TORRENT_ASSERT(m_outstanding_check_files);
|
||||
|
@ -2160,7 +1961,6 @@ namespace libtorrent
|
|||
// it at the end of the function.
|
||||
bool const need_save_resume_data = m_need_save_resume_data;
|
||||
|
||||
dec_refcount("check_fastresume");
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
if (j->ret == piece_manager::fatal_disk_error)
|
||||
|
@ -2361,8 +2161,6 @@ namespace libtorrent
|
|||
|
||||
clear_error();
|
||||
|
||||
if (!need_loaded()) return;
|
||||
|
||||
disconnect_all(errors::stopping_torrent, op_bittorrent);
|
||||
stop_announcing();
|
||||
|
||||
|
@ -2404,7 +2202,6 @@ namespace libtorrent
|
|||
m_add_torrent_params.reset();
|
||||
|
||||
std::vector<std::string> links;
|
||||
inc_refcount("force_recheck");
|
||||
m_ses.disk_thread().async_check_files(m_storage.get(), nullptr
|
||||
, links, std::bind(&torrent::on_force_recheck
|
||||
, shared_from_this(), _1));
|
||||
|
@ -2415,9 +2212,6 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
// hold a reference until this function returns
|
||||
torrent_ref_holder h(this, "force_recheck");
|
||||
|
||||
dec_refcount("force_recheck");
|
||||
state_updated();
|
||||
|
||||
if (m_abort) return;
|
||||
|
@ -2471,17 +2265,8 @@ namespace libtorrent
|
|||
num_outstanding -= (m_checking_piece - m_num_checked_pieces);
|
||||
if (num_outstanding < 0) num_outstanding = 0;
|
||||
|
||||
if (!need_loaded())
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
debug_log("start_checking, need_loaded() failed");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < num_outstanding; ++i)
|
||||
{
|
||||
inc_refcount("start_checking");
|
||||
m_ses.disk_thread().async_hash(m_storage.get(), m_checking_piece++
|
||||
, disk_io_job::sequential_access | disk_io_job::volatile_read
|
||||
, std::bind(&torrent::on_piece_hashed
|
||||
|
@ -2497,14 +2282,9 @@ namespace libtorrent
|
|||
// of existing files
|
||||
void torrent::on_piece_hashed(disk_io_job const* j)
|
||||
{
|
||||
// hold a reference until this function returns
|
||||
torrent_ref_holder h(this, "start_checking");
|
||||
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
INVARIANT_CHECK;
|
||||
|
||||
dec_refcount("start_checking");
|
||||
|
||||
if (m_abort) return;
|
||||
|
||||
if (j->ret == piece_manager::disk_check_aborted)
|
||||
|
@ -2569,15 +2349,6 @@ namespace libtorrent
|
|||
|
||||
m_progress_ppm = std::int64_t(m_num_checked_pieces) * 1000000 / torrent_file().num_pieces();
|
||||
|
||||
// we're using the piece hashes here, we need the torrent to be loaded
|
||||
if (!need_loaded())
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
debug_log("on_piece_hashed, need_loaded failed");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
if (settings().get_bool(settings_pack::disable_hash_checks)
|
||||
|| sha1_hash(j->d.piece_hash) == m_torrent_file->hash_for_piece(j->piece))
|
||||
{
|
||||
|
@ -2623,15 +2394,6 @@ namespace libtorrent
|
|||
return;
|
||||
}
|
||||
|
||||
if (!need_loaded())
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
debug_log("on_piece_hashed, need_loaded failed");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
inc_refcount("start_checking");
|
||||
m_ses.disk_thread().async_hash(m_storage.get(), m_checking_piece++
|
||||
, disk_io_job::sequential_access | disk_io_job::volatile_read
|
||||
, std::bind(&torrent::on_piece_hashed
|
||||
|
@ -3748,10 +3510,6 @@ namespace libtorrent
|
|||
// subtract padding files
|
||||
if (m_padding > 0)
|
||||
{
|
||||
// this is a bit unfortunate
|
||||
// (both the const cast and the requirement to load the torrent)
|
||||
if (!const_cast<torrent*>(this)->need_loaded()) return;
|
||||
|
||||
file_storage const& files = m_torrent_file->files();
|
||||
for (int i = 0; i < files.num_files(); ++i)
|
||||
{
|
||||
|
@ -3909,10 +3667,6 @@ namespace libtorrent
|
|||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
torrent_ref_holder h(this, "verify_piece");
|
||||
|
||||
dec_refcount("verify_piece");
|
||||
|
||||
if (m_abort) return;
|
||||
|
||||
int ret = j->ret;
|
||||
|
@ -3924,17 +3678,11 @@ namespace libtorrent
|
|||
{
|
||||
handle_disk_error(j);
|
||||
}
|
||||
// we're using the piece hashes here, we need the torrent to be loaded
|
||||
else if (need_loaded())
|
||||
else
|
||||
{
|
||||
if (sha1_hash(j->d.piece_hash) != m_torrent_file->hash_for_piece(j->piece))
|
||||
ret = -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// failing to load the .torrent file counts as disk failure
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
// 0: success, piece passed check
|
||||
// -1: disk failure
|
||||
|
@ -3961,8 +3709,6 @@ namespace libtorrent
|
|||
|
||||
TORRENT_ASSERT(!m_picker->have_piece(j->piece));
|
||||
|
||||
// picker().mark_as_done_checking(j->piece);
|
||||
|
||||
state_updated();
|
||||
|
||||
// even though the piece passed the hash-check
|
||||
|
@ -4573,7 +4319,6 @@ namespace libtorrent
|
|||
// the torrent object from there
|
||||
if (m_storage.get())
|
||||
{
|
||||
inc_refcount("release_files");
|
||||
m_ses.disk_thread().async_stop_torrent(m_storage.get()
|
||||
, std::bind(&torrent::on_cache_flushed, shared_from_this(), _1));
|
||||
}
|
||||
|
@ -4630,9 +4375,6 @@ namespace libtorrent
|
|||
// seeded by any peer
|
||||
TORRENT_ASSERT(m_super_seeding);
|
||||
|
||||
if (!need_loaded())
|
||||
return -1;
|
||||
|
||||
// do a linear search from the first piece
|
||||
int min_availability = 9999;
|
||||
std::vector<int> avail_vec;
|
||||
|
@ -4673,7 +4415,6 @@ namespace libtorrent
|
|||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
dec_refcount("delete_files");
|
||||
if (j->ret != 0)
|
||||
{
|
||||
if (alerts().should_post<torrent_delete_failed_alert>())
|
||||
|
@ -4689,7 +4430,6 @@ namespace libtorrent
|
|||
void torrent::on_file_renamed(disk_io_job const* j)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
dec_refcount("rename_file");
|
||||
|
||||
if (j->ret == 0)
|
||||
{
|
||||
|
@ -5168,10 +4908,7 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
void torrent::on_file_priority()
|
||||
{
|
||||
dec_refcount("file_priority");
|
||||
}
|
||||
void torrent::on_file_priority() {}
|
||||
|
||||
void torrent::prioritize_files(std::vector<int> const& files)
|
||||
{
|
||||
|
@ -5203,7 +4940,6 @@ namespace libtorrent
|
|||
// storage may be nullptr during construction and shutdown
|
||||
if (m_torrent_file->num_pieces() > 0 && m_storage)
|
||||
{
|
||||
inc_refcount("file_priority");
|
||||
m_ses.disk_thread().async_set_file_priority(m_storage.get()
|
||||
, m_file_priority, std::bind(&torrent::on_file_priority, this));
|
||||
}
|
||||
|
@ -5242,7 +4978,6 @@ namespace libtorrent
|
|||
// storage may be nullptr during shutdown
|
||||
if (m_storage)
|
||||
{
|
||||
inc_refcount("file_priority");
|
||||
m_ses.disk_thread().async_set_file_priority(m_storage.get()
|
||||
, m_file_priority, std::bind(&torrent::on_file_priority, this));
|
||||
}
|
||||
|
@ -6342,8 +6077,6 @@ namespace libtorrent
|
|||
std::shared_ptr<const torrent_info> torrent::get_torrent_copy()
|
||||
{
|
||||
if (!m_torrent_file->is_valid()) return std::shared_ptr<const torrent_info>();
|
||||
if (!need_loaded()) return std::shared_ptr<const torrent_info>();
|
||||
|
||||
return m_torrent_file;
|
||||
}
|
||||
|
||||
|
@ -7719,7 +7452,6 @@ namespace libtorrent
|
|||
if (m_storage)
|
||||
{
|
||||
// we need to keep the object alive during this operation
|
||||
inc_refcount("release_files");
|
||||
m_ses.disk_thread().async_release_files(m_storage.get()
|
||||
, std::bind(&torrent::on_cache_flushed, shared_from_this(), _1));
|
||||
}
|
||||
|
@ -8021,7 +7753,6 @@ namespace libtorrent
|
|||
return;
|
||||
}
|
||||
|
||||
inc_refcount("rename_file");
|
||||
m_ses.disk_thread().async_rename_file(m_storage.get(), index, name
|
||||
, std::bind(&torrent::on_file_renamed, shared_from_this(), _1));
|
||||
return;
|
||||
|
@ -8058,7 +7789,6 @@ namespace libtorrent
|
|||
#else
|
||||
std::string const& path = save_path;
|
||||
#endif
|
||||
inc_refcount("move_storage");
|
||||
m_ses.disk_thread().async_move_storage(m_storage.get(), path, flags
|
||||
, std::bind(&torrent::on_storage_moved, shared_from_this(), _1));
|
||||
m_moving_storage = true;
|
||||
|
@ -8085,7 +7815,6 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
m_moving_storage = false;
|
||||
dec_refcount("move_storage");
|
||||
if (j->ret == piece_manager::no_error || j->ret == piece_manager::need_full_check)
|
||||
{
|
||||
if (alerts().should_post<storage_moved_alert>())
|
||||
|
@ -8171,8 +7900,6 @@ namespace libtorrent
|
|||
}
|
||||
#endif
|
||||
|
||||
if (!is_loaded()) return;
|
||||
|
||||
TORRENT_ASSERT(want_peers_download() == m_links[aux::session_interface::torrent_want_peers_download].in_list());
|
||||
TORRENT_ASSERT(want_peers_finished() == m_links[aux::session_interface::torrent_want_peers_finished].in_list());
|
||||
TORRENT_ASSERT(want_tick() == m_links[aux::session_interface::torrent_want_tick].in_list());
|
||||
|
@ -8526,7 +8253,6 @@ namespace libtorrent
|
|||
if (m_storage.get())
|
||||
{
|
||||
TORRENT_ASSERT(m_storage);
|
||||
inc_refcount("delete_files");
|
||||
m_ses.disk_thread().async_delete_files(m_storage.get(), options
|
||||
, std::bind(&torrent::on_files_deleted, shared_from_this(), _1));
|
||||
m_deleted = true;
|
||||
|
@ -8801,22 +8527,6 @@ namespace libtorrent
|
|||
m_save_resume_flags = std::uint8_t(flags);
|
||||
state_updated();
|
||||
|
||||
if (!need_loaded())
|
||||
{
|
||||
alerts().emplace_alert<save_resume_data_failed_alert>(get_handle()
|
||||
, m_error);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
// storage may be nullptr during shutdown
|
||||
if (!m_storage)
|
||||
{
|
||||
TORRENT_ASSERT(m_abort);
|
||||
alerts().emplace_alert<save_resume_data_failed_alert>(get_handle()
|
||||
, boost::asio::error::operation_aborted);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
if ((flags & torrent_handle::flush_disk_cache) && m_storage.get())
|
||||
m_ses.disk_thread().async_release_files(m_storage.get());
|
||||
|
||||
|
@ -8847,14 +8557,12 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(m_abort);
|
||||
return;
|
||||
}
|
||||
inc_refcount("release_files");
|
||||
m_ses.disk_thread().async_release_files(m_storage.get()
|
||||
, std::bind(&torrent::on_cache_flushed, shared_from_this(), _1));
|
||||
}
|
||||
|
||||
void torrent::on_cache_flushed(disk_io_job const*)
|
||||
{
|
||||
dec_refcount("release_files");
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
||||
if (m_ses.is_aborted()) return;
|
||||
|
@ -9006,12 +8714,6 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
stop_announcing();
|
||||
|
||||
// if the torrent is pinned, we should not unload it
|
||||
if (!is_pinned())
|
||||
{
|
||||
m_ses.evict_torrent(this);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
|
@ -9400,7 +9102,7 @@ namespace libtorrent
|
|||
set_upload_mode(false);
|
||||
}
|
||||
|
||||
if (m_storage_tick > 0 && is_loaded())
|
||||
if (m_storage_tick > 0)
|
||||
{
|
||||
--m_storage_tick;
|
||||
if (m_storage_tick == 0 && m_storage)
|
||||
|
@ -10611,7 +10313,6 @@ namespace libtorrent
|
|||
|
||||
TORRENT_ASSERT(m_storage.get());
|
||||
|
||||
inc_refcount("verify_piece");
|
||||
m_ses.disk_thread().async_hash(m_storage.get(), piece, 0
|
||||
, std::bind(&torrent::on_piece_verified, shared_from_this(), _1)
|
||||
, reinterpret_cast<void*>(1));
|
||||
|
@ -10694,7 +10395,6 @@ namespace libtorrent
|
|||
return;
|
||||
}
|
||||
|
||||
if (!need_loaded()) return;
|
||||
fp.resize(m_torrent_file->num_files(), 1.f);
|
||||
if (is_seed()) return;
|
||||
|
||||
|
@ -10718,8 +10418,6 @@ namespace libtorrent
|
|||
return;
|
||||
}
|
||||
|
||||
if (!need_loaded()) return;
|
||||
|
||||
// if we're a seed, we don't have an m_file_progress anyway
|
||||
// since we don't need one. We know we have all files
|
||||
// just fill in the full file sizes as a shortcut
|
||||
|
@ -10749,11 +10447,6 @@ namespace libtorrent
|
|||
|
||||
std::vector<piece_picker::downloading_piece> q = m_picker->get_download_queue();
|
||||
|
||||
if (!q.empty())
|
||||
{
|
||||
if (!const_cast<torrent&>(*this).need_loaded()) return;
|
||||
}
|
||||
|
||||
file_storage const& fs = m_torrent_file->files();
|
||||
for (std::vector<piece_picker::downloading_piece>::const_iterator
|
||||
i = q.begin(), end(q.end()); i != end; ++i)
|
||||
|
@ -11011,7 +10704,9 @@ namespace libtorrent
|
|||
|
||||
st->handle = get_handle();
|
||||
st->info_hash = info_hash();
|
||||
st->is_loaded = is_loaded();
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
st->is_loaded = true;
|
||||
#endif
|
||||
|
||||
if (flags & torrent_handle::query_name)
|
||||
st->name = name();
|
||||
|
|
|
@ -379,6 +379,8 @@ namespace libtorrent
|
|||
{
|
||||
async_call(&torrent::set_tracker_login, name, password);
|
||||
}
|
||||
|
||||
void torrent_handle::set_pinned(bool) const {}
|
||||
#endif
|
||||
|
||||
void torrent_handle::file_progress(std::vector<std::int64_t>& progress, int flags) const
|
||||
|
@ -393,11 +395,6 @@ namespace libtorrent
|
|||
return st;
|
||||
}
|
||||
|
||||
void torrent_handle::set_pinned(bool p) const
|
||||
{
|
||||
async_call(&torrent::set_pinned, p);
|
||||
}
|
||||
|
||||
void torrent_handle::set_sequential_download(bool sd) const
|
||||
{
|
||||
async_call(&torrent::set_sequential_download, sd);
|
||||
|
|
|
@ -102,7 +102,9 @@ namespace libtorrent
|
|||
, has_incoming(false)
|
||||
, seed_mode(false)
|
||||
, moving_storage(false)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
, is_loaded(true)
|
||||
#endif
|
||||
, announcing_to_trackers(false)
|
||||
, announcing_to_lsd(false)
|
||||
, announcing_to_dht(false)
|
||||
|
|
|
@ -95,21 +95,6 @@ namespace libtorrent { namespace
|
|||
metadata();
|
||||
}
|
||||
|
||||
bool need_loaded()
|
||||
{ return m_torrent.need_loaded(); }
|
||||
|
||||
void on_unload() override
|
||||
{
|
||||
m_metadata.reset();
|
||||
}
|
||||
|
||||
void on_load() override
|
||||
{
|
||||
// initialize m_metadata_size
|
||||
TORRENT_ASSERT(m_torrent.is_loaded());
|
||||
metadata();
|
||||
}
|
||||
|
||||
void on_files_checked() override
|
||||
{
|
||||
// TODO: 2 if we were to initialize m_metadata_size lazily instead,
|
||||
|
@ -129,7 +114,6 @@ namespace libtorrent { namespace
|
|||
|
||||
span<char const> metadata() const
|
||||
{
|
||||
if (!m_torrent.need_loaded()) return span<char const>();
|
||||
TORRENT_ASSERT(m_torrent.valid_metadata());
|
||||
if (!m_metadata)
|
||||
{
|
||||
|
@ -274,9 +258,6 @@ namespace libtorrent { namespace
|
|||
TORRENT_ASSERT(m_torrent.valid_metadata());
|
||||
|
||||
int offset = piece * 16 * 1024;
|
||||
// unloaded torrents don't have any metadata. Since we're
|
||||
// about to send the metadata, we need it to be loaded
|
||||
if (!m_tp.need_loaded()) return;
|
||||
metadata = m_tp.metadata().data() + offset;
|
||||
metadata_piece_size = (std::min)(
|
||||
m_tp.get_metadata_size() - offset, 16 * 1024);
|
||||
|
|
|
@ -376,12 +376,6 @@ void web_peer_connection::write_request(peer_request const& r)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!t->need_loaded())
|
||||
{
|
||||
disconnect(errors::torrent_aborted, op_bittorrent);
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<file_slice> files = info.orig_files().map_block(req.piece, req.start
|
||||
, req.length);
|
||||
|
||||
|
@ -626,12 +620,6 @@ void web_peer_connection::handle_redirect(int const bytes_left)
|
|||
TORRENT_ASSERT(!m_file_requests.empty());
|
||||
int const file_index = m_file_requests.front().file_index;
|
||||
|
||||
if (!t->need_loaded())
|
||||
{
|
||||
disconnect(errors::torrent_aborted, op_bittorrent);
|
||||
return;
|
||||
}
|
||||
|
||||
location = resolve_redirect_location(m_url, location);
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
peer_log(peer_log_alert::info, "LOCATION", "%s", location.c_str());
|
||||
|
|
Loading…
Reference in New Issue