From f05fad0d41d1987bd74e4a53814611295dd901db Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 21 Jul 2016 18:10:29 -0700 Subject: [PATCH 1/6] remove load_asnum_db and load_country_db from python bindings (#930) --- ChangeLog | 1 + bindings/python/src/session.cpp | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17b05d787..cedd201f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 1.1.1 release + * remove load_asnum_db and load_country_db from python bindings * fix crash in session::get_ip_filter when not having set one * fix filename escaping when repairing torrents with broken web seeds * fix bug where file_completed_alert would not be posted unless file_progress diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 614ac163a..42626f6b7 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -498,9 +498,6 @@ namespace } return pieces; } - - void load_asnum_db(lt::session& s, std::string file) {} - void load_country_db(lt::session& s, std::string file) {} #endif entry save_state(lt::session const& s, boost::uint32_t flags) @@ -875,8 +872,6 @@ void bind_session() .def("set_max_connections", allow_threads(<::session::set_max_connections)) .def("max_connections", allow_threads(<::session::max_connections)) .def("num_connections", allow_threads(<::session::num_connections)) - .def("load_asnum_db", &load_asnum_db) - .def("load_country_db", &load_country_db) .def("set_max_half_open_connections", allow_threads(<::session::set_max_half_open_connections)) .def("set_severity_level", allow_threads(<::session::set_severity_level)) .def("set_alert_queue_size_limit", allow_threads(<::session::set_alert_queue_size_limit)) From 3321ca10f175cd88fbbba1268f0f2db5d660e823 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sun, 24 Jul 2016 18:30:36 -0700 Subject: [PATCH 2/6] update our id in the rpc manager when it changes (#942) update our id in the rpc manager when it changes --- ChangeLog | 1 + include/libtorrent/kademlia/rpc_manager.hpp | 2 ++ src/kademlia/node.cpp | 1 + 3 files changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index cedd201f1..a1ae48654 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,7 @@ * fix set_settings in python binding * Added missing alert categories in python binding * Added dht_get_peers_reply_alert alert in python binding + * fixed updating the node id reported to peers after changing IPs 1.1.0 release diff --git a/include/libtorrent/kademlia/rpc_manager.hpp b/include/libtorrent/kademlia/rpc_manager.hpp index 55c40c3ae..a1ae527ec 100644 --- a/include/libtorrent/kademlia/rpc_manager.hpp +++ b/include/libtorrent/kademlia/rpc_manager.hpp @@ -111,6 +111,8 @@ public: int num_allocated_observers() const { return m_allocated_observers; } + void update_node_id(node_id const& id) { m_our_id = id; } + private: boost::uint32_t calc_connection_id(udp::endpoint addr); diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 51be55850..a268efd94 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -138,6 +138,7 @@ void node::update_node_id() m_id = generate_id(m_observer->external_address()); m_table.update_node_id(m_id); + m_rpc.update_node_id(m_id); } bool node::verify_token(std::string const& token, char const* info_hash From 6370d5bc812289b1de40052a785ce785d6856150 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 24 Jul 2016 23:37:03 -0400 Subject: [PATCH 3/6] deprecate lt_trackers extension (#940) deprecate lt_trackers extension --- ChangeLog | 1 + bindings/python/src/session.cpp | 4 +++- include/libtorrent/extensions/lt_trackers.hpp | 3 +++ simulation/test_swarm.cpp | 2 ++ simulation/test_trackers_extension.cpp | 8 +++++++- src/lt_trackers.cpp | 2 ++ 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a1ae48654..4f524c201 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 1.1.1 release + * deprecate lt_trackers extension * remove load_asnum_db and load_country_db from python bindings * fix crash in session::get_ip_filter when not having set one * fix filename escaping when repairing torrents with broken web seeds diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 42626f6b7..1363f02b6 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -17,8 +17,10 @@ #include #include // for sign_mutable_item +#ifndef TORRENT_NO_DEPRECATE #include #include +#endif #include #include #include @@ -88,9 +90,9 @@ namespace s.add_extension(create_ut_pex_plugin); else if (name == "smart_ban") s.add_extension(create_smart_ban_plugin); +#ifndef TORRENT_NO_DEPRECATE else if (name == "lt_trackers") s.add_extension(create_lt_trackers_plugin); -#ifndef TORRENT_NO_DEPRECATE else if (name == "metadata_transfer") s.add_extension(create_metadata_plugin); #endif // TORRENT_NO_DEPRECATE diff --git a/include/libtorrent/extensions/lt_trackers.hpp b/include/libtorrent/extensions/lt_trackers.hpp index 3e3e21be8..b97973e27 100644 --- a/include/libtorrent/extensions/lt_trackers.hpp +++ b/include/libtorrent/extensions/lt_trackers.hpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_LT_TRACKERS_HPP_INCLUDED #define TORRENT_LT_TRACKERS_HPP_INCLUDED +#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_DISABLE_EXTENSIONS #include "libtorrent/config.hpp" @@ -51,10 +52,12 @@ namespace libtorrent // constructor function for the trackers exchange extension. This can // either be passed in the add_torrent_params::extensions field, or // via torrent_handle::add_extension(). + TORRENT_DEPRECATED boost::shared_ptr TORRENT_EXPORT create_lt_trackers_plugin(torrent_handle const&, void*); } #endif // TORRENT_DISABLE_EXTENSIONS +#endif // TORRENT_NO_DEPRECATE #endif // TORRENT_LT_TRACKERS_HPP_INCLUDED diff --git a/simulation/test_swarm.cpp b/simulation/test_swarm.cpp index a7ca939aa..fc40f8021 100644 --- a/simulation/test_swarm.cpp +++ b/simulation/test_swarm.cpp @@ -308,6 +308,7 @@ TORRENT_TEST(stop_start_seed_graceful) test_stop_start_download(swarm_test::upload, true); } +#ifndef TORRENT_NO_DEPRECATE TORRENT_TEST(explicit_cache) { setup_swarm(2, swarm_test::download @@ -333,6 +334,7 @@ TORRENT_TEST(explicit_cache) return true; }); } +#endif TORRENT_TEST(shutdown) { diff --git a/simulation/test_trackers_extension.cpp b/simulation/test_trackers_extension.cpp index 10cf1eac1..0e639d989 100644 --- a/simulation/test_trackers_extension.cpp +++ b/simulation/test_trackers_extension.cpp @@ -30,6 +30,10 @@ POSSIBILITY OF SUCH DAMAGE. */ +#include "test.hpp" + +#ifndef TORRENT_NO_DEPRECATE + #include "setup_swarm.hpp" #include "libtorrent/alert.hpp" #include "libtorrent/announce_entry.hpp" @@ -38,7 +42,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert_types.hpp" #include "libtorrent/extensions/lt_trackers.hpp" #include "libtorrent/session.hpp" -#include "test.hpp" #include "settings.hpp" using namespace libtorrent; @@ -153,4 +156,7 @@ TORRENT_TEST(no_metadata) TEST_EQUAL(connected, true); } +#else +TORRENT_TEST(dummy) {} +#endif diff --git a/src/lt_trackers.cpp b/src/lt_trackers.cpp index e6f78781e..e019435c3 100644 --- a/src/lt_trackers.cpp +++ b/src/lt_trackers.cpp @@ -30,6 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. */ +#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_DISABLE_EXTENSIONS #include "libtorrent/aux_/disable_warnings_push.hpp" @@ -390,4 +391,5 @@ namespace libtorrent } #endif +#endif From 0ea449a7b531c261f1f8747ce84a2d4cecd65c15 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 25 Jul 2016 08:05:54 -0400 Subject: [PATCH 4/6] make local service discovery cookie support not so random numbers, to make the test reliable (#943) --- src/lsd.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lsd.cpp b/src/lsd.cpp index b1aaf3c52..a46e2a471 100644 --- a/src/lsd.cpp +++ b/src/lsd.cpp @@ -57,8 +57,8 @@ namespace libtorrent { namespace { -int render_lsd_packet(char* dst, int len, int listen_port - , char const* info_hash_hex, int m_cookie, char const* host) +int render_lsd_packet(char* dst, int const len, int const listen_port + , char const* info_hash_hex, int const cookie, char const* host) { TORRENT_ASSERT(len > 0); return snprintf(dst, len, @@ -67,7 +67,7 @@ int render_lsd_packet(char* dst, int len, int listen_port "Port: %d\r\n" "Infohash: %s\r\n" "cookie: %x\r\n" - "\r\n\r\n", host, listen_port, info_hash_hex, m_cookie); + "\r\n\r\n", host, listen_port, info_hash_hex, cookie); } } // anonymous namespace @@ -87,7 +87,7 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb , m_log_cb(log) #endif , m_broadcast_timer(ios) - , m_cookie(random() & 0x7fffffff) + , m_cookie((random() ^ boost::uintptr_t(this)) & 0x7fffffff) , m_disabled(false) #if TORRENT_USE_IPV6 , m_disabled6(false) @@ -128,8 +128,8 @@ void lsd::announce(sha1_hash const& ih, int listen_port, bool broadcast) announce_impl(ih, listen_port, broadcast, 0); } -void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast - , int retry_count) +void lsd::announce_impl(sha1_hash const& ih, int const listen_port + , bool const broadcast, int retry_count) { #if TORRENT_USE_IPV6 if (m_disabled && m_disabled6) return; @@ -148,7 +148,7 @@ void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast error_code ec; if (!m_disabled) { - int msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex + int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex , m_cookie, "239.192.152.143"); m_socket.send(msg, msg_len, ec, broadcast ? broadcast_socket::broadcast : 0); if (ec) @@ -164,7 +164,7 @@ void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast #if TORRENT_USE_IPV6 if (!m_disabled6) { - int msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex + int const msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex , m_cookie, "[ff15::efc0:988f]"); m_socket6.send(msg, msg_len, ec, broadcast ? broadcast_socket::broadcast : 0); if (ec) @@ -252,12 +252,12 @@ void lsd::on_announce(udp::endpoint const& from, char* buf { // we expect it to be hexadecimal // if it isn't, it's not our cookie anyway - boost::int32_t cookie = strtol(cookie_iter->second.c_str(), NULL, 16); + boost::int32_t const cookie = strtol(cookie_iter->second.c_str(), NULL, 16); if (cookie == m_cookie) { #ifndef TORRENT_DISABLE_LOGGING - debug_log("<== LSD: ignoring packet (cookie matched our own): %x == %x" - , cookie, m_cookie); + debug_log("<== LSD: ignoring packet (cookie matched our own): %x" + , cookie); #endif return; } From 6777ec5d0576b9ff77f897170b4d877c243adf39 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 26 Jul 2016 01:05:32 -0400 Subject: [PATCH 5/6] back-ported dbghlp fix (#946) back-ported dbghlp fix --- src/assert.cpp | 7 +++++++ test/main.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/assert.cpp b/src/assert.cpp index 46ce98803..f05965fc8 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -146,12 +146,19 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth) #include "windows.h" #include "libtorrent/utf8.hpp" +#include "libtorrent/thread.hpp" #include "winbase.h" #include "dbghelp.h" +static libtorrent::mutex dbghlp_mutex; + TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth) { + // all calls to DbgHlp.dll are thread-unsafe. i.e. they all need to be + // synchronized and not called concurrently. This mutex serializes access + libtorrent::mutex::scoped_lock l(dbghlp_mutex); + typedef USHORT (WINAPI *RtlCaptureStackBackTrace_t)( __in ULONG FramesToSkip, __in ULONG FramesToCapture, diff --git a/test/main.cpp b/test/main.cpp index 3f210aa53..678774e3d 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include // fot SetErrorMode #include // for _dup and _dup2 #include // for _getpid +#include #define dup _dup #define dup2 _dup2 @@ -224,6 +225,12 @@ EXPORT int main(int argc, char const* argv[]) | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); SetUnhandledExceptionFilter(&seh_exception_handler); + +#ifdef _DEBUG + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); +#endif + #endif #ifdef O_NONBLOCK From 48ca20968e66d73464e85cc0dca8b1fa8cebc7f5 Mon Sep 17 00:00:00 2001 From: terry zhao Date: Tue, 26 Jul 2016 13:13:28 +0800 Subject: [PATCH 6/6] fix value of current_tracker when all tracker failed (#932) fix torrent_status::current_tracker when all trackers fail. --- ChangeLog | 1 + src/torrent.cpp | 3 ++- test/test_tracker.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4f524c201..fcdc10f54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 1.1.1 release + * fix value of current_tracker when all tracker failed * deprecate lt_trackers extension * remove load_asnum_db and load_country_db from python bindings * fix crash in session::get_ip_filter when not having set one diff --git a/src/torrent.cpp b/src/torrent.cpp index 7218ddb5c..ffb611da4 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -12099,7 +12099,8 @@ namespace libtorrent std::vector::const_iterator i; for (i = m_trackers.begin(); i != m_trackers.end(); ++i) { - if (!i->updating) continue; + if (i->updating) continue; + if (!i->verified) continue; st->current_tracker = i->url; break; } diff --git a/test/test_tracker.cpp b/test/test_tracker.cpp index eead9c622..fb4f7fdc5 100644 --- a/test/test_tracker.cpp +++ b/test/test_tracker.cpp @@ -421,9 +421,16 @@ TORRENT_TEST(http_peers) addp.save_path = "tmp2_tracker"; torrent_handle h = s->add_torrent(addp); + libtorrent::torrent_status status = h.status(); + TEST_CHECK(status.current_tracker.empty()); + // wait to hit the tracker wait_for_alert(*s, tracker_reply_alert::alert_type, "s"); + status = h.status(); + TEST_CHECK(!status.current_tracker.empty()); + TEST_CHECK(status.current_tracker == tracker_url); + // we expect to have certain peers in our peer list now // these peers are hard coded in web_server.py std::vector peers; @@ -455,6 +462,61 @@ TORRENT_TEST(http_peers) fprintf(stderr, "done\n"); } +TORRENT_TEST(current_tracker) +{ + // use a invalid tracker port + int http_port = 39527; + + settings_pack pack = settings(); + pack.set_bool(settings_pack::announce_to_all_trackers, true); + pack.set_bool(settings_pack::announce_to_all_tiers, false); + pack.set_int(settings_pack::tracker_completion_timeout, 2); + pack.set_int(settings_pack::tracker_receive_timeout, 1); + pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:39775"); + //pack.set_int(settings_pack::alert_mask, alert::tracker_notification); + + boost::scoped_ptr s(new lt::session(pack)); + + error_code ec; + remove_all("tmp3_tracker", ec); + create_directory("tmp3_tracker", ec); + std::ofstream file(combine_path("tmp3_tracker", "temporary").c_str()); + boost::shared_ptr t = ::create_torrent(&file, "temporary", 16 * 1024, 13, false); + file.close(); + + char tracker_url[200]; + snprintf(tracker_url, sizeof(tracker_url), "http://127.0.0.1:%d/announce" + , http_port); + t->add_tracker(tracker_url, 0); + + add_torrent_params addp; + addp.flags &= ~add_torrent_params::flag_paused; + addp.flags &= ~add_torrent_params::flag_auto_managed; + addp.flags |= add_torrent_params::flag_seed_mode; + addp.ti = t; + addp.save_path = "tmp3_tracker"; + torrent_handle h = s->add_torrent(addp); + + libtorrent::torrent_status status = h.status(); + TEST_CHECK(status.current_tracker.empty()); + + // wait to hit the tracker announce + wait_for_alert(*s, tracker_announce_alert::alert_type, "s"); + + status = h.status(); + TEST_CHECK(status.current_tracker.empty()); + + // wait to hit the tracker error + wait_for_alert(*s, tracker_error_alert::alert_type, "s"); + + status = h.status(); + TEST_CHECK(status.current_tracker.empty()); + + fprintf(stderr, "destructing session\n"); + s.reset(); + fprintf(stderr, "done\n"); +} + void test_proxy(bool proxy_trackers) { int http_port = start_web_server();