diff --git a/libtransmission/announcer-http.cc b/libtransmission/announcer-http.cc index 63c60d274..c6b1b0fa5 100644 --- a/libtransmission/announcer-http.cc +++ b/libtransmission/announcer-http.cc @@ -118,7 +118,7 @@ bool handleAnnounceResponse(tr_web::FetchResponse const& web_response, tr_announ if (status != HTTP_OK) { auto const* const response_str = tr_webGetResponseStr(status); - response->errmsg = fmt::format(FMT_STRING("Tracker HTTP response {:d} ({:s}"), status, response_str); + response->errmsg = fmt::format(FMT_STRING("Tracker HTTP response {:d} ({:s})"), status, response_str); return false; } diff --git a/libtransmission/announcer.cc b/libtransmission/announcer.cc index 1c9d60f61..ef71ebbbb 100644 --- a/libtransmission/announcer.cc +++ b/libtransmission/announcer.cc @@ -856,8 +856,10 @@ void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e) { using namespace announce_helpers; - /* increment the error count */ auto* current_tracker = tier->currentTracker(); + std::string announce_url = current_tracker != nullptr ? tr_urlTrackerLogName(current_tracker->announce_url) : "nullptr"; + + /* increment the error count */ if (current_tracker != nullptr) { ++current_tracker->consecutive_failures; @@ -871,12 +873,14 @@ void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e) if (isUnregistered(err)) { - tr_logAddErrorTier(tier, fmt::format(_("Announce error: {error}"), fmt::arg("error", err))); + tr_logAddErrorTier( + tier, + fmt::format(_("Announce error: {error}"), fmt::arg("error", err)).append(fmt::format(" ({})", announce_url))); } else { /* schedule a reannounce */ - int const interval = current_tracker->getRetryInterval(); + auto const interval = current_tracker->getRetryInterval(); tr_logAddWarnTier( tier, fmt::format( @@ -885,7 +889,8 @@ void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e) "Announce error: {error} (Retrying in {count} seconds)", interval), fmt::arg("error", err), - fmt::arg("count", interval))); + fmt::arg("count", interval)) + .append(fmt::format(" ({})", announce_url))); tier_announce_event_push(tier, e, tr_time() + interval); } } @@ -1275,13 +1280,7 @@ void checkMultiscrapeMax(tr_announcer_impl* announcer, tr_scrape_response const& if (multiscrape_max != n) { // don't log the full URL, since that might have a personal announce id - // (note: we know 'parsed' will be successful since this url has a scrape_info) - if (auto const parsed = tr_urlParse(url); parsed) - { - tr_logAddDebug( - fmt::format(FMT_STRING("Reducing multiscrape max to {:d}"), n), - fmt::format(FMT_STRING("{:s}://{:s}:{:d}"), parsed->scheme, parsed->host, parsed->port)); - } + tr_logAddDebug(fmt::format(FMT_STRING("Reducing multiscrape max to {:d}"), n), tr_urlTrackerLogName(url)); multiscrape_max = n; } diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 345e5e9e3..ae5b59e50 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -2213,7 +2213,10 @@ void tr_torrent::onTrackerResponse(tr_tracker_event const* event) break; case tr_tracker_event::Type::Warning: - tr_logAddWarnTor(this, fmt::format(_("Tracker warning: '{warning}'"), fmt::arg("warning", event->text))); + tr_logAddWarnTor( + this, + fmt::format(_("Tracker warning: '{warning}'"), fmt::arg("warning", event->text)) + .append(fmt::format(" ({})", tr_urlTrackerLogName(event->announce_url)))); error = TR_STAT_TRACKER_WARNING; error_announce_url = event->announce_url; error_string = event->text; diff --git a/libtransmission/web-utils.cc b/libtransmission/web-utils.cc index 1846e2784..87061bd0d 100644 --- a/libtransmission/web-utils.cc +++ b/libtransmission/web-utils.cc @@ -373,6 +373,17 @@ bool tr_urlIsValid(std::string_view url) return parsed && std::find(std::begin(Schemes), std::end(Schemes), parsed->scheme) != std::end(Schemes); } +std::string tr_urlTrackerLogName(std::string_view url) +{ + if (auto const parsed = tr_urlParse(url); parsed) + { + return fmt::format(FMT_STRING("{:s}://{:s}:{:d}"), parsed->scheme, parsed->host, parsed->port); + } + + // we have an invalid URL, we log the full string + return std::string{ url }; +} + tr_url_query_view::iterator& tr_url_query_view::iterator::operator++() { auto pair = tr_strvSep(&remain, '&'); diff --git a/libtransmission/web-utils.h b/libtransmission/web-utils.h index 7c7f4518b..63c90c1b8 100644 --- a/libtransmission/web-utils.h +++ b/libtransmission/web-utils.h @@ -45,6 +45,10 @@ struct tr_url_parsed_t // must be one we that Transmission supports for announce and scrape [[nodiscard]] std::optional tr_urlParseTracker(std::string_view url); +// Convenience function to get a log-safe version of a tracker URL. +// This is to avoid logging sensitive info, e.g. a personal announcer id in the URL. +[[nodiscard]] std::string tr_urlTrackerLogName(std::string_view url); + // example use: `for (auto const [key, val] : tr_url_query_view{ querystr })` struct tr_url_query_view {