2003-10-30 00:28:09 +01:00
|
|
|
/*
|
|
|
|
|
2016-01-18 00:57:46 +01:00
|
|
|
Copyright (c) 2003-2016, Arvid Norberg
|
2003-10-30 00:28:09 +01:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <set>
|
|
|
|
#include <cctype>
|
2004-01-25 19:18:36 +01:00
|
|
|
|
2016-12-09 01:22:47 +01:00
|
|
|
#include "libtorrent/torrent_handle.hpp"
|
|
|
|
#include "libtorrent/torrent.hpp"
|
2003-10-30 00:28:09 +01:00
|
|
|
#include "libtorrent/torrent_info.hpp"
|
|
|
|
#include "libtorrent/bencode.hpp"
|
|
|
|
#include "libtorrent/entry.hpp"
|
2006-10-11 16:02:21 +02:00
|
|
|
#include "libtorrent/aux_/session_impl.hpp"
|
2014-08-26 06:51:09 +02:00
|
|
|
#include "libtorrent/aux_/session_call.hpp"
|
2017-01-29 21:37:42 +01:00
|
|
|
#include "libtorrent/aux_/throw.hpp"
|
2004-02-29 17:39:52 +01:00
|
|
|
#include "libtorrent/invariant_check.hpp"
|
2008-11-30 09:12:26 +01:00
|
|
|
#include "libtorrent/utf8.hpp"
|
2015-09-18 06:23:45 +02:00
|
|
|
#include "libtorrent/announce_entry.hpp"
|
2017-03-05 15:31:28 +01:00
|
|
|
#include "libtorrent/write_resume_data.hpp"
|
2017-07-09 16:32:01 +02:00
|
|
|
#include "libtorrent/torrent_flags.hpp"
|
2003-10-30 00:28:09 +01:00
|
|
|
|
2017-07-16 21:25:07 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2016-02-21 05:40:45 +01:00
|
|
|
#include "libtorrent/peer_info.hpp" // for peer_list_entry
|
|
|
|
#endif
|
|
|
|
|
2006-10-11 16:02:21 +02:00
|
|
|
using libtorrent::aux::session_impl;
|
2004-10-29 15:21:09 +02:00
|
|
|
|
2017-04-12 19:00:57 +02:00
|
|
|
namespace libtorrent {
|
2007-11-25 19:48:43 +01:00
|
|
|
|
2017-07-27 01:16:29 +02:00
|
|
|
constexpr resume_data_flags_t torrent_handle::flush_disk_cache;
|
|
|
|
constexpr resume_data_flags_t torrent_handle::save_info_dict;
|
|
|
|
constexpr resume_data_flags_t torrent_handle::only_if_modified;
|
2017-07-27 10:37:32 +02:00
|
|
|
constexpr add_piece_flags_t torrent_handle::overwrite_existing;
|
|
|
|
constexpr pause_flags_t torrent_handle::graceful_pause;
|
|
|
|
constexpr deadline_flags_t torrent_handle::alert_when_available;
|
2017-07-27 01:16:29 +02:00
|
|
|
|
2017-07-27 01:50:46 +02:00
|
|
|
constexpr status_flags_t torrent_handle::query_distributed_copies;
|
|
|
|
constexpr status_flags_t torrent_handle::query_accurate_download_counters;
|
|
|
|
constexpr status_flags_t torrent_handle::query_last_seen_complete;
|
|
|
|
constexpr status_flags_t torrent_handle::query_pieces;
|
|
|
|
constexpr status_flags_t torrent_handle::query_verified_pieces;
|
|
|
|
constexpr status_flags_t torrent_handle::query_torrent_file;
|
|
|
|
constexpr status_flags_t torrent_handle::query_name;
|
|
|
|
constexpr status_flags_t torrent_handle::query_save_path;
|
|
|
|
|
2007-11-25 19:48:43 +01:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2017-01-29 21:37:42 +01:00
|
|
|
void TORRENT_NO_RETURN throw_invalid_handle()
|
2009-02-23 02:21:19 +01:00
|
|
|
{
|
2016-05-15 06:33:06 +02:00
|
|
|
throw system_error(errors::invalid_torrent_handle);
|
2004-03-23 23:58:18 +01:00
|
|
|
}
|
2009-02-23 02:21:19 +01:00
|
|
|
#endif
|
2004-03-23 23:58:18 +01:00
|
|
|
|
2016-05-22 01:05:42 +02:00
|
|
|
template<typename Fun, typename... Args>
|
|
|
|
void torrent_handle::async_call(Fun f, Args&&... a) const
|
|
|
|
{
|
2016-08-31 14:27:36 +02:00
|
|
|
std::shared_ptr<torrent> t = m_torrent.lock();
|
2017-01-29 21:37:42 +01:00
|
|
|
if (!t) aux::throw_ex<system_error>(errors::invalid_torrent_handle);
|
2016-05-22 01:05:42 +02:00
|
|
|
session_impl& ses = static_cast<session_impl&>(t->session());
|
2016-10-06 06:08:14 +02:00
|
|
|
ses.get_io_service().dispatch([=,&ses] ()
|
|
|
|
{
|
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
try {
|
|
|
|
#endif
|
|
|
|
(t.get()->*f)(a...);
|
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
} catch (system_error const& e) {
|
|
|
|
ses.alerts().emplace_alert<torrent_error_alert>(torrent_handle(m_torrent)
|
|
|
|
, e.code(), e.what());
|
|
|
|
} catch (std::exception const& e) {
|
|
|
|
ses.alerts().emplace_alert<torrent_error_alert>(torrent_handle(m_torrent)
|
|
|
|
, error_code(), e.what());
|
|
|
|
} catch (...) {
|
|
|
|
ses.alerts().emplace_alert<torrent_error_alert>(torrent_handle(m_torrent)
|
|
|
|
, error_code(), "unknown error");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} );
|
2016-05-22 01:05:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Fun, typename... Args>
|
|
|
|
void torrent_handle::sync_call(Fun f, Args&&... a) const
|
|
|
|
{
|
2016-08-31 14:27:36 +02:00
|
|
|
std::shared_ptr<torrent> t = m_torrent.lock();
|
2017-01-29 21:37:42 +01:00
|
|
|
if (!t) aux::throw_ex<system_error>(errors::invalid_torrent_handle);
|
2016-05-22 01:05:42 +02:00
|
|
|
session_impl& ses = static_cast<session_impl&>(t->session());
|
|
|
|
|
|
|
|
// this is the flag to indicate the call has completed
|
|
|
|
bool done = false;
|
|
|
|
|
2016-10-06 06:08:14 +02:00
|
|
|
std::exception_ptr ex;
|
|
|
|
ses.get_io_service().dispatch([=,&done,&ses,&ex] ()
|
2016-05-22 01:05:42 +02:00
|
|
|
{
|
2016-10-06 06:08:14 +02:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
try {
|
|
|
|
#endif
|
|
|
|
(t.get()->*f)(a...);
|
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
} catch (...) {
|
|
|
|
ex = std::current_exception();
|
|
|
|
}
|
|
|
|
#endif
|
2016-05-22 01:05:42 +02:00
|
|
|
std::unique_lock<std::mutex> l(ses.mut);
|
|
|
|
done = true;
|
|
|
|
ses.cond.notify_all();
|
|
|
|
} );
|
|
|
|
|
|
|
|
aux::torrent_wait(done, ses);
|
2016-10-06 06:08:14 +02:00
|
|
|
if (ex) std::rethrow_exception(ex);
|
2016-05-22 01:05:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Ret, typename Fun, typename... Args>
|
|
|
|
Ret torrent_handle::sync_call_ret(Ret def, Fun f, Args&&... a) const
|
|
|
|
{
|
2016-08-31 14:27:36 +02:00
|
|
|
std::shared_ptr<torrent> t = m_torrent.lock();
|
2016-05-22 01:05:42 +02:00
|
|
|
Ret r = def;
|
2016-10-19 07:18:05 +02:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
if (!t) throw_invalid_handle();
|
|
|
|
#else
|
2016-05-22 01:05:42 +02:00
|
|
|
if (!t) return r;
|
2016-10-19 07:18:05 +02:00
|
|
|
#endif
|
2016-05-22 01:05:42 +02:00
|
|
|
session_impl& ses = static_cast<session_impl&>(t->session());
|
|
|
|
|
|
|
|
// this is the flag to indicate the call has completed
|
|
|
|
bool done = false;
|
|
|
|
|
2016-10-06 06:08:14 +02:00
|
|
|
std::exception_ptr ex;
|
|
|
|
ses.get_io_service().dispatch([=,&r,&done,&ses,&ex] ()
|
2016-05-22 01:05:42 +02:00
|
|
|
{
|
2016-10-06 06:08:14 +02:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
try {
|
|
|
|
#endif
|
|
|
|
r = (t.get()->*f)(a...);
|
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
} catch (...) {
|
|
|
|
ex = std::current_exception();
|
|
|
|
}
|
|
|
|
#endif
|
2016-05-22 01:05:42 +02:00
|
|
|
std::unique_lock<std::mutex> l(ses.mut);
|
|
|
|
done = true;
|
|
|
|
ses.cond.notify_all();
|
|
|
|
} );
|
|
|
|
|
|
|
|
aux::torrent_wait(done, ses);
|
|
|
|
|
2016-10-06 06:08:14 +02:00
|
|
|
if (ex) std::rethrow_exception(ex);
|
2016-05-22 01:05:42 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-04-09 22:09:36 +02:00
|
|
|
sha1_hash torrent_handle::info_hash() const
|
|
|
|
{
|
2016-08-31 14:27:36 +02:00
|
|
|
std::shared_ptr<torrent> t = m_torrent.lock();
|
2017-09-25 01:29:05 +02:00
|
|
|
return t ? t->info_hash() : sha1_hash();
|
2008-04-09 22:09:36 +02:00
|
|
|
}
|
|
|
|
|
2009-04-07 17:55:05 +02:00
|
|
|
int torrent_handle::max_uploads() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<int>(0, &torrent::max_uploads);
|
2009-04-07 17:55:05 +02:00
|
|
|
}
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::set_max_uploads(int max_uploads) const
|
2003-12-14 06:56:12 +01:00
|
|
|
{
|
2014-03-23 08:40:43 +01:00
|
|
|
TORRENT_ASSERT_PRECOND(max_uploads >= 2 || max_uploads == -1);
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_max_uploads, max_uploads, true);
|
2003-12-14 06:56:12 +01:00
|
|
|
}
|
2004-01-21 01:59:38 +01:00
|
|
|
|
2008-11-08 08:40:55 +01:00
|
|
|
int torrent_handle::max_connections() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<int>(0, &torrent::max_connections);
|
2008-11-08 08:40:55 +01:00
|
|
|
}
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::set_max_connections(int max_connections) const
|
2004-01-21 01:59:38 +01:00
|
|
|
{
|
2014-03-23 08:40:43 +01:00
|
|
|
TORRENT_ASSERT_PRECOND(max_connections >= 2 || max_connections == -1);
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_max_connections, max_connections, true);
|
2004-01-21 01:59:38 +01:00
|
|
|
}
|
2003-10-30 00:28:09 +01:00
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::set_upload_limit(int limit) const
|
2003-11-28 18:29:27 +01:00
|
|
|
{
|
2014-03-23 08:40:43 +01:00
|
|
|
TORRENT_ASSERT_PRECOND(limit >= -1);
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_upload_limit, limit);
|
2003-11-28 18:29:27 +01:00
|
|
|
}
|
|
|
|
|
2007-04-10 11:25:17 +02:00
|
|
|
int torrent_handle::upload_limit() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<int>(0, &torrent::upload_limit);
|
2007-04-10 11:25:17 +02:00
|
|
|
}
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::set_download_limit(int limit) const
|
2004-07-01 20:51:13 +02:00
|
|
|
{
|
2014-03-23 08:40:43 +01:00
|
|
|
TORRENT_ASSERT_PRECOND(limit >= -1);
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_download_limit, limit);
|
2004-07-01 20:51:13 +02:00
|
|
|
}
|
|
|
|
|
2007-04-10 11:25:17 +02:00
|
|
|
int torrent_handle::download_limit() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<int>(0, &torrent::download_limit);
|
2007-04-10 11:25:17 +02:00
|
|
|
}
|
|
|
|
|
2017-06-01 10:15:15 +02:00
|
|
|
void torrent_handle::move_storage(std::string const& save_path, move_flags_t flags) const
|
2004-07-18 02:39:58 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::move_storage, save_path, flags);
|
2004-07-18 02:39:58 +02:00
|
|
|
}
|
|
|
|
|
2017-06-01 10:15:15 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
void torrent_handle::move_storage(
|
|
|
|
std::string const& save_path, int const flags) const
|
|
|
|
{
|
|
|
|
async_call(&torrent::move_storage, save_path, static_cast<move_flags_t>(flags));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-08-02 07:03:22 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2008-11-30 09:12:26 +01:00
|
|
|
void torrent_handle::move_storage(
|
2013-05-09 04:50:16 +02:00
|
|
|
std::wstring const& save_path, int flags) const
|
2008-11-30 09:12:26 +01:00
|
|
|
{
|
2017-06-01 10:15:15 +02:00
|
|
|
async_call(&torrent::move_storage, wchar_utf8(save_path), static_cast<move_flags_t>(flags));
|
2008-11-30 09:12:26 +01:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
void torrent_handle::rename_file(file_index_t index, std::wstring const& new_name) const
|
2008-11-30 09:12:26 +01:00
|
|
|
{
|
2016-09-25 04:16:10 +02:00
|
|
|
async_call(&torrent::rename_file, index, wchar_utf8(new_name));
|
2008-11-30 09:12:26 +01:00
|
|
|
}
|
2013-08-02 07:03:22 +02:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
2009-03-31 10:12:35 +02:00
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
void torrent_handle::rename_file(file_index_t index, std::string const& new_name) const
|
2009-03-31 10:12:35 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::rename_file, index, new_name);
|
2009-03-31 10:12:35 +02:00
|
|
|
}
|
2008-11-30 09:12:26 +01:00
|
|
|
|
2007-11-08 02:45:35 +01:00
|
|
|
void torrent_handle::add_extension(
|
2016-08-17 20:30:24 +02:00
|
|
|
std::function<std::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext
|
2007-11-08 02:45:35 +01:00
|
|
|
, void* userdata)
|
|
|
|
{
|
2013-04-09 04:38:11 +02:00
|
|
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::add_extension_fun, ext, userdata);
|
2015-08-22 00:28:12 +02:00
|
|
|
#else
|
|
|
|
TORRENT_UNUSED(ext);
|
|
|
|
TORRENT_UNUSED(userdata);
|
2011-01-29 13:13:49 +01:00
|
|
|
#endif
|
2013-04-09 04:38:11 +02:00
|
|
|
}
|
2007-11-08 02:45:35 +01:00
|
|
|
|
2016-08-22 17:02:51 +02:00
|
|
|
bool torrent_handle::set_metadata(span<char const> metadata) const
|
2008-09-24 04:32:33 +02:00
|
|
|
{
|
2016-08-22 17:02:51 +02:00
|
|
|
return sync_call_ret<bool>(false, &torrent::set_metadata, metadata);
|
2008-09-24 04:32:33 +02:00
|
|
|
}
|
|
|
|
|
2017-07-27 10:37:32 +02:00
|
|
|
void torrent_handle::pause(pause_flags_t const flags) const
|
2004-03-21 03:03:37 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::pause, bool(flags & graceful_pause));
|
2004-03-21 03:03:37 +01:00
|
|
|
}
|
|
|
|
|
2017-07-09 16:32:01 +02:00
|
|
|
torrent_flags_t torrent_handle::flags() const
|
2017-07-01 17:43:39 +02:00
|
|
|
{
|
2017-07-09 16:32:01 +02:00
|
|
|
return sync_call_ret<torrent_flags_t>(torrent_flags_t{}, &torrent::flags);
|
2017-07-01 17:43:39 +02:00
|
|
|
}
|
|
|
|
|
2017-07-09 16:32:01 +02:00
|
|
|
void torrent_handle::set_flags(torrent_flags_t const flags
|
|
|
|
, torrent_flags_t const mask) const
|
2017-07-01 17:43:39 +02:00
|
|
|
{
|
|
|
|
async_call(&torrent::set_flags, flags, mask);
|
|
|
|
}
|
|
|
|
|
2017-07-09 16:32:01 +02:00
|
|
|
void torrent_handle::set_flags(torrent_flags_t const flags) const
|
2017-07-01 17:43:39 +02:00
|
|
|
{
|
2017-07-09 16:32:01 +02:00
|
|
|
async_call(&torrent::set_flags, torrent_flags::all, flags);
|
2017-07-01 17:43:39 +02:00
|
|
|
}
|
|
|
|
|
2017-07-09 16:32:01 +02:00
|
|
|
void torrent_handle::unset_flags(torrent_flags_t const flags) const
|
2017-07-01 17:43:39 +02:00
|
|
|
{
|
2017-07-09 16:32:01 +02:00
|
|
|
async_call(&torrent::set_flags, torrent_flags_t{}, flags);
|
2017-07-01 17:43:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2015-10-04 00:15:29 +02:00
|
|
|
void torrent_handle::stop_when_ready(bool b) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::stop_when_ready, b);
|
2015-10-04 00:15:29 +02:00
|
|
|
}
|
|
|
|
|
2011-02-27 18:26:57 +01:00
|
|
|
void torrent_handle::apply_ip_filter(bool b) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_apply_ip_filter, b);
|
2011-02-27 18:26:57 +01:00
|
|
|
}
|
|
|
|
|
2010-09-05 18:01:36 +02:00
|
|
|
void torrent_handle::set_share_mode(bool b) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_share_mode, b);
|
2010-09-05 18:01:36 +02:00
|
|
|
}
|
|
|
|
|
2009-06-19 00:32:55 +02:00
|
|
|
void torrent_handle::set_upload_mode(bool b) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_upload_mode, b);
|
2009-06-19 00:32:55 +02:00
|
|
|
}
|
2017-07-01 17:43:39 +02:00
|
|
|
#endif
|
2009-06-19 00:32:55 +02:00
|
|
|
|
2010-01-09 22:17:52 +01:00
|
|
|
void torrent_handle::flush_cache() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::flush_cache);
|
2010-01-09 22:17:52 +01:00
|
|
|
}
|
|
|
|
|
2011-09-12 05:51:49 +02:00
|
|
|
void torrent_handle::set_ssl_certificate(
|
|
|
|
std::string const& certificate
|
|
|
|
, std::string const& private_key
|
|
|
|
, std::string const& dh_params
|
|
|
|
, std::string const& passphrase)
|
2011-09-10 07:52:07 +02:00
|
|
|
{
|
|
|
|
#ifdef TORRENT_USE_OPENSSL
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_ssl_cert, certificate, private_key, dh_params, passphrase);
|
2015-04-20 06:52:49 +02:00
|
|
|
#else
|
|
|
|
TORRENT_UNUSED(certificate);
|
|
|
|
TORRENT_UNUSED(private_key);
|
|
|
|
TORRENT_UNUSED(dh_params);
|
|
|
|
TORRENT_UNUSED(passphrase);
|
2011-09-10 07:52:07 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-10 23:53:50 +02:00
|
|
|
void torrent_handle::set_ssl_certificate_buffer(
|
|
|
|
std::string const& certificate
|
|
|
|
, std::string const& private_key
|
|
|
|
, std::string const& dh_params)
|
|
|
|
{
|
|
|
|
#ifdef TORRENT_USE_OPENSSL
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_ssl_cert_buffer, certificate, private_key, dh_params);
|
2015-04-20 06:52:49 +02:00
|
|
|
#else
|
|
|
|
TORRENT_UNUSED(certificate);
|
|
|
|
TORRENT_UNUSED(private_key);
|
|
|
|
TORRENT_UNUSED(dh_params);
|
2014-05-10 23:53:50 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:16:29 +02:00
|
|
|
void torrent_handle::save_resume_data(resume_data_flags_t f) const
|
2008-04-13 20:54:36 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::save_resume_data, f);
|
2008-04-13 20:54:36 +02:00
|
|
|
}
|
|
|
|
|
2010-04-12 02:36:31 +02:00
|
|
|
bool torrent_handle::need_save_resume_data() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<bool>(false, &torrent::need_save_resume_data);
|
2010-04-12 02:36:31 +02:00
|
|
|
}
|
|
|
|
|
2008-06-07 18:24:56 +02:00
|
|
|
void torrent_handle::force_recheck() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::force_recheck);
|
2008-06-07 18:24:56 +02:00
|
|
|
}
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::resume() const
|
2004-03-21 03:03:37 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::resume);
|
2004-03-23 23:58:18 +01:00
|
|
|
}
|
2004-03-21 03:03:37 +01:00
|
|
|
|
2017-07-01 17:43:39 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2008-04-24 05:28:48 +02:00
|
|
|
void torrent_handle::auto_managed(bool m) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::auto_managed, m);
|
2008-04-24 05:28:48 +02:00
|
|
|
}
|
2017-07-01 17:43:39 +02:00
|
|
|
#endif
|
2008-04-24 05:28:48 +02:00
|
|
|
|
2008-05-29 05:37:19 +02:00
|
|
|
int torrent_handle::queue_position() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<int>(-1, &torrent::queue_position);
|
2008-05-29 05:37:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::queue_position_up() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::queue_up);
|
2008-05-29 05:37:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::queue_position_down() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::queue_down);
|
2008-05-29 05:37:19 +02:00
|
|
|
}
|
|
|
|
|
2017-01-31 03:31:31 +01:00
|
|
|
void torrent_handle::queue_position_set(int p) const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT_PRECOND(p >= 0);
|
|
|
|
if (p < 0) return;
|
2017-02-03 05:09:54 +01:00
|
|
|
async_call(&torrent::set_queue_position, p);
|
2017-01-31 03:31:31 +01:00
|
|
|
}
|
|
|
|
|
2008-05-29 05:37:19 +02:00
|
|
|
void torrent_handle::queue_position_top() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_queue_position, 0);
|
2008-05-29 05:37:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::queue_position_bottom() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_queue_position, INT_MAX);
|
2008-05-29 05:37:19 +02:00
|
|
|
}
|
|
|
|
|
2008-07-12 19:00:52 +02:00
|
|
|
void torrent_handle::clear_error() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::clear_error);
|
2008-07-12 19:00:52 +02:00
|
|
|
}
|
|
|
|
|
2015-12-13 21:14:19 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2016-08-26 18:37:23 +02:00
|
|
|
void torrent_handle::set_priority(int) const {}
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::set_tracker_login(std::string const& name
|
|
|
|
, std::string const& password) const
|
2004-03-23 23:58:18 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_tracker_login, name, password);
|
2004-03-21 03:03:37 +01:00
|
|
|
}
|
2016-10-15 19:32:59 +02:00
|
|
|
|
|
|
|
void torrent_handle::set_pinned(bool) const {}
|
2015-12-13 21:14:19 +01:00
|
|
|
#endif
|
2004-03-21 03:03:37 +01:00
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
void torrent_handle::file_progress(std::vector<std::int64_t>& progress, int flags) const
|
2006-06-12 01:24:36 +02:00
|
|
|
{
|
2016-12-22 16:42:33 +01:00
|
|
|
auto& arg = static_cast<aux::vector<std::int64_t, file_index_t>&>(progress);
|
|
|
|
sync_call(&torrent::file_progress, std::ref(arg), flags);
|
2006-06-12 01:24:36 +02:00
|
|
|
}
|
2004-03-23 23:58:18 +01:00
|
|
|
|
2017-07-27 01:50:46 +02:00
|
|
|
torrent_status torrent_handle::status(status_flags_t const flags) const
|
2004-02-22 23:40:45 +01:00
|
|
|
{
|
2011-02-01 10:48:28 +01:00
|
|
|
torrent_status st;
|
2016-05-22 01:05:42 +02:00
|
|
|
sync_call(&torrent::status, &st, flags);
|
2011-02-01 10:48:28 +01:00
|
|
|
return st;
|
2004-02-22 23:40:45 +01:00
|
|
|
}
|
|
|
|
|
2017-07-01 17:43:39 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2008-01-31 18:52:29 +01:00
|
|
|
void torrent_handle::set_sequential_download(bool sd) const
|
2006-09-04 19:17:45 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_sequential_download, sd);
|
2006-09-04 19:17:45 +02:00
|
|
|
}
|
2017-07-01 17:43:39 +02:00
|
|
|
#endif
|
2006-09-04 19:17:45 +02:00
|
|
|
|
2007-05-30 08:52:59 +02:00
|
|
|
void torrent_handle::piece_availability(std::vector<int>& avail) const
|
|
|
|
{
|
2016-12-22 16:42:33 +01:00
|
|
|
auto availr = std::ref(static_cast<aux::vector<int, piece_index_t>&>(avail));
|
2016-05-22 01:05:42 +02:00
|
|
|
sync_call(&torrent::piece_availability, availr);
|
2007-05-30 08:52:59 +02:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
void torrent_handle::piece_priority(piece_index_t index, int priority) const
|
2007-03-20 02:59:00 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_piece_priority, index, priority);
|
2007-03-20 02:59:00 +01:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
int torrent_handle::piece_priority(piece_index_t index) const
|
2007-03-20 02:59:00 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<int>(0, &torrent::piece_priority, index);
|
2007-03-20 02:59:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::prioritize_pieces(std::vector<int> const& pieces) const
|
|
|
|
{
|
2016-12-22 16:42:33 +01:00
|
|
|
async_call(&torrent::prioritize_pieces, static_cast<aux::vector<int, piece_index_t> const&>(pieces));
|
2007-03-20 02:59:00 +01:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
void torrent_handle::prioritize_pieces(std::vector<std::pair<piece_index_t, int>> const& pieces) const
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::prioritize_piece_list, pieces);
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
2007-03-20 02:59:00 +01:00
|
|
|
std::vector<int> torrent_handle::piece_priorities() const
|
|
|
|
{
|
2016-12-22 16:42:33 +01:00
|
|
|
aux::vector<int, piece_index_t> ret;
|
2016-05-22 01:05:42 +02:00
|
|
|
auto retp = &ret;
|
|
|
|
sync_call(&torrent::piece_priorities, retp);
|
2007-03-20 02:59:00 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
void torrent_handle::file_priority(file_index_t index, int priority) const
|
2008-07-20 18:00:08 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_file_priority, index, priority);
|
2008-07-20 18:00:08 +02:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
int torrent_handle::file_priority(file_index_t index) const
|
2008-07-20 18:00:08 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<int>(0, &torrent::file_priority, index);
|
2008-07-20 18:00:08 +02:00
|
|
|
}
|
|
|
|
|
2007-03-20 02:59:00 +01:00
|
|
|
void torrent_handle::prioritize_files(std::vector<int> const& files) const
|
|
|
|
{
|
2016-12-22 16:42:33 +01:00
|
|
|
async_call(&torrent::prioritize_files
|
|
|
|
, static_cast<aux::vector<int, file_index_t> const&>(files));
|
2007-03-20 02:59:00 +01:00
|
|
|
}
|
|
|
|
|
2008-07-20 18:00:08 +02:00
|
|
|
std::vector<int> torrent_handle::file_priorities() const
|
|
|
|
{
|
2016-12-22 16:42:33 +01:00
|
|
|
aux::vector<int, file_index_t> ret;
|
2016-05-22 01:05:42 +02:00
|
|
|
auto retp = &ret;
|
|
|
|
sync_call(&torrent::file_priorities, retp);
|
2008-07-20 18:00:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
// ============ start deprecation ===============
|
|
|
|
|
2015-04-20 06:52:49 +02:00
|
|
|
int torrent_handle::get_peer_upload_limit(tcp::endpoint) const { return -1; }
|
|
|
|
int torrent_handle::get_peer_download_limit(tcp::endpoint) const { return -1; }
|
|
|
|
void torrent_handle::set_peer_upload_limit(tcp::endpoint, int /* limit */) const {}
|
|
|
|
void torrent_handle::set_peer_download_limit(tcp::endpoint, int /* limit */) const {}
|
|
|
|
void torrent_handle::set_ratio(float) const {}
|
2012-11-02 17:48:18 +01:00
|
|
|
void torrent_handle::use_interface(const char* net_interface) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::use_interface, std::string(net_interface));
|
2012-11-02 17:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if !TORRENT_NO_FPU
|
|
|
|
void torrent_handle::file_progress(std::vector<float>& progress) const
|
|
|
|
{
|
2016-12-22 16:42:33 +01:00
|
|
|
sync_call(&torrent::file_progress_float, std::ref(static_cast<aux::vector<float, file_index_t>&>(progress)));
|
2012-11-02 17:48:18 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-10-30 19:23:30 +02:00
|
|
|
bool torrent_handle::is_seed() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<bool>(false, &torrent::is_seed);
|
2010-10-30 19:23:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool torrent_handle::is_finished() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<bool>(false, &torrent::is_finished);
|
2010-10-30 19:23:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool torrent_handle::is_paused() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<bool>(false, &torrent::is_torrent_paused);
|
2010-10-30 19:23:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool torrent_handle::is_sequential_download() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<bool>(false, &torrent::is_sequential_download);
|
2010-10-30 19:23:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool torrent_handle::is_auto_managed() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<bool>(false, &torrent::is_auto_managed);
|
2010-10-30 19:23:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool torrent_handle::has_metadata() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<bool>(false, &torrent::valid_metadata);
|
2010-10-30 19:23:30 +02:00
|
|
|
}
|
|
|
|
|
2012-03-01 10:01:48 +01:00
|
|
|
bool torrent_handle::super_seeding() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<bool>(false, &torrent::super_seeding);
|
2012-03-01 10:01:48 +01:00
|
|
|
}
|
|
|
|
|
2007-03-20 02:59:00 +01:00
|
|
|
// ============ end deprecation ===============
|
2008-08-03 17:14:08 +02:00
|
|
|
#endif
|
2007-03-20 02:59:00 +01:00
|
|
|
|
2008-11-29 09:38:40 +01:00
|
|
|
std::vector<announce_entry> torrent_handle::trackers() const
|
2004-09-12 12:12:16 +02:00
|
|
|
{
|
2015-03-14 01:42:27 +01:00
|
|
|
static const std::vector<announce_entry> empty;
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<std::vector<announce_entry>>(empty, &torrent::trackers);
|
2004-09-12 12:12:16 +02:00
|
|
|
}
|
|
|
|
|
2007-08-17 18:40:55 +02:00
|
|
|
void torrent_handle::add_url_seed(std::string const& url) const
|
2006-04-25 23:04:48 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::add_web_seed, url, web_seed_entry::url_seed
|
2016-10-03 08:08:03 +02:00
|
|
|
, std::string(), web_seed_entry::headers_t(), false);
|
2006-04-25 23:04:48 +02:00
|
|
|
}
|
|
|
|
|
2007-08-17 18:40:55 +02:00
|
|
|
void torrent_handle::remove_url_seed(std::string const& url) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::remove_web_seed, url, web_seed_entry::url_seed);
|
2007-08-17 18:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::set<std::string> torrent_handle::url_seeds() const
|
|
|
|
{
|
2015-03-14 01:42:27 +01:00
|
|
|
static const std::set<std::string> empty;
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<std::set<std::string>>(empty, &torrent::web_seeds, web_seed_entry::url_seed);
|
2008-12-30 04:54:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::add_http_seed(std::string const& url) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::add_web_seed, url, web_seed_entry::http_seed
|
2016-10-03 08:08:03 +02:00
|
|
|
, std::string(), web_seed_entry::headers_t(), false);
|
2008-12-30 04:54:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::remove_http_seed(std::string const& url) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::remove_web_seed, url, web_seed_entry::http_seed);
|
2008-12-30 04:54:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::set<std::string> torrent_handle::http_seeds() const
|
|
|
|
{
|
2015-03-14 01:42:27 +01:00
|
|
|
static const std::set<std::string> empty;
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<std::set<std::string>>(empty, &torrent::web_seeds, web_seed_entry::http_seed);
|
2007-08-17 18:40:55 +02:00
|
|
|
}
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::replace_trackers(
|
|
|
|
std::vector<announce_entry> const& urls) const
|
2004-09-12 12:12:16 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::replace_trackers, urls);
|
2004-09-12 12:12:16 +02:00
|
|
|
}
|
|
|
|
|
2008-11-26 02:42:14 +01:00
|
|
|
void torrent_handle::add_tracker(announce_entry const& url) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::add_tracker, url);
|
2008-11-26 02:42:14 +01:00
|
|
|
}
|
|
|
|
|
2017-07-27 10:37:32 +02:00
|
|
|
void torrent_handle::add_piece(piece_index_t piece, char const* data, add_piece_flags_t const flags) const
|
2008-12-07 22:04:19 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
sync_call(&torrent::add_piece, piece, data, flags);
|
2008-12-07 22:04:19 +01:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
void torrent_handle::read_piece(piece_index_t piece) const
|
2008-12-14 20:47:02 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::read_piece, piece);
|
2008-12-14 20:47:02 +01:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
bool torrent_handle::have_piece(piece_index_t piece) const
|
2011-11-27 01:01:13 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<bool>(false, &torrent::have_piece, piece);
|
2011-11-27 01:01:13 +01:00
|
|
|
}
|
|
|
|
|
2008-09-04 18:20:19 +02:00
|
|
|
storage_interface* torrent_handle::get_storage_impl() const
|
|
|
|
{
|
2016-12-31 18:35:10 +01:00
|
|
|
return sync_call_ret<storage_interface*>(nullptr, &torrent::get_storage_impl);
|
2008-09-04 18:20:19 +02:00
|
|
|
}
|
|
|
|
|
2012-10-02 18:07:55 +02:00
|
|
|
bool torrent_handle::is_valid() const
|
|
|
|
{
|
|
|
|
return !m_torrent.expired();
|
|
|
|
}
|
|
|
|
|
2016-08-17 23:26:35 +02:00
|
|
|
std::shared_ptr<const torrent_info> torrent_handle::torrent_file() const
|
2012-10-02 18:07:55 +02:00
|
|
|
{
|
2016-08-17 23:26:35 +02:00
|
|
|
return sync_call_ret<std::shared_ptr<const torrent_info>>(
|
|
|
|
std::shared_ptr<const torrent_info>(), &torrent::get_torrent_copy);
|
2012-10-02 18:07:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
// this function should either be removed, or return
|
|
|
|
// reference counted handle to the torrent_info which
|
|
|
|
// forces the torrent to stay loaded while the client holds it
|
2006-11-14 01:08:16 +01:00
|
|
|
torrent_info const& torrent_handle::get_torrent_info() const
|
2004-03-23 23:58:18 +01:00
|
|
|
{
|
2017-02-08 05:36:13 +01:00
|
|
|
static aux::array<std::shared_ptr<const torrent_info>, 4> holder;
|
2014-07-06 21:18:00 +02:00
|
|
|
static int cursor = 0;
|
2016-05-01 00:54:23 +02:00
|
|
|
static std::mutex holder_mutex;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2016-08-17 23:26:35 +02:00
|
|
|
std::shared_ptr<const torrent_info> r = torrent_file();
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2016-05-01 00:54:23 +02:00
|
|
|
std::lock_guard<std::mutex> l(holder_mutex);
|
2014-07-06 21:18:00 +02:00
|
|
|
holder[cursor++] = r;
|
2017-02-08 05:36:13 +01:00
|
|
|
cursor = cursor % holder.end_index();;
|
2014-07-06 21:18:00 +02:00
|
|
|
return *r;
|
2004-03-23 23:58:18 +01:00
|
|
|
}
|
|
|
|
|
2004-02-25 00:55:42 +01:00
|
|
|
entry torrent_handle::write_resume_data() const
|
2004-01-02 21:46:24 +01:00
|
|
|
{
|
2017-03-05 15:31:28 +01:00
|
|
|
add_torrent_params params;
|
|
|
|
auto retr = std::ref(params);
|
2016-05-22 01:05:42 +02:00
|
|
|
sync_call(&torrent::write_resume_data, retr);
|
2017-03-05 15:31:28 +01:00
|
|
|
return libtorrent::write_resume_data(params);
|
2004-01-02 21:46:24 +01:00
|
|
|
}
|
|
|
|
|
2009-10-26 02:29:39 +01:00
|
|
|
std::string torrent_handle::save_path() const
|
2003-12-07 06:53:04 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<std::string>("", &torrent::save_path);
|
2003-12-07 06:53:04 +01:00
|
|
|
}
|
|
|
|
|
2013-03-03 00:17:48 +01:00
|
|
|
std::string torrent_handle::name() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
return sync_call_ret<std::string>("", &torrent::name);
|
2013-03-03 00:17:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-07-16 20:26:00 +02:00
|
|
|
void torrent_handle::connect_peer(tcp::endpoint const& adr
|
|
|
|
, peer_source_flags_t const source, int flags) const
|
2004-01-08 18:03:04 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::add_peer, adr, source, flags);
|
2004-01-08 18:03:04 +01:00
|
|
|
}
|
|
|
|
|
2014-01-02 03:16:31 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2005-05-03 15:13:57 +02:00
|
|
|
void torrent_handle::force_reannounce(
|
2007-04-07 05:05:59 +02:00
|
|
|
boost::posix_time::time_duration duration) const
|
2005-05-03 15:13:57 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::force_tracker_request, aux::time_now()
|
2014-01-02 03:16:31 +01:00
|
|
|
+ seconds(duration.total_seconds()), -1);
|
2005-05-03 15:13:57 +02:00
|
|
|
}
|
2016-08-14 19:11:59 +02:00
|
|
|
|
2017-04-09 00:24:50 +02:00
|
|
|
void torrent_handle::file_status(std::vector<open_file_state>& status) const
|
2016-08-14 19:11:59 +02:00
|
|
|
{
|
|
|
|
status.clear();
|
|
|
|
|
2016-08-31 14:27:36 +02:00
|
|
|
std::shared_ptr<torrent> t = m_torrent.lock();
|
2016-08-14 19:11:59 +02:00
|
|
|
if (!t || !t->has_storage()) return;
|
|
|
|
session_impl& ses = static_cast<session_impl&>(t->session());
|
2017-04-09 00:24:50 +02:00
|
|
|
status = ses.disk_thread().get_status(t->storage());
|
2016-08-14 19:11:59 +02:00
|
|
|
}
|
2014-01-02 03:16:31 +01:00
|
|
|
#endif
|
2005-05-03 15:13:57 +02:00
|
|
|
|
2009-10-25 03:37:45 +01:00
|
|
|
void torrent_handle::force_dht_announce() const
|
|
|
|
{
|
2013-04-09 03:04:43 +02:00
|
|
|
#ifndef TORRENT_DISABLE_DHT
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::dht_announce);
|
2009-10-25 03:37:45 +01:00
|
|
|
#endif
|
2013-04-09 03:04:43 +02:00
|
|
|
}
|
2009-10-25 03:37:45 +01:00
|
|
|
|
2014-01-02 03:16:31 +01:00
|
|
|
void torrent_handle::force_reannounce(int s, int idx) const
|
2004-01-08 18:03:04 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::force_tracker_request, aux::time_now() + seconds(s), idx);
|
2004-01-08 18:03:04 +01:00
|
|
|
}
|
|
|
|
|
2017-04-09 00:24:50 +02:00
|
|
|
std::vector<open_file_state> torrent_handle::file_status() const
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
2016-08-31 14:27:36 +02:00
|
|
|
std::shared_ptr<torrent> t = m_torrent.lock();
|
2016-08-14 19:11:59 +02:00
|
|
|
if (!t || !t->has_storage()) return {};
|
2015-08-02 01:55:28 +02:00
|
|
|
session_impl& ses = static_cast<session_impl&>(t->session());
|
2017-04-09 00:24:50 +02:00
|
|
|
return ses.disk_thread().get_status(t->storage());
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
2016-01-25 06:51:20 +01:00
|
|
|
void torrent_handle::scrape_tracker(int idx) const
|
2007-11-20 23:46:27 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::scrape_tracker, idx, true);
|
2007-11-20 23:46:27 +01:00
|
|
|
}
|
|
|
|
|
2017-07-01 17:43:39 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2008-12-08 07:36:22 +01:00
|
|
|
void torrent_handle::super_seeding(bool on) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_super_seeding, on);
|
2008-12-08 07:36:22 +01:00
|
|
|
}
|
|
|
|
|
2008-04-13 08:32:48 +02:00
|
|
|
void torrent_handle::get_full_peer_list(std::vector<peer_list_entry>& v) const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
auto vp = &v;
|
|
|
|
sync_call(&torrent::get_full_peer_list, vp);
|
2008-04-13 08:32:48 +02:00
|
|
|
}
|
2016-06-17 22:07:28 +02:00
|
|
|
#endif
|
2008-04-13 08:32:48 +02:00
|
|
|
|
2003-12-07 06:53:04 +01:00
|
|
|
void torrent_handle::get_peer_info(std::vector<peer_info>& v) const
|
2003-10-30 00:28:09 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
auto vp = &v;
|
|
|
|
sync_call(&torrent::get_peer_info, vp);
|
2003-10-30 00:28:09 +01:00
|
|
|
}
|
2005-03-22 18:50:05 +01:00
|
|
|
|
2003-12-07 06:53:04 +01:00
|
|
|
void torrent_handle::get_download_queue(std::vector<partial_piece_info>& queue) const
|
2003-10-30 00:28:09 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
auto queuep = &queue;
|
|
|
|
sync_call(&torrent::get_download_queue, queuep);
|
2003-11-02 22:06:50 +01:00
|
|
|
}
|
|
|
|
|
2017-07-27 10:37:32 +02:00
|
|
|
void torrent_handle::set_piece_deadline(piece_index_t index, int deadline
|
|
|
|
, deadline_flags_t const flags) const
|
2009-03-17 10:34:44 +01:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::set_piece_deadline, index, deadline, flags);
|
2009-03-17 10:34:44 +01:00
|
|
|
}
|
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
void torrent_handle::reset_piece_deadline(piece_index_t index) const
|
2011-08-05 08:31:46 +02:00
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::reset_piece_deadline, index);
|
2011-08-05 08:31:46 +02:00
|
|
|
}
|
|
|
|
|
2014-05-23 04:23:11 +02:00
|
|
|
void torrent_handle::clear_piece_deadlines() const
|
|
|
|
{
|
2016-05-22 01:05:42 +02:00
|
|
|
async_call(&torrent::clear_time_critical);
|
2014-05-23 04:23:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-31 14:27:36 +02:00
|
|
|
std::shared_ptr<torrent> torrent_handle::native_handle() const
|
2012-08-30 03:54:35 +02:00
|
|
|
{
|
|
|
|
return m_torrent.lock();
|
|
|
|
}
|
|
|
|
|
2011-12-23 06:36:13 +01:00
|
|
|
std::size_t hash_value(torrent_handle const& th)
|
|
|
|
{
|
2012-11-10 20:50:10 +01:00
|
|
|
// using the locked shared_ptr value as hash doesn't work
|
|
|
|
// for expired weak_ptrs. So, we're left with a hack
|
|
|
|
return std::size_t(*reinterpret_cast<void* const*>(&th.m_torrent));
|
2011-12-23 06:36:13 +01:00
|
|
|
}
|
2017-06-07 16:41:28 +02:00
|
|
|
|
|
|
|
static_assert(std::is_nothrow_move_constructible<torrent_handle>::value
|
|
|
|
, "should be nothrow move constructible");
|
|
|
|
static_assert(std::is_nothrow_move_assignable<torrent_handle>::value
|
|
|
|
, "should be nothrow move assignable");
|
|
|
|
static_assert(std::is_nothrow_default_constructible<torrent_handle>::value
|
|
|
|
, "should be nothrow default constructible");
|
2003-10-30 00:28:09 +01:00
|
|
|
}
|