From cc792d86381a77b435a3f6ff4f28a27d95d55411 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 26 Feb 2020 09:04:37 +0100 Subject: [PATCH] improve error messages and error reporting of failing enum_routes() --- include/libtorrent/operations.hpp | 3 +++ src/alert.cpp | 4 +++- src/session_impl.cpp | 31 ++++++++++++++++++++++--------- src/string_util.cpp | 6 +++--- test/enum_if.cpp | 4 ++-- test/test_session_params.cpp | 6 ++++-- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/include/libtorrent/operations.hpp b/include/libtorrent/operations.hpp index 4847184e1..10a1644db 100644 --- a/include/libtorrent/operations.hpp +++ b/include/libtorrent/operations.hpp @@ -172,6 +172,9 @@ namespace libtorrent { // set socket option sock_option, + + // enumeration network routes + enum_route, }; // maps an operation id (from peer_error_alert and peer_disconnected_alert) diff --git a/src/alert.cpp b/src/alert.cpp index d5cd080b1..bc4d42eb5 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -897,6 +897,7 @@ namespace { case o::symlink: return -1; case o::handshake: return -1; case o::sock_option: return -1; + case o::enum_route: return -1; } return -1; } @@ -1564,7 +1565,8 @@ namespace { "hostname_lookup", "symlink", "handshake", - "sock_option" + "sock_option", + "enum_route" }; int const idx = static_cast(op); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 077b2e687..4340e7435 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1359,8 +1359,12 @@ namespace aux { #ifndef TORRENT_DISABLE_LOGGING if (should_log()) { - session_log("attempting to open listen socket to: %s on device: %s ssl: %x" - , print_endpoint(bind_ep).c_str(), lep.device.c_str(), static_cast(lep.ssl)); + session_log("attempting to open listen socket to: %s on device: %s %s%s%s%s" + , print_endpoint(bind_ep).c_str(), lep.device.c_str() + , (lep.ssl == transport::ssl) ? "ssl " : "" + , (lep.flags & listen_socket_t::has_gateway) ? "has-gateway " : "" + , (lep.flags & listen_socket_t::accept_incoming) ? "accept-incoming " : "no-incoming " + , (lep.flags & listen_socket_t::was_expanded) ? "expanded-ip " : ""); } #endif @@ -1806,6 +1810,20 @@ namespace aux { ? listen_socket_flags_t{} : listen_socket_t::accept_incoming; + std::vector const ifs = enum_net_interfaces(m_io_service, ec); + if (ec && m_alerts.should_post()) + { + m_alerts.emplace_alert("" + , operation_t::enum_if, ec, socket_type_t::tcp); + } + auto const routes = enum_routes(m_io_service, ec); + if (ec && m_alerts.should_post()) + { + m_alerts.emplace_alert("" + , operation_t::enum_route, ec, socket_type_t::tcp); + } + + // expand device names and populate eps for (auto const& iface : m_listen_interfaces) { std::string const& device = iface.device; @@ -1847,13 +1865,8 @@ namespace aux { , listen_socket_flags_t{}); } - std::vector const ifs = enum_net_interfaces(m_io_service, ec); - if (!ec) - { - expand_unspecified_address(ifs, eps); - auto const routes = enum_routes(m_io_service, ec); - if (!ec) expand_devices(ifs, routes, eps); - } + expand_unspecified_address(ifs, eps); + expand_devices(ifs, routes, eps); auto remove_iter = partition_listen_sockets(eps, m_listen_sockets); diff --git a/src/string_util.cpp b/src/string_util.cpp index f2b750940..215459fbd 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -278,9 +278,9 @@ namespace libtorrent { return out; } - // this parses the string that's used as the listen_interfaces setting. - // it is a comma-separated list of IP or device names with ports. For - // example: "eth0:6881,eth1:6881" or "127.0.0.1:6881" + // this parses the string that's used as the dht_bootstrap setting. + // it is a comma-separated list of IP or hostnames with ports. For + // example: "router.bittorrent.com:6881,router.utorrent.com:6881" or "127.0.0.1:6881" void parse_comma_separated_string_port(std::string const& in , std::vector>& out) { diff --git a/test/enum_if.cpp b/test/enum_if.cpp index 481343045..00e407253 100644 --- a/test/enum_if.cpp +++ b/test/enum_if.cpp @@ -46,7 +46,7 @@ int main() auto const routes = enum_routes(ios, ec); if (ec) { - std::printf("%s\n", ec.message().c_str()); + std::printf("enum_routes: %s\n", ec.message().c_str()); return 1; } @@ -68,7 +68,7 @@ int main() auto const net = enum_net_interfaces(ios, ec); if (ec) { - std::printf("%s\n", ec.message().c_str()); + std::printf("enum_ifs: %s\n", ec.message().c_str()); return 1; } diff --git a/test/test_session_params.cpp b/test/test_session_params.cpp index 986560a1b..5ce83e1cb 100644 --- a/test/test_session_params.cpp +++ b/test/test_session_params.cpp @@ -142,8 +142,10 @@ TORRENT_TEST(dht_state) TEST_EQUAL(params1.dht_state.nids.size(), 1); - // not a chance the nid will be the fake initial ones - TEST_CHECK(params1.dht_state.nids[0].second != s.nids[0].second); + if (params1.dht_state.nids.size() >= 1) { + // not a chance the nid will be the fake initial ones + TEST_CHECK(params1.dht_state.nids[0].second != s.nids[0].second); + } } #endif