1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

refactor: followup/cleanup of tr_global_ip_cache PR (#5498)

* remove tr_session::bindAddress()

* replace tr_net_hasIPv6 with tr_session::has_ip_protocol()

* update comment
This commit is contained in:
tearfur 2023-05-06 11:05:28 +08:00 committed by GitHub
parent 693d202a64
commit d65f9329cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 2 additions and 50 deletions

View file

@ -360,32 +360,6 @@ tr_socket_t tr_netBindTCP(tr_address const& addr, tr_port port, bool suppress_ms
return tr_netBindTCPImpl(addr, port, suppress_msgs, &unused);
}
bool tr_net_hasIPv6(tr_port port)
{
static bool result = false;
static bool already_done = false;
if (!already_done)
{
int err = 0;
auto const fd = tr_netBindTCPImpl(tr_address::any_ipv6(), port, true, &err);
if (fd != TR_BAD_SOCKET || err != EAFNOSUPPORT) /* we support ipv6 */
{
result = true;
}
if (fd != TR_BAD_SOCKET)
{
tr_net_close_socket(fd);
}
already_done = true;
}
return result;
}
std::optional<std::tuple<tr_address, tr_port, tr_socket_t>> tr_netAccept(tr_session* session, tr_socket_t listening_sockfd)
{
TR_ASSERT(session != nullptr);

View file

@ -327,8 +327,6 @@ void tr_netSetCongestionControl(tr_socket_t s, char const* algorithm);
void tr_net_close_socket(tr_socket_t fd);
[[nodiscard]] bool tr_net_hasIPv6(tr_port);
// --- TOS / DSCP
/**

View file

@ -429,7 +429,7 @@ tr_address tr_session::publicAddress(tr_address_type type) const noexcept
if (type == TR_AF_INET6)
{
// if user provided an address, use it.
// otherwise, if we can determine which one to use via globalSourceIPv6 magic, use it.
// otherwise, if we can determine which one to use via global_source_address(ipv6) magic, use it.
// otherwise, use any_ipv6 (::).
auto const source_addr = global_source_address(type);
return source_addr && source_addr->is_global_unicast_address() ? *source_addr : global_ip_cache_->bind_addr(type);
@ -2052,22 +2052,6 @@ void tr_session::closeTorrentFile(tr_torrent* tor, tr_file_index_t file_num) noe
// ---
std::string tr_session::bindAddress(tr_address_type type) const noexcept
{
switch (type)
{
case TR_AF_INET:
return settings_.bind_address_ipv4;
case TR_AF_INET6:
return settings_.bind_address_ipv6;
default:
TR_ASSERT_MSG(false, "invalid type");
return {};
}
}
// ---
void tr_sessionSetQueueStartCallback(tr_session* session, void (*callback)(tr_session*, tr_torrent*, void*), void* user_data)
{
session->setQueueStartCallback(callback, user_data);

View file

@ -506,10 +506,6 @@ public:
void closeTorrentFiles(tr_torrent* tor) noexcept;
void closeTorrentFile(tr_torrent* tor, tr_file_index_t file_num) noexcept;
// bind address
[[nodiscard]] std::string bindAddress(tr_address_type type) const noexcept;
// announce ip
[[nodiscard]] constexpr std::string const& announceIP() const noexcept

View file

@ -175,7 +175,7 @@ tr_session::tr_udp_core::tr_udp_core(tr_session& session, tr_port udp_port)
}
}
if (!tr_net_hasIPv6(udp_port_))
if (!session.has_ip_protocol(TR_AF_INET6))
{
// no IPv6; do nothing
}