2003-10-30 00:28:09 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2003, Arvid Norberg
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-03-17 18:15:16 +01:00
|
|
|
#include "libtorrent/pch.hpp"
|
|
|
|
|
2003-10-30 00:28:09 +01:00
|
|
|
#include <ctime>
|
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <set>
|
|
|
|
#include <cctype>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2004-01-25 19:18:36 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push, 1)
|
|
|
|
#endif
|
|
|
|
|
2003-10-30 00:28:09 +01:00
|
|
|
#include <boost/filesystem/convenience.hpp>
|
2003-12-09 19:09:34 +01:00
|
|
|
#include <boost/optional.hpp>
|
2004-03-23 23:58:18 +01:00
|
|
|
#include <boost/bind.hpp>
|
2003-10-30 00:28:09 +01:00
|
|
|
|
2004-01-25 19:18:36 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2003-10-30 00:28:09 +01:00
|
|
|
#include "libtorrent/peer_id.hpp"
|
2006-04-25 23:04:48 +02:00
|
|
|
#include "libtorrent/bt_peer_connection.hpp"
|
2003-10-30 00:28:09 +01:00
|
|
|
#include "libtorrent/torrent_info.hpp"
|
2004-01-31 11:46:15 +01:00
|
|
|
#include "libtorrent/tracker_manager.hpp"
|
2003-10-30 00:28:09 +01:00
|
|
|
#include "libtorrent/bencode.hpp"
|
|
|
|
#include "libtorrent/hasher.hpp"
|
|
|
|
#include "libtorrent/entry.hpp"
|
|
|
|
#include "libtorrent/session.hpp"
|
2006-10-11 16:02:21 +02:00
|
|
|
#include "libtorrent/aux_/session_impl.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"
|
2003-10-30 00:28:09 +01:00
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
using ::srand;
|
2004-01-02 21:46:24 +01:00
|
|
|
using ::isalnum;
|
2003-10-30 00:28:09 +01:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2004-10-29 15:21:09 +02:00
|
|
|
using boost::bind;
|
2006-10-11 16:02:21 +02:00
|
|
|
using libtorrent::aux::session_impl;
|
2004-10-29 15:21:09 +02:00
|
|
|
|
2007-11-25 19:48:43 +01:00
|
|
|
#ifdef BOOST_NO_EXCEPTIONS
|
|
|
|
|
|
|
|
#define TORRENT_FORWARD(call) \
|
2008-04-09 22:09:36 +02:00
|
|
|
boost::shared_ptr<torrent> t = m_torrent.lock(); \
|
2008-03-08 07:06:31 +01:00
|
|
|
if (!t) return; \
|
2008-04-09 22:09:36 +02:00
|
|
|
session_impl::mutex_t::scoped_lock l(t->session().m_mutex); \
|
2007-11-25 19:48:43 +01:00
|
|
|
t->call
|
|
|
|
|
|
|
|
#define TORRENT_FORWARD_RETURN(call, def) \
|
2008-04-09 22:09:36 +02:00
|
|
|
boost::shared_ptr<torrent> t = m_torrent.lock(); \
|
2008-03-08 07:06:31 +01:00
|
|
|
if (!t) return def; \
|
2008-04-09 22:09:36 +02:00
|
|
|
session_impl::mutex_t::scoped_lock l(t->session().m_mutex); \
|
2007-11-25 19:48:43 +01:00
|
|
|
return t->call
|
|
|
|
|
|
|
|
#define TORRENT_FORWARD_RETURN2(call, def) \
|
2008-04-09 22:09:36 +02:00
|
|
|
boost::shared_ptr<torrent> t = m_torrent.lock(); \
|
2008-03-08 07:06:31 +01:00
|
|
|
if (!t) return def; \
|
2008-04-09 22:09:36 +02:00
|
|
|
session_impl::mutex_t::scoped_lock l(t->session().m_mutex); \
|
2007-11-25 19:48:43 +01:00
|
|
|
t->call
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define TORRENT_FORWARD(call) \
|
2008-04-09 22:09:36 +02:00
|
|
|
boost::shared_ptr<torrent> t = m_torrent.lock(); \
|
2008-03-08 07:06:31 +01:00
|
|
|
if (!t) throw_invalid_handle(); \
|
2008-04-09 22:09:36 +02:00
|
|
|
session_impl::mutex_t::scoped_lock l(t->session().m_mutex); \
|
2007-11-25 19:48:43 +01:00
|
|
|
t->call
|
|
|
|
|
|
|
|
#define TORRENT_FORWARD_RETURN(call, def) \
|
2008-04-09 22:09:36 +02:00
|
|
|
boost::shared_ptr<torrent> t = m_torrent.lock(); \
|
|
|
|
if (!t) throw_invalid_handle(); \
|
|
|
|
session_impl::mutex_t::scoped_lock l(t->session().m_mutex); \
|
2007-11-25 19:48:43 +01:00
|
|
|
return t->call
|
|
|
|
|
|
|
|
#define TORRENT_FORWARD_RETURN2(call, def) \
|
2008-04-09 22:09:36 +02:00
|
|
|
boost::shared_ptr<torrent> t = m_torrent.lock(); \
|
|
|
|
if (!t) throw_invalid_handle(); \
|
|
|
|
session_impl::mutex_t::scoped_lock l(t->session().m_mutex); \
|
2007-11-25 19:48:43 +01:00
|
|
|
t->call
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2003-10-30 00:28:09 +01:00
|
|
|
namespace libtorrent
|
|
|
|
{
|
2007-06-10 22:46:09 +02:00
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
2007-11-25 19:48:43 +01:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2009-02-23 02:21:19 +01:00
|
|
|
void throw_invalid_handle()
|
|
|
|
{
|
|
|
|
throw libtorrent_exception(error_code(
|
|
|
|
errors::invalid_torrent_handle, libtorrent_category));
|
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
|
|
|
|
2008-11-29 22:33:21 +01:00
|
|
|
#ifdef TORRENT_DEBUG
|
2004-02-29 17:39:52 +01:00
|
|
|
|
|
|
|
void torrent_handle::check_invariant() const
|
2008-04-09 22:09:36 +02:00
|
|
|
{}
|
2004-02-29 17:39:52 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-04-09 22:09:36 +02:00
|
|
|
sha1_hash torrent_handle::info_hash() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
const static sha1_hash empty;
|
|
|
|
TORRENT_FORWARD_RETURN(torrent_file().info_hash(), empty);
|
|
|
|
}
|
|
|
|
|
2009-04-07 17:55:05 +02:00
|
|
|
int torrent_handle::max_uploads() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD_RETURN(max_uploads(), 0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(max_uploads >= 2 || max_uploads == -1);
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(set_max_uploads(max_uploads));
|
2003-12-14 06:56:12 +01:00
|
|
|
}
|
2004-01-21 01:59:38 +01:00
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::use_interface(const char* net_interface) const
|
2004-02-26 01:27:06 +01:00
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(use_interface(net_interface));
|
2004-02-26 01:27:06 +01:00
|
|
|
}
|
|
|
|
|
2008-11-08 08:40:55 +01:00
|
|
|
int torrent_handle::max_connections() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD_RETURN(max_connections(), 0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(max_connections >= 2 || max_connections == -1);
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(set_max_connections(max_connections));
|
2004-01-21 01:59:38 +01:00
|
|
|
}
|
2003-10-30 00:28:09 +01:00
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
void torrent_handle::set_peer_upload_limit(tcp::endpoint ip, int limit) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(limit >= -1);
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(set_peer_upload_limit(ip, limit));
|
2006-04-25 23:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::set_peer_download_limit(tcp::endpoint ip, int limit) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(limit >= -1);
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(set_peer_download_limit(ip, limit));
|
2006-04-25 23:04:48 +02: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
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(limit >= -1);
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(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
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN(upload_limit(), 0);
|
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
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(limit >= -1);
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(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
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN(download_limit(), 0);
|
2007-04-10 11:25:17 +02:00
|
|
|
}
|
|
|
|
|
2007-06-10 22:46:09 +02:00
|
|
|
void torrent_handle::move_storage(
|
|
|
|
fs::path const& save_path) const
|
2004-07-18 02:39:58 +02:00
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(move_storage(save_path));
|
2004-07-18 02:39:58 +02:00
|
|
|
}
|
|
|
|
|
2009-03-31 10:12:35 +02:00
|
|
|
#ifndef BOOST_FILESYSTEM_NARROW_ONLY
|
2008-11-30 09:12:26 +01:00
|
|
|
void torrent_handle::move_storage(
|
|
|
|
fs::wpath const& save_path) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
std::string utf8;
|
|
|
|
wchar_utf8(save_path.string(), utf8);
|
|
|
|
TORRENT_FORWARD(move_storage(utf8));
|
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::rename_file(int index, fs::wpath const& new_name) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
std::string utf8;
|
|
|
|
wchar_utf8(new_name.string(), utf8);
|
|
|
|
TORRENT_FORWARD(rename_file(index, utf8));
|
|
|
|
}
|
2009-03-31 10:12:35 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void torrent_handle::rename_file(int index, fs::path const& new_name) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(rename_file(index, new_name.string()));
|
|
|
|
}
|
2008-11-30 09:12:26 +01:00
|
|
|
|
2007-11-08 02:45:35 +01:00
|
|
|
void torrent_handle::add_extension(
|
|
|
|
boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext
|
|
|
|
, void* userdata)
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(add_extension(ext, userdata));
|
2007-11-08 02:45:35 +01:00
|
|
|
}
|
|
|
|
|
2004-09-10 02:47:30 +02:00
|
|
|
bool torrent_handle::has_metadata() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN(valid_metadata(), false);
|
2004-09-10 02:47:30 +02:00
|
|
|
}
|
|
|
|
|
2008-09-24 04:32:33 +02:00
|
|
|
bool torrent_handle::set_metadata(char const* metadata, int size) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD_RETURN(set_metadata(metadata, size), false);
|
|
|
|
}
|
|
|
|
|
2004-09-08 01:16:11 +02:00
|
|
|
bool torrent_handle::is_seed() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN(is_seed(), false);
|
2004-09-08 01:16:11 +02:00
|
|
|
}
|
|
|
|
|
2008-04-13 04:15:56 +02:00
|
|
|
bool torrent_handle::is_finished() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD_RETURN(is_finished(), false);
|
|
|
|
}
|
|
|
|
|
2004-03-21 03:03:37 +01:00
|
|
|
bool torrent_handle::is_paused() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2008-08-21 13:24:24 +02:00
|
|
|
TORRENT_FORWARD_RETURN(is_torrent_paused(), false);
|
2004-03-21 03:03:37 +01:00
|
|
|
}
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::pause() const
|
2004-03-21 03:03:37 +01:00
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(pause());
|
2004-03-21 03:03:37 +01:00
|
|
|
}
|
|
|
|
|
2009-06-19 00:32:55 +02:00
|
|
|
void torrent_handle::set_upload_mode(bool b) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(set_upload_mode(b));
|
|
|
|
}
|
|
|
|
|
2008-04-13 20:54:36 +02:00
|
|
|
void torrent_handle::save_resume_data() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(save_resume_data());
|
|
|
|
}
|
|
|
|
|
2008-06-07 18:24:56 +02:00
|
|
|
void torrent_handle::force_recheck() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(force_recheck());
|
|
|
|
}
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::resume() const
|
2004-03-21 03:03:37 +01:00
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(resume());
|
2004-03-23 23:58:18 +01:00
|
|
|
}
|
2004-03-21 03:03:37 +01:00
|
|
|
|
2008-04-24 05:28:48 +02:00
|
|
|
bool torrent_handle::is_auto_managed() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD_RETURN(is_auto_managed(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::auto_managed(bool m) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(auto_managed(m));
|
|
|
|
}
|
|
|
|
|
2008-05-29 05:37:19 +02:00
|
|
|
int torrent_handle::queue_position() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD_RETURN(queue_position(), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::queue_position_up() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2009-01-05 19:45:05 +01:00
|
|
|
TORRENT_FORWARD(set_queue_position(t->queue_position() == 0
|
|
|
|
? t->queue_position() : t->queue_position() - 1));
|
2008-05-29 05:37:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::queue_position_down() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(set_queue_position(t->queue_position() + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::queue_position_top() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(set_queue_position(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::queue_position_bottom() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(set_queue_position((std::numeric_limits<int>::max)()));
|
|
|
|
}
|
|
|
|
|
2008-07-12 19:00:52 +02:00
|
|
|
void torrent_handle::clear_error() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(clear_error());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2008-03-22 01:26:58 +01:00
|
|
|
TORRENT_FORWARD(set_tracker_login(name, password));
|
2004-03-21 03:03:37 +01:00
|
|
|
}
|
|
|
|
|
2008-08-03 17:14:08 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2008-07-12 15:38:22 +02:00
|
|
|
void torrent_handle::file_progress(std::vector<float>& progress) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(file_progress(progress));
|
|
|
|
}
|
2008-08-03 17:14:08 +02:00
|
|
|
#endif
|
2008-07-12 15:38:22 +02:00
|
|
|
|
2009-07-04 06:58:24 +02:00
|
|
|
void torrent_handle::file_progress(std::vector<size_type>& progress, int flags) const
|
2006-06-12 01:24:36 +02:00
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2009-07-04 06:58:24 +02:00
|
|
|
TORRENT_FORWARD(file_progress(progress, flags));
|
2006-06-12 01:24:36 +02:00
|
|
|
}
|
2004-03-23 23:58:18 +01:00
|
|
|
|
|
|
|
torrent_status torrent_handle::status() const
|
2004-02-22 23:40:45 +01:00
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2008-04-09 22:09:36 +02:00
|
|
|
TORRENT_FORWARD_RETURN(status(), torrent_status());
|
2004-02-22 23:40:45 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2008-01-31 18:52:29 +01:00
|
|
|
TORRENT_FORWARD(set_sequential_download(sd));
|
2006-09-04 19:17:45 +02:00
|
|
|
}
|
|
|
|
|
2008-06-17 10:30:04 +02:00
|
|
|
bool torrent_handle::is_sequential_download() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD_RETURN(is_sequential_download(), false);
|
|
|
|
}
|
|
|
|
|
2007-03-20 02:59:00 +01:00
|
|
|
std::string torrent_handle::name() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN(name(), "");
|
2007-03-20 02:59:00 +01:00
|
|
|
}
|
|
|
|
|
2007-05-30 08:52:59 +02:00
|
|
|
void torrent_handle::piece_availability(std::vector<int>& avail) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(piece_availability(avail));
|
2007-05-30 08:52:59 +02:00
|
|
|
}
|
|
|
|
|
2007-03-20 02:59:00 +01:00
|
|
|
void torrent_handle::piece_priority(int index, int priority) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(set_piece_priority(index, priority));
|
2007-03-20 02:59:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int torrent_handle::piece_priority(int index) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN(piece_priority(index), 0);
|
2007-03-20 02:59:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::prioritize_pieces(std::vector<int> const& pieces) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(prioritize_pieces(pieces));
|
2007-03-20 02:59:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> torrent_handle::piece_priorities() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
std::vector<int> ret;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN2(piece_priorities(ret), ret);
|
2007-03-20 02:59:00 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-07-20 18:00:08 +02:00
|
|
|
void torrent_handle::file_priority(int index, int priority) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(set_file_priority(index, priority));
|
|
|
|
}
|
|
|
|
|
|
|
|
int torrent_handle::file_priority(int index) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD_RETURN(file_priority(index), 0);
|
|
|
|
}
|
|
|
|
|
2007-03-20 02:59:00 +01:00
|
|
|
void torrent_handle::prioritize_files(std::vector<int> const& files) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(prioritize_files(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
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
std::vector<int> ret;
|
|
|
|
TORRENT_FORWARD_RETURN2(file_priorities(ret), ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-03 17:14:08 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2007-03-20 02:59:00 +01:00
|
|
|
// ============ start deprecation ===============
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::filter_piece(int index, bool filter) const
|
2005-05-25 12:01:01 +02:00
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(filter_piece(index, filter));
|
2005-05-25 12:01:01 +02:00
|
|
|
}
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::filter_pieces(std::vector<bool> const& pieces) const
|
2005-06-23 01:04:37 +02:00
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(filter_pieces(pieces));
|
2005-06-23 01:04:37 +02:00
|
|
|
}
|
|
|
|
|
2005-05-25 12:01:01 +02:00
|
|
|
bool torrent_handle::is_piece_filtered(int index) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN(is_piece_filtered(index), false);
|
2005-05-25 12:01:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<bool> torrent_handle::filtered_pieces() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
std::vector<bool> ret;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN2(filtered_pieces(ret), ret);
|
2005-05-25 12:01:01 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2005-07-02 10:47:46 +02:00
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::filter_files(std::vector<bool> const& files) const
|
2005-07-04 01:33:47 +02:00
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(filter_files(files));
|
2005-07-04 01:33:47 +02: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
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
const static std::vector<announce_entry> empty;
|
|
|
|
TORRENT_FORWARD_RETURN(trackers(), empty);
|
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
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2008-12-30 04:54:07 +01:00
|
|
|
TORRENT_FORWARD(add_web_seed(url, web_seed_entry::url_seed));
|
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
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2008-12-30 04:54:07 +01:00
|
|
|
TORRENT_FORWARD(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
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
const static std::set<std::string> empty;
|
2008-12-30 04:54:07 +01:00
|
|
|
TORRENT_FORWARD_RETURN(web_seeds(web_seed_entry::url_seed), empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::add_http_seed(std::string const& url) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(add_web_seed(url, web_seed_entry::http_seed));
|
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::remove_http_seed(std::string const& url) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(remove_web_seed(url, web_seed_entry::http_seed));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<std::string> torrent_handle::http_seeds() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
const static std::set<std::string> empty;
|
|
|
|
TORRENT_FORWARD_RETURN(web_seeds(web_seed_entry::http_seed), empty);
|
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
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(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
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(add_tracker(url));
|
|
|
|
}
|
|
|
|
|
2008-12-07 22:04:19 +01:00
|
|
|
void torrent_handle::add_piece(int piece, char const* data, int flags) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(add_piece(piece, data, flags));
|
|
|
|
}
|
|
|
|
|
2008-12-14 20:47:02 +01:00
|
|
|
void torrent_handle::read_piece(int piece) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(read_piece(piece));
|
|
|
|
}
|
|
|
|
|
2008-09-04 18:20:19 +02:00
|
|
|
storage_interface* torrent_handle::get_storage_impl() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD_RETURN(get_storage(), 0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
#ifdef BOOST_NO_EXCEPTIONS
|
2008-10-21 10:45:42 +02:00
|
|
|
const static torrent_info empty(sha1_hash(0));
|
2008-04-09 22:09:36 +02:00
|
|
|
#endif
|
|
|
|
boost::shared_ptr<torrent> t = m_torrent.lock();
|
|
|
|
if (!t)
|
|
|
|
#ifdef BOOST_NO_EXCEPTIONS
|
|
|
|
return empty;
|
2007-11-25 19:48:43 +01:00
|
|
|
#else
|
2008-04-09 22:09:36 +02:00
|
|
|
throw_invalid_handle();
|
2007-11-25 19:48:43 +01:00
|
|
|
#endif
|
2008-04-09 22:09:36 +02:00
|
|
|
session_impl::mutex_t::scoped_lock l(t->session().m_mutex);
|
|
|
|
if (!t->valid_metadata())
|
2007-11-25 19:48:43 +01:00
|
|
|
#ifdef BOOST_NO_EXCEPTIONS
|
|
|
|
return empty;
|
|
|
|
#else
|
|
|
|
throw_invalid_handle();
|
|
|
|
#endif
|
2007-08-27 02:47:17 +02:00
|
|
|
return t->torrent_file();
|
2004-03-23 23:58:18 +01:00
|
|
|
}
|
|
|
|
|
2003-12-07 06:53:04 +01:00
|
|
|
bool torrent_handle::is_valid() const
|
2003-11-28 18:29:27 +01:00
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2008-04-09 22:09:36 +02:00
|
|
|
return !m_torrent.expired();
|
2003-10-30 00:28:09 +01:00
|
|
|
}
|
|
|
|
|
2008-08-03 17:14:08 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2004-02-25 00:55:42 +01:00
|
|
|
entry torrent_handle::write_resume_data() const
|
2004-01-02 21:46:24 +01:00
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
|
|
|
|
2004-01-07 01:48:02 +01:00
|
|
|
entry ret(entry::dictionary_t);
|
2008-10-21 10:45:42 +02:00
|
|
|
TORRENT_FORWARD_RETURN2(write_resume_data(ret), ret);
|
2008-04-13 20:54:36 +02:00
|
|
|
t->filesystem().write_resume_data(ret);
|
2004-01-12 04:05:10 +01:00
|
|
|
|
2004-01-07 01:48:02 +01:00
|
|
|
return ret;
|
2004-01-02 21:46:24 +01:00
|
|
|
}
|
2008-08-03 17:14:08 +02:00
|
|
|
#endif
|
2004-01-02 21:46:24 +01:00
|
|
|
|
2007-06-10 22:46:09 +02:00
|
|
|
fs::path torrent_handle::save_path() const
|
2003-12-07 06:53:04 +01:00
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN(save_path(), fs::path());
|
2003-12-07 06:53:04 +01:00
|
|
|
}
|
|
|
|
|
2007-04-10 23:23:13 +02:00
|
|
|
void torrent_handle::connect_peer(tcp::endpoint const& adr, int source) const
|
2004-01-08 18:03:04 +01:00
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
|
|
|
|
2008-04-09 22:09:36 +02:00
|
|
|
boost::shared_ptr<torrent> t = m_torrent.lock();
|
2006-05-28 21:03:54 +02:00
|
|
|
if (!t)
|
2007-11-25 19:48:43 +01:00
|
|
|
#ifdef BOOST_NO_EXCEPTIONS
|
2008-03-08 07:06:31 +01:00
|
|
|
return;
|
2007-11-25 19:48:43 +01:00
|
|
|
#else
|
2008-03-08 07:06:31 +01:00
|
|
|
throw_invalid_handle();
|
2007-11-25 19:48:43 +01:00
|
|
|
#endif
|
2008-04-09 22:09:36 +02:00
|
|
|
session_impl::mutex_t::scoped_lock l(t->session().m_mutex);
|
|
|
|
|
2004-01-08 18:03:04 +01:00
|
|
|
peer_id id;
|
|
|
|
std::fill(id.begin(), id.end(), 0);
|
2009-05-16 00:07:19 +02:00
|
|
|
t->get_policy().add_peer(adr, id, source, 0);
|
2004-01-08 18:03:04 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(force_tracker_request(time_now() + seconds(duration.total_seconds())));
|
2005-05-03 15:13:57 +02:00
|
|
|
}
|
|
|
|
|
2004-01-08 18:03:04 +01:00
|
|
|
void torrent_handle::force_reannounce() const
|
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(force_tracker_request());
|
2004-01-08 18:03:04 +01:00
|
|
|
}
|
|
|
|
|
2007-11-20 23:46:27 +01:00
|
|
|
void torrent_handle::scrape_tracker() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(scrape_tracker());
|
2007-11-20 23:46:27 +01:00
|
|
|
}
|
|
|
|
|
2008-12-08 07:36:22 +01:00
|
|
|
bool torrent_handle::super_seeding() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD_RETURN(super_seeding(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void torrent_handle::super_seeding(bool on) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(super_seeding(on));
|
|
|
|
}
|
|
|
|
|
2005-10-19 15:58:41 +02:00
|
|
|
void torrent_handle::set_ratio(float ratio) const
|
2004-01-12 04:05:10 +01:00
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(ratio >= 0.f);
|
2004-01-12 04:05:10 +01:00
|
|
|
if (ratio < 1.f && ratio > 0.f)
|
|
|
|
ratio = 1.f;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(set_ratio(ratio));
|
2004-01-12 04:05:10 +01:00
|
|
|
}
|
|
|
|
|
2007-05-02 21:47:38 +02:00
|
|
|
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
|
2007-01-29 08:39:33 +01:00
|
|
|
void torrent_handle::resolve_countries(bool r)
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(resolve_countries(r));
|
2007-01-29 08:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool torrent_handle::resolve_countries() const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD_RETURN(resolving_countries(), false);
|
2007-01-29 08:39:33 +01:00
|
|
|
}
|
2007-05-02 21:47:38 +02:00
|
|
|
#endif
|
2007-01-29 08:39:33 +01:00
|
|
|
|
2008-04-13 08:32:48 +02:00
|
|
|
void torrent_handle::get_full_peer_list(std::vector<peer_list_entry>& v) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(get_full_peer_list(v));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(get_peer_info(v));
|
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
|
|
|
{
|
2004-02-29 17:39:52 +01:00
|
|
|
INVARIANT_CHECK;
|
2007-11-25 19:48:43 +01:00
|
|
|
TORRENT_FORWARD(get_download_queue(queue));
|
2003-11-02 22:06:50 +01:00
|
|
|
}
|
|
|
|
|
2009-03-17 10:34:44 +01:00
|
|
|
void torrent_handle::set_piece_deadline(int index, time_duration deadline, int flags) const
|
|
|
|
{
|
|
|
|
INVARIANT_CHECK;
|
|
|
|
TORRENT_FORWARD(set_piece_deadline(index, deadline, flags));
|
|
|
|
}
|
|
|
|
|
2003-10-30 00:28:09 +01:00
|
|
|
}
|
2005-10-19 15:58:41 +02:00
|
|
|
|