mirror of
https://github.com/transmission/transmission
synced 2025-01-30 19:03:04 +00:00
refactor: make tr_session.rpc_server_private_ (#3646)
* refactor: make tr_session.rpc_server_ private * chore: sort some fields to reduce number of padding holes * chore: remove unused forward declarations * refactor: aggregate tr_bitfield in tr_turtle * chore: remove unused forward declarations * chore: remove unused forward declarations
This commit is contained in:
parent
0fbfed60b1
commit
c625ec7e0f
6 changed files with 66 additions and 67 deletions
|
@ -26,7 +26,6 @@ class tr_peerIo;
|
|||
/** @brief opaque struct holding handshake state information.
|
||||
freed when the handshake is completed. */
|
||||
struct tr_handshake;
|
||||
struct event_base;
|
||||
|
||||
struct tr_handshake_result
|
||||
{
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "net.h"
|
||||
#include "timer.h"
|
||||
|
||||
struct event;
|
||||
struct evhttp;
|
||||
struct tr_variant;
|
||||
struct tr_rpc_address;
|
||||
|
|
|
@ -1356,7 +1356,7 @@ static auto constexpr MinutesPerWeek = int{ MinutesPerDay * 7 };
|
|||
|
||||
static void turtleUpdateTable(struct tr_turtle_info* t)
|
||||
{
|
||||
t->minutes->setHasNone();
|
||||
t->minutes.setHasNone();
|
||||
|
||||
for (int day = 0; day < 7; ++day)
|
||||
{
|
||||
|
@ -1372,7 +1372,7 @@ static void turtleUpdateTable(struct tr_turtle_info* t)
|
|||
|
||||
for (time_t i = begin; i < end; ++i)
|
||||
{
|
||||
t->minutes->set((i + day * MinutesPerDay) % MinutesPerWeek);
|
||||
t->minutes.set((i + day * MinutesPerDay) % MinutesPerWeek);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1421,7 +1421,7 @@ static bool getInTurtleTime(struct tr_turtle_info const* t)
|
|||
minute_of_the_week = MinutesPerWeek - 1;
|
||||
}
|
||||
|
||||
return t->minutes->test(minute_of_the_week);
|
||||
return t->minutes.test(minute_of_the_week);
|
||||
}
|
||||
|
||||
static constexpr tr_auto_switch_state_t autoSwitchState(bool enabled)
|
||||
|
@ -1452,8 +1452,7 @@ static void turtleBootstrap(tr_session* session, struct tr_turtle_info* turtle)
|
|||
{
|
||||
turtle->changedByUser = false;
|
||||
turtle->autoTurtleState = TR_AUTO_SWITCH_UNUSED;
|
||||
|
||||
turtle->minutes = new tr_bitfield(MinutesPerWeek);
|
||||
turtle->minutes.setHasNone();
|
||||
|
||||
turtleUpdateTable(turtle);
|
||||
|
||||
|
@ -1888,9 +1887,6 @@ void tr_sessionClose(tr_session* session)
|
|||
}
|
||||
}
|
||||
|
||||
/* free the session memory */
|
||||
delete session->turtle.minutes;
|
||||
|
||||
delete session;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "announce-list.h"
|
||||
#include "bandwidth.h"
|
||||
#include "bitfield.h"
|
||||
#include "cache.h"
|
||||
#include "interned-string.h"
|
||||
#include "net.h" // tr_socket_t
|
||||
|
@ -50,17 +51,12 @@ tr_peer_id_t tr_peerIdInit();
|
|||
struct event_base;
|
||||
struct evdns_base;
|
||||
|
||||
class tr_bitfield;
|
||||
class tr_rpc_server;
|
||||
class tr_web;
|
||||
struct BlocklistFile;
|
||||
struct struct_utp_context;
|
||||
struct tr_address;
|
||||
struct tr_announcer;
|
||||
struct tr_announcer_udp;
|
||||
struct tr_bandwidth;
|
||||
struct tr_bindsockets;
|
||||
struct tr_fdInfo;
|
||||
|
||||
struct tr_bindinfo
|
||||
{
|
||||
|
@ -116,9 +112,7 @@ struct tr_turtle_info
|
|||
/* bitfield of all the minutes in a week.
|
||||
* Each bit's value indicates whether the scheduler wants turtle
|
||||
* limits on or off at that given minute in the week. */
|
||||
// Changed to non-owning pointer temporarily till tr_turtle_info becomes C++-constructible and destructible
|
||||
// TODO: remove * and own the value
|
||||
tr_bitfield* minutes = nullptr;
|
||||
tr_bitfield minutes{ 10080 };
|
||||
|
||||
/* recent action that was done by turtle's automatic switch */
|
||||
tr_auto_switch_state_t autoTurtleState = TR_AUTO_SWITCH_UNUSED;
|
||||
|
@ -524,8 +518,6 @@ public:
|
|||
tr_bindinfo bind_ipv4 = tr_bindinfo{ tr_inaddr_any };
|
||||
tr_bindinfo bind_ipv6 = tr_bindinfo{ tr_in6addr_any };
|
||||
|
||||
std::unique_ptr<tr_rpc_server> rpc_server_;
|
||||
|
||||
[[nodiscard]] auto constexpr queueEnabled(tr_direction dir) const noexcept
|
||||
{
|
||||
return queue_enabled_[dir];
|
||||
|
@ -706,16 +698,34 @@ private:
|
|||
|
||||
void loadBlocklists();
|
||||
|
||||
struct init_data;
|
||||
void initImpl(init_data&);
|
||||
void setImpl(init_data&);
|
||||
void closeImplStart();
|
||||
void closeImplWaitForIdleUdp();
|
||||
void closeImplFinish();
|
||||
|
||||
friend bool tr_blocklistExists(tr_session const* session);
|
||||
friend bool tr_sessionGetAntiBruteForceEnabled(tr_session const* session);
|
||||
friend bool tr_sessionIsRPCEnabled(tr_session const* session);
|
||||
friend bool tr_sessionIsRPCPasswordEnabled(tr_session const* session);
|
||||
friend char const* tr_sessionGetRPCPassword(tr_session const* session);
|
||||
friend char const* tr_sessionGetRPCUrl(tr_session const* session);
|
||||
friend char const* tr_sessionGetRPCUsername(tr_session const* session);
|
||||
friend char const* tr_sessionGetRPCWhitelist(tr_session const* session);
|
||||
friend int tr_sessionGetAntiBruteForceThreshold(tr_session const* session);
|
||||
friend size_t tr_blocklistGetRuleCount(tr_session const* session);
|
||||
friend size_t tr_blocklistSetContent(tr_session* session, char const* content_filename);
|
||||
friend tr_session* tr_sessionInit(char const* config_dir, bool message_queueing_enabled, tr_variant* client_settings);
|
||||
friend uint16_t tr_sessionGetRPCPort(tr_session const* session);
|
||||
friend uint16_t tr_sessionSetPeerPortRandom(tr_session* session);
|
||||
friend void tr_sessionClose(tr_session* session);
|
||||
friend void tr_sessionGetSettings(tr_session const* s, tr_variant* setme_dictionary);
|
||||
friend void tr_sessionLimitSpeed(tr_session* session, tr_direction dir, bool limited);
|
||||
friend void tr_sessionReloadBlocklists(tr_session* session);
|
||||
friend void tr_sessionSet(tr_session* session, tr_variant* settings);
|
||||
friend void tr_sessionSetAntiBruteForceEnabled(tr_session* session, bool is_enabled);
|
||||
friend void tr_sessionSetAntiBruteForceThreshold(tr_session* session, int max_bad_requests);
|
||||
friend void tr_sessionSetDHTEnabled(tr_session* session, bool enabled);
|
||||
friend void tr_sessionSetDeleteSource(tr_session* session, bool delete_source);
|
||||
friend void tr_sessionSetEncryption(tr_session* session, tr_encryption_mode mode);
|
||||
|
@ -733,13 +743,23 @@ private:
|
|||
friend void tr_sessionSetQueueStalledEnabled(tr_session* session, bool is_enabled);
|
||||
friend void tr_sessionSetQueueStalledMinutes(tr_session* session, int minutes);
|
||||
friend void tr_sessionSetRPCCallback(tr_session* session, tr_rpc_func func, void* user_data);
|
||||
friend void tr_sessionSetRPCEnabled(tr_session* session, bool is_enabled);
|
||||
friend void tr_sessionSetRPCPassword(tr_session* session, char const* password);
|
||||
friend void tr_sessionSetRPCPasswordEnabled(tr_session* session, bool enabled);
|
||||
friend void tr_sessionSetRPCPort(tr_session* session, uint16_t hport);
|
||||
friend void tr_sessionSetRPCUrl(tr_session* session, char const* url);
|
||||
friend void tr_sessionSetRPCUsername(tr_session* session, char const* username);
|
||||
friend void tr_sessionSetRatioLimit(tr_session* session, double desired_ratio);
|
||||
friend void tr_sessionSetRatioLimited(tr_session* session, bool is_limited);
|
||||
friend void tr_sessionSetSpeedLimit_Bps(tr_session* session, tr_direction dir, unsigned int Bps);
|
||||
friend void tr_sessionSetUTPEnabled(tr_session* session, bool enabled);
|
||||
|
||||
static std::recursive_mutex session_mutex_;
|
||||
|
||||
std::vector<std::unique_ptr<BlocklistFile>> blocklists_;
|
||||
|
||||
std::unique_ptr<tr_rpc_server> rpc_server_;
|
||||
|
||||
tr_announce_list default_trackers_;
|
||||
|
||||
tr_session_id session_id_;
|
||||
|
@ -747,12 +767,42 @@ private:
|
|||
std::array<unsigned int, 2> speed_limit_Bps_ = { 0U, 0U };
|
||||
std::array<bool, 2> speed_limit_enabled_ = { false, false };
|
||||
|
||||
std::array<bool, 2> queue_enabled_ = { false, false };
|
||||
std::array<int, 2> queue_size_ = { 0, 0 };
|
||||
|
||||
tr_rpc_func rpc_func_ = nullptr;
|
||||
void* rpc_func_user_data_ = nullptr;
|
||||
|
||||
float desired_ratio_ = 2.0F;
|
||||
|
||||
int umask_ = 022;
|
||||
|
||||
// One of <netinet/ip.h>'s IPTOS_ values.
|
||||
// See tr_netTos*() in libtransmission/net.h for more info
|
||||
int peer_socket_tos_ = *tr_netTosFromName(TR_DEFAULT_PEER_SOCKET_TOS_STR);
|
||||
|
||||
int queue_stalled_minutes_ = 0;
|
||||
|
||||
tr_encryption_mode encryption_mode_ = TR_ENCRYPTION_PREFERRED;
|
||||
|
||||
tr_preallocation_mode preallocation_mode_ = TR_PREALLOCATE_SPARSE;
|
||||
|
||||
tr_port random_port_low_;
|
||||
tr_port random_port_high_;
|
||||
|
||||
uint16_t peer_count_ = 0;
|
||||
uint16_t peer_limit_ = 200;
|
||||
uint16_t peer_limit_per_torrent_ = 50;
|
||||
|
||||
uint16_t idle_limit_minutes_;
|
||||
|
||||
uint16_t upload_slots_per_torrent_ = 8;
|
||||
|
||||
uint8_t peer_id_ttl_hours_ = 6;
|
||||
|
||||
bool is_closing_ = false;
|
||||
bool is_closed_ = false;
|
||||
|
||||
bool is_utp_enabled_ = false;
|
||||
bool is_pex_enabled_ = false;
|
||||
bool is_dht_enabled_ = false;
|
||||
|
@ -761,52 +811,15 @@ private:
|
|||
bool is_idle_limited_ = false;
|
||||
bool is_prefetch_enabled_ = false;
|
||||
bool is_ratio_limited_ = false;
|
||||
bool queue_stalled_enabled_ = false;
|
||||
|
||||
uint8_t peer_id_ttl_hours_ = 6;
|
||||
|
||||
struct init_data;
|
||||
void initImpl(init_data&);
|
||||
void setImpl(init_data&);
|
||||
void closeImplStart();
|
||||
void closeImplWaitForIdleUdp();
|
||||
void closeImplFinish();
|
||||
|
||||
tr_port random_port_low_;
|
||||
tr_port random_port_high_;
|
||||
|
||||
tr_rpc_func rpc_func_ = nullptr;
|
||||
void* rpc_func_user_data_ = nullptr;
|
||||
|
||||
float desired_ratio_ = 2.0F;
|
||||
|
||||
uint16_t upload_slots_per_torrent_ = 8;
|
||||
bool is_port_random_ = false;
|
||||
|
||||
bool should_pause_added_torrents_ = false;
|
||||
bool should_delete_source_torrents_ = false;
|
||||
bool should_scrape_paused_torrents_ = false;
|
||||
bool is_incomplete_file_naming_enabled_ = false;
|
||||
|
||||
tr_encryption_mode encryption_mode_ = TR_ENCRYPTION_PREFERRED;
|
||||
|
||||
tr_preallocation_mode preallocation_mode_ = TR_PREALLOCATE_SPARSE;
|
||||
|
||||
bool is_closing_ = false;
|
||||
bool is_closed_ = false;
|
||||
bool is_port_random_ = false;
|
||||
|
||||
uint16_t peer_count_ = 0;
|
||||
uint16_t peer_limit_ = 200;
|
||||
uint16_t peer_limit_per_torrent_ = 50;
|
||||
|
||||
uint16_t idle_limit_minutes_;
|
||||
|
||||
std::array<bool, 2> queue_enabled_ = { false, false };
|
||||
std::array<int, 2> queue_size_ = { 0, 0 };
|
||||
int queue_stalled_minutes_ = 0;
|
||||
bool queue_stalled_enabled_ = false;
|
||||
|
||||
static std::recursive_mutex session_mutex_;
|
||||
|
||||
class WebMediator final : public tr_web::Mediator
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -19,12 +19,6 @@
|
|||
#include "platform-quota.h"
|
||||
#include "tr-macros.h"
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
struct event;
|
||||
struct timeval;
|
||||
struct tr_error;
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
|
||||
#include "tr-macros.h" // tr_sha1_digest_t
|
||||
|
||||
struct evbuffer;
|
||||
|
||||
/** @brief convenience function to determine if an address is an IP address (IPv4 or IPv6) */
|
||||
bool tr_addressIsIP(char const* address);
|
||||
|
||||
|
|
Loading…
Reference in a new issue