diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index e0054f628..284f31d00 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -396,7 +396,7 @@ namespace libtorrent void dht_live_nodes(sha1_hash const& nid); - void dht_direct_request(udp::endpoint ep, entry& e + void dht_direct_request(udp::endpoint const& ep, entry& e , void* userdata = nullptr); #ifndef TORRENT_NO_DEPRECATE diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index 50acdd256..d0a268847 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -455,7 +455,7 @@ namespace libtorrent // with the response (if any) and the userdata pointer passed in here. // Since this alert is a response to an explicit call, it will always be // posted, regardless of the alert mask. - void dht_direct_request(udp::endpoint ep, entry const& e, void* userdata = nullptr); + void dht_direct_request(udp::endpoint const& ep, entry const& e, void* userdata = nullptr); #ifndef TORRENT_NO_DEPRECATE // deprecated in 0.15 diff --git a/src/kademlia/get_item.cpp b/src/kademlia/get_item.cpp index 7047f9ece..0b4f052e9 100644 --- a/src/kademlia/get_item.cpp +++ b/src/kademlia/get_item.cpp @@ -31,15 +31,11 @@ POSSIBILITY OF SUCH DAMAGE. */ #include -#include #include #include #include #include - -#if TORRENT_USE_ASSERTS -#include -#endif +#include namespace libtorrent { namespace dht { @@ -91,7 +87,7 @@ void get_item::got_data(bdecode_node const& v, // for get_item, we should call callback when we get data, // even if the date is not authoritative, we can update later. - // so caller can get response ASAP without waitting transaction + // so caller can get response ASAP without waiting transaction // time-out (15 seconds). // for put_item, the callback function will do nothing // if the data is non-authoritative. @@ -146,6 +142,8 @@ bool get_item::invoke(observer_ptr o) e["q"] = "get"; a["target"] = target().to_string(); + m_node.stats_counters().inc_stats_counter(counters::dht_get_out); + return m_node.m_rpc.invoke(e, o->target_ep(), o); } diff --git a/src/kademlia/put_data.cpp b/src/kademlia/put_data.cpp index 04ad553a2..5e19f4b87 100644 --- a/src/kademlia/put_data.cpp +++ b/src/kademlia/put_data.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace libtorrent { namespace dht { @@ -85,8 +86,8 @@ bool put_data::invoke(observer_ptr o) { if (m_done) return false; - // TODO: what if o is not an isntance of put_data_observer? This need to be - // redesigned for better type saftey. + // TODO: what if o is not an instance of put_data_observer? This need to be + // redesigned for better type safety. put_data_observer* po = static_cast(o.get()); entry e; @@ -106,6 +107,8 @@ bool put_data::invoke(observer_ptr o) } } + m_node.stats_counters().inc_stats_counter(counters::dht_put_out); + return m_node.m_rpc.invoke(e, o->target_ep(), o); } diff --git a/src/session_handle.cpp b/src/session_handle.cpp index 6f4fcfddb..5b8202472 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -59,7 +59,7 @@ namespace libtorrent #ifndef BOOST_NO_EXCEPTIONS try { #endif - (m_impl->*f)(a...); + (m_impl->*f)(std::forward(a)...); #ifndef BOOST_NO_EXCEPTIONS } catch (system_error const& e) { m_impl->alerts().emplace_alert(e.code(), e.what()); @@ -81,12 +81,12 @@ namespace libtorrent bool done = false; std::exception_ptr ex; - m_impl->get_io_service().dispatch([=,&done,&ex]() mutable + m_impl->get_io_service().dispatch([=, &done, &ex]() mutable { #ifndef BOOST_NO_EXCEPTIONS try { #endif - (m_impl->*f)(a...); + (m_impl->*f)(std::forward(a)...); #ifndef BOOST_NO_EXCEPTIONS } catch (...) { ex = std::current_exception(); @@ -110,12 +110,12 @@ namespace libtorrent bool done = false; Ret r; std::exception_ptr ex; - m_impl->get_io_service().dispatch([=,&r,&done,&ex]() mutable + m_impl->get_io_service().dispatch([=, &r, &done, &ex]() mutable { #ifndef BOOST_NO_EXCEPTIONS try { #endif - r = (m_impl->*f)(a...); + r = (m_impl->*f)(std::forward(a)...); #ifndef BOOST_NO_EXCEPTIONS } catch (...) { ex = std::current_exception(); @@ -610,7 +610,7 @@ namespace libtorrent #endif } - void session_handle::dht_direct_request(udp::endpoint ep, entry const& e, void* userdata) + void session_handle::dht_direct_request(udp::endpoint const& ep, entry const& e, void* userdata) { #ifndef TORRENT_DISABLE_DHT entry copy = e; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index e8c713239..cd6f5b73b 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5838,7 +5838,7 @@ namespace aux { m_alerts.emplace_alert(nid, nodes); } - void session_impl::dht_direct_request(udp::endpoint ep, entry& e, void* userdata) + void session_impl::dht_direct_request(udp::endpoint const& ep, entry& e, void* userdata) { if (!m_dht) return; m_dht->direct_request(ep, e, std::bind(&on_direct_response, std::ref(m_alerts), userdata, _1)); diff --git a/test/test_alert_types.cpp b/test/test_alert_types.cpp index 8df1fa29f..e81a7d8a2 100644 --- a/test/test_alert_types.cpp +++ b/test/test_alert_types.cpp @@ -39,6 +39,21 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; +TORRENT_TEST(alerts_types) +{ +#define TEST_ALERT_TYPE(name, seq, prio) \ + TEST_EQUAL(name::priority, prio); \ + TEST_EQUAL(name::alert_type, seq); + + TEST_ALERT_TYPE(dht_get_peers_reply_alert, 87, 0); + TEST_ALERT_TYPE(session_error_alert, 90, 0); + TEST_ALERT_TYPE(dht_live_nodes_alert, 91, 0); + +#undef TEST_ALERT_TYPE + + TEST_EQUAL(num_alert_types, 92); +} + TORRENT_TEST(dht_get_peers_reply_alert) { alert_manager mgr(1, dht_get_peers_reply_alert::static_category); diff --git a/test/test_bitfield.cpp b/test/test_bitfield.cpp index ae711e076..a90c1ebac 100644 --- a/test/test_bitfield.cpp +++ b/test/test_bitfield.cpp @@ -195,7 +195,7 @@ TORRENT_TEST(test_assign2) bitfield test1; for (int i = 0; i < 4; ++i) { - memset(&b[i], 0xff, 5); + std::memset(&b[i], 0xff, 5); b[i + 5] = char(0xc0); test1.assign(&b[i], 32 + 8 + 2); print_bitfield(test1); @@ -402,4 +402,4 @@ TORRENT_TEST(not_initialized_resize) bitfield test2(0); test2.resize(8); TEST_EQUAL(test2.size(), 8); -} \ No newline at end of file +} diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 3beaa3aa4..a78a30529 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -2437,7 +2437,7 @@ TORRENT_TEST(traversal_done) std::array nodes = build_nodes(target); // invert the ith most significant byte so that the test nodes are - // progressivly closer to the target item + // progressively closer to the target item for (int i = 0; i < num_test_nodes; ++i) nodes[i].id[i] = ~nodes[i].id[i];