forked from premiere/premiere-libtorrent
added option to set file priorities when adding torrents
This commit is contained in:
parent
a3d95677b0
commit
97afe3fca8
|
@ -1,3 +1,4 @@
|
||||||
|
* added option to set file priorities when adding torrents
|
||||||
* removed the session mutex for improved performance
|
* removed the session mutex for improved performance
|
||||||
* added upload and download activity timer stats for torrents
|
* added upload and download activity timer stats for torrents
|
||||||
* made the reuse-address flag configurable on the listen socket
|
* made the reuse-address flag configurable on the listen socket
|
||||||
|
|
|
@ -369,12 +369,14 @@ add_torrent()
|
||||||
::
|
::
|
||||||
|
|
||||||
typedef storage_interface* (&storage_constructor_type)(
|
typedef storage_interface* (&storage_constructor_type)(
|
||||||
file_storage const&, file_storage const*, fs::path const&, file_pool&);
|
file_storage const&, file_storage const*, fs::path const&, file_pool&
|
||||||
|
, std::vector<boost::uint8_t> const&);
|
||||||
|
|
||||||
struct add_torrent_params
|
struct add_torrent_params
|
||||||
{
|
{
|
||||||
add_torrent_params(storage_constructor_type s);
|
add_torrent_params(storage_constructor_type s);
|
||||||
|
|
||||||
|
int version;
|
||||||
boost::intrusive_ptr<torrent_info> ti;
|
boost::intrusive_ptr<torrent_info> ti;
|
||||||
char const* tracker_url;
|
char const* tracker_url;
|
||||||
sha1_hash info_hash;
|
sha1_hash info_hash;
|
||||||
|
@ -390,6 +392,7 @@ add_torrent()
|
||||||
bool seed_mode;
|
bool seed_mode;
|
||||||
bool override_resume_data;
|
bool override_resume_data;
|
||||||
bool upload_mode;
|
bool upload_mode;
|
||||||
|
std::vector<boost::uint8_t> const* file_priorities;
|
||||||
};
|
};
|
||||||
|
|
||||||
torrent_handle add_torrent(add_torrent_params const& params);
|
torrent_handle add_torrent(add_torrent_params const& params);
|
||||||
|
@ -500,6 +503,12 @@ on disk I/O errors, and if the torrent is also auto managed, it will be taken ou
|
||||||
of this state periodically. This mode can be used to avoid race conditions when
|
of this state periodically. This mode can be used to avoid race conditions when
|
||||||
adjusting priorities of pieces before allowing the torrent to start downloading.
|
adjusting priorities of pieces before allowing the torrent to start downloading.
|
||||||
|
|
||||||
|
``file_priorities`` can be set to control the initial file priorities when adding
|
||||||
|
a torrent. The semantics are the same as for ``torrent_handle::prioritize_files()``.
|
||||||
|
|
||||||
|
``version`` is filled in by the constructor and should be left untouched. It
|
||||||
|
is used for forward binary compatibility.
|
||||||
|
|
||||||
remove_torrent()
|
remove_torrent()
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
@ -3749,6 +3758,7 @@ session_settings
|
||||||
struct session_settings
|
struct session_settings
|
||||||
{
|
{
|
||||||
session_settings();
|
session_settings();
|
||||||
|
int version;
|
||||||
std::string user_agent;
|
std::string user_agent;
|
||||||
int tracker_completion_timeout;
|
int tracker_completion_timeout;
|
||||||
int tracker_receive_timeout;
|
int tracker_receive_timeout;
|
||||||
|
@ -3912,6 +3922,9 @@ session_settings
|
||||||
int tick_interval;
|
int tick_interval;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
``version`` is automatically set to the libtorrent version you're using
|
||||||
|
in order to be forward binary compatible. This field should not be changed.
|
||||||
|
|
||||||
``user_agent`` this is the client identification to the tracker.
|
``user_agent`` this is the client identification to the tracker.
|
||||||
The recommended format of this string is:
|
The recommended format of this string is:
|
||||||
"ClientName/ClientVersion libtorrent/libtorrentVersion".
|
"ClientName/ClientVersion libtorrent/libtorrentVersion".
|
||||||
|
|
|
@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "libtorrent/storage_defs.hpp"
|
#include "libtorrent/storage_defs.hpp"
|
||||||
#include "libtorrent/peer_id.hpp" // sha1_hash
|
#include "libtorrent/peer_id.hpp" // sha1_hash
|
||||||
|
#include "libtorrent/version.hpp"
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
@ -47,7 +48,8 @@ namespace libtorrent
|
||||||
struct add_torrent_params
|
struct add_torrent_params
|
||||||
{
|
{
|
||||||
add_torrent_params(storage_constructor_type sc = default_storage_constructor)
|
add_torrent_params(storage_constructor_type sc = default_storage_constructor)
|
||||||
: tracker_url(0)
|
: version(LIBTORRENT_VERSION_NUM)
|
||||||
|
, tracker_url(0)
|
||||||
, name(0)
|
, name(0)
|
||||||
, resume_data(0)
|
, resume_data(0)
|
||||||
, storage_mode(storage_mode_sparse)
|
, storage_mode(storage_mode_sparse)
|
||||||
|
@ -59,8 +61,11 @@ namespace libtorrent
|
||||||
, seed_mode(false)
|
, seed_mode(false)
|
||||||
, override_resume_data(false)
|
, override_resume_data(false)
|
||||||
, upload_mode(false)
|
, upload_mode(false)
|
||||||
|
, file_priorities(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
// libtorrent version. Used for forward binary compatibility
|
||||||
|
int version;
|
||||||
boost::intrusive_ptr<torrent_info> ti;
|
boost::intrusive_ptr<torrent_info> ti;
|
||||||
char const* tracker_url;
|
char const* tracker_url;
|
||||||
sha1_hash info_hash;
|
sha1_hash info_hash;
|
||||||
|
@ -76,6 +81,7 @@ namespace libtorrent
|
||||||
bool seed_mode;
|
bool seed_mode;
|
||||||
bool override_resume_data;
|
bool override_resume_data;
|
||||||
bool upload_mode;
|
bool upload_mode;
|
||||||
|
std::vector<boost::uint8_t> const* file_priorities;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,7 +255,8 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
file_pool fp;
|
file_pool fp;
|
||||||
boost::scoped_ptr<storage_interface> st(
|
boost::scoped_ptr<storage_interface> st(
|
||||||
default_storage_constructor(const_cast<file_storage&>(t.files()), 0, p, fp));
|
default_storage_constructor(const_cast<file_storage&>(t.files()), 0, p, fp
|
||||||
|
, std::vector<boost::uint8_t>()));
|
||||||
|
|
||||||
// if we're calculating file hashes as well, use this hasher
|
// if we're calculating file hashes as well, use this hasher
|
||||||
hasher filehash;
|
hasher filehash;
|
||||||
|
@ -354,7 +355,8 @@ namespace libtorrent
|
||||||
std::string utf8;
|
std::string utf8;
|
||||||
wchar_utf8(p, utf8);
|
wchar_utf8(p, utf8);
|
||||||
boost::scoped_ptr<storage_interface> st(
|
boost::scoped_ptr<storage_interface> st(
|
||||||
default_storage_constructor(const_cast<file_storage&>(t.files()), 0, utf8, fp));
|
default_storage_constructor(const_cast<file_storage&>(t.files()), 0, utf8, fp
|
||||||
|
, std::vector<boost::uint8_t>()));
|
||||||
|
|
||||||
// calculate the hash for all pieces
|
// calculate the hash for all pieces
|
||||||
int num = t.num_pieces();
|
int num = t.num_pieces();
|
||||||
|
|
|
@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "libtorrent/version.hpp"
|
#include "libtorrent/version.hpp"
|
||||||
#include "libtorrent/config.hpp"
|
#include "libtorrent/config.hpp"
|
||||||
|
#include "libtorrent/version.hpp"
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
@ -84,7 +85,8 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
session_settings(std::string const& user_agent_ = "libtorrent/"
|
session_settings(std::string const& user_agent_ = "libtorrent/"
|
||||||
LIBTORRENT_VERSION)
|
LIBTORRENT_VERSION)
|
||||||
: user_agent(user_agent_)
|
: version(LIBTORRENT_VERSION_NUM)
|
||||||
|
, user_agent(user_agent_)
|
||||||
, tracker_completion_timeout(60)
|
, tracker_completion_timeout(60)
|
||||||
, tracker_receive_timeout(40)
|
, tracker_receive_timeout(40)
|
||||||
, stop_tracker_timeout(5)
|
, stop_tracker_timeout(5)
|
||||||
|
@ -216,6 +218,9 @@ namespace libtorrent
|
||||||
, tick_interval(100)
|
, tick_interval(100)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
// libtorrent version. Used for forward binary compatibility
|
||||||
|
int version;
|
||||||
|
|
||||||
// this is the user agent that will be sent to the tracker
|
// this is the user agent that will be sent to the tracker
|
||||||
// when doing requests. It is used to identify the client.
|
// when doing requests. It is used to identify the client.
|
||||||
// It cannot contain \r or \n
|
// It cannot contain \r or \n
|
||||||
|
|
|
@ -199,7 +199,8 @@ namespace libtorrent
|
||||||
, file_pool& fp
|
, file_pool& fp
|
||||||
, disk_io_thread& io
|
, disk_io_thread& io
|
||||||
, storage_constructor_type sc
|
, storage_constructor_type sc
|
||||||
, storage_mode_t sm);
|
, storage_mode_t sm
|
||||||
|
, std::vector<boost::uint8_t> const& file_prio);
|
||||||
|
|
||||||
~piece_manager();
|
~piece_manager();
|
||||||
|
|
||||||
|
|
|
@ -50,13 +50,13 @@ namespace libtorrent
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef storage_interface* (*storage_constructor_type)(
|
typedef storage_interface* (*storage_constructor_type)(
|
||||||
file_storage const&, file_storage const*, std::string const&, file_pool&);
|
file_storage const&, file_storage const*, std::string const&, file_pool&, std::vector<boost::uint8_t> const&);
|
||||||
|
|
||||||
TORRENT_EXPORT storage_interface* default_storage_constructor(
|
TORRENT_EXPORT storage_interface* default_storage_constructor(
|
||||||
file_storage const&, file_storage const* mapped, std::string const&, file_pool&);
|
file_storage const&, file_storage const* mapped, std::string const&, file_pool&, std::vector<boost::uint8_t> const&);
|
||||||
|
|
||||||
TORRENT_EXPORT storage_interface* disabled_storage_constructor(
|
TORRENT_EXPORT storage_interface* disabled_storage_constructor(
|
||||||
file_storage const&, file_storage const* mapped, std::string const&, file_pool&);
|
file_storage const&, file_storage const* mapped, std::string const&, file_pool&, std::vector<boost::uint8_t> const&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define LIBTORRENT_VERSION_MINOR 16
|
#define LIBTORRENT_VERSION_MINOR 16
|
||||||
#define LIBTORRENT_VERSION_TINY 0
|
#define LIBTORRENT_VERSION_TINY 0
|
||||||
|
|
||||||
|
// the format of this version is: MMmmtt
|
||||||
|
// M = Major version, m = minor version, t = tiny version
|
||||||
|
#define LIBTORRENT_VERSION_NUM ((LIBTORRENT_VERSION_MAJOR * 10000) + (LIBTORRENT_VERSION_MINOR * 100) + LIBTORRENT_VERSION_TINY)
|
||||||
|
|
||||||
#define LIBTORRENT_VERSION "0.16.0.0"
|
#define LIBTORRENT_VERSION "0.16.0.0"
|
||||||
#define LIBTORRENT_REVISION "$Rev$"
|
#define LIBTORRENT_REVISION "$Rev$"
|
||||||
|
|
||||||
|
|
|
@ -344,11 +344,13 @@ namespace libtorrent
|
||||||
class storage : public storage_interface, boost::noncopyable
|
class storage : public storage_interface, boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
storage(file_storage const& fs, file_storage const* mapped, std::string const& path, file_pool& fp)
|
storage(file_storage const& fs, file_storage const* mapped, std::string const& path
|
||||||
|
, file_pool& fp, std::vector<boost::uint8_t> const& file_prio)
|
||||||
: m_files(fs)
|
: m_files(fs)
|
||||||
, m_pool(fp)
|
, m_pool(fp)
|
||||||
, m_page_size(page_size())
|
, m_page_size(page_size())
|
||||||
, m_allocate_files(false)
|
, m_allocate_files(false)
|
||||||
|
, m_file_priority(file_prio)
|
||||||
{
|
{
|
||||||
if (mapped) m_mapped_files.reset(new file_storage(*mapped));
|
if (mapped) m_mapped_files.reset(new file_storage(*mapped));
|
||||||
|
|
||||||
|
@ -1318,9 +1320,10 @@ ret:
|
||||||
}
|
}
|
||||||
|
|
||||||
storage_interface* default_storage_constructor(file_storage const& fs
|
storage_interface* default_storage_constructor(file_storage const& fs
|
||||||
, file_storage const* mapped, std::string const& path, file_pool& fp)
|
, file_storage const* mapped, std::string const& path, file_pool& fp
|
||||||
|
, std::vector<boost::uint8_t> const& file_prio)
|
||||||
{
|
{
|
||||||
return new storage(fs, mapped, path, fp);
|
return new storage(fs, mapped, path, fp, file_prio);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this storage implementation does not write anything to disk
|
// this storage implementation does not write anything to disk
|
||||||
|
@ -1398,7 +1401,8 @@ ret:
|
||||||
};
|
};
|
||||||
|
|
||||||
storage_interface* disabled_storage_constructor(file_storage const& fs
|
storage_interface* disabled_storage_constructor(file_storage const& fs
|
||||||
, file_storage const* mapped, std::string const& path, file_pool& fp)
|
, file_storage const* mapped, std::string const& path, file_pool& fp
|
||||||
|
, std::vector<boost::uint8_t> const&)
|
||||||
{
|
{
|
||||||
return new disabled_storage(fs.piece_length());
|
return new disabled_storage(fs.piece_length());
|
||||||
}
|
}
|
||||||
|
@ -1412,11 +1416,12 @@ ret:
|
||||||
, file_pool& fp
|
, file_pool& fp
|
||||||
, disk_io_thread& io
|
, disk_io_thread& io
|
||||||
, storage_constructor_type sc
|
, storage_constructor_type sc
|
||||||
, storage_mode_t sm)
|
, storage_mode_t sm
|
||||||
|
, std::vector<boost::uint8_t> const& file_prio)
|
||||||
: m_info(info)
|
: m_info(info)
|
||||||
, m_files(m_info->files())
|
, m_files(m_info->files())
|
||||||
, m_storage(sc(m_info->orig_files(), &m_info->files() != &m_info->orig_files()
|
, m_storage(sc(m_info->orig_files(), &m_info->files() != &m_info->orig_files()
|
||||||
? &m_info->files() : 0, save_path, fp))
|
? &m_info->files() : 0, save_path, fp, file_prio))
|
||||||
, m_storage_mode(sm)
|
, m_storage_mode(sm)
|
||||||
, m_save_path(complete(save_path))
|
, m_save_path(complete(save_path))
|
||||||
, m_state(state_none)
|
, m_state(state_none)
|
||||||
|
|
|
@ -382,6 +382,9 @@ namespace libtorrent
|
||||||
, m_last_download(0)
|
, m_last_download(0)
|
||||||
, m_last_upload(0)
|
, m_last_upload(0)
|
||||||
{
|
{
|
||||||
|
if (p.file_priorities)
|
||||||
|
m_file_priority = *p.file_priorities;
|
||||||
|
|
||||||
if (m_seed_mode)
|
if (m_seed_mode)
|
||||||
m_verified.resize(m_torrent_file->num_pieces(), false);
|
m_verified.resize(m_torrent_file->num_pieces(), false);
|
||||||
|
|
||||||
|
@ -841,7 +844,7 @@ namespace libtorrent
|
||||||
// cycle of ownership, se the hpp file for description.
|
// cycle of ownership, se the hpp file for description.
|
||||||
m_owning_storage = new piece_manager(shared_from_this(), m_torrent_file
|
m_owning_storage = new piece_manager(shared_from_this(), m_torrent_file
|
||||||
, m_save_path, m_ses.m_files, m_ses.m_disk_thread, m_storage_constructor
|
, m_save_path, m_ses.m_files, m_ses.m_disk_thread, m_storage_constructor
|
||||||
, (storage_mode_t)m_storage_mode);
|
, (storage_mode_t)m_storage_mode, m_file_priority);
|
||||||
m_storage = m_owning_storage.get();
|
m_storage = m_owning_storage.get();
|
||||||
|
|
||||||
if (has_picker())
|
if (has_picker())
|
||||||
|
|
|
@ -222,7 +222,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
storage_interface* create_test_storage(file_storage const& fs
|
storage_interface* create_test_storage(file_storage const& fs
|
||||||
, file_storage const* mapped, std::string const& path, file_pool& fp)
|
, file_storage const* mapped, std::string const& path, file_pool& fp
|
||||||
|
, std::vector<boost::uint8_t> const&)
|
||||||
{
|
{
|
||||||
return new test_storage;
|
return new test_storage;
|
||||||
}
|
}
|
||||||
|
@ -280,7 +281,7 @@ void run_elevator_test()
|
||||||
error_code ec;
|
error_code ec;
|
||||||
disk_io_thread dio(ios, &nop, fp);
|
disk_io_thread dio(ios, &nop, fp);
|
||||||
boost::intrusive_ptr<piece_manager> pm(new piece_manager(boost::shared_ptr<void>(), ti, ""
|
boost::intrusive_ptr<piece_manager> pm(new piece_manager(boost::shared_ptr<void>(), ti, ""
|
||||||
, fp, dio, &create_test_storage, storage_mode_sparse));
|
, fp, dio, &create_test_storage, storage_mode_sparse, std::vector<boost::uint8_t>()));
|
||||||
|
|
||||||
// we must disable the read cache in order to
|
// we must disable the read cache in order to
|
||||||
// verify that the elevator algorithm works.
|
// verify that the elevator algorithm works.
|
||||||
|
@ -418,7 +419,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||||
file_pool fp;
|
file_pool fp;
|
||||||
disk_buffer_pool dp(16 * 1024);
|
disk_buffer_pool dp(16 * 1024);
|
||||||
boost::scoped_ptr<storage_interface> s(
|
boost::scoped_ptr<storage_interface> s(
|
||||||
default_storage_constructor(fs, 0, test_path, fp));
|
default_storage_constructor(fs, 0, test_path, fp, std::vector<boost::uint8_t>()));
|
||||||
s->m_settings = &set;
|
s->m_settings = &set;
|
||||||
s->m_disk_pool = &dp;
|
s->m_disk_pool = &dp;
|
||||||
|
|
||||||
|
@ -470,7 +471,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||||
disk_io_thread io(ios, boost::function<void()>(), fp);
|
disk_io_thread io(ios, boost::function<void()>(), fp);
|
||||||
boost::shared_ptr<int> dummy(new int);
|
boost::shared_ptr<int> dummy(new int);
|
||||||
boost::intrusive_ptr<piece_manager> pm = new piece_manager(dummy, info
|
boost::intrusive_ptr<piece_manager> pm = new piece_manager(dummy, info
|
||||||
, test_path, fp, io, default_storage_constructor, storage_mode);
|
, test_path, fp, io, default_storage_constructor, storage_mode, std::vector<boost::uint8_t>());
|
||||||
libtorrent::mutex lock;
|
libtorrent::mutex lock;
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
@ -615,7 +616,7 @@ void test_remove(std::string const& test_path, bool unbuffered)
|
||||||
file_pool fp;
|
file_pool fp;
|
||||||
disk_buffer_pool dp(16 * 1024);
|
disk_buffer_pool dp(16 * 1024);
|
||||||
boost::scoped_ptr<storage_interface> s(
|
boost::scoped_ptr<storage_interface> s(
|
||||||
default_storage_constructor(fs, 0, test_path, fp));
|
default_storage_constructor(fs, 0, test_path, fp, std::vector<boost::uint8_t>()));
|
||||||
s->m_settings = &set;
|
s->m_settings = &set;
|
||||||
s->m_disk_pool = &dp;
|
s->m_disk_pool = &dp;
|
||||||
|
|
||||||
|
@ -697,7 +698,7 @@ void test_check_files(std::string const& test_path
|
||||||
disk_io_thread io(ios, boost::function<void()>(), fp);
|
disk_io_thread io(ios, boost::function<void()>(), fp);
|
||||||
boost::shared_ptr<int> dummy(new int);
|
boost::shared_ptr<int> dummy(new int);
|
||||||
boost::intrusive_ptr<piece_manager> pm = new piece_manager(dummy, info
|
boost::intrusive_ptr<piece_manager> pm = new piece_manager(dummy, info
|
||||||
, test_path, fp, io, default_storage_constructor, storage_mode);
|
, test_path, fp, io, default_storage_constructor, storage_mode, std::vector<boost::uint8_t>());
|
||||||
libtorrent::mutex lock;
|
libtorrent::mutex lock;
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
|
@ -121,7 +121,7 @@ void print_alert(std::auto_ptr<alert>)
|
||||||
struct test_storage : storage_interface
|
struct test_storage : storage_interface
|
||||||
{
|
{
|
||||||
test_storage(file_storage const& fs, std::string const& p, file_pool& fp)
|
test_storage(file_storage const& fs, std::string const& p, file_pool& fp)
|
||||||
: m_lower_layer(default_storage_constructor(fs, 0, p, fp))
|
: m_lower_layer(default_storage_constructor(fs, 0, p, fp, std::vector<boost::uint8_t>()))
|
||||||
, m_written(0)
|
, m_written(0)
|
||||||
, m_limit(16 * 1024 * 2)
|
, m_limit(16 * 1024 * 2)
|
||||||
{}
|
{}
|
||||||
|
@ -213,7 +213,7 @@ struct test_storage : storage_interface
|
||||||
};
|
};
|
||||||
|
|
||||||
storage_interface* test_storage_constructor(file_storage const& fs
|
storage_interface* test_storage_constructor(file_storage const& fs
|
||||||
, file_storage const*, std::string const& path, file_pool& fp)
|
, file_storage const*, std::string const& path, file_pool& fp, std::vector<boost::uint8_t> const&)
|
||||||
{
|
{
|
||||||
return new test_storage(fs, path, fp);
|
return new test_storage(fs, path, fp);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue