move logic that loads torrent files from resume data into read_resume_data()
This commit is contained in:
parent
a725a3ded2
commit
67dbca14b7
|
@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
||||
|
||||
|
@ -42,6 +43,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/add_torrent_params.hpp"
|
||||
#include "libtorrent/announce_entry.hpp"
|
||||
#include "libtorrent/socket_io.hpp" // for read_*_endpoint()
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
@ -75,12 +78,36 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
std::string info_hash = rd.dict_find_string_value("info-hash");
|
||||
if (info_hash.empty())
|
||||
if (info_hash.size() != 20)
|
||||
{
|
||||
ec = error_code(errors::missing_info_hash, get_libtorrent_category());
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO: 4 add unit test for this, and all other fields of the resume data
|
||||
bdecode_node info = rd.dict_find_dict("info");
|
||||
if (info)
|
||||
{
|
||||
// verify the info-hash of the metadata stored in the resume file matches
|
||||
// the torrent we're loading
|
||||
std::pair<char const*, int> buf = info.data_section();
|
||||
sha1_hash resume_ih = hasher(buf.first, buf.second).final();
|
||||
|
||||
// if url is set, the info_hash is not actually the info-hash of the
|
||||
// torrent, but the hash of the URL, until we have the full torrent
|
||||
// only require the info-hash to match if we actually passed in one
|
||||
if (resume_ih == sha1_hash(info_hash))
|
||||
{
|
||||
ret.ti = boost::make_shared<torrent_info>(resume_ih);
|
||||
|
||||
error_code err;
|
||||
if (!ret.ti->parse_info_section(info, err, 0))
|
||||
{
|
||||
ec = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: 4 we need to verify the info-hash from the resume data
|
||||
// matches the torrent_info object or the magnet link in the URL field. This
|
||||
// can only be done reliably on the libtorrent side as the torrent is being
|
||||
|
|
|
@ -4674,80 +4674,6 @@ namespace aux {
|
|||
}
|
||||
else ih = ¶ms.info_hash;
|
||||
|
||||
// we don't have a torrent file. If the user provided
|
||||
// resume data, there may be some metadata in there
|
||||
// TODO: 4 the logic of loading the .torrent file from the resume data
|
||||
// should be moved into read_resume_data()
|
||||
/*
|
||||
if ((!params.ti || !params.ti->is_valid())
|
||||
&& !params.resume_data.empty())
|
||||
{
|
||||
int pos;
|
||||
error_code err;
|
||||
bdecode_node root;
|
||||
bdecode_node info;
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
session_log("adding magnet link with resume data");
|
||||
#endif
|
||||
if (bdecode(¶ms.resume_data[0], ¶ms.resume_data[0]
|
||||
+ params.resume_data.size(), root, err, &pos) == 0
|
||||
&& root.type() == bdecode_node::dict_t
|
||||
&& (info = root.dict_find_dict("info")))
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
session_log("found metadata in resume data");
|
||||
#endif
|
||||
// verify the info-hash of the metadata stored in the resume file matches
|
||||
// the torrent we're loading
|
||||
|
||||
std::pair<char const*, int> buf = info.data_section();
|
||||
sha1_hash resume_ih = hasher(buf.first, buf.second).final();
|
||||
|
||||
// if url is set, the info_hash is not actually the info-hash of the
|
||||
// torrent, but the hash of the URL, until we have the full torrent
|
||||
// only require the info-hash to match if we actually passed in one
|
||||
if (resume_ih == params.info_hash
|
||||
|| !params.url.empty()
|
||||
|| params.info_hash.is_all_zeros())
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
session_log("info-hash matched");
|
||||
#endif
|
||||
params.ti = boost::make_shared<torrent_info>(resume_ih);
|
||||
|
||||
if (params.ti->parse_info_section(info, err, 0))
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
session_log("successfully loaded metadata from resume file");
|
||||
#endif
|
||||
// make the info-hash be the one in the resume file
|
||||
params.info_hash = resume_ih;
|
||||
ih = ¶ms.info_hash;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
session_log("failed to load metadata from resume file: %s"
|
||||
, err.message().c_str());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
else
|
||||
{
|
||||
session_log("metadata info-hash failed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
else
|
||||
{
|
||||
session_log("no metadata found (\"%s\")", err.message().c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
// is the torrent already active?
|
||||
boost::shared_ptr<torrent> torrent_ptr = find_torrent(*ih).lock();
|
||||
if (!torrent_ptr && !params.uuid.empty()) torrent_ptr = find_torrent(params.uuid).lock();
|
||||
|
|
Loading…
Reference in New Issue