add make_tcp() and make_udp() to convert endpoint types

This commit is contained in:
Arvid Norberg 2018-09-17 07:56:48 -07:00 committed by Arvid Norberg
parent c5b415b89f
commit 81356cfce1
4 changed files with 12 additions and 11 deletions

View File

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

View File

@ -773,7 +773,7 @@ entry write_nodes_entry(std::vector<node_entry> 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;
}

View File

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

View File

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