build: lint header files with clang-tidy (#7527)

* build: clang-tidy headers when building libtransmission

* chore: revert `= default` workaround

It was introduced in 6909ec0bad to fix build issues with macOS 10.14. We
no longer support that version.

* fix: clang-tidy warnings for libtransmission

* build: clang-tidy headers when building tests

* fix: clang-tidy warnings for tests

* build: clang-tidy headers when building qt

* code review: don't manually edit mime-types.h

* code review: unify variable naming for static private members
This commit is contained in:
Yat Ho
2025-05-08 05:10:16 +08:00
committed by GitHub
parent f0c8fd689a
commit 08ec7fb7c7
78 changed files with 368 additions and 237 deletions
+1
View File
@@ -0,0 +1 @@
libtransmission/mime-types.h linguist-generated=true
+3 -3
View File
@@ -117,9 +117,9 @@ int main(int argc, char** argv)
// init the unit formatters
using Config = libtransmission::Values::Config;
Config::Speed = { Config::Base::Kilo, _("B/s"), _("kB/s"), _("MB/s"), _("GB/s"), _("TB/s") };
Config::Memory = { Config::Base::Kibi, _("B"), _("KiB"), _("MiB"), _("GiB"), _("TiB") };
Config::Storage = { Config::Base::Kilo, _("B"), _("kB"), _("MB"), _("GB"), _("TB") };
Config::speed = { Config::Base::Kilo, _("B/s"), _("kB/s"), _("MB/s"), _("GB/s"), _("TB/s") };
Config::memory = { Config::Base::Kibi, _("B"), _("KiB"), _("MiB"), _("GiB"), _("TiB") };
Config::storage = { Config::Base::Kilo, _("B"), _("kB"), _("MB"), _("GB"), _("TB") };
/* set up the config dir */
if (std::empty(config_dir))
+8 -5
View File
@@ -1,4 +1,6 @@
---
HeaderFilterRegex: .*/libtransmission/.*
# PRs welcome to fix & re-enable any of these explicitly-disabled checks
Checks: >
bugprone-*,
@@ -39,9 +41,10 @@ Checks: >
-readability-qualified-auto,
CheckOptions:
- { key: cppcoreguidelines-avoid-do-while.IgnoreMacros, value: true }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-implicit-bool-conversion.UseUpperCaseLiteralSuffix, value: true }
- { key: cppcoreguidelines-avoid-do-while.IgnoreMacros, value: true }
- { key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor, value: true }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-implicit-bool-conversion.UseUpperCaseLiteralSuffix, value: true }
+1 -1
View File
@@ -115,7 +115,7 @@ public:
TR_CONSTEXPR20 void clear()
{
return trackers_.clear();
trackers_.clear();
}
/**
+11 -11
View File
@@ -40,7 +40,7 @@ struct tr_torrent_announcer;
/** @brief Notification object to tell listeners about announce or scrape occurrences */
struct tr_tracker_event
{
enum class Type
enum class Type : uint8_t
{
Error,
ErrorClear,
@@ -70,7 +70,7 @@ using tr_tracker_callback = std::function<void(tr_torrent&, tr_tracker_event con
class tr_announcer
{
public:
[[nodiscard]] static std::unique_ptr<tr_announcer> create(tr_session* session, tr_announcer_udp&);
[[nodiscard]] static std::unique_ptr<tr_announcer> create(tr_session* session, tr_announcer_udp& announcer_udp);
virtual ~tr_announcer() = default;
virtual tr_torrent_announcer* addTorrent(tr_torrent*, tr_tracker_callback callback) = 0;
@@ -87,24 +87,24 @@ std::unique_ptr<tr_announcer> tr_announcerCreate(tr_session* session);
// --- For torrent customers
void tr_announcerChangeMyPort(tr_torrent*);
void tr_announcerChangeMyPort(tr_torrent* tor);
bool tr_announcerCanManualAnnounce(tr_torrent const*);
bool tr_announcerCanManualAnnounce(tr_torrent const* tor);
void tr_announcerManualAnnounce(tr_torrent*);
void tr_announcerManualAnnounce(tr_torrent* tor);
void tr_announcerTorrentCompleted(tr_torrent*);
void tr_announcerTorrentCompleted(tr_torrent* tor);
enum
enum : uint8_t
{
TR_ANN_UP,
TR_ANN_DOWN,
TR_ANN_CORRUPT
};
void tr_announcerAddBytes(tr_torrent*, int type, uint32_t n_bytes);
void tr_announcerAddBytes(tr_torrent* tor, int type, uint32_t n_bytes);
time_t tr_announcerNextManualAnnounce(tr_torrent const*);
time_t tr_announcerNextManualAnnounce(tr_torrent const* tor);
tr_tracker_view tr_announcerTracker(tr_torrent const* torrent, size_t nth);
@@ -112,7 +112,7 @@ size_t tr_announcerTrackerCount(tr_torrent const* tor);
// --- ANNOUNCE
enum tr_announce_event
enum tr_announce_event : uint8_t
{
/* Note: the ordering of this enum's values is important to
* announcer.c's tr_tier.announce_event_priority. If changing
@@ -147,7 +147,7 @@ public:
virtual ~tr_announcer_udp() noexcept = default;
[[nodiscard]] static std::unique_ptr<tr_announcer_udp> create(Mediator&);
[[nodiscard]] static std::unique_ptr<tr_announcer_udp> create(Mediator& mediator);
virtual void announce(tr_announce_request const& request, tr_announce_response_func on_response) = 0;
+1 -1
View File
@@ -182,7 +182,7 @@ private:
template<std::size_t MaxDepth>
struct ParserStack
{
enum class ParentType
enum class ParentType : uint8_t
{
Array,
Dict
+1 -3
View File
@@ -14,9 +14,7 @@ struct tr_block_info
public:
static auto constexpr BlockSize = uint32_t{ 1024U * 16U };
tr_block_info() noexcept
{
}
tr_block_info() noexcept = default;
tr_block_info(uint64_t const total_size_in, uint32_t const piece_size_in) noexcept
{
+3 -3
View File
@@ -84,13 +84,13 @@ struct tr_completion
[[nodiscard]] constexpr double percent_complete() const
{
auto const denom = block_info_->total_size();
return denom ? std::clamp(double(size_now_) / denom, 0.0, 1.0) : 0.0;
return denom != 0U ? std::clamp(double(size_now_) / denom, 0.0, 1.0) : 0.0;
}
[[nodiscard]] double percent_done() const
{
auto const denom = size_when_done();
return denom ? std::clamp(double(size_now_) / denom, 0.0, 1.0) : 0.0;
return denom != 0U ? std::clamp(double(size_now_) / denom, 0.0, 1.0) : 0.0;
}
[[nodiscard]] uint64_t size_when_done() const;
@@ -155,7 +155,7 @@ struct tr_completion
size_when_done_.reset();
}
[[nodiscard]] uint64_t count_has_bytes_in_span(tr_byte_span_t) const;
[[nodiscard]] uint64_t count_has_bytes_in_span(tr_byte_span_t span) const;
[[nodiscard]] constexpr bool has_metainfo() const noexcept
{
+3 -3
View File
@@ -174,7 +174,7 @@ using tr_sha1_string = tr_strbuf<char, sizeof(tr_sha1_digest_t) * 2U + 1U>;
/**
* @brief Generate an ascii hex string for a sha1 digest.
*/
[[nodiscard]] tr_sha1_string tr_sha1_to_string(tr_sha1_digest_t const&);
[[nodiscard]] tr_sha1_string tr_sha1_to_string(tr_sha1_digest_t const& digest);
/**
* @brief Generate a sha1 digest from a hex string.
@@ -186,7 +186,7 @@ using tr_sha256_string = tr_strbuf<char, sizeof(tr_sha256_digest_t) * 2U + 1U>;
/**
* @brief Generate an ascii hex string for a sha256 digest.
*/
[[nodiscard]] tr_sha256_string tr_sha256_to_string(tr_sha256_digest_t const&);
[[nodiscard]] tr_sha256_string tr_sha256_to_string(tr_sha256_digest_t const& digest);
/**
* @brief Generate a sha256 digest from a hex string.
@@ -196,7 +196,7 @@ using tr_sha256_string = tr_strbuf<char, sizeof(tr_sha256_digest_t) * 2U + 1U>;
// Convenience utility to efficiently get many random small values.
// Use this instead of making a lot of calls to tr_rand_int().
template<typename T = uint8_t, size_t N = 1024U>
class tr_salt_shaker
class tr_salt_shaker // NOLINT(cppcoreguidelines-pro-type-member-init): buf doesn't need to be initialised
{
public:
[[nodiscard]] auto operator()() noexcept
+1 -1
View File
@@ -37,7 +37,7 @@ public:
return code_ != 0;
}
[[nodiscard]] constexpr operator bool() const noexcept
[[nodiscard]] explicit constexpr operator bool() const noexcept
{
return has_value();
}
+18 -13
View File
@@ -90,6 +90,11 @@ public:
maybe_recycle_dh();
}
tr_handshake(tr_handshake const&) = delete;
tr_handshake(tr_handshake&&) = delete;
tr_handshake& operator=(tr_handshake const&) = delete;
tr_handshake& operator=(tr_handshake&&) = delete;
// bittorrent handshake constants
// https://www.bittorrent.org/beps/bep_0003.html#peer-protocol
// https://wiki.theory.org/BitTorrentSpecification#Handshake
@@ -173,19 +178,19 @@ private:
// ---
ReadState read_crypto_provide(tr_peerIo*);
ReadState read_crypto_select(tr_peerIo*);
ReadState read_handshake(tr_peerIo*);
ReadState read_ia(tr_peerIo*);
ReadState read_pad_a(tr_peerIo*);
ReadState read_pad_c(tr_peerIo*);
ReadState read_pad_d(tr_peerIo*);
ReadState read_peer_id(tr_peerIo*);
ReadState read_vc(tr_peerIo*);
ReadState read_ya(tr_peerIo*);
ReadState read_yb(tr_peerIo*);
ReadState read_crypto_provide(tr_peerIo* peer_io);
ReadState read_crypto_select(tr_peerIo* peer_io);
ReadState read_handshake(tr_peerIo* peer_io);
ReadState read_ia(tr_peerIo* peer_io);
ReadState read_pad_a(tr_peerIo* peer_io);
ReadState read_pad_c(tr_peerIo* peer_io);
ReadState read_pad_d(tr_peerIo* peer_io);
ReadState read_peer_id(tr_peerIo* peer_io);
ReadState read_vc(tr_peerIo* peer_io);
ReadState read_ya(tr_peerIo* peer_io);
ReadState read_yb(tr_peerIo* peer_io);
void send_ya(tr_peerIo*);
void send_ya(tr_peerIo* io);
void set_peer_id(tr_peer_id_t const& id) noexcept
{
@@ -228,7 +233,7 @@ private:
static ReadState can_read(tr_peerIo* peer_io, void* vhandshake, size_t* piece);
static void on_error(tr_peerIo* io, tr_error const&, void* vhandshake);
static void on_error(tr_peerIo* io, tr_error const& error, void* vhandshake);
bool build_handshake_message(tr_peerIo* io, libtransmission::BufferWriter<std::byte>& buf) const;
+3 -2
View File
@@ -31,7 +31,7 @@ public:
}
explicit tr_interned_string(char const* c_str)
: tr_interned_string{ std::string_view{ c_str ? c_str : "" } }
: tr_interned_string{ std::string_view{ c_str != nullptr ? c_str : "" } }
{
}
@@ -157,6 +157,7 @@ public:
return *this != std::string_view{ that != nullptr ? that : "" };
}
// NOLINTNEXTLINE(google-explicit-constructor)
[[nodiscard]] constexpr operator std::string_view() const noexcept
{
return sv();
@@ -164,7 +165,7 @@ public:
private:
tr_quark quark_ = TR_KEY_NONE;
std::string_view sv_ = "";
std::string_view sv_;
};
template<>
+3 -3
View File
@@ -50,7 +50,7 @@ public:
tr_log_message** queue_tail_ = &queue_;
int queue_length_ = 0;
size_t queue_length_ = 0;
std::recursive_mutex message_mutex_;
};
@@ -121,14 +121,14 @@ void logAddImpl(
log_state.queue_tail_ = &newmsg->next;
++log_state.queue_length_;
if (log_state.queue_length_ > TR_LOG_MAX_QUEUE_LENGTH)
if (log_state.queue_length_ > TrLogMaxQueueLength)
{
tr_log_message* old = log_state.queue_;
log_state.queue_ = old->next;
old->next = nullptr;
tr_logFreeQueue(old);
--log_state.queue_length_;
TR_ASSERT(log_state.queue_length_ == TR_LOG_MAX_QUEUE_LENGTH);
TR_ASSERT(log_state.queue_length_ == TrLogMaxQueueLength);
}
}
else
+2 -2
View File
@@ -68,7 +68,7 @@ struct tr_log_message
// ---
#define TR_LOG_MAX_QUEUE_LENGTH 10000
inline constexpr auto TrLogMaxQueueLength = 10000U;
void tr_logSetQueueEnabled(bool is_enabled);
@@ -78,7 +78,7 @@ void tr_logFreeQueue(tr_log_message* freeme);
// ---
void tr_logSetLevel(tr_log_level);
void tr_logSetLevel(tr_log_level level);
[[nodiscard]] tr_log_level tr_logGetLevel();
+3 -1
View File
@@ -27,6 +27,8 @@ class tr_metainfo_builder
public:
explicit tr_metainfo_builder(std::string_view single_file_or_parent_directory);
~tr_metainfo_builder() = default;
tr_metainfo_builder(tr_metainfo_builder&&) = delete;
tr_metainfo_builder(tr_metainfo_builder const&) = delete;
tr_metainfo_builder& operator=(tr_metainfo_builder&&) = delete;
@@ -182,7 +184,7 @@ public:
[[nodiscard]] constexpr static bool is_legal_piece_size(uint32_t x)
{
// It must be a power of two and at least 16KiB
auto const MinSize = uint32_t{ 1024U * 16U };
auto constexpr MinSize = uint32_t{ 1024U * 16U };
auto const is_power_of_two = (x & (x - 1)) == 0;
return x >= MinSize && is_power_of_two;
}
+43 -2
View File
@@ -17,9 +17,10 @@ struct mime_type_suffix
std::string_view mime_type;
};
inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
inline auto constexpr MimeTypeSuffixes = std::array<mime_type_suffix, 1291>{
{ { "123", "application/vnd.lotus-1-2-3" },
{ "1km", "application/vnd.1000minds.decision-model+xml" },
{ "210", "model/step" },
{ "3dml", "text/vnd.in3d.3dml" },
{ "3ds", "image/x-3ds" },
{ "3g2", "video/3gpp2" },
@@ -90,16 +91,19 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "azv", "image/vnd.airzip.accelerator.azv" },
{ "azw", "application/vnd.amazon.ebook" },
{ "b16", "image/vnd.pco.b16" },
{ "bary", "model/vnd.bary" },
{ "bat", "application/x-msdownload" },
{ "bcpio", "application/x-bcpio" },
{ "bdf", "application/x-font-bdf" },
{ "bdm", "application/vnd.syncml.dm+wbxml" },
{ "bdo", "application/vnd.nato.bindingdataobject+xml" },
{ "bdoc", "application/bdoc" },
{ "bdoc", "application/x-bdoc" },
{ "bed", "application/vnd.realvnc.bed" },
{ "bh2", "application/vnd.fujitsu.oasysprs" },
{ "bin", "application/octet-stream" },
{ "blb", "application/x-blorb" },
{ "blend", "application/x-blender" },
{ "blorb", "application/x-blorb" },
{ "bmi", "application/vnd.bmi" },
{ "bmml", "application/vnd.balsamiq.bmml+xml" },
@@ -109,6 +113,8 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "box", "application/vnd.previewsystems.box" },
{ "boz", "application/x-bzip2" },
{ "bpk", "application/octet-stream" },
{ "brush", "application/vnd.procreate.brush" },
{ "brushset", "application/vnd.procrate.brushset" },
{ "bsp", "model/vnd.valve.source.compiled-map" },
{ "btf", "image/prs.btif" },
{ "btif", "image/prs.btif" },
@@ -206,6 +212,8 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "davmount", "application/davmount+xml" },
{ "dbf", "application/vnd.dbf" },
{ "dbk", "application/docbook+xml" },
{ "dcm", "application/dicom" },
{ "dcmp", "application/vnd.dcmp+xml" },
{ "dcr", "application/x-director" },
{ "dcurl", "text/vnd.curl.dcurl" },
{ "dd2", "application/vnd.oma.dd2+xml" },
@@ -235,6 +243,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "dmp", "application/vnd.tcpdump.pcap" },
{ "dms", "application/octet-stream" },
{ "dna", "application/vnd.dna" },
{ "dng", "image/x-adobe-dng" },
{ "doc", "application/msword" },
{ "docm", "application/vnd.ms-word.document.macroenabled.12" },
{ "docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
@@ -246,6 +255,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "dpx", "image/dpx" },
{ "dra", "audio/vnd.dra" },
{ "drle", "image/dicom-rle" },
{ "drm", "application/vnd.procreate.dream" },
{ "dsc", "text/prs.lines.tag" },
{ "dssc", "application/dssc+der" },
{ "dtb", "application/x-dtbook+xml" },
@@ -303,6 +313,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "f77", "text/x-fortran" },
{ "f90", "text/x-fortran" },
{ "fbs", "image/vnd.fastbidsheet" },
{ "fbx", "application/vnd.autodesk.fbx" },
{ "fcdt", "application/vnd.adobe.formscentral.fcdt" },
{ "fcs", "application/vnd.isac.fcs" },
{ "fdf", "application/fdf" },
@@ -348,17 +359,22 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "gca", "application/x-gca-compressed" },
{ "gdl", "model/vnd.gdl" },
{ "gdoc", "application/vnd.google-apps.document" },
{ "gdraw", "application/vnd.google-apps.drawing" },
{ "ged", "text/vnd.familysearch.gedcom" },
{ "geo", "application/vnd.dynageo" },
{ "geojson", "application/geo+json" },
{ "gex", "application/vnd.geometry-explorer" },
{ "gform", "application/vnd.google-apps.form" },
{ "ggb", "application/vnd.geogebra.file" },
{ "ggs", "application/vnd.geogebra.slides" },
{ "ggt", "application/vnd.geogebra.tool" },
{ "ghf", "application/vnd.groove-help" },
{ "gif", "image/gif" },
{ "gim", "application/vnd.groove-identity-message" },
{ "gjam", "application/vnd.google-apps.jam" },
{ "glb", "model/gltf-binary" },
{ "gltf", "model/gltf+json" },
{ "gmap", "application/vnd.google-apps.map" },
{ "gml", "application/gml+xml" },
{ "gmx", "application/vnd.gmx" },
{ "gnumeric", "application/x-gnumeric" },
@@ -371,8 +387,10 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "gre", "application/vnd.geometry-explorer" },
{ "grv", "application/vnd.groove-injector" },
{ "grxml", "application/srgs+xml" },
{ "gscript", "application/vnd.google-apps.script" },
{ "gsf", "application/x-font-ghostscript" },
{ "gsheet", "application/vnd.google-apps.spreadsheet" },
{ "gsite", "application/vnd.google-apps.site" },
{ "gslides", "application/vnd.google-apps.presentation" },
{ "gtar", "application/x-gtar" },
{ "gtm", "application/vnd.groove-tool-message" },
@@ -403,7 +421,6 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "hpid", "application/vnd.hp-hpid" },
{ "hps", "application/vnd.hp-hps" },
{ "hqx", "application/mac-binhex40" },
{ "hsj2", "image/hsj2" },
{ "htc", "text/x-component" },
{ "htke", "application/vnd.kenameaapp" },
{ "htm", "text/html" },
@@ -438,6 +455,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "iota", "application/vnd.astraea-software.iota" },
{ "ipfix", "application/ipfix" },
{ "ipk", "application/vnd.shana.informed.package" },
{ "ipynb", "application/x-ipynb+json" },
{ "irm", "application/vnd.ibm.rights-management" },
{ "irp", "application/vnd.irepository.package+xml" },
{ "iso", "application/octet-stream" },
@@ -448,10 +466,13 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "ivu", "application/vnd.immervision-ivu" },
{ "jad", "text/vnd.sun.j2me.app-descriptor" },
{ "jade", "text/jade" },
{ "jaii", "image/jaii" },
{ "jais", "image/jais" },
{ "jam", "application/vnd.jam" },
{ "jar", "application/java-archive" },
{ "jardiff", "application/x-java-archive-diff" },
{ "java", "text/x-java-source" },
{ "jfif", "image/pjpeg" },
{ "jhc", "image/jphc" },
{ "jisp", "application/vnd.jisp" },
{ "jls", "image/jls" },
@@ -480,6 +501,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "jsonml", "application/jsonml+json" },
{ "jsx", "text/jsx" },
{ "jt", "model/jt" },
{ "jxl", "image/jxl" },
{ "jxr", "image/jxr" },
{ "jxra", "image/jxra" },
{ "jxrs", "image/jxrs" },
@@ -525,6 +547,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "lnk", "application/x-ms-shortcut" },
{ "log", "text/plain" },
{ "lostxml", "application/lost+xml" },
{ "lottie", "application/zip+dotlottie" },
{ "lrf", "application/octet-stream" },
{ "lrm", "application/vnd.ms-lrm" },
{ "ltf", "application/vnd.frogans.ltf" },
@@ -538,12 +561,15 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "m1v", "video/mpeg" },
{ "m21", "application/mp21" },
{ "m2a", "audio/mpeg" },
{ "m2t", "video/mp2t" },
{ "m2ts", "video/mp2t" },
{ "m2v", "video/mpeg" },
{ "m3a", "audio/mpeg" },
{ "m3u", "audio/x-mpegurl" },
{ "m3u8", "application/vnd.apple.mpegurl" },
{ "m4a", "audio/mp4" },
{ "m4a", "audio/x-m4a" },
{ "m4b", "audio/mp4" },
{ "m4p", "application/mp4" },
{ "m4s", "video/iso.segment" },
{ "m4u", "video/vnd.mpegurl" },
@@ -578,6 +604,8 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "mft", "application/rpki-manifest" },
{ "mgp", "application/vnd.osgeo.mapguide.package" },
{ "mgz", "application/vnd.proteus.magazine" },
{ "mht", "message/rfc822" },
{ "mhtml", "message/rfc822" },
{ "mid", "audio/midi" },
{ "midi", "audio/midi" },
{ "mie", "application/x-mie" },
@@ -648,6 +676,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "msty", "application/vnd.muvee.style" },
{ "mtl", "model/mtl" },
{ "mts", "model/vnd.mts" },
{ "mts", "video/mp2t" },
{ "mus", "application/vnd.musician" },
{ "musd", "application/mmt-usd+xml" },
{ "musicxml", "application/vnd.recordare.musicxml+xml" },
@@ -707,6 +736,8 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "ogv", "video/ogg" },
{ "ogx", "application/ogg" },
{ "omdoc", "application/omdoc+xml" },
{ "one", "application/onenote" },
{ "onea", "application/onenote" },
{ "onepkg", "application/onenote" },
{ "onetmp", "application/onenote" },
{ "onetoc", "application/onenote" },
@@ -736,6 +767,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "p", "text/x-pascal" },
{ "p10", "application/pkcs10" },
{ "p12", "application/x-pkcs12" },
{ "p21", "model/step" },
{ "p7b", "application/x-pkcs7-certificates" },
{ "p7c", "application/pkcs7-mime" },
{ "p7m", "application/pkcs7-mime" },
@@ -836,6 +868,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "raml", "application/raml+yaml" },
{ "rapd", "application/route-apd+xml" },
{ "rar", "application/vnd.rar" },
{ "rar", "application/x-compressed" },
{ "rar", "application/x-rar-compressed" },
{ "ras", "image/x-cmu-raster" },
{ "rcprofile", "application/vnd.ipunplugged.rcprofile" },
@@ -967,11 +1000,14 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "st", "application/vnd.sailingtracker.track" },
{ "stc", "application/vnd.sun.xml.calc.template" },
{ "std", "application/vnd.sun.xml.draw.template" },
{ "step", "model/step" },
{ "stf", "application/vnd.wt.stf" },
{ "sti", "application/vnd.sun.xml.impress.template" },
{ "stk", "application/hyperstudio" },
{ "stl", "application/vnd.ms-pki.stl" },
{ "stl", "model/stl" },
{ "stp", "model/step" },
{ "stpnc", "model/step" },
{ "stpx", "model/step+xml" },
{ "stpxz", "model/step-xml+zip" },
{ "stpz", "model/step+zip" },
@@ -1106,6 +1142,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "vcx", "application/vnd.vcx" },
{ "vdi", "application/x-virtualbox-vdi" },
{ "vds", "model/vnd.sap.vds" },
{ "vdx", "application/vnd.ms-visio.viewer" },
{ "vhd", "application/x-virtualbox-vhd" },
{ "vis", "application/vnd.visionary" },
{ "viv", "video/vnd.vivo" },
@@ -1115,6 +1152,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "vox", "application/x-authorware-bin" },
{ "vrml", "model/vrml" },
{ "vsd", "application/vnd.visio" },
{ "vsdx", "application/vnd.visio" },
{ "vsf", "application/vnd.vsf" },
{ "vss", "application/vnd.visio" },
{ "vst", "application/vnd.visio" },
@@ -1122,6 +1160,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "vtf", "image/vnd.valve.source.texture" },
{ "vtt", "text/vtt" },
{ "vtu", "model/vnd.vtu" },
{ "vtx", "application/vnd.visio" },
{ "vxml", "application/voicexml+xml" },
{ "w3d", "application/x-director" },
{ "wad", "application/x-doom" },
@@ -1194,6 +1233,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "xbm", "image/x-xbitmap" },
{ "xca", "application/xcap-caps+xml" },
{ "xcs", "application/calendar+xml" },
{ "xdcf", "application/vnd.gov.sk.xmldatacontainer+xml" },
{ "xdf", "application/xcap-diff+xml" },
{ "xdm", "application/vnd.syncml.dm+xml" },
{ "xdp", "application/vnd.adobe.xdp+xml" },
@@ -1264,6 +1304,7 @@ inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, 1250>{
{ "z7", "application/x-zmachine" },
{ "z8", "application/x-zmachine" },
{ "zaz", "application/vnd.zzazz.deck+xml" },
{ "zip", "application/x-zip-compressed" },
{ "zip", "application/zip" },
{ "zir", "application/vnd.zul" },
{ "zirz", "application/vnd.zul" },
+1 -1
View File
@@ -52,7 +52,7 @@ struct mime_type_suffix
std::string_view mime_type;
};
inline auto constexpr mime_type_suffixes = std::array<mime_type_suffix, ${suffixes.length}>{
inline auto constexpr MimeTypeSuffixes = std::array<mime_type_suffix, ${suffixes.length}>{
{ ${mime_type_lines.trim()} }
};
`);
+2 -3
View File
@@ -487,7 +487,7 @@ std::pair<tr_port, std::byte const*> tr_port::from_compact(std::byte const* comp
std::optional<tr_address> tr_address::from_string(std::string_view address_sv)
{
auto const address_sz = tr_strbuf<char, TR_ADDRSTRLEN>{ address_sv };
auto const address_sz = tr_strbuf<char, TrAddrStrlen>{ address_sv };
auto ss = sockaddr_storage{};
auto sslen = int{ sizeof(ss) };
@@ -814,8 +814,7 @@ std::optional<tr_socket_address> tr_socket_address::from_string(std::string_view
{
auto ss = sockaddr_storage{};
auto sslen = int{ sizeof(ss) };
if (evutil_parse_sockaddr_port(tr_strbuf<char, TR_ADDRSTRLEN>{ sockaddr_sv }, reinterpret_cast<sockaddr*>(&ss), &sslen) !=
0)
if (evutil_parse_sockaddr_port(tr_strbuf<char, TrAddrStrlen>{ sockaddr_sv }, reinterpret_cast<sockaddr*>(&ss), &sslen) != 0)
{
return {};
}
+6 -5
View File
@@ -194,7 +194,7 @@ struct tr_address
}
template<typename OutputIt>
OutputIt to_compact(OutputIt out) const
OutputIt to_compact(OutputIt out) const // NOLINT(modernize-use-nodiscard)
{
switch (type)
{
@@ -255,7 +255,7 @@ struct tr_address
{
struct in6_addr addr6;
struct in_addr addr4;
} addr;
} addr = {};
static auto constexpr CompactAddrBytes = std::array{ 4U, 16U };
static auto constexpr CompactAddrMaxBytes = *std::max_element(std::begin(CompactAddrBytes), std::end(CompactAddrBytes));
@@ -362,7 +362,7 @@ struct tr_socket_address
}
template<typename OutputIt>
OutputIt to_compact(OutputIt out) const
OutputIt to_compact(OutputIt out) const // NOLINT(modernize-use-nodiscard)
{
return to_compact(out, address_, port_);
}
@@ -389,7 +389,7 @@ struct tr_socket_address
// --- sockaddr helpers
[[nodiscard]] static std::optional<tr_socket_address> from_string(std::string_view sockaddr_sv);
[[nodiscard]] static std::optional<tr_socket_address> from_sockaddr(sockaddr const*);
[[nodiscard]] static std::optional<tr_socket_address> from_sockaddr(sockaddr const* from);
[[nodiscard]] static std::pair<sockaddr_storage, socklen_t> to_sockaddr(tr_address const& addr, tr_port port) noexcept;
[[nodiscard]] std::pair<sockaddr_storage, socklen_t> to_sockaddr() const noexcept
@@ -488,12 +488,13 @@ public:
{
}
// NOLINTNEXTLINE(google-explicit-constructor)
[[nodiscard]] constexpr operator int() const noexcept
{
return value_;
}
[[nodiscard]] static std::optional<tr_tos_t> from_string(std::string_view);
[[nodiscard]] static std::optional<tr_tos_t> from_string(std::string_view name);
[[nodiscard]] std::string toString() const;
+3 -1
View File
@@ -67,7 +67,7 @@ private:
// remove-during-emit; this is meant to be as lightweight
// as possible for very basic use cases.
template<typename... Args>
class SimpleObservable
class SimpleObservable // NOLINT(cppcoreguidelines-special-member-functions)
{
using Key = size_t;
@@ -104,6 +104,8 @@ private:
TR_ASSERT(n_removed == 1U);
}
// TODO: Re-enable after setting readability-identifier-naming.PrivateMemberSuffix to _
// NOLINTNEXTLINE(readability-identifier-naming)
static auto inline next_key_ = Key{ 1U };
small::map<Key, Observer, 4U> observers_;
};
+3 -3
View File
@@ -45,7 +45,7 @@ class tr_peer_event
}
public:
enum class Type
enum class Type : uint8_t
{
// Unless otherwise specified, all events are for BT peers only
ClientGotBlock, // applies to webseed too
@@ -275,9 +275,9 @@ struct tr_swarm_stats
// connected peers
uint16_t peer_count;
// connected peers by peer source
std::array<uint16_t, TR_PEER_FROM__MAX> peer_from_count;
std::array<uint16_t, TR_PEER_FROM_N_TYPES> peer_from_count;
// known peers by peer source
std::array<uint16_t, TR_PEER_FROM__MAX> known_peer_from_count;
std::array<uint16_t, TR_PEER_FROM_N_TYPES> known_peer_from_count;
};
tr_swarm_stats tr_swarmGetStats(tr_swarm const* swarm);
+8 -3
View File
@@ -59,8 +59,8 @@ class tr_peerIo final : public std::enable_shared_from_this<tr_peerIo>
using DH = tr_message_stream_encryption::DH;
using Filter = tr_message_stream_encryption::Filter;
using CanRead = ReadState (*)(tr_peerIo* io, void* user_data, size_t* setme_piece_byte_count);
using DidWrite = void (*)(tr_peerIo* io, size_t bytesWritten, bool wasPieceData, void* userData);
using GotError = void (*)(tr_peerIo* io, tr_error const& error, void* userData);
using DidWrite = void (*)(tr_peerIo* io, size_t bytes_written, bool was_piece_data, void* user_data);
using GotError = void (*)(tr_peerIo* io, tr_error const& error, void* user_data);
public:
tr_peerIo(
@@ -73,6 +73,11 @@ public:
~tr_peerIo();
tr_peerIo(tr_peerIo const&) = delete;
tr_peerIo(tr_peerIo&&) = delete;
tr_peerIo& operator=(tr_peerIo const&) = delete;
tr_peerIo& operator=(tr_peerIo&&) = delete;
static std::shared_ptr<tr_peerIo> new_outgoing(
tr_session* session,
tr_bandwidth* parent,
@@ -96,7 +101,7 @@ public:
set_callbacks(nullptr, nullptr, nullptr, nullptr);
}
void set_socket(tr_peer_socket);
void set_socket(tr_peer_socket socket_in);
[[nodiscard]] constexpr auto is_utp() const noexcept
{
+2 -2
View File
@@ -468,7 +468,7 @@ public:
tr_peer_from const from)
{
TR_ASSERT(socket_address.is_valid());
TR_ASSERT(from < TR_PEER_FROM__MAX);
TR_ASSERT(from < TR_PEER_FROM_N_TYPES);
auto peer_info = get_existing_peer_info(socket_address);
if (peer_info)
@@ -2585,7 +2585,7 @@ namespace connect_helpers
/* Prefer peers that we got from more trusted sources.
* lower `fromBest` values indicate more trusted sources */
score = addValToKey(score, 4U, peer_info.from_best()); // TODO(tearfur): use std::bit_width(TR_PEER_FROM__MAX - 1)
score = addValToKey(score, 4U, peer_info.from_best()); // TODO(tearfur): use std::bit_width(TR_PEER_FROM_N_TYPES - 1)
/* salt */
score = addValToKey(score, 8U, salt);
+3 -3
View File
@@ -39,7 +39,7 @@ struct tr_session;
struct tr_torrent;
/* added_f's bitwise-or'ed flags */
enum
enum : uint8_t
{
/* true if the peer supports encryption */
ADDED_F_ENCRYPTION_FLAG = 1,
@@ -561,7 +561,7 @@ struct tr_pex
}
template<typename OutputIt>
OutputIt to_compact(OutputIt out) const
OutputIt to_compact(OutputIt out) const // NOLINT(modernize-use-nodiscard)
{
return socket_address.to_compact(out);
}
@@ -653,7 +653,7 @@ void tr_peerMgrAddIncoming(tr_peerMgr* manager, tr_peer_socket&& socket);
size_t tr_peerMgrAddPex(tr_torrent* tor, tr_peer_from from, tr_pex const* pex, size_t n_pex);
enum
enum : uint8_t
{
TR_PEERS_CONNECTED,
TR_PEERS_INTERESTING
+2 -2
View File
@@ -76,7 +76,7 @@ private:
class Filter
{
public:
void decrypt_init(bool is_incoming, DH const&, tr_sha1_digest_t const& info_hash);
void decrypt_init(bool is_incoming, DH const& dh, tr_sha1_digest_t const& info_hash);
constexpr void decrypt_disable() noexcept
{
dec_active_ = false;
@@ -88,7 +88,7 @@ public:
process(buf_in, buf_len, buf_out, dec_active_, dec_key_);
}
void encrypt_init(bool is_incoming, DH const&, tr_sha1_digest_t const& info_hash);
void encrypt_init(bool is_incoming, DH const& dh, tr_sha1_digest_t const& info_hash);
constexpr void encrypt_disable() noexcept
{
enc_active_ = false;
+1 -1
View File
@@ -1179,7 +1179,7 @@ void tr_peerMsgsImpl::send_ltep_handshake()
// you as. i.e. this is the receiver's external ip address (no port is included).
// This may be either an IPv4 (4 bytes) or an IPv6 (16 bytes) address.
{
auto buf = std::array<std::byte, TR_ADDRSTRLEN>{};
auto buf = std::array<std::byte, TrAddrStrlen>{};
auto const begin = std::data(buf);
auto const end = io_->address().to_compact(begin);
auto const len = end - begin;
+5
View File
@@ -45,6 +45,11 @@ public:
~tr_peerMsgs() override;
tr_peerMsgs(tr_peerMsgs const&) = delete;
tr_peerMsgs(tr_peerMsgs&&) = delete;
tr_peerMsgs& operator=(tr_peerMsgs const&) = delete;
tr_peerMsgs& operator=(tr_peerMsgs&&) = delete;
[[nodiscard]] static auto size() noexcept
{
return n_peers.load();
+3 -1
View File
@@ -103,7 +103,7 @@ public:
[[nodiscard]] static bool limit_reached(tr_session const* session) noexcept;
private:
enum class Type
enum class Type : uint8_t
{
None,
TCP,
@@ -114,5 +114,7 @@ private:
enum Type type_ = Type::None;
// TODO: Re-enable after setting readability-identifier-naming.PrivateMemberSuffix to _
// NOLINTNEXTLINE(readability-identifier-naming)
static inline std::atomic<size_t> n_open_sockets_ = {};
};
+1 -1
View File
@@ -14,7 +14,7 @@
struct tr_session;
/** @brief return the directory where the Web Client's web ui files are kept */
[[nodiscard]] std::string tr_getWebClientDir(tr_session const*);
[[nodiscard]] std::string tr_getWebClientDir(tr_session const* session);
/** @brief return the directory where session id lock files are stored */
[[nodiscard]] std::string tr_getSessionIdDir();
+6 -1
View File
@@ -31,6 +31,11 @@ public:
closenatpmp(&natpmp_);
}
tr_natpmp(tr_natpmp const&) = delete;
tr_natpmp(tr_natpmp&&) = delete;
tr_natpmp& operator=(tr_natpmp const&) = delete;
tr_natpmp& operator=(tr_natpmp&&) = delete;
[[nodiscard]] constexpr auto renewTime() const noexcept
{
return renew_time_;
@@ -47,7 +52,7 @@ public:
PulseResult pulse(tr_port local_port, bool is_enabled);
private:
enum class State
enum class State : uint8_t
{
Idle,
Err,
+2 -2
View File
@@ -26,7 +26,7 @@
#include "libtransmission/net.h"
#include "libtransmission/port-forwarding-upnp.h"
#include "libtransmission/tr-assert.h"
#include "libtransmission/tr-macros.h" // TR_ADDRSTRLEN
#include "libtransmission/tr-macros.h" // TrAddrStrlen
#include "libtransmission/utils.h" // for _(), tr_strerror()
#ifndef MINIUPNPC_API_VERSION
@@ -260,7 +260,7 @@ tr_port_forwarding_state tr_upnpPulse(
handle->discover_future.reset();
FreeUPNPUrls(&handle->urls);
auto lanaddr = std::array<char, TR_ADDRSTRLEN>{};
auto lanaddr = std::array<char, TrAddrStrlen>{};
if (
#if (MINIUPNPC_API_VERSION >= 18)
UPNP_GetValidIGD(devlist, &handle->urls, &handle->data, std::data(lanaddr), std::size(lanaddr) - 1, nullptr, 0)
+1 -1
View File
@@ -26,7 +26,7 @@ tr_upnp* tr_upnpInit();
void tr_upnpClose(tr_upnp* handle);
tr_port_forwarding_state tr_upnpPulse(
tr_upnp*,
tr_upnp* handle,
tr_port advertised_port,
tr_port local_port,
bool is_enabled,
+1 -1
View File
@@ -35,7 +35,7 @@ public:
virtual void on_port_forwarded(tr_port advertised_port) = 0;
};
[[nodiscard]] static std::unique_ptr<tr_port_forwarding> create(Mediator&);
[[nodiscard]] static std::unique_ptr<tr_port_forwarding> create(Mediator& mediator);
virtual ~tr_port_forwarding() = default;
[[nodiscard]] virtual bool is_enabled() const = 0;
+1 -1
View File
@@ -19,7 +19,7 @@ using tr_quark = size_t;
* between RPC and settings. This will be a mess and we shouldn't be
* in a hurry to do it.
*/
enum
enum // NOLINT(performance-enum-size)
{
TR_KEY_NONE, /* represented as an empty string */
TR_KEY_activeTorrentCount, /* rpc */
+4 -4
View File
@@ -54,13 +54,13 @@ public:
bool is_whitelist_enabled = true;
size_t anti_brute_force_limit = 100U;
std::string bind_address_str = "0.0.0.0";
std::string host_whitelist_str = "";
std::string salted_password = "";
std::string host_whitelist_str;
std::string salted_password;
std::string url = TR_DEFAULT_RPC_URL_STR;
std::string username = "";
std::string username;
std::string whitelist_str = TR_DEFAULT_RPC_WHITELIST;
tr_mode_t socket_mode = 0750;
tr_port port = tr_port::from_host(TR_DEFAULT_RPC_PORT);
tr_port port = tr_port::from_host(TrDefaultRpcPort);
private:
[[nodiscard]] Fields fields() override
+3 -3
View File
@@ -180,9 +180,9 @@ private:
// whether `time` hits in one of the `minutes_` that is true
[[nodiscard]] bool is_active_minute(time_t time) const noexcept;
static auto constexpr MinutesPerHour = int{ 60 };
static auto constexpr MinutesPerDay = int{ MinutesPerHour * 24 };
static auto constexpr MinutesPerWeek = int{ MinutesPerDay * 7 };
static int constexpr MinutesPerHour = 60;
static int constexpr MinutesPerDay = MinutesPerHour * 24;
static int constexpr MinutesPerWeek = MinutesPerDay * 7;
// bitfield of all the minutes in a week.
// Each bit's value indicates whether the scheduler wants
+1 -1
View File
@@ -36,7 +36,7 @@ public:
* relative paths to absolute before passing through RPC, or presenting
* different UI for local and remote sessions.
*/
[[nodiscard]] static bool is_local(std::string_view) noexcept;
[[nodiscard]] static bool is_local(std::string_view session_id) noexcept;
// current session identifier
[[nodiscard]] std::string_view sv() const noexcept;
+10 -2
View File
@@ -34,12 +34,20 @@ public:
template<typename Func, typename... Args>
void queue(Func&& func, Args&&... args)
{
queue(std::function<void(void)>{ std::bind(std::forward<Func>(func), std::forward<Args>(args)...) });
// TODO(tearfur): Use C++20 P0780R2, GCC 9, clang 9
queue(std::function<void(void)>{
[func = std::forward<Func>(func), args = std::make_tuple(std::forward<Args>(args)...)]()
{ std::apply(std::move(func), std::move(args)); },
});
}
template<typename Func, typename... Args>
void run(Func&& func, Args&&... args)
{
run(std::function<void(void)>{ std::bind(std::forward<Func>(func), std::forward<Args>(args)...) });
// TODO(tearfur): Use C++20 P0780R2, GCC 9, clang 9
run(std::function<void(void)>{
[func = std::forward<Func>(func), args = std::make_tuple(std::forward<Args>(args)...)]()
{ std::apply(std::move(func), std::move(args)); },
});
}
};
+12 -7
View File
@@ -163,7 +163,7 @@ private:
class DhtMediator : public tr_dht::Mediator
{
public:
DhtMediator(tr_session& session) noexcept
explicit DhtMediator(tr_session& session) noexcept
: session_{ session }
{
}
@@ -184,7 +184,7 @@ private:
return session_.timerMaker();
}
void add_pex(tr_sha1_digest_t const&, tr_pex const* pex, size_t n_pex) override;
void add_pex(tr_sha1_digest_t const& info_hash, tr_pex const* pex, size_t n_pex) override;
private:
tr_session& session_;
@@ -353,6 +353,11 @@ private:
tr_udp_core(tr_session& session, tr_port udp_port);
~tr_udp_core();
tr_udp_core(tr_udp_core const&) = delete;
tr_udp_core(tr_udp_core&&) = delete;
tr_udp_core& operator=(tr_udp_core const&) = delete;
tr_udp_core& operator=(tr_udp_core&&) = delete;
void sendto(void const* buf, size_t buflen, struct sockaddr const* to, socklen_t tolen) const;
[[nodiscard]] constexpr auto socket4() const noexcept
@@ -416,8 +421,8 @@ public:
size_t cache_size_mbytes = 4U;
size_t download_queue_size = 5U;
size_t idle_seeding_limit_minutes = 30U;
size_t peer_limit_global = TR_DEFAULT_PEER_LIMIT_GLOBAL;
size_t peer_limit_per_torrent = TR_DEFAULT_PEER_LIMIT_TORRENT;
size_t peer_limit_global = TrDefaultPeerLimitGlobal;
size_t peer_limit_per_torrent = TrDefaultPeerLimitTorrent;
size_t queue_stalled_minutes = 30U;
size_t reqq = 2000U;
size_t seed_queue_size = 10U;
@@ -444,7 +449,7 @@ public:
tr_open_files::Preallocation preallocation_mode = tr_open_files::Preallocation::Sparse;
tr_port peer_port_random_high = tr_port::from_host(65535);
tr_port peer_port_random_low = tr_port::from_host(49152);
tr_port peer_port = tr_port::from_host(TR_DEFAULT_PEER_PORT);
tr_port peer_port = tr_port::from_host(TrDefaultPeerPort);
tr_tos_t peer_socket_tos{ 0x04 };
tr_verify_added_mode torrent_added_verify_mode = TR_VERIFY_ADDED_FAST;
@@ -1103,6 +1108,7 @@ public:
void addTorrent(tr_torrent* tor);
// NOLINTNEXTLINE(readability-make-member-function-const)
void maybe_add_dht_node(tr_address const& addr, tr_port port)
{
if (dht_)
@@ -1149,7 +1155,7 @@ private:
void onAdvertisedPeerPortChanged();
struct init_data;
void initImpl(init_data&);
void initImpl(init_data& data);
void setSettings(tr_variant const& settings_map, bool force);
void setSettings(Settings&& settings, bool force);
@@ -1311,7 +1317,6 @@ private:
QueueMediator torrent_queue_mediator_{ *this };
tr_torrent_queue torrent_queue_{ torrent_queue_mediator_ };
private:
/// other fields
// depends-on: session_thread_, settings_.bind_address_ipv4, local_peer_port_, global_ip_cache (via tr_session::bind_address())
+5
View File
@@ -33,6 +33,11 @@ public:
save();
}
tr_stats(tr_stats const&) = delete;
tr_stats(tr_stats&&) = delete;
tr_stats& operator=(tr_stats const&) = delete;
tr_stats& operator=(tr_stats&&) = delete;
void clear();
[[nodiscard]] tr_session_stats current() const;
+2 -1
View File
@@ -31,6 +31,7 @@ public:
: mediator_{ mediator }
{
}
~tr_torrent_queue() = default;
tr_torrent_queue(tr_torrent_queue const&) = delete;
tr_torrent_queue(tr_torrent_queue&&) = delete;
tr_torrent_queue& operator=(tr_torrent_queue const&) = delete;
@@ -42,7 +43,7 @@ public:
[[nodiscard]] size_t get_pos(tr_torrent_id_t id);
void set_pos(tr_torrent_id_t id, size_t new_pos);
bool to_file() const;
bool to_file() const; // NOLINT(modernize-use-nodiscard)
[[nodiscard]] std::vector<std::string> from_file();
static auto constexpr MinQueuePosition = size_t{};
+1 -1
View File
@@ -1285,7 +1285,7 @@ tr_stat tr_torrent::stats() const
stats.peersGettingFromUs = swarm_stats.active_peer_count[TR_UP];
stats.webseedsSendingToUs = swarm_stats.active_webseed_count;
for (int i = 0; i < TR_PEER_FROM__MAX; i++)
for (int i = 0; i < TR_PEER_FROM_N_TYPES; i++)
{
stats.peersFrom[i] = swarm_stats.peer_from_count[i];
stats.knownPeersFrom[i] = swarm_stats.known_peer_from_count[i];
+3 -3
View File
@@ -95,7 +95,7 @@ struct tr_torrent
friend class libtransmission::test::RenameTest_singleFilenameTorrent_Test;
friend struct tr_torrent;
ResumeHelper(tr_torrent& tor)
explicit ResumeHelper(tr_torrent& tor)
: tor_{ tor }
{
}
@@ -965,7 +965,7 @@ struct tr_torrent
return session->torrent_queue().get_pos(id());
}
void set_queue_position(size_t new_pos)
void set_queue_position(size_t new_pos) // NOLINT(readability-make-member-function-const)
{
session->torrent_queue().set_pos(id(), new_pos);
}
@@ -1393,7 +1393,7 @@ private:
uint16_t idle_limit_minutes_ = 0;
uint16_t max_connected_peers_ = TR_DEFAULT_PEER_LIMIT_TORRENT;
uint16_t max_connected_peers_ = TrDefaultPeerLimitTorrent;
bool is_deleting_ = false;
bool is_dirty_ = false;
+1 -1
View File
@@ -42,7 +42,7 @@ public:
for (size_t i = 0, j = 0; i < 256; ++i)
{
j = static_cast<uint8_t>(j + s_[i] + ((uint8_t const*)key)[i % key_length]);
j = static_cast<uint8_t>(j + s_[i] + reinterpret_cast<uint8_t const*>(key)[i % key_length]);
arc4_swap(i, j);
}
}
+1
View File
@@ -255,6 +255,7 @@ class StackBuffer final
{
public:
StackBuffer() = default;
~StackBuffer() override = default;
StackBuffer(StackBuffer&&) = delete;
StackBuffer(StackBuffer const&) = delete;
StackBuffer& operator=(StackBuffer&&) = delete;
+3 -1
View File
@@ -5,6 +5,8 @@
#pragma once
#include <cstdint>
/**
* @addtogroup utils Utilities
* @{
@@ -23,7 +25,7 @@ struct tr_option
char const* argName; /* argument's description for tr_getopt_usage() */
};
enum
enum : int8_t
{
/* all options have been processed */
TR_OPT_DONE = 0,
+2 -2
View File
@@ -39,9 +39,9 @@
// ---
#define TR_INET6_ADDRSTRLEN 46
inline auto constexpr TrInet6AddrStrlen = 46U;
#define TR_ADDRSTRLEN 64
inline auto constexpr TrAddrStrlen = 64U;
// https://www.bittorrent.org/beps/bep_0007.html
// "The client SHOULD include a key parameter in its announces. The key
+19 -18
View File
@@ -10,6 +10,7 @@
#ifndef TR_POPCNT_H
#define TR_POPCNT_H
#include <array>
#include <cstdint>
#include <type_traits>
@@ -26,31 +27,31 @@
template<typename T>
struct tr_popcnt
{
static_assert(std::is_integral<T>::value != 0, "Can only popcnt integral types");
static_assert(std::is_integral_v<T> != 0, "Can only popcnt integral types");
static_assert(sizeof(T) <= sizeof(uint64_t), "Unsupported size");
/* Needed regularly to avoid sign extension / get unsigned shift behavior.
*/
using unsigned_T = typename std::make_unsigned<T>::type;
using unsigned_T = typename std::make_unsigned_t<T>;
/* Sanity tests. */
static_assert(sizeof(unsigned_T) == sizeof(T), "Unsigned type somehow smaller than signed type");
static_assert(std::is_integral<unsigned_T>::value != 0, "Unsigned type somehow non integral");
static_assert(std::is_integral_v<unsigned_T> != 0, "Unsigned type somehow non integral");
#if defined(TR_HAVE_STD_POPCOUNT)
/* If we have std::popcount just use that. */
static constexpr inline unsigned count(T v)
static constexpr unsigned count(T v)
{
unsigned_T unsigned_v = static_cast<unsigned_T>(v);
auto const unsigned_v = static_cast<unsigned_T>(v);
return static_cast<unsigned>(std::popcount(unsigned_v));
}
#else
/* Generic implementation. */
static inline unsigned count(T v)
static constexpr unsigned count(T v)
{
/* To avoid signed shifts. */
unsigned_T unsigned_v = static_cast<unsigned_T>(v);
auto unsigned_v = static_cast<unsigned_T>(v);
if constexpr (sizeof(T) <= sizeof(uint16_t))
{
@@ -58,7 +59,7 @@ struct tr_popcnt
* byte for each value if ever hit a case where perf is
* limited by severe bottleneck on L1D this can be
* optimized. */
static constexpr uint8_t popcnt_lut[256] = {
constexpr auto PopcntLut = std::array<uint8_t, 256>{
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2,
3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3,
3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5,
@@ -69,11 +70,11 @@ struct tr_popcnt
};
if constexpr (sizeof(T) == sizeof(uint8_t))
{
return popcnt_lut[unsigned_v];
return PopcntLut[unsigned_v];
}
else
{
return popcnt_lut[unsigned_v & 0xFF] + popcnt_lut[unsigned_v >> 8];
return PopcntLut[unsigned_v & 0xFF] + PopcntLut[unsigned_v >> 8];
}
}
else
@@ -81,16 +82,16 @@ struct tr_popcnt
/* for larger sizes use implementation described here:
* http://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation
*/
static constexpr unsigned_T m1 = static_cast<unsigned_T>(0x5555555555555555ll);
static constexpr unsigned_T m2 = static_cast<unsigned_T>(0x3333333333333333ll);
static constexpr unsigned_T m4 = static_cast<unsigned_T>(0x0F0F0F0F0F0F0F0Fll);
static constexpr unsigned_T h01 = static_cast<unsigned_T>(0x0101010101010101ll);
constexpr auto M1 = static_cast<unsigned_T>(0x5555555555555555LL);
constexpr auto M2 = static_cast<unsigned_T>(0x3333333333333333LL);
constexpr auto M4 = static_cast<unsigned_T>(0x0F0F0F0F0F0F0F0FLL);
constexpr auto H01 = static_cast<unsigned_T>(0x0101010101010101LL);
unsigned_v = unsigned_v - ((unsigned_v >> 1) & m1);
unsigned_v = (unsigned_v & m2) + ((unsigned_v >> 2) & m2);
unsigned_v = (unsigned_v + (unsigned_v >> 4)) & m4;
unsigned_v = unsigned_v - ((unsigned_v >> 1) & M1);
unsigned_v = (unsigned_v & M2) + ((unsigned_v >> 2) & M2);
unsigned_v = (unsigned_v + (unsigned_v >> 4)) & M4;
unsigned_v = unsigned_v * h01;
unsigned_v = unsigned_v * H01;
return unsigned_v >> (8 * sizeof(T) - 8);
}
}
+7 -2
View File
@@ -51,13 +51,15 @@ public:
return *this;
}
tr_strbuf(tr_strbuf&& other)
tr_strbuf(tr_strbuf&& other) noexcept
: buffer_{ std::move(other.buffer_) }
{
ensure_sz();
}
tr_strbuf& operator=(tr_strbuf&& other)
~tr_strbuf() = default;
tr_strbuf& operator=(tr_strbuf&& other) noexcept
{
buffer_ = std::move(other.buffer_);
ensure_sz();
@@ -269,11 +271,13 @@ public:
join(std::basic_string_view<Char>{ sz_delim }, args...);
}
// NOLINTNEXTLINE(google-explicit-constructor)
[[nodiscard]] constexpr operator std::basic_string_view<Char>() const noexcept
{
return sv();
}
// NOLINTNEXTLINE(google-explicit-constructor)
[[nodiscard]] constexpr operator auto() const noexcept
{
return c_str();
@@ -281,6 +285,7 @@ public:
bool popdir() noexcept
{
// NOLINTNEXTLINE(readability-redundant-declaration): P.S. This looks like some dark magic
std::string_view tr_sys_path_dirname(std::string_view path);
auto const parent = tr_sys_path_dirname(sv());
auto const changed = parent != sv();
+36 -27
View File
@@ -55,7 +55,7 @@ struct tr_variant;
#define TR_RPC_SESSION_ID_HEADER "X-Transmission-Session-Id"
enum tr_verify_added_mode
enum tr_verify_added_mode : uint8_t
{
// See discussion @ https://github.com/transmission/transmission/pull/2626
// Let newly-added torrents skip upfront verify do it on-demand later.
@@ -65,7 +65,7 @@ enum tr_verify_added_mode
TR_VERIFY_ADDED_FULL = 1
};
enum tr_encryption_mode
enum tr_encryption_mode : uint8_t
{
TR_CLEAR_PREFERRED,
TR_ENCRYPTION_PREFERRED,
@@ -79,8 +79,11 @@ enum tr_priority_t : int8_t
TR_PRI_HIGH = 1
};
#define TR_RATIO_NA (-1)
#define TR_RATIO_INF (-2)
enum : int8_t
{
TR_RATIO_NA = -1,
TR_RATIO_INF = -2
};
// --- Startup & Shutdown
@@ -129,15 +132,15 @@ size_t tr_getDefaultDownloadDirToBuf(char* buf, size_t buflen);
#define TR_DEFAULT_RPC_WHITELIST "127.0.0.1,::1"
#define TR_DEFAULT_RPC_PORT_STR "9091"
#define TR_DEFAULT_RPC_PORT 9091
inline auto constexpr TrDefaultRpcPort = 9091U;
#define TR_DEFAULT_RPC_URL_STR "/transmission/"
#define TR_DEFAULT_PEER_PORT_STR "51413"
#define TR_DEFAULT_PEER_PORT 51413
inline auto constexpr TrDefaultPeerPort = 51413U;
#define TR_DEFAULT_PEER_SOCKET_TOS_STR "le"
#define TR_DEFAULT_PEER_LIMIT_GLOBAL_STR "200"
#define TR_DEFAULT_PEER_LIMIT_GLOBAL 200
inline auto constexpr TrDefaultPeerLimitGlobal = 200U;
#define TR_DEFAULT_PEER_LIMIT_TORRENT_STR "50"
#define TR_DEFAULT_PEER_LIMIT_TORRENT 50
inline auto constexpr TrDefaultPeerLimitTorrent = 50U;
/**
* Add libtransmission's default settings to the benc dictionary.
@@ -365,7 +368,7 @@ void tr_sessionSetRPCPasswordEnabled(tr_session* session, bool is_enabled);
void tr_sessionSetDefaultTrackers(tr_session* session, char const* trackers);
enum tr_rpc_callback_type
enum tr_rpc_callback_type : uint8_t
{
TR_RPC_TORRENT_ADDED,
TR_RPC_TORRENT_STARTED,
@@ -379,7 +382,7 @@ enum tr_rpc_callback_type
TR_RPC_SESSION_CLOSE
};
enum tr_rpc_callback_status
enum tr_rpc_callback_status : uint8_t
{
/* no special handling is needed by the caller */
TR_RPC_OK = 0,
@@ -465,7 +468,7 @@ uint16_t tr_sessionSetPeerPortRandom(tr_session* session);
bool tr_sessionGetPeerPortRandomOnStart(tr_session const* session);
void tr_sessionSetPeerPortRandomOnStart(tr_session* session, bool random);
enum tr_port_forwarding_state
enum tr_port_forwarding_state : uint8_t
{
TR_PORT_ERROR,
TR_PORT_UNMAPPED,
@@ -476,7 +479,7 @@ enum tr_port_forwarding_state
tr_port_forwarding_state tr_sessionGetPortForwarding(tr_session const* session);
enum tr_direction
enum tr_direction : uint8_t
{
TR_CLIENT_TO_PEER = 0,
TR_UP = 0,
@@ -509,7 +512,7 @@ void tr_sessionSetAltSpeedBegin(tr_session* session, size_t minutes_since_midnig
size_t tr_sessionGetAltSpeedEnd(tr_session const* session);
void tr_sessionSetAltSpeedEnd(tr_session* session, size_t minutes_since_midnight);
enum tr_sched_day
enum tr_sched_day : uint8_t
{
TR_SCHED_SUN = (1 << 0),
TR_SCHED_MON = (1 << 1),
@@ -664,7 +667,7 @@ size_t tr_sessionGetAllTorrents(tr_session* session, tr_torrent** buf, size_t bu
// ---
enum TrScript
enum TrScript : uint8_t
{
TR_SCRIPT_ON_TORRENT_ADDED,
TR_SCRIPT_ON_TORRENT_DONE,
@@ -737,7 +740,7 @@ void tr_blocklistSetURL(tr_session* session, char const* url);
* When ready, pass the builder object to `tr_torrentNew()`.
*/
enum tr_ctorMode
enum tr_ctorMode : uint8_t
{
TR_FALLBACK, /* indicates the ctor value should be used only in case of missing resume settings */
TR_FORCE /* indicates the ctor value should be used regardless of what's in the resume settings */
@@ -902,7 +905,7 @@ void tr_torrentRenamePath(
tr_torrent_rename_done_func callback,
void* callback_user_data);
enum
enum : uint8_t
{
TR_LOC_MOVING,
TR_LOC_DONE,
@@ -973,7 +976,7 @@ void tr_torrentUseSessionLimits(tr_torrent* tor, bool enabled);
// --- Ratio Limits
enum tr_ratiolimit
enum tr_ratiolimit : uint8_t
{
/* follow the global settings */
TR_RATIOLIMIT_GLOBAL = 0,
@@ -993,7 +996,7 @@ bool tr_torrentGetSeedRatio(tr_torrent const* tor, double* ratio);
// --- Idle Time Limits
enum tr_idlelimit
enum tr_idlelimit : uint8_t
{
/* follow the global settings */
TR_IDLELIMIT_GLOBAL = 0,
@@ -1086,7 +1089,7 @@ bool tr_torrentSetTrackerList(tr_torrent* tor, char const* text);
// ---
enum tr_completeness
enum tr_completeness : uint8_t
{
TR_LEECH, /* doesn't have all the desired pieces */
TR_SEED, /* has the entire torrent */
@@ -1169,6 +1172,7 @@ bool tr_torrentCanManualUpdate(tr_torrent const* torrent);
// --- tr_peer_stat
// NOLINTBEGIN(modernize-avoid-c-arrays)
struct tr_peer_stat
{
bool isUTP;
@@ -1187,7 +1191,7 @@ struct tr_peer_stat
uint8_t from;
uint16_t port;
char addr[TR_INET6_ADDRSTRLEN];
char addr[TrInet6AddrStrlen];
char flagStr[32];
char const* client;
@@ -1212,6 +1216,7 @@ struct tr_peer_stat
/* how many requests we've made and are currently awaiting a response for */
size_t activeReqsToPeer;
};
// NOLINTEND(modernize-avoid-c-arrays)
tr_peer_stat* tr_torrentPeers(tr_torrent const* torrent, size_t* peer_count);
@@ -1219,7 +1224,7 @@ void tr_torrentPeersFree(tr_peer_stat* peer_stats, size_t peer_count);
// --- tr_tracker_stat
enum tr_tracker_state
enum tr_tracker_state : uint8_t
{
/* we won't (announce,scrape) this torrent to this tracker because
* the torrent is stopped, or because of an error, or whatever */
@@ -1234,6 +1239,7 @@ enum tr_tracker_state
TR_TRACKER_ACTIVE = 3
};
// NOLINTBEGIN(modernize-avoid-c-arrays)
/*
* Unlike other _view structs, it is safe to keep a tr_tracker_view copy.
* The announce and scrape strings are interned & never go out-of-scope.
@@ -1280,6 +1286,7 @@ struct tr_tracker_view
bool lastScrapeSucceeded; // if hasScraped, whether or not the latest scrape succeeded
bool lastScrapeTimedOut; // true iff the latest scrape request timed out
};
// NOLINTEND(modernize-avoid-c-arrays)
struct tr_tracker_view tr_torrentTracker(tr_torrent const* torrent, size_t i);
@@ -1385,7 +1392,7 @@ bool tr_torrentHasMetadata(tr_torrent const* tor);
* Note: these values will become a straight enum at some point in the future.
* Do not rely on their current `bitfield` implementation
*/
enum tr_torrent_activity
enum tr_torrent_activity : uint8_t
{
TR_STATUS_STOPPED = 0, /* Torrent is stopped */
TR_STATUS_CHECK_WAIT = 1, /* Queued to check files */
@@ -1404,15 +1411,15 @@ enum tr_peer_from : uint8_t
TR_PEER_FROM_PEX, /* peers found from PEX */
TR_PEER_FROM_RESUME, /* peers found in the .resume file */
TR_PEER_FROM_LTEP, /* peer address provided in an LTEP handshake */
TR_PEER_FROM__MAX
TR_PEER_FROM_N_TYPES
};
enum tr_eta : time_t
enum tr_eta : time_t // NOLINT(performance-enum-size)
{
TR_ETA_NOT_AVAIL = -1,
TR_ETA_UNKNOWN = -2,
};
enum tr_stat_errtype
enum tr_stat_errtype : uint8_t
{
/* everything's fine */
TR_STAT_OK = 0,
@@ -1424,6 +1431,7 @@ enum tr_stat_errtype
TR_STAT_LOCAL_ERROR = 3
};
// NOLINTBEGIN(modernize-avoid-c-arrays)
/** @brief Used by `tr_torrentStat()` to tell clients about a torrent's state and statistics */
struct tr_stat
{
@@ -1563,11 +1571,11 @@ struct tr_stat
/** How many connected peers we found out about from the tracker, or from pex,
or from incoming connections, or from our resume file. */
uint16_t peersFrom[TR_PEER_FROM__MAX];
uint16_t peersFrom[TR_PEER_FROM_N_TYPES];
/** How many known peers we found out about from the tracker, or from pex,
or from incoming connections, or from our resume file. */
uint16_t knownPeersFrom[TR_PEER_FROM__MAX];
uint16_t knownPeersFrom[TR_PEER_FROM_N_TYPES];
/** Number of peers that are sending data to us. */
uint16_t peersSendingToUs;
@@ -1586,6 +1594,7 @@ struct tr_stat
to be considered stalled. @see `tr_sessionGetQueueStalledMinutes()` */
bool isStalled;
};
// NOLINTEND(modernize-avoid-c-arrays)
/** Return a pointer to an `tr_stat` structure with updated information
on the torrent. This is typically called by the GUI clients every
+5 -5
View File
@@ -68,9 +68,9 @@ namespace libtransmission::Values
{
// default values; can be overridden by client apps
Config::Units<MemoryUnits> Config::Memory{ Config::Base::Kibi, "B"sv, "KiB"sv, "MiB"sv, "GiB"sv, "TiB"sv };
Config::Units<SpeedUnits> Config::Speed{ Config::Base::Kilo, "B/s"sv, "kB/s"sv, "MB/s"sv, "GB/s"sv, "TB/s"sv };
Config::Units<StorageUnits> Config::Storage{ Config::Base::Kilo, "B"sv, "kB"sv, "MB"sv, "GB"sv, "TB"sv };
Config::Units<MemoryUnits> Config::memory{ Config::Base::Kibi, "B"sv, "KiB"sv, "MiB"sv, "GiB"sv, "TiB"sv };
Config::Units<SpeedUnits> Config::speed{ Config::Base::Kilo, "B/s"sv, "kB/s"sv, "MB/s"sv, "GB/s"sv, "TB/s"sv };
Config::Units<StorageUnits> Config::storage{ Config::Base::Kilo, "B"sv, "kB"sv, "MB"sv, "GB"sv, "TB"sv };
} // namespace libtransmission::Values
@@ -794,8 +794,8 @@ std::string_view tr_get_mime_type_for_filename(std::string_view filename)
if (auto const pos = filename.rfind('.'); pos != std::string_view::npos)
{
auto const suffix_lc = tr_strlower(filename.substr(pos + 1));
auto const it = std::lower_bound(std::begin(mime_type_suffixes), std::end(mime_type_suffixes), suffix_lc, Compare);
if (it != std::end(mime_type_suffixes) && suffix_lc == it->suffix)
auto const it = std::lower_bound(std::begin(MimeTypeSuffixes), std::end(MimeTypeSuffixes), suffix_lc, Compare);
if (it != std::end(MimeTypeSuffixes) && suffix_lc == it->suffix)
{
return it->mime_type;
}
+8 -8
View File
@@ -47,7 +47,7 @@ struct Config
template<typename UnitsEnum>
struct Units
{
template<typename... Names>
template<typename... Names> // NOLINTNEXTLINE(google-explicit-constructor, cppcoreguidelines-pro-type-member-init)
Units(Base base, Names... names) noexcept
{
set_base(base);
@@ -96,12 +96,12 @@ struct Config
std::array<std::array<char, 32>, 5> display_names_ = {};
std::array<uint64_t, 5> multipliers_;
Base base_;
Base base_ = {};
};
static Units<MemoryUnits> Memory;
static Units<SpeedUnits> Speed;
static Units<StorageUnits> Storage;
static Units<MemoryUnits> memory;
static Units<SpeedUnits> speed;
static Units<StorageUnits> storage;
};
template<typename UnitsEnum, Config::Units<UnitsEnum> const& units_>
@@ -263,8 +263,8 @@ private:
}
};
using Memory = Value<MemoryUnits, Config::Memory>;
using Storage = Value<StorageUnits, Config::Storage>;
using Speed = Value<SpeedUnits, Config::Speed>;
using Memory = Value<MemoryUnits, Config::memory>;
using Storage = Value<StorageUnits, Config::storage>;
using Speed = Value<SpeedUnits, Config::speed>;
} // namespace libtransmission::Values
+10 -5
View File
@@ -49,7 +49,7 @@ public:
public:
Map() = default;
Map(size_t const n_reserve)
explicit Map(size_t const n_reserve)
{
vec_.reserve(n_reserve);
}
@@ -193,13 +193,14 @@ public:
};
constexpr tr_variant() noexcept = default;
~tr_variant() = default;
tr_variant(tr_variant const&) = delete;
tr_variant(tr_variant&& that) noexcept = default;
tr_variant& operator=(tr_variant const&) = delete;
tr_variant& operator=(tr_variant&& that) noexcept = default;
template<typename Val>
tr_variant(Val&& value)
tr_variant(Val&& value) // NOLINT(bugprone-forwarding-reference-overload, google-explicit-constructor)
{
*this = std::forward<Val>(value);
}
@@ -382,10 +383,14 @@ private:
{
public:
StringHolder() = default;
~StringHolder() = default;
explicit StringHolder(std::string&& str) noexcept;
explicit StringHolder(StringHolder&& that) noexcept;
StringHolder(StringHolder&& that) noexcept;
StringHolder(StringHolder const&) = delete;
void set_unmanaged(std::string_view sv);
StringHolder& operator=(StringHolder&& that) noexcept;
StringHolder& operator=(StringHolder const&) = delete;
std::string_view sv_;
private:
@@ -565,7 +570,7 @@ public:
private:
friend tr_variant;
enum class Type
enum class Type : uint8_t
{
Benc,
Json
@@ -583,7 +588,7 @@ private:
void (*container_end_func)(tr_variant const& var, void* user_data);
};
tr_variant_serde(Type type)
explicit tr_variant_serde(Type type)
: type_{ type }
{
}
+6
View File
@@ -41,8 +41,14 @@ public:
virtual void on_verify_done(bool aborted) = 0;
};
tr_verify_worker() = default;
~tr_verify_worker();
tr_verify_worker(tr_verify_worker const&) = delete;
tr_verify_worker(tr_verify_worker&&) = delete;
tr_verify_worker& operator=(tr_verify_worker const&) = delete;
tr_verify_worker& operator=(tr_verify_worker&&) = delete;
void add(std::unique_ptr<Mediator> mediator, tr_priority_t priority);
void remove(tr_sha1_digest_t const& info_hash);
+4
View File
@@ -1,5 +1,7 @@
#pragma once
// NOLINTBEGIN
#define PEERID_PREFIX "${TR_PEER_ID_PREFIX}"
#define USERAGENT_PREFIX "${TR_USER_AGENT_PREFIX}"
#define VCS_REVISION "${TR_VCS_REVISION}"
@@ -15,3 +17,5 @@
#cmakedefine TR_BETA_RELEASE 1
#cmakedefine TR_NIGHTLY_RELEASE 1
#cmakedefine TR_STABLE_RELEASE 1
// NOLINTEND
+2
View File
@@ -37,6 +37,8 @@ public:
retry_timer_->set_callback([this]() { onRetryTimer(); });
}
~BaseWatchdir() override = default;
BaseWatchdir(BaseWatchdir&&) = delete;
BaseWatchdir(BaseWatchdir const&) = delete;
BaseWatchdir& operator=(BaseWatchdir&&) = delete;
+3 -1
View File
@@ -20,7 +20,7 @@ class TimerMaker;
class Watchdir
{
public:
enum class Action
enum class Action : uint8_t
{
Done,
Retry
@@ -60,6 +60,8 @@ public:
std::chrono::milliseconds rescan_interval = generic_rescan_interval_);
private:
// TODO: Re-enable after setting readability-identifier-naming.PrivateMemberSuffix to _
// NOLINTNEXTLINE(readability-identifier-naming)
static inline auto generic_rescan_interval_ = std::chrono::milliseconds{ 1000 };
};
+1 -2
View File
@@ -446,8 +446,7 @@ tr_url_query_view::iterator tr_url_query_view::begin() const
{
auto it = iterator{};
it.remain = query;
++it;
return it;
return ++it;
}
std::string tr_urlPercentDecode(std::string_view in)
+3 -3
View File
@@ -62,8 +62,8 @@ struct tr_url_query_view
struct iterator
{
std::pair<std::string_view, std::string_view> keyval = std::make_pair(std::string_view{ "" }, std::string_view{ "" });
std::string_view remain = "";
std::pair<std::string_view, std::string_view> keyval;
std::string_view remain;
iterator& operator++();
@@ -90,7 +90,7 @@ struct tr_url_query_view
[[nodiscard]] iterator begin() const;
[[nodiscard]] constexpr iterator end() const
[[nodiscard]] static constexpr iterator end()
{
return iterator{};
}
+6 -1
View File
@@ -38,7 +38,7 @@ public:
class FetchOptions
{
public:
enum class IPProtocol
enum class IPProtocol : uint8_t
{
ANY,
V4,
@@ -108,6 +108,11 @@ public:
// all of its tasks.
~tr_web();
tr_web(tr_web const&) = delete;
tr_web(tr_web&&) = delete;
tr_web& operator=(tr_web const&) = delete;
tr_web& operator=(tr_web&&) = delete;
/**
* Mediates between `tr_web` and its clients.
*
+1 -1
View File
@@ -29,7 +29,7 @@ protected:
public:
[[nodiscard]] static std::unique_ptr<tr_webseed> create(
tr_torrent& torrent,
std::string_view,
std::string_view url,
tr_peer_callback_webseed callback,
void* callback_data);
+3 -3
View File
@@ -149,9 +149,9 @@ static void initUnits()
NSString* g_str = [unitFormatter stringFromByteCount:ArbitraryPluralNumber];
unitFormatter.allowedUnits = NSByteCountFormatterUseTB;
NSString* t_str = [unitFormatter stringFromByteCount:ArbitraryPluralNumber];
Config::Memory = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String,
Config::memory = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String,
m_str.UTF8String, g_str.UTF8String, t_str.UTF8String };
Config::Storage = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String,
Config::storage = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String,
m_str.UTF8String, g_str.UTF8String, t_str.UTF8String };
b_str = NSLocalizedString(@"B/s", "Transfer speed (bytes per second)");
@@ -159,7 +159,7 @@ static void initUnits()
m_str = NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)");
g_str = NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)");
t_str = NSLocalizedString(@"TB/s", "Transfer speed (terabytes per second)");
Config::Speed = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String,
Config::speed = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String,
m_str.UTF8String, g_str.UTF8String, t_str.UTF8String };
}
+2 -2
View File
@@ -268,11 +268,11 @@ static NSTimeInterval const kUpdateSeconds = 0.75;
}
}
if (self.fMessages.count > TR_LOG_MAX_QUEUE_LENGTH)
if (self.fMessages.count > TrLogMaxQueueLength)
{
NSUInteger const oldCount = self.fDisplayedMessages.count;
NSIndexSet* removeIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.fMessages.count - TR_LOG_MAX_QUEUE_LENGTH)];
NSIndexSet* removeIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.fMessages.count - TrLogMaxQueueLength)];
NSArray* itemsToRemove = [self.fMessages objectsAtIndexes:removeIndexes];
[self.fMessages removeObjectsAtIndexes:removeIndexes];
+2
View File
@@ -1,4 +1,6 @@
---
HeaderFilterRegex: .*/qt/.*
# Many of these checks are disabled only because the code hasn't been
# cleaned up yet. Pull requests welcomed.
Checks: >
+3 -3
View File
@@ -71,21 +71,21 @@ void initUnits()
{
using Config = libtransmission::Values::Config;
Config::Speed = { Config::Base::Kilo,
Config::speed = { Config::Base::Kilo,
QObject::tr("B/s").toStdString(),
QObject::tr("kB/s").toStdString(),
QObject::tr("MB/s").toStdString(),
QObject::tr("GB/s").toStdString(),
QObject::tr("TB/s").toStdString() };
Config::Memory = { Config::Base::Kibi,
Config::memory = { Config::Base::Kibi,
QObject::tr("B").toStdString(),
QObject::tr("KiB").toStdString(),
QObject::tr("MiB").toStdString(),
QObject::tr("GiB").toStdString(),
QObject::tr("TiB").toStdString() };
Config::Storage = { Config::Base::Kilo,
Config::storage = { Config::Base::Kilo,
QObject::tr("B").toStdString(),
QObject::tr("kB").toStdString(),
QObject::tr("MB").toStdString(),
+1 -1
View File
@@ -464,7 +464,7 @@ tr_variant Prefs::get_default_app_settings()
settings.try_emplace(TR_KEY_main_window_width, 300);
settings.try_emplace(TR_KEY_main_window_x, 50);
settings.try_emplace(TR_KEY_main_window_y, 50);
settings.try_emplace(TR_KEY_remote_session_port, TR_DEFAULT_RPC_PORT);
settings.try_emplace(TR_KEY_remote_session_port, TrDefaultRpcPort);
settings.try_emplace(TR_KEY_download_dir, download_dir);
settings.try_emplace(TR_KEY_filter_mode, FilterMode);
settings.try_emplace(TR_KEY_main_window_layout_order, WindowLayout);
+3 -1
View File
@@ -1,4 +1,6 @@
---
HeaderFilterRegex: .*/tests/libtransmission/.*
# Many of these checks are disabled only because the code hasn't been
# cleaned up yet. Pull requests welcomed.
Checks: >
@@ -24,6 +26,7 @@ Checks: >
-hicpp-signed-bitwise,
misc-*,
-misc-include-cleaner,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-use-trailing-return-type,
@@ -39,7 +42,6 @@ CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.ClassMethodCase, value: camelBack }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
- { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.FunctionCase, value: camelBack }
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
- { key: readability-identifier-naming.MemberConstantCase, value: CamelCase }
+1 -1
View File
@@ -363,7 +363,7 @@ TEST_F(AnnounceListTest, save)
// first, set up a scratch torrent
auto constexpr* const OriginalFile = LIBTRANSMISSION_TEST_ASSETS_DIR "/Android-x86 8.1 r6 iso.torrent";
auto original_content = std::vector<char>{};
auto const sandbox = libtransmission::test::Sandbox::create_sandbox(::testing::TempDir(), "transmission-test-XXXXXX");
auto const sandbox = libtransmission::test::Sandbox::createSandbox(::testing::TempDir(), "transmission-test-XXXXXX");
auto const test_file = tr_pathbuf{ sandbox, "transmission-announce-list-test.torrent"sv };
auto error = tr_error{};
EXPECT_TRUE(tr_file_read(OriginalFile, original_content, &error));
+1 -1
View File
@@ -37,7 +37,7 @@ protected:
static auto constexpr DefaultMaxFileCount = size_t{ 16 };
static auto constexpr DefaultMaxFileSize = size_t{ 1024 };
auto makeRandomFiles(
static auto makeRandomFiles(
std::string_view top,
size_t n_files = std::max(size_t{ 1U }, static_cast<size_t>(tr_rand_int(DefaultMaxFileCount))),
size_t max_size = DefaultMaxFileSize)
+2 -4
View File
@@ -69,9 +69,7 @@ TEST_P(IncompleteDirTest, incompleteDir)
EXPECT_EQ(path, tr_torrentFindFile(tor, 1));
EXPECT_EQ(tor->piece_size(), tr_torrentStat(tor)->leftUntilDone);
// auto constexpr completeness_unset = tr_completeness { -1 };
// auto completeness = completeness_unset;
int completeness = -1;
auto completeness = TR_LEECH;
auto const zeroes_completeness_func =
[](tr_torrent* /*torrent*/, tr_completeness c, bool /*was_running*/, void* vc) noexcept
{
@@ -125,7 +123,7 @@ TEST_P(IncompleteDirTest, incompleteDir)
auto test = [&completeness]()
{
return completeness != -1;
return completeness != TR_LEECH;
};
EXPECT_TRUE(waitFor(test, MaxWaitMsec));
EXPECT_EQ(TR_SEED, completeness);
+1 -1
View File
@@ -172,7 +172,7 @@ protected:
return files;
}
auto createFiles(tr_torrent_files const& files, char const* parent)
static auto createFiles(tr_torrent_files const& files, char const* parent)
{
auto paths = std::set<std::string>{};
+2 -2
View File
@@ -46,13 +46,13 @@ protected:
EXPECT_TRUE(waitFor(test, MaxWaitMsec));
}
void createSingleFileTorrentContents(std::string_view top)
static void createSingleFileTorrentContents(std::string_view top)
{
auto const path = tr_pathbuf{ top, "/hello-world.txt" };
createFileWithContents(path, "hello, world!\n");
}
void createMultifileTorrentContents(std::string_view top)
static void createMultifileTorrentContents(std::string_view top)
{
auto path = tr_pathbuf{ top, "/Felidae/Felinae/Acinonyx/Cheetah/Chester"sv };
createFileWithContents(path, "It ain't easy bein' cheesy.\n");
+27 -27
View File
@@ -37,15 +37,12 @@ inline std::ostream& operator<<(std::ostream& os, tr_error const& err)
return os;
}
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
using file_func_t = std::function<void(char const* filename)>;
static void depthFirstWalk(char const* path, file_func_t func)
static void depthFirstWalk(char const* path, file_func_t const& func)
{
if (auto const info = tr_sys_path_get_info(path); info && info->isFolder())
{
@@ -125,8 +122,8 @@ class Sandbox
{
public:
Sandbox()
: parent_dir_{ get_default_parent_dir() }
, sandbox_dir_{ create_sandbox(parent_dir_, "transmission-test-XXXXXX") }
: parent_dir_{ getDefaultParentDir() }
, sandbox_dir_{ createSandbox(parent_dir_, "transmission-test-XXXXXX") }
{
}
@@ -135,12 +132,17 @@ public:
rimraf(sandbox_dir_);
}
Sandbox(Sandbox const&) = delete;
Sandbox(Sandbox&&) = delete;
Sandbox& operator=(Sandbox const&) = delete;
Sandbox& operator=(Sandbox&&) = delete;
[[nodiscard]] constexpr std::string const& path() const
{
return sandbox_dir_;
}
static std::string create_sandbox(std::string const& parent_dir, std::string const& tmpl)
static std::string createSandbox(std::string const& parent_dir, std::string const& tmpl)
{
auto path = fmt::format(FMT_STRING("{:s}/{:s}"sv), tr_sys_path_resolve(parent_dir), tmpl);
tr_sys_dir_create_temp(std::data(path));
@@ -149,7 +151,7 @@ public:
}
protected:
static std::string get_default_parent_dir()
static std::string getDefaultParentDir()
{
if (auto* const path = getenv("TMPDIR"); path != nullptr)
{
@@ -166,7 +168,7 @@ protected:
{
if (verbose)
{
std::cerr << "cleanup: removing '" << filename << "'" << std::endl;
std::cerr << "cleanup: removing '" << filename << "'\n";
}
tr_sys_path_remove(filename);
@@ -188,7 +190,7 @@ protected:
return sandbox_.path();
}
[[nodiscard]] auto currentTestName() const
[[nodiscard]] static auto currentTestName()
{
auto const* i = ::testing::UnitTest::GetInstance()->current_test_info();
auto child = std::string(i->test_suite_name());
@@ -197,7 +199,7 @@ protected:
return child;
}
void buildParentDir(std::string_view path) const
static void buildParentDir(std::string_view path)
{
auto const tmperr = errno;
@@ -237,7 +239,7 @@ protected:
}
}
void createTmpfileWithContents(char* tmpl, void const* payload, size_t n) const
static void createTmpfileWithContents(char* tmpl, void const* payload, size_t n)
{
auto const tmperr = errno;
@@ -260,7 +262,7 @@ protected:
errno = tmperr;
}
void createFileWithContents(std::string_view path, void const* payload, size_t n) const
static void createFileWithContents(std::string_view path, void const* payload, size_t n)
{
auto const tmperr = errno;
@@ -278,19 +280,19 @@ protected:
errno = tmperr;
}
void createFileWithContents(std::string_view path, std::string_view payload) const
static void createFileWithContents(std::string_view path, std::string_view payload)
{
createFileWithContents(path, std::data(payload), std::size(payload));
}
void createFileWithContents(std::string_view path, void const* payload) const
static void createFileWithContents(std::string_view path, void const* payload)
{
createFileWithContents(path, payload, strlen(static_cast<char const*>(payload)));
}
bool verbose = false;
bool verbose_ = false;
void sync() const
static void sync()
{
#ifndef _WIN32
::sync();
@@ -330,19 +332,19 @@ private:
// fill in any missing settings
settings_map->try_emplace(TR_KEY_port_forwarding_enabled, false);
settings_map->try_emplace(TR_KEY_dht_enabled, false);
settings_map->try_emplace(TR_KEY_message_level, verbose ? TR_LOG_DEBUG : TR_LOG_ERROR);
settings_map->try_emplace(TR_KEY_message_level, verbose_ ? TR_LOG_DEBUG : TR_LOG_ERROR);
return tr_sessionInit(sandboxDir().data(), !verbose, settings);
return tr_sessionInit(sandboxDir().data(), !verbose_, settings);
}
void sessionClose(tr_session* session)
static void sessionClose(tr_session* session)
{
tr_sessionClose(session);
tr_logFreeQueue(tr_logGetQueue());
}
protected:
enum class ZeroTorrentState
enum class ZeroTorrentState : uint8_t
{
NoFiles,
Partial,
@@ -485,7 +487,7 @@ protected:
return settings_.get();
}
virtual void SetUp() override
void SetUp() override
{
SandboxedTest::SetUp();
@@ -494,7 +496,7 @@ protected:
session_ = sessionInit(*settings());
}
virtual void TearDown() override
void TearDown() override
{
sessionClose(session_);
session_ = nullptr;
@@ -509,6 +511,4 @@ private:
std::vector<tr_torrent*> verified_;
};
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test
@@ -134,7 +134,7 @@ TEST_F(TorrentMetainfoTest, AndroidTorrent)
TEST_F(TorrentMetainfoTest, ctorSaveContents)
{
auto const sandbox = libtransmission::test::Sandbox::create_sandbox(::testing::TempDir(), "transmission-test-XXXXXX");
auto const sandbox = libtransmission::test::Sandbox::createSandbox(::testing::TempDir(), "transmission-test-XXXXXX");
auto const src_filename = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, "/Android-x86 8.1 r6 iso.torrent"sv };
auto const tgt_filename = tr_pathbuf{ sandbox, "save-contents-test.torrent" };
+1 -1
View File
@@ -262,7 +262,7 @@ TEST_F(UtilsTest, saveFile)
auto filename = tr_pathbuf{};
// save a file to GoogleTest's temp dir
auto const sandbox = libtransmission::test::Sandbox::create_sandbox(::testing::TempDir(), "transmission-test-XXXXXX");
auto const sandbox = libtransmission::test::Sandbox::createSandbox(::testing::TempDir(), "transmission-test-XXXXXX");
filename.assign(sandbox, "filename.txt"sv);
auto contents = "these are the contents"sv;
auto error = tr_error{};
+1 -2
View File
@@ -4,9 +4,7 @@
// License text can be found in the licenses/ folder.
#include <array>
#include <cassert>
#include <cerrno>
#include <cmath> // lrint()
#include <cstddef> // size_t
#include <cstdint> // int64_t
#include <string>
@@ -22,6 +20,7 @@
#include <libtransmission/variant.h>
#include "gtest/gtest.h"
#include "test-fixtures.h"
using namespace std::literals;
+1 -1
View File
@@ -96,7 +96,7 @@ protected:
return watchdir;
}
void createFile(std::string_view dirname, std::string_view basename, std::string_view contents = ""sv)
static void createFile(std::string_view dirname, std::string_view basename, std::string_view contents = ""sv)
{
createFileWithContents(tr_pathbuf{ dirname, '/', basename }, contents);
}
+1 -1
View File
@@ -48,7 +48,7 @@ using namespace libtransmission::Values;
namespace
{
auto constexpr DefaultPort = uint16_t{ TR_DEFAULT_RPC_PORT };
auto constexpr DefaultPort = uint16_t{ TrDefaultRpcPort };
char constexpr DefaultHost[] = "localhost";
char constexpr DefaultUrl[] = TR_DEFAULT_RPC_URL_STR "rpc/";