diff --git a/simulation/setup_dht.cpp b/simulation/setup_dht.cpp index 43340b49e..f3fb31ad0 100644 --- a/simulation/setup_dht.cpp +++ b/simulation/setup_dht.cpp @@ -99,6 +99,7 @@ struct dht_node final : lt::dht::udp_socket_interface , m_add_dead_nodes(flags & dht_network::add_dead_nodes) , m_ipv6(flags & dht_network::bind_ipv6) { + m_dht_storage->update_node_ids({id_from_addr(m_io_service.get_ips().front())}); error_code ec; sock().open(m_ipv6 ? asio::ip::udp::v6() : asio::ip::udp::v4()); sock().bind(asio::ip::udp::endpoint( diff --git a/simulation/setup_swarm.cpp b/simulation/setup_swarm.cpp index 2776f9ac1..38ed47554 100644 --- a/simulation/setup_swarm.cpp +++ b/simulation/setup_swarm.cpp @@ -152,6 +152,30 @@ int completed_pieces(lt::session& ses) return h.status().num_pieces; } +namespace { +bool should_print(lt::alert* a) +{ + using namespace libtorrent; + +#ifndef TORRENT_DISABLE_LOGGING + if (auto pla = alert_cast(a)) + { + if (pla->direction != peer_log_alert::incoming_message + && pla->direction != peer_log_alert::outgoing_message) + return false; + } +#endif + if (alert_cast(a) + || alert_cast(a) + || alert_cast(a) + || alert_cast(a)) + { + return false; + } + return true; +} +} + void utp_only(lt::settings_pack& p) { using namespace libtorrent; @@ -327,10 +351,14 @@ void setup_swarm(int num_nodes // only print alerts from the session under test lt::time_duration d = a->timestamp() - start_time; - boost::uint32_t millis = lt::duration_cast(d).count(); - std::printf("%4d.%03d: %-25s %s\n", millis / 1000, millis % 1000 - , a->what() - , a->message().c_str()); + boost::uint32_t const millis = lt::duration_cast(d).count(); + + if (should_print(a)) + { + std::printf("%4d.%03d: %-25s %s\n", millis / 1000, millis % 1000 + , a->what() + , a->message().c_str()); + } // if a torrent was added save the torrent handle if (lt::add_torrent_alert* at = lt::alert_cast(a)) diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 890f061a5..c66c49c7c 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -3264,12 +3264,14 @@ namespace libtorrent abort_jobs(); + TORRENT_ASSERT(m_magic == 0x1337); + // release the io_service to allow the run() call to return // we do this once we stop posting new callbacks to it. COMPLETE_ASYNC("disk_io_thread::work"); w.reset(); - - TORRENT_ASSERT(m_magic == 0x1337); + // at this point, the disk_io_thread object may have been destructed. + // the call to w.reset() above is what synchronizes with the main thread } void disk_io_thread::abort_jobs() diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 145b803e9..57f99aae4 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -507,7 +507,12 @@ namespace aux { TORRENT_ASSERT(is_single_thread()); #ifndef TORRENT_DISABLE_LOGGING - if (m_alerts.should_post()) + // this alert is a bit special. Since it's so verbose it's not only + // filtered by its own alert type (log_alert) but also whether session + // stats alerts are actually enabled. Without session_stats alerts the + // headers aren't very useful anyway + if (m_alerts.should_post() + && m_alerts.should_post()) { session_log(" *** session thread init"); diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index adcb5af81..28157346f 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -109,7 +109,7 @@ sha1_hash rand_hash() address rand_v6() { address_v6::bytes_type bytes; - for (int i = 0; i < int(bytes.size()); ++i) bytes[i] = rand(); + for (int i = 0; i < int(bytes.size()); ++i) bytes[i] = lt::random(); return address_v6(bytes); } #endif @@ -149,7 +149,27 @@ std::map get_counters(libtorrent::session& s) ret[metrics[i].name] = sa->values[metrics[i].value_index]; return ret; } - +namespace { +bool should_print(lt::alert* a) +{ +#ifndef TORRENT_DISABLE_LOGGING + if (auto pla = alert_cast(a)) + { + if (pla->direction != peer_log_alert::incoming_message + && pla->direction != peer_log_alert::outgoing_message) + return false; + } +#endif + if (alert_cast(a) + || alert_cast(a) + || alert_cast(a) + || alert_cast(a)) + { + return false; + } + return true; +} +} alert const* wait_for_alert(lt::session& ses, int type, char const* name) { time_point end = libtorrent::clock_type::now() + seconds(10); @@ -166,8 +186,11 @@ alert const* wait_for_alert(lt::session& ses, int type, char const* name) for (std::vector::iterator i = alerts.begin() , end(alerts.end()); i != end; ++i) { - std::fprintf(stderr, "%s: %s: [%s] %s\n", time_now_string(), name - , (*i)->what(), (*i)->message().c_str()); + if (should_print(*i)) + { + std::fprintf(stderr, "%s: %s: [%s] %s\n", time_now_string(), name + , (*i)->what(), (*i)->message().c_str()); + } if ((*i)->type() == type && !ret) { ret = *i; @@ -278,9 +301,7 @@ bool print_alerts(lt::session& ses, char const* name { std::fprintf(stderr, "%s: %s: [%s] (%s): %s\n", time_now_string(), name, (*i)->what(), print_endpoint(p->ip).c_str(), p->message().c_str()); } - else if ((*i)->message() != "block downloading" - && (*i)->message() != "block finished" - && (*i)->message() != "piece finished" + else if (should_print(*i) && !no_output) { std::fprintf(stderr, "%s: %s: [%s] %s\n", time_now_string(), name, (*i)->what(), (*i)->message().c_str()); @@ -591,7 +612,7 @@ boost::shared_ptr clone_ptr(boost::shared_ptr const& ptr) } unsigned char random_byte() -{ return std::rand() & 0xff; } +{ return lt::random() & 0xff; } void create_random_files(std::string const& path, const int file_sizes[], int num_files) { diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 8af344107..ada236e6c 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -509,6 +509,7 @@ void do_test_dht(address(&rand_addr)()) obs observer; counters cnt; std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); + dht_storage->update_node_ids({node_id(0)}); udp::endpoint source(rand_addr(), 20); std::map nodes; dht::node node(source.protocol(), &s, sett @@ -1427,7 +1428,8 @@ void do_test_dht(address(&rand_addr)()) do { std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); - dht::node node(udp::v4(), &s, sett, (node_id::min)(), &observer, cnt, nodes, *dht_storage); + dht_storage->update_node_ids({node_id::min()}); + dht::node node(udp::v4(), &s, sett, node_id::min(), &observer, cnt, nodes, *dht_storage); udp::endpoint initial_node(address_v4::from_string("4.4.4.4"), 1234); std::vector nodesv; @@ -1499,8 +1501,9 @@ void do_test_dht(address(&rand_addr)()) do { std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); + dht_storage->update_node_ids({node_id::min()}); dht::node_id target = to_hash("1234876923549721020394873245098347598635"); - dht::node node(udp::v4(), &s, sett, (node_id::min)(), &observer, cnt, nodes, *dht_storage); + dht::node node(udp::v4(), &s, sett, node_id::min(), &observer, cnt, nodes, *dht_storage); udp::endpoint initial_node(address_v4::from_string("4.4.4.4"), 1234); node.m_table.add_node(initial_node); @@ -1596,7 +1599,8 @@ void do_test_dht(address(&rand_addr)()) do { std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); - dht::node node(udp::v4(), &s, sett, (node_id::min)(), &observer, cnt, nodes, *dht_storage); + dht_storage->update_node_ids({node_id::min()}); + dht::node node(udp::v4(), &s, sett, node_id::min(), &observer, cnt, nodes, *dht_storage); udp::endpoint initial_node(address_v4::from_string("4.4.4.4"), 1234); node.m_table.add_node(initial_node); @@ -1643,7 +1647,8 @@ void do_test_dht(address(&rand_addr)()) do { std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); - dht::node node(udp::v4(), &s, sett, (node_id::min)(), &observer, cnt, nodes, *dht_storage); + dht_storage->update_node_ids({node_id::min()}); + dht::node node(udp::v4(), &s, sett, node_id::min(), &observer, cnt, nodes, *dht_storage); udp::endpoint initial_node(address_v4::from_string("4.4.4.4"), 1234); node.m_table.add_node(initial_node); @@ -1731,7 +1736,8 @@ void do_test_dht(address(&rand_addr)()) int old_branching = sett.search_branching; sett.search_branching = 8; std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); - dht::node node(udp::v4(), &s, sett, (node_id::min)(), &observer, cnt, nodes, *dht_storage); + dht_storage->update_node_ids({node_id::min()}); + dht::node node(udp::v4(), &s, sett, node_id::min(), &observer, cnt, nodes, *dht_storage); enum { num_test_nodes = 8 }; node_entry nodes[num_test_nodes] = { node_entry(items[0].target, udp::endpoint(address_v4::from_string("1.1.1.1"), 1231)) @@ -1832,7 +1838,8 @@ void do_test_dht(address(&rand_addr)()) int old_branching = sett.search_branching; sett.search_branching = 8; std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); - dht::node node(udp::v4(), &s, sett, (node_id::min)(), &observer, cnt, nodes, *dht_storage); + dht_storage->update_node_ids({node_id::min()}); + dht::node node(udp::v4(), &s, sett, node_id::min(), &observer, cnt, nodes, *dht_storage); enum { num_test_nodes = 8 }; node_entry nodes[num_test_nodes] = { node_entry(items[0].target, udp::endpoint(address_v4::from_string("1.1.1.1"), 1231)) @@ -1935,7 +1942,8 @@ void do_test_dht(address(&rand_addr)()) int old_branching = sett.search_branching; sett.search_branching = 8; std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); - dht::node node(udp::v4(), &s, sett, (node_id::min)(), &observer, cnt, nodes, *dht_storage); + dht_storage->update_node_ids({node_id::min()}); + dht::node node(udp::v4(), &s, sett, node_id::min(), &observer, cnt, nodes, *dht_storage); sha1_hash target = hasher(public_key, item_pk_len).final(); enum { num_test_nodes = 9 }; // we need K + 1 nodes to create the failing sequence node_entry nodes[num_test_nodes] = @@ -2032,6 +2040,7 @@ TORRENT_TEST(dht_dual_stack) counters cnt; std::map nodes; std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); + dht_storage->update_node_ids({node_id(0)}); dht::node node4(udp::v4(), &s, sett, node_id(0), &observer, cnt, nodes, *dht_storage); dht::node node6(udp::v6(), &s, sett, node_id(0), &observer, cnt, nodes, *dht_storage); nodes.insert(std::make_pair("n4", &node4)); @@ -2493,6 +2502,7 @@ TORRENT_TEST(read_only_node) std::map nodes; std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); + dht_storage->update_node_ids({node_id(0)}); dht::node node(udp::v4(), &s, sett, node_id(0), &observer, cnt, nodes, *dht_storage); udp::endpoint source(address::from_string("10.0.0.1"), 20); bdecode_node response; @@ -2583,6 +2593,7 @@ TORRENT_TEST(invalid_error_msg) std::map nodes; std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); + dht_storage->update_node_ids({node_id(0)}); dht::node node(udp::v4(), &s, sett, node_id(0), &observer, cnt, nodes, *dht_storage); udp::endpoint source(address::from_string("10.0.0.1"), 20); @@ -2624,6 +2635,7 @@ TORRENT_TEST(rpc_invalid_error_msg) dht::routing_table table(node_id(), udp::v4(), 8, sett, &observer); dht::rpc_manager rpc(node_id(), sett, table, &s, &observer); std::unique_ptr dht_storage(dht_default_storage_constructor(sett)); + dht_storage->update_node_ids({node_id(0)}); dht::node node(udp::v4(), &s, sett, node_id(0), &observer, cnt, nodes, *dht_storage); udp::endpoint source(address::from_string("10.0.0.1"), 20);