announce port=1 instead of port=0, when there is no listen port

This commit is contained in:
arvidn 2020-03-07 16:12:30 +01:00 committed by Arvid Norberg
parent 9469913cb2
commit eaa18ff7a1
4 changed files with 19 additions and 6 deletions

View File

@ -1,3 +1,4 @@
* announce port=1 instead of port=0, when there is no listen port
* fix LSD over IPv6 * fix LSD over IPv6
* support TCP_NOTSENT_LOWAT on Linux * support TCP_NOTSENT_LOWAT on Linux
* fix correct interface binding of local service discovery multicast * fix correct interface binding of local service discovery multicast

View File

@ -353,7 +353,7 @@ void test_ipv6_support(char const* listen_interfaces
// if we're not listening we'll just report port 0 // if we're not listening we'll just report port 0
std::string const expect_port = (listen_interfaces && listen_interfaces == ""_sv) std::string const expect_port = (listen_interfaces && listen_interfaces == ""_sv)
? "&port=0" : "&port=6881"; ? "&port=1" : "&port=6881";
http_v4.register_handler("/announce" http_v4.register_handler("/announce"
, [&v4_announces,expect_port](std::string method, std::string req , [&v4_announces,expect_port](std::string method, std::string req

View File

@ -121,7 +121,7 @@ namespace libtorrent {
, escape_string({tracker_req().pid.data(), 20}).c_str() , escape_string({tracker_req().pid.data(), 20}).c_str()
// the i2p tracker seems to verify that the port is not 0, // the i2p tracker seems to verify that the port is not 0,
// even though it ignores it otherwise // even though it ignores it otherwise
, i2p ? 1 : tracker_req().listen_port , tracker_req().listen_port
, tracker_req().uploaded , tracker_req().uploaded
, tracker_req().downloaded , tracker_req().downloaded
, tracker_req().left , tracker_req().left

View File

@ -1095,6 +1095,12 @@ namespace aux {
return ret; return ret;
} }
namespace {
std::uint16_t make_announce_port(std::uint16_t const p)
{ return p == 0 ? 1 : p; }
}
void session_impl::queue_tracker_request(tracker_request&& req void session_impl::queue_tracker_request(tracker_request&& req
, std::weak_ptr<request_callback> c) , std::weak_ptr<request_callback> c)
{ {
@ -1116,11 +1122,14 @@ namespace aux {
auto ls = req.outgoing_socket.get(); auto ls = req.outgoing_socket.get();
req.listen_port = req.listen_port =
#if TORRENT_USE_I2P
(req.kind == tracker_request::i2p) ? 1 :
#endif
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
// SSL torrents use the SSL listen port // SSL torrents use the SSL listen port
use_ssl ? ssl_listen_port(ls) : use_ssl ? make_announce_port(ssl_listen_port(ls)) :
#endif #endif
listen_port(ls); make_announce_port(listen_port(ls));
m_tracker_manager.queue_request(get_io_service(), std::move(req), c); m_tracker_manager.queue_request(get_io_service(), std::move(req), c);
} }
else else
@ -1133,11 +1142,14 @@ namespace aux {
#endif #endif
tracker_request socket_req(req); tracker_request socket_req(req);
socket_req.listen_port = socket_req.listen_port =
#if TORRENT_USE_I2P
(req.kind == tracker_request::i2p) ? 1 :
#endif
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
// SSL torrents use the SSL listen port // SSL torrents use the SSL listen port
use_ssl ? ssl_listen_port(ls.get()) : use_ssl ? make_announce_port(ssl_listen_port(ls.get())) :
#endif #endif
listen_port(ls.get()); make_announce_port(listen_port(ls.get()));
socket_req.outgoing_socket = ls; socket_req.outgoing_socket = ls;
m_tracker_manager.queue_request(get_io_service(), std::move(socket_req), c); m_tracker_manager.queue_request(get_io_service(), std::move(socket_req), c);