deprecated alert::progress_notification alert category, split into finer grained categories

This commit is contained in:
Arvid Norberg 2018-03-30 12:50:31 +02:00 committed by Arvid Norberg
parent 2a82bb5880
commit 6efff919cd
22 changed files with 234 additions and 60 deletions

View File

@ -1,3 +1,5 @@
* deprecated alert::progress_notification alert category, split into
finer grained categories
* update plugin interface functions for improved type-safety
* implemented support magnet URI extension, select specific file indices
for download, BEP53

View File

@ -275,7 +275,9 @@ void bind_alert()
s.attr("tracker_notification") = alert::tracker_notification;
s.attr("debug_notification") = alert::debug_notification;
s.attr("status_notification") = alert::status_notification;
#ifndef TORRENT_NO_DEPRECATE
s.attr("progress_notification") = alert::progress_notification;
#endif
s.attr("ip_block_notification") = alert::ip_block_notification;
s.attr("performance_warning") = alert::performance_warning;
s.attr("dht_notification") = alert::dht_notification;
@ -288,6 +290,10 @@ void bind_alert()
s.attr("dht_operation_notification") = alert::dht_operation_notification;
s.attr("port_mapping_log_notification") = alert::port_mapping_log_notification;
s.attr("picker_log_notification") = alert::picker_log_notification;
s.attr("file_progress_notification") = alert::file_progress_notification;
s.attr("piece_progress_notification") = alert::piece_progress_notification;
s.attr("upload_notification") = alert::upload_notification;
s.attr("block_progress_notification") = alert::block_progress_notification;
s.attr("all_categories") = alert::all_categories;
}

View File

@ -216,3 +216,4 @@ pe
lt
tex
natpmp
cancelled

View File

@ -73,6 +73,17 @@ This means they are no longer heap allocated nor held by a smart pointer.
The ``clone()`` member on alerts was deprecated in 1.1 and removed in 1.2.
To pass alerts across threads, instead pull out the relevant information from the alerts and pass that across.
progress alert category
=======================
The ``alert::progress_notification`` category has been deprecated.
Alerts posted in this category are now also posted in one of these new categories:
* ``alert::block_progress_notification``
* ``alert::piece_progress_notification``
* ``alert::file_progress_notification``
* ``alert::upload_notification``
boost replaced by std
=====================

View File

@ -1086,16 +1086,21 @@ example alert_masks:
settings.set_int(settings_pack::choking_algorithm, settings_pack::rate_based_choker);
settings.set_str(settings_pack::user_agent, "client_test/" LIBTORRENT_VERSION);
settings.set_int(settings_pack::alert_mask, alert::all_categories
& ~(alert::dht_notification
| alert::progress_notification
| alert::stats_notification
| alert::session_log_notification
| alert::torrent_log_notification
| alert::peer_log_notification
| alert::dht_log_notification
| alert::picker_log_notification
));
settings.set_int(settings_pack::alert_mask
, alert::error_notification
| alert::peer_notification
| alert::port_mapping_notification
| alert::storage_notification
| alert::tracker_notification
| alert::debug_notification
| alert::status_notification
| alert::ip_block_notification
| alert::performance_warning
| alert::dht_notification
| alert::incoming_request_notification
| alert::dht_operation_notification
| alert::port_mapping_log_notification
| alert::file_progress_notification);
lt::time_duration refresh_delay = lt::milliseconds(500);
bool rate_limit_locals = false;

View File

@ -70,12 +70,20 @@ namespace libtorrent {
// hidden
using alert_category_t = flags::bitfield_flag<std::uint32_t, struct alert_category_tag>;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
// The ``alert`` class is the base class that specific messages are derived from.
// alert types are not copyable, and cannot be constructed by the client. The
// pointers returned by libtorrent are short lived (the details are described
// under session_handle::pop_alerts())
class TORRENT_EXPORT alert
{
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
public:
alert(alert const& rhs) = delete;
@ -84,7 +92,7 @@ namespace libtorrent {
#ifndef TORRENT_NO_DEPRECATE
// only here for backwards compatibility
enum TORRENT_DEPRECATED severity_t { debug, info, warning, critical, fatal, none };
enum TORRENT_DEPRECATED_ENUM severity_t { debug, info, warning, critical, fatal, none };
#endif
// Enables alerts that report an error. This includes:
@ -120,9 +128,11 @@ namespace libtorrent {
// Enables alerts for when a torrent or the session changes state.
static constexpr alert_category_t status_notification = 6_bit;
#ifndef TORRENT_NO_DEPRECATE
// Alerts for when blocks are requested and completed. Also when
// pieces are completed.
static constexpr alert_category_t progress_notification = 7_bit;
static constexpr alert_category_t TORRENT_DEPRECATED_MEMBER progress_notification = 7_bit;
#endif
// Alerts when a peer is blocked by the ip blocker or port blocker.
static constexpr alert_category_t ip_block_notification = 8_bit;
@ -181,6 +191,20 @@ namespace libtorrent {
// enables verbose logging from the piece picker.
static constexpr alert_category_t picker_log_notification = 20_bit;
// alerts when files complete downloading
static constexpr alert_category_t file_progress_notification = 21_bit;
// alerts when pieces complete downloading or fail hash check
static constexpr alert_category_t piece_progress_notification = 22_bit;
// alerts when we upload blocks to other peers
static constexpr alert_category_t upload_notification = 23_bit;
// alerts on individual blocks being requested, downloading, finished,
// rejected, time-out and cancelled. This is likely to post alerts at a
// high rate.
static constexpr alert_category_t block_progress_notification = 24_bit;
// The full bitmask, representing all available categories.
//
// since the enum is signed, make sure this isn't

View File

@ -59,6 +59,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/shared_array.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#ifndef TORRENT_NO_DEPRECATE
#define PROGRESS_NOTIFICATION | alert::progress_notification
#else
#define PROGRESS_NOTIFICATION
#endif
namespace libtorrent {
#ifndef TORRENT_NO_DEPRECATE
@ -254,7 +261,17 @@ namespace libtorrent {
TORRENT_DEFINE_ALERT(file_completed_alert, 6)
static constexpr alert_category_t static_category = alert::progress_notification;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
static constexpr alert_category_t static_category =
alert::file_progress_notification
PROGRESS_NOTIFICATION
;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
std::string message() const override;
// refers to the index of the file that completed.
@ -809,7 +826,17 @@ namespace libtorrent {
TORRENT_DEFINE_ALERT(piece_finished_alert, 27)
static constexpr alert_category_t static_category = alert::progress_notification;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
static constexpr alert_category_t static_category =
alert::piece_progress_notification
PROGRESS_NOTIFICATION
;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
std::string message() const override;
// the index of the piece that finished
@ -826,8 +853,18 @@ namespace libtorrent {
TORRENT_DEFINE_ALERT(request_dropped_alert, 28)
static constexpr alert_category_t static_category = alert::progress_notification
| alert::peer_notification;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
static constexpr alert_category_t static_category =
alert::block_progress_notification
| alert::peer_notification
PROGRESS_NOTIFICATION
;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
std::string message() const override;
int const block_index;
@ -844,8 +881,18 @@ namespace libtorrent {
TORRENT_DEFINE_ALERT(block_timeout_alert, 29)
static constexpr alert_category_t static_category = alert::progress_notification
| alert::peer_notification;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
static constexpr alert_category_t static_category =
alert::block_progress_notification
| alert::peer_notification
PROGRESS_NOTIFICATION
;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
std::string message() const override;
int const block_index;
@ -862,7 +909,17 @@ namespace libtorrent {
TORRENT_DEFINE_ALERT(block_finished_alert, 30)
static constexpr alert_category_t static_category = alert::progress_notification;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
static constexpr alert_category_t static_category =
alert::block_progress_notification
PROGRESS_NOTIFICATION
;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
std::string message() const override;
int const block_index;
@ -879,7 +936,17 @@ namespace libtorrent {
TORRENT_DEFINE_ALERT(block_downloading_alert, 31)
static constexpr alert_category_t static_category = alert::progress_notification;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
static constexpr alert_category_t static_category =
alert::block_progress_notification
PROGRESS_NOTIFICATION
;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
std::string message() const override;
int const block_index;
@ -2710,7 +2777,7 @@ namespace libtorrent {
// This alert is posted when a block intended to be sent to a peer is placed in the
// send buffer. Note that if the connection is closed before the send buffer is sent,
// the alert may be posted without the bytes having been sent to the peer.
// It belongs to the ``progress_notification`` category.
// It belongs to the ``upload_notification`` category.
struct TORRENT_EXPORT block_uploaded_alert final : peer_alert
{
// internal
@ -2720,7 +2787,17 @@ namespace libtorrent {
TORRENT_DEFINE_ALERT(block_uploaded_alert, 94)
static constexpr alert_category_t static_category = alert::progress_notification;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
static constexpr alert_category_t static_category =
alert::upload_notification
PROGRESS_NOTIFICATION
;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
std::string message() const override;
int const block_index;
@ -2730,6 +2807,7 @@ namespace libtorrent {
#undef TORRENT_DEFINE_ALERT_IMPL
#undef TORRENT_DEFINE_ALERT
#undef TORRENT_DEFINE_ALERT_PRIO
#undef PROGRESS_NOTIFICATION
constexpr int num_alert_types = 95; // this constant represents "max_alert_index" + 1
}

View File

@ -370,7 +370,7 @@ void run_test(lt::aux::proxy_settings ps, std::string url, int expect_size, int
});
http.register_handler("/redirect"
, [&data_buffer,&counters](std::string method, std::string req
, [&counters](std::string method, std::string req
, std::map<std::string, std::string>&)
{
++counters[redirect_req];
@ -381,7 +381,7 @@ void run_test(lt::aux::proxy_settings ps, std::string url, int expect_size, int
});
http.register_handler("/relative/redirect"
, [&data_buffer,&counters](std::string method, std::string req
, [&counters](std::string method, std::string req
, std::map<std::string, std::string>&)
{
++counters[rel_redirect_req];
@ -392,7 +392,7 @@ void run_test(lt::aux::proxy_settings ps, std::string url, int expect_size, int
});
http.register_handler("/infinite/redirect"
, [&data_buffer,&counters](std::string method, std::string req
, [&counters](std::string method, std::string req
, std::map<std::string, std::string>&)
{
++counters[inf_redirect_req];

View File

@ -512,7 +512,7 @@ TORRENT_TEST(torrent_completed_alert)
// add session
, [](lt::settings_pack& pack)
{
pack.set_int(lt::settings_pack::alert_mask, alert::progress_notification);
pack.set_int(lt::settings_pack::alert_mask, alert::file_progress_notification);
}
// add torrent
, [](lt::add_torrent_params&) {}
@ -550,7 +550,7 @@ TORRENT_TEST(block_uploaded_alert)
, [](lt::settings_pack& pack)
{
pack.set_int(lt::settings_pack::alert_mask,
alert::progress_notification | alert::status_notification);
alert::upload_notification | alert::status_notification);
}
// add torrent
, [](lt::add_torrent_params&) {}

View File

@ -74,7 +74,6 @@ void test_interval(int interval)
sim::default_config network_cfg;
sim::simulation sim{network_cfg};
lt::time_point start = lt::clock_type::now();
bool ran_to_completion = false;
sim::asio::io_service web_server(sim, address_v4::from_string("2.2.2.2"));
@ -85,7 +84,7 @@ void test_interval(int interval)
std::vector<lt::time_point> announces;
http.register_handler("/announce"
, [&announces,interval,start,&ran_to_completion](std::string /* method */
, [&announces,interval,&ran_to_completion](std::string /* method */
, std::string /* req */
, std::map<std::string, std::string>&)
{

View File

@ -62,7 +62,9 @@ namespace libtorrent {
constexpr alert_category_t alert::tracker_notification;
constexpr alert_category_t alert::debug_notification;
constexpr alert_category_t alert::status_notification;
#ifndef TORRENT_NO_DEPRECATE
constexpr alert_category_t alert::progress_notification;
#endif
constexpr alert_category_t alert::ip_block_notification;
constexpr alert_category_t alert::performance_warning;
constexpr alert_category_t alert::dht_notification;
@ -75,6 +77,11 @@ namespace libtorrent {
constexpr alert_category_t alert::dht_operation_notification;
constexpr alert_category_t alert::port_mapping_log_notification;
constexpr alert_category_t alert::picker_log_notification;
constexpr alert_category_t alert::file_progress_notification;
constexpr alert_category_t alert::piece_progress_notification;
constexpr alert_category_t alert::upload_notification;
constexpr alert_category_t alert::block_progress_notification;
constexpr alert_category_t alert::all_categories;
#ifndef TORRENT_NO_DEPRECATE
constexpr alert_category_t alert::rss_notification;

View File

@ -39,8 +39,11 @@ using namespace lt;
lt::settings_pack settings()
{
auto const mask = alert::all_categories
& ~(alert::progress_notification
| alert::performance_warning
& ~(
alert::performance_warning
#ifndef TORRENT_NO_DEPRECATE
| alert::progress_notification
#endif
| alert::stats_notification
| alert::picker_log_notification);

View File

@ -770,9 +770,16 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
ses2->set_peer_class_filter(f);
if (ses3) ses3->set_peer_class_filter(f);
auto const mask = alert::all_categories
& ~(
alert::performance_warning
#ifndef TORRENT_NO_DEPRECATE
| alert::progress_notification
#endif
| alert::stats_notification);
settings_pack pack;
pack.set_int(settings_pack::alert_mask
, ~(alert::progress_notification | alert::stats_notification));
pack.set_int(settings_pack::alert_mask, mask);
if (ses3) pack.set_bool(settings_pack::allow_multiple_connections_per_ip, true);
pack.set_int(settings_pack::mixed_mode_algorithm, settings_pack::prefer_tcp);
pack.set_int(settings_pack::max_failcount, 1);

View File

@ -75,9 +75,11 @@ void test_swarm(test_flags_t const flags)
session_proxy p2;
session_proxy p3;
auto const mask = alert::all_categories
& ~(alert::progress_notification
| alert::performance_warning
auto const mask = ~(
alert::performance_warning
#ifndef TORRENT_NO_DEPRECATE
| alert::progress_notification
#endif
| alert::stats_notification);
settings_pack pack;

View File

@ -65,9 +65,16 @@ TORRENT_TEST(alerts_types)
#else
++count_alert_types;
#endif
#ifndef TORRENT_NO_DEPRECATE
#define PROGRESS_NOTIFICATION alert::progress_notification |
#else
#define PROGRESS_NOTIFICATION
#endif
TEST_ALERT_TYPE(torrent_removed_alert, 4, 1, alert::status_notification);
TEST_ALERT_TYPE(read_piece_alert, 5, 1, alert::storage_notification);
TEST_ALERT_TYPE(file_completed_alert, 6, 0, alert::progress_notification);
TEST_ALERT_TYPE(file_completed_alert, 6, 0, PROGRESS_NOTIFICATION alert::file_progress_notification);
TEST_ALERT_TYPE(file_renamed_alert, 7, 1, alert::storage_notification);
TEST_ALERT_TYPE(file_rename_failed_alert, 8, 1, alert::storage_notification);
TEST_ALERT_TYPE(performance_alert, 9, 0, alert::performance_warning);
@ -88,11 +95,11 @@ TORRENT_TEST(alerts_types)
TEST_ALERT_TYPE(peer_disconnected_alert, 24, 0, alert::debug_notification);
TEST_ALERT_TYPE(invalid_request_alert, 25, 0, alert::peer_notification);
TEST_ALERT_TYPE(torrent_finished_alert, 26, 0, alert::status_notification);
TEST_ALERT_TYPE(piece_finished_alert, 27, 0, alert::progress_notification);
TEST_ALERT_TYPE(request_dropped_alert, 28, 0, alert::progress_notification | alert::peer_notification);
TEST_ALERT_TYPE(block_timeout_alert, 29, 0, alert::progress_notification | alert::peer_notification);
TEST_ALERT_TYPE(block_finished_alert, 30, 0, alert::progress_notification);
TEST_ALERT_TYPE(block_downloading_alert, 31, 0, alert::progress_notification);
TEST_ALERT_TYPE(piece_finished_alert, 27, 0, PROGRESS_NOTIFICATION alert::piece_progress_notification);
TEST_ALERT_TYPE(request_dropped_alert, 28, 0, PROGRESS_NOTIFICATION alert::block_progress_notification | alert::peer_notification);
TEST_ALERT_TYPE(block_timeout_alert, 29, 0, PROGRESS_NOTIFICATION alert::block_progress_notification | alert::peer_notification);
TEST_ALERT_TYPE(block_finished_alert, 30, 0, PROGRESS_NOTIFICATION alert::block_progress_notification);
TEST_ALERT_TYPE(block_downloading_alert, 31, 0, PROGRESS_NOTIFICATION alert::block_progress_notification);
TEST_ALERT_TYPE(unwanted_block_alert, 32, 0, alert::peer_notification);
TEST_ALERT_TYPE(storage_moved_alert, 33, 1, alert::storage_notification);
TEST_ALERT_TYPE(storage_moved_failed_alert, 34, 1, alert::storage_notification);
@ -163,7 +170,7 @@ TORRENT_TEST(alerts_types)
TEST_ALERT_TYPE(dht_live_nodes_alert, 91, 0, alert::dht_notification);
TEST_ALERT_TYPE(session_stats_header_alert, 92, 0, alert::stats_notification);
TEST_ALERT_TYPE(dht_sample_infohashes_alert, 93, 0, alert::dht_operation_notification);
TEST_ALERT_TYPE(block_uploaded_alert, 94, 0, alert::progress_notification);
TEST_ALERT_TYPE(block_uploaded_alert, 94, 0, PROGRESS_NOTIFICATION alert::upload_notification);
#undef TEST_ALERT_TYPE
@ -324,3 +331,6 @@ TORRENT_TEST(dht_sample_infohashes_alert)
std::sort(nodes.begin(), nodes.end());
TEST_CHECK(nv == nodes);
}
#undef PROGRESS_NOTIFICATION

View File

@ -59,9 +59,11 @@ void test_pex()
session_proxy p2;
session_proxy p3;
auto const mask = alert::all_categories
& ~(alert::progress_notification
| alert::performance_warning
auto const mask = ~(
alert::performance_warning
#ifndef TORRENT_NO_DEPRECATE
| alert::progress_notification
#endif
| alert::stats_notification);
// this is to avoid everything finish from a single peer

View File

@ -101,9 +101,12 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
int const prev_udp_announces = num_udp_announces();
auto const alert_mask = alert::all_categories
& ~alert::progress_notification
& ~alert::stats_notification;
auto const alert_mask = ~(
alert::performance_warning
#ifndef TORRENT_NO_DEPRECATE
| alert::progress_notification
#endif
| alert::stats_notification);
settings_pack sett = settings();
sett.set_int(settings_pack::stop_tracker_timeout, 2);

View File

@ -91,9 +91,11 @@ void test_read_piece(int flags)
std::printf("generated torrent: %s tmp1_read_piece/test_torrent\n"
, aux::to_hex(ti->info_hash()).c_str());
auto const mask = alert::all_categories
& ~(alert::progress_notification
| alert::performance_warning
auto const mask = ~(
alert::performance_warning
#ifndef TORRENT_NO_DEPRECATE
| alert::progress_notification
#endif
| alert::stats_notification);
settings_pack sett;

View File

@ -263,14 +263,14 @@ void test_ssl(int test_idx, bool use_utp)
<< std::endl;
}
if (st2.is_finished) break;
if (peer_disconnects >= 2)
{
std::printf("too many disconnects (%d), breaking\n", peer_disconnects);
break;
}
if (st2.is_finished) break;
if (st2.state != torrent_status::downloading)
{
static char const* state_str[] =

View File

@ -62,9 +62,11 @@ void test_transfer()
session_proxy p1;
session_proxy p2;
auto const mask = alert::all_categories
& ~(alert::progress_notification
| alert::performance_warning
auto const mask = ~(
alert::performance_warning
#ifndef TORRENT_NO_DEPRECATE
| alert::progress_notification
#endif
| alert::stats_notification);
settings_pack pack;

View File

@ -88,9 +88,16 @@ TORRENT_TEST(web_seed_redirect)
auto torrent_file = std::make_shared<torrent_info>(buf, ec, from_span);
{
auto const mask = ~(
alert::performance_warning
#ifndef TORRENT_NO_DEPRECATE
| alert::progress_notification
#endif
| alert::stats_notification);
settings_pack p = settings();
p.set_int(settings_pack::max_queued_disk_bytes, 256 * 1024);
p.set_int(settings_pack::alert_mask, ~(alert::progress_notification | alert::stats_notification));
p.set_int(settings_pack::alert_mask, mask);
lt::session ses(p);
// disable keep-alive because otherwise the test will choke on seeing

View File

@ -392,8 +392,11 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
{
auto const mask = alert::all_categories
& ~(alert::progress_notification
| alert::performance_warning
& ~(
alert::performance_warning
#ifndef TORRENT_NO_DEPRECATE
| alert::progress_notification
#endif
| alert::stats_notification);
settings_pack pack;