From 04769d998619d59a99b9e25e0cf2c398e61547ef Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Tue, 11 Mar 2025 00:07:15 +0800 Subject: [PATCH] feat: support trackers with only old BEP-7 support (#7481) * feat: restore old BEP-7 query parameters * fix: treat failed tracker response as failure --- libtransmission/announcer-http.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libtransmission/announcer-http.cc b/libtransmission/announcer-http.cc index 9a89cdfe8..68de60a3b 100644 --- a/libtransmission/announcer-http.cc +++ b/libtransmission/announcer-http.cc @@ -122,6 +122,11 @@ bool handleAnnounceResponse(tr_web::FetchResponse const& web_response, tr_announ tr_announcerParseHttpAnnounceResponse(response, body, log_name); + if (!std::empty(response.errmsg)) + { + return false; + } + if (!std::empty(response.pex6)) { tr_logAddTrace(fmt::format("got a peers6 length of {}", std::size(response.pex6)), log_name); @@ -229,6 +234,22 @@ void announce_url_new(tr_urlbuf& url, tr_session const* session, tr_announce_req { fmt::format_to(out, "&trackerid={}", req.tracker_id); } + + if (auto ipv4_addr = session->global_address(TR_AF_INET); ipv4_addr) + { + auto buf = std::array{}; + auto const display_name = ipv4_addr->display_name(std::data(buf), std::size(buf)); + fmt::format_to(out, "&ipv4="); + tr_urlPercentEncode(out, display_name); + } + + if (auto ipv6_addr = session->global_address(TR_AF_INET6); ipv6_addr) + { + auto buf = std::array{}; + auto const display_name = ipv6_addr->display_name(std::data(buf), std::size(buf)); + fmt::format_to(out, "&ipv6="); + tr_urlPercentEncode(out, display_name); + } } [[nodiscard]] std::string format_ip_arg(std::string_view ip) @@ -255,8 +276,8 @@ void tr_tracker_http_announce( public address they want to use. We should ensure that we send the announce both via IPv6 and IPv4, - but no longer use the "ipv4=" and "ipv6=" parameters. So, we no - longer need to compute the global IPv4 and IPv6 addresses. + and to be safe we also add the "ipv4=" and "ipv6=" parameters, if + we already have them. */ auto url = tr_urlbuf{}; announce_url_new(url, session, request);