properly deprecated adding torrents by http url

This commit is contained in:
arvidn 2016-02-20 15:49:49 -05:00
parent 10e547529f
commit cc8066bf11
12 changed files with 117 additions and 174 deletions

View File

@ -101,8 +101,10 @@ dict get_params(add_torrent_alert const& alert)
ret["flags"] = p.flags;
ret["trackerid"] = p.trackerid;
ret["url"] = p.url;
#ifndef TORRENT_NO_DEPRECATE
ret["source_feed_url"] = p.source_feed_url;
ret["uuid"] = p.uuid;
#endif
return ret;
}
@ -677,11 +679,13 @@ void bind_alert()
.add_property("params", &get_params)
;
#ifndef TORRENT_NO_DEPRECATE
class_<torrent_update_alert, bases<torrent_alert>, noncopyable>(
"torrent_update_alert", no_init)
.def_readonly("old_ih", &torrent_update_alert::old_ih)
.def_readonly("new_ih", &torrent_update_alert::new_ih)
;
#endif
class_<dht_outgoing_get_peers_alert, bases<alert>, noncopyable>(
"dht_outgoing_get_peers_alert", no_init)

View File

@ -63,8 +63,10 @@ namespace {
ret["save_path"] = p.save_path;
ret["storage_mode"] = p.storage_mode;
ret["url"] = p.url;
#ifndef TORRENT_NO_DEPRECATE
ret["uuid"] = p.uuid;
ret["source_feed_url"] = p.source_feed_url;
#endif
ret["flags"] = p.flags;
return ret;
}

View File

@ -228,10 +228,12 @@ namespace
p.trackerid = extract<std::string>(params["trackerid"]);
if (params.has_key("url"))
p.url = extract<std::string>(params["url"]);
#ifndef TORRENT_NO_DEPRECATE
if (params.has_key("source_feed_url"))
p.source_feed_url = extract<std::string>(params["source_feed_url"]);
if (params.has_key("uuid"))
p.uuid = extract<std::string>(params["uuid"]);
#endif
if (params.has_key("file_priorities"))
{

View File

@ -362,16 +362,6 @@ namespace libtorrent
// will indicate what went wrong. The ``url`` may be set to a magnet link.
std::string url;
// if ``uuid`` is specified, it is used to find duplicates. If another
// torrent is already running with the same UUID as the one being added,
// it will be considered a duplicate. This is mainly useful for RSS feed
// items which has UUIDs specified.
std::string uuid;
// should point to the URL of the RSS feed this torrent comes from, if it
// comes from an RSS feed.
std::string source_feed_url;
// flags controlling aspects of this torrent and how it's added. See
// flags_t for details.
boost::uint64_t flags;
@ -485,6 +475,17 @@ namespace libtorrent
std::map<int, std::string> renamed_files;
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
// if ``uuid`` is specified, it is used to find duplicates. If another
// torrent is already running with the same UUID as the one being added,
// it will be considered a duplicate. This is mainly useful for RSS feed
// items which has UUIDs specified.
std::string uuid;
// should point to the URL of the RSS feed this torrent comes from, if it
// comes from an RSS feed.
std::string source_feed_url;
// The optional parameter, ``resume_data`` can be given if up to date
// fast-resume data is available. The fast-resume data can be acquired
// from a running torrent by calling save_resume_data() on
@ -498,6 +499,13 @@ namespace libtorrent
// communicated forward into libtorrent via this field. If this is set, a
// fastresume_rejected_alert will be posted.
error_code internal_resume_data_error;
#else
// hidden
// to maintain ABI compatibility
std::string deprecated1;
std::string deprecated2;
std::vector<char> deprecated3;
error_code deprecated4;
#endif
};

View File

@ -1887,6 +1887,7 @@ namespace libtorrent
boost::uint64_t values[counters::num_counters];
};
#ifndef TORRENT_NO_DEPRECATE
// hidden
// When a torrent changes its info-hash, this alert is posted. This only
// happens in very specific cases. For instance, when a torrent is
@ -1911,7 +1912,6 @@ namespace libtorrent
sha1_hash new_ih;
};
#ifndef TORRENT_NO_DEPRECATE
// This alert is posted every time a new RSS item (i.e. torrent) is received
// from an RSS feed.
//

View File

@ -266,7 +266,10 @@ namespace libtorrent
#endif
boost::weak_ptr<torrent> find_torrent(sha1_hash const& info_hash) const TORRENT_OVERRIDE;
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
boost::weak_ptr<torrent> find_torrent(std::string const& uuid) const;
#endif
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
std::vector<boost::shared_ptr<torrent> > find_collection(
std::string const& collection) const TORRENT_OVERRIDE;
@ -276,8 +279,11 @@ namespace libtorrent
void insert_torrent(sha1_hash const& ih, boost::shared_ptr<torrent> const& t
, std::string uuid) TORRENT_OVERRIDE;
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
void insert_uuid_torrent(std::string uuid, boost::shared_ptr<torrent> const& t) TORRENT_OVERRIDE
{ m_uuids.insert(std::make_pair(uuid, t)); }
#endif
boost::shared_ptr<torrent> delay_load_torrent(sha1_hash const& info_hash
, peer_connection* pc) TORRENT_OVERRIDE;
void set_queue_position(torrent* t, int p) TORRENT_OVERRIDE;
@ -794,7 +800,10 @@ namespace libtorrent
// list.
linked_list<torrent> m_torrent_lru;
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
std::map<std::string, boost::shared_ptr<torrent> > m_uuids;
#endif
// peer connections are put here when disconnected to avoid
// race conditions with the disk thread. It's important that

View File

@ -190,7 +190,10 @@ namespace libtorrent { namespace aux
, peer_connection* pc) = 0;
virtual void insert_torrent(sha1_hash const& ih, boost::shared_ptr<torrent> const& t
, std::string uuid) = 0;
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
virtual void insert_uuid_torrent(std::string uuid, boost::shared_ptr<torrent> const& t) = 0;
#endif
virtual void set_queue_position(torrent* t, int p) = 0;
virtual int num_torrents() const = 0;

View File

@ -963,12 +963,15 @@ namespace libtorrent
boost::shared_ptr<const torrent_info> get_torrent_copy();
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
std::string const& uuid() const { return m_uuid; }
void set_uuid(std::string const& s) { m_uuid = s; }
std::string const& url() const { return m_url; }
void set_url(std::string const& s) { m_url = s; }
std::string const& source_feed_url() const { return m_source_feed_url; }
void set_source_feed_url(std::string const& s) { m_source_feed_url = s; }
#endif
std::vector<announce_entry> const& trackers() const
{ return m_trackers; }
@ -1030,8 +1033,10 @@ namespace libtorrent
// a return value of false indicates an error
bool set_metadata(char const* metadata_buf, int metadata_size);
#ifndef TORRENT_NO_DEPRECATE
void on_torrent_download(error_code const& ec, http_parser const& parser
, char const* data, int size);
#endif
int sequence_number() const { return m_sequence_number; }
@ -1256,6 +1261,9 @@ namespace libtorrent
std::string m_save_path;
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
// if we don't have the metadata, this is a url to
// the torrent file
std::string m_url;
@ -1267,10 +1275,7 @@ namespace libtorrent
// if this torrent was added by an RSS feed, this is the
// URL to that feed
std::string m_source_feed_url;
// this is used as temporary storage while downloading
// the .torrent file from m_url
// std::vector<char> m_torrent_file_buf;
#endif
// this is a list of all pieces that we have announced
// as having, without actually having yet. If we receive

View File

@ -1355,6 +1355,7 @@ namespace libtorrent {
return names[op];
}
#ifndef TORRENT_NO_DEPRECATE
torrent_update_alert::torrent_update_alert(aux::stack_allocator& alloc, torrent_handle h
, sha1_hash const& old_hash, sha1_hash const& new_hash)
: torrent_alert(alloc, h)
@ -1371,7 +1372,6 @@ namespace libtorrent {
return torrent_alert::message() + msg;
}
#ifndef TORRENT_NO_DEPRECATE
rss_item_alert::rss_item_alert(aux::stack_allocator&, feed_handle h
, feed_item const& i)
: handle(h)

View File

@ -145,8 +145,11 @@ namespace libtorrent
ret.save_path = rd.dict_find_string_value("save_path");
ret.url = rd.dict_find_string_value("url");
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
ret.uuid = rd.dict_find_string_value("uuid");
ret.source_feed_url = rd.dict_find_string_value("feed");
#endif
bdecode_node mapped_files = rd.dict_find_list("mapped_files");
if (mapped_files)

View File

@ -4243,7 +4243,12 @@ namespace aux {
, std::string uuid)
{
m_torrents.insert(std::make_pair(ih, t));
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
if (!uuid.empty()) m_uuids.insert(std::make_pair(uuid, t));
#else
TORRENT_UNUSED(uuid);
#endif
TORRENT_ASSERT(m_torrents.size() >= m_torrent_lru.size());
}
@ -4340,6 +4345,8 @@ namespace aux {
}
#endif
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
boost::weak_ptr<torrent> session_impl::find_torrent(std::string const& uuid) const
{
TORRENT_ASSERT(is_single_thread());
@ -4349,6 +4356,7 @@ namespace aux {
if (i != m_uuids.end()) return i->second;
return boost::weak_ptr<torrent>();
}
#endif
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
std::vector<boost::shared_ptr<torrent> > session_impl::find_collection(
@ -4662,6 +4670,8 @@ namespace aux {
sha1_hash const* ih = 0;
sha1_hash tmp;
if (params.ti) ih = &params.ti->info_hash();
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
else if (!params.url.empty())
{
// in order to avoid info-hash collisions, for
@ -4672,10 +4682,13 @@ namespace aux {
tmp = hasher(&params.url[0], params.url.size()).final();
ih = &tmp;
}
#endif
else ih = &params.info_hash;
// is the torrent already active?
boost::shared_ptr<torrent> torrent_ptr = find_torrent(*ih).lock();
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
if (!torrent_ptr && !params.uuid.empty()) torrent_ptr = find_torrent(params.uuid).lock();
// if we still can't find the torrent, look for it by url
if (!torrent_ptr && !params.url.empty())
@ -4686,17 +4699,21 @@ namespace aux {
if (i != m_torrents.end())
torrent_ptr = i->second;
}
#endif
if (torrent_ptr)
{
if ((params.flags & add_torrent_params::flag_duplicate_is_error) == 0)
{
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
if (!params.uuid.empty() && torrent_ptr->uuid().empty())
torrent_ptr->set_uuid(params.uuid);
if (!params.url.empty() && torrent_ptr->url().empty())
torrent_ptr->set_url(params.url);
if (!params.source_feed_url.empty() && torrent_ptr->source_feed_url().empty())
torrent_ptr->set_source_feed_url(params.source_feed_url);
#endif
return torrent_handle(torrent_ptr);
}
@ -4787,9 +4804,13 @@ namespace aux {
#endif
}
#endif // TORRENT_HAS_BOOST_UNORDERED
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
if (!params.uuid.empty() || !params.url.empty())
m_uuids.insert(std::make_pair(params.uuid.empty()
? params.url : params.uuid, torrent_ptr));
#endif
// recalculate auto-managed torrents sooner (or put it off)
// if another torrent will be added within one second from now
@ -4941,6 +4962,8 @@ namespace aux {
void session_impl::remove_torrent_impl(boost::shared_ptr<torrent> tptr, int options)
{
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
// remove from uuid list
if (!tptr->uuid().empty())
{
@ -4948,10 +4971,13 @@ namespace aux {
= m_uuids.find(tptr->uuid());
if (j != m_uuids.end()) m_uuids.erase(j);
}
#endif
torrent_map::iterator i =
m_torrents.find(tptr->torrent_file().info_hash());
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
// this torrent might be filed under the URL-hash
if (i == m_torrents.end() && !tptr->url().empty())
{
@ -4959,6 +4985,7 @@ namespace aux {
sha1_hash urlhash = hasher(&url[0], url.size()).final();
i = m_torrents.find(urlhash);
}
#endif
if (i == m_torrents.end()) return;

View File

@ -196,9 +196,12 @@ namespace libtorrent
, m_inactivity_timer(ses.get_io_service())
, m_trackerid(p.trackerid)
, m_save_path(complete(p.save_path))
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
, m_url(p.url)
, m_uuid(p.uuid)
, m_source_feed_url(p.source_feed_url)
#endif
, m_stats_counters(ses.stats_counters())
, m_storage_constructor(p.storage)
, m_added_time(time(0))
@ -412,7 +415,10 @@ namespace libtorrent
if (!p.name.empty()) m_name.reset(new std::string(p.name));
}
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
if (!m_url.empty() && m_uuid.empty()) m_uuid = m_url;
#endif
TORRENT_ASSERT(is_single_thread());
m_file_priority = p.file_priorities;
@ -441,161 +447,8 @@ namespace libtorrent
void torrent::inc_stats_counter(int c, int value)
{ m_ses.stats_counters().inc_stats_counter(c, value); }
#if 0
// NON BOTTLED VERSION. SUPPORTS PROGRESS REPORTING
// since this download is not bottled, this callback will
// be called every time we receive another piece of the
// .torrent file
void torrent::on_torrent_download(error_code const& ec
, http_parser const& parser
, char const* data, int size)
{
if (m_abort) return;
if (ec && ec != boost::asio::error::eof)
{
set_error(ec, error_file_url);
pause();
return;
}
if (size > 0)
{
m_torrent_file_buf.insert(m_torrent_file_buf.end(), data, data + size);
if (parser.content_length() > 0)
set_progress_ppm(boost::int64_t(m_torrent_file_buf.size())
* 1000000 / parser.content_length());
}
if (parser.header_finished() && parser.status_code() != 200)
{
set_error(error_code(parser.status_code(), get_http_category()), error_file_url);
pause();
return;
}
if (!ec) return;
// if this was received with chunked encoding, we need to strip out
// the chunk headers
size = parser.collapse_chunk_headers((char*)&m_torrent_file_buf[0], m_torrent_file_buf.size());
m_torrent_file_buf.resize(size);
std::string const& encoding = parser.header("content-encoding");
if ((encoding == "gzip" || encoding == "x-gzip") && m_torrent_file_buf.size())
{
std::vector<char> buf;
error_code ec;
inflate_gzip(&m_torrent_file_buf[0], m_torrent_file_buf.size()
, buf, 4 * 1024 * 1024, ex);
if (ec)
{
set_error(ec, error_file_url);
pause();
std::vector<char>().swap(m_torrent_file_buf);
return;
}
m_torrent_file_buf.swap(buf);
}
// we're done!
error_code e;
boost::shared_ptr<torrent_info> tf(boost::make_shared<torrent_info>(
&m_torrent_file_buf[0], m_torrent_file_buf.size(), e));
if (e)
{
set_error(e, error_file_url);
pause();
std::vector<char>().swap(m_torrent_file_buf);
return;
}
std::vector<char>().swap(m_torrent_file_buf);
// update our torrent_info object and move the
// torrent from the old info-hash to the new one
// as we replace the torrent_info object
#if TORRENT_USE_ASSERTS
int num_torrents = m_ses.m_torrents.size();
#endif
// we're about to erase the session's reference to this
// torrent, create another reference
boost::shared_ptr<torrent> me(shared_from_this());
m_ses.remove_torrent_impl(me, 0);
m_torrent_file = tf;
// now, we might already have this torrent in the session.
boost::shared_ptr<torrent> t = m_ses.find_torrent(m_torrent_file->info_hash()).lock();
if (t)
{
if (!m_uuid.empty() && t->uuid().empty())
t->set_uuid(m_uuid);
if (!m_url.empty() && t->url().empty())
t->set_url(m_url);
if (!m_source_feed_url.empty() && t->source_feed_url().empty())
t->set_source_feed_url(m_source_feed_url);
// insert this torrent in the uuid index
if (!m_uuid.empty() || !m_url.empty())
{
m_ses.insert_uuid_torrent(m_uuid.empty() ? m_url : m_uuid, t);
}
// TODO: if the existing torrent doesn't have metadata, insert
// the metadata we just downloaded into it.
set_error(error_code(errors::duplicate_torrent, get_libtorrent_category()), error_file_url);
abort();
return;
}
m_ses.insert_torrent(m_torrent_file->info_hash(), me, m_uuid);
TORRENT_ASSERT(num_torrents == int(m_ses.m_torrents.size()));
// if the user added any trackers while downloading the
// .torrent file, merge them into the new tracker list
std::vector<announce_entry> new_trackers = m_torrent_file->trackers();
for (std::vector<announce_entry>::iterator i = m_trackers.begin()
, end(m_trackers.end()); i != end; ++i)
{
// if we already have this tracker, ignore it
if (std::find_if(new_trackers.begin(), new_trackers.end()
, boost::bind(&announce_entry::url, _1) == i->url) != new_trackers.end())
continue;
// insert the tracker ordered by tier
new_trackers.insert(std::find_if(new_trackers.begin(), new_trackers.end()
, boost::bind(&announce_entry::tier, _1) >= i->tier), *i);
}
m_trackers.swap(new_trackers);
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
hasher h;
h.update("req2", 4);
h.update((char*)&m_torrent_file->info_hash()[0], 20);
// this is SHA1("req2" + info-hash), used for
// encrypted hand shakes
m_ses.add_obfuscated_hash(h.final(), shared_from_this());
#endif
if (m_ses.alerts().should_post<metadata_received_alert>())
{
m_ses.alerts().emplace_alert<metadata_received_alert>(
get_handle());
}
state_updated();
set_state(torrent_status::downloading);
init();
}
#else // if 0
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
void torrent::on_torrent_download(error_code const& ec
, http_parser const& parser, char const* data, int size)
{
@ -707,7 +560,7 @@ namespace libtorrent
init();
}
#endif // if 0
#endif // TORRENT_NO_DEPRECATE
int torrent::current_stats_state() const
{
@ -857,7 +710,9 @@ namespace libtorrent
set_limit_impl(p.upload_limit, peer_connection::upload_channel, false);
set_limit_impl(p.download_limit, peer_connection::download_channel, false);
#ifndef TORRENT_NO_DEPRECATE
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
@ -884,12 +739,16 @@ namespace libtorrent
update_want_tick();
update_state_list();
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
if (!m_torrent_file->is_valid() && !m_url.empty())
{
// we need to download the .torrent file from m_url
start_download_url();
}
else if (m_torrent_file->is_valid())
else
#endif
if (m_torrent_file->is_valid())
{
init();
}
@ -906,6 +765,8 @@ namespace libtorrent
#endif
}
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
void torrent::start_download_url()
{
TORRENT_ASSERT(!m_url.empty());
@ -929,6 +790,7 @@ namespace libtorrent
, 5, settings().get_str(settings_pack::user_agent));
set_state(torrent_status::downloading_metadata);
}
#endif
void torrent::set_apply_ip_filter(bool b)
{
@ -964,10 +826,13 @@ namespace libtorrent
if (!m_announce_to_dht) return false;
if (!m_allow_peers) return false;
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
// if we don't have the metadata, and we're waiting
// for a web server to serve it to us, no need to announce
// because the info-hash is just the URL hash
if (!m_torrent_file->is_valid() && !m_url.empty()) return false;
#endif
// don't announce private torrents
if (m_torrent_file->is_valid() && m_torrent_file->priv()) return false;
@ -2907,8 +2772,11 @@ namespace libtorrent
if (!m_allow_peers)
debug_log("DHT: torrent paused, no DHT announce");
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
if (!m_torrent_file->is_valid() && !m_url.empty())
debug_log("DHT: no info-hash, waiting for \"%s\"", m_url.c_str());
#endif
if (m_torrent_file->is_valid() && m_torrent_file->priv())
debug_log("DHT: private torrent, no DHT announce");
@ -6759,9 +6627,12 @@ namespace libtorrent
ret["save_path"] = m_save_path;
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
if (!m_url.empty()) ret["url"] = m_url;
if (!m_uuid.empty()) ret["uuid"] = m_uuid;
if (!m_source_feed_url.empty()) ret["feed"] = m_source_feed_url;
#endif
const sha1_hash& info_hash = torrent_file().info_hash();
ret["info-hash"] = info_hash.to_string();
@ -8944,12 +8815,15 @@ namespace libtorrent
update_want_peers();
update_state_list();
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
// if we haven't downloaded the metadata from m_url, try again
if (!m_url.empty() && !m_torrent_file->is_valid())
{
start_download_url();
return;
}
#endif
// if the error happened during initialization, try again now
if (!m_connections_initialized && valid_metadata()) init();
if (!checking_files && should_check_files())
@ -8958,7 +8832,10 @@ namespace libtorrent
std::string torrent::resolve_filename(int file) const
{
if (file == torrent_status::error_file_none) return "";
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
if (file == torrent_status::error_file_url) return m_url;
#endif
if (file == torrent_status::error_file_ssl_ctx) return "SSL Context";
if (file == torrent_status::error_file_metadata) return "metadata (from user load function)";
@ -9653,6 +9530,8 @@ namespace libtorrent
#endif
return;
}
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
if (!m_torrent_file->is_valid() && !m_url.empty())
{
#ifndef TORRENT_DISABLE_LOGGING
@ -9660,6 +9539,7 @@ namespace libtorrent
#endif
return;
}
#endif
if (m_announcing) return;
m_announcing = true;