1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 09:37:56 +00:00

refactor: tr_session.congestion (#2151)

* refactor: tr_session.congestion
This commit is contained in:
Charles Kerr 2021-11-14 00:41:44 -06:00 committed by GitHub
parent d55474161e
commit 3d38e01a13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 26 deletions

View file

@ -427,11 +427,11 @@ FAIL:
***
**/
static void maybeSetCongestionAlgorithm(tr_socket_t socket, char const* algorithm)
static void maybeSetCongestionAlgorithm(tr_socket_t socket, std::string const& algorithm)
{
if (!tr_str_is_empty(algorithm))
if (!std::empty(algorithm))
{
tr_netSetCongestionControl(socket, algorithm);
tr_netSetCongestionControl(socket, algorithm.c_str());
}
}
@ -628,8 +628,8 @@ static tr_peerIo* tr_peerIoNew(
if (socket.type == TR_PEER_SOCKET_TYPE_TCP)
{
tr_netSetTOS(socket.handle.tcp, session->peerSocketTOS, addr->type);
maybeSetCongestionAlgorithm(socket.handle.tcp, session->peer_congestion_algorithm);
tr_netSetTOS(socket.handle.tcp, session->peerSocketTos(), addr->type);
maybeSetCongestionAlgorithm(socket.handle.tcp, session->peerCongestionAlgorithm());
}
auto* io = new tr_peerIo{ session, *addr, port, isSeed };
@ -986,8 +986,8 @@ int tr_peerIoReconnect(tr_peerIo* io)
io->event_write = event_new(session->event_base, io->socket.handle.tcp, EV_WRITE, event_write_cb, io);
event_enable(io, pendingEvents);
tr_netSetTOS(io->socket.handle.tcp, session->peerSocketTOS, io->addr.type);
maybeSetCongestionAlgorithm(io->socket.handle.tcp, session->peer_congestion_algorithm);
tr_netSetTOS(io->socket.handle.tcp, session->peerSocketTos(), io->addr.type);
maybeSetCongestionAlgorithm(io->socket.handle.tcp, session->peerCongestionAlgorithm());
return 0;
}

View file

@ -256,7 +256,7 @@ tr_address const* tr_sessionGetPublicAddress(tr_session const* session, int tr_a
****
***/
static int parse_tos(std::string_view tos_in)
static int parseTos(std::string_view tos_in)
{
auto tos = tr_strlower(tr_strvStrip(tos_in));
@ -422,8 +422,8 @@ void tr_sessionGetSettings(tr_session* s, tr_variant* d)
tr_variantDictAddBool(d, TR_KEY_peer_port_random_on_start, s->isPortRandom);
tr_variantDictAddInt(d, TR_KEY_peer_port_random_low, s->randomPortLow);
tr_variantDictAddInt(d, TR_KEY_peer_port_random_high, s->randomPortHigh);
tr_variantDictAddStr(d, TR_KEY_peer_socket_tos, format_tos(s->peerSocketTOS));
tr_variantDictAddStr(d, TR_KEY_peer_congestion_algorithm, s->peer_congestion_algorithm);
tr_variantDictAddStr(d, TR_KEY_peer_socket_tos, format_tos(s->peerSocketTos()));
tr_variantDictAddStr(d, TR_KEY_peer_congestion_algorithm, s->peerCongestionAlgorithm());
tr_variantDictAddBool(d, TR_KEY_pex_enabled, s->isPexEnabled);
tr_variantDictAddBool(d, TR_KEY_port_forwarding_enabled, tr_sessionIsPortForwardingEnabled(s));
tr_variantDictAddInt(d, TR_KEY_preallocation, s->preallocationMode);
@ -840,17 +840,12 @@ static void sessionSetImpl(void* vdata)
if (tr_variantDictFindStrView(settings, TR_KEY_peer_socket_tos, &sv))
{
session->peerSocketTOS = parse_tos(sv);
session->setPeerSocketTos(parseTos(sv));
}
if (tr_variantDictFindStr(settings, TR_KEY_peer_congestion_algorithm, &strVal, nullptr))
{
session->peer_congestion_algorithm = tr_strdup(strVal);
}
else
{
session->peer_congestion_algorithm = tr_strdup("");
}
sv = ""sv;
tr_variantDictFindStrView(settings, TR_KEY_peer_congestion_algorithm, &sv);
session->setPeerCongestionAlgorithm(sv);
if (tr_variantDictFindBool(settings, TR_KEY_blocklist_enabled, &boolVal))
{
@ -2040,7 +2035,6 @@ void tr_sessionClose(tr_session* session)
tr_free(session->configDir);
tr_free(session->resumeDir);
tr_free(session->torrentDir);
tr_free(session->peer_congestion_algorithm);
delete session;
}

View file

@ -231,6 +231,28 @@ public:
return tr_rpcGetWhitelistEnabled(this->rpcServer);
}
// peer networking
std::string const& peerCongestionAlgorithm() const
{
return peer_congestion_algorithm_;
}
void setPeerCongestionAlgorithm(std::string_view algorithm)
{
peer_congestion_algorithm_ = algorithm;
}
int peerSocketTos() const
{
return peer_socket_tos_;
}
void setPeerSocketTos(int tos)
{
peer_socket_tos_ = tos;
}
public:
bool isPortRandom;
bool isPexEnabled;
@ -305,9 +327,6 @@ public:
tr_port randomPortLow;
tr_port randomPortHigh;
int peerSocketTOS;
char* peer_congestion_algorithm;
std::unordered_set<tr_torrent*> torrents;
std::map<int, tr_torrent*> torrentsById;
std::map<uint8_t const*, tr_torrent*, CompareHash> torrentsByHash;
@ -357,6 +376,9 @@ private:
std::string blocklist_url_;
std::string download_dir_;
std::string incomplete_dir_;
std::string peer_congestion_algorithm_;
int peer_socket_tos_ = 0;
std::array<bool, TR_SCRIPT_N_TYPES> scripts_enabled_;
bool blocklist_enabled_ = false;

View file

@ -126,19 +126,21 @@ void tr_udpSetSocketBuffers(tr_session* session)
void tr_udpSetSocketTOS(tr_session* session)
{
if (session->peerSocketTOS == 0)
auto const tos = session->peerSocketTos();
if (tos)
{
return;
}
if (session->udp_socket != TR_BAD_SOCKET)
{
tr_netSetTOS(session->udp_socket, session->peerSocketTOS, TR_AF_INET);
tr_netSetTOS(session->udp_socket, tos, TR_AF_INET);
}
if (session->udp6_socket != TR_BAD_SOCKET)
{
tr_netSetTOS(session->udp6_socket, session->peerSocketTOS, TR_AF_INET6);
tr_netSetTOS(session->udp6_socket, tos, TR_AF_INET6);
}
}