improve error messages and error reporting of failing enum_routes()

This commit is contained in:
arvidn 2020-02-26 09:04:37 +01:00 committed by Arvid Norberg
parent 8dbb7c4232
commit cc792d8638
6 changed files with 37 additions and 17 deletions

View File

@ -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)

View File

@ -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<int>(op);

View File

@ -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<int>(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<ip_interface> const ifs = enum_net_interfaces(m_io_service, ec);
if (ec && m_alerts.should_post<listen_failed_alert>())
{
m_alerts.emplace_alert<listen_failed_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<listen_failed_alert>())
{
m_alerts.emplace_alert<listen_failed_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<ip_interface> 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);

View File

@ -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<std::pair<std::string, int>>& out)
{

View File

@ -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;
}

View File

@ -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