Skip to content

Commit

Permalink
announce port=1 instead of port=0, when there is no listen port
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Mar 8, 2020
1 parent 9469913 commit eaa18ff
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* announce port=1 instead of port=0, when there is no listen port
* fix LSD over IPv6
* support TCP_NOTSENT_LOWAT on Linux
* fix correct interface binding of local service discovery multicast
Expand Down
2 changes: 1 addition & 1 deletion simulation/test_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void test_ipv6_support(char const* listen_interfaces

// if we're not listening we'll just report port 0
std::string const expect_port = (listen_interfaces && listen_interfaces == ""_sv)
? "&port=0" : "&port=6881";
? "&port=1" : "&port=6881";

http_v4.register_handler("/announce"
, [&v4_announces,expect_port](std::string method, std::string req
Expand Down
2 changes: 1 addition & 1 deletion src/http_tracker_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace libtorrent {
, escape_string({tracker_req().pid.data(), 20}).c_str()
// the i2p tracker seems to verify that the port is not 0,
// even though it ignores it otherwise
, i2p ? 1 : tracker_req().listen_port
, tracker_req().listen_port
, tracker_req().uploaded
, tracker_req().downloaded
, tracker_req().left
Expand Down
20 changes: 16 additions & 4 deletions src/session_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,12 @@ namespace aux {
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
, std::weak_ptr<request_callback> c)
{
Expand All @@ -1116,11 +1122,14 @@ namespace aux {
auto ls = req.outgoing_socket.get();

req.listen_port =
#if TORRENT_USE_I2P
(req.kind == tracker_request::i2p) ? 1 :
#endif
#ifdef TORRENT_USE_OPENSSL
// SSL torrents use the SSL listen port
use_ssl ? ssl_listen_port(ls) :
use_ssl ? make_announce_port(ssl_listen_port(ls)) :
#endif
listen_port(ls);
make_announce_port(listen_port(ls));
m_tracker_manager.queue_request(get_io_service(), std::move(req), c);
}
else
Expand All @@ -1133,11 +1142,14 @@ namespace aux {
#endif
tracker_request socket_req(req);
socket_req.listen_port =
#if TORRENT_USE_I2P
(req.kind == tracker_request::i2p) ? 1 :
#endif
#ifdef TORRENT_USE_OPENSSL
// 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
listen_port(ls.get());
make_announce_port(listen_port(ls.get()));

socket_req.outgoing_socket = ls;
m_tracker_manager.queue_request(get_io_service(), std::move(socket_req), c);
Expand Down

0 comments on commit eaa18ff

Please sign in to comment.