deprecated a bunch of query functions on torrent_handle in favor of using status() to get as much information as possible in fewer calls, and saving time on synchronizing with the main thread
This commit is contained in:
@@ -139,7 +139,6 @@ The ``session`` class has the following synopsis::
|
|||||||
|
|
||||||
void pause();
|
void pause();
|
||||||
void resume();
|
void resume();
|
||||||
bool is_paused() const;
|
|
||||||
|
|
||||||
session_proxy abort();
|
session_proxy abort();
|
||||||
|
|
||||||
@@ -1883,6 +1882,16 @@ torrent_handle
|
|||||||
|
|
||||||
You will usually have to store your torrent handles somewhere, since it's the
|
You will usually have to store your torrent handles somewhere, since it's the
|
||||||
object through which you retrieve information about the torrent and aborts the torrent.
|
object through which you retrieve information about the torrent and aborts the torrent.
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
Any member function that returns a value or fills in a value has to
|
||||||
|
be made synchronously. This means it has to wait for the main thread
|
||||||
|
to complete the query before it can return. This might potentially be
|
||||||
|
expensive if done from within a GUI thread that needs to stay responsive.
|
||||||
|
Try to avoid quering for information you don't need, and try to do it
|
||||||
|
in as few calls as possible. You can get most of the interesting information
|
||||||
|
about a torrent from the ``torrent_handle::status()`` call.
|
||||||
|
|
||||||
Its declaration looks like this::
|
Its declaration looks like this::
|
||||||
|
|
||||||
struct torrent_handle
|
struct torrent_handle
|
||||||
@@ -1958,7 +1967,6 @@ Its declaration looks like this::
|
|||||||
enum pause_flags_t { graceful_pause = 1 };
|
enum pause_flags_t { graceful_pause = 1 };
|
||||||
void pause(int flags = 0) const;
|
void pause(int flags = 0) const;
|
||||||
void resume() const;
|
void resume() const;
|
||||||
bool is_paused() const;
|
|
||||||
bool is_seed() const;
|
bool is_seed() const;
|
||||||
void force_recheck() const;
|
void force_recheck() const;
|
||||||
void clear_error() const;
|
void clear_error() const;
|
||||||
@@ -1984,10 +1992,8 @@ Its declaration looks like this::
|
|||||||
void prioritize_files(std::vector<int> const& files) const;
|
void prioritize_files(std::vector<int> const& files) const;
|
||||||
std::vector<int> file_priorities() const;
|
std::vector<int> file_priorities() const;
|
||||||
|
|
||||||
bool is_auto_managed() const;
|
|
||||||
void auto_managed(bool m) const;
|
void auto_managed(bool m) const;
|
||||||
|
|
||||||
bool has_metadata() const;
|
|
||||||
bool set_metadata(char const* buf, int size) const;
|
bool set_metadata(char const* buf, int size) const;
|
||||||
|
|
||||||
boost::filesystem::path save_path() const;
|
boost::filesystem::path save_path() const;
|
||||||
@@ -2357,13 +2363,12 @@ limit.
|
|||||||
download, respectively.
|
download, respectively.
|
||||||
|
|
||||||
|
|
||||||
set_sequential_download() is_sequential_download()
|
set_sequential_download()
|
||||||
--------------------------------------------------
|
-------------------------
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
void set_sequential_download(bool sd);
|
void set_sequential_download(bool sd);
|
||||||
bool is_sequential_download() const;
|
|
||||||
|
|
||||||
``set_sequential_download()`` enables or disables *sequential download*. When enabled, the piece
|
``set_sequential_download()`` enables or disables *sequential download*. When enabled, the piece
|
||||||
picker will pick pieces in sequence instead of rarest first.
|
picker will pick pieces in sequence instead of rarest first.
|
||||||
@@ -2371,10 +2376,6 @@ picker will pick pieces in sequence instead of rarest first.
|
|||||||
Enabling sequential download will affect the piece distribution negatively in the swarm. It should be
|
Enabling sequential download will affect the piece distribution negatively in the swarm. It should be
|
||||||
used sparingly.
|
used sparingly.
|
||||||
|
|
||||||
``is_sequential_download()`` returns true if this torrent is downloading in sequence, and false
|
|
||||||
otherwise.
|
|
||||||
|
|
||||||
|
|
||||||
get_peer_download_limit() get_peer_upload_limit() set_peer_upload_limit() set_peer_download_limit()
|
get_peer_download_limit() get_peer_upload_limit() set_peer_upload_limit() set_peer_download_limit()
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -2389,21 +2390,22 @@ Works like ``get_upload_limit``, ``get_download_limit``, ``set_upload_limit`` an
|
|||||||
``set_download_limit`` respectively, but controls individual peer instead of the
|
``set_download_limit`` respectively, but controls individual peer instead of the
|
||||||
whole torrent.
|
whole torrent.
|
||||||
|
|
||||||
pause() resume() is_paused()
|
pause() resume()
|
||||||
----------------------------
|
----------------
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
enum pause_flags_t { graceful_pause = 1 };
|
enum pause_flags_t { graceful_pause = 1 };
|
||||||
void pause(int flags) const;
|
void pause(int flags) const;
|
||||||
void resume() const;
|
void resume() const;
|
||||||
bool is_paused() const;
|
|
||||||
|
|
||||||
``pause()``, and ``resume()`` will disconnect all peers and reconnect all peers respectively.
|
``pause()``, and ``resume()`` will disconnect all peers and reconnect all peers respectively.
|
||||||
When a torrent is paused, it will however remember all share ratios to all peers and remember
|
When a torrent is paused, it will however remember all share ratios to all peers and remember
|
||||||
all potential (not connected) peers. You can use ``is_paused()`` to determine if a torrent
|
all potential (not connected) peers. Torrents may be paused automatically if there is a file
|
||||||
is currently paused. Torrents may be paused automatically if there is a file error (e.g. disk full)
|
error (e.g. disk full) or something similar. See file_error_alert_.
|
||||||
or something similar. See file_error_alert_.
|
|
||||||
|
To know if a torrent is paused or not, call ``torrent_handle::status()`` and inspect
|
||||||
|
``torrent_status::paused``.
|
||||||
|
|
||||||
The ``flags`` argument to pause can be set to ``torrent_handle::graceful_pause`` which will
|
The ``flags`` argument to pause can be set to ``torrent_handle::graceful_pause`` which will
|
||||||
delay the disconnect of peers that we're still downloading outstanding requests from. The torrent
|
delay the disconnect of peers that we're still downloading outstanding requests from. The torrent
|
||||||
@@ -2415,11 +2417,6 @@ torrents that are auto-managed may be automatically resumed again. It does not m
|
|||||||
pause an auto-managed torrent without making it not automanaged first. Torrents are auto-managed
|
pause an auto-managed torrent without making it not automanaged first. Torrents are auto-managed
|
||||||
by default when added to the session. For more information, see queuing_.
|
by default when added to the session. For more information, see queuing_.
|
||||||
|
|
||||||
``is_paused()`` only returns true if the torrent itself is paused. If the torrent
|
|
||||||
is not running because the session is paused, this still returns false. To know if a
|
|
||||||
torrent is active or not, you need to inspect both ``torrent_handle::is_paused()``
|
|
||||||
and ``session::is_paused()``.
|
|
||||||
|
|
||||||
flush_cache()
|
flush_cache()
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
@@ -2509,32 +2506,23 @@ is_seed()
|
|||||||
|
|
||||||
Returns true if the torrent is in seed mode (i.e. if it has finished downloading).
|
Returns true if the torrent is in seed mode (i.e. if it has finished downloading).
|
||||||
|
|
||||||
is_auto_managed() auto_managed()
|
auto_managed()
|
||||||
--------------------------------
|
--------------
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
bool is_auto_managed() const;
|
|
||||||
void auto_managed(bool m) const;
|
void auto_managed(bool m) const;
|
||||||
|
|
||||||
``is_auto_managed()`` returns true if this torrent is currently *auto managed*.
|
|
||||||
``auto_managed()`` changes whether the torrent is auto managed or not. For more info,
|
``auto_managed()`` changes whether the torrent is auto managed or not. For more info,
|
||||||
see queuing_.
|
see queuing_.
|
||||||
|
|
||||||
has_metadata() set_metadata()
|
set_metadata()
|
||||||
-----------------------------
|
--------------
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
bool has_metadata() const;
|
|
||||||
bool set_metadata(char const* buf, int size) const;
|
bool set_metadata(char const* buf, int size) const;
|
||||||
|
|
||||||
``has_metadata`` returns true if this torrent has metadata (either it was started from a
|
|
||||||
.torrent file or the metadata has been downloaded). The only scenario where this can return
|
|
||||||
false is when the torrent was started torrent-less (i.e. with just an info-hash and tracker
|
|
||||||
ip). Note that if the torrent doesn't have metadata, the member `get_torrent_info()`_ will
|
|
||||||
throw.
|
|
||||||
|
|
||||||
``set_metadata`` expects the *info* section of metadata. i.e. The buffer passed in will be
|
``set_metadata`` expects the *info* section of metadata. i.e. The buffer passed in will be
|
||||||
hashed and verified against the info-hash. If it fails, a ``metadata_failed_alert`` will be
|
hashed and verified against the info-hash. If it fails, a ``metadata_failed_alert`` will be
|
||||||
generated. If it passes, a ``metadata_received_alert`` is generated. The function returns
|
generated. If it passes, a ``metadata_received_alert`` is generated. The function returns
|
||||||
@@ -2784,8 +2772,9 @@ Example code to pause and save resume data for all torrents and wait for the ale
|
|||||||
i != handles.end(); ++i)
|
i != handles.end(); ++i)
|
||||||
{
|
{
|
||||||
torrent_handle& h = *i;
|
torrent_handle& h = *i;
|
||||||
if (!h.has_metadata()) continue;
|
|
||||||
if (!h.is_valid()) continue;
|
if (!h.is_valid()) continue;
|
||||||
|
torrent_status s = h.status();
|
||||||
|
if (!s.has_metadata) continue;
|
||||||
|
|
||||||
h.save_resume_data();
|
h.save_resume_data();
|
||||||
++num_resume_data;
|
++num_resume_data;
|
||||||
@@ -2991,6 +2980,10 @@ It contains the following fields::
|
|||||||
|
|
||||||
state_t state;
|
state_t state;
|
||||||
bool paused;
|
bool paused;
|
||||||
|
bool auto_managed;
|
||||||
|
bool sequential_download;
|
||||||
|
bool seeding;
|
||||||
|
bool finished;
|
||||||
float progress;
|
float progress;
|
||||||
int progress_ppm;
|
int progress_ppm;
|
||||||
std::string error;
|
std::string error;
|
||||||
@@ -3126,7 +3119,29 @@ The torrent's current task is in the ``state`` member, it will be one of the fol
|
|||||||
When downloading, the progress is ``total_wanted_done`` / ``total_wanted``. This takes
|
When downloading, the progress is ``total_wanted_done`` / ``total_wanted``. This takes
|
||||||
into account files whose priority have been set to 0. They are not considered.
|
into account files whose priority have been set to 0. They are not considered.
|
||||||
|
|
||||||
``paused`` is set to true if the torrent is paused and false otherwise.
|
``paused`` is set to true if the torrent is paused and false otherwise. It's only true
|
||||||
|
if the torrent itself is paused. If the torrent is not running because the session is
|
||||||
|
paused, this is still false. To know if a torrent is active or not, you need to inspect
|
||||||
|
both ``torrent_status::paused`` and ``session::is_paused()``.
|
||||||
|
|
||||||
|
``auto_managed`` is set to true if the torrent is auto managed, i.e. libtorrent is
|
||||||
|
responsible for determining whether it should be started or queued. For more info
|
||||||
|
see queuing_
|
||||||
|
|
||||||
|
``sequential_download`` is true when the torrent is in sequential download mode. In
|
||||||
|
this mode pieces are downloaded in order rather than rarest first.
|
||||||
|
|
||||||
|
``is_seeding`` is true if all pieces have been downloaded.
|
||||||
|
|
||||||
|
``is_finished`` is true if all pieces that have a priority > 0 are downloaded. There is
|
||||||
|
only a distinction between finished and seeding if some pieces or files have been
|
||||||
|
set to priority 0, i.e. are not downloaded.
|
||||||
|
|
||||||
|
``has_metadata`` is true if this torrent has metadata (either it was started from a
|
||||||
|
.torrent file or the metadata has been downloaded). The only scenario where this can be
|
||||||
|
false is when the torrent was started torrent-less (i.e. with just an info-hash and tracker
|
||||||
|
ip, a magnet link for instance). Note that if the torrent doesn't have metadata, the member
|
||||||
|
`get_torrent_info()`_ will throw.
|
||||||
|
|
||||||
``error`` may be set to an error message describing why the torrent was paused, in
|
``error`` may be set to an error message describing why the torrent was paused, in
|
||||||
case it was paused by an error. If the torrent is not paused or if it's paused but
|
case it was paused by an error. If the torrent is not paused or if it's paused but
|
||||||
@@ -4546,7 +4561,7 @@ the default upload and download rate limits for peers, respectively. These
|
|||||||
default to 0, which means unlimited. These settings affect the rate limits
|
default to 0, which means unlimited. These settings affect the rate limits
|
||||||
set on new peer connections (not existing ones). The peer rate limits can
|
set on new peer connections (not existing ones). The peer rate limits can
|
||||||
be changed individually later using
|
be changed individually later using
|
||||||
`set_peer_upload_limit() set_peer_download_limit()`_.
|
`get_peer_download_limit() get_peer_upload_limit() set_peer_upload_limit() set_peer_download_limit()`_.
|
||||||
|
|
||||||
if ``broadcast_lsd`` is set to true, the local peer discovery
|
if ``broadcast_lsd`` is set to true, the local peer discovery
|
||||||
(or Local Service Discovery) will not only use IP multicast, but also
|
(or Local Service Discovery) will not only use IP multicast, but also
|
||||||
|
@@ -1176,7 +1176,7 @@ int main(int argc, char* argv[])
|
|||||||
if (c == 's')
|
if (c == 's')
|
||||||
{
|
{
|
||||||
torrent_handle h = get_active_torrent(handles);
|
torrent_handle h = get_active_torrent(handles);
|
||||||
if (h.is_valid()) h.set_sequential_download(!h.is_sequential_download());
|
if (h.is_valid()) h.set_sequential_download(!h.status().sequential_download);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == 'R')
|
if (c == 'R')
|
||||||
@@ -1215,7 +1215,8 @@ int main(int argc, char* argv[])
|
|||||||
torrent_handle h = get_active_torrent(handles);
|
torrent_handle h = get_active_torrent(handles);
|
||||||
if (h.is_valid())
|
if (h.is_valid())
|
||||||
{
|
{
|
||||||
if (!h.is_auto_managed() && h.is_paused())
|
torrent_status s = h.status();
|
||||||
|
if (!s.auto_managed && s.paused)
|
||||||
{
|
{
|
||||||
h.auto_managed(true);
|
h.auto_managed(true);
|
||||||
}
|
}
|
||||||
@@ -1346,9 +1347,6 @@ int main(int argc, char* argv[])
|
|||||||
snprintf(str, sizeof(str), "%-40s %s ", name.c_str(), term);
|
snprintf(str, sizeof(str), "%-40s %s ", name.c_str(), term);
|
||||||
out += str;
|
out += str;
|
||||||
|
|
||||||
bool auto_managed = h.is_auto_managed();
|
|
||||||
bool sequential_download = h.is_sequential_download();
|
|
||||||
|
|
||||||
if (!s.error.empty())
|
if (!s.error.empty())
|
||||||
{
|
{
|
||||||
out += esc("31");
|
out += esc("31");
|
||||||
@@ -1372,7 +1370,7 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
snprintf(str, sizeof(str), "%-13s down: (%s%s%s) up: %s%s%s (%s%s%s) swarm: %4d:%4d"
|
snprintf(str, sizeof(str), "%-13s down: (%s%s%s) up: %s%s%s (%s%s%s) swarm: %4d:%4d"
|
||||||
" bw queue: (%d|%d) all-time (Rx: %s%s%s Tx: %s%s%s) seed rank: %x %c%s\n"
|
" bw queue: (%d|%d) all-time (Rx: %s%s%s Tx: %s%s%s) seed rank: %x %c%s\n"
|
||||||
, (s.paused && !auto_managed)?"paused":(s.paused && auto_managed)?"queued":state_str[s.state]
|
, (s.paused && !s.auto_managed)?"paused":(s.paused && s.auto_managed)?"queued":state_str[s.state]
|
||||||
, esc("32"), add_suffix(s.total_download).c_str(), term
|
, esc("32"), add_suffix(s.total_download).c_str(), term
|
||||||
, esc("31"), add_suffix(s.upload_rate, "/s").c_str(), term
|
, esc("31"), add_suffix(s.upload_rate, "/s").c_str(), term
|
||||||
, esc("31"), add_suffix(s.total_upload).c_str(), term
|
, esc("31"), add_suffix(s.total_upload).c_str(), term
|
||||||
@@ -1399,7 +1397,7 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
snprintf(str, sizeof(str), " %-10s: %s%-11"PRId64"%s Bytes %6.2f%% %s\n"
|
snprintf(str, sizeof(str), " %-10s: %s%-11"PRId64"%s Bytes %6.2f%% %s\n"
|
||||||
, sequential_download?"sequential":"progress"
|
, s.sequential_download?"sequential":"progress"
|
||||||
, esc("32"), s.total_done, esc("0")
|
, esc("32"), s.total_done, esc("0")
|
||||||
, s.progress_ppm / 10000.f
|
, s.progress_ppm / 10000.f
|
||||||
, progress_bar(s.progress_ppm / 1000, terminal_width - 43, progress_bar_color).c_str());
|
, progress_bar(s.progress_ppm / 1000, terminal_width - 43, progress_bar_color).c_str());
|
||||||
@@ -1635,7 +1633,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
if (print_file_progress
|
if (print_file_progress
|
||||||
&& s.state != torrent_status::seeding
|
&& s.state != torrent_status::seeding
|
||||||
&& h.has_metadata())
|
&& s.has_metadata)
|
||||||
{
|
{
|
||||||
std::vector<size_type> file_progress;
|
std::vector<size_type> file_progress;
|
||||||
h.file_progress(file_progress);
|
h.file_progress(file_progress);
|
||||||
@@ -1697,8 +1695,9 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
torrent_handle& h = i->second;
|
torrent_handle& h = i->second;
|
||||||
if (!h.is_valid()) continue;
|
if (!h.is_valid()) continue;
|
||||||
if (h.is_paused()) continue;
|
torrent_status s = h.status();
|
||||||
if (!h.has_metadata()) continue;
|
if (s.paused) continue;
|
||||||
|
if (!s.has_metadata) continue;
|
||||||
|
|
||||||
printf("saving resume data for %s\n", h.name().c_str());
|
printf("saving resume data for %s\n", h.name().c_str());
|
||||||
// save_resume_data will generate an alert when it's done
|
// save_resume_data will generate an alert when it's done
|
||||||
|
@@ -81,6 +81,11 @@ namespace libtorrent
|
|||||||
torrent_status()
|
torrent_status()
|
||||||
: state(checking_resume_data)
|
: state(checking_resume_data)
|
||||||
, paused(false)
|
, paused(false)
|
||||||
|
, auto_managed(false)
|
||||||
|
, sequential_download(false)
|
||||||
|
, is_seeding(false)
|
||||||
|
, is_finished(false)
|
||||||
|
, has_metadata(false)
|
||||||
, progress(0.f)
|
, progress(0.f)
|
||||||
, progress_ppm(0)
|
, progress_ppm(0)
|
||||||
, total_download(0)
|
, total_download(0)
|
||||||
@@ -146,6 +151,12 @@ namespace libtorrent
|
|||||||
|
|
||||||
state_t state;
|
state_t state;
|
||||||
bool paused;
|
bool paused;
|
||||||
|
bool auto_managed;
|
||||||
|
bool sequential_download;
|
||||||
|
bool is_seeding;
|
||||||
|
bool is_finished;
|
||||||
|
bool has_metadata;
|
||||||
|
|
||||||
float progress;
|
float progress;
|
||||||
// progress parts per million (progress * 1000000)
|
// progress parts per million (progress * 1000000)
|
||||||
// when disabling floating point operations, this is
|
// when disabling floating point operations, this is
|
||||||
@@ -461,14 +472,10 @@ namespace libtorrent
|
|||||||
, void* userdata = 0);
|
, void* userdata = 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool has_metadata() const;
|
|
||||||
bool set_metadata(char const* metadata, int size) const;
|
bool set_metadata(char const* metadata, int size) const;
|
||||||
const torrent_info& get_torrent_info() const;
|
const torrent_info& get_torrent_info() const;
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
|
|
||||||
bool is_seed() const;
|
|
||||||
bool is_finished() const;
|
|
||||||
bool is_paused() const;
|
|
||||||
enum pause_flags_t { graceful_pause = 1 };
|
enum pause_flags_t { graceful_pause = 1 };
|
||||||
void pause(int flags = 0) const;
|
void pause(int flags = 0) const;
|
||||||
void resume() const;
|
void resume() const;
|
||||||
@@ -482,7 +489,6 @@ namespace libtorrent
|
|||||||
void save_resume_data(int flags = 0) const;
|
void save_resume_data(int flags = 0) const;
|
||||||
bool need_save_resume_data() const;
|
bool need_save_resume_data() const;
|
||||||
|
|
||||||
bool is_auto_managed() const;
|
|
||||||
void auto_managed(bool m) const;
|
void auto_managed(bool m) const;
|
||||||
|
|
||||||
int queue_position() const;
|
int queue_position() const;
|
||||||
@@ -504,6 +510,20 @@ namespace libtorrent
|
|||||||
// ================ start deprecation ============
|
// ================ start deprecation ============
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
// deprecated in 0.16. use status() instead
|
||||||
|
TORRENT_DEPRECATED_PREFIX
|
||||||
|
bool is_seed() const TORRENT_DEPRECATED;
|
||||||
|
TORRENT_DEPRECATED_PREFIX
|
||||||
|
bool is_finished() const TORRENT_DEPRECATED;
|
||||||
|
TORRENT_DEPRECATED_PREFIX
|
||||||
|
bool is_paused() const TORRENT_DEPRECATED;
|
||||||
|
TORRENT_DEPRECATED_PREFIX
|
||||||
|
bool is_auto_managed() const TORRENT_DEPRECATED;
|
||||||
|
TORRENT_DEPRECATED_PREFIX
|
||||||
|
bool is_sequential_download() const TORRENT_DEPRECATED;
|
||||||
|
TORRENT_DEPRECATED_PREFIX
|
||||||
|
bool has_metadata() const TORRENT_DEPRECATED;
|
||||||
|
|
||||||
// deprecated in 0.13
|
// deprecated in 0.13
|
||||||
// marks the piece with the given index as filtered
|
// marks the piece with the given index as filtered
|
||||||
// it will not be downloaded
|
// it will not be downloaded
|
||||||
@@ -583,7 +603,6 @@ namespace libtorrent
|
|||||||
int download_limit() const;
|
int download_limit() const;
|
||||||
|
|
||||||
void set_sequential_download(bool sd) const;
|
void set_sequential_download(bool sd) const;
|
||||||
bool is_sequential_download() const;
|
|
||||||
|
|
||||||
int get_peer_upload_limit(tcp::endpoint ip) const;
|
int get_peer_upload_limit(tcp::endpoint ip) const;
|
||||||
int get_peer_download_limit(tcp::endpoint ip) const;
|
int get_peer_download_limit(tcp::endpoint ip) const;
|
||||||
|
@@ -6754,7 +6754,12 @@ namespace libtorrent
|
|||||||
|
|
||||||
st.num_complete = (m_complete == 0xffffff) ? -1 : m_complete;
|
st.num_complete = (m_complete == 0xffffff) ? -1 : m_complete;
|
||||||
st.num_incomplete = (m_incomplete == 0xffffff) ? -1 : m_incomplete;
|
st.num_incomplete = (m_incomplete == 0xffffff) ? -1 : m_incomplete;
|
||||||
st.paused = !m_allow_peers || m_graceful_pause_mode;
|
st.paused = is_torrent_paused();
|
||||||
|
st.auto_managed = m_auto_managed;
|
||||||
|
st.sequential_download = m_sequential_download;
|
||||||
|
st.is_seeding = is_seed();
|
||||||
|
st.is_finished = is_finished();
|
||||||
|
st.has_metadata = valid_metadata();
|
||||||
bytes_done(st, flags & torrent_handle::query_accurate_download_counters);
|
bytes_done(st, flags & torrent_handle::query_accurate_download_counters);
|
||||||
TORRENT_ASSERT(st.total_wanted_done >= 0);
|
TORRENT_ASSERT(st.total_wanted_done >= 0);
|
||||||
TORRENT_ASSERT(st.total_done >= st.total_wanted_done);
|
TORRENT_ASSERT(st.total_done >= st.total_wanted_done);
|
||||||
|
@@ -336,13 +336,6 @@ namespace libtorrent
|
|||||||
TORRENT_ASYNC_CALL2(add_extension, ext, userdata);
|
TORRENT_ASYNC_CALL2(add_extension, ext, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool torrent_handle::has_metadata() const
|
|
||||||
{
|
|
||||||
INVARIANT_CHECK;
|
|
||||||
TORRENT_SYNC_CALL_RET(bool, false, valid_metadata);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool torrent_handle::set_metadata(char const* metadata, int size) const
|
bool torrent_handle::set_metadata(char const* metadata, int size) const
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
@@ -350,27 +343,6 @@ namespace libtorrent
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool torrent_handle::is_seed() const
|
|
||||||
{
|
|
||||||
INVARIANT_CHECK;
|
|
||||||
TORRENT_SYNC_CALL_RET(bool, false, is_seed);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool torrent_handle::is_finished() const
|
|
||||||
{
|
|
||||||
INVARIANT_CHECK;
|
|
||||||
TORRENT_SYNC_CALL_RET(bool, false, is_finished);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool torrent_handle::is_paused() const
|
|
||||||
{
|
|
||||||
INVARIANT_CHECK;
|
|
||||||
TORRENT_SYNC_CALL_RET(bool, false, is_torrent_paused);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void torrent_handle::pause(int flags) const
|
void torrent_handle::pause(int flags) const
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
@@ -420,13 +392,6 @@ namespace libtorrent
|
|||||||
TORRENT_ASYNC_CALL(resume);
|
TORRENT_ASYNC_CALL(resume);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool torrent_handle::is_auto_managed() const
|
|
||||||
{
|
|
||||||
INVARIANT_CHECK;
|
|
||||||
TORRENT_SYNC_CALL_RET(bool, false, is_auto_managed);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void torrent_handle::auto_managed(bool m) const
|
void torrent_handle::auto_managed(bool m) const
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
@@ -512,13 +477,6 @@ namespace libtorrent
|
|||||||
TORRENT_ASYNC_CALL1(set_sequential_download, sd);
|
TORRENT_ASYNC_CALL1(set_sequential_download, sd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool torrent_handle::is_sequential_download() const
|
|
||||||
{
|
|
||||||
INVARIANT_CHECK;
|
|
||||||
TORRENT_SYNC_CALL_RET(bool, false, is_sequential_download);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string torrent_handle::name() const
|
std::string torrent_handle::name() const
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
@@ -589,6 +547,48 @@ namespace libtorrent
|
|||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
// ============ start deprecation ===============
|
// ============ start deprecation ===============
|
||||||
|
|
||||||
|
bool torrent_handle::is_seed() const
|
||||||
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
TORRENT_SYNC_CALL_RET(bool, false, is_seed);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool torrent_handle::is_finished() const
|
||||||
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
TORRENT_SYNC_CALL_RET(bool, false, is_finished);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool torrent_handle::is_paused() const
|
||||||
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
TORRENT_SYNC_CALL_RET(bool, false, is_torrent_paused);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool torrent_handle::is_sequential_download() const
|
||||||
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
TORRENT_SYNC_CALL_RET(bool, false, is_sequential_download);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool torrent_handle::is_auto_managed() const
|
||||||
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
TORRENT_SYNC_CALL_RET(bool, false, is_auto_managed);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool torrent_handle::has_metadata() const
|
||||||
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
TORRENT_SYNC_CALL_RET(bool, false, valid_metadata);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
void torrent_handle::filter_piece(int index, bool filter) const
|
void torrent_handle::filter_piece(int index, bool filter) const
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
@@ -99,7 +99,7 @@ bool print_alerts(libtorrent::session& ses, char const* name
|
|||||||
|
|
||||||
peer_error_alert* pea = alert_cast<peer_error_alert>(a.get());
|
peer_error_alert* pea = alert_cast<peer_error_alert>(a.get());
|
||||||
TEST_CHECK(pea == 0
|
TEST_CHECK(pea == 0
|
||||||
|| (!handles.empty() && h.is_seed())
|
|| (!handles.empty() && h.status().is_seeding)
|
||||||
|| pea->error.message() == "connecting to peer"
|
|| pea->error.message() == "connecting to peer"
|
||||||
|| pea->error.message() == "closing connection to ourself"
|
|| pea->error.message() == "closing connection to ourself"
|
||||||
|| pea->error.message() == "duplicate connection"
|
|| pea->error.message() == "duplicate connection"
|
||||||
|
@@ -61,9 +61,9 @@ void report_failure(char const* str, char const* file, int line);
|
|||||||
TEST_REPORT_AUX("TEST_CHECK failed: \"" #x "\"", __FILE__, __LINE__);
|
TEST_REPORT_AUX("TEST_CHECK failed: \"" #x "\"", __FILE__, __LINE__);
|
||||||
#define TEST_EQUAL(x, y) \
|
#define TEST_EQUAL(x, y) \
|
||||||
if (x != y) { \
|
if (x != y) { \
|
||||||
std::stringstream s; \
|
std::stringstream s__; \
|
||||||
s << "TEST_EQUAL_ERROR: " << #x << ": " << x << " expected: " << y << std::endl; \
|
s__ << "TEST_EQUAL_ERROR: " << #x << ": " << x << " expected: " << y << std::endl; \
|
||||||
TEST_REPORT_AUX(s.str().c_str(), __FILE__, __LINE__); \
|
TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define TEST_CHECK(x) \
|
#define TEST_CHECK(x) \
|
||||||
@@ -84,9 +84,9 @@ void report_failure(char const* str, char const* file, int line);
|
|||||||
#define TEST_EQUAL(x, y) \
|
#define TEST_EQUAL(x, y) \
|
||||||
try { \
|
try { \
|
||||||
if (x != y) { \
|
if (x != y) { \
|
||||||
std::stringstream s; \
|
std::stringstream s__; \
|
||||||
s << "TEST_EQUAL_ERROR: " << #x << ": " << x << " expected: " << y << std::endl; \
|
s__ << "TEST_EQUAL_ERROR: " << #x << ": " << x << " expected: " << y << std::endl; \
|
||||||
TEST_REPORT_AUX(s.str().c_str(), __FILE__, __LINE__); \
|
TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
catch (std::exception& e) \
|
catch (std::exception& e) \
|
||||||
|
@@ -75,13 +75,13 @@ void test_lsd()
|
|||||||
<< "\033[0m" << int(st2.progress * 100) << "% "
|
<< "\033[0m" << int(st2.progress * 100) << "% "
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
if (tor2.is_seed() /*&& tor3.is_seed()*/) break;
|
if (st2.is_seeding /*&& st3.is_seeding*/) break;
|
||||||
test_sleep(1000);
|
test_sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CHECK(tor2.is_seed());
|
TEST_CHECK(tor2.status().is_seeding);
|
||||||
|
|
||||||
if (tor2.is_seed()) std::cerr << "done\n";
|
if (tor2.status().is_seeding) std::cerr << "done\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_main()
|
int test_main()
|
||||||
|
@@ -73,13 +73,13 @@ void test_transfer(bool clear_files, bool disconnect
|
|||||||
print_alerts(ses2, "ses2", false, true);
|
print_alerts(ses2, "ses2", false, true);
|
||||||
|
|
||||||
if (disconnect && tor2.is_valid()) ses2.remove_torrent(tor2);
|
if (disconnect && tor2.is_valid()) ses2.remove_torrent(tor2);
|
||||||
if (!disconnect && tor2.has_metadata()) break;
|
if (!disconnect && tor2.status().has_metadata) break;
|
||||||
test_sleep(100);
|
test_sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disconnect) return;
|
if (disconnect) return;
|
||||||
|
|
||||||
TEST_CHECK(tor2.has_metadata());
|
TEST_CHECK(tor2.status().has_metadata);
|
||||||
std::cerr << "waiting for transfer to complete\n";
|
std::cerr << "waiting for transfer to complete\n";
|
||||||
|
|
||||||
for (int i = 0; i < 30; ++i)
|
for (int i = 0; i < 30; ++i)
|
||||||
@@ -95,12 +95,12 @@ void test_transfer(bool clear_files, bool disconnect
|
|||||||
<< "\033[0m" << int(st2.progress * 100) << "% "
|
<< "\033[0m" << int(st2.progress * 100) << "% "
|
||||||
<< st2.num_peers
|
<< st2.num_peers
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
if (tor2.is_seed()) break;
|
if (st2.is_seeding) break;
|
||||||
test_sleep(1000);
|
test_sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CHECK(tor2.is_seed());
|
TEST_CHECK(tor2.status().is_seeding);
|
||||||
if (tor2.is_seed()) std::cerr << "done\n";
|
if (tor2.status().is_seeding) std::cerr << "done\n";
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
remove_all("./tmp1_meta", ec);
|
remove_all("./tmp1_meta", ec);
|
||||||
|
@@ -112,16 +112,16 @@ void test_transfer(libtorrent::pe_settings::enc_policy policy,
|
|||||||
|
|
||||||
for (int i = 0; i < 50; ++i)
|
for (int i = 0; i < 50; ++i)
|
||||||
{
|
{
|
||||||
tor2.status();
|
torrent_status s = tor2.status();
|
||||||
print_alerts(ses1, "ses1");
|
print_alerts(ses1, "ses1");
|
||||||
print_alerts(ses2, "ses2");
|
print_alerts(ses2, "ses2");
|
||||||
|
|
||||||
if (tor2.is_seed()) break;
|
if (s.is_seeding) break;
|
||||||
test_sleep(1000);
|
test_sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CHECK(tor2.is_seed());
|
TEST_CHECK(tor2.status().is_seeding);
|
||||||
if (tor2.is_seed()) std::cerr << "done\n";
|
if (tor2.status().is_seeding) std::cerr << "done\n";
|
||||||
ses1.remove_torrent(tor1);
|
ses1.remove_torrent(tor1);
|
||||||
ses2.remove_torrent(tor2);
|
ses2.remove_torrent(tor2);
|
||||||
|
|
||||||
|
@@ -135,7 +135,7 @@ void test_pex()
|
|||||||
|
|
||||||
TEST_CHECK(st1.num_peers == 2 && st2.num_peers == 2 && st3.num_peers == 2)
|
TEST_CHECK(st1.num_peers == 2 && st2.num_peers == 2 && st3.num_peers == 2)
|
||||||
|
|
||||||
if (!tor2.is_seed() && tor3.is_seed()) std::cerr << "done\n";
|
if (!tor2.status().is_seeding && tor3.status().is_seeding) std::cerr << "done\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_main()
|
int test_main()
|
||||||
|
@@ -144,12 +144,12 @@ void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode
|
|||||||
<< st3.num_peers
|
<< st3.num_peers
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
if (tor2.is_seed() && tor3.is_seed()) break;
|
if (st2.is_seeding && st3.is_seeding) break;
|
||||||
test_sleep(1000);
|
test_sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CHECK(tor2.is_seed());
|
TEST_CHECK(tor2.status().is_seeding);
|
||||||
TEST_CHECK(tor3.is_seed());
|
TEST_CHECK(tor3.status().is_seeding);
|
||||||
|
|
||||||
float average2 = sum_dl_rate2 / float(count_dl_rates2);
|
float average2 = sum_dl_rate2 / float(count_dl_rates2);
|
||||||
float average3 = sum_dl_rate3 / float(count_dl_rates3);
|
float average3 = sum_dl_rate3 / float(count_dl_rates3);
|
||||||
@@ -158,7 +158,7 @@ void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode
|
|||||||
std::cerr << "average rate: " << (average2 / 1000.f) << "kB/s - "
|
std::cerr << "average rate: " << (average2 / 1000.f) << "kB/s - "
|
||||||
<< (average3 / 1000.f) << "kB/s" << std::endl;
|
<< (average3 / 1000.f) << "kB/s" << std::endl;
|
||||||
|
|
||||||
if (tor2.is_seed() && tor3.is_seed()) std::cerr << "done\n";
|
if (tor2.status().is_seeding && tor3.status().is_seeding) std::cerr << "done\n";
|
||||||
|
|
||||||
// make sure the files are deleted
|
// make sure the files are deleted
|
||||||
ses1.remove_torrent(tor1, session::delete_files);
|
ses1.remove_torrent(tor1, session::delete_files);
|
||||||
|
@@ -99,11 +99,11 @@ void test_rate()
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tor2.is_seed()) break;
|
if (st2.is_seeding) break;
|
||||||
test_sleep(100);
|
test_sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CHECK(tor2.is_seed());
|
TEST_CHECK(tor2.status().is_seeding);
|
||||||
|
|
||||||
time_duration dt = time_now() - start;
|
time_duration dt = time_now() - start;
|
||||||
|
|
||||||
@@ -377,7 +377,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!test_disk_full && tor2.is_finished()) break;
|
if (!test_disk_full && st2.is_finished) break;
|
||||||
|
|
||||||
TEST_CHECK(st1.state == torrent_status::seeding
|
TEST_CHECK(st1.state == torrent_status::seeding
|
||||||
|| st1.state == torrent_status::checking_files);
|
|| st1.state == torrent_status::checking_files);
|
||||||
@@ -390,9 +390,9 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
|
|||||||
// 1 announce per tracker to start
|
// 1 announce per tracker to start
|
||||||
TEST_CHECK(tracker_responses >= 2);
|
TEST_CHECK(tracker_responses >= 2);
|
||||||
|
|
||||||
TEST_CHECK(!tor2.is_seed());
|
TEST_CHECK(!tor2.status().is_seeding);
|
||||||
TEST_CHECK(tor2.is_finished());
|
TEST_CHECK(tor2.status().is_finished);
|
||||||
if (tor2.is_finished())
|
if (tor2.status().is_finished)
|
||||||
std::cerr << "torrent is finished (50% complete)" << std::endl;
|
std::cerr << "torrent is finished (50% complete)" << std::endl;
|
||||||
|
|
||||||
std::cerr << "force recheck" << std::endl;
|
std::cerr << "force recheck" << std::endl;
|
||||||
@@ -500,7 +500,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
|
|||||||
test_sleep(100);
|
test_sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CHECK(!tor2.is_seed());
|
TEST_CHECK(!tor2.status().is_seeding);
|
||||||
|
|
||||||
std::fill(priorities.begin(), priorities.end(), 1);
|
std::fill(priorities.begin(), priorities.end(), 1);
|
||||||
tor2.prioritize_pieces(priorities);
|
tor2.prioritize_pieces(priorities);
|
||||||
@@ -530,7 +530,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tor2.is_finished()) break;
|
if (tor2.status().is_finished) break;
|
||||||
|
|
||||||
TEST_CHECK(st1.state == torrent_status::seeding);
|
TEST_CHECK(st1.state == torrent_status::seeding);
|
||||||
TEST_CHECK(st2.state == torrent_status::downloading);
|
TEST_CHECK(st2.state == torrent_status::downloading);
|
||||||
@@ -538,7 +538,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
|
|||||||
test_sleep(100);
|
test_sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CHECK(tor2.is_seed());
|
TEST_CHECK(tor2.status().is_seeding);
|
||||||
|
|
||||||
stop_tracker();
|
stop_tracker();
|
||||||
stop_web_server();
|
stop_web_server();
|
||||||
|
@@ -120,10 +120,9 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file
|
|||||||
|
|
||||||
print_alerts(ses, " >> ses");
|
print_alerts(ses, " >> ses");
|
||||||
|
|
||||||
if (th.is_seed()/* && ss.download_rate == 0.f*/)
|
if (s.is_seeding /* && ss.download_rate == 0.f*/)
|
||||||
{
|
{
|
||||||
torrent_status st = th.status();
|
TEST_EQUAL(s.total_payload_download - s.total_redundant_bytes, total_size);
|
||||||
TEST_EQUAL(st.total_payload_download - st.total_redundant_bytes, total_size);
|
|
||||||
// we need to sleep here a bit to let the session sync with the torrent stats
|
// we need to sleep here a bit to let the session sync with the torrent stats
|
||||||
test_sleep(1000);
|
test_sleep(1000);
|
||||||
TEST_EQUAL(ses.status().total_payload_download - ses.status().total_redundant_bytes
|
TEST_EQUAL(ses.status().total_payload_download - ses.status().total_redundant_bytes
|
||||||
@@ -148,7 +147,7 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file
|
|||||||
// TEST_CHECK(fabs(rate_sum - total_size) < total_size * .1f);
|
// TEST_CHECK(fabs(rate_sum - total_size) < total_size * .1f);
|
||||||
// TEST_CHECK(fabs(ses_rate_sum - total_size) < total_size * .1f);
|
// TEST_CHECK(fabs(ses_rate_sum - total_size) < total_size * .1f);
|
||||||
|
|
||||||
TEST_CHECK(th.is_seed());
|
TEST_CHECK(th.status().is_seeding);
|
||||||
|
|
||||||
if (proxy) stop_proxy(8002);
|
if (proxy) stop_proxy(8002);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user