fix port mapping for SSL UDP socket
This commit is contained in:
parent
13e9eb6680
commit
cdfdbfd6aa
|
@ -335,7 +335,7 @@ namespace libtorrent
|
|||
, std::vector<address> const& addresses, int port);
|
||||
#endif
|
||||
|
||||
void maybe_update_udp_mapping(int nat, int local_port, int external_port);
|
||||
void maybe_update_udp_mapping(int nat, bool ssl, int local_port, int external_port);
|
||||
|
||||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||
torrent const* find_encrypted_torrent(
|
||||
|
|
|
@ -2062,7 +2062,26 @@ retry:
|
|||
}
|
||||
ec.clear();
|
||||
}
|
||||
// TODO: 3 port map SSL udp socket here
|
||||
else
|
||||
{
|
||||
maybe_update_udp_mapping(0, true, ssl_port, ssl_port);
|
||||
maybe_update_udp_mapping(1, true, ssl_port, ssl_port);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if there are mappings for the SSL socket, delete them now
|
||||
if (m_ssl_udp_mapping[0] != -1 && m_natpmp)
|
||||
{
|
||||
m_natpmp->delete_mapping(m_ssl_udp_mapping[0]);
|
||||
m_ssl_udp_mapping[0] = -1;
|
||||
}
|
||||
if (m_ssl_udp_mapping[1] != -1 && m_upnp)
|
||||
{
|
||||
m_upnp->delete_mapping(m_ssl_udp_mapping[1]);
|
||||
m_ssl_udp_mapping[1] = -1;
|
||||
}
|
||||
|
||||
}
|
||||
#endif // TORRENT_USE_OPENSSL
|
||||
|
||||
|
@ -2094,8 +2113,8 @@ retry:
|
|||
else
|
||||
{
|
||||
m_external_udp_port = m_udp_socket.local_port();
|
||||
maybe_update_udp_mapping(0, m_listen_interface.port(), m_listen_interface.port());
|
||||
maybe_update_udp_mapping(1, m_listen_interface.port(), m_listen_interface.port());
|
||||
maybe_update_udp_mapping(0, false, m_listen_interface.port(), m_listen_interface.port());
|
||||
maybe_update_udp_mapping(1, false, m_listen_interface.port(), m_listen_interface.port());
|
||||
}
|
||||
|
||||
// we made it! now post all the listen_succeeded_alerts
|
||||
|
@ -5869,38 +5888,39 @@ retry:
|
|||
|
||||
#endif
|
||||
|
||||
void session_impl::maybe_update_udp_mapping(int nat, int local_port, int external_port)
|
||||
void session_impl::maybe_update_udp_mapping(int nat, bool ssl, int local_port, int external_port)
|
||||
{
|
||||
int local, external, protocol;
|
||||
int* mapping = ssl ? m_ssl_udp_mapping : m_udp_mapping;
|
||||
if (nat == 0 && m_natpmp)
|
||||
{
|
||||
if (m_udp_mapping[nat] != -1)
|
||||
if (mapping[nat] != -1)
|
||||
{
|
||||
if (m_natpmp->get_mapping(m_udp_mapping[nat], local, external, protocol))
|
||||
if (m_natpmp->get_mapping(mapping[nat], local, external, protocol))
|
||||
{
|
||||
// we already have a mapping. If it's the same, don't do anything
|
||||
if (local == local_port && external == external_port && protocol == natpmp::udp)
|
||||
return;
|
||||
}
|
||||
m_natpmp->delete_mapping(m_udp_mapping[nat]);
|
||||
m_natpmp->delete_mapping(mapping[nat]);
|
||||
}
|
||||
m_udp_mapping[nat] = m_natpmp->add_mapping(natpmp::udp
|
||||
mapping[nat] = m_natpmp->add_mapping(natpmp::udp
|
||||
, local_port, external_port);
|
||||
return;
|
||||
}
|
||||
else if (nat == 1 && m_upnp)
|
||||
{
|
||||
if (m_udp_mapping[nat] != -1)
|
||||
if (mapping[nat] != -1)
|
||||
{
|
||||
if (m_upnp->get_mapping(m_udp_mapping[nat], local, external, protocol))
|
||||
if (m_upnp->get_mapping(mapping[nat], local, external, protocol))
|
||||
{
|
||||
// we already have a mapping. If it's the same, don't do anything
|
||||
if (local == local_port && external == external_port && protocol == natpmp::udp)
|
||||
return;
|
||||
}
|
||||
m_upnp->delete_mapping(m_udp_mapping[nat]);
|
||||
m_upnp->delete_mapping(mapping[nat]);
|
||||
}
|
||||
m_udp_mapping[nat] = m_upnp->add_mapping(upnp::udp
|
||||
mapping[nat] = m_upnp->add_mapping(upnp::udp
|
||||
, local_port, external_port);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue