mirror of
https://github.com/transmission/transmission
synced 2024-12-21 23:32:35 +00:00
fix: misc µTP trace log fixes (#6929)
* fix: FTBFS when `TR_UTP_TRACE` is defined * refactor: log socket address when processing udp packets * refactor: log details of unexpected UDP packet * fix: don't unset utp context userdata during shutdown It is still needed inside `utp_destroy()` when `UTP_DEBUG_LOGGING` is defined. * code review: lazy evaluate incoming udp packet display name * code review: move `from_str` out of loop
This commit is contained in:
parent
a92fc3b76e
commit
e334f3c37f
2 changed files with 12 additions and 4 deletions
|
@ -95,6 +95,11 @@ void event_callback(evutil_socket_t s, [[maybe_unused]] short type, void* vsessi
|
|||
auto* const session = static_cast<tr_session*>(vsession);
|
||||
auto got_utp_packet = false;
|
||||
|
||||
auto const from_str = [from_sa]
|
||||
{
|
||||
return tr_socket_address::from_sockaddr(from_sa).value_or(tr_socket_address{}).display_name();
|
||||
};
|
||||
|
||||
for (;;)
|
||||
{
|
||||
auto const n_read = recvfrom(s, reinterpret_cast<char*>(std::data(buf)), std::size(buf) - 1, 0, from_sa, &fromlen);
|
||||
|
@ -128,7 +133,7 @@ void event_callback(evutil_socket_t s, [[maybe_unused]] short type, void* vsessi
|
|||
{
|
||||
if (!session->announcer_udp_->handle_message(std::data(buf), n_read, from_sa, fromlen))
|
||||
{
|
||||
tr_logAddTrace("Couldn't parse UDP tracker packet.");
|
||||
tr_logAddTrace(fmt::format("{} Couldn't parse UDP tracker packet.", from_str()));
|
||||
}
|
||||
}
|
||||
else if (session->allowsUTP() && session->utp_context != nullptr)
|
||||
|
@ -139,7 +144,11 @@ void event_callback(evutil_socket_t s, [[maybe_unused]] short type, void* vsessi
|
|||
}
|
||||
else
|
||||
{
|
||||
tr_logAddTrace("Unexpected UDP packet");
|
||||
tr_logAddTrace(fmt::format(
|
||||
"{} Unexpected UDP packet... len {} [{}]",
|
||||
from_str(),
|
||||
n_read,
|
||||
tr_base64_encode({ reinterpret_cast<char const*>(std::data(buf)), static_cast<size_t>(n_read) })));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ uint64 utp_callback(utp_callback_arguments* args)
|
|||
{
|
||||
#ifdef TR_UTP_TRACE
|
||||
case UTP_LOG:
|
||||
fmt::print(stderr, "[µTP] {}\n", args->buf);
|
||||
tr_logAddTrace(fmt::format("[µTP] {}", reinterpret_cast<char const*>(args->buf)));
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
@ -227,7 +227,6 @@ void tr_utp_close(tr_session* session)
|
|||
|
||||
if (session->utp_context != nullptr)
|
||||
{
|
||||
utp_context_set_userdata(session->utp_context, nullptr);
|
||||
utp_destroy(session->utp_context);
|
||||
session->utp_context = nullptr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue