From 247672820c20cfdb6387a317cec202d0a805d693 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sat, 9 Jun 2018 15:04:38 -0700 Subject: [PATCH] report transport version in NAT-PMP send/receive logs --- include/libtorrent/natpmp.hpp | 2 ++ src/natpmp.cpp | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/natpmp.hpp b/include/libtorrent/natpmp.hpp index a92b032fb..296c96ac8 100644 --- a/include/libtorrent/natpmp.hpp +++ b/include/libtorrent/natpmp.hpp @@ -120,6 +120,8 @@ private: version_pcp = 2, }; + static char const* version_to_string(protocol_version version); + // See RFC 6887 Section 19.2 enum pcp_opcode { diff --git a/src/natpmp.cpp b/src/natpmp.cpp index cabbec1b7..fd47dc1c0 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -125,6 +125,11 @@ error_code natpmp::from_result_code(int const version, int result) return errors::pcp_errors(result); } +char const* natpmp::version_to_string(protocol_version version) +{ + return version == version_natpmp ? "NAT-PMP" : "PCP"; +} + using namespace aux; using namespace std::placeholders; @@ -544,8 +549,9 @@ void natpmp::send_map_request(port_mapping_t const i) if (should_log()) { log("==> port map [ mapping: %d action: %s" - " proto: %s local: %u external: %u ttl: %u ]" + " transport: %s proto: %s local: %u external: %u ttl: %u ]" , static_cast(i), to_string(m.act) + , version_to_string(m_version) , to_string(m.protocol) , m.local_port, m.external_port, ttl); } @@ -677,6 +683,9 @@ void natpmp::on_reply(error_code const& e if (result == errors::pcp_unsupp_version) { +#ifndef TORRENT_DISABLE_LOGGING + log("unsupported version"); +#endif if (m_version == version_pcp && !is_v6(m_socket.local_endpoint())) { m_version = version_natpmp; @@ -765,7 +774,8 @@ void natpmp::on_reply(error_code const& e #ifndef TORRENT_DISABLE_LOGGING char msg[200]; int const num_chars = std::snprintf(msg, sizeof(msg), "<== port map [" - " protocol: %s local: %u external: %u ttl: %u ]" + " transport: %s protocol: %s local: %u external: %u ttl: %u ]" + , version_to_string(protocol_version(version)) , (protocol == portmap_protocol::udp ? "udp" : "tcp") , private_port, public_port, lifetime); #endif