only post listen_succeeded_alert once all sockets have succeeded, since we may re-open previously successful ones if a later one fails

This commit is contained in:
arvidn 2015-09-05 20:58:15 -04:00
parent d7c6a3b3ea
commit 43ee75ce02
3 changed files with 47 additions and 19 deletions

@ -1 +1 @@
Subproject commit 5924e3b17eb0bdd710027187ccd2952422b25a39 Subproject commit c82420cd1b6a83a028f51eeff6d19828136b466c

View File

@ -1756,11 +1756,6 @@ namespace aux {
} }
} }
if (m_alerts.should_post<listen_succeeded_alert>())
m_alerts.emplace_alert<listen_succeeded_alert>(tcp::endpoint(bind_ip, port)
, (flags & open_ssl_socket) ? listen_succeeded_alert::tcp_ssl
: listen_succeeded_alert::tcp);
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
session_log(" listening on: %s external port: %d" session_log(" listening on: %s external port: %d"
, print_endpoint(tcp::endpoint(bind_ip, port)).c_str(), ret.external_port); , print_endpoint(tcp::endpoint(bind_ip, port)).c_str(), ret.external_port);
@ -1966,12 +1961,11 @@ retry:
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
int ssl_port = m_settings.get_int(settings_pack::ssl_listen); int ssl_port = m_settings.get_int(settings_pack::ssl_listen);
udp::endpoint ssl_bind_if(m_listen_interface.address(), ssl_port);
// if ssl port is 0, we don't want to listen on an SSL port // if ssl port is 0, we don't want to listen on an SSL port
if (ssl_port != 0) if (ssl_port != 0)
{ {
udp::endpoint ssl_bind_if(m_listen_interface.address(), ssl_port);
// TODO: 2 use bind_to_device in udp_socket // TODO: 2 use bind_to_device in udp_socket
m_ssl_udp_socket.bind(ssl_bind_if, ec); m_ssl_udp_socket.bind(ssl_bind_if, ec);
if (ec) if (ec)
@ -1988,18 +1982,13 @@ retry:
} }
ec.clear(); ec.clear();
} }
else // TODO: 3 port map SSL udp socket here
{
if (m_alerts.should_post<listen_succeeded_alert>())
m_alerts.emplace_alert<listen_succeeded_alert>(
tcp::endpoint(ssl_bind_if.address(), ssl_bind_if.port())
, listen_succeeded_alert::utp_ssl);
}
} }
#endif // TORRENT_USE_OPENSSL #endif // TORRENT_USE_OPENSSL
// TODO: 2 use bind_to_device in udp_socket // TODO: 2 use bind_to_device in udp_socket
m_udp_socket.bind(udp::endpoint(m_listen_interface.address(), m_listen_interface.port()), ec); m_udp_socket.bind(udp::endpoint(m_listen_interface.address()
, m_listen_interface.port()), ec);
if (ec) if (ec)
{ {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
@ -2025,8 +2014,41 @@ retry:
m_external_udp_port = m_udp_socket.local_port(); 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(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(1, m_listen_interface.port(), m_listen_interface.port());
}
// we made it! now post all the listen_succeeded_alerts
for (std::list<listen_socket_t>::iterator i = m_listen_sockets.begin()
, end(m_listen_sockets.end()); i != end; ++i)
{
listen_succeeded_alert::socket_type_t socket_type = i->ssl
? listen_succeeded_alert::tcp_ssl
: listen_succeeded_alert::tcp;
if (!m_alerts.should_post<listen_succeeded_alert>()) continue;
error_code err;
tcp::endpoint bind_ep = i->sock->local_endpoint(err);
if (err) continue;
m_alerts.emplace_alert<listen_succeeded_alert>(bind_ep, socket_type);
}
#ifdef TORRENT_USE_OPENSSL
if (m_ssl_udp_socket.is_open())
{
if (m_alerts.should_post<listen_succeeded_alert>()) if (m_alerts.should_post<listen_succeeded_alert>())
m_alerts.emplace_alert<listen_succeeded_alert>(m_listen_interface, listen_succeeded_alert::udp); m_alerts.emplace_alert<listen_succeeded_alert>(
tcp::endpoint(ssl_bind_if.address(), ssl_bind_if.port())
, listen_succeeded_alert::utp_ssl);
}
#endif
if (m_udp_socket.is_open())
{
if (m_alerts.should_post<listen_succeeded_alert>())
m_alerts.emplace_alert<listen_succeeded_alert>(m_listen_interface
, listen_succeeded_alert::udp);
} }
if (m_settings.get_int(settings_pack::peer_tos) != 0) if (m_settings.get_int(settings_pack::peer_tos) != 0)

View File

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alert_types.hpp" #include "libtorrent/alert_types.hpp"
#include "libtorrent/thread.hpp" #include "libtorrent/thread.hpp"
#include "libtorrent/file.hpp" #include "libtorrent/file.hpp"
#include "libtorrent/session_status.hpp"
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
@ -137,7 +138,7 @@ void test_ssl(int test_idx, bool use_utp)
sett.set_bool(settings_pack::enable_lsd, false); sett.set_bool(settings_pack::enable_lsd, false);
sett.set_bool(settings_pack::enable_upnp, false); sett.set_bool(settings_pack::enable_upnp, false);
sett.set_bool(settings_pack::enable_natpmp, false); sett.set_bool(settings_pack::enable_natpmp, false);
// if a pwer fails once, don't try it again // if a peer fails once, don't try it again
sett.set_int(settings_pack::max_failcount, 1); sett.set_int(settings_pack::max_failcount, 1);
sett.set_int(settings_pack::ssl_listen, ssl_port); sett.set_int(settings_pack::ssl_listen, ssl_port);
@ -194,7 +195,12 @@ void test_ssl(int test_idx, bool use_utp)
// make sure they've taken effect // make sure they've taken effect
if (test.downloader_has_cert || test.seed_has_cert) if (test.downloader_has_cert || test.seed_has_cert)
test_sleep(500); {
// this will cause a round-trip to the main thread, and make sure the
// previous async. calls have completed
ses1.status();
ses2.status();
}
// connect the peers after setting the certificates // connect the peers after setting the certificates
int port = 0; int port = 0;