mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +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:
parent
693d202a64
commit
d65f9329cd
5 changed files with 2 additions and 50 deletions
|
@ -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);
|
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)
|
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);
|
TR_ASSERT(session != nullptr);
|
||||||
|
|
|
@ -327,8 +327,6 @@ void tr_netSetCongestionControl(tr_socket_t s, char const* algorithm);
|
||||||
|
|
||||||
void tr_net_close_socket(tr_socket_t fd);
|
void tr_net_close_socket(tr_socket_t fd);
|
||||||
|
|
||||||
[[nodiscard]] bool tr_net_hasIPv6(tr_port);
|
|
||||||
|
|
||||||
// --- TOS / DSCP
|
// --- TOS / DSCP
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -429,7 +429,7 @@ tr_address tr_session::publicAddress(tr_address_type type) const noexcept
|
||||||
if (type == TR_AF_INET6)
|
if (type == TR_AF_INET6)
|
||||||
{
|
{
|
||||||
// if user provided an address, use it.
|
// 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 (::).
|
// otherwise, use any_ipv6 (::).
|
||||||
auto const source_addr = global_source_address(type);
|
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);
|
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)
|
void tr_sessionSetQueueStartCallback(tr_session* session, void (*callback)(tr_session*, tr_torrent*, void*), void* user_data)
|
||||||
{
|
{
|
||||||
session->setQueueStartCallback(callback, user_data);
|
session->setQueueStartCallback(callback, user_data);
|
||||||
|
|
|
@ -506,10 +506,6 @@ public:
|
||||||
void closeTorrentFiles(tr_torrent* tor) noexcept;
|
void closeTorrentFiles(tr_torrent* tor) noexcept;
|
||||||
void closeTorrentFile(tr_torrent* tor, tr_file_index_t file_num) 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
|
// announce ip
|
||||||
|
|
||||||
[[nodiscard]] constexpr std::string const& announceIP() const noexcept
|
[[nodiscard]] constexpr std::string const& announceIP() const noexcept
|
||||||
|
|
|
@ -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
|
// no IPv6; do nothing
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue