chore: misc code cleanups (#6927)

* refactor: avoid repeated subscripting in `announcer-udp.cc`

* chore: remove redundant locking in global ip cache

* chore: misc code cleanup in global ip cache

* fixup! chore: misc code cleanup in global ip cache

* refactor: remove `tr_global_ip_cache::create()`

* refactor: rename `tr_global_ip_cache` to `tr_ip_cache`

* build: sync changes to xcode
This commit is contained in:
Yat Ho
2024-07-14 08:37:55 +08:00
committed by GitHub
parent 7f79cb16ee
commit a76a07ae99
9 changed files with 106 additions and 116 deletions

View File

@@ -42,8 +42,8 @@
#include "libtransmission/bandwidth.h"
#include "libtransmission/blocklist.h"
#include "libtransmission/cache.h"
#include "libtransmission/global-ip-cache.h"
#include "libtransmission/interned-string.h"
#include "libtransmission/ip-cache.h"
#include "libtransmission/log.h" // for tr_log_level
#include "libtransmission/net.h" // for tr_port, tr_tos_t
#include "libtransmission/open-files.h"
@@ -290,10 +290,10 @@ private:
tr_session& session_;
};
class GlobalIPCacheMediator final : public tr_global_ip_cache::Mediator
class IPCacheMediator final : public tr_ip_cache::Mediator
{
public:
explicit GlobalIPCacheMediator(tr_session& session) noexcept
explicit IPCacheMediator(tr_session& session) noexcept
: session_{ session }
{
}
@@ -960,7 +960,7 @@ public:
[[nodiscard]] bool has_ip_protocol(tr_address_type type) const noexcept
{
TR_ASSERT(tr_address::is_valid(type));
return global_ip_cache_->has_ip_protocol(type);
return ip_cache_.has_ip_protocol(type);
}
[[nodiscard]] tr_address bind_address(tr_address_type type) const noexcept;
@@ -968,18 +968,18 @@ public:
[[nodiscard]] std::optional<tr_address> global_address(tr_address_type type) const noexcept
{
TR_ASSERT(tr_address::is_valid(type));
return global_ip_cache_->global_addr(type);
return ip_cache_.global_addr(type);
}
bool set_global_address(tr_address const& addr) noexcept
{
return global_ip_cache_->set_global_addr(addr.type, addr);
return ip_cache_.set_global_addr(addr.type, addr);
}
[[nodiscard]] std::optional<tr_address> global_source_address(tr_address_type type) const noexcept
{
TR_ASSERT(tr_address::is_valid(type));
return global_ip_cache_->global_source_addr(type);
return ip_cache_.global_source_addr(type);
}
[[nodiscard]] auto speed_limit(tr_direction const dir) const noexcept
@@ -1290,8 +1290,8 @@ private:
tr_torrents torrents_;
// depends-on: settings_, session_thread_, timer_maker_, web_
GlobalIPCacheMediator global_ip_cache_mediator_{ *this };
std::unique_ptr<tr_global_ip_cache> global_ip_cache_ = tr_global_ip_cache::create(global_ip_cache_mediator_);
IPCacheMediator ip_cache_mediator_{ *this };
tr_ip_cache ip_cache_{ ip_cache_mediator_ };
// depends-on: settings_, session_thread_, torrents_, global_ip_cache (via tr_session::bind_address())
WebMediator web_mediator_{ this };