fix binding TCP and UDP sockets to the same port, when specifying port 0

This commit is contained in:
arvidn 2020-02-05 18:01:38 +01:00 committed by Arvid Norberg
parent b4cda2989e
commit 3092b7ca44
4 changed files with 50 additions and 1 deletions

View File

@ -1,5 +1,6 @@
1.2.4 release
* fix binding TCP and UDP sockets to the same port, when specifying port 0
* fix announce_to_all_trackers and announce_to_all_tiers behavior
* fix suggest_read_cache setting
* back-off tracker hostname looksups resulting in NXDOMAIN

@ -1 +1 @@
Subproject commit ba65f2fc25cb0cf6ab141102952b9c5c54f02c41
Subproject commit 3e4a9fc7a5971104154d11a361139043029435c5

View File

@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "simulator/utils.hpp" // for timer
#include "settings.hpp"
#include "create_torrent.hpp"
#include "setup_transfer.hpp" // for addr()
using namespace lt;
@ -175,3 +176,48 @@ TORRENT_TEST(add_extension_while_transfer)
TEST_CHECK(p->m_files_checked);
}
#endif // TORRENT_DISABLE_EXTENSIONS
// make sure TCP and UDP listen sockets use the same port
TORRENT_TEST(tie_listen_ports)
{
using namespace libtorrent;
sim::default_config network_cfg;
sim::simulation sim{network_cfg};
sim::asio::io_service ios { sim, addr("50.0.0.1")};
lt::session_proxy zombie;
// create session
auto pack = settings();
pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:0");
pack.set_int(settings_pack::alert_mask, alert::error_notification
| alert::status_notification
| alert::torrent_log_notification);
auto ses = std::make_shared<lt::session>(pack, ios);
std::vector<int> listen_ports;
// only monitor alerts for session 0 (the downloader)
print_alerts(*ses, [&](lt::session&, lt::alert const* a){
if (auto const* la = alert_cast<listen_succeeded_alert>(a))
{
listen_ports.push_back(la->port);
}
});
sim::timer t(sim, lt::seconds(30), [&](boost::system::error_code const&)
{
// TEST
zombie = ses->abort();
ses.reset();
TEST_CHECK(listen_ports.size() > 0);
int const port = listen_ports.front();
for (int const p : listen_ports)
TEST_EQUAL(p, port);
});
sim.run();
}

View File

@ -1549,6 +1549,8 @@ namespace aux {
TORRENT_ASSERT(ret->local_endpoint.port() == bind_ep.port()
|| bind_ep.port() == 0);
if (bind_ep.port() == 0) bind_ep = ret->local_endpoint;
ret->sock->listen(m_settings.get_int(settings_pack::listen_queue_size), ec);
last_op = operation_t::sock_listen;