refactor: add more nodiscard, constexpr, and noexcept (#4089)
This commit is contained in:
parent
ee8a6bd130
commit
09bb1a60f0
|
@ -191,7 +191,7 @@ public:
|
|||
/**
|
||||
* @return nonzero if this bandwidth throttles its peer-ios speeds
|
||||
*/
|
||||
[[nodiscard]] constexpr bool isLimited(tr_direction dir) const
|
||||
[[nodiscard]] constexpr bool isLimited(tr_direction dir) const noexcept
|
||||
{
|
||||
return this->band_[dir].is_limited_;
|
||||
}
|
||||
|
|
|
@ -74,12 +74,12 @@ public:
|
|||
tr_block_index_t block = 0;
|
||||
uint32_t block_offset = 0;
|
||||
|
||||
[[nodiscard]] bool operator==(Location const& that) const
|
||||
[[nodiscard]] constexpr bool operator==(Location const& that) const noexcept
|
||||
{
|
||||
return this->byte == that.byte;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool operator<(Location const& that) const
|
||||
[[nodiscard]] constexpr bool operator<(Location const& that) const noexcept
|
||||
{
|
||||
return this->byte < that.byte;
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ public:
|
|||
|
||||
private:
|
||||
// Location of the last byte in `piece`.
|
||||
[[nodiscard]] constexpr Location pieceLastLoc(tr_piece_index_t piece) const
|
||||
[[nodiscard]] constexpr Location pieceLastLoc(tr_piece_index_t piece) const noexcept
|
||||
{
|
||||
return byteLoc(static_cast<uint64_t>(piece) * pieceSize() + pieceSize(piece) - 1);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
* @param when the current time in sec, such as from tr_time()
|
||||
* @param n how many items to add to the history's counter
|
||||
*/
|
||||
void add(time_t now, SizeType n)
|
||||
constexpr void add(time_t now, SizeType n)
|
||||
{
|
||||
if (timestamps_[newest_] != now)
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ public:
|
|||
* @param when the current time in sec, such as from tr_time()
|
||||
* @param seconds how many seconds to count back through.
|
||||
*/
|
||||
SizeType count(time_t now, unsigned int age_sec) const
|
||||
constexpr SizeType count(time_t now, unsigned int age_sec) const
|
||||
{
|
||||
auto sum = SizeType{};
|
||||
time_t const oldest = now - age_sec;
|
||||
|
|
|
@ -21,12 +21,15 @@ public:
|
|||
|
||||
explicit tr_interned_string(tr_quark quark)
|
||||
: quark_{ quark }
|
||||
, sv_{ tr_quark_get_string_view(quark_) }
|
||||
{
|
||||
}
|
||||
|
||||
explicit tr_interned_string(std::string_view sv)
|
||||
: tr_interned_string{ tr_quark_new(sv) }
|
||||
{
|
||||
}
|
||||
|
||||
explicit tr_interned_string(char const* c_str)
|
||||
: tr_interned_string{ std::string_view{ c_str ? c_str : "" } }
|
||||
{
|
||||
|
@ -35,63 +38,72 @@ public:
|
|||
tr_interned_string& operator=(tr_quark quark)
|
||||
{
|
||||
quark_ = quark;
|
||||
sv_ = tr_quark_get_string_view(quark_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
tr_interned_string& operator=(std::string_view sv)
|
||||
{
|
||||
return *this = tr_quark_new(sv);
|
||||
}
|
||||
|
||||
tr_interned_string& operator=(char const* c_str)
|
||||
{
|
||||
return *this = std::string_view{ c_str != nullptr ? c_str : "" };
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr tr_quark quark() const noexcept
|
||||
[[nodiscard]] constexpr auto quark() const noexcept
|
||||
{
|
||||
return quark_;
|
||||
}
|
||||
[[nodiscard]] std::string_view sv() const
|
||||
|
||||
[[nodiscard]] constexpr auto sv() const noexcept
|
||||
{
|
||||
return tr_quark_get_string_view(quark_);
|
||||
return sv_;
|
||||
}
|
||||
[[nodiscard]] char const* c_str() const
|
||||
|
||||
[[nodiscard]] constexpr char const* c_str() const noexcept
|
||||
{
|
||||
return std::data(sv()); // tr_quark strs are always zero-terminated
|
||||
}
|
||||
|
||||
[[nodiscard]] auto data() const
|
||||
[[nodiscard]] constexpr auto data() const noexcept
|
||||
{
|
||||
return std::data(this->sv());
|
||||
return std::data(sv());
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto empty() const noexcept
|
||||
{
|
||||
return quark_ == TR_KEY_NONE;
|
||||
}
|
||||
[[nodiscard]] auto size() const
|
||||
|
||||
[[nodiscard]] constexpr auto size() const noexcept
|
||||
{
|
||||
return std::size(this->sv());
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
*this = TR_KEY_NONE;
|
||||
return std::size(sv());
|
||||
}
|
||||
|
||||
[[nodiscard]] auto begin() const
|
||||
constexpr void clear()
|
||||
{
|
||||
return std::begin(this->sv());
|
||||
}
|
||||
[[nodiscard]] auto end() const
|
||||
{
|
||||
return std::end(this->sv());
|
||||
*this = tr_interned_string{};
|
||||
}
|
||||
|
||||
[[nodiscard]] auto rbegin() const
|
||||
[[nodiscard]] constexpr auto begin() const noexcept
|
||||
{
|
||||
return std::rbegin(this->sv());
|
||||
return std::begin(sv());
|
||||
}
|
||||
[[nodiscard]] auto rend() const
|
||||
|
||||
[[nodiscard]] constexpr auto end() const noexcept
|
||||
{
|
||||
return std::rend(this->sv());
|
||||
return std::end(sv());
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto rbegin() const noexcept
|
||||
{
|
||||
return std::rbegin(sv());
|
||||
}
|
||||
[[nodiscard]] constexpr auto rend() const noexcept
|
||||
{
|
||||
return std::rend(sv());
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto compare(tr_interned_string const& that) const noexcept // <=>
|
||||
|
@ -128,30 +140,31 @@ public:
|
|||
return this->compare(that) != 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool operator==(std::string_view that) const
|
||||
[[nodiscard]] constexpr auto operator==(std::string_view that) const noexcept
|
||||
{
|
||||
return this->sv() == that;
|
||||
return sv() == that;
|
||||
}
|
||||
[[nodiscard]] bool operator!=(std::string_view that) const
|
||||
[[nodiscard]] constexpr auto operator!=(std::string_view that) const noexcept
|
||||
{
|
||||
return this->sv() != that;
|
||||
return sv() != that;
|
||||
}
|
||||
[[nodiscard]] bool operator==(char const* that) const
|
||||
[[nodiscard]] constexpr bool operator==(char const* that) const noexcept
|
||||
{
|
||||
return *this == std::string_view{ that != nullptr ? that : "" };
|
||||
}
|
||||
[[nodiscard]] bool operator!=(char const* that) const
|
||||
[[nodiscard]] constexpr bool operator!=(char const* that) const noexcept
|
||||
{
|
||||
return *this != std::string_view{ that != nullptr ? that : "" };
|
||||
}
|
||||
|
||||
operator std::string_view() const
|
||||
constexpr operator std::string_view() const noexcept
|
||||
{
|
||||
return sv();
|
||||
}
|
||||
|
||||
private:
|
||||
tr_quark quark_ = TR_KEY_NONE;
|
||||
std::string_view sv_ = "";
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
|
@ -805,7 +805,7 @@ static size_t getDesiredOutputBufferSize(tr_peerIo const* io, uint64_t now)
|
|||
return std::max(ceiling, current_speed_bytes_per_second * period);
|
||||
}
|
||||
|
||||
size_t tr_peerIo::getWriteBufferSpace(uint64_t now) const
|
||||
size_t tr_peerIo::getWriteBufferSpace(uint64_t now) const noexcept
|
||||
{
|
||||
size_t const desired_len = getDesiredOutputBufferSize(this, now);
|
||||
size_t const current_len = std::size(outbuf);
|
||||
|
|
|
@ -147,7 +147,7 @@ public:
|
|||
// This is a destructive add: `buf` is empty after this call.
|
||||
void write(libtransmission::Buffer& buf, bool is_piece_data);
|
||||
|
||||
size_t getWriteBufferSpace(uint64_t now) const;
|
||||
[[nodiscard]] size_t getWriteBufferSpace(uint64_t now) const noexcept;
|
||||
|
||||
[[nodiscard]] auto hasBandwidthLeft(tr_direction dir) noexcept
|
||||
{
|
||||
|
|
|
@ -85,7 +85,7 @@ private:
|
|||
}
|
||||
|
||||
public:
|
||||
explicit tr_handshake_mediator_impl(tr_session& session)
|
||||
explicit tr_handshake_mediator_impl(tr_session& session) noexcept
|
||||
: session_{ session }
|
||||
{
|
||||
}
|
||||
|
@ -1107,11 +1107,6 @@ static struct peer_atom* ensureAtomExists(
|
|||
return a;
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr auto getMaxPeerCount(tr_torrent const* tor) noexcept
|
||||
{
|
||||
return tor->max_connected_peers;
|
||||
}
|
||||
|
||||
static void createBitTorrentPeer(tr_torrent* tor, std::shared_ptr<tr_peerIo> io, struct peer_atom* atom, tr_quark client)
|
||||
{
|
||||
TR_ASSERT(atom != nullptr);
|
||||
|
@ -1208,7 +1203,7 @@ static bool on_handshake_done(tr_handshake_result const& result)
|
|||
{
|
||||
tr_logAddTraceSwarm(s, fmt::format("banned peer {} tried to reconnect", atom->readable()));
|
||||
}
|
||||
else if (result.io->isIncoming() && s->peerCount() >= getMaxPeerCount(s->tor))
|
||||
else if (result.io->isIncoming() && s->peerCount() >= s->tor->peerLimit())
|
||||
{
|
||||
/* too many peers already */
|
||||
}
|
||||
|
@ -1498,7 +1493,7 @@ void tr_peerMgrStartTorrent(tr_torrent* tor)
|
|||
tr_swarm* const swarm = tor->swarm;
|
||||
|
||||
swarm->is_running = true;
|
||||
swarm->max_peers = getMaxPeerCount(tor);
|
||||
swarm->max_peers = tor->peerLimit();
|
||||
|
||||
swarm->manager->rechokeSoon();
|
||||
}
|
||||
|
@ -1975,7 +1970,7 @@ void rechokeDownloads(tr_swarm* s)
|
|||
}
|
||||
|
||||
/* don't let the previous section's number tweaking go too far... */
|
||||
max_peers = std::clamp(max_peers, MinInterestingPeers, s->tor->max_connected_peers);
|
||||
max_peers = std::clamp(max_peers, MinInterestingPeers, s->tor->peerLimit());
|
||||
|
||||
s->max_peers = max_peers;
|
||||
|
||||
|
@ -2332,7 +2327,7 @@ auto constexpr MaxUploadIdleSecs = time_t{ 60 * 5 };
|
|||
/* disconnect if it's been too long since piece data has been transferred.
|
||||
* this is on a sliding scale based on number of available peers... */
|
||||
{
|
||||
auto const relax_strictness_if_fewer_than_n = static_cast<size_t>(std::lround(getMaxPeerCount(tor) * 0.9));
|
||||
auto const relax_strictness_if_fewer_than_n = static_cast<size_t>(std::lround(tor->peerLimit() * 0.9));
|
||||
/* if we have >= relaxIfFewerThan, strictness is 100%.
|
||||
* if we have zero connections, strictness is 0% */
|
||||
float const strictness = peer_count >= relax_strictness_if_fewer_than_n ?
|
||||
|
@ -2440,7 +2435,7 @@ void enforceTorrentPeerLimit(tr_swarm* swarm)
|
|||
{
|
||||
// do we have too many peers?
|
||||
auto const n = swarm->peerCount();
|
||||
auto const max = tr_torrentGetPeerLimit(swarm->tor);
|
||||
auto const max = swarm->tor->peerLimit();
|
||||
if (n <= max)
|
||||
{
|
||||
return;
|
||||
|
@ -2687,7 +2682,7 @@ struct peer_candidate
|
|||
score = addValToKey(score, 32, i);
|
||||
|
||||
/* prefer peers belonging to a torrent of a higher priority */
|
||||
switch (tr_torrentGetPriority(tor))
|
||||
switch (tor->getPriority())
|
||||
{
|
||||
case TR_PRI_HIGH:
|
||||
i = 0;
|
||||
|
@ -2777,7 +2772,7 @@ struct peer_candidate
|
|||
}
|
||||
|
||||
/* if we've already got enough peers in this torrent... */
|
||||
if (tr_torrentGetPeerLimit(tor) <= tor->swarm->peerCount())
|
||||
if (tor->peerLimit() <= tor->swarm->peerCount())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -578,13 +578,13 @@ private:
|
|||
// TODO: this needs to consider all the other peers as well...
|
||||
uint64_t const now = tr_time_msec();
|
||||
auto rate_bytes_per_second = tr_peerGetPieceSpeedBytesPerSecond(this, now, TR_PEER_TO_CLIENT);
|
||||
if (tr_torrentUsesSpeedLimit(torrent, TR_PEER_TO_CLIENT))
|
||||
if (torrent->usesSpeedLimit(TR_PEER_TO_CLIENT))
|
||||
{
|
||||
rate_bytes_per_second = std::min(rate_bytes_per_second, torrent->speedLimitBps(TR_PEER_TO_CLIENT));
|
||||
}
|
||||
|
||||
// honor the session limits, if enabled
|
||||
if (tr_torrentUsesSessionLimits(torrent))
|
||||
if (torrent->usesSessionLimits())
|
||||
{
|
||||
if (auto const irate_bytes_per_second = torrent->session->activeSpeedLimitBps(TR_PEER_TO_CLIENT);
|
||||
irate_bytes_per_second)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
struct tr_session;
|
||||
|
||||
/** @brief return the directory where the Web Client's web ui files are kept */
|
||||
std::string tr_getWebClientDir(tr_session const*);
|
||||
[[nodiscard]] std::string tr_getWebClientDir(tr_session const*);
|
||||
|
||||
/** @brief return the directory where session id lock files are stored */
|
||||
std::string tr_getSessionIdDir();
|
||||
[[nodiscard]] std::string tr_getSessionIdDir();
|
||||
|
|
|
@ -249,8 +249,8 @@ static void saveSingleSpeedLimit(tr_variant* d, tr_torrent const* tor, tr_direct
|
|||
{
|
||||
tr_variantDictReserve(d, 3);
|
||||
tr_variantDictAddInt(d, TR_KEY_speed_Bps, tor->speedLimitBps(dir));
|
||||
tr_variantDictAddBool(d, TR_KEY_use_global_speed_limit, tr_torrentUsesSessionLimits(tor));
|
||||
tr_variantDictAddBool(d, TR_KEY_use_speed_limit, tr_torrentUsesSpeedLimit(tor, dir));
|
||||
tr_variantDictAddBool(d, TR_KEY_use_global_speed_limit, tor->usesSessionLimits());
|
||||
tr_variantDictAddBool(d, TR_KEY_use_speed_limit, tor->usesSpeedLimit(dir));
|
||||
}
|
||||
|
||||
static void saveSpeedLimits(tr_variant* dict, tr_torrent const* tor)
|
||||
|
@ -269,8 +269,8 @@ static void saveRatioLimits(tr_variant* dict, tr_torrent const* tor)
|
|||
static void saveIdleLimits(tr_variant* dict, tr_torrent const* tor)
|
||||
{
|
||||
tr_variant* d = tr_variantDictAddDict(dict, TR_KEY_idle_limit, 2);
|
||||
tr_variantDictAddInt(d, TR_KEY_idle_limit, tr_torrentGetIdleLimit(tor));
|
||||
tr_variantDictAddInt(d, TR_KEY_idle_mode, tr_torrentGetIdleMode(tor));
|
||||
tr_variantDictAddInt(d, TR_KEY_idle_limit, tor->idleLimitMinutes());
|
||||
tr_variantDictAddInt(d, TR_KEY_idle_mode, tor->idleLimitMode());
|
||||
}
|
||||
|
||||
static void loadSingleSpeedLimit(tr_variant* d, tr_direction dir, tr_torrent* tor)
|
||||
|
@ -286,7 +286,7 @@ static void loadSingleSpeedLimit(tr_variant* d, tr_direction dir, tr_torrent* to
|
|||
|
||||
if (auto val = bool{}; tr_variantDictFindBool(d, TR_KEY_use_speed_limit, &val))
|
||||
{
|
||||
tr_torrentUseSpeedLimit(tor, dir, val);
|
||||
tor->useSpeedLimit(dir, val);
|
||||
}
|
||||
|
||||
if (auto val = bool{}; tr_variantDictFindBool(d, TR_KEY_use_global_speed_limit, &val))
|
||||
|
@ -327,7 +327,7 @@ static auto loadRatioLimits(tr_variant* dict, tr_torrent* tor)
|
|||
|
||||
if (auto i = int64_t{}; tr_variantDictFindInt(d, TR_KEY_ratio_mode, &i))
|
||||
{
|
||||
tr_torrentSetRatioMode(tor, tr_ratiolimit(i));
|
||||
tor->setRatioMode(tr_ratiolimit(i));
|
||||
}
|
||||
|
||||
ret = tr_resume::Ratiolimit;
|
||||
|
@ -344,7 +344,7 @@ static auto loadIdleLimits(tr_variant* dict, tr_torrent* tor)
|
|||
{
|
||||
if (auto imin = int64_t{}; tr_variantDictFindInt(d, TR_KEY_idle_limit, &imin))
|
||||
{
|
||||
tr_torrentSetIdleLimit(tor, imin);
|
||||
tor->setIdleLimit(imin);
|
||||
}
|
||||
|
||||
if (auto i = int64_t{}; tr_variantDictFindInt(d, TR_KEY_idle_mode, &i))
|
||||
|
@ -723,7 +723,7 @@ static auto loadFromFile(tr_torrent* tor, tr_resume::fields_t fields_to_load, bo
|
|||
|
||||
if ((fields_to_load & tr_resume::MaxPeers) != 0 && tr_variantDictFindInt(&top, TR_KEY_max_peers, &i))
|
||||
{
|
||||
tor->max_connected_peers = static_cast<uint16_t>(i);
|
||||
tor->max_connected_peers_ = static_cast<uint16_t>(i);
|
||||
fields_loaded |= tr_resume::MaxPeers;
|
||||
}
|
||||
|
||||
|
@ -853,7 +853,7 @@ static auto setFromCtor(tr_torrent* tor, tr_resume::fields_t fields, tr_ctor con
|
|||
}
|
||||
}
|
||||
|
||||
if (((fields & tr_resume::MaxPeers) != 0) && tr_ctorGetPeerLimit(ctor, mode, &tor->max_connected_peers))
|
||||
if (((fields & tr_resume::MaxPeers) != 0) && tr_ctorGetPeerLimit(ctor, mode, &tor->max_connected_peers_))
|
||||
{
|
||||
ret |= tr_resume::MaxPeers;
|
||||
}
|
||||
|
@ -923,8 +923,8 @@ void save(tr_torrent* tor)
|
|||
|
||||
tr_variantDictAddInt(&top, TR_KEY_downloaded, tor->downloadedPrev + tor->downloadedCur);
|
||||
tr_variantDictAddInt(&top, TR_KEY_uploaded, tor->uploadedPrev + tor->uploadedCur);
|
||||
tr_variantDictAddInt(&top, TR_KEY_max_peers, tor->max_connected_peers);
|
||||
tr_variantDictAddInt(&top, TR_KEY_bandwidth_priority, tr_torrentGetPriority(tor));
|
||||
tr_variantDictAddInt(&top, TR_KEY_max_peers, tor->peerLimit());
|
||||
tr_variantDictAddInt(&top, TR_KEY_bandwidth_priority, tor->getPriority());
|
||||
tr_variantDictAddBool(&top, TR_KEY_paused, !tor->isRunning && !tor->isQueued());
|
||||
savePeers(&top, tor);
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ static char const* queueMoveBottom(
|
|||
|
||||
struct CompareTorrentByQueuePosition
|
||||
{
|
||||
bool operator()(tr_torrent const* a, tr_torrent const* b) const
|
||||
constexpr bool operator()(tr_torrent const* a, tr_torrent const* b) const
|
||||
{
|
||||
return a->queuePosition < b->queuePosition;
|
||||
}
|
||||
|
@ -569,7 +569,7 @@ static void initField(tr_torrent const* const tor, tr_stat const* const st, tr_v
|
|||
break;
|
||||
|
||||
case TR_KEY_bandwidthPriority:
|
||||
tr_variantInitInt(initme, tr_torrentGetPriority(tor));
|
||||
tr_variantInitInt(initme, tor->getPriority());
|
||||
break;
|
||||
|
||||
case TR_KEY_comment:
|
||||
|
@ -609,7 +609,7 @@ static void initField(tr_torrent const* const tor, tr_stat const* const st, tr_v
|
|||
break;
|
||||
|
||||
case TR_KEY_downloadLimited:
|
||||
tr_variantInitBool(initme, tr_torrentUsesSpeedLimit(tor, TR_DOWN));
|
||||
tr_variantInitBool(initme, tor->usesSpeedLimit(TR_DOWN));
|
||||
break;
|
||||
|
||||
case TR_KEY_error:
|
||||
|
@ -655,7 +655,7 @@ static void initField(tr_torrent const* const tor, tr_stat const* const st, tr_v
|
|||
break;
|
||||
|
||||
case TR_KEY_honorsSessionLimits:
|
||||
tr_variantInitBool(initme, tr_torrentUsesSessionLimits(tor));
|
||||
tr_variantInitBool(initme, tor->usesSessionLimits());
|
||||
break;
|
||||
|
||||
case TR_KEY_id:
|
||||
|
@ -691,7 +691,8 @@ static void initField(tr_torrent const* const tor, tr_stat const* const st, tr_v
|
|||
break;
|
||||
|
||||
case TR_KEY_maxConnectedPeers:
|
||||
tr_variantInitInt(initme, tr_torrentGetPeerLimit(tor));
|
||||
case TR_KEY_peer_limit:
|
||||
tr_variantInitInt(initme, tor->peerLimit());
|
||||
break;
|
||||
|
||||
case TR_KEY_magnetLink:
|
||||
|
@ -714,10 +715,6 @@ static void initField(tr_torrent const* const tor, tr_stat const* const st, tr_v
|
|||
tr_variantInitReal(initme, st->percentDone);
|
||||
break;
|
||||
|
||||
case TR_KEY_peer_limit:
|
||||
tr_variantInitInt(initme, tr_torrentGetPeerLimit(tor));
|
||||
break;
|
||||
|
||||
case TR_KEY_peers:
|
||||
addPeers(tor, initme);
|
||||
break;
|
||||
|
@ -806,11 +803,11 @@ static void initField(tr_torrent const* const tor, tr_stat const* const st, tr_v
|
|||
break;
|
||||
|
||||
case TR_KEY_seedIdleLimit:
|
||||
tr_variantInitInt(initme, tr_torrentGetIdleLimit(tor));
|
||||
tr_variantInitInt(initme, tor->idleLimitMinutes());
|
||||
break;
|
||||
|
||||
case TR_KEY_seedIdleMode:
|
||||
tr_variantInitInt(initme, tr_torrentGetIdleMode(tor));
|
||||
tr_variantInitInt(initme, tor->idleLimitMode());
|
||||
break;
|
||||
|
||||
case TR_KEY_seedRatioLimit:
|
||||
|
@ -883,7 +880,7 @@ static void initField(tr_torrent const* const tor, tr_stat const* const st, tr_v
|
|||
break;
|
||||
|
||||
case TR_KEY_uploadLimited:
|
||||
tr_variantInitBool(initme, tr_torrentUsesSpeedLimit(tor, TR_UP));
|
||||
tr_variantInitBool(initme, tor->usesSpeedLimit(TR_UP));
|
||||
break;
|
||||
|
||||
case TR_KEY_uploadRatio:
|
||||
|
@ -1274,7 +1271,7 @@ static char const* torrentSet(
|
|||
|
||||
if (auto val = bool{}; tr_variantDictFindBool(args_in, TR_KEY_downloadLimited, &val))
|
||||
{
|
||||
tr_torrentUseSpeedLimit(tor, TR_DOWN, val);
|
||||
tor->useSpeedLimit(TR_DOWN, val);
|
||||
}
|
||||
|
||||
if (auto val = bool{}; tr_variantDictFindBool(args_in, TR_KEY_honorsSessionLimits, &val))
|
||||
|
@ -1289,12 +1286,12 @@ static char const* torrentSet(
|
|||
|
||||
if (auto val = bool{}; tr_variantDictFindBool(args_in, TR_KEY_uploadLimited, &val))
|
||||
{
|
||||
tr_torrentUseSpeedLimit(tor, TR_UP, val);
|
||||
tor->useSpeedLimit(TR_UP, val);
|
||||
}
|
||||
|
||||
if (tr_variantDictFindInt(args_in, TR_KEY_seedIdleLimit, &tmp))
|
||||
{
|
||||
tr_torrentSetIdleLimit(tor, static_cast<uint16_t>(tmp));
|
||||
tor->setIdleLimit(static_cast<uint16_t>(tmp));
|
||||
}
|
||||
|
||||
if (tr_variantDictFindInt(args_in, TR_KEY_seedIdleMode, &tmp))
|
||||
|
@ -1309,7 +1306,7 @@ static char const* torrentSet(
|
|||
|
||||
if (tr_variantDictFindInt(args_in, TR_KEY_seedRatioMode, &tmp))
|
||||
{
|
||||
tr_torrentSetRatioMode(tor, (tr_ratiolimit)tmp);
|
||||
tor->setRatioMode(static_cast<tr_ratiolimit>(tmp));
|
||||
}
|
||||
|
||||
if (tr_variantDictFindInt(args_in, TR_KEY_queuePosition, &tmp))
|
||||
|
|
|
@ -100,7 +100,7 @@ private:
|
|||
class AltSpeedMediator final : public tr_session_alt_speeds::Mediator
|
||||
{
|
||||
public:
|
||||
explicit AltSpeedMediator(tr_session& session)
|
||||
explicit AltSpeedMediator(tr_session& session) noexcept
|
||||
: session_{ session }
|
||||
{
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ private:
|
|||
class AnnouncerUdpMediator final : public tr_announcer_udp::Mediator
|
||||
{
|
||||
public:
|
||||
explicit AnnouncerUdpMediator(tr_session& session)
|
||||
explicit AnnouncerUdpMediator(tr_session& session) noexcept
|
||||
: session_{ session }
|
||||
{
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ private:
|
|||
class PortForwardingMediator final : public tr_port_forwarding::Mediator
|
||||
{
|
||||
public:
|
||||
explicit PortForwardingMediator(tr_session& session)
|
||||
explicit PortForwardingMediator(tr_session& session) noexcept
|
||||
: session_{ session }
|
||||
{
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ private:
|
|||
class WebMediator final : public tr_web::Mediator
|
||||
{
|
||||
public:
|
||||
explicit WebMediator(tr_session* session)
|
||||
explicit WebMediator(tr_session* session) noexcept
|
||||
: session_{ session }
|
||||
{
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ private:
|
|||
class LpdMediator final : public tr_lpd::Mediator
|
||||
{
|
||||
public:
|
||||
explicit LpdMediator(tr_session& session)
|
||||
explicit LpdMediator(tr_session& session) noexcept
|
||||
: session_{ session }
|
||||
{
|
||||
}
|
||||
|
@ -594,19 +594,19 @@ public:
|
|||
return session_stats_;
|
||||
}
|
||||
|
||||
void addUploaded(uint32_t n_bytes) noexcept
|
||||
constexpr void addUploaded(uint32_t n_bytes) noexcept
|
||||
{
|
||||
session_stats_.addUploaded(n_bytes);
|
||||
stats().addUploaded(n_bytes);
|
||||
}
|
||||
|
||||
void addDownloaded(uint32_t n_bytes) noexcept
|
||||
constexpr void addDownloaded(uint32_t n_bytes) noexcept
|
||||
{
|
||||
session_stats_.addDownloaded(n_bytes);
|
||||
stats().addDownloaded(n_bytes);
|
||||
}
|
||||
|
||||
void addFileCreated() noexcept
|
||||
constexpr void addFileCreated() noexcept
|
||||
{
|
||||
session_stats_.addFileCreated();
|
||||
stats().addFileCreated();
|
||||
}
|
||||
|
||||
// The incoming peer port that's been opened on the local machine
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace libtransmission
|
|||
class EvTimerMaker final : public TimerMaker
|
||||
{
|
||||
public:
|
||||
explicit EvTimerMaker(event_base* base)
|
||||
explicit EvTimerMaker(event_base* base) noexcept
|
||||
: event_base_{ base }
|
||||
{
|
||||
}
|
||||
|
|
|
@ -71,15 +71,15 @@ public:
|
|||
{
|
||||
return blockInfo().blockCount();
|
||||
}
|
||||
[[nodiscard]] constexpr auto byteLoc(uint64_t nth_byte) const
|
||||
[[nodiscard]] constexpr auto byteLoc(uint64_t nth_byte) const noexcept
|
||||
{
|
||||
return blockInfo().byteLoc(nth_byte);
|
||||
}
|
||||
[[nodiscard]] constexpr auto blockLoc(tr_block_index_t block) const
|
||||
[[nodiscard]] constexpr auto blockLoc(tr_block_index_t block) const noexcept
|
||||
{
|
||||
return blockInfo().blockLoc(block);
|
||||
}
|
||||
[[nodiscard]] constexpr auto pieceLoc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const
|
||||
[[nodiscard]] constexpr auto pieceLoc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const noexcept
|
||||
{
|
||||
return blockInfo().pieceLoc(piece, offset, length);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public:
|
|||
{
|
||||
return blockInfo().blockSize(block);
|
||||
}
|
||||
[[nodiscard]] constexpr auto blockSpanForPiece(tr_piece_index_t piece) const
|
||||
[[nodiscard]] constexpr auto blockSpanForPiece(tr_piece_index_t piece) const noexcept
|
||||
{
|
||||
return blockInfo().blockSpanForPiece(piece);
|
||||
}
|
||||
|
|
|
@ -134,31 +134,11 @@ bool tr_torrentSetMetainfoFromFile(tr_torrent* tor, tr_torrent_metainfo const* m
|
|||
return true;
|
||||
}
|
||||
|
||||
bool tr_torrent::isPieceTransferAllowed(tr_direction direction) const
|
||||
{
|
||||
TR_ASSERT(tr_isDirection(direction));
|
||||
|
||||
if (tr_torrentUsesSpeedLimit(this, direction) && this->speedLimitBps(direction) <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tr_torrentUsesSessionLimits(this))
|
||||
{
|
||||
if (auto const limit = session->activeSpeedLimitBps(direction); limit && *limit == 0U)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
static void tr_torrentUnsetPeerId(tr_torrent* tor)
|
||||
static constexpr void tr_torrentUnsetPeerId(tr_torrent* tor)
|
||||
{
|
||||
// triggers a rebuild next time tr_torrentGetPeerId() is called
|
||||
tor->peer_id_ = {};
|
||||
|
@ -188,28 +168,11 @@ tr_peer_id_t const& tr_torrentGetPeerId(tr_torrent* tor)
|
|||
**** PER-TORRENT UL / DL SPEEDS
|
||||
***/
|
||||
|
||||
void tr_torrent::setSpeedLimitBps(tr_direction dir, tr_bytes_per_second_t bytes_per_second)
|
||||
{
|
||||
TR_ASSERT(tr_isDirection(dir));
|
||||
|
||||
if (this->bandwidth_.setDesiredSpeedBytesPerSecond(dir, bytes_per_second))
|
||||
{
|
||||
this->setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void tr_torrentSetSpeedLimit_KBps(tr_torrent* tor, tr_direction dir, tr_kilobytes_per_second_t kilo_per_second)
|
||||
{
|
||||
tor->setSpeedLimitBps(dir, tr_toSpeedBytes(kilo_per_second));
|
||||
}
|
||||
|
||||
tr_bytes_per_second_t tr_torrent::speedLimitBps(tr_direction dir) const
|
||||
{
|
||||
TR_ASSERT(tr_isDirection(dir));
|
||||
|
||||
return this->bandwidth_.getDesiredSpeedBytesPerSecond(dir);
|
||||
}
|
||||
|
||||
tr_kilobytes_per_second_t tr_torrentGetSpeedLimit_KBps(tr_torrent const* tor, tr_direction dir)
|
||||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
|
@ -223,17 +186,14 @@ void tr_torrentUseSpeedLimit(tr_torrent* tor, tr_direction dir, bool do_use)
|
|||
TR_ASSERT(tr_isTorrent(tor));
|
||||
TR_ASSERT(tr_isDirection(dir));
|
||||
|
||||
if (tor->bandwidth_.setLimited(dir, do_use))
|
||||
{
|
||||
tor->setDirty();
|
||||
}
|
||||
tor->useSpeedLimit(dir, do_use);
|
||||
}
|
||||
|
||||
bool tr_torrentUsesSpeedLimit(tr_torrent const* tor, tr_direction dir)
|
||||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
|
||||
return tor->bandwidth_.isLimited(dir);
|
||||
return tor->usesSpeedLimit(dir);
|
||||
}
|
||||
|
||||
void tr_torrentUseSessionLimits(tr_torrent* tor, bool do_use)
|
||||
|
@ -250,7 +210,7 @@ bool tr_torrentUsesSessionLimits(tr_torrent const* tor)
|
|||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
|
||||
return tor->bandwidth_.areParentLimitsHonored(TR_UP);
|
||||
return tor->usesSessionLimits();
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -262,12 +222,7 @@ void tr_torrentSetRatioMode(tr_torrent* tor, tr_ratiolimit mode)
|
|||
TR_ASSERT(tr_isTorrent(tor));
|
||||
TR_ASSERT(mode == TR_RATIOLIMIT_GLOBAL || mode == TR_RATIOLIMIT_SINGLE || mode == TR_RATIOLIMIT_UNLIMITED);
|
||||
|
||||
if (mode != tor->ratioLimitMode)
|
||||
{
|
||||
tor->ratioLimitMode = mode;
|
||||
|
||||
tor->setDirty();
|
||||
}
|
||||
tor->setRatioMode(mode);
|
||||
}
|
||||
|
||||
tr_ratiolimit tr_torrentGetRatioMode(tr_torrent const* tor)
|
||||
|
@ -377,9 +332,9 @@ void tr_torrentSetIdleMode(tr_torrent* tor, tr_idlelimit mode)
|
|||
TR_ASSERT(tr_isTorrent(tor));
|
||||
TR_ASSERT(mode == TR_IDLELIMIT_GLOBAL || mode == TR_IDLELIMIT_SINGLE || mode == TR_IDLELIMIT_UNLIMITED);
|
||||
|
||||
if (mode != tor->idleLimitMode)
|
||||
if (tor->idle_limit_mode_ != mode)
|
||||
{
|
||||
tor->idleLimitMode = mode;
|
||||
tor->idle_limit_mode_ = mode;
|
||||
|
||||
tor->setDirty();
|
||||
}
|
||||
|
@ -389,40 +344,35 @@ tr_idlelimit tr_torrentGetIdleMode(tr_torrent const* tor)
|
|||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
|
||||
return tor->idleLimitMode;
|
||||
return tor->idleLimitMode();
|
||||
}
|
||||
|
||||
void tr_torrentSetIdleLimit(tr_torrent* tor, uint16_t idle_minutes)
|
||||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
|
||||
if (idle_minutes > 0)
|
||||
{
|
||||
tor->idleLimitMinutes = idle_minutes;
|
||||
|
||||
tor->setDirty();
|
||||
}
|
||||
tor->setIdleLimit(idle_minutes);
|
||||
}
|
||||
|
||||
uint16_t tr_torrentGetIdleLimit(tr_torrent const* tor)
|
||||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
|
||||
return tor->idleLimitMinutes;
|
||||
return tor->idleLimitMinutes();
|
||||
}
|
||||
|
||||
bool tr_torrentGetSeedIdle(tr_torrent const* tor, uint16_t* idle_minutes)
|
||||
{
|
||||
auto is_limited = bool{};
|
||||
|
||||
switch (tr_torrentGetIdleMode(tor))
|
||||
switch (tor->idleLimitMode())
|
||||
{
|
||||
case TR_IDLELIMIT_SINGLE:
|
||||
is_limited = true;
|
||||
|
||||
if (idle_minutes != nullptr)
|
||||
{
|
||||
*idle_minutes = tr_torrentGetIdleLimit(tor);
|
||||
*idle_minutes = tor->idleLimitMinutes();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -752,23 +702,23 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
|
|||
|
||||
if ((loaded & tr_resume::Speedlimit) == 0)
|
||||
{
|
||||
tr_torrentUseSpeedLimit(tor, TR_UP, false);
|
||||
tor->useSpeedLimit(TR_UP, false);
|
||||
tor->setSpeedLimitBps(TR_UP, tr_toSpeedBytes(tor->session->speedLimitKBps(TR_UP)));
|
||||
tr_torrentUseSpeedLimit(tor, TR_DOWN, false);
|
||||
tor->useSpeedLimit(TR_DOWN, false);
|
||||
tor->setSpeedLimitBps(TR_DOWN, tr_toSpeedBytes(tor->session->speedLimitKBps(TR_DOWN)));
|
||||
tr_torrentUseSessionLimits(tor, true);
|
||||
}
|
||||
|
||||
if ((loaded & tr_resume::Ratiolimit) == 0)
|
||||
{
|
||||
tr_torrentSetRatioMode(tor, TR_RATIOLIMIT_GLOBAL);
|
||||
tor->setRatioMode(TR_RATIOLIMIT_GLOBAL);
|
||||
tr_torrentSetRatioLimit(tor, tor->session->desiredRatio());
|
||||
}
|
||||
|
||||
if ((loaded & tr_resume::Idlelimit) == 0)
|
||||
{
|
||||
tr_torrentSetIdleMode(tor, TR_IDLELIMIT_GLOBAL);
|
||||
tr_torrentSetIdleLimit(tor, tor->session->idleLimitMinutes());
|
||||
tor->setIdleLimit(tor->session->idleLimitMinutes());
|
||||
}
|
||||
|
||||
auto has_local_data = std::optional<bool>{};
|
||||
|
@ -1423,7 +1373,7 @@ static void torrentStart(tr_torrent* tor, torrent_start_opts opts)
|
|||
if (tr_torrentIsSeedRatioDone(tor))
|
||||
{
|
||||
tr_logAddInfoTor(tor, _("Restarted manually -- disabling its seed ratio"));
|
||||
tr_torrentSetRatioMode(tor, TR_RATIOLIMIT_UNLIMITED);
|
||||
tor->setRatioMode(TR_RATIOLIMIT_UNLIMITED);
|
||||
}
|
||||
|
||||
/* corresponds to the peer_id sent as a tracker request parameter.
|
||||
|
@ -1894,7 +1844,7 @@ tr_priority_t tr_torrentGetPriority(tr_torrent const* tor)
|
|||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
|
||||
return tor->bandwidth_.getPriority();
|
||||
return tor->getPriority();
|
||||
}
|
||||
|
||||
void tr_torrentSetPriority(tr_torrent* tor, tr_priority_t priority)
|
||||
|
@ -1918,9 +1868,9 @@ void tr_torrentSetPeerLimit(tr_torrent* tor, uint16_t max_connected_peers)
|
|||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
|
||||
if (tor->max_connected_peers != max_connected_peers)
|
||||
if (tor->max_connected_peers_ != max_connected_peers)
|
||||
{
|
||||
tor->max_connected_peers = max_connected_peers;
|
||||
tor->max_connected_peers_ = max_connected_peers;
|
||||
|
||||
tor->setDirty();
|
||||
}
|
||||
|
@ -1930,7 +1880,7 @@ uint16_t tr_torrentGetPeerLimit(tr_torrent const* tor)
|
|||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
|
||||
return tor->max_connected_peers;
|
||||
return tor->peerLimit();
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -2428,7 +2378,7 @@ void tr_torrentSetQueuePosition(tr_torrent* tor, size_t queue_position)
|
|||
|
||||
struct CompareTorrentByQueuePosition
|
||||
{
|
||||
bool operator()(tr_torrent const* a, tr_torrent const* b) const
|
||||
constexpr bool operator()(tr_torrent const* a, tr_torrent const* b) const noexcept
|
||||
{
|
||||
return a->queuePosition < b->queuePosition;
|
||||
}
|
||||
|
|
|
@ -61,11 +61,11 @@ bool tr_ctorGetIncompleteDir(tr_ctor const* ctor, char const** setmeIncompleteDi
|
|||
|
||||
void tr_torrentChangeMyPort(tr_torrent* tor);
|
||||
|
||||
tr_torrent* tr_torrentFindFromObfuscatedHash(tr_session* session, tr_sha1_digest_t const& hash);
|
||||
[[nodiscard]] tr_torrent* tr_torrentFindFromObfuscatedHash(tr_session* session, tr_sha1_digest_t const& hash);
|
||||
|
||||
bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_t offset, uint32_t length);
|
||||
|
||||
tr_block_span_t tr_torGetFileBlockSpan(tr_torrent const* tor, tr_file_index_t file);
|
||||
[[nodiscard]] tr_block_span_t tr_torGetFileBlockSpan(tr_torrent const* tor, tr_file_index_t file);
|
||||
|
||||
void tr_torrentCheckSeedLimit(tr_torrent* tor);
|
||||
|
||||
|
@ -123,13 +123,58 @@ public:
|
|||
|
||||
/// SPEED LIMIT
|
||||
|
||||
void setSpeedLimitBps(tr_direction, tr_bytes_per_second_t bytes_per_second);
|
||||
constexpr void setSpeedLimitBps(tr_direction dir, tr_bytes_per_second_t bytes_per_second)
|
||||
{
|
||||
if (bandwidth_.setDesiredSpeedBytesPerSecond(dir, bytes_per_second))
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] tr_bytes_per_second_t speedLimitBps(tr_direction) const;
|
||||
constexpr void useSpeedLimit(tr_direction dir, bool do_use)
|
||||
{
|
||||
if (bandwidth_.setLimited(dir, do_use))
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto speedLimitBps(tr_direction dir) const
|
||||
{
|
||||
return bandwidth_.getDesiredSpeedBytesPerSecond(dir);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto usesSessionLimits() const noexcept
|
||||
{
|
||||
return bandwidth_.areParentLimitsHonored(TR_UP);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto usesSpeedLimit(tr_direction dir) const noexcept
|
||||
{
|
||||
return bandwidth_.isLimited(dir);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto isPieceTransferAllowed(tr_direction direction) const noexcept
|
||||
{
|
||||
if (usesSpeedLimit(direction) && speedLimitBps(direction) <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (usesSessionLimits())
|
||||
{
|
||||
if (auto const limit = session->activeSpeedLimitBps(direction); limit && *limit == 0U)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// BLOCK INFO
|
||||
|
||||
[[nodiscard]] constexpr auto const& blockInfo() const
|
||||
[[nodiscard]] constexpr auto const& blockInfo() const noexcept
|
||||
{
|
||||
return metainfo_.blockInfo();
|
||||
}
|
||||
|
@ -138,15 +183,15 @@ public:
|
|||
{
|
||||
return metainfo_.blockCount();
|
||||
}
|
||||
[[nodiscard]] constexpr auto byteLoc(uint64_t byte) const
|
||||
[[nodiscard]] constexpr auto byteLoc(uint64_t byte) const noexcept
|
||||
{
|
||||
return metainfo_.byteLoc(byte);
|
||||
}
|
||||
[[nodiscard]] constexpr auto blockLoc(tr_block_index_t block) const
|
||||
[[nodiscard]] constexpr auto blockLoc(tr_block_index_t block) const noexcept
|
||||
{
|
||||
return metainfo_.blockLoc(block);
|
||||
}
|
||||
[[nodiscard]] constexpr auto pieceLoc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const
|
||||
[[nodiscard]] constexpr auto pieceLoc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const noexcept
|
||||
{
|
||||
return metainfo_.pieceLoc(piece, offset, length);
|
||||
}
|
||||
|
@ -154,7 +199,7 @@ public:
|
|||
{
|
||||
return metainfo_.blockSize(block);
|
||||
}
|
||||
[[nodiscard]] constexpr auto blockSpanForPiece(tr_piece_index_t piece) const
|
||||
[[nodiscard]] constexpr auto blockSpanForPiece(tr_piece_index_t piece) const noexcept
|
||||
{
|
||||
return metainfo_.blockSpanForPiece(piece);
|
||||
}
|
||||
|
@ -530,8 +575,6 @@ public:
|
|||
return this->isPublic() && this->session->allowsLPD();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isPieceTransferAllowed(tr_direction direction) const;
|
||||
|
||||
[[nodiscard]] bool clientCanDownload() const
|
||||
{
|
||||
return this->isPieceTransferAllowed(TR_PEER_TO_CLIENT);
|
||||
|
@ -581,7 +624,7 @@ public:
|
|||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto id() const noexcept
|
||||
[[nodiscard]] constexpr auto const& id() const noexcept
|
||||
{
|
||||
return unique_id_;
|
||||
}
|
||||
|
@ -612,11 +655,49 @@ public:
|
|||
|
||||
void setBandwidthGroup(std::string_view group_name) noexcept;
|
||||
|
||||
[[nodiscard]] constexpr tr_interned_string const& bandwidthGroup() const noexcept
|
||||
[[nodiscard]] constexpr auto getPriority() const noexcept
|
||||
{
|
||||
return bandwidth_.getPriority();
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto const& bandwidthGroup() const noexcept
|
||||
{
|
||||
return bandwidth_group_;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto idleLimitMode() const noexcept
|
||||
{
|
||||
return idle_limit_mode_;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto idleLimitMinutes() const noexcept
|
||||
{
|
||||
return idle_limit_minutes_;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto peerLimit() const noexcept
|
||||
{
|
||||
return max_connected_peers_;
|
||||
}
|
||||
|
||||
constexpr void setRatioMode(tr_ratiolimit mode) noexcept
|
||||
{
|
||||
if (ratioLimitMode != mode)
|
||||
{
|
||||
ratioLimitMode = mode;
|
||||
setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void setIdleLimit(uint16_t idle_minutes) noexcept
|
||||
{
|
||||
if ((idle_limit_minutes_ != idle_minutes) && (idle_minutes > 0))
|
||||
{
|
||||
idle_limit_minutes_ = idle_minutes;
|
||||
setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
tr_torrent_metainfo metainfo_;
|
||||
|
||||
tr_bandwidth bandwidth_;
|
||||
|
@ -719,11 +800,11 @@ public:
|
|||
float desiredRatio = 0.0F;
|
||||
tr_ratiolimit ratioLimitMode = TR_RATIOLIMIT_GLOBAL;
|
||||
|
||||
tr_idlelimit idleLimitMode = TR_IDLELIMIT_GLOBAL;
|
||||
tr_idlelimit idle_limit_mode_ = TR_IDLELIMIT_GLOBAL;
|
||||
|
||||
uint16_t max_connected_peers = TR_DEFAULT_PEER_LIMIT_TORRENT;
|
||||
uint16_t max_connected_peers_ = TR_DEFAULT_PEER_LIMIT_TORRENT;
|
||||
|
||||
uint16_t idleLimitMinutes = 0;
|
||||
uint16_t idle_limit_minutes_ = 0;
|
||||
|
||||
bool finishedSeedingByIdle = false;
|
||||
|
||||
|
|
|
@ -1013,17 +1013,17 @@ std::string tr_env_get_string(std::string_view key, std::string_view default_val
|
|||
|
||||
void tr_net_init()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
static bool initialized = false;
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
#endif
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// mime-type
|
||||
|
|
|
@ -32,11 +32,9 @@ struct VariantWalkFuncs
|
|||
|
||||
void tr_variantWalk(tr_variant const* top, VariantWalkFuncs const* walk_funcs, void* user_data, bool sort_dicts);
|
||||
|
||||
std::string tr_variantToStrJson(tr_variant const* top, bool lean);
|
||||
[[nodiscard]] std::string tr_variantToStrJson(tr_variant const* top, bool lean);
|
||||
|
||||
std::string tr_variantToStrBenc(tr_variant const* top);
|
||||
|
||||
void tr_variantInit(tr_variant* v, char type);
|
||||
[[nodiscard]] std::string tr_variantToStrBenc(tr_variant const* top);
|
||||
|
||||
/** @brief Private function that's exposed here only for unit tests */
|
||||
[[nodiscard]] std::optional<int64_t> tr_bencParseInt(std::string_view* benc_inout);
|
||||
|
|
|
@ -36,17 +36,11 @@ using namespace std::literals;
|
|||
****
|
||||
***/
|
||||
|
||||
static bool tr_variantIsContainer(tr_variant const* v)
|
||||
static constexpr bool tr_variantIsContainer(tr_variant const* v)
|
||||
{
|
||||
return tr_variantIsList(v) || tr_variantIsDict(v);
|
||||
}
|
||||
|
||||
void tr_variantInit(tr_variant* v, char type)
|
||||
{
|
||||
v->type = type;
|
||||
memset(&v->val, 0, sizeof(v->val));
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
@ -95,15 +89,6 @@ static void tr_variant_string_set_quark(struct tr_variant_string* str, tr_quark
|
|||
str->len = std::size(sv);
|
||||
}
|
||||
|
||||
static void tr_variant_string_set_string_view(struct tr_variant_string* str, std::string_view in)
|
||||
{
|
||||
tr_variant_string_clear(str);
|
||||
|
||||
str->type = TR_STRING_TYPE_VIEW;
|
||||
str->len = std::size(in);
|
||||
str->str.str = std::data(in);
|
||||
}
|
||||
|
||||
static void tr_variant_string_set_string(struct tr_variant_string* str, std::string_view in)
|
||||
{
|
||||
tr_variant_string_clear(str);
|
||||
|
@ -144,7 +129,7 @@ static constexpr char const* getStr(tr_variant const* v)
|
|||
return tr_variant_string_get_string(&v->val.s);
|
||||
}
|
||||
|
||||
static int dictIndexOf(tr_variant const* dict, tr_quark const key)
|
||||
static constexpr int dictIndexOf(tr_variant const* dict, tr_quark const key)
|
||||
{
|
||||
if (tr_variantIsDict(dict))
|
||||
{
|
||||
|
@ -162,7 +147,7 @@ static int dictIndexOf(tr_variant const* dict, tr_quark const key)
|
|||
|
||||
tr_variant* tr_variantDictFind(tr_variant* dict, tr_quark const key)
|
||||
{
|
||||
int const i = dictIndexOf(dict, key);
|
||||
auto const i = dictIndexOf(dict, key);
|
||||
|
||||
return i < 0 ? nullptr : dict->val.l.vals + i;
|
||||
}
|
||||
|
@ -173,11 +158,6 @@ static bool tr_variantDictFindType(tr_variant* dict, tr_quark const key, int typ
|
|||
return tr_variantIsType(*setme, type);
|
||||
}
|
||||
|
||||
size_t tr_variantListSize(tr_variant const* list)
|
||||
{
|
||||
return tr_variantIsList(list) ? list->val.l.count : 0;
|
||||
}
|
||||
|
||||
tr_variant* tr_variantListChild(tr_variant* list, size_t pos)
|
||||
{
|
||||
if (tr_variantIsList(list) && pos < list->val.l.count)
|
||||
|
@ -403,30 +383,6 @@ void tr_variantInitStr(tr_variant* initme, std::string_view str)
|
|||
tr_variant_string_set_string(&initme->val.s, str);
|
||||
}
|
||||
|
||||
void tr_variantInitStrView(tr_variant* initme, std::string_view str)
|
||||
{
|
||||
tr_variantInit(initme, TR_VARIANT_TYPE_STR);
|
||||
tr_variant_string_set_string_view(&initme->val.s, str);
|
||||
}
|
||||
|
||||
void tr_variantInitBool(tr_variant* initme, bool value)
|
||||
{
|
||||
tr_variantInit(initme, TR_VARIANT_TYPE_BOOL);
|
||||
initme->val.b = value;
|
||||
}
|
||||
|
||||
void tr_variantInitReal(tr_variant* initme, double value)
|
||||
{
|
||||
tr_variantInit(initme, TR_VARIANT_TYPE_REAL);
|
||||
initme->val.d = value;
|
||||
}
|
||||
|
||||
void tr_variantInitInt(tr_variant* initme, int64_t value)
|
||||
{
|
||||
tr_variantInit(initme, TR_VARIANT_TYPE_INT);
|
||||
initme->val.i = value;
|
||||
}
|
||||
|
||||
void tr_variantInitList(tr_variant* initme, size_t reserve_count)
|
||||
{
|
||||
tr_variantInit(initme, TR_VARIANT_TYPE_LIST);
|
||||
|
@ -1009,7 +965,7 @@ static void tr_variantListCopy(tr_variant* target, tr_variant const* src)
|
|||
}
|
||||
}
|
||||
|
||||
static size_t tr_variantDictSize(tr_variant const* dict)
|
||||
static constexpr size_t tr_variantDictSize(tr_variant const* dict)
|
||||
{
|
||||
return tr_variantIsDict(dict) ? dict->val.l.count : 0;
|
||||
}
|
||||
|
|
|
@ -172,10 +172,23 @@ bool tr_variantFromBuf(
|
|||
bool tr_variantGetStrView(tr_variant const* variant, std::string_view* setme);
|
||||
|
||||
void tr_variantInitStr(tr_variant* initme, std::string_view);
|
||||
void tr_variantInitStrView(tr_variant* initme, std::string_view);
|
||||
void tr_variantInitQuark(tr_variant* initme, tr_quark const quark);
|
||||
void tr_variantInitRaw(tr_variant* initme, void const* raw, size_t raw_len);
|
||||
|
||||
constexpr void tr_variantInit(tr_variant* initme, char type)
|
||||
{
|
||||
initme->val = {};
|
||||
initme->type = type;
|
||||
}
|
||||
|
||||
constexpr void tr_variantInitStrView(tr_variant* initme, std::string_view in)
|
||||
{
|
||||
tr_variantInit(initme, TR_VARIANT_TYPE_STR);
|
||||
initme->val.s.type = TR_STRING_TYPE_VIEW;
|
||||
initme->val.s.len = std::size(in);
|
||||
initme->val.s.str.str = std::data(in);
|
||||
}
|
||||
|
||||
bool tr_variantGetRaw(tr_variant const* variant, std::byte const** setme_raw, size_t* setme_len);
|
||||
bool tr_variantGetRaw(tr_variant const* variant, uint8_t const** setme_raw, size_t* setme_len);
|
||||
|
||||
|
@ -188,9 +201,14 @@ bool tr_variantGetRaw(tr_variant const* variant, uint8_t const** setme_raw, size
|
|||
return v != nullptr && v->type == TR_VARIANT_TYPE_REAL;
|
||||
}
|
||||
|
||||
void tr_variantInitReal(tr_variant* initme, double value);
|
||||
bool tr_variantGetReal(tr_variant const* variant, double* value_setme);
|
||||
|
||||
constexpr void tr_variantInitReal(tr_variant* initme, double value)
|
||||
{
|
||||
tr_variantInit(initme, TR_VARIANT_TYPE_REAL);
|
||||
initme->val.d = value;
|
||||
}
|
||||
|
||||
/***
|
||||
**** Booleans
|
||||
***/
|
||||
|
@ -200,9 +218,14 @@ bool tr_variantGetReal(tr_variant const* variant, double* value_setme);
|
|||
return v != nullptr && v->type == TR_VARIANT_TYPE_BOOL;
|
||||
}
|
||||
|
||||
void tr_variantInitBool(tr_variant* initme, bool value);
|
||||
bool tr_variantGetBool(tr_variant const* variant, bool* setme);
|
||||
|
||||
constexpr void tr_variantInitBool(tr_variant* initme, bool value)
|
||||
{
|
||||
tr_variantInit(initme, TR_VARIANT_TYPE_BOOL);
|
||||
initme->val.b = value;
|
||||
}
|
||||
|
||||
/***
|
||||
**** Ints
|
||||
***/
|
||||
|
@ -212,9 +235,14 @@ bool tr_variantGetBool(tr_variant const* variant, bool* setme);
|
|||
return v != nullptr && v->type == TR_VARIANT_TYPE_INT;
|
||||
}
|
||||
|
||||
void tr_variantInitInt(tr_variant* initme, int64_t value);
|
||||
bool tr_variantGetInt(tr_variant const* val, int64_t* setme);
|
||||
|
||||
constexpr void tr_variantInitInt(tr_variant* initme, int64_t value)
|
||||
{
|
||||
tr_variantInit(initme, TR_VARIANT_TYPE_INT);
|
||||
initme->val.i = value;
|
||||
}
|
||||
|
||||
/***
|
||||
**** Lists
|
||||
***/
|
||||
|
@ -240,7 +268,11 @@ tr_variant* tr_variantListAddDict(tr_variant* list, size_t reserve_count);
|
|||
tr_variant* tr_variantListChild(tr_variant* list, size_t pos);
|
||||
|
||||
bool tr_variantListRemove(tr_variant* list, size_t pos);
|
||||
[[nodiscard]] size_t tr_variantListSize(tr_variant const* list);
|
||||
|
||||
[[nodiscard]] constexpr size_t tr_variantListSize(tr_variant const* list)
|
||||
{
|
||||
return tr_variantIsList(list) ? list->val.l.count : 0;
|
||||
}
|
||||
|
||||
/***
|
||||
**** Dictionaries
|
||||
|
|
Loading…
Reference in New Issue