diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index 8ad12b3c3..1d157e771 100644 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -93,6 +93,12 @@ namespace libtorrent { using null_buffers = boost::asio::null_buffers; #endif + inline udp::endpoint make_udp(tcp::endpoint const ep) + { return {ep.address(), ep.port()}; } + + inline tcp::endpoint make_tcp(udp::endpoint const ep) + { return {ep.address(), ep.port()}; } + #ifdef TORRENT_WINDOWS #ifndef PROTECTION_LEVEL_UNRESTRICTED diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index db17cabd2..2f82e96b7 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -773,7 +773,7 @@ entry write_nodes_entry(std::vector const& nodes) for (auto const& n : nodes) { std::copy(n.id.begin(), n.id.end(), out); - detail::write_endpoint(udp::endpoint(n.addr(), std::uint16_t(n.port())), out); + detail::write_endpoint(n.ep(), out); } return r; } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index a410aee33..87cef88c9 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2104,11 +2104,6 @@ namespace aux { if (ep != EndpointType()) map_handle = m.add_mapping(protocol, ep.port(), ep); } - - tcp::endpoint to_tcp(udp::endpoint const& ep) - { - return tcp::endpoint(ep.address(), ep.port()); - } } void session_impl::remap_ports(remap_port_mask_t const mask @@ -2120,12 +2115,12 @@ namespace aux { if ((mask & remap_natpmp) && s.natpmp_mapper) { map_port(*s.natpmp_mapper, portmap_protocol::tcp, tcp_ep, s.tcp_port_mapping[0]); - map_port(*s.natpmp_mapper, portmap_protocol::udp, to_tcp(udp_ep), s.udp_port_mapping[0]); + map_port(*s.natpmp_mapper, portmap_protocol::udp, make_tcp(udp_ep), s.udp_port_mapping[0]); } if ((mask & remap_upnp) && m_upnp) { map_port(*m_upnp, portmap_protocol::tcp, tcp_ep, s.tcp_port_mapping[1]); - map_port(*m_upnp, portmap_protocol::udp, to_tcp(udp_ep), s.udp_port_mapping[1]); + map_port(*m_upnp, portmap_protocol::udp, make_tcp(udp_ep), s.udp_port_mapping[1]); } } diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index ddf2d3e95..635f8ed2c 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -132,7 +132,7 @@ namespace libtorrent { { // m_target failed. remove it from the endpoint list auto const i = std::find(m_endpoints.begin() - , m_endpoints.end(), tcp::endpoint(m_target.address(), m_target.port())); + , m_endpoints.end(), make_tcp(m_target)); if (i != m_endpoints.end()) m_endpoints.erase(i); @@ -154,7 +154,7 @@ namespace libtorrent { #endif // pick another target endpoint and try again - m_target = udp::endpoint(m_endpoints.front().address(), m_endpoints.front().port()); + m_target = make_udp(m_endpoints.front()); #ifndef TORRENT_DISABLE_LOGGING if (cb && cb->should_log()) @@ -252,7 +252,7 @@ namespace libtorrent { return; } - m_target = udp::endpoint(m_endpoints.front().address(), m_endpoints.front().port()); + m_target = make_udp(m_endpoints.front()); start_announce(); }