Skip to content

Commit

Permalink
deprecate set_file_hash() in torrent creator, as it's superceded by v…
Browse files Browse the repository at this point in the history
…2 torrents
  • Loading branch information
arvidn committed Jun 13, 2020
1 parent 0b7ea81 commit 002778b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
2.0 release

* deprecate set_file_hash() in torrent creator, as it's superceded by v2 torrents
* deprecate mutable access to info_section in torrent_info
* removed deprecated lazy_entry/lazy_bdecode
* stats_alert deprecated
Expand Down
4 changes: 4 additions & 0 deletions bindings/python/src/create_torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ namespace
c.set_hash(p, sha1_hash(b.arr));
}

#if TORRENT_ABI_VERSION < 3
void set_file_hash(create_torrent& c, file_index_t f, bytes const& b)
{
c.set_file_hash(f, sha1_hash(b.arr));
}
#endif

#ifndef BOOST_NO_EXCEPTIONS
void set_piece_hashes_callback(create_torrent& c, std::string const& p
Expand Down Expand Up @@ -218,7 +220,9 @@ void bind_create_torrent()
.def("set_comment", &create_torrent::set_comment)
.def("set_creator", &create_torrent::set_creator)
.def("set_hash", &set_hash)
#if TORRENT_ABI_VERSION < 3
.def("set_file_hash", &set_file_hash)
#endif
.def("add_url_seed", &create_torrent::add_url_seed)
.def("add_http_seed", &create_torrent::add_http_seed)
.def("add_node", &add_node)
Expand Down
5 changes: 5 additions & 0 deletions include/libtorrent/create_torrent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,16 @@ namespace libtorrent {
// object constructed with the v1_only flag.
void set_hash2(file_index_t file, piece_index_t::diff_type piece, sha256_hash const& h);

#if TORRENT_ABI_VERSION < 3
// This sets the sha1 hash for this file. This hash will end up under the key ``sha1``
// associated with this file (for multi-file torrents) or in the root info dictionary
// for single-file torrents.
// .. note::
//
// with bittorrent v2, this feature is obsolete
TORRENT_DEPRECATED
void set_file_hash(file_index_t index, sha1_hash const& h);
#endif

// This adds a url seed to the torrent. You can have any number of url seeds. For a
// single file torrent, this should be an HTTP url, pointing to a file with identical
Expand Down Expand Up @@ -359,6 +362,8 @@ namespace libtorrent {

aux::vector<sha1_hash, piece_index_t> m_piece_hash;

// leave this here for now, to preserve ABI between building with
// deprecated functions and without
aux::vector<sha1_hash, file_index_t> m_filehashes;

mutable aux::vector<sha256_hash, file_index_t> m_fileroots;
Expand Down
6 changes: 6 additions & 0 deletions src/create_torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,12 @@ namespace {
elems = lsplit_path(elems.second))
sympath_e.list().emplace_back(elems.first);
}
#if TORRENT_ABI_VERSION < 3
if (!m_filehashes.empty())
{
info["sha1"] = m_filehashes[first].to_string();
}
#endif
}

if (make_v2 && !info.find_key("file tree"))
Expand Down Expand Up @@ -819,10 +821,12 @@ namespace {
elems = lsplit_path(elems.second))
sympath_e.list().emplace_back(elems.first);
}
#if TORRENT_ABI_VERSION < 3
if (!m_filehashes.empty() && m_filehashes[i] != sha1_hash())
{
file_e["sha1"] = m_filehashes[i].to_string();
}
#endif
}
}

Expand Down Expand Up @@ -973,13 +977,15 @@ namespace {
fh[piece] = h;
}

#if TORRENT_ABI_VERSION < 3
void create_torrent::set_file_hash(file_index_t index, sha1_hash const& h)
{
TORRENT_ASSERT(index >= file_index_t(0));
TORRENT_ASSERT(index < m_files.end_file());
if (m_filehashes.empty()) m_filehashes.resize(m_files.num_files());
m_filehashes[index] = h;
}
#endif

void create_torrent::add_node(std::pair<std::string, int> node)
{
Expand Down

0 comments on commit 002778b

Please sign in to comment.