diff --git a/libtransmission/announce-list.cc b/libtransmission/announce-list.cc index 16e9bf066..02140975a 100644 --- a/libtransmission/announce-list.cc +++ b/libtransmission/announce-list.cc @@ -269,7 +269,7 @@ bool tr_announce_list::save(std::string_view torrent_file, tr_error** error) con // confirm that it's good by parsing it back again auto const contents = tr_variantToStr(&metainfo, TR_VARIANT_FMT_BENC); tr_variantClear(&metainfo); - if (auto tm = tr_torrent_metainfo{}; !tm.parseBenc(contents, error)) + if (auto tm = tr_torrent_metainfo{}; !tm.parse_benc(contents, error)) { return false; } diff --git a/libtransmission/announcer.cc b/libtransmission/announcer.cc index 580b455bf..5c1927ab3 100644 --- a/libtransmission/announcer.cc +++ b/libtransmission/announcer.cc @@ -627,10 +627,10 @@ struct tr_torrent_announcer private: [[nodiscard]] static tr_announce_list getAnnounceList(tr_torrent const* tor) { - auto announce_list = tor->announceList(); + auto announce_list = tor->announce_list(); // if it's a public torrent, add the default trackers - if (tor->isPublic()) + if (tor->is_public()) { announce_list.add(tor->session->defaultTrackers()); } @@ -734,7 +734,7 @@ bool tr_announcerCanManualAnnounce(tr_torrent const* tor) TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(tor->torrent_announcer != nullptr); - return tor->isRunning && tor->torrent_announcer->canManualAnnounce(); + return tor->is_running() && tor->torrent_announcer->canManualAnnounce(); } time_t tr_announcerNextManualAnnounce(tr_torrent const* tor) @@ -909,16 +909,16 @@ void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e) req.port = announcer->session->advertisedPeerPort(); req.announce_url = current_tracker->announce_url; req.tracker_id = current_tracker->tracker_id; - req.info_hash = tor->infoHash(); + req.info_hash = tor->info_hash(); req.peer_id = tor->peer_id(); req.up = tier->byteCounts[TR_ANN_UP]; req.down = tier->byteCounts[TR_ANN_DOWN]; req.corrupt = tier->byteCounts[TR_ANN_CORRUPT]; - req.leftUntilComplete = tor->hasMetainfo() ? tor->totalSize() - tor->hasTotal() : INT64_MAX; + req.leftUntilComplete = tor->has_metainfo() ? tor->total_size() - tor->has_total() : INT64_MAX; req.event = event; req.numwant = event == TR_ANNOUNCE_EVENT_STOPPED ? 0 : Numwant; req.key = tor->announce_key(); - req.partial_seed = tor->isPartialSeed(); + req.partial_seed = tor->is_partial_seed(); tier->buildLogName(req.log_name, sizeof(req.log_name)); return req; } @@ -1023,7 +1023,7 @@ void tr_announcer_impl::onAnnounceDone( Don't bother publishing if there are other trackers -- it's all too common for people to load up dozens of dead trackers in a torrent's metainfo... */ - if (tier->tor->trackerCount() < 2) + if (tier->tor->tracker_count() < 2) { publishError(tier, response.errmsg); } @@ -1436,7 +1436,7 @@ void multiscrape(tr_announcer_impl* announcer, std::vector const& tier continue; } - req->info_hash[req->info_hash_count] = tier->tor->infoHash(); + req->info_hash[req->info_hash_count] = tier->tor->info_hash(); ++req->info_hash_count; tier->isScraping = true; tier->lastScrapeStartTime = now; @@ -1450,7 +1450,7 @@ void multiscrape(tr_announcer_impl* announcer, std::vector const& tier req->scrape_url = scrape_info->scrape_url; tier->buildLogName(req->log_name, sizeof(req->log_name)); - req->info_hash[req->info_hash_count] = tier->tor->infoHash(); + req->info_hash[req->info_hash_count] = tier->tor->info_hash(); ++req->info_hash_count; tier->isScraping = true; tier->lastScrapeStartTime = now; @@ -1491,7 +1491,7 @@ int compareAnnounceTiers(tr_tier const* a, tr_tier const* b) } /* prefer swarms where we might download */ - if (auto const is_done_a = a->tor->isDone(), is_done_b = b->tor->isDone(); is_done_a != is_done_b) + if (auto const is_done_a = a->tor->is_done(), is_done_b = b->tor->is_done(); is_done_a != is_done_b) { return is_done_a ? 1 : -1; } @@ -1533,7 +1533,7 @@ void tierAnnounce(tr_announcer_impl* announcer, tr_tier* tier) tier->lastAnnounceStartTime = now; auto tier_id = tier->id; - auto is_running_on_success = tor->isRunning; + auto is_running_on_success = tor->is_running(); announcer->announce( req, @@ -1693,7 +1693,7 @@ namespace tracker_view_helpers { view.announceState = TR_TRACKER_ACTIVE; } - else if (!tor.isRunning || tier.announceAt == 0) + else if (!tor.is_running() || tier.announceAt == 0) { view.announceState = TR_TRACKER_INACTIVE; } @@ -1795,7 +1795,7 @@ void tr_announcer_impl::resetTorrent(tr_torrent* tor) } // kickstart any tiers that didn't get started - if (tor->isRunning) + if (tor->is_running()) { auto const now = tr_time(); for (auto& tier : newer->tiers) diff --git a/libtransmission/bandwidth.cc b/libtransmission/bandwidth.cc index e879b73e9..390702e72 100644 --- a/libtransmission/bandwidth.cc +++ b/libtransmission/bandwidth.cc @@ -18,7 +18,7 @@ #include "libtransmission/tr-assert.h" #include "libtransmission/utils.h" // tr_time_msec() -tr_bytes_per_second_t tr_bandwidth::getSpeedBytesPerSecond(RateControl& r, unsigned int interval_msec, uint64_t now) +tr_bytes_per_second_t tr_bandwidth::get_speed_bytes_per_second(RateControl& r, unsigned int interval_msec, uint64_t now) { if (now == 0) { @@ -52,7 +52,7 @@ tr_bytes_per_second_t tr_bandwidth::getSpeedBytesPerSecond(RateControl& r, unsig return r.cache_val_; } -void tr_bandwidth::notifyBandwidthConsumedBytes(uint64_t const now, RateControl* r, size_t size) +void tr_bandwidth::notify_bandwidth_consumed_bytes(uint64_t const now, RateControl* r, size_t size) { if (r->date_[r->newest_] + GranularityMSec >= now) { @@ -77,7 +77,7 @@ void tr_bandwidth::notifyBandwidthConsumedBytes(uint64_t const now, RateControl* tr_bandwidth::tr_bandwidth(tr_bandwidth* parent) { - this->setParent(parent); + this->set_parent(parent); } // --- @@ -112,7 +112,7 @@ void tr_bandwidth::deparent() noexcept parent_ = nullptr; } -void tr_bandwidth::setParent(tr_bandwidth* new_parent) +void tr_bandwidth::set_parent(tr_bandwidth* new_parent) { TR_ASSERT(this != new_parent); @@ -133,7 +133,7 @@ void tr_bandwidth::setParent(tr_bandwidth* new_parent) // --- -void tr_bandwidth::allocateBandwidth( +void tr_bandwidth::allocate_bandwidth( tr_priority_t parent_priority, unsigned int period_msec, std::vector>& peer_pool) @@ -160,11 +160,11 @@ void tr_bandwidth::allocateBandwidth( // traverse & repeat for the subtree for (auto* child : this->children_) { - child->allocateBandwidth(priority, period_msec, peer_pool); + child->allocate_bandwidth(priority, period_msec, peer_pool); } } -void tr_bandwidth::phaseOne(std::vector& peers, tr_direction dir) +void tr_bandwidth::phase_one(std::vector& peers, tr_direction dir) { // First phase of IO. Tries to distribute bandwidth fairly to keep faster // peers from starving the others. @@ -215,7 +215,7 @@ void tr_bandwidth::allocate(unsigned int period_msec) // allocateBandwidth () is a helper function with two purposes: // 1. allocate bandwidth to b and its subtree // 2. accumulate an array of all the peerIos from b and its subtree. - this->allocateBandwidth(TR_PRI_LOW, period_msec, refs); + this->allocate_bandwidth(TR_PRI_LOW, period_msec, refs); for (auto const& io : refs) { @@ -242,8 +242,8 @@ void tr_bandwidth::allocate(unsigned int period_msec) // and/or peers that can use it for (auto& peers : peer_arrays) { - phaseOne(peers, TR_UP); - phaseOne(peers, TR_DOWN); + phase_one(peers, TR_UP); + phase_one(peers, TR_DOWN); } // Second phase of IO. To help us scale in high bandwidth situations, @@ -276,8 +276,8 @@ size_t tr_bandwidth::clamp(uint64_t now, tr_direction dir, size_t byte_count) co now = tr_time_msec(); } - auto const current = this->getRawSpeedBytesPerSecond(now, TR_DOWN); - auto const desired = this->getDesiredSpeedBytesPerSecond(TR_DOWN); + auto const current = this->get_raw_speed_bytes_per_second(now, TR_DOWN); + auto const desired = this->get_desired_speed_bytes_per_second(TR_DOWN); auto const r = desired >= 1 ? static_cast(current) / desired : 0.0; if (r > 1.0) @@ -303,7 +303,7 @@ size_t tr_bandwidth::clamp(uint64_t now, tr_direction dir, size_t byte_count) co return byte_count; } -void tr_bandwidth::notifyBandwidthConsumed(tr_direction dir, size_t byte_count, bool is_piece_data, uint64_t now) +void tr_bandwidth::notify_bandwidth_consumed(tr_direction dir, size_t byte_count, bool is_piece_data, uint64_t now) { TR_ASSERT(tr_isDirection(dir)); @@ -330,35 +330,35 @@ void tr_bandwidth::notifyBandwidthConsumed(tr_direction dir, size_t byte_count, #endif - notifyBandwidthConsumedBytes(now, &band->raw_, byte_count); + notify_bandwidth_consumed_bytes(now, &band->raw_, byte_count); if (is_piece_data) { - notifyBandwidthConsumedBytes(now, &band->piece_, byte_count); + notify_bandwidth_consumed_bytes(now, &band->piece_, byte_count); } if (this->parent_ != nullptr) { - this->parent_->notifyBandwidthConsumed(dir, byte_count, is_piece_data, now); + this->parent_->notify_bandwidth_consumed(dir, byte_count, is_piece_data, now); } } // --- -tr_bandwidth_limits tr_bandwidth::getLimits() const +tr_bandwidth_limits tr_bandwidth::get_limits() const { tr_bandwidth_limits limits; - limits.up_limit_KBps = tr_toSpeedKBps(this->getDesiredSpeedBytesPerSecond(TR_UP)); - limits.down_limit_KBps = tr_toSpeedKBps(this->getDesiredSpeedBytesPerSecond(TR_DOWN)); - limits.up_limited = this->isLimited(TR_UP); - limits.down_limited = this->isLimited(TR_DOWN); + limits.up_limit_KBps = tr_toSpeedKBps(this->get_desired_speed_bytes_per_second(TR_UP)); + limits.down_limit_KBps = tr_toSpeedKBps(this->get_desired_speed_bytes_per_second(TR_DOWN)); + limits.up_limited = this->is_limited(TR_UP); + limits.down_limited = this->is_limited(TR_DOWN); return limits; } -void tr_bandwidth::setLimits(tr_bandwidth_limits const* limits) +void tr_bandwidth::set_limits(tr_bandwidth_limits const* limits) { - this->setDesiredSpeedBytesPerSecond(TR_UP, tr_toSpeedBytes(limits->up_limit_KBps)); - this->setDesiredSpeedBytesPerSecond(TR_DOWN, tr_toSpeedBytes(limits->down_limit_KBps)); - this->setLimited(TR_UP, limits->up_limited); - this->setLimited(TR_DOWN, limits->down_limited); + this->set_desired_speed_bytes_per_second(TR_UP, tr_toSpeedBytes(limits->up_limit_KBps)); + this->set_desired_speed_bytes_per_second(TR_DOWN, tr_toSpeedBytes(limits->down_limit_KBps)); + this->set_limited(TR_UP, limits->up_limited); + this->set_limited(TR_DOWN, limits->down_limited); } diff --git a/libtransmission/bandwidth.h b/libtransmission/bandwidth.h index 85eed3914..b453fe8d3 100644 --- a/libtransmission/bandwidth.h +++ b/libtransmission/bandwidth.h @@ -101,7 +101,7 @@ public: tr_bandwidth(tr_bandwidth&) = delete; // @brief Sets the peer. nullptr is allowed. - void setPeer(std::weak_ptr peer) noexcept + void set_peer(std::weak_ptr peer) noexcept { this->peer_ = std::move(peer); } @@ -110,21 +110,21 @@ public: * @brief Notify the bandwidth object that some of its allocated bandwidth has been consumed. * This is is usually invoked by the peer-io after a read or write. */ - void notifyBandwidthConsumed(tr_direction dir, size_t byte_count, bool is_piece_data, uint64_t now); + void notify_bandwidth_consumed(tr_direction dir, size_t byte_count, bool is_piece_data, uint64_t now); /** * @brief allocate the next `period_msec`'s worth of bandwidth for the peer-ios to consume */ void allocate(unsigned int period_msec); - void setParent(tr_bandwidth* new_parent); + void set_parent(tr_bandwidth* new_parent); - [[nodiscard]] constexpr tr_priority_t getPriority() const noexcept + [[nodiscard]] constexpr tr_priority_t get_priority() const noexcept { return this->priority_; } - constexpr void setPriority(tr_priority_t prio) noexcept + constexpr void set_priority(tr_priority_t prio) noexcept { this->priority_ = prio; } @@ -138,19 +138,19 @@ public: } /** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */ - [[nodiscard]] auto getRawSpeedBytesPerSecond(uint64_t const now, tr_direction const dir) const + [[nodiscard]] auto get_raw_speed_bytes_per_second(uint64_t const now, tr_direction const dir) const { TR_ASSERT(tr_isDirection(dir)); - return getSpeedBytesPerSecond(this->band_[dir].raw_, HistoryMSec, now); + return get_speed_bytes_per_second(this->band_[dir].raw_, HistoryMSec, now); } /** @brief Get the number of piece data bytes read or sent by this bandwidth subtree. */ - [[nodiscard]] auto getPieceSpeedBytesPerSecond(uint64_t const now, tr_direction const dir) const + [[nodiscard]] auto get_piece_speed_bytes_per_second(uint64_t const now, tr_direction const dir) const { TR_ASSERT(tr_isDirection(dir)); - return getSpeedBytesPerSecond(this->band_[dir].piece_, HistoryMSec, now); + return get_speed_bytes_per_second(this->band_[dir].piece_, HistoryMSec, now); } /** @@ -158,7 +158,7 @@ public: * @see `tr_bandwidth::allocate` * @see `tr_bandwidth::getDesiredSpeed` */ - constexpr bool setDesiredSpeedBytesPerSecond(tr_direction dir, tr_bytes_per_second_t desired_speed) + constexpr bool set_desired_speed_bytes_per_second(tr_direction dir, tr_bytes_per_second_t desired_speed) { auto& value = this->band_[dir].desired_speed_bps_; bool const did_change = desired_speed != value; @@ -170,27 +170,27 @@ public: * @brief Get the desired speed for the bandwidth subtree. * @see `tr_bandwidth::setDesiredSpeed` */ - [[nodiscard]] constexpr auto getDesiredSpeedBytesPerSecond(tr_direction dir) const + [[nodiscard]] constexpr auto get_desired_speed_bytes_per_second(tr_direction dir) const { return this->band_[dir].desired_speed_bps_; } [[nodiscard]] bool is_maxed_out(tr_direction dir, uint64_t now_msec) const noexcept { - if (!isLimited(dir)) + if (!is_limited(dir)) { return false; } - auto const got = getPieceSpeedBytesPerSecond(now_msec, dir); - auto const want = getDesiredSpeedBytesPerSecond(dir); + auto const got = get_piece_speed_bytes_per_second(now_msec, dir); + auto const want = get_desired_speed_bytes_per_second(dir); return got >= want; } /** * @brief Set whether or not this bandwidth should throttle its peer-io's speeds */ - constexpr bool setLimited(tr_direction dir, bool is_limited) + constexpr bool set_limited(tr_direction dir, bool is_limited) { bool* value = &this->band_[dir].is_limited_; bool const did_change = is_limited != *value; @@ -201,7 +201,7 @@ public: /** * @return nonzero if this bandwidth throttles its peer-ios speeds */ - [[nodiscard]] constexpr bool isLimited(tr_direction dir) const noexcept + [[nodiscard]] constexpr bool is_limited(tr_direction dir) const noexcept { return this->band_[dir].is_limited_; } @@ -212,7 +212,7 @@ public: * But when we set a torrent's speed mode to `TR_SPEEDLIMIT_UNLIMITED`, then * in that particular case we want to ignore the global speed limit... */ - constexpr bool honorParentLimits(tr_direction direction, bool is_enabled) + constexpr bool honor_parent_limits(tr_direction direction, bool is_enabled) { bool* value = &this->band_[direction].honor_parent_limits_; bool const did_change = is_enabled != *value; @@ -220,16 +220,16 @@ public: return did_change; } - [[nodiscard]] constexpr bool areParentLimitsHonored(tr_direction direction) const + [[nodiscard]] constexpr bool are_parent_limits_honored(tr_direction direction) const { TR_ASSERT(tr_isDirection(direction)); return this->band_[direction].honor_parent_limits_; } - [[nodiscard]] tr_bandwidth_limits getLimits() const; + [[nodiscard]] tr_bandwidth_limits get_limits() const; - void setLimits(tr_bandwidth_limits const* limits); + void set_limits(tr_bandwidth_limits const* limits); private: struct RateControl @@ -251,7 +251,7 @@ private: bool honor_parent_limits_ = true; }; - static tr_bytes_per_second_t getSpeedBytesPerSecond(RateControl& r, unsigned int interval_msec, uint64_t now); + static tr_bytes_per_second_t get_speed_bytes_per_second(RateControl& r, unsigned int interval_msec, uint64_t now); [[nodiscard]] constexpr auto* parent() noexcept { @@ -260,13 +260,13 @@ private: void deparent() noexcept; - static void notifyBandwidthConsumedBytes(uint64_t now, RateControl* r, size_t size); + static void notify_bandwidth_consumed_bytes(uint64_t now, RateControl* r, size_t size); [[nodiscard]] size_t clamp(uint64_t now, tr_direction dir, size_t byte_count) const; - static void phaseOne(std::vector& peers, tr_direction dir); + static void phase_one(std::vector& peers, tr_direction dir); - void allocateBandwidth( + void allocate_bandwidth( tr_priority_t parent_priority, unsigned int period_msec, std::vector>& peer_pool); diff --git a/libtransmission/bitfield.cc b/libtransmission/bitfield.cc index fdd82ea1d..bdfaca4e6 100644 --- a/libtransmission/bitfield.cc +++ b/libtransmission/bitfield.cc @@ -75,12 +75,12 @@ void setAllTrue(uint8_t* array, size_t bit_count) // --- -size_t tr_bitfield::countFlags() const noexcept +size_t tr_bitfield::count_flags() const noexcept { return rawCountFlags(std::data(flags_), std::size(flags_)); } -size_t tr_bitfield::countFlags(size_t begin, size_t end) const noexcept +size_t tr_bitfield::count_flags(size_t begin, size_t end) const noexcept { auto ret = size_t{}; size_t const first_byte = begin >> 3U; @@ -158,24 +158,24 @@ size_t tr_bitfield::countFlags(size_t begin, size_t end) const noexcept size_t tr_bitfield::count(size_t begin, size_t end) const { - if (hasAll()) + if (has_all()) { return end - begin; } - if (hasNone()) + if (has_none()) { return 0; } - return countFlags(begin, end); + return count_flags(begin, end); } // --- -bool tr_bitfield::isValid() const +bool tr_bitfield::is_valid() const { - return std::empty(flags_) || true_count_ == countFlags(); + return std::empty(flags_) || true_count_ == count_flags(); } std::vector tr_bitfield::raw() const @@ -190,7 +190,7 @@ std::vector tr_bitfield::raw() const auto raw = std::vector(n); - if (hasAll()) + if (has_all()) { setAllTrue(std::data(raw), bit_count_); } @@ -198,9 +198,9 @@ std::vector tr_bitfield::raw() const return raw; } -void tr_bitfield::ensureBitsAlloced(size_t n) +void tr_bitfield::ensure_bits_alloced(size_t n) { - bool const has_all = hasAll(); + bool const has_all = this->has_all(); /* Cant use getBytesNeededSafe as n can be > SIZE_MAX - 8. */ size_t const bytes_needed = has_all ? getBytesNeeded(std::max(n, true_count_)) : getBytesNeeded(n); @@ -215,7 +215,7 @@ void tr_bitfield::ensureBitsAlloced(size_t n) } } -bool tr_bitfield::ensureNthBitAlloced(size_t nth) +bool tr_bitfield::ensure_nth_bit_alloced(size_t nth) { // count is zero-based, so we need to allocate nth+1 bits before setting the nth */ if (nth == SIZE_MAX) @@ -223,11 +223,11 @@ bool tr_bitfield::ensureNthBitAlloced(size_t nth) return false; } - ensureBitsAlloced(nth + 1); + ensure_bits_alloced(nth + 1); return true; } -void tr_bitfield::setTrueCount(size_t n) noexcept +void tr_bitfield::set_true_count(size_t n) noexcept { TR_ASSERT(bit_count_ == 0 || n <= bit_count_); @@ -235,28 +235,28 @@ void tr_bitfield::setTrueCount(size_t n) noexcept have_all_hint_ = n == bit_count_; have_none_hint_ = n == 0; - if (hasAll() || hasNone()) + if (has_all() || has_none()) { - freeArray(); + free_array(); } - TR_ASSERT(isValid()); + TR_ASSERT(is_valid()); } -void tr_bitfield::incrementTrueCount(size_t inc) noexcept +void tr_bitfield::increment_true_count(size_t inc) noexcept { TR_ASSERT(bit_count_ == 0 || inc <= bit_count_); TR_ASSERT(bit_count_ == 0 || true_count_ <= bit_count_ - inc); - setTrueCount(true_count_ + inc); + set_true_count(true_count_ + inc); } -void tr_bitfield::decrementTrueCount(size_t dec) noexcept +void tr_bitfield::decrement_true_count(size_t dec) noexcept { TR_ASSERT(bit_count_ == 0 || dec <= bit_count_); TR_ASSERT(bit_count_ == 0 || true_count_ >= dec); - setTrueCount(true_count_ - dec); + set_true_count(true_count_ - dec); } // --- @@ -264,30 +264,30 @@ void tr_bitfield::decrementTrueCount(size_t dec) noexcept tr_bitfield::tr_bitfield(size_t bit_count) : bit_count_{ bit_count } { - TR_ASSERT(isValid()); + TR_ASSERT(is_valid()); } -void tr_bitfield::setHasNone() noexcept +void tr_bitfield::set_has_none() noexcept { - freeArray(); + free_array(); true_count_ = 0; have_all_hint_ = false; have_none_hint_ = true; - TR_ASSERT(isValid()); + TR_ASSERT(is_valid()); } -void tr_bitfield::setHasAll() noexcept +void tr_bitfield::set_has_all() noexcept { - freeArray(); + free_array(); true_count_ = bit_count_; have_all_hint_ = true; have_none_hint_ = false; - TR_ASSERT(isValid()); + TR_ASSERT(is_valid()); } -void tr_bitfield::setRaw(uint8_t const* raw, size_t byte_count) +void tr_bitfield::set_raw(uint8_t const* raw, size_t byte_count) { flags_.assign(raw, raw + byte_count); @@ -304,15 +304,15 @@ void tr_bitfield::setRaw(uint8_t const* raw, size_t byte_count) } } - rebuildTrueCount(); + rebuild_true_count(); } -void tr_bitfield::setFromBools(bool const* flags, size_t n) +void tr_bitfield::set_from_bools(bool const* flags, size_t n) { size_t true_count = 0; - freeArray(); - ensureBitsAlloced(n); + free_array(); + ensure_bits_alloced(n); for (size_t i = 0; i < n; ++i) { @@ -323,7 +323,7 @@ void tr_bitfield::setFromBools(bool const* flags, size_t n) } } - setTrueCount(true_count); + set_true_count(true_count); } void tr_bitfield::set(size_t nth, bool value) @@ -333,7 +333,7 @@ void tr_bitfield::set(size_t nth, bool value) return; } - if (!ensureNthBitAlloced(nth)) + if (!ensure_nth_bit_alloced(nth)) { return; } @@ -363,7 +363,7 @@ void tr_bitfield::set(size_t nth, bool value) } /* Sets bit range [begin, end) to 1 */ -void tr_bitfield::setSpan(size_t begin, size_t end, bool value) +void tr_bitfield::set_span(size_t begin, size_t end, bool value) { // bounds check end = std::min(end, bit_count_); @@ -383,7 +383,7 @@ void tr_bitfield::setSpan(size_t begin, size_t end, bool value) } --end; - if (!ensureNthBitAlloced(end)) + if (!ensure_nth_bit_alloced(end)) { return; } @@ -412,7 +412,7 @@ void tr_bitfield::setSpan(size_t begin, size_t end, bool value) } } - incrementTrueCount(new_count - old_count); + increment_true_count(new_count - old_count); } else { @@ -434,18 +434,18 @@ void tr_bitfield::setSpan(size_t begin, size_t end, bool value) } } - decrementTrueCount(old_count); + decrement_true_count(old_count); } } tr_bitfield& tr_bitfield::operator|=(tr_bitfield const& that) noexcept { - if (hasAll() || that.hasNone()) + if (has_all() || that.has_none()) { return *this; } - if (that.hasAll() || hasNone()) + if (that.has_all() || has_none()) { *this = that; return *this; @@ -458,18 +458,18 @@ tr_bitfield& tr_bitfield::operator|=(tr_bitfield const& that) noexcept flags_[i] |= that.flags_[i]; } - rebuildTrueCount(); + rebuild_true_count(); return *this; } tr_bitfield& tr_bitfield::operator&=(tr_bitfield const& that) noexcept { - if (hasNone() || that.hasAll()) + if (has_none() || that.has_all()) { return *this; } - if (that.hasNone() || hasAll()) + if (that.has_none() || has_all()) { *this = that; return *this; @@ -482,18 +482,18 @@ tr_bitfield& tr_bitfield::operator&=(tr_bitfield const& that) noexcept flags_[i] &= that.flags_[i]; } - rebuildTrueCount(); + rebuild_true_count(); return *this; } bool tr_bitfield::intersects(tr_bitfield const& that) const noexcept { - if (hasNone() || that.hasNone()) + if (has_none() || that.has_none()) { return false; } - if (hasAll() || that.hasAll()) + if (has_all() || that.has_all()) { return true; } diff --git a/libtransmission/bitfield.h b/libtransmission/bitfield.h index 9d1f60bdc..88b0f8ea8 100644 --- a/libtransmission/bitfield.h +++ b/libtransmission/bitfield.h @@ -41,41 +41,41 @@ class tr_bitfield public: explicit tr_bitfield(size_t bit_count); - void setHasAll() noexcept; - void setHasNone() noexcept; + void set_has_all() noexcept; + void set_has_none() noexcept; // set one or more bits void set(size_t nth, bool value = true); - void setSpan(size_t begin, size_t end, bool value = true); + void set_span(size_t begin, size_t end, bool value = true); void unset(size_t bit) { set(bit, false); } - void unsetSpan(size_t begin, size_t end) + void unset_span(size_t begin, size_t end) { - setSpan(begin, end, false); + set_span(begin, end, false); } - void setFromBools(bool const* flags, size_t n); + void set_from_bools(bool const* flags, size_t n); // "raw" here is in BEP0003 format: "The first byte of the bitfield // corresponds to indices 0 - 7 from high bit to low bit, respectively. // The next one 8-15, etc. Spare bits at the end are set to zero." - void setRaw(uint8_t const* raw, size_t byte_count); + void set_raw(uint8_t const* raw, size_t byte_count); [[nodiscard]] std::vector raw() const; - [[nodiscard]] constexpr bool hasAll() const noexcept + [[nodiscard]] constexpr bool has_all() const noexcept { return have_all_hint_ || (bit_count_ > 0 && bit_count_ == true_count_); } - [[nodiscard]] constexpr bool hasNone() const noexcept + [[nodiscard]] constexpr bool has_none() const noexcept { return have_none_hint_ || (bit_count_ > 0 && true_count_ == 0); } [[nodiscard]] TR_CONSTEXPR20 bool test(size_t bit) const { - return hasAll() || (!hasNone() && testFlag(bit)); + return has_all() || (!has_none() && test_flag(bit)); } [[nodiscard]] constexpr size_t count() const noexcept @@ -95,16 +95,16 @@ public: return size() == 0; } - [[nodiscard]] bool isValid() const; + [[nodiscard]] bool is_valid() const; [[nodiscard]] constexpr auto percent() const noexcept { - if (hasAll()) + if (has_all()) { return 1.0F; } - if (hasNone() || empty()) + if (has_none() || empty()) { return 0.0F; } @@ -117,10 +117,10 @@ public: [[nodiscard]] bool intersects(tr_bitfield const& that) const noexcept; private: - [[nodiscard]] size_t countFlags() const noexcept; - [[nodiscard]] size_t countFlags(size_t begin, size_t end) const noexcept; + [[nodiscard]] size_t count_flags() const noexcept; + [[nodiscard]] size_t count_flags(size_t begin, size_t end) const noexcept; - [[nodiscard]] TR_CONSTEXPR20 bool testFlag(size_t n) const + [[nodiscard]] TR_CONSTEXPR20 bool test_flag(size_t n) const { if (n >> 3U >= std::size(flags_)) { @@ -131,21 +131,21 @@ private: return ret; } - void ensureBitsAlloced(size_t n); - [[nodiscard]] bool ensureNthBitAlloced(size_t nth); + void ensure_bits_alloced(size_t n); + [[nodiscard]] bool ensure_nth_bit_alloced(size_t nth); - void freeArray() noexcept + void free_array() noexcept { // move-assign to ensure the reserve memory is cleared flags_ = std::vector{}; } - void incrementTrueCount(size_t inc) noexcept; - void decrementTrueCount(size_t dec) noexcept; - void setTrueCount(size_t n) noexcept; - void rebuildTrueCount() noexcept + void increment_true_count(size_t inc) noexcept; + void decrement_true_count(size_t dec) noexcept; + void set_true_count(size_t n) noexcept; + void rebuild_true_count() noexcept { - setTrueCount(countFlags()); + set_true_count(count_flags()); } std::vector flags_; diff --git a/libtransmission/block-info.cc b/libtransmission/block-info.cc index dada74051..3ead4b39e 100644 --- a/libtransmission/block-info.cc +++ b/libtransmission/block-info.cc @@ -8,7 +8,7 @@ #include "libtransmission/block-info.h" #include "libtransmission/tr-assert.h" -void tr_block_info::initSizes(uint64_t total_size_in, uint32_t piece_size_in) noexcept +void tr_block_info::init_sizes(uint64_t total_size_in, uint32_t piece_size_in) noexcept { TR_ASSERT(piece_size_in == 0 || piece_size_in >= BlockSize); if (piece_size_in == 0) diff --git a/libtransmission/block-info.h b/libtransmission/block-info.h index 6d0158d39..d2f844b97 100644 --- a/libtransmission/block-info.h +++ b/libtransmission/block-info.h @@ -29,37 +29,37 @@ public: tr_block_info(uint64_t total_size_in, uint32_t piece_size_in) noexcept { - initSizes(total_size_in, piece_size_in); + init_sizes(total_size_in, piece_size_in); } - void initSizes(uint64_t total_size_in, uint32_t piece_size_in) noexcept; + void init_sizes(uint64_t total_size_in, uint32_t piece_size_in) noexcept; - [[nodiscard]] constexpr auto blockCount() const noexcept + [[nodiscard]] constexpr auto block_count() const noexcept { return n_blocks_; } - [[nodiscard]] constexpr auto blockSize(tr_block_index_t block) const noexcept + [[nodiscard]] constexpr auto block_size(tr_block_index_t block) const noexcept { return block + 1 == n_blocks_ ? final_block_size_ : BlockSize; } - [[nodiscard]] constexpr auto pieceCount() const noexcept + [[nodiscard]] constexpr auto piece_count() const noexcept { return n_pieces_; } - [[nodiscard]] constexpr auto pieceSize() const noexcept + [[nodiscard]] constexpr auto piece_size() const noexcept { return piece_size_; } - [[nodiscard]] constexpr auto pieceSize(tr_piece_index_t piece) const noexcept + [[nodiscard]] constexpr auto piece_size(tr_piece_index_t piece) const noexcept { - return piece + 1 == n_pieces_ ? final_piece_size_ : pieceSize(); + return piece + 1 == n_pieces_ ? final_piece_size_ : piece_size(); } - [[nodiscard]] constexpr auto totalSize() const noexcept + [[nodiscard]] constexpr auto total_size() const noexcept { return total_size_; } @@ -86,73 +86,73 @@ public: }; // Location of the torrent's nth byte - [[nodiscard]] constexpr auto byteLoc(uint64_t byte_idx) const noexcept + [[nodiscard]] constexpr auto byte_loc(uint64_t byte_idx) const noexcept { auto loc = Location{}; - if (isInitialized()) + if (is_initialized()) { loc.byte = byte_idx; - if (byte_idx == totalSize()) // handle 0-byte files at the end of a torrent + if (byte_idx == total_size()) // handle 0-byte files at the end of a torrent { - loc.block = blockCount() - 1; - loc.piece = pieceCount() - 1; + loc.block = block_count() - 1; + loc.piece = piece_count() - 1; } else { loc.block = byte_idx / BlockSize; - loc.piece = byte_idx / pieceSize(); + loc.piece = byte_idx / piece_size(); } loc.block_offset = static_cast(loc.byte - (uint64_t{ loc.block } * BlockSize)); - loc.piece_offset = static_cast(loc.byte - (uint64_t{ loc.piece } * pieceSize())); + loc.piece_offset = static_cast(loc.byte - (uint64_t{ loc.piece } * piece_size())); } return loc; } // Location of the first byte in `block`. - [[nodiscard]] constexpr auto blockLoc(tr_block_index_t block) const noexcept + [[nodiscard]] constexpr auto block_loc(tr_block_index_t block) const noexcept { - return byteLoc(uint64_t{ block } * BlockSize); + return byte_loc(uint64_t{ block } * BlockSize); } // Location of the first byte (+ optional offset and length) in `piece` - [[nodiscard]] constexpr auto pieceLoc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const noexcept + [[nodiscard]] constexpr auto piece_loc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const noexcept { - return byteLoc(uint64_t{ piece } * pieceSize() + offset + length); + return byte_loc(uint64_t{ piece } * piece_size() + offset + length); } - [[nodiscard]] constexpr tr_block_span_t blockSpanForPiece(tr_piece_index_t piece) const noexcept + [[nodiscard]] constexpr tr_block_span_t block_span_for_piece(tr_piece_index_t piece) const noexcept { - if (!isInitialized()) + if (!is_initialized()) { return { 0U, 0U }; } - return { pieceLoc(piece).block, pieceLastLoc(piece).block + 1 }; + return { piece_loc(piece).block, piece_last_loc(piece).block + 1 }; } - [[nodiscard]] constexpr tr_byte_span_t byteSpanForPiece(tr_piece_index_t piece) const noexcept + [[nodiscard]] constexpr tr_byte_span_t byte_span_for_piece(tr_piece_index_t piece) const noexcept { - if (!isInitialized()) + if (!is_initialized()) { return { 0U, 0U }; } - auto const offset = pieceLoc(piece).byte; - return { offset, offset + pieceSize(piece) }; + auto const offset = piece_loc(piece).byte; + return { offset, offset + piece_size(piece) }; } private: // Location of the last byte in `piece`. - [[nodiscard]] constexpr Location pieceLastLoc(tr_piece_index_t piece) const noexcept + [[nodiscard]] constexpr Location piece_last_loc(tr_piece_index_t piece) const noexcept { - return byteLoc(static_cast(piece) * pieceSize() + pieceSize(piece) - 1); + return byte_loc(static_cast(piece) * piece_size() + piece_size(piece) - 1); } - [[nodiscard]] constexpr bool isInitialized() const noexcept + [[nodiscard]] constexpr bool is_initialized() const noexcept { return piece_size_ != 0; } diff --git a/libtransmission/cache.cc b/libtransmission/cache.cc index 47d06441e..1767071e3 100644 --- a/libtransmission/cache.cc +++ b/libtransmission/cache.cc @@ -105,7 +105,7 @@ int Cache::writeContiguous(CIter const begin, CIter const end) const return EINVAL; } - auto const loc = tor->blockLoc(block); + auto const loc = tor->block_loc(block); if (auto const err = tr_ioWrite(tor, loc, std::size(*towrite), std::data(*towrite)); err != 0) { diff --git a/libtransmission/completion.cc b/libtransmission/completion.cc index 496c59850..685258c01 100644 --- a/libtransmission/completion.cc +++ b/libtransmission/completion.cc @@ -14,26 +14,26 @@ #include "libtransmission/torrent.h" #include "libtransmission/tr-assert.h" -uint64_t tr_completion::computeHasValid() const +uint64_t tr_completion::compute_has_valid() const { uint64_t size = 0; - for (tr_piece_index_t piece = 0, n_pieces = block_info_->pieceCount(); piece < n_pieces; ++piece) + for (tr_piece_index_t piece = 0, n_pieces = block_info_->piece_count(); piece < n_pieces; ++piece) { - if (hasPiece(piece)) + if (has_piece(piece)) { - size += block_info_->pieceSize(piece); + size += block_info_->piece_size(piece); } } return size; } -uint64_t tr_completion::hasValid() const +uint64_t tr_completion::has_valid() const { if (!has_valid_) { - auto const val = computeHasValid(); + auto const val = compute_has_valid(); has_valid_ = val; return val; } @@ -41,35 +41,35 @@ uint64_t tr_completion::hasValid() const return *has_valid_; } -uint64_t tr_completion::computeSizeWhenDone() const +uint64_t tr_completion::compute_size_when_done() const { - if (hasAll()) + if (has_all()) { - return block_info_->totalSize(); + return block_info_->total_size(); } // count bytes that we want or that we already have auto size = uint64_t{ 0 }; - for (tr_piece_index_t piece = 0, n_pieces = block_info_->pieceCount(); piece < n_pieces; ++piece) + for (tr_piece_index_t piece = 0, n_pieces = block_info_->piece_count(); piece < n_pieces; ++piece) { - if (tor_->pieceIsWanted(piece)) + if (tor_->piece_is_wanted(piece)) { - size += block_info_->pieceSize(piece); + size += block_info_->piece_size(piece); } else { - size += countHasBytesInPiece(piece); + size += count_has_bytes_in_piece(piece); } } return size; } -uint64_t tr_completion::sizeWhenDone() const +uint64_t tr_completion::size_when_done() const { if (!size_when_done_) { - auto const value = computeSizeWhenDone(); + auto const value = compute_size_when_done(); size_when_done_ = value; return value; } @@ -77,7 +77,7 @@ uint64_t tr_completion::sizeWhenDone() const return *size_when_done_; } -void tr_completion::amountDone(float* tab, size_t n_tabs) const +void tr_completion::amount_done(float* tab, size_t n_tabs) const { if (n_tabs < 1) { @@ -94,95 +94,95 @@ void tr_completion::amountDone(float* tab, size_t n_tabs) const } } -std::vector tr_completion::createPieceBitfield() const +std::vector tr_completion::create_piece_bitfield() const { - size_t const n = block_info_->pieceCount(); + size_t const n = block_info_->piece_count(); auto pieces = tr_bitfield{ n }; // NOLINTNEXTLINE modernize-avoid-c-arrays auto flags = std::make_unique(n); for (tr_piece_index_t piece = 0; piece < n; ++piece) { - flags[piece] = hasPiece(piece); + flags[piece] = has_piece(piece); } - pieces.setFromBools(flags.get(), n); + pieces.set_from_bools(flags.get(), n); return pieces.raw(); } // --- mutators -void tr_completion::addBlock(tr_block_index_t block) +void tr_completion::add_block(tr_block_index_t block) { - if (hasBlock(block)) + if (has_block(block)) { return; // already had it } blocks_.set(block); - size_now_ += block_info_->blockSize(block); + size_now_ += block_info_->block_size(block); size_when_done_.reset(); has_valid_.reset(); } -void tr_completion::setBlocks(tr_bitfield blocks) +void tr_completion::set_blocks(tr_bitfield blocks) { TR_ASSERT(std::size(blocks_) == std::size(blocks)); blocks_ = std::move(blocks); - size_now_ = countHasBytesInSpan({ 0, block_info_->totalSize() }); + size_now_ = count_has_bytes_in_span({ 0, block_info_->total_size() }); size_when_done_.reset(); has_valid_.reset(); } -void tr_completion::setHasAll() noexcept +void tr_completion::set_has_all() noexcept { - auto const total_size = block_info_->totalSize(); + auto const total_size = block_info_->total_size(); - blocks_.setHasAll(); + blocks_.set_has_all(); size_now_ = total_size; size_when_done_ = total_size; has_valid_ = total_size; } -void tr_completion::addPiece(tr_piece_index_t piece) +void tr_completion::add_piece(tr_piece_index_t piece) { - auto const span = block_info_->blockSpanForPiece(piece); + auto const span = block_info_->block_span_for_piece(piece); for (tr_block_index_t block = span.begin; block < span.end; ++block) { - addBlock(block); + add_block(block); } } -void tr_completion::removeBlock(tr_block_index_t block) +void tr_completion::remove_block(tr_block_index_t block) { - if (!hasBlock(block)) + if (!has_block(block)) { return; // already didn't have it } blocks_.unset(block); - size_now_ -= block_info_->blockSize(block); + size_now_ -= block_info_->block_size(block); size_when_done_.reset(); has_valid_.reset(); } -void tr_completion::removePiece(tr_piece_index_t piece) +void tr_completion::remove_piece(tr_piece_index_t piece) { - for (auto [block, end] = block_info_->blockSpanForPiece(piece); block < end; ++block) + for (auto [block, end] = block_info_->block_span_for_piece(piece); block < end; ++block) { - removeBlock(block); + remove_block(block); } } -uint64_t tr_completion::countHasBytesInSpan(tr_byte_span_t span) const +uint64_t tr_completion::count_has_bytes_in_span(tr_byte_span_t span) const { // confirm the span is valid - span.begin = std::clamp(span.begin, uint64_t{ 0 }, block_info_->totalSize()); - span.end = std::clamp(span.end, uint64_t{ 0 }, block_info_->totalSize()); + span.begin = std::clamp(span.begin, uint64_t{ 0 }, block_info_->total_size()); + span.end = std::clamp(span.end, uint64_t{ 0 }, block_info_->total_size()); auto const [begin_byte, end_byte] = span; if (begin_byte >= end_byte) { @@ -190,19 +190,19 @@ uint64_t tr_completion::countHasBytesInSpan(tr_byte_span_t span) const } // get the block span of the byte span - auto const begin_block = block_info_->byteLoc(begin_byte).block; - auto const final_block = block_info_->byteLoc(end_byte - 1).block; + auto const begin_block = block_info_->byte_loc(begin_byte).block; + auto const final_block = block_info_->byte_loc(end_byte - 1).block; // if the entire span is in a single block if (begin_block == final_block) { - return hasBlock(begin_block) ? end_byte - begin_byte : 0; + return has_block(begin_block) ? end_byte - begin_byte : 0; } auto total = uint64_t{}; // the first block - if (hasBlock(begin_block)) + if (has_block(begin_block)) { uint64_t u = begin_block + 1; u *= tr_block_info::BlockSize; @@ -219,7 +219,7 @@ uint64_t tr_completion::countHasBytesInSpan(tr_byte_span_t span) const } // the last block - if (hasBlock(final_block)) + if (has_block(final_block)) { uint64_t u = final_block; u *= tr_block_info::BlockSize; diff --git a/libtransmission/completion.h b/libtransmission/completion.h index 4afdd094e..1495ba22a 100644 --- a/libtransmission/completion.h +++ b/libtransmission/completion.h @@ -27,7 +27,7 @@ struct tr_completion { struct torrent_view { - virtual bool pieceIsWanted(tr_piece_index_t piece) const = 0; + virtual bool piece_is_wanted(tr_piece_index_t piece) const = 0; virtual ~torrent_view() = default; }; @@ -35,9 +35,9 @@ struct tr_completion explicit tr_completion(torrent_view const* tor, tr_block_info const* block_info) : tor_{ tor } , block_info_{ block_info } - , blocks_{ block_info_->blockCount() } + , blocks_{ block_info_->block_count() } { - blocks_.setHasNone(); + blocks_.set_has_none(); } [[nodiscard]] constexpr tr_bitfield const& blocks() const noexcept @@ -45,70 +45,70 @@ struct tr_completion return blocks_; } - [[nodiscard]] constexpr bool hasAll() const noexcept + [[nodiscard]] constexpr bool has_all() const noexcept { - return hasMetainfo() && blocks_.hasAll(); + return has_metainfo() && blocks_.has_all(); } - [[nodiscard]] TR_CONSTEXPR20 bool hasBlock(tr_block_index_t block) const + [[nodiscard]] TR_CONSTEXPR20 bool has_block(tr_block_index_t block) const { return blocks_.test(block); } - [[nodiscard]] bool hasBlocks(tr_block_span_t span) const + [[nodiscard]] bool has_blocks(tr_block_span_t span) const { return blocks_.count(span.begin, span.end) == span.end - span.begin; } - [[nodiscard]] constexpr bool hasNone() const noexcept + [[nodiscard]] constexpr bool has_none() const noexcept { - return !hasMetainfo() || blocks_.hasNone(); + return !has_metainfo() || blocks_.has_none(); } - [[nodiscard]] bool hasPiece(tr_piece_index_t piece) const + [[nodiscard]] bool has_piece(tr_piece_index_t piece) const { - return block_info_->pieceSize() != 0 && countMissingBlocksInPiece(piece) == 0; + return block_info_->piece_size() != 0 && count_missing_blocks_in_piece(piece) == 0; } - [[nodiscard]] constexpr uint64_t hasTotal() const noexcept + [[nodiscard]] constexpr uint64_t has_total() const noexcept { return size_now_; } - [[nodiscard]] uint64_t hasValid() const; + [[nodiscard]] uint64_t has_valid() const; - [[nodiscard]] auto leftUntilDone() const + [[nodiscard]] auto left_until_done() const { - return sizeWhenDone() - hasTotal(); + return size_when_done() - has_total(); } - [[nodiscard]] constexpr double percentComplete() const + [[nodiscard]] constexpr double percent_complete() const { - auto const denom = block_info_->totalSize(); + auto const denom = block_info_->total_size(); return denom ? std::clamp(double(size_now_) / denom, 0.0, 1.0) : 0.0; } - [[nodiscard]] double percentDone() const + [[nodiscard]] double percent_done() const { - auto const denom = sizeWhenDone(); + auto const denom = size_when_done(); return denom ? std::clamp(double(size_now_) / denom, 0.0, 1.0) : 0.0; } - [[nodiscard]] uint64_t sizeWhenDone() const; + [[nodiscard]] uint64_t size_when_done() const; [[nodiscard]] tr_completeness status() const { - if (!hasMetainfo()) + if (!has_metainfo()) { return TR_LEECH; } - if (hasAll()) + if (has_all()) { return TR_SEED; } - if (size_now_ == sizeWhenDone()) + if (size_now_ == size_when_done()) { return TR_PARTIAL_SEED; } @@ -116,63 +116,63 @@ struct tr_completion return TR_LEECH; } - [[nodiscard]] std::vector createPieceBitfield() const; + [[nodiscard]] std::vector create_piece_bitfield() const; - [[nodiscard]] size_t countMissingBlocksInPiece(tr_piece_index_t piece) const + [[nodiscard]] size_t count_missing_blocks_in_piece(tr_piece_index_t piece) const { - auto const [begin, end] = block_info_->blockSpanForPiece(piece); + auto const [begin, end] = block_info_->block_span_for_piece(piece); return (end - begin) - blocks_.count(begin, end); } - [[nodiscard]] size_t countMissingBytesInPiece(tr_piece_index_t piece) const + [[nodiscard]] size_t count_missing_bytes_in_piece(tr_piece_index_t piece) const { - return block_info_->pieceSize(piece) - countHasBytesInPiece(piece); + return block_info_->piece_size(piece) - count_has_bytes_in_piece(piece); } - void amountDone(float* tab, size_t n_tabs) const; + void amount_done(float* tab, size_t n_tabs) const; - void addBlock(tr_block_index_t block); - void addPiece(tr_piece_index_t piece); - void removePiece(tr_piece_index_t piece); + void add_block(tr_block_index_t block); + void add_piece(tr_piece_index_t piece); + void remove_piece(tr_piece_index_t piece); - void setHasPiece(tr_piece_index_t i, bool has) + void set_has_piece(tr_piece_index_t i, bool has) { if (has) { - addPiece(i); + add_piece(i); } else { - removePiece(i); + remove_piece(i); } } - void setHasAll() noexcept; + void set_has_all() noexcept; - void setBlocks(tr_bitfield blocks); + void set_blocks(tr_bitfield blocks); - void invalidateSizeWhenDone() + void invalidate_size_when_done() { size_when_done_.reset(); } - [[nodiscard]] uint64_t countHasBytesInSpan(tr_byte_span_t) const; + [[nodiscard]] uint64_t count_has_bytes_in_span(tr_byte_span_t) const; - [[nodiscard]] constexpr bool hasMetainfo() const noexcept + [[nodiscard]] constexpr bool has_metainfo() const noexcept { return !std::empty(blocks_); } private: - [[nodiscard]] uint64_t computeHasValid() const; - [[nodiscard]] uint64_t computeSizeWhenDone() const; + [[nodiscard]] uint64_t compute_has_valid() const; + [[nodiscard]] uint64_t compute_size_when_done() const; - [[nodiscard]] uint64_t countHasBytesInPiece(tr_piece_index_t piece) const + [[nodiscard]] uint64_t count_has_bytes_in_piece(tr_piece_index_t piece) const { - return countHasBytesInSpan(block_info_->byteSpanForPiece(piece)); + return count_has_bytes_in_span(block_info_->byte_span_for_piece(piece)); } - void removeBlock(tr_block_index_t block); + void remove_block(tr_block_index_t block); torrent_view const* tor_; tr_block_info const* block_info_; diff --git a/libtransmission/file-piece-map.cc b/libtransmission/file-piece-map.cc index 6d8b592a6..642422833 100644 --- a/libtransmission/file-piece-map.cc +++ b/libtransmission/file-piece-map.cc @@ -29,7 +29,7 @@ void tr_file_piece_map::reset(tr_block_info const& block_info, uint64_t const* f { auto const file_size = file_sizes[i]; auto const begin_byte = offset; - auto const begin_piece = block_info.byteLoc(begin_byte).piece; + auto const begin_piece = block_info.byte_loc(begin_byte).piece; auto end_byte = tr_byte_index_t{}; auto end_piece = tr_piece_index_t{}; @@ -39,7 +39,7 @@ void tr_file_piece_map::reset(tr_block_info const& block_info, uint64_t const* f { end_byte = offset + file_size; auto const final_byte = end_byte - 1; - auto const final_piece = block_info.byteLoc(final_byte).piece; + auto const final_piece = block_info.byte_loc(final_byte).piece; end_piece = final_piece + 1; edge_pieces.insert(final_piece); @@ -60,16 +60,16 @@ void tr_file_piece_map::reset(tr_block_info const& block_info, uint64_t const* f void tr_file_piece_map::reset(tr_torrent_metainfo const& tm) { - auto const n = tm.fileCount(); + auto const n = tm.file_count(); auto file_sizes = std::vector(n); for (tr_file_index_t i = 0; i < n; ++i) { - file_sizes[i] = tm.fileSize(i); + file_sizes[i] = tm.file_size(i); } - reset({ tm.totalSize(), tm.pieceSize() }, std::data(file_sizes), std::size(file_sizes)); + reset({ tm.total_size(), tm.piece_size() }, std::data(file_sizes), std::size(file_sizes)); } -tr_file_piece_map::file_span_t tr_file_piece_map::fileSpan(tr_piece_index_t piece) const +tr_file_piece_map::file_span_t tr_file_piece_map::file_span(tr_piece_index_t piece) const { constexpr auto Compare = CompareToSpan{}; auto const begin = std::begin(file_pieces_); @@ -77,7 +77,7 @@ tr_file_piece_map::file_span_t tr_file_piece_map::fileSpan(tr_piece_index_t piec return { tr_piece_index_t(equal_begin - begin), tr_piece_index_t(equal_end - begin) }; } -tr_file_piece_map::file_offset_t tr_file_piece_map::fileOffset(uint64_t offset) const +tr_file_piece_map::file_offset_t tr_file_piece_map::file_offset(uint64_t offset) const { constexpr auto Compare = CompareToSpan{}; auto const begin = std::begin(file_bytes_); @@ -119,7 +119,7 @@ void tr_file_priorities::set(tr_file_index_t const* files, size_t n, tr_priority } } -tr_priority_t tr_file_priorities::filePriority(tr_file_index_t file) const +tr_priority_t tr_file_priorities::file_priority(tr_file_index_t file) const { TR_ASSERT(file < std::size(*fpm_)); @@ -131,7 +131,7 @@ tr_priority_t tr_file_priorities::filePriority(tr_file_index_t file) const return priorities_[file]; } -tr_priority_t tr_file_priorities::piecePriority(tr_piece_index_t piece) const +tr_priority_t tr_file_priorities::piece_priority(tr_piece_index_t piece) const { // increase priority if a file begins or ends in this piece // because that makes life easier for code/users using at incomplete files. @@ -142,7 +142,7 @@ tr_priority_t tr_file_priorities::piecePriority(tr_piece_index_t piece) const } // check the priorities of the files that touch this piece - if (auto const [begin_file, end_file] = fpm_->fileSpan(piece); end_file <= std::size(priorities_)) + if (auto const [begin_file, end_file] = fpm_->file_span(piece); end_file <= std::size(priorities_)) { auto const begin = std::begin(priorities_) + begin_file; auto const end = std::begin(priorities_) + end_file; @@ -161,7 +161,7 @@ void tr_files_wanted::reset(tr_file_piece_map const* fpm) { fpm_ = fpm; wanted_ = tr_bitfield{ std::size(*fpm) }; - wanted_.setHasAll(); // by default we want all files + wanted_.set_has_all(); // by default we want all files } void tr_files_wanted::set(tr_file_index_t file, bool wanted) @@ -177,13 +177,13 @@ void tr_files_wanted::set(tr_file_index_t const* files, size_t n, bool wanted) } } -bool tr_files_wanted::pieceWanted(tr_piece_index_t piece) const +bool tr_files_wanted::piece_wanted(tr_piece_index_t piece) const { - if (wanted_.hasAll()) + if (wanted_.has_all()) { return true; } - auto const [begin, end] = fpm_->fileSpan(piece); + auto const [begin, end] = fpm_->file_span(piece); return wanted_.count(begin, end) != 0; } diff --git a/libtransmission/file-piece-map.h b/libtransmission/file-piece-map.h index bc20d15f4..d08ffaa38 100644 --- a/libtransmission/file-piece-map.h +++ b/libtransmission/file-piece-map.h @@ -55,14 +55,14 @@ public: void reset(tr_torrent_metainfo const& tm); - [[nodiscard]] TR_CONSTEXPR20 piece_span_t pieceSpan(tr_file_index_t file) const noexcept + [[nodiscard]] TR_CONSTEXPR20 piece_span_t piece_span(tr_file_index_t file) const noexcept { return file_pieces_[file]; } - [[nodiscard]] file_span_t fileSpan(tr_piece_index_t piece) const; + [[nodiscard]] file_span_t file_span(tr_piece_index_t piece) const; - [[nodiscard]] file_offset_t fileOffset(uint64_t offset) const; + [[nodiscard]] file_offset_t file_offset(uint64_t offset) const; [[nodiscard]] TR_CONSTEXPR20 size_t size() const { @@ -75,7 +75,7 @@ public: } // TODO(ckerr) minor wart here, two identical span types - [[nodiscard]] TR_CONSTEXPR20 tr_byte_span_t byteSpan(tr_file_index_t file) const + [[nodiscard]] TR_CONSTEXPR20 tr_byte_span_t byte_span(tr_file_index_t file) const { auto const& span = file_bytes_.at(file); return tr_byte_span_t{ span.begin, span.end }; @@ -145,8 +145,8 @@ public: void set(tr_file_index_t file, tr_priority_t priority); void set(tr_file_index_t const* files, size_t n, tr_priority_t priority); - [[nodiscard]] tr_priority_t filePriority(tr_file_index_t file) const; - [[nodiscard]] tr_priority_t piecePriority(tr_piece_index_t piece) const; + [[nodiscard]] tr_priority_t file_priority(tr_file_index_t file) const; + [[nodiscard]] tr_priority_t piece_priority(tr_piece_index_t piece) const; private: tr_file_piece_map const* fpm_; @@ -166,12 +166,12 @@ public: void set(tr_file_index_t file, bool wanted); void set(tr_file_index_t const* files, size_t n, bool wanted); - [[nodiscard]] TR_CONSTEXPR20 bool fileWanted(tr_file_index_t file) const + [[nodiscard]] TR_CONSTEXPR20 bool file_wanted(tr_file_index_t file) const { return wanted_.test(file); } - [[nodiscard]] bool pieceWanted(tr_piece_index_t piece) const; + [[nodiscard]] bool piece_wanted(tr_piece_index_t piece) const; private: tr_file_piece_map const* fpm_; diff --git a/libtransmission/handshake.cc b/libtransmission/handshake.cc index c0c874b00..420672f5a 100644 --- a/libtransmission/handshake.cc +++ b/libtransmission/handshake.cc @@ -81,7 +81,7 @@ tr_handshake::ParseResult tr_handshake::parse_handshake(tr_peerIo* peer_io) auto flags = tr_bitfield{ HandshakeFlagsBits }; auto reserved = std::array{}; peer_io->read_bytes(std::data(reserved), std::size(reserved)); - flags.setRaw(std::data(reserved), std::size(reserved)); + flags.set_raw(std::data(reserved), std::size(reserved)); peer_io->set_supports_dht(flags.test(DhtFlag)); peer_io->set_supports_ltep(flags.test(LtepFlag)); peer_io->set_supports_fext(flags.test(FextFlag)); @@ -363,7 +363,7 @@ ReadState tr_handshake::read_handshake(tr_peerIo* peer_io) auto reserved = std::array{}; auto flags = tr_bitfield{ HandshakeFlagsBits }; peer_io->read_bytes(std::data(reserved), std::size(reserved)); - flags.setRaw(std::data(reserved), std::size(reserved)); + flags.set_raw(std::data(reserved), std::size(reserved)); peer_io->set_supports_dht(flags.test(DhtFlag)); peer_io->set_supports_ltep(flags.test(LtepFlag)); peer_io->set_supports_fext(flags.test(FextFlag)); diff --git a/libtransmission/inout.cc b/libtransmission/inout.cc index 9444b9843..e0b10e4af 100644 --- a/libtransmission/inout.cc +++ b/libtransmission/inout.cc @@ -74,7 +74,7 @@ enum class IoMode bool getFilename(tr_pathbuf& setme, tr_torrent const* tor, tr_file_index_t file_index, IoMode io_mode) { - if (auto found = tor->findFile(file_index); found) + if (auto found = tor->find_file(file_index); found) { setme.assign(found->filename()); return true; @@ -87,9 +87,9 @@ bool getFilename(tr_pathbuf& setme, tr_torrent const* tor, tr_file_index_t file_ // We didn't find the file that we want to write to. // Let's figure out where it goes so that we can create it. - auto const base = tor->currentDir(); + auto const base = tor->current_dir(); auto const suffix = tor->session->isIncompleteFileNamingEnabled() ? tr_torrent_files::PartialFileSuffix : ""sv; - setme.assign(base, '/', tor->fileSubpath(file_index), suffix); + setme.assign(base, '/', tor->file_subpath(file_index), suffix); return true; } @@ -103,10 +103,10 @@ void readOrWriteBytes( size_t buflen, tr_error** error) { - TR_ASSERT(file_index < tor->fileCount()); + TR_ASSERT(file_index < tor->file_count()); bool const do_write = io_mode == IoMode::Write; - auto const file_size = tor->fileSize(file_index); + auto const file_size = tor->file_size(file_index); TR_ASSERT(file_size == 0 || file_offset < file_size); TR_ASSERT(file_offset + buflen <= file_size); @@ -124,7 +124,7 @@ void readOrWriteBytes( auto const err = ENOENT; auto const msg = fmt::format( _("Couldn't get '{path}': {error} ({error_code})"), - fmt::arg("path", tor->fileSubpath(file_index)), + fmt::arg("path", tor->file_subpath(file_index)), fmt::arg("error", tr_strerror(err)), fmt::arg("error_code", err)); tr_error_set(error, err, msg); @@ -134,8 +134,8 @@ void readOrWriteBytes( if (!fd) // not in the cache, so open or create it now { // open (and maybe create) the file - auto const prealloc = (!do_write || !tor->fileIsWanted(file_index)) ? TR_PREALLOCATE_NONE : - tor->session->preallocationMode(); + auto const prealloc = (!do_write || !tor->file_is_wanted(file_index)) ? TR_PREALLOCATE_NONE : + tor->session->preallocationMode(); fd = session->openFiles().get(tor->id(), file_index, do_write, filename, prealloc, file_size); if (fd && do_write) { @@ -166,7 +166,7 @@ void readOrWriteBytes( tor, fmt::format( _("Couldn't read '{path}': {error} ({error_code})"), - fmt::arg("path", tor->fileSubpath(file_index)), + fmt::arg("path", tor->file_subpath(file_index)), fmt::arg("error", my_error->message), fmt::arg("error_code", my_error->code))); tr_error_propagate(error, &my_error); @@ -181,7 +181,7 @@ void readOrWriteBytes( tor, fmt::format( _("Couldn't save '{path}': {error} ({error_code})"), - fmt::arg("path", tor->fileSubpath(file_index)), + fmt::arg("path", tor->file_subpath(file_index)), fmt::arg("error", my_error->message), fmt::arg("error_code", my_error->code))); tr_error_propagate(error, &my_error); @@ -198,16 +198,16 @@ void readOrWriteBytes( /* returns 0 on success, or an errno on failure */ int readOrWritePiece(tr_torrent* tor, IoMode io_mode, tr_block_info::Location loc, uint8_t* buf, size_t buflen) { - if (loc.piece >= tor->pieceCount()) + if (loc.piece >= tor->piece_count()) { return EINVAL; } - auto [file_index, file_offset] = tor->fileOffset(loc); + auto [file_index, file_offset] = tor->file_offset(loc); while (buflen != 0) { - uint64_t const bytes_this_pass = std::min(uint64_t{ buflen }, uint64_t{ tor->fileSize(file_index) - file_offset }); + uint64_t const bytes_this_pass = std::min(uint64_t{ buflen }, uint64_t{ tor->file_size(file_index) - file_offset }); tr_error* error = nullptr; readOrWriteBytes(tor->session, tor, io_mode, file_index, file_offset, buf, bytes_this_pass, &error); @@ -216,7 +216,7 @@ int readOrWritePiece(tr_torrent* tor, IoMode io_mode, tr_block_info::Location lo { if (io_mode == IoMode::Write && tor->error != TR_STAT_LOCAL_ERROR) { - tor->setLocalError(error->message); + tor->set_local_error(error->message); tr_torrentStop(tor); } @@ -241,19 +241,19 @@ int readOrWritePiece(tr_torrent* tor, IoMode io_mode, tr_block_info::Location lo std::optional recalculateHash(tr_torrent* tor, tr_piece_index_t piece) { TR_ASSERT(tor != nullptr); - TR_ASSERT(piece < tor->pieceCount()); + TR_ASSERT(piece < tor->piece_count()); auto sha = tr_sha1::create(); auto buffer = std::array{}; auto& cache = tor->session->cache; - auto const [begin_byte, end_byte] = tor->blockInfo().byteSpanForPiece(piece); - auto const [begin_block, end_block] = tor->blockSpanForPiece(piece); + auto const [begin_byte, end_byte] = tor->block_info().byte_span_for_piece(piece); + auto const [begin_block, end_block] = tor->block_span_for_piece(piece); auto n_bytes_checked = size_t{}; for (auto block = begin_block; block < end_block; ++block) { - auto const block_loc = tor->blockLoc(block); - auto const block_len = tor->blockSize(block); + auto const block_loc = tor->block_loc(block); + auto const block_len = tor->block_size(block); if (auto const success = cache->readBlock(tor, block_loc, block_len, std::data(buffer)) == 0; !success) { return {}; @@ -276,7 +276,7 @@ std::optional recalculateHash(tr_torrent* tor, tr_piece_index_ n_bytes_checked += (end - begin); } - TR_ASSERT(tor->pieceSize(piece) == n_bytes_checked); + TR_ASSERT(tor->piece_size(piece) == n_bytes_checked); return sha->finish(); } @@ -300,5 +300,5 @@ int tr_ioWrite(tr_torrent* tor, tr_block_info::Location const& loc, size_t len, bool tr_ioTestPiece(tr_torrent* tor, tr_piece_index_t piece) { auto const hash = recalculateHash(tor, piece); - return hash && *hash == tor->pieceHash(piece); + return hash && *hash == tor->piece_hash(piece); } diff --git a/libtransmission/magnet-metainfo.cc b/libtransmission/magnet-metainfo.cc index 1e53af7dd..2f8aa2953 100644 --- a/libtransmission/magnet-metainfo.cc +++ b/libtransmission/magnet-metainfo.cc @@ -169,7 +169,7 @@ std::optional parseHash2(std::string_view sv) tr_urlbuf tr_magnet_metainfo::magnet() const { - auto s = tr_urlbuf{ "magnet:?xt=urn:btih:"sv, infoHashString() }; + auto s = tr_urlbuf{ "magnet:?xt=urn:btih:"sv, info_hash_string() }; if (!std::empty(name_)) { @@ -177,7 +177,7 @@ tr_urlbuf tr_magnet_metainfo::magnet() const tr_urlPercentEncode(std::back_inserter(s), name_); } - for (auto const& tracker : this->announceList()) + for (auto const& tracker : this->announce_list()) { s += "&tr="sv; tr_urlPercentEncode(std::back_inserter(s), tracker.announce.sv()); @@ -192,7 +192,7 @@ tr_urlbuf tr_magnet_metainfo::magnet() const return s; } -void tr_magnet_metainfo::addWebseed(std::string_view webseed) +void tr_magnet_metainfo::add_webseed(std::string_view webseed) { if (!tr_urlIsValid(webseed)) { @@ -229,7 +229,7 @@ bool tr_magnet_metainfo::parseMagnet(std::string_view magnet_link, tr_error** er { if (key == "dn"sv) { - this->setName(tr_urlPercentDecode(value)); + this->set_name(tr_urlPercentDecode(value)); } else if (key == "tr"sv || tr_strvStartsWith(key, "tr."sv)) { @@ -265,11 +265,11 @@ bool tr_magnet_metainfo::parseMagnet(std::string_view magnet_link, tr_error** er } } - info_hash_str_ = tr_sha1_to_string(this->infoHash()); + info_hash_str_ = tr_sha1_to_string(this->info_hash()); if (std::empty(name())) { - this->setName(info_hash_str_); + this->set_name(info_hash_str_); } return got_hash; diff --git a/libtransmission/magnet-metainfo.h b/libtransmission/magnet-metainfo.h index 196a391b2..b6e3430ca 100644 --- a/libtransmission/magnet-metainfo.h +++ b/libtransmission/magnet-metainfo.h @@ -28,7 +28,7 @@ public: [[nodiscard]] tr_urlbuf magnet() const; - [[nodiscard]] constexpr auto const& infoHash() const noexcept + [[nodiscard]] constexpr auto const& info_hash() const noexcept { return info_hash_; } @@ -38,7 +38,7 @@ public: return name_; } - [[nodiscard]] TR_CONSTEXPR20 auto webseedCount() const noexcept + [[nodiscard]] TR_CONSTEXPR20 auto webseed_count() const noexcept { return std::size(webseed_urls_); } @@ -48,32 +48,32 @@ public: return webseed_urls_.at(i); } - [[nodiscard]] constexpr auto& announceList() noexcept + [[nodiscard]] constexpr auto& announce_list() noexcept { return announce_list_; } - [[nodiscard]] constexpr auto const& announceList() const noexcept + [[nodiscard]] constexpr auto const& announce_list() const noexcept { return announce_list_; } - [[nodiscard]] constexpr std::string const& infoHashString() const noexcept + [[nodiscard]] constexpr std::string const& info_hash_string() const noexcept { return info_hash_str_; } - [[nodiscard]] constexpr std::string const& infoHash2String() const noexcept + [[nodiscard]] constexpr std::string const& info_hash2_string() const noexcept { return info_hash2_str_; } - void setName(std::string_view name) + void set_name(std::string_view name) { name_ = tr_strv_convert_utf8(name); } - void addWebseed(std::string_view webseed); + void add_webseed(std::string_view webseed); protected: tr_announce_list announce_list_; diff --git a/libtransmission/makemeta.cc b/libtransmission/makemeta.cc index 90d3f9d74..d998db367 100644 --- a/libtransmission/makemeta.cc +++ b/libtransmission/makemeta.cc @@ -191,7 +191,7 @@ bool tr_metainfo_builder::blockingMakeChecksums(tr_error** error) TR_ASSERT(piece_index < pieceCount()); - uint32_t const piece_size = block_info_.pieceSize(piece_index); + auto const piece_size = block_info_.piece_size(piece_index); buf.resize(piece_size); auto* bufptr = std::data(buf); diff --git a/libtransmission/makemeta.h b/libtransmission/makemeta.h index a35fd395c..98912f681 100644 --- a/libtransmission/makemeta.h +++ b/libtransmission/makemeta.h @@ -53,7 +53,7 @@ public: // The current piece being tested and the total number of pieces in the torrent. [[nodiscard]] constexpr std::pair checksumStatus() const noexcept { - return std::make_pair(checksum_piece_, block_info_.pieceCount()); + return std::make_pair(checksum_piece_, block_info_.piece_count()); } // Tell the `makeChecksums()` worker thread to cleanly exit ASAP. @@ -150,12 +150,12 @@ public: [[nodiscard]] constexpr auto pieceSize() const noexcept { - return block_info_.pieceSize(); + return block_info_.piece_size(); } [[nodiscard]] constexpr auto pieceCount() const noexcept { - return block_info_.pieceCount(); + return block_info_.piece_count(); } [[nodiscard]] constexpr auto const& source() const noexcept diff --git a/libtransmission/peer-common.h b/libtransmission/peer-common.h index 372685c57..803fab817 100644 --- a/libtransmission/peer-common.h +++ b/libtransmission/peer-common.h @@ -64,12 +64,12 @@ public: [[nodiscard]] constexpr static auto GotBlock(tr_block_info const& block_info, tr_block_index_t block) noexcept { - auto const loc = block_info.blockLoc(block); + auto const loc = block_info.block_loc(block); auto event = tr_peer_event{}; event.type = Type::ClientGotBlock; event.pieceIndex = loc.piece; event.offset = loc.piece_offset; - event.length = block_info.blockSize(block); + event.length = block_info.block_size(block); return event; } @@ -144,12 +144,12 @@ public: [[nodiscard]] constexpr static auto GotRejected(tr_block_info const& block_info, tr_block_index_t block) noexcept { - auto const loc = block_info.blockLoc(block); + auto const loc = block_info.block_loc(block); auto event = tr_peer_event{}; event.type = Type::ClientGotRej; event.pieceIndex = loc.piece; event.offset = loc.piece_offset; - event.length = block_info.blockSize(block); + event.length = block_info.block_size(block); return event; } @@ -198,7 +198,7 @@ public: [[nodiscard]] bool isSeed() const noexcept { - return has().hasAll(); + return has().has_all(); } [[nodiscard]] virtual std::string display_name() const = 0; diff --git a/libtransmission/peer-io.cc b/libtransmission/peer-io.cc index 9fd666307..21641e5aa 100644 --- a/libtransmission/peer-io.cc +++ b/libtransmission/peer-io.cc @@ -96,7 +96,7 @@ std::shared_ptr tr_peerIo::create( auto lock = session->unique_lock(); auto io = std::make_shared(session, info_hash, is_incoming, is_seed, parent); - io->bandwidth().setPeer(io); + io->bandwidth().set_peer(io); tr_logAddTraceIo(io, fmt::format("bandwidth is {}; its parent is {}", fmt::ptr(&io->bandwidth()), fmt::ptr(parent))); return io; } @@ -254,11 +254,11 @@ void tr_peerIo::did_write_wrapper(size_t bytes_transferred) size_t const overhead = socket_.guess_packet_overhead(payload); uint64_t const now = tr_time_msec(); - bandwidth().notifyBandwidthConsumed(TR_UP, payload, is_piece_data, now); + bandwidth().notify_bandwidth_consumed(TR_UP, payload, is_piece_data, now); if (overhead > 0) { - bandwidth().notifyBandwidthConsumed(TR_UP, overhead, false, now); + bandwidth().notify_bandwidth_consumed(TR_UP, overhead, false, now); } if (did_write_ != nullptr) @@ -363,18 +363,18 @@ void tr_peerIo::can_read_wrapper() { if (piece != 0) { - bandwidth().notifyBandwidthConsumed(TR_DOWN, piece, true, now); + bandwidth().notify_bandwidth_consumed(TR_DOWN, piece, true, now); } if (used != piece) { - bandwidth().notifyBandwidthConsumed(TR_DOWN, used - piece, false, now); + bandwidth().notify_bandwidth_consumed(TR_DOWN, used - piece, false, now); } } if (overhead > 0) { - bandwidth().notifyBandwidthConsumed(TR_DOWN, overhead, false, now); + bandwidth().notify_bandwidth_consumed(TR_DOWN, overhead, false, now); } switch (read_state) @@ -769,7 +769,7 @@ void tr_peerIo::utp_init([[maybe_unused]] struct_utp_context* ctx) if (auto* const io = static_cast(utp_get_userdata(args->socket)); io != nullptr) { tr_logAddTraceIo(io, fmt::format("{:d} overhead bytes via utp", args->len)); - io->bandwidth().notifyBandwidthConsumed(args->send != 0 ? TR_UP : TR_DOWN, args->len, false, tr_time_msec()); + io->bandwidth().notify_bandwidth_consumed(args->send != 0 ? TR_UP : TR_DOWN, args->len, false, tr_time_msec()); } return {}; }); diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index 0d7157bcc..07c36a75d 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -142,7 +142,7 @@ public: [[nodiscard]] auto get_piece_speed_bytes_per_second(uint64_t now, tr_direction dir) const noexcept { - return bandwidth_.getPieceSpeedBytesPerSecond(now, dir); + return bandwidth_.get_piece_speed_bytes_per_second(now, dir); } /// @@ -195,7 +195,7 @@ public: void set_bandwidth(tr_bandwidth* parent) { - bandwidth_.setParent(parent); + bandwidth_.set_parent(parent); } /// diff --git a/libtransmission/peer-mgr.cc b/libtransmission/peer-mgr.cc index 0b7063c3e..ca7e67f35 100644 --- a/libtransmission/peer-mgr.cc +++ b/libtransmission/peer-mgr.cc @@ -74,10 +74,10 @@ private: } auto info = TorrentInfo{}; - info.info_hash = tor->infoHash(); + info.info_hash = tor->info_hash(); info.client_peer_id = tor->peer_id(); info.id = tor->id(); - info.is_done = tor->isDone(); + info.is_done = tor->is_done(); return info; } @@ -358,7 +358,7 @@ public: [[nodiscard]] uint16_t countActiveWebseeds(uint64_t now) const noexcept { - if (!tor->isRunning || tor->isDone()) + if (!tor->is_running() || tor->is_done()) { return {}; } @@ -421,7 +421,7 @@ public: { /* we consider ourselves to be in endgame if the number of bytes we've got requested is >= the number of bytes left to download */ - is_endgame_ = uint64_t(std::size(active_requests)) * tr_block_info::BlockSize >= tor->leftUntilDone(); + is_endgame_ = uint64_t(std::size(active_requests)) * tr_block_info::BlockSize >= tor->left_until_done(); } [[nodiscard]] constexpr auto isEndgame() const noexcept @@ -445,7 +445,7 @@ public: void rebuildWebseeds() { - auto const n = tor->webseedCount(); + auto const n = tor->webseed_count(); webseeds.clear(); webseeds.reserve(n); @@ -541,8 +541,8 @@ public: tor->uploadedCur += event.length; tr_announcerAddBytes(tor, TR_ANN_UP, event.length); - tor->setDateActive(now); - tor->setDirty(); + tor->set_date_active(now); + tor->set_dirty(); tor->session->addUploaded(event.length); if (peer->atom != nullptr) @@ -559,8 +559,8 @@ public: auto* const tor = s->tor; tor->downloadedCur += event.length; - tor->setDateActive(now); - tor->setDirty(); + tor->set_date_active(now); + tor->set_dirty(); tor->session->addDownloaded(event.length); if (peer->atom != nullptr) @@ -580,7 +580,7 @@ public: break; case tr_peer_event::Type::ClientGotRej: - s->active_requests.remove(s->tor->pieceLoc(event.pieceIndex, event.offset).block, peer); + s->active_requests.remove(s->tor->piece_loc(event.pieceIndex, event.offset).block, peer); break; case tr_peer_event::Type::ClientGotChoke: @@ -603,7 +603,7 @@ public: case tr_peer_event::Type::ClientGotBlock: { auto* const tor = s->tor; - auto const loc = tor->pieceLoc(event.pieceIndex, event.offset); + auto const loc = tor->piece_loc(event.pieceIndex, event.offset); s->cancelAllRequestsForBlock(loc.block, peer); peer->blocks_sent_to_client.add(tr_time(), 1); tr_torrentGotBlock(tor, loc.block); @@ -762,7 +762,7 @@ tr_peer::tr_peer(tr_torrent const* tor, peer_atom* atom_in) : session{ tor->session } , swarm{ tor->swarm } , atom{ atom_in } - , blame{ tor->blockCount() } + , blame{ tor->block_count() } { } @@ -873,12 +873,12 @@ std::vector tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_p [[nodiscard]] bool clientCanRequestBlock(tr_block_index_t block) const override { - return !torrent_->hasBlock(block) && !swarm_->active_requests.has(block, peer_); + return !torrent_->has_block(block) && !swarm_->active_requests.has(block, peer_); } [[nodiscard]] bool clientCanRequestPiece(tr_piece_index_t piece) const override { - return torrent_->pieceIsWanted(piece) && peer_->hasPiece(piece); + return torrent_->piece_is_wanted(piece) && peer_->hasPiece(piece); } [[nodiscard]] bool isEndgame() const override @@ -893,27 +893,27 @@ std::vector tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_p [[nodiscard]] size_t countMissingBlocks(tr_piece_index_t piece) const override { - return torrent_->countMissingBlocksInPiece(piece); + return torrent_->count_missing_blocks_in_piece(piece); } [[nodiscard]] tr_block_span_t blockSpan(tr_piece_index_t piece) const override { - return torrent_->blockSpanForPiece(piece); + return torrent_->block_span_for_piece(piece); } [[nodiscard]] tr_piece_index_t countAllPieces() const override { - return torrent_->pieceCount(); + return torrent_->piece_count(); } [[nodiscard]] tr_priority_t priority(tr_piece_index_t piece) const override { - return torrent_->piecePriority(piece); + return torrent_->piece_priority(piece); } [[nodiscard]] bool isSequentialDownload() const override { - return torrent_->isSequentialDownload(); + return torrent_->is_sequential_download(); } private: @@ -966,7 +966,7 @@ void tr_peerMgrPieceCompleted(tr_torrent* tor, tr_piece_index_t p) if (piece_came_from_peers) /* webseed downloads don't belong in announce totals */ { - tr_announcerAddBytes(tor, TR_ANN_DOWN, tor->pieceSize(p)); + tr_announcerAddBytes(tor, TR_ANN_DOWN, tor->piece_size(p)); } // bookkeeping @@ -1068,7 +1068,7 @@ void create_bit_torrent_peer(tr_torrent* tor, std::shared_ptr io, str { tr_logAddTraceSwarm(s, fmt::format("banned peer {} tried to reconnect", atom->display_name())); } - else if (result.io->is_incoming() && s->peerCount() >= s->tor->peerLimit()) + else if (result.io->is_incoming() && s->peerCount() >= s->tor->peer_limit()) { /* too many peers already */ } @@ -1214,7 +1214,7 @@ std::vector tr_pex::from_compact_ipv6( void tr_peerMgrGotBadPiece(tr_torrent* tor, tr_piece_index_t piece_index) { auto* const swarm = tor->swarm; - auto const byte_count = tor->pieceSize(piece_index); + auto const byte_count = tor->piece_size(piece_index); for (auto* const peer : swarm->peers) { @@ -1275,7 +1275,7 @@ struct CompareAtomsByUsefulness [[nodiscard]] bool isAtomInteresting(tr_torrent const* tor, peer_atom const& atom) { - if (tor->isDone() && atom.isSeed()) + if (tor->is_done() && atom.isSeed()) { return false; } @@ -1420,12 +1420,12 @@ void tr_peerMgrOnTorrentGotMetainfo(tr_torrent* tor) int8_t tr_peerMgrPieceAvailability(tr_torrent const* tor, tr_piece_index_t piece) { - if (!tor->hasMetainfo()) + if (!tor->has_metainfo()) { return 0; } - if (tor->isSeed() || tor->hasPiece(piece)) + if (tor->is_seed() || tor->has_piece(piece)) { return -1; } @@ -1442,7 +1442,7 @@ void tr_peerMgrTorrentAvailability(tr_torrent const* tor, int8_t* tab, unsigned std::fill_n(tab, n_tabs, int8_t{}); - auto const interval = tor->pieceCount() / static_cast(n_tabs); + auto const interval = tor->piece_count() / static_cast(n_tabs); for (tr_piece_index_t i = 0; i < n_tabs; ++i) { auto const piece = static_cast(i * interval); @@ -1476,7 +1476,7 @@ uint64_t tr_peerMgrGetDesiredAvailable(tr_torrent const* tor) // common shortcuts... - if (!tor->isRunning || tor->isStopping || tor->isDone() || !tor->hasMetainfo()) + if (!tor->is_running() || tor->is_stopping() || tor->is_done() || !tor->has_metainfo()) { return 0; } @@ -1493,22 +1493,22 @@ uint64_t tr_peerMgrGetDesiredAvailable(tr_torrent const* tor) available |= peer->has(); } - if (available.hasAll()) + if (available.has_all()) { - return tor->leftUntilDone(); + return tor->left_until_done(); } auto desired_available = uint64_t{}; - for (tr_piece_index_t i = 0, n = tor->pieceCount(); i < n; ++i) + for (tr_piece_index_t i = 0, n = tor->piece_count(); i < n; ++i) { - if (tor->pieceIsWanted(i) && available.test(i)) + if (tor->piece_is_wanted(i) && available.test(i)) { - desired_available += tor->countMissingBytesInPiece(i); + desired_available += tor->count_missing_bytes_in_piece(i); } } - TR_ASSERT(desired_available <= tor->totalSize()); + TR_ASSERT(desired_available <= tor->total_size()); return desired_available; } @@ -1670,15 +1670,15 @@ namespace update_interest_helpers tr_peerMsgs const* const peer) { /* these cases should have already been handled by the calling code... */ - TR_ASSERT(!tor->isDone()); - TR_ASSERT(tor->clientCanDownload()); + TR_ASSERT(!tor->is_done()); + TR_ASSERT(tor->client_can_download()); if (peer->isSeed()) { return true; } - for (tr_piece_index_t i = 0; i < tor->pieceCount(); ++i) + for (tr_piece_index_t i = 0; i < tor->piece_count(); ++i) { if (piece_is_interesting[i] && peer->hasPiece(i)) { @@ -1694,21 +1694,21 @@ void updateInterest(tr_swarm* swarm) { // sometimes this function isn't necessary auto const* const tor = swarm->tor; - if (tor->isDone() || !tor->clientCanDownload()) + if (tor->is_done() || !tor->client_can_download()) { return; } if (auto const& peers = swarm->peers; !std::empty(peers)) { - int const n = tor->pieceCount(); + int const n = tor->piece_count(); // build a bitfield of interesting pieces... auto piece_is_interesting = std::vector{}; piece_is_interesting.resize(n); for (int i = 0; i < n; ++i) { - piece_is_interesting[i] = tor->pieceIsWanted(i) && !tor->hasPiece(i); + piece_is_interesting[i] = tor->piece_is_wanted(i) && !tor->has_piece(i); } for (auto* const peer : peers) @@ -1774,14 +1774,14 @@ struct ChokeData /* get a rate for deciding which peers to choke and unchoke. */ [[nodiscard]] auto getRateBps(tr_torrent const* tor, tr_peer const* peer, uint64_t now) { - if (tor->isDone()) + if (tor->is_done()) { return peer->get_piece_speed_bytes_per_second(now, TR_CLIENT_TO_PEER); } /* downloading a private torrent... take upload speed into account * because there may only be a small window of opportunity to share */ - if (tor->isPrivate()) + if (tor->is_private()) { return peer->get_piece_speed_bytes_per_second(now, TR_PEER_TO_CLIENT) + peer->get_piece_speed_bytes_per_second(now, TR_CLIENT_TO_PEER); @@ -1804,7 +1804,7 @@ void rechokeUploads(tr_swarm* s, uint64_t const now) auto choked = std::vector{}; choked.reserve(peer_count); auto const* const session = s->manager->session; - bool const choke_all = !s->tor->clientCanUpload(); + bool const choke_all = !s->tor->client_can_upload(); bool const is_maxed_out = s->tor->bandwidth_.is_maxed_out(TR_UP, now); /* an optimistic unchoke peer's "optimistic" @@ -1921,13 +1921,13 @@ void tr_peerMgr::rechokePulse() const for (auto* const tor : session->torrents()) { - if (tor->isRunning) + if (tor->is_running()) { // possibly stop torrents that have seeded enough tr_torrentCheckSeedLimit(tor); } - if (tor->isRunning) + if (tor->is_running()) { if (auto* const swarm = tor->swarm; swarm->stats.peer_count > 0) { @@ -1963,15 +1963,15 @@ auto constexpr MaxUploadIdleSecs = time_t{ 60 * 5 }; auto const* const atom = peer->atom; /* disconnect if we're both seeds and enough time has passed for PEX */ - if (tor->isDone() && peer->isSeed()) + if (tor->is_done() && peer->isSeed()) { - return !tor->allowsPex() || now - atom->time >= 30; + return !tor->allows_pex() || now - atom->time >= 30; } /* 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(std::lround(tor->peerLimit() * 0.9)); + auto const relax_strictness_if_fewer_than_n = static_cast(std::lround(tor->peer_limit() * 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 ? @@ -2142,9 +2142,9 @@ void tr_peerMgr::reconnectPulse() // if we're over the per-torrent peer limits, cull some peers for (auto* const tor : session->torrents()) { - if (tor->isRunning) + if (tor->is_running()) { - enforceSwarmPeerLimit(tor->swarm, tor->peerLimit()); + enforceSwarmPeerLimit(tor->swarm, tor->peer_limit()); } } @@ -2243,7 +2243,7 @@ namespace connect_helpers } // not if we're both seeds - if (tor->isDone() && atom.isSeed()) + if (tor->is_done() && atom.isSeed()) { return false; } @@ -2310,7 +2310,7 @@ struct peer_candidate score = addValToKey(score, 32, i); /* prefer peers belonging to a torrent of a higher priority */ - switch (tor->getPriority()) + switch (tor->get_priority()) { case TR_PRI_HIGH: i = 0; @@ -2332,7 +2332,7 @@ struct peer_candidate score = addValToKey(score, 1, i); /* prefer torrents we're downloading with */ - i = tor->isDone() ? 1 : 0; + i = tor->is_done() ? 1 : 0; score = addValToKey(score, 1, i); /* prefer peers that are known to be connectible */ @@ -2381,14 +2381,14 @@ struct peer_candidate /* if everyone in the swarm is seeds and pex is disabled because * the torrent is private, then don't initiate connections */ - bool const seeding = tor->isDone(); - if (seeding && swarm->isAllSeeds() && tor->isPrivate()) + bool const seeding = tor->is_done(); + if (seeding && swarm->isAllSeeds() && tor->is_private()) { continue; } /* if we've already got enough peers in this torrent... */ - if (tor->peerLimit() <= swarm->peerCount()) + if (tor->peer_limit() <= swarm->peerCount()) { continue; } @@ -2453,7 +2453,7 @@ void initiateConnection(tr_peerMgr* mgr, tr_swarm* s, peer_atom& atom) &session->top_bandwidth_, atom.addr, atom.port, - s->tor->infoHash(), + s->tor->info_hash(), s->tor->completeness == TR_SEED, utp); diff --git a/libtransmission/peer-msgs.cc b/libtransmission/peer-msgs.cc index 9556473e5..e6f1a25fe 100644 --- a/libtransmission/peer-msgs.cc +++ b/libtransmission/peer-msgs.cc @@ -205,8 +205,8 @@ struct peer_request peer_request blockToReq(tr_torrent const* tor, tr_block_index_t block) { - auto const loc = tor->blockLoc(block); - return peer_request{ loc.piece, loc.piece_offset, tor->blockSize(block) }; + auto const loc = tor->block_loc(block); + return peer_request{ loc.piece, loc.piece_offset, tor->block_size(block) }; } // --- @@ -298,11 +298,11 @@ public: : tr_peerMsgs{ torrent_in, atom_in, client, io_in->is_encrypted(), io_in->is_incoming(), io_in->is_utp() } , torrent{ torrent_in } , io{ std::move(io_in) } - , have_{ torrent_in->pieceCount() } + , have_{ torrent_in->piece_count() } , callback_{ callback } , callback_data_{ callback_data } { - if (torrent->allowsPex()) + if (torrent->allows_pex()) { pex_timer_ = session->timerMaker().create([this]() { sendPex(); }); pex_timer_->startRepeating(SendPexInterval); @@ -479,7 +479,7 @@ public: void requestBlocks(tr_block_span_t const* block_spans, size_t n_spans) override { - TR_ASSERT(torrent->clientCanDownload()); + TR_ASSERT(torrent->client_can_download()); TR_ASSERT(client_is_interested()); TR_ASSERT(!client_is_choked()); @@ -490,14 +490,14 @@ public: // Note that requests can't cross over a piece boundary. // So if a piece isn't evenly divisible by the block size, // we need to split our block request info per-piece chunks. - auto const byte_begin = torrent->blockLoc(block).byte; - auto const block_size = torrent->blockSize(block); + auto const byte_begin = torrent->block_loc(block).byte; + auto const block_size = torrent->block_size(block); auto const byte_end = byte_begin + block_size; for (auto offset = byte_begin; offset < byte_end;) { - auto const loc = torrent->byteLoc(offset); + auto const loc = torrent->byte_loc(offset); auto const left_in_block = block_size - loc.block_offset; - auto const left_in_piece = torrent->pieceSize(loc.piece) - loc.piece_offset; + auto const left_in_piece = torrent->piece_size(loc.piece) - loc.piece_offset; auto const req_len = std::min(left_in_block, left_in_piece); protocolSendRequest(this, { loc.piece, loc.piece_offset, req_len }); offset += req_len; @@ -528,7 +528,7 @@ public: private: [[nodiscard]] size_t maxAvailableReqs() const { - if (torrent->isDone() || !torrent->hasMetainfo() || client_is_choked() || !client_is_interested()) + if (torrent->is_done() || !torrent->has_metainfo() || client_is_choked() || !client_is_interested()) { return 0; } @@ -537,13 +537,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 = get_piece_speed_bytes_per_second(now, TR_PEER_TO_CLIENT); - if (torrent->usesSpeedLimit(TR_PEER_TO_CLIENT)) + if (torrent->uses_speed_limit(TR_PEER_TO_CLIENT)) { - rate_bytes_per_second = std::min(rate_bytes_per_second, torrent->speedLimitBps(TR_PEER_TO_CLIENT)); + rate_bytes_per_second = std::min(rate_bytes_per_second, torrent->speed_limit_bps(TR_PEER_TO_CLIENT)); } // honor the session limits, if enabled - if (torrent->usesSessionLimits()) + if (torrent->uses_session_limits()) { if (auto const irate_bytes_per_second = torrent->session->activeSpeedLimitBps(TR_PEER_TO_CLIENT); irate_bytes_per_second) @@ -574,13 +574,13 @@ private: // TR_PEER_TO_CLIENT - if (!torrent->hasMetainfo()) + if (!torrent->has_metainfo()) { return true; } auto const active = client_is_interested() && !client_is_choked(); - TR_ASSERT(!active || !torrent->isDone()); + TR_ASSERT(!active || !torrent->is_done()); return active; } @@ -683,7 +683,7 @@ private: return len == 5U; case BtPeerMsgs::Bitfield: - return !tor->hasMetainfo() || len == 1 + ((tor->pieceCount() + 7U) / 8U); + return !tor->has_metainfo() || len == 1 + ((tor->piece_count() + 7U) / 8U); case BtPeerMsgs::Request: case BtPeerMsgs::Cancel: @@ -914,11 +914,11 @@ void sendLtepHandshake(tr_peerMsgsImpl* msgs) msgs->clientSentLtepHandshake = true; /* decide if we want to advertise metadata xfer support (BEP 9) */ - bool const allow_metadata_xfer = msgs->torrent->isPublic(); + bool const allow_metadata_xfer = msgs->torrent->is_public(); /* decide if we want to advertise pex support */ auto allow_pex = bool{}; - if (!msgs->torrent->allowsPex()) + if (!msgs->torrent->allows_pex()) { allow_pex = false; } @@ -945,8 +945,8 @@ void sendLtepHandshake(tr_peerMsgsImpl* msgs) // It also adds "metadata_size" to the handshake message (not the // "m" dictionary) specifying an integer value of the number of // bytes of the metadata. - if (auto const info_dict_size = msgs->torrent->infoDictSize(); - allow_metadata_xfer && msgs->torrent->hasMetainfo() && info_dict_size > 0) + if (auto const info_dict_size = msgs->torrent->info_dict_size(); + allow_metadata_xfer && msgs->torrent->has_metainfo() && info_dict_size > 0) { tr_variantDictAddInt(&val, TR_KEY_metadata_size, info_dict_size); } @@ -988,7 +988,7 @@ void sendLtepHandshake(tr_peerMsgsImpl* msgs) // the extension handshake 'upload_only'. Setting the value of this // key to 1 indicates that this peer is not interested in downloading // anything. - tr_variantDictAddBool(&val, TR_KEY_upload_only, msgs->torrent->isDone()); + tr_variantDictAddBool(&val, TR_KEY_upload_only, msgs->torrent->is_done()); if (allow_metadata_xfer || allow_pex) { @@ -1149,7 +1149,7 @@ void parseUtMetadata(tr_peerMsgsImpl* msgs, libtransmission::Buffer& payload_in) /* NOOP */ } - if (msg_type == MetadataMsgType::Data && !msgs->torrent->hasMetainfo() && msg_end - benc_end <= METADATA_PIECE_SIZE && + if (msg_type == MetadataMsgType::Data && !msgs->torrent->has_metainfo() && msg_end - benc_end <= METADATA_PIECE_SIZE && piece * METADATA_PIECE_SIZE + (msg_end - benc_end) <= total_size) { size_t const piece_len = msg_end - benc_end; @@ -1158,7 +1158,7 @@ void parseUtMetadata(tr_peerMsgsImpl* msgs, libtransmission::Buffer& payload_in) if (msg_type == MetadataMsgType::Request) { - if (piece >= 0 && msgs->torrent->hasMetainfo() && msgs->torrent->isPublic() && + if (piece >= 0 && msgs->torrent->has_metainfo() && msgs->torrent->is_public() && std::size(msgs->peerAskedForMetadata) < MetadataReqQ) { msgs->peerAskedForMetadata.push(piece); @@ -1179,7 +1179,7 @@ void parseUtMetadata(tr_peerMsgsImpl* msgs, libtransmission::Buffer& payload_in) void parseUtPex(tr_peerMsgsImpl* msgs, libtransmission::Buffer& payload) { auto* const tor = msgs->torrent; - if (!tor->allowsPex()) + if (!tor->allows_pex()) { return; } @@ -1274,7 +1274,7 @@ void prefetchPieces(tr_peerMsgsImpl* msgs) { if (auto& req = requests[i]; !req.prefetched) { - msgs->session->cache->prefetchBlock(msgs->torrent, msgs->torrent->pieceLoc(req.index, req.offset), req.length); + msgs->session->cache->prefetchBlock(msgs->torrent, msgs->torrent->piece_loc(req.index, req.offset), req.length); req.prefetched = true; } } @@ -1300,7 +1300,7 @@ void prefetchPieces(tr_peerMsgsImpl* msgs) return false; } - if (!msgs->torrent->hasPiece(req.index)) + if (!msgs->torrent->has_piece(req.index)) { logtrace(msgs, "rejecting request for a piece we don't have."); return false; @@ -1331,9 +1331,9 @@ ReadResult read_piece_data(tr_peerMsgsImpl* msgs, libtransmission::Buffer& paylo auto const offset = payload.to_uint32(); auto const len = std::size(payload); - auto const loc = msgs->torrent->pieceLoc(piece, offset); + auto const loc = msgs->torrent->piece_loc(piece, offset); auto const block = loc.block; - auto const block_size = msgs->torrent->blockSize(block); + auto const block_size = msgs->torrent->block_size(block); if (loc.block_offset + len > block_size) { @@ -1351,11 +1351,11 @@ ReadResult read_piece_data(tr_peerMsgsImpl* msgs, libtransmission::Buffer& paylo auto& incoming_block = blocks.try_emplace(block, block_size).first->second; payload.to_buf(std::data(*incoming_block.buf) + loc.block_offset, len); msgs->publish(tr_peer_event::GotPieceData(len)); - incoming_block.have.setSpan(loc.block_offset, loc.block_offset + len); + incoming_block.have.set_span(loc.block_offset, loc.block_offset + len); logtrace(msgs, fmt::format("got {:d} bytes for req {:d}:{:d}->{:d}", len, piece, offset, len)); // if we haven't gotten the entire block yet, wait for more - if (!incoming_block.have.hasAll()) + if (!incoming_block.have.has_all()) { return { READ_LATER, len }; } @@ -1431,7 +1431,7 @@ ReadResult process_peer_message(tr_peerMsgsImpl* msgs, uint8_t id, libtransmissi ui32 = payload.to_uint32(); logtrace(msgs, fmt::format(FMT_STRING("got Have: {:d}"), ui32)); - if (msgs->torrent->hasMetainfo() && ui32 >= msgs->torrent->pieceCount()) + if (msgs->torrent->has_metainfo() && ui32 >= msgs->torrent->piece_count()) { msgs->publish(tr_peer_event::GotError(ERANGE)); return { READ_ERR, {} }; @@ -1451,8 +1451,8 @@ ReadResult process_peer_message(tr_peerMsgsImpl* msgs, uint8_t id, libtransmissi { logtrace(msgs, "got a bitfield"); auto const [buf, buflen] = payload.pullup(); - msgs->have_ = tr_bitfield{ msgs->torrent->hasMetainfo() ? msgs->torrent->pieceCount() : buflen * 8 }; - msgs->have_.setRaw(reinterpret_cast(buf), buflen); + msgs->have_ = tr_bitfield{ msgs->torrent->has_metainfo() ? msgs->torrent->piece_count() : buflen * 8 }; + msgs->have_.set_raw(reinterpret_cast(buf), buflen); msgs->publish(tr_peer_event::GotBitfield(&msgs->have_)); msgs->invalidatePercentDone(); break; @@ -1554,7 +1554,7 @@ ReadResult process_peer_message(tr_peerMsgsImpl* msgs, uint8_t id, libtransmissi if (fext) { - msgs->have_.setHasAll(); + msgs->have_.set_has_all(); msgs->publish(tr_peer_event::GotHaveAll()); msgs->invalidatePercentDone(); } @@ -1571,7 +1571,7 @@ ReadResult process_peer_message(tr_peerMsgsImpl* msgs, uint8_t id, libtransmissi if (fext) { - msgs->have_.setHasNone(); + msgs->have_.set_has_none(); msgs->publish(tr_peer_event::GotHaveNone()); msgs->invalidatePercentDone(); } @@ -1593,7 +1593,7 @@ ReadResult process_peer_message(tr_peerMsgsImpl* msgs, uint8_t id, libtransmissi if (fext) { msgs->publish( - tr_peer_event::GotRejected(msgs->torrent->blockInfo(), msgs->torrent->pieceLoc(r.index, r.offset).block)); + tr_peer_event::GotRejected(msgs->torrent->block_info(), msgs->torrent->piece_loc(r.index, r.offset).block)); } else { @@ -1623,7 +1623,7 @@ int clientGotBlock(tr_peerMsgsImpl* msgs, std::unique_ptr> TR_ASSERT(msgs != nullptr); tr_torrent const* const tor = msgs->torrent; - auto const n_expected = msgs->torrent->blockSize(block); + auto const n_expected = msgs->torrent->block_size(block); if (!block_data) { @@ -1631,7 +1631,7 @@ int clientGotBlock(tr_peerMsgsImpl* msgs, std::unique_ptr> return EMSGSIZE; } - if (std::size(*block_data) != msgs->torrent->blockSize(block)) + if (std::size(*block_data) != msgs->torrent->block_size(block)) { logdbg(msgs, fmt::format("wrong block size: expected {:d}, got {:d}", n_expected, std::size(*block_data))); return EMSGSIZE; @@ -1645,8 +1645,8 @@ int clientGotBlock(tr_peerMsgsImpl* msgs, std::unique_ptr> return 0; } - auto const loc = msgs->torrent->blockLoc(block); - if (msgs->torrent->hasPiece(loc.piece)) + auto const loc = msgs->torrent->block_loc(block); + if (msgs->torrent->has_piece(loc.piece)) { logtrace(msgs, "we did ask for this message, but the piece is already complete..."); return 0; @@ -1660,7 +1660,7 @@ int clientGotBlock(tr_peerMsgsImpl* msgs, std::unique_ptr> } msgs->blame.set(loc.piece); - msgs->publish(tr_peer_event::GotBlock(tor->blockInfo(), block)); + msgs->publish(tr_peer_event::GotBlock(tor->block_info(), block)); return 0; } @@ -1793,7 +1793,7 @@ void updateBlockRequests(tr_peerMsgsImpl* msgs) { auto* const tor = msgs->torrent; - if (!tor->clientCanDownload()) + if (!tor->client_can_download()) { return; } @@ -1853,7 +1853,7 @@ namespace peer_pulse_helpers tr_variantInitDict(&tmp, 3); tr_variantDictAddInt(&tmp, TR_KEY_msg_type, MetadataMsgType::Data); tr_variantDictAddInt(&tmp, TR_KEY_piece, *piece); - tr_variantDictAddInt(&tmp, TR_KEY_total_size, msgs->torrent->infoDictSize()); + tr_variantDictAddInt(&tmp, TR_KEY_total_size, msgs->torrent->info_dict_size()); auto const n_bytes_written = protocol_send_message( msgs, BtPeerMsgs::Ltep, @@ -1875,15 +1875,15 @@ namespace peer_pulse_helpers msgs->peer_requested_.erase(std::begin(msgs->peer_requested_)); auto buf = std::array{}; - auto ok = msgs->isValidRequest(req) && msgs->torrent->hasPiece(req.index); + auto ok = msgs->isValidRequest(req) && msgs->torrent->has_piece(req.index); if (ok) { - ok = msgs->torrent->ensurePieceIsChecked(req.index); + ok = msgs->torrent->ensure_piece_is_checked(req.index); if (!ok) { - msgs->torrent->setLocalError( + msgs->torrent->set_local_error( fmt::format(FMT_STRING("Please Verify Local Data! Piece #{:d} is corrupt."), req.index)); } } @@ -1891,7 +1891,7 @@ namespace peer_pulse_helpers if (ok) { ok = msgs->session->cache - ->readBlock(msgs->torrent, msgs->torrent->pieceLoc(req.index, req.offset), req.length, std::data(buf)) == 0; + ->readBlock(msgs->torrent, msgs->torrent->piece_loc(req.index, req.offset), req.length, std::data(buf)) == 0; } if (ok) @@ -1972,24 +1972,24 @@ void tellPeerWhatWeHave(tr_peerMsgsImpl* msgs) { bool const fext = msgs->io->supports_fext(); - if (fext && msgs->torrent->hasAll()) + if (fext && msgs->torrent->has_all()) { protocol_send_message(msgs, BtPeerMsgs::FextHaveAll); } - else if (fext && msgs->torrent->hasNone()) + else if (fext && msgs->torrent->has_none()) { protocol_send_message(msgs, BtPeerMsgs::FextHaveNone); } - else if (!msgs->torrent->hasNone()) + else if (!msgs->torrent->has_none()) { - protocol_send_message(msgs, BtPeerMsgs::Bitfield, msgs->torrent->createPieceBitfield()); + protocol_send_message(msgs, BtPeerMsgs::Bitfield, msgs->torrent->create_piece_bitfield()); } } void tr_peerMsgsImpl::sendPex() { // only send pex if both the torrent and peer support it - if (!this->peerSupportsPex || !this->torrent->allowsPex()) + if (!this->peerSupportsPex || !this->torrent->allows_pex()) { return; } diff --git a/libtransmission/resume.cc b/libtransmission/resume.cc index d8cadd73a..74a89648f 100644 --- a/libtransmission/resume.cc +++ b/libtransmission/resume.cc @@ -121,14 +121,14 @@ auto loadLabels(tr_variant* dict, tr_torrent* tor) void saveGroup(tr_variant* dict, tr_torrent const* tor) { - tr_variantDictAddStrView(dict, TR_KEY_group, tor->bandwidthGroup()); + tr_variantDictAddStrView(dict, TR_KEY_group, tor->bandwidth_group()); } auto loadGroup(tr_variant* dict, tr_torrent* tor) { if (std::string_view group_name; tr_variantDictFindStrView(dict, TR_KEY_group, &group_name) && !std::empty(group_name)) { - tor->setBandwidthGroup(group_name); + tor->set_bandwidth_group(group_name); return tr_resume::Group; } @@ -139,7 +139,7 @@ auto loadGroup(tr_variant* dict, tr_torrent* tor) void saveDND(tr_variant* dict, tr_torrent const* tor) { - auto const n = tor->fileCount(); + auto const n = tor->file_count(); tr_variant* const list = tr_variantDictAddList(dict, TR_KEY_dnd, n); for (tr_file_index_t i = 0; i < n; ++i) @@ -153,7 +153,7 @@ auto loadDND(tr_variant* dict, tr_torrent* tor) auto ret = tr_resume::fields_t{}; tr_variant* list = nullptr; - if (auto const n = tor->fileCount(); tr_variantDictFindList(dict, TR_KEY_dnd, &list) && tr_variantListSize(list) == n) + if (auto const n = tor->file_count(); tr_variantDictFindList(dict, TR_KEY_dnd, &list) && tr_variantListSize(list) == n) { auto wanted = std::vector{}; auto unwanted = std::vector{}; @@ -173,8 +173,8 @@ auto loadDND(tr_variant* dict, tr_torrent* tor) } } - tor->initFilesWanted(std::data(unwanted), std::size(unwanted), false); - tor->initFilesWanted(std::data(wanted), std::size(wanted), true); + tor->init_files_wanted(std::data(unwanted), std::size(unwanted), false); + tor->init_files_wanted(std::data(wanted), std::size(wanted), true); ret = tr_resume::Dnd; } @@ -196,7 +196,7 @@ auto loadDND(tr_variant* dict, tr_torrent* tor) void saveFilePriorities(tr_variant* dict, tr_torrent const* tor) { - auto const n = tor->fileCount(); + auto const n = tor->file_count(); tr_variant* const list = tr_variantDictAddList(dict, TR_KEY_priority, n); for (tr_file_index_t i = 0; i < n; ++i) @@ -209,7 +209,7 @@ auto loadFilePriorities(tr_variant* dict, tr_torrent* tor) { auto ret = tr_resume::fields_t{}; - auto const n = tor->fileCount(); + auto const n = tor->file_count(); tr_variant* list = nullptr; if (tr_variantDictFindList(dict, TR_KEY_priority, &list) && tr_variantListSize(list) == n) { @@ -218,7 +218,7 @@ auto loadFilePriorities(tr_variant* dict, tr_torrent* tor) auto priority = int64_t{}; if (tr_variantGetInt(tr_variantListChild(list, i), &priority)) { - tor->setFilePriority(i, tr_priority_t(priority)); + tor->set_file_priority(i, tr_priority_t(priority)); } } @@ -233,9 +233,9 @@ auto loadFilePriorities(tr_variant* dict, tr_torrent* tor) void saveSingleSpeedLimit(tr_variant* d, tr_torrent const* tor, tr_direction dir) { tr_variantDictReserve(d, 3); - tr_variantDictAddInt(d, TR_KEY_speed_Bps, tor->speedLimitBps(dir)); - tr_variantDictAddBool(d, TR_KEY_use_global_speed_limit, tor->usesSessionLimits()); - tr_variantDictAddBool(d, TR_KEY_use_speed_limit, tor->usesSpeedLimit(dir)); + tr_variantDictAddInt(d, TR_KEY_speed_Bps, tor->speed_limit_bps(dir)); + tr_variantDictAddBool(d, TR_KEY_use_global_speed_limit, tor->uses_session_limits()); + tr_variantDictAddBool(d, TR_KEY_use_speed_limit, tor->uses_speed_limit(dir)); } void saveSpeedLimits(tr_variant* dict, tr_torrent const* tor) @@ -254,24 +254,24 @@ void saveRatioLimits(tr_variant* dict, tr_torrent const* tor) 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, tor->idleLimitMinutes()); - tr_variantDictAddInt(d, TR_KEY_idle_mode, tor->idleLimitMode()); + tr_variantDictAddInt(d, TR_KEY_idle_limit, tor->idle_limit_minutes()); + tr_variantDictAddInt(d, TR_KEY_idle_mode, tor->idle_limit_mode()); } void loadSingleSpeedLimit(tr_variant* d, tr_direction dir, tr_torrent* tor) { if (auto val = int64_t{}; tr_variantDictFindInt(d, TR_KEY_speed_Bps, &val)) { - tor->setSpeedLimitBps(dir, val); + tor->set_speed_limit_bps(dir, val); } else if (tr_variantDictFindInt(d, TR_KEY_speed, &val)) { - tor->setSpeedLimitBps(dir, val * 1024); + tor->set_speed_limit_bps(dir, val * 1024); } if (auto val = bool{}; tr_variantDictFindBool(d, TR_KEY_use_speed_limit, &val)) { - tor->useSpeedLimit(dir, val); + tor->use_speed_limit(dir, val); } if (auto val = bool{}; tr_variantDictFindBool(d, TR_KEY_use_global_speed_limit, &val)) @@ -312,7 +312,7 @@ auto loadRatioLimits(tr_variant* dict, tr_torrent* tor) if (auto i = int64_t{}; tr_variantDictFindInt(d, TR_KEY_ratio_mode, &i)) { - tor->setRatioMode(tr_ratiolimit(i)); + tor->set_ratio_mode(tr_ratiolimit(i)); } ret = tr_resume::Ratiolimit; @@ -329,7 +329,7 @@ auto loadIdleLimits(tr_variant* dict, tr_torrent* tor) { if (auto imin = int64_t{}; tr_variantDictFindInt(d, TR_KEY_idle_limit, &imin)) { - tor->setIdleLimit(imin); + tor->set_idle_limit(imin); } if (auto i = int64_t{}; tr_variantDictFindInt(d, TR_KEY_idle_mode, &i)) @@ -366,7 +366,7 @@ auto loadName(tr_variant* dict, tr_torrent* tor) return ret; } - tor->setName(name); + tor->set_name(name); ret |= tr_resume::Name; return ret; @@ -376,11 +376,11 @@ auto loadName(tr_variant* dict, tr_torrent* tor) void saveFilenames(tr_variant* dict, tr_torrent const* tor) { - auto const n = tor->fileCount(); + auto const n = tor->file_count(); tr_variant* const list = tr_variantDictAddList(dict, TR_KEY_files, n); for (tr_file_index_t i = 0; i < n; ++i) { - tr_variantListAddStrView(list, tor->fileSubpath(i)); + tr_variantListAddStrView(list, tor->file_subpath(i)); } } @@ -394,14 +394,14 @@ auto loadFilenames(tr_variant* dict, tr_torrent* tor) return ret; } - auto const n_files = tor->fileCount(); + auto const n_files = tor->file_count(); auto const n_list = tr_variantListSize(list); for (tr_file_index_t i = 0; i < n_files && i < n_list; ++i) { auto sv = std::string_view{}; if (tr_variantGetStrView(tr_variantListChild(list, i), &sv) && !std::empty(sv)) { - tor->setFileSubpath(i, sv); + tor->set_file_subpath(i, sv); } } @@ -413,11 +413,11 @@ auto loadFilenames(tr_variant* dict, tr_torrent* tor) void bitfieldToRaw(tr_bitfield const& b, tr_variant* benc) { - if (b.hasNone() || (std::empty(b) != 0U)) + if (b.has_none() || (std::empty(b) != 0U)) { tr_variantInitStr(benc, "none"sv); } - else if (b.hasAll()) + else if (b.has_all()) { tr_variantInitStrView(benc, "all"sv); } @@ -432,15 +432,15 @@ void rawToBitfield(tr_bitfield& bitfield, uint8_t const* raw, size_t rawlen) { if (raw == nullptr || rawlen == 0 || (rawlen == 4 && memcmp(raw, "none", 4) == 0)) { - bitfield.setHasNone(); + bitfield.set_has_none(); } else if (rawlen == 3 && memcmp(raw, "all", 3) == 0) { - bitfield.setHasAll(); + bitfield.set_has_all(); } else { - bitfield.setRaw(raw, rawlen); + bitfield.set_raw(raw, rawlen); } } @@ -496,9 +496,9 @@ auto loadProgress(tr_variant* dict, tr_torrent* tor) { /// CHECKED PIECES - auto checked = tr_bitfield(tor->pieceCount()); + auto checked = tr_bitfield(tor->piece_count()); auto mtimes = std::vector{}; - auto const n_files = tor->fileCount(); + auto const n_files = tor->file_count(); mtimes.reserve(n_files); // try to load mtimes @@ -541,7 +541,7 @@ auto loadProgress(tr_variant* dict, tr_torrent* tor) tr_variantGetInt(tr_variantListChild(b, 0), &offset); time_checked = tr_time(); - auto const [begin, end] = tor->piecesInFile(fi); + auto const [begin, end] = tor->pieces_in_file(fi); for (size_t i = 0, n = end - begin; i < n; ++i) { int64_t piece_time = 0; @@ -563,11 +563,11 @@ auto loadProgress(tr_variant* dict, tr_torrent* tor) mtimes.resize(n_files); } - tor->initCheckedPieces(checked, std::data(mtimes)); + tor->init_checked_pieces(checked, std::data(mtimes)); /// COMPLETION - auto blocks = tr_bitfield{ tor->blockCount() }; + auto blocks = tr_bitfield{ tor->block_count() }; char const* err = nullptr; if (tr_variant const* const b = tr_variantDictFind(prog, TR_KEY_blocks); b != nullptr) { @@ -587,7 +587,7 @@ auto loadProgress(tr_variant* dict, tr_torrent* tor) { if (sv == "all"sv) { - blocks.setHasAll(); + blocks.set_has_all(); } else { @@ -596,7 +596,7 @@ auto loadProgress(tr_variant* dict, tr_torrent* tor) } else if (tr_variantDictFindRaw(prog, TR_KEY_bitfield, &raw, &rawlen)) { - blocks.setRaw(raw, rawlen); + blocks.set_raw(raw, rawlen); } else { @@ -609,7 +609,7 @@ auto loadProgress(tr_variant* dict, tr_torrent* tor) } else { - tor->setBlocks(blocks); + tor->set_blocks(blocks); } return tr_resume::Progress; @@ -625,11 +625,11 @@ auto loadFromFile(tr_torrent* tor, tr_resume::fields_t fields_to_load) auto fields_loaded = tr_resume::fields_t{}; TR_ASSERT(tr_isTorrent(tor)); - auto const was_dirty = tor->isDirty; + auto const was_dirty = tor->is_dirty(); - tr_torrent_metainfo::migrateFile(tor->session->resumeDir(), tor->name(), tor->infoHashString(), ".resume"sv); + tr_torrent_metainfo::migrate_file(tor->session->resumeDir(), tor->name(), tor->info_hash_string(), ".resume"sv); - auto const filename = tor->resumeFile(); + auto const filename = tor->resume_file(); if (!tr_sys_path_exists(filename)) { return fields_loaded; @@ -660,11 +660,11 @@ auto loadFromFile(tr_torrent* tor, tr_resume::fields_t fields_to_load) if ((fields_to_load & (tr_resume::Progress | tr_resume::DownloadDir)) != 0 && tr_variantDictFindStrView(&top, TR_KEY_destination, &sv) && !std::empty(sv)) { - bool const is_current_dir = tor->current_dir == tor->download_dir; - tor->download_dir = sv; + bool const is_current_dir = tor->current_dir() == tor->download_dir(); + tor->download_dir_ = sv; if (is_current_dir) { - tor->current_dir = sv; + tor->current_dir_ = sv; } fields_loaded |= tr_resume::DownloadDir; @@ -673,11 +673,11 @@ auto loadFromFile(tr_torrent* tor, tr_resume::fields_t fields_to_load) if ((fields_to_load & (tr_resume::Progress | tr_resume::IncompleteDir)) != 0 && tr_variantDictFindStrView(&top, TR_KEY_incomplete_dir, &sv) && !std::empty(sv)) { - bool const is_current_dir = tor->current_dir == tor->incomplete_dir; - tor->incomplete_dir = sv; + bool const is_current_dir = tor->current_dir() == tor->incomplete_dir(); + tor->incomplete_dir_ = sv; if (is_current_dir) { - tor->current_dir = sv; + tor->current_dir_ = sv; } fields_loaded |= tr_resume::IncompleteDir; @@ -721,7 +721,7 @@ auto loadFromFile(tr_torrent* tor, tr_resume::fields_t fields_to_load) if ((fields_to_load & tr_resume::ActivityDate) != 0 && tr_variantDictFindInt(&top, TR_KEY_activity_date, &i)) { - tor->setDateActive(i); + tor->set_date_active(i); fields_loaded |= tr_resume::ActivityDate; } @@ -765,7 +765,7 @@ auto loadFromFile(tr_torrent* tor, tr_resume::fields_t fields_to_load) fields_loaded |= loadProgress(&top, tor); } - if (!tor->isDone() && (fields_to_load & tr_resume::FilePriorities) != 0) + if (!tor->is_done() && (fields_to_load & tr_resume::FilePriorities) != 0) { fields_loaded |= loadFilePriorities(&top, tor); } @@ -808,7 +808,7 @@ auto loadFromFile(tr_torrent* tor, tr_resume::fields_t fields_to_load) /* loading the resume file triggers of a lot of changes, * but none of them needs to trigger a re-saving of the * same resume information... */ - tor->isDirty = was_dirty; + tor->set_dirty(was_dirty); tr_variantClear(&top); return fields_loaded; @@ -838,7 +838,7 @@ auto setFromCtor(tr_torrent* tor, tr_resume::fields_t fields, tr_ctor const* cto if (tr_ctorGetDownloadDir(ctor, mode, &path) && !tr_str_is_empty(path)) { ret |= tr_resume::DownloadDir; - tor->download_dir = path; + tor->download_dir_ = path; } } @@ -881,28 +881,28 @@ void save(tr_torrent* tor) auto top = tr_variant{}; auto const now = tr_time(); tr_variantInitDict(&top, 50); /* arbitrary "big enough" number */ - tr_variantDictAddInt(&top, TR_KEY_seeding_time_seconds, tor->secondsSeeding(now)); - tr_variantDictAddInt(&top, TR_KEY_downloading_time_seconds, tor->secondsDownloading(now)); + tr_variantDictAddInt(&top, TR_KEY_seeding_time_seconds, tor->seconds_seeding(now)); + tr_variantDictAddInt(&top, TR_KEY_downloading_time_seconds, tor->seconds_downloading(now)); tr_variantDictAddInt(&top, TR_KEY_activity_date, tor->activityDate); tr_variantDictAddInt(&top, TR_KEY_added_date, tor->addedDate); tr_variantDictAddInt(&top, TR_KEY_corrupt, tor->corruptPrev + tor->corruptCur); tr_variantDictAddInt(&top, TR_KEY_done_date, tor->doneDate); - tr_variantDictAddQuark(&top, TR_KEY_destination, tor->downloadDir().quark()); + tr_variantDictAddQuark(&top, TR_KEY_destination, tor->download_dir().quark()); - if (!std::empty(tor->incompleteDir())) + if (!std::empty(tor->incomplete_dir())) { - tr_variantDictAddQuark(&top, TR_KEY_incomplete_dir, tor->incompleteDir().quark()); + tr_variantDictAddQuark(&top, TR_KEY_incomplete_dir, tor->incomplete_dir().quark()); } 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->peerLimit()); - tr_variantDictAddInt(&top, TR_KEY_bandwidth_priority, tor->getPriority()); + tr_variantDictAddInt(&top, TR_KEY_max_peers, tor->peer_limit()); + tr_variantDictAddInt(&top, TR_KEY_bandwidth_priority, tor->get_priority()); tr_variantDictAddBool(&top, TR_KEY_paused, !tor->start_when_stable); - tr_variantDictAddBool(&top, TR_KEY_sequentialDownload, tor->isSequentialDownload()); + tr_variantDictAddBool(&top, TR_KEY_sequentialDownload, tor->is_sequential_download()); savePeers(&top, tor); - if (tor->hasMetainfo()) + if (tor->has_metainfo()) { saveFilePriorities(&top, tor); saveDND(&top, tor); @@ -917,10 +917,10 @@ void save(tr_torrent* tor) saveLabels(&top, tor); saveGroup(&top, tor); - auto const resume_file = tor->resumeFile(); + auto const resume_file = tor->resume_file(); if (auto const err = tr_variantToFile(&top, TR_VARIANT_FMT_BENC, resume_file); err != 0) { - tor->setLocalError(fmt::format(FMT_STRING("Unable to save resume file: {:s}"), tr_strerror(err))); + tor->set_local_error(fmt::format(FMT_STRING("Unable to save resume file: {:s}"), tr_strerror(err))); } tr_variantClear(&top); diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index 4f730bc40..d65d350fa 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -211,7 +211,7 @@ char const* torrentStart(tr_session* session, tr_variant* args_in, tr_variant* / std::sort(std::begin(torrents), std::end(torrents), CompareTorrentByQueuePosition{}); for (auto* tor : torrents) { - if (!tor->isRunning) + if (!tor->is_running()) { tr_torrentStart(tor); session->rpcNotify(TR_RPC_TORRENT_STARTED, tor); @@ -227,7 +227,7 @@ char const* torrentStartNow(tr_session* session, tr_variant* args_in, tr_variant std::sort(std::begin(torrents), std::end(torrents), CompareTorrentByQueuePosition{}); for (auto* tor : torrents) { - if (!tor->isRunning) + if (!tor->is_running()) { tr_torrentStartNow(tor); session->rpcNotify(TR_RPC_TORRENT_STARTED, tor); @@ -241,9 +241,9 @@ char const* torrentStop(tr_session* session, tr_variant* args_in, tr_variant* /* { for (auto* tor : getTorrents(session, args_in)) { - if (tor->isRunning || tor->isQueued() || tor->verifyState() != TR_VERIFY_NONE) + if (tor->is_running() || tor->is_queued() || tor->verify_state() != TR_VERIFY_NONE) { - tor->isStopping = true; + tor->is_stopping_ = true; session->rpcNotify(TR_RPC_TORRENT_STOPPED, tor); } } @@ -311,7 +311,7 @@ void addLabels(tr_torrent const* tor, tr_variant* list) void addFileStats(tr_torrent const* tor, tr_variant* list) { - for (tr_file_index_t i = 0, n = tor->fileCount(); i < n; ++i) + for (tr_file_index_t i = 0, n = tor->file_count(); i < n; ++i) { auto const file = tr_torrentFile(tor, i); tr_variant* d = tr_variantListAddDict(list, 3); @@ -323,7 +323,7 @@ void addFileStats(tr_torrent const* tor, tr_variant* list) void addFiles(tr_torrent const* tor, tr_variant* list) { - for (tr_file_index_t i = 0, n = tor->fileCount(); i < n; ++i) + for (tr_file_index_t i = 0, n = tor->file_count(); i < n; ++i) { auto const file = tr_torrentFile(tor, i); tr_variant* d = tr_variantListAddDict(list, 3); @@ -335,7 +335,7 @@ void addFiles(tr_torrent const* tor, tr_variant* list) void addWebseeds(tr_torrent const* tor, tr_variant* webseeds) { - for (size_t i = 0, n = tor->webseedCount(); i < n; ++i) + for (size_t i = 0, n = tor->webseed_count(); i < n; ++i) { tr_variantListAddStr(webseeds, tor->webseed(i)); } @@ -343,7 +343,7 @@ void addWebseeds(tr_torrent const* tor, tr_variant* webseeds) void addTrackers(tr_torrent const* tor, tr_variant* trackers) { - for (auto const& tracker : tor->announceList()) + for (auto const& tracker : tor->announce_list()) { auto* const d = tr_variantListAddDict(trackers, 5); tr_variantDictAddQuark(d, TR_KEY_announce, tracker.announce.quark()); @@ -521,15 +521,15 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_availability: - tr_variantInitList(initme, tor->pieceCount()); - for (tr_piece_index_t piece = 0, n = tor->pieceCount(); piece < n; ++piece) + tr_variantInitList(initme, tor->piece_count()); + for (tr_piece_index_t piece = 0, n = tor->piece_count(); piece < n; ++piece) { tr_variantListAddInt(initme, tr_peerMgrPieceAvailability(tor, piece)); } break; case TR_KEY_bandwidthPriority: - tr_variantInitInt(initme, tor->getPriority()); + tr_variantInitInt(initme, tor->get_priority()); break; case TR_KEY_comment: @@ -545,7 +545,7 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_dateCreated: - tr_variantInitInt(initme, tor->dateCreated()); + tr_variantInitInt(initme, tor->date_created()); break; case TR_KEY_desiredAvailable: @@ -569,7 +569,7 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_downloadLimited: - tr_variantInitBool(initme, tor->usesSpeedLimit(TR_DOWN)); + tr_variantInitBool(initme, tor->uses_speed_limit(TR_DOWN)); break; case TR_KEY_error: @@ -585,25 +585,25 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_file_count: - tr_variantInitInt(initme, tor->fileCount()); + tr_variantInitInt(initme, tor->file_count()); break; case TR_KEY_files: - tr_variantInitList(initme, tor->fileCount()); + tr_variantInitList(initme, tor->file_count()); addFiles(tor, initme); break; case TR_KEY_fileStats: - tr_variantInitList(initme, tor->fileCount()); + tr_variantInitList(initme, tor->file_count()); addFileStats(tor, initme); break; case TR_KEY_group: - tr_variantInitStrView(initme, tor->bandwidthGroup().sv()); + tr_variantInitStrView(initme, tor->bandwidth_group().sv()); break; case TR_KEY_hashString: - tr_variantInitStrView(initme, tor->infoHashString()); + tr_variantInitStrView(initme, tor->info_hash_string()); break; case TR_KEY_haveUnchecked: @@ -611,7 +611,7 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_sequentialDownload: - tr_variantDictAddBool(initme, TR_KEY_sequentialDownload, tor->isSequentialDownload()); + tr_variantDictAddBool(initme, TR_KEY_sequentialDownload, tor->is_sequential_download()); break; case TR_KEY_haveValid: @@ -619,7 +619,7 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_honorsSessionLimits: - tr_variantInitBool(initme, tor->usesSessionLimits()); + tr_variantInitBool(initme, tor->uses_session_limits()); break; case TR_KEY_id: @@ -635,7 +635,7 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_isPrivate: - tr_variantInitBool(initme, tor->isPrivate()); + tr_variantInitBool(initme, tor->is_private()); break; case TR_KEY_isStalled: @@ -656,7 +656,7 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* case TR_KEY_maxConnectedPeers: case TR_KEY_peer_limit: - tr_variantInitInt(initme, tor->peerLimit()); + tr_variantInitInt(initme, tor->peer_limit()); break; case TR_KEY_magnetLink: @@ -710,9 +710,9 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_pieces: - if (tor->hasMetainfo()) + if (tor->has_metainfo()) { - auto const bytes = tor->createPieceBitfield(); + auto const bytes = tor->create_piece_bitfield(); auto const enc = tr_base64_encode({ reinterpret_cast(std::data(bytes)), std::size(bytes) }); tr_variantInitStr(initme, enc); } @@ -724,20 +724,20 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_pieceCount: - tr_variantInitInt(initme, tor->pieceCount()); + tr_variantInitInt(initme, tor->piece_count()); break; case TR_KEY_pieceSize: - tr_variantInitInt(initme, tor->pieceSize()); + tr_variantInitInt(initme, tor->piece_size()); break; case TR_KEY_primary_mime_type: - tr_variantInitStrView(initme, tor->primaryMimeType()); + tr_variantInitStrView(initme, tor->primary_mime_type()); break; case TR_KEY_priorities: { - auto const n = tor->fileCount(); + auto const n = tor->file_count(); tr_variantInitList(initme, n); for (tr_file_index_t i = 0; i < n; ++i) { @@ -767,11 +767,11 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_seedIdleLimit: - tr_variantInitInt(initme, tor->idleLimitMinutes()); + tr_variantInitInt(initme, tor->idle_limit_minutes()); break; case TR_KEY_seedIdleMode: - tr_variantInitInt(initme, tor->idleLimitMode()); + tr_variantInitInt(initme, tor->idle_limit_mode()); break; case TR_KEY_seedRatioLimit: @@ -807,12 +807,12 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_trackers: - tr_variantInitList(initme, tor->trackerCount()); + tr_variantInitList(initme, tor->tracker_count()); addTrackers(tor, initme); break; case TR_KEY_trackerList: - tr_variantInitStr(initme, tor->trackerList()); + tr_variantInitStr(initme, tor->tracker_list()); break; case TR_KEY_trackerStats: @@ -828,11 +828,11 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* } case TR_KEY_torrentFile: - tr_variantInitStr(initme, tor->torrentFile()); + tr_variantInitStr(initme, tor->torrent_file()); break; case TR_KEY_totalSize: - tr_variantInitInt(initme, tor->totalSize()); + tr_variantInitInt(initme, tor->total_size()); break; case TR_KEY_uploadedEver: @@ -844,7 +844,7 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_uploadLimited: - tr_variantInitBool(initme, tor->usesSpeedLimit(TR_UP)); + tr_variantInitBool(initme, tor->uses_speed_limit(TR_UP)); break; case TR_KEY_uploadRatio: @@ -853,7 +853,7 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* case TR_KEY_wanted: { - auto const n = tor->fileCount(); + auto const n = tor->file_count(); tr_variantInitList(initme, n); for (tr_file_index_t i = 0; i < n; ++i) { @@ -863,7 +863,7 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* break; case TR_KEY_webseeds: - tr_variantInitList(initme, tor->webseedCount()); + tr_variantInitList(initme, tor->webseed_count()); addWebseeds(tor, initme); break; @@ -1013,7 +1013,7 @@ char const* setLabels(tr_torrent* tor, tr_variant* list) char const* setFilePriorities(tr_torrent* tor, tr_priority_t priority, tr_variant* list) { char const* errmsg = nullptr; - auto const n_files = tor->fileCount(); + auto const n_files = tor->file_count(); auto files = std::vector{}; files.reserve(n_files); @@ -1041,7 +1041,7 @@ char const* setFilePriorities(tr_torrent* tor, tr_priority_t priority, tr_varian std::iota(std::begin(files), std::end(files), 0); } - tor->setFilePriorities(std::data(files), std::size(files), priority); + tor->set_file_priorities(std::data(files), std::size(files), priority); return errmsg; } @@ -1050,7 +1050,7 @@ char const* setFileDLs(tr_torrent* tor, bool wanted, tr_variant* list) { char const* errmsg = nullptr; - auto const n_files = tor->fileCount(); + auto const n_files = tor->file_count(); auto const n_items = tr_variantListSize(list); auto files = std::vector{}; @@ -1079,14 +1079,14 @@ char const* setFileDLs(tr_torrent* tor, bool wanted, tr_variant* list) std::iota(std::begin(files), std::end(files), 0); } - tor->setFilesWanted(std::data(files), std::size(files), wanted); + tor->set_files_wanted(std::data(files), std::size(files), wanted); return errmsg; } char const* addTrackerUrls(tr_torrent* tor, tr_variant* urls) { - auto const old_size = tor->trackerCount(); + auto const old_size = tor->tracker_count(); for (size_t i = 0, n = tr_variantListSize(urls); i < n; ++i) { @@ -1097,15 +1097,15 @@ char const* addTrackerUrls(tr_torrent* tor, tr_variant* urls) continue; } - tor->announceList().add(announce); + tor->announce_list().add(announce); } - if (tor->trackerCount() == old_size) + if (tor->tracker_count() == old_size) { return "error setting announce list"; } - tor->announceList().save(tor->torrentFile()); + tor->announce_list().save(tor->torrent_file()); tor->on_announce_list_changed(); return nullptr; @@ -1123,7 +1123,7 @@ char const* replaceTrackers(tr_torrent* tor, tr_variant* urls) if (tr_variantGetInt(tr_variantListChild(urls, i), &id) && tr_variantGetStrView(tr_variantListChild(urls, i + 1), &newval)) { - changed |= tor->announceList().replace(static_cast(id), newval); + changed |= tor->announce_list().replace(static_cast(id), newval); } } @@ -1132,7 +1132,7 @@ char const* replaceTrackers(tr_torrent* tor, tr_variant* urls) return "error setting announce list"; } - tor->announceList().save(tor->torrentFile()); + tor->announce_list().save(tor->torrent_file()); tor->on_announce_list_changed(); return nullptr; @@ -1140,7 +1140,7 @@ char const* replaceTrackers(tr_torrent* tor, tr_variant* urls) char const* removeTrackers(tr_torrent* tor, tr_variant* ids) { - auto const old_size = tor->trackerCount(); + auto const old_size = tor->tracker_count(); for (size_t i = 0, n = tr_variantListSize(ids); i < n; ++i) { @@ -1151,15 +1151,15 @@ char const* removeTrackers(tr_torrent* tor, tr_variant* ids) continue; } - tor->announceList().remove(static_cast(id)); + tor->announce_list().remove(static_cast(id)); } - if (tor->trackerCount() == old_size) + if (tor->tracker_count() == old_size) { return "error setting announce list"; } - tor->announceList().save(tor->torrentFile()); + tor->announce_list().save(tor->torrent_file()); tor->on_announce_list_changed(); return nullptr; @@ -1187,7 +1187,7 @@ char const* torrentSet(tr_session* session, tr_variant* args_in, tr_variant* /*a if (std::string_view group; tr_variantDictFindStrView(args_in, TR_KEY_group, &group)) { - tor->setBandwidthGroup(group); + tor->set_bandwidth_group(group); } if (errmsg == nullptr && tr_variantDictFindList(args_in, TR_KEY_labels, &tmp_variant)) @@ -1232,12 +1232,12 @@ char const* torrentSet(tr_session* session, tr_variant* args_in, tr_variant* /*a if (auto val = bool{}; tr_variantDictFindBool(args_in, TR_KEY_sequentialDownload, &val)) { - tor->setSequentialDownload(val); + tor->set_sequential_download(val); } if (auto val = bool{}; tr_variantDictFindBool(args_in, TR_KEY_downloadLimited, &val)) { - tor->useSpeedLimit(TR_DOWN, val); + tor->use_speed_limit(TR_DOWN, val); } if (auto val = bool{}; tr_variantDictFindBool(args_in, TR_KEY_honorsSessionLimits, &val)) @@ -1252,12 +1252,12 @@ char const* torrentSet(tr_session* session, tr_variant* args_in, tr_variant* /*a if (auto val = bool{}; tr_variantDictFindBool(args_in, TR_KEY_uploadLimited, &val)) { - tor->useSpeedLimit(TR_UP, val); + tor->use_speed_limit(TR_UP, val); } if (tr_variantDictFindInt(args_in, TR_KEY_seedIdleLimit, &tmp)) { - tor->setIdleLimit(static_cast(tmp)); + tor->set_idle_limit(static_cast(tmp)); } if (tr_variantDictFindInt(args_in, TR_KEY_seedIdleMode, &tmp)) @@ -1272,7 +1272,7 @@ char const* torrentSet(tr_session* session, tr_variant* args_in, tr_variant* /*a if (tr_variantDictFindInt(args_in, TR_KEY_seedRatioMode, &tmp)) { - tor->setRatioMode(static_cast(tmp)); + tor->set_ratio_mode(static_cast(tmp)); } if (tr_variantDictFindInt(args_in, TR_KEY_queuePosition, &tmp)) @@ -1297,7 +1297,7 @@ char const* torrentSet(tr_session* session, tr_variant* args_in, tr_variant* /*a if (std::string_view txt; errmsg == nullptr && tr_variantDictFindStrView(args_in, TR_KEY_trackerList, &txt)) { - if (!tor->setTrackerList(txt)) + if (!tor->set_tracker_list(txt)) { errmsg = "Invalid tracker list"; } @@ -1332,7 +1332,7 @@ char const* torrentSetLocation( for (auto* tor : getTorrents(session, args_in)) { - tor->setLocation(location, move, nullptr, nullptr); + tor->set_location(location, move, nullptr, nullptr); session->rpcNotify(TR_RPC_TORRENT_MOVED, tor); } @@ -1367,7 +1367,7 @@ char const* torrentRenamePath( if (auto const torrents = getTorrents(session, args_in); std::size(torrents) == 1) { - torrents[0]->renamePath(oldpath, newname, torrentRenamePathDone, idle_data); + torrents[0]->rename_path(oldpath, newname, torrentRenamePathDone, idle_data); } else { @@ -1754,8 +1754,8 @@ char const* groupGet(tr_session* s, tr_variant* args_in, tr_variant* args_out, s if (names.empty() || names.count(name.sv()) > 0) { tr_variant* dict = tr_variantListAddDict(list, 5); - auto limits = group->getLimits(); - tr_variantDictAddBool(dict, TR_KEY_honorsSessionLimits, group->areParentLimitsHonored(TR_UP)); + auto limits = group->get_limits(); + tr_variantDictAddBool(dict, TR_KEY_honorsSessionLimits, group->are_parent_limits_honored(TR_UP)); tr_variantDictAddStr(dict, TR_KEY_name, name); tr_variantDictAddInt(dict, TR_KEY_speed_limit_down, limits.down_limit_KBps); tr_variantDictAddBool(dict, TR_KEY_speed_limit_down_enabled, limits.down_limited); @@ -1778,7 +1778,7 @@ char const* groupSet(tr_session* session, tr_variant* args_in, tr_variant* /*arg } auto& group = session->getBandwidthGroup(name); - auto limits = group.getLimits(); + auto limits = group.get_limits(); (void)tr_variantDictFindBool(args_in, TR_KEY_speed_limit_down_enabled, &limits.down_limited); (void)tr_variantDictFindBool(args_in, TR_KEY_speed_limit_up_enabled, &limits.up_limited); @@ -1793,12 +1793,12 @@ char const* groupSet(tr_session* session, tr_variant* args_in, tr_variant* /*arg limits.up_limit_KBps = static_cast(limit); } - group.setLimits(&limits); + group.set_limits(&limits); if (auto honors = bool{}; tr_variantDictFindBool(args_in, TR_KEY_honorsSessionLimits, &honors)) { - group.honorParentLimits(TR_UP, honors); - group.honorParentLimits(TR_DOWN, honors); + group.honor_parent_limits(TR_UP, honors); + group.honor_parent_limits(TR_DOWN, honors); } return nullptr; @@ -2076,7 +2076,7 @@ char const* sessionStats(tr_session* session, tr_variant* /*args_in*/, tr_varian auto const running = std::count_if( std::begin(torrents), std::end(torrents), - [](auto const* tor) { return tor->isRunning; }); + [](auto const* tor) { return tor->is_running(); }); tr_variantDictAddInt(args_out, TR_KEY_activeTorrentCount, running); tr_variantDictAddReal(args_out, TR_KEY_downloadSpeed, session->pieceSpeedBps(TR_DOWN)); diff --git a/libtransmission/session.cc b/libtransmission/session.cc index 0bf07af09..41b6a7179 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -103,12 +103,12 @@ void bandwidthGroupRead(tr_session* session, std::string_view config_dir) limits.down_limit_KBps = static_cast(limit); } - group.setLimits(&limits); + group.set_limits(&limits); if (auto honors = bool{}; tr_variantDictFindBool(dict, TR_KEY_honorsSessionLimits, &honors)) { - group.honorParentLimits(TR_UP, honors); - group.honorParentLimits(TR_DOWN, honors); + group.honor_parent_limits(TR_UP, honors); + group.honor_parent_limits(TR_DOWN, honors); } } tr_variantClear(&groups_dict); @@ -123,7 +123,7 @@ int bandwidthGroupWrite(tr_session const* session, std::string_view config_dir) for (auto const& [name, group] : groups) { - auto const limits = group->getLimits(); + auto const limits = group->get_limits(); auto* const dict = tr_variantDictAddDict(&groups_dict, name.quark(), 5); tr_variantDictAddStrView(dict, TR_KEY_name, name.sv()); @@ -131,7 +131,7 @@ int bandwidthGroupWrite(tr_session const* session, std::string_view config_dir) tr_variantDictAddInt(dict, TR_KEY_uploadLimit, limits.up_limit_KBps); tr_variantDictAddBool(dict, TR_KEY_downloadLimited, limits.down_limited); tr_variantDictAddInt(dict, TR_KEY_downloadLimit, limits.down_limit_KBps); - tr_variantDictAddBool(dict, TR_KEY_honorsSessionLimits, group->areParentLimitsHonored(TR_UP)); + tr_variantDictAddBool(dict, TR_KEY_honorsSessionLimits, group->are_parent_limits_honored(TR_UP)); } auto const filename = tr_pathbuf{ config_dir, '/', BandwidthGroupsFilename }; @@ -146,12 +146,12 @@ void update_bandwidth(tr_session* session, tr_direction dir) { if (auto const limit_bytes_per_second = session->activeSpeedLimitBps(dir); limit_bytes_per_second) { - session->top_bandwidth_.setLimited(dir, *limit_bytes_per_second > 0U); - session->top_bandwidth_.setDesiredSpeedBytesPerSecond(dir, *limit_bytes_per_second); + session->top_bandwidth_.set_limited(dir, *limit_bytes_per_second > 0U); + session->top_bandwidth_.set_desired_speed_bytes_per_second(dir, *limit_bytes_per_second); } else { - session->top_bandwidth_.setLimited(dir, false); + session->top_bandwidth_.set_limited(dir, false); } } } // namespace @@ -204,7 +204,7 @@ std::vector tr_session::DhtMediator::torrentsAllowingDHT() cons ids.reserve(std::size(torrents)); for (auto const* const tor : torrents) { - if (tor->isRunning && tor->allowsDht()) + if (tor->is_running() && tor->allows_dht()) { ids.push_back(tor->id()); } @@ -217,7 +217,7 @@ tr_sha1_digest_t tr_session::DhtMediator::torrentInfoHash(tr_torrent_id_t id) co { if (auto const* const tor = session_.torrents().get(id); tor != nullptr) { - return tor->infoHash(); + return tor->info_hash(); } return {}; @@ -242,7 +242,7 @@ bool tr_session::LpdMediator::onPeerFound(std::string_view info_hash_str, tr_add } tr_torrent* const tor = session_.torrents_.get(*digest); - if (!tr_isTorrent(tor) || !tor->allowsLpd()) + if (!tr_isTorrent(tor) || !tor->allows_lpd()) { return false; } @@ -261,9 +261,9 @@ std::vector tr_session::LpdMediator::torrents() c for (auto const* const tor : session_.torrents()) { auto info = tr_lpd::Mediator::TorrentInfo{}; - info.info_hash_str = tor->infoHashString(); + info.info_hash_str = tor->info_hash_string(); info.activity = tor->activity(); - info.allows_lpd = tor->allowsLpd(); + info.allows_lpd = tor->allows_lpd(); info.announce_after = tor->lpdAnnounceAt; ret.emplace_back(info); } @@ -334,7 +334,7 @@ void tr_session::WebMediator::notifyBandwidthConsumed(int torrent_id, size_t byt if (auto* const tor = session_->torrents().get(torrent_id); tor != nullptr) { - tor->bandwidth_.notifyBandwidthConsumed(TR_DOWN, byte_count, true, tr_time_msec()); + tor->bandwidth_.notify_bandwidth_consumed(TR_DOWN, byte_count, true, tr_time_msec()); } } @@ -1235,7 +1235,7 @@ void tr_sessionSetDeleteSource(tr_session* session, bool delete_source) double tr_sessionGetRawSpeed_KBps(tr_session const* session, tr_direction dir) { - auto const bps = session != nullptr ? session->top_bandwidth_.getRawSpeedBytesPerSecond(0, dir) : 0; + auto const bps = session != nullptr ? session->top_bandwidth_.get_raw_speed_bytes_per_second(0, dir) : 0; return tr_toSpeedKBps(bps); } @@ -1526,7 +1526,7 @@ void tr_session::setDefaultTrackers(std::string_view trackers) { for (auto* const tor : torrents()) { - if (tor->isPublic()) + if (tor->is_public()) { announcer_->resetTorrent(tor); } @@ -1957,7 +1957,7 @@ std::vector tr_session::getNextQueuedTorrents(tr_direction dir, siz candidates.reserve(std::size(torrents())); for (auto* const tor : torrents()) { - if (tor->isQueued() && (dir == tor->queueDirection())) + if (tor->is_queued() && (dir == tor->queue_direction())) { candidates.push_back(tor); } diff --git a/libtransmission/session.h b/libtransmission/session.h index d588cbb68..4c9d32c88 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -791,7 +791,7 @@ public: [[nodiscard]] auto pieceSpeedBps(tr_direction dir) const noexcept { - return top_bandwidth_.getPieceSpeedBytesPerSecond(0, dir); + return top_bandwidth_.get_piece_speed_bytes_per_second(0, dir); } [[nodiscard]] std::optional activeSpeedLimitBps(tr_direction dir) const noexcept; diff --git a/libtransmission/torrent-ctor.cc b/libtransmission/torrent-ctor.cc index 5f2c46673..80d72c27d 100644 --- a/libtransmission/torrent-ctor.cc +++ b/libtransmission/torrent-ctor.cc @@ -82,7 +82,7 @@ bool tr_ctorSetMetainfoFromFile(tr_ctor* ctor, std::string_view filename, tr_err ctor->torrent_filename = filename; auto const contents_sv = std::string_view{ std::data(ctor->contents), std::size(ctor->contents) }; - return ctor->metainfo.parseBenc(contents_sv, error); + return ctor->metainfo.parse_benc(contents_sv, error); } bool tr_ctorSetMetainfoFromFile(tr_ctor* ctor, char const* filename, tr_error** error) @@ -95,7 +95,7 @@ bool tr_ctorSetMetainfo(tr_ctor* ctor, char const* metainfo, size_t len, tr_erro ctor->torrent_filename.clear(); ctor->contents.assign(metainfo, metainfo + len); auto const contents_sv = std::string_view{ std::data(ctor->contents), std::size(ctor->contents) }; - return ctor->metainfo.parseBenc(contents_sv, error); + return ctor->metainfo.parse_benc(contents_sv, error); } bool tr_ctorSetMetainfoFromMagnetLink(tr_ctor* ctor, std::string_view magnet_link, tr_error** error) @@ -151,9 +151,9 @@ void tr_ctorSetFilePriorities(tr_ctor* ctor, tr_file_index_t const* files, tr_fi void tr_ctorInitTorrentPriorities(tr_ctor const* ctor, tr_torrent* tor) { - tor->setFilePriorities(std::data(ctor->low), std::size(ctor->low), TR_PRI_LOW); - tor->setFilePriorities(std::data(ctor->normal), std::size(ctor->normal), TR_PRI_NORMAL); - tor->setFilePriorities(std::data(ctor->high), std::size(ctor->high), TR_PRI_HIGH); + tor->set_file_priorities(std::data(ctor->low), std::size(ctor->low), TR_PRI_LOW); + tor->set_file_priorities(std::data(ctor->normal), std::size(ctor->normal), TR_PRI_NORMAL); + tor->set_file_priorities(std::data(ctor->high), std::size(ctor->high), TR_PRI_HIGH); } void tr_ctorSetFilesWanted(tr_ctor* ctor, tr_file_index_t const* files, tr_file_index_t file_count, bool wanted) @@ -164,8 +164,8 @@ void tr_ctorSetFilesWanted(tr_ctor* ctor, tr_file_index_t const* files, tr_file_ void tr_ctorInitTorrentWanted(tr_ctor const* ctor, tr_torrent* tor) { - tor->initFilesWanted(std::data(ctor->unwanted), std::size(ctor->unwanted), false); - tor->initFilesWanted(std::data(ctor->wanted), std::size(ctor->wanted), true); + tor->init_files_wanted(std::data(ctor->unwanted), std::size(ctor->unwanted), false); + tor->init_files_wanted(std::data(ctor->wanted), std::size(ctor->wanted), true); } // --- @@ -295,7 +295,7 @@ tr_torrent_metainfo tr_ctorStealMetainfo(tr_ctor* ctor) tr_torrent_metainfo const* tr_ctorGetMetainfo(tr_ctor const* ctor) { - return !std::empty(ctor->metainfo.infoHashString()) ? &ctor->metainfo : nullptr; + return !std::empty(ctor->metainfo.info_hash_string()) ? &ctor->metainfo : nullptr; } tr_session* tr_ctorGetSession(tr_ctor const* ctor) diff --git a/libtransmission/torrent-magnet.cc b/libtransmission/torrent-magnet.cc index 7aa0cfb07..95dd45f88 100644 --- a/libtransmission/torrent-magnet.cc +++ b/libtransmission/torrent-magnet.cc @@ -69,7 +69,7 @@ auto create_all_needed(int n_pieces) bool tr_torrentSetMetadataSizeHint(tr_torrent* tor, int64_t size) { - if (tor->hasMetainfo()) + if (tor->has_metainfo()) { return false; } @@ -116,27 +116,27 @@ std::optional> tr_torrentGetMetadataPiece(tr_torrent cons TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(piece >= 0); - if (!tor->hasMetainfo()) + if (!tor->has_metainfo()) { return {}; } - auto const n_pieces = std::max(1, static_cast(tor->infoDictSize() / METADATA_PIECE_SIZE)); + auto const n_pieces = std::max(1, static_cast(tor->info_dict_size() / METADATA_PIECE_SIZE)); if (piece < 0 || piece >= n_pieces) { return {}; } - auto in = std::ifstream{ tor->torrentFile(), std::ios_base::in }; + auto in = std::ifstream{ tor->torrent_file(), std::ios_base::in }; if (!in.is_open()) { return {}; } - auto const info_dict_size = tor->infoDictSize(); + auto const info_dict_size = tor->info_dict_size(); TR_ASSERT(info_dict_size > 0); auto const offset_in_info_dict = static_cast(piece) * METADATA_PIECE_SIZE; - if (auto const offset_in_file = tor->infoDictOffset() + offset_in_info_dict; !in.seekg(offset_in_file)) + if (auto const offset_in_file = tor->info_dict_offset() + offset_in_info_dict; !in.seekg(offset_in_file)) { return {}; } @@ -160,16 +160,16 @@ bool tr_torrentUseMetainfoFromFile( tr_error** error) { // add .torrent file - if (!tr_sys_path_copy(filename_in, tor->torrentFile(), error)) + if (!tr_sys_path_copy(filename_in, tor->torrent_file(), error)) { return false; } // remove .magnet file - tr_sys_path_remove(tor->magnetFile()); + tr_sys_path_remove(tor->magnet_file()); // tor should keep this metainfo - tor->setMetainfo(*metainfo); + tor->set_metainfo(*metainfo); if (tor->incompleteMetadata != nullptr) { @@ -212,12 +212,12 @@ void build_metainfo_except_info_dict(tr_torrent_metainfo const& tm, tr_variant* tr_variantDictAddStr(top, TR_KEY_created_by, val); } - if (auto const val = tm.dateCreated(); val != 0) + if (auto const val = tm.date_created(); val != 0) { tr_variantDictAddInt(top, TR_KEY_creation_date, val); } - if (auto const& announce_list = tm.announceList(); !std::empty(announce_list)) + if (auto const& announce_list = tm.announce_list(); !std::empty(announce_list)) { auto const n = std::size(announce_list); if (n == 1) @@ -241,7 +241,7 @@ void build_metainfo_except_info_dict(tr_torrent_metainfo const& tm, tr_variant* } } - if (auto const n_webseeds = tm.webseedCount(); n_webseeds > 0) + if (auto const n_webseeds = tm.webseed_count(); n_webseeds > 0) { auto* const webseeds_variant = tr_variantDictAddList(top, TR_KEY_url_list, n_webseeds); for (size_t i = 0; i < n_webseeds; ++i) @@ -254,7 +254,7 @@ void build_metainfo_except_info_dict(tr_torrent_metainfo const& tm, tr_variant* bool use_new_metainfo(tr_torrent* tor, tr_incomplete_metadata const* m, tr_error** error) { // test the info_dict checksum - if (tr_sha1::digest(m->metadata) != tor->infoHash()) + if (tr_sha1::digest(m->metadata) != tor->info_hash()) { return false; } @@ -276,22 +276,22 @@ bool use_new_metainfo(tr_torrent* tor, tr_incomplete_metadata const* m, tr_error // does this synthetic torrent file parse? auto metainfo = tr_torrent_metainfo{}; - if (!metainfo.parseBenc(benc)) + if (!metainfo.parse_benc(benc)) { return false; } // save it - if (!tr_saveFile(tor->torrentFile(), benc, error)) + if (!tr_saveFile(tor->torrent_file(), benc, error)) { return false; } // remove .magnet file - tr_sys_path_remove(tor->magnetFile()); + tr_sys_path_remove(tor->magnet_file()); // tor should keep this metainfo - tor->setMetainfo(metainfo); + tor->set_metainfo(metainfo); return true; } @@ -413,7 +413,7 @@ std::optional tr_torrentGetNextMetadataRequest(tr_torrent* tor, time_t now) double tr_torrentGetMetadataPercent(tr_torrent const* tor) { - if (tor->hasMetainfo()) + if (tor->has_metainfo()) { return 1.0; } diff --git a/libtransmission/torrent-metainfo.cc b/libtransmission/torrent-metainfo.cc index 0c24a7c6b..d7321383b 100644 --- a/libtransmission/torrent-metainfo.cc +++ b/libtransmission/torrent-metainfo.cc @@ -40,11 +40,11 @@ using namespace std::literals; * mktorrent and very old versions of utorrent, that don't add the * trailing slash for multifile torrents if omitted by the end user. */ -std::string tr_torrent_metainfo::fixWebseedUrl(tr_torrent_metainfo const& tm, std::string_view url) +std::string tr_torrent_metainfo::fix_webseed_url(tr_torrent_metainfo const& tm, std::string_view url) { url = tr_strvStrip(url); - if (tm.fileCount() > 1U && !std::empty(url) && url.back() != '/') + if (tm.file_count() > 1U && !std::empty(url) && url.back() != '/') { return std::string{ url } + '/'; } @@ -347,7 +347,7 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler{}; auto handler = MetainfoHandler{ *this }; @@ -664,7 +664,7 @@ bool tr_torrent_metainfo::parseBenc(std::string_view benc, tr_error** error) return true; } -bool tr_torrent_metainfo::parseTorrentFile(std::string_view filename, std::vector* contents, tr_error** error) +bool tr_torrent_metainfo::parse_torrent_file(std::string_view filename, std::vector* contents, tr_error** error) { auto local_contents = std::vector{}; @@ -673,10 +673,10 @@ bool tr_torrent_metainfo::parseTorrentFile(std::string_view filename, std::vecto contents = &local_contents; } - return tr_loadFile(filename, *contents, error) && parseBenc({ std::data(*contents), std::size(*contents) }, error); + return tr_loadFile(filename, *contents, error) && parse_benc({ std::data(*contents), std::size(*contents) }, error); } -tr_pathbuf tr_torrent_metainfo::makeFilename( +tr_pathbuf tr_torrent_metainfo::make_filename( std::string_view dirname, std::string_view name, std::string_view info_hash_string, @@ -689,19 +689,19 @@ tr_pathbuf tr_torrent_metainfo::makeFilename( tr_pathbuf{ dirname, '/', name, '.', info_hash_string.substr(0, 16), suffix }; } -bool tr_torrent_metainfo::migrateFile( +bool tr_torrent_metainfo::migrate_file( std::string_view dirname, std::string_view name, std::string_view info_hash_string, std::string_view suffix) { - auto const old_filename = makeFilename(dirname, name, info_hash_string, BasenameFormat::NameAndPartialHash, suffix); + auto const old_filename = make_filename(dirname, name, info_hash_string, BasenameFormat::NameAndPartialHash, suffix); if (!tr_sys_path_exists(old_filename)) { return false; } - auto const new_filename = makeFilename(dirname, name, info_hash_string, BasenameFormat::Hash, suffix); + auto const new_filename = make_filename(dirname, name, info_hash_string, BasenameFormat::Hash, suffix); if (tr_sys_path_exists(new_filename)) { tr_sys_path_remove(old_filename); @@ -723,15 +723,15 @@ bool tr_torrent_metainfo::migrateFile( return renamed; } -void tr_torrent_metainfo::removeFile( +void tr_torrent_metainfo::remove_file( std::string_view dirname, std::string_view name, std::string_view info_hash_string, std::string_view suffix) { - auto filename = makeFilename(dirname, name, info_hash_string, BasenameFormat::NameAndPartialHash, suffix); + auto filename = make_filename(dirname, name, info_hash_string, BasenameFormat::NameAndPartialHash, suffix); tr_sys_path_remove(filename, nullptr); - filename = makeFilename(dirname, name, info_hash_string, BasenameFormat::Hash, suffix); + filename = make_filename(dirname, name, info_hash_string, BasenameFormat::Hash, suffix); tr_sys_path_remove(filename, nullptr); } diff --git a/libtransmission/torrent-metainfo.h b/libtransmission/torrent-metainfo.h index 6aec4a629..98119385f 100644 --- a/libtransmission/torrent-metainfo.h +++ b/libtransmission/torrent-metainfo.h @@ -28,13 +28,13 @@ public: return std::empty(files_); } - bool parseBenc(std::string_view benc, tr_error** error = nullptr); + bool parse_benc(std::string_view benc, tr_error** error = nullptr); // Helper function wrapper around parseBenc(). // If you're looping through several files, passing in a non-nullptr // `contents` can reduce the number of memory allocations needed to // load multiple files. - bool parseTorrentFile(std::string_view benc_filename, std::vector* contents = nullptr, tr_error** error = nullptr); + bool parse_torrent_file(std::string_view benc_filename, std::vector* contents = nullptr, tr_error** error = nullptr); // FILES @@ -42,70 +42,70 @@ public: { return files_; } - [[nodiscard]] TR_CONSTEXPR20 auto fileCount() const noexcept + [[nodiscard]] TR_CONSTEXPR20 auto file_count() const noexcept { return files().fileCount(); } - [[nodiscard]] TR_CONSTEXPR20 auto fileSize(tr_file_index_t i) const + [[nodiscard]] TR_CONSTEXPR20 auto file_size(tr_file_index_t i) const { return files().fileSize(i); } - [[nodiscard]] TR_CONSTEXPR20 auto const& fileSubpath(tr_file_index_t i) const + [[nodiscard]] TR_CONSTEXPR20 auto const& file_subpath(tr_file_index_t i) const { return files().path(i); } - void setFileSubpath(tr_file_index_t i, std::string_view subpath) + void set_file_subpath(tr_file_index_t i, std::string_view subpath) { files_.setPath(i, subpath); } /// BLOCK INFO - [[nodiscard]] constexpr auto const& blockInfo() const noexcept + [[nodiscard]] constexpr auto const& block_info() const noexcept { return block_info_; } - [[nodiscard]] constexpr auto blockCount() const noexcept + [[nodiscard]] constexpr auto block_count() const noexcept { - return blockInfo().blockCount(); + return block_info().block_count(); } - [[nodiscard]] constexpr auto byteLoc(uint64_t nth_byte) const noexcept + [[nodiscard]] constexpr auto byte_loc(uint64_t nth_byte) const noexcept { - return blockInfo().byteLoc(nth_byte); + return block_info().byte_loc(nth_byte); } - [[nodiscard]] constexpr auto blockLoc(tr_block_index_t block) const noexcept + [[nodiscard]] constexpr auto block_loc(tr_block_index_t block) const noexcept { - return blockInfo().blockLoc(block); + return block_info().block_loc(block); } - [[nodiscard]] constexpr auto pieceLoc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const noexcept + [[nodiscard]] constexpr auto piece_loc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const noexcept { - return blockInfo().pieceLoc(piece, offset, length); + return block_info().piece_loc(piece, offset, length); } - [[nodiscard]] constexpr auto blockSize(tr_block_index_t block) const noexcept + [[nodiscard]] constexpr auto block_size(tr_block_index_t block) const noexcept { - return blockInfo().blockSize(block); + return block_info().block_size(block); } - [[nodiscard]] constexpr auto blockSpanForPiece(tr_piece_index_t piece) const noexcept + [[nodiscard]] constexpr auto block_span_for_piece(tr_piece_index_t piece) const noexcept { - return blockInfo().blockSpanForPiece(piece); + return block_info().block_span_for_piece(piece); } - [[nodiscard]] constexpr auto pieceCount() const noexcept + [[nodiscard]] constexpr auto piece_count() const noexcept { - return blockInfo().pieceCount(); + return block_info().piece_count(); } - [[nodiscard]] constexpr auto pieceSize() const noexcept + [[nodiscard]] constexpr auto piece_size() const noexcept { - return blockInfo().pieceSize(); + return block_info().piece_size(); } - [[nodiscard]] constexpr auto pieceSize(tr_piece_index_t piece) const noexcept + [[nodiscard]] constexpr auto piece_size(tr_piece_index_t piece) const noexcept { - return blockInfo().pieceSize(piece); + return block_info().piece_size(piece); } - [[nodiscard]] constexpr auto totalSize() const noexcept + [[nodiscard]] constexpr auto total_size() const noexcept { - return blockInfo().totalSize(); + return block_info().total_size(); } // OTHER PROPERTIES @@ -123,72 +123,72 @@ public: return source_; } - [[nodiscard]] constexpr auto const& isPrivate() const noexcept + [[nodiscard]] constexpr auto const& is_private() const noexcept { return is_private_; } - [[nodiscard]] TR_CONSTEXPR20 tr_sha1_digest_t const& pieceHash(tr_piece_index_t piece) const + [[nodiscard]] TR_CONSTEXPR20 tr_sha1_digest_t const& piece_hash(tr_piece_index_t piece) const { return pieces_[piece]; } - [[nodiscard]] TR_CONSTEXPR20 bool hasV1Metadata() const noexcept + [[nodiscard]] TR_CONSTEXPR20 bool has_v1_metadata() const noexcept { // need 'pieces' field and 'files' or 'length' // TODO check for 'files' or 'length' return !std::empty(pieces_); } - [[nodiscard]] constexpr bool hasV2Metadata() const noexcept + [[nodiscard]] constexpr bool has_v2_metadata() const noexcept { return is_v2_; } - [[nodiscard]] constexpr auto const& dateCreated() const noexcept + [[nodiscard]] constexpr auto const& date_created() const noexcept { return date_created_; } - [[nodiscard]] constexpr auto infoDictSize() const noexcept + [[nodiscard]] constexpr auto info_dict_size() const noexcept { return info_dict_size_; } - [[nodiscard]] constexpr auto infoDictOffset() const noexcept + [[nodiscard]] constexpr auto info_dict_offset() const noexcept { return info_dict_offset_; } - [[nodiscard]] constexpr auto piecesOffset() const noexcept + [[nodiscard]] constexpr auto pieces_offset() const noexcept { return pieces_offset_; } // UTILS - [[nodiscard]] auto torrentFile(std::string_view torrent_dir) const + [[nodiscard]] auto torrent_file(std::string_view torrent_dir) const { - return makeFilename(torrent_dir, name(), infoHashString(), BasenameFormat::Hash, ".torrent"); + return make_filename(torrent_dir, name(), info_hash_string(), BasenameFormat::Hash, ".torrent"); } - [[nodiscard]] auto magnetFile(std::string_view torrent_dir) const + [[nodiscard]] auto magnet_file(std::string_view torrent_dir) const { - return makeFilename(torrent_dir, name(), infoHashString(), BasenameFormat::Hash, ".magnet"); + return make_filename(torrent_dir, name(), info_hash_string(), BasenameFormat::Hash, ".magnet"); } - [[nodiscard]] auto resumeFile(std::string_view resume_dir) const + [[nodiscard]] auto resume_file(std::string_view resume_dir) const { - return makeFilename(resume_dir, name(), infoHashString(), BasenameFormat::Hash, ".resume"); + return make_filename(resume_dir, name(), info_hash_string(), BasenameFormat::Hash, ".resume"); } - static bool migrateFile( + static bool migrate_file( std::string_view dirname, std::string_view name, std::string_view info_hash_string, std::string_view suffix); - static void removeFile( + static void remove_file( std::string_view dirname, std::string_view name, std::string_view info_hash_string, @@ -196,12 +196,8 @@ public: private: friend struct MetainfoHandler; - static bool parseImpl(tr_torrent_metainfo& setme, std::string_view benc, tr_error** error); - // static bool parsePath(std::string_view root, tr_variant* path, std::string& setme); - static std::string fixWebseedUrl(tr_torrent_metainfo const& tm, std::string_view url); - // static std::string_view parseFiles(tr_torrent_metainfo& setme, tr_variant* info_dict, uint64_t* setme_total_size); - // static std::string_view parseAnnounce(tr_torrent_metainfo& setme, tr_variant* meta); - // static void parseWebseeds(tr_torrent_metainfo& setme, tr_variant* meta); + static bool parse_impl(tr_torrent_metainfo& setme, std::string_view benc, tr_error** error); + static std::string fix_webseed_url(tr_torrent_metainfo const& tm, std::string_view url); enum class BasenameFormat { @@ -209,16 +205,16 @@ private: NameAndPartialHash }; - [[nodiscard]] static tr_pathbuf makeFilename( + [[nodiscard]] static tr_pathbuf make_filename( std::string_view dirname, std::string_view name, std::string_view info_hash_string, BasenameFormat format, std::string_view suffix); - [[nodiscard]] auto makeFilename(std::string_view dirname, BasenameFormat format, std::string_view suffix) const + [[nodiscard]] auto make_filename(std::string_view dirname, BasenameFormat format, std::string_view suffix) const { - return makeFilename(dirname, name(), infoHashString(), format, suffix); + return make_filename(dirname, name(), info_hash_string(), format, suffix); } tr_block_info block_info_ = tr_block_info{ 0, 0 }; diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 45b5a8231..b3f772dd8 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -63,7 +63,7 @@ uint64_t tr_torrentTotalSize(tr_torrent const* tor) { TR_ASSERT(tr_isTorrent(tor)); - return tor->totalSize(); + return tor->total_size(); } tr_torrent_id_t tr_torrentId(tr_torrent const* tor) @@ -83,7 +83,7 @@ tr_torrent* tr_torrentFindFromMetainfo(tr_session* session, tr_torrent_metainfo return nullptr; } - return session->torrents().get(metainfo->infoHash()); + return session->torrents().get(metainfo->info_hash()); } tr_torrent* tr_torrentFindFromMagnetLink(tr_session* session, char const* magnet_link) @@ -116,7 +116,7 @@ bool tr_torrentSetMetainfoFromFile(tr_torrent* tor, tr_torrent_metainfo const* m if (error != nullptr) { - tor->setLocalError(fmt::format( + tor->set_local_error(fmt::format( _("Couldn't use metainfo from '{path}' for '{magnet}': {error} ({error_code})"), fmt::arg("path", filename), fmt::arg("magnet", tor->magnet()), @@ -133,27 +133,25 @@ bool tr_torrentSetMetainfoFromFile(tr_torrent* tor, tr_torrent_metainfo const* m namespace { -void torrentSetQueued(tr_torrent* tor, bool queued) +constexpr void torrentSetQueued(tr_torrent* tor, bool queued) { - TR_ASSERT(tr_isTorrent(tor)); - - if (tor->isQueued() != queued) + if (tor->is_queued_ != queued) { - tor->is_queued = queued; - tor->markChanged(); - tor->setDirty(); + tor->is_queued_ = queued; + tor->mark_changed(); + tor->set_dirty(); } } bool setLocalErrorIfFilesDisappeared(tr_torrent* tor, std::optional has_local_data = {}) { - auto const has = has_local_data ? *has_local_data : tor->hasAnyLocalData(); - bool const files_disappeared = tor->hasTotal() > 0 && !has; + auto const has = has_local_data ? *has_local_data : tor->has_any_local_data(); + bool const files_disappeared = tor->has_total() > 0 && !has; if (files_disappeared) { tr_logAddTraceTor(tor, "[LAZY] uh oh, the files disappeared"); - tor->setLocalError(_( + tor->set_local_error(_( "No data found! Ensure your drives are connected or use \"Set Location\". To re-download, remove the torrent and re-add it.")); } @@ -178,7 +176,7 @@ bool tr_torrentGetSeedRatioBytes(tr_torrent const* tor, uint64_t* setme_left, ui if (auto seed_ratio = double{}; tr_torrentGetSeedRatio(tor, &seed_ratio)) { auto const uploaded = tor->uploadedCur + tor->uploadedPrev; - auto const baseline = tor->sizeWhenDone(); + auto const baseline = tor->size_when_done(); auto const goal = baseline * seed_ratio; if (setme_left != nullptr) @@ -191,7 +189,7 @@ bool tr_torrentGetSeedRatioBytes(tr_torrent const* tor, uint64_t* setme_left, ui *setme_goal = goal; } - seed_ratio_applies = tor->isDone(); + seed_ratio_applies = tor->is_done(); } return seed_ratio_applies; @@ -208,7 +206,7 @@ bool tr_torrentIsSeedRatioDone(tr_torrent const* tor) 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)); + tor->set_speed_limit_bps(dir, tr_toSpeedBytes(kilo_per_second)); } tr_kilobytes_per_second_t tr_torrentGetSpeedLimit_KBps(tr_torrent const* tor, tr_direction dir) @@ -216,7 +214,7 @@ tr_kilobytes_per_second_t tr_torrentGetSpeedLimit_KBps(tr_torrent const* tor, tr TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(tr_isDirection(dir)); - return tr_toSpeedKBps(tor->speedLimitBps(dir)); + return tr_toSpeedKBps(tor->speed_limit_bps(dir)); } void tr_torrentUseSpeedLimit(tr_torrent* tor, tr_direction dir, bool enabled) @@ -224,23 +222,23 @@ void tr_torrentUseSpeedLimit(tr_torrent* tor, tr_direction dir, bool enabled) TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(tr_isDirection(dir)); - tor->useSpeedLimit(dir, enabled); + tor->use_speed_limit(dir, enabled); } bool tr_torrentUsesSpeedLimit(tr_torrent const* tor, tr_direction dir) { TR_ASSERT(tr_isTorrent(tor)); - return tor->usesSpeedLimit(dir); + return tor->uses_speed_limit(dir); } void tr_torrentUseSessionLimits(tr_torrent* tor, bool enabled) { TR_ASSERT(tr_isTorrent(tor)); - if (tor->bandwidth_.honorParentLimits(TR_UP, enabled) || tor->bandwidth_.honorParentLimits(TR_DOWN, enabled)) + if (tor->bandwidth_.honor_parent_limits(TR_UP, enabled) || tor->bandwidth_.honor_parent_limits(TR_DOWN, enabled)) { - tor->setDirty(); + tor->set_dirty(); } } @@ -248,7 +246,7 @@ bool tr_torrentUsesSessionLimits(tr_torrent const* tor) { TR_ASSERT(tr_isTorrent(tor)); - return tor->usesSessionLimits(); + return tor->uses_session_limits(); } // --- Download Ratio @@ -258,7 +256,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); - tor->setRatioMode(mode); + tor->set_ratio_mode(mode); } tr_ratiolimit tr_torrentGetRatioMode(tr_torrent const* tor) @@ -276,7 +274,7 @@ void tr_torrentSetRatioLimit(tr_torrent* tor, double desired_ratio) { tor->desiredRatio = desired_ratio; - tor->setDirty(); + tor->set_dirty(); } } @@ -334,7 +332,7 @@ void tr_torrentSetIdleMode(tr_torrent* tor, tr_idlelimit mode) { tor->idle_limit_mode_ = mode; - tor->setDirty(); + tor->set_dirty(); } } @@ -342,35 +340,35 @@ tr_idlelimit tr_torrentGetIdleMode(tr_torrent const* tor) { TR_ASSERT(tr_isTorrent(tor)); - return tor->idleLimitMode(); + return tor->idle_limit_mode(); } void tr_torrentSetIdleLimit(tr_torrent* tor, uint16_t idle_minutes) { TR_ASSERT(tr_isTorrent(tor)); - tor->setIdleLimit(idle_minutes); + tor->set_idle_limit(idle_minutes); } uint16_t tr_torrentGetIdleLimit(tr_torrent const* tor) { TR_ASSERT(tr_isTorrent(tor)); - return tor->idleLimitMinutes(); + return tor->idle_limit_minutes(); } bool tr_torrentGetSeedIdle(tr_torrent const* tor, uint16_t* idle_minutes) { auto is_limited = bool{}; - switch (tor->idleLimitMode()) + switch (tor->idle_limit_mode()) { case TR_IDLELIMIT_SINGLE: is_limited = true; if (idle_minutes != nullptr) { - *idle_minutes = tor->idleLimitMinutes(); + *idle_minutes = tor->idle_limit_minutes(); } break; @@ -438,7 +436,7 @@ void torrentCallScript(tr_torrent const* tor, std::string const& script) return; } - auto torrent_dir = tr_pathbuf{ tor->currentDir() }; + auto torrent_dir = tr_pathbuf{ tor->current_dir() }; tr_sys_path_native_separators(std::data(torrent_dir)); auto const cmd = std::array{ script.c_str(), nullptr }; @@ -454,7 +452,7 @@ void torrentCallScript(tr_torrent const* tor, std::string const& script) { "TR_TIME_LOCALTIME"sv, localtime_str }, { "TR_TORRENT_BYTES_DOWNLOADED"sv, bytes_downloaded_str }, { "TR_TORRENT_DIR"sv, torrent_dir.c_str() }, - { "TR_TORRENT_HASH"sv, tor->infoHashString() }, + { "TR_TORRENT_HASH"sv, tor->info_hash_string() }, { "TR_TORRENT_ID"sv, id_str }, { "TR_TORRENT_LABELS"sv, labels_str }, { "TR_TORRENT_NAME"sv, tr_torrentName(tor) }, @@ -514,7 +512,7 @@ void tr_torrentCheckSeedLimit(tr_torrent* tor) TR_ASSERT(tr_isTorrent(tor)); - if (!tor->isRunning || tor->isStopping || !tor->isDone()) + if (!tor->is_running() || tor->is_stopping_ || !tor->is_done()) { return; } @@ -523,7 +521,7 @@ void tr_torrentCheckSeedLimit(tr_torrent* tor) if (tr_torrentIsSeedRatioDone(tor)) { tr_logAddInfoTor(tor, _("Seed ratio reached; pausing torrent")); - tor->isStopping = true; + tor->is_stopping_ = true; tor->session->onRatioLimitHit(tor); } /* if we're seeding and reach our inactivity limit, stop the torrent */ @@ -531,12 +529,12 @@ void tr_torrentCheckSeedLimit(tr_torrent* tor) { tr_logAddInfoTor(tor, _("Seeding idle limit reached; pausing torrent")); - tor->isStopping = true; - tor->finishedSeedingByIdle = true; + tor->is_stopping_ = true; + tor->finished_seeding_by_idle_ = true; tor->session->onIdleLimitHit(tor); } - if (tor->isStopping) + if (tor->is_stopping_) { callScriptIfEnabled(tor, TR_SCRIPT_ON_TORRENT_DONE_SEEDING); } @@ -598,13 +596,13 @@ void tr_torrentSetQueuePosition(tr_torrent* tor, size_t queue_position) if ((old_pos < queue_position) && (old_pos <= walk->queuePosition) && (walk->queuePosition <= queue_position)) { walk->queuePosition--; - walk->markChanged(); + walk->mark_changed(); } if ((old_pos > queue_position) && (queue_position <= walk->queuePosition) && (walk->queuePosition < old_pos)) { walk->queuePosition++; - walk->markChanged(); + walk->mark_changed(); } if (current < walk->queuePosition + 1) @@ -614,7 +612,7 @@ void tr_torrentSetQueuePosition(tr_torrent* tor, size_t queue_position) } tor->queuePosition = std::min(queue_position, current); - tor->markChanged(); + tor->mark_changed(); TR_ASSERT(queueIsSequenced(tor->session)); } @@ -681,7 +679,7 @@ namespace start_stop_helpers { bool torrentShouldQueue(tr_torrent const* const tor) { - tr_direction const dir = tor->queueDirection(); + tr_direction const dir = tor->queue_direction(); return tor->session->countQueueFreeSlots(dir) == 0; } @@ -697,7 +695,7 @@ void torrentResetTransferStats(tr_torrent* tor) tor->corruptPrev += tor->corruptCur; tor->corruptCur = 0; - tor->setDirty(); + tor->set_dirty(); } void torrentStartImpl(tr_torrent* const tor) @@ -706,17 +704,17 @@ void torrentStartImpl(tr_torrent* const tor) TR_ASSERT(tr_isTorrent(tor)); - tor->recheckCompleteness(); + tor->recheck_completeness(); torrentSetQueued(tor, false); time_t const now = tr_time(); - tor->isRunning = true; + tor->is_running_ = true; tor->completeness = tor->completion.status(); tor->startDate = now; - tor->markChanged(); + tor->mark_changed(); tr_torrentClearError(tor); - tor->finishedSeedingByIdle = false; + tor->finished_seeding_by_idle_ = false; torrentResetTransferStats(tor); tor->session->announcer_->startTorrent(tor); @@ -733,7 +731,7 @@ void removeTorrentInSessionThread(tr_torrent* tor, bool delete_flag, tr_fileFunc { auto const lock = tor->unique_lock(); - if (delete_flag && tor->hasMetainfo()) + if (delete_flag && tor->has_metainfo()) { // ensure the files are all closed and idle before moving tor->session->closeTorrentFiles(tor); @@ -748,7 +746,7 @@ void removeTorrentInSessionThread(tr_torrent* tor, bool delete_flag, tr_fileFunc { delete_func(filename, user_data, nullptr); }; - tor->metainfo_.files().remove(tor->currentDir(), tor->name(), delete_func_wrapper); + tor->metainfo_.files().remove(tor->current_dir(), tor->name(), delete_func_wrapper); } tr_torrentFreeInSessionThread(tor); @@ -760,7 +758,7 @@ void freeTorrent(tr_torrent* tor) auto const lock = tor->unique_lock(); - TR_ASSERT(!tor->isRunning); + TR_ASSERT(!tor->is_running()); tr_session* session = tor->session; @@ -779,7 +777,7 @@ void freeTorrent(tr_torrent* tor) if (t->queuePosition > tor->queuePosition) { t->queuePosition--; - t->markChanged(); + t->mark_changed(); } } @@ -846,11 +844,11 @@ void torrentStart(tr_torrent* tor, torrent_start_opts opts) if (tr_torrentIsSeedRatioDone(tor)) { tr_logAddInfoTor(tor, _("Restarted manually -- disabling its seed ratio")); - tor->setRatioMode(TR_RATIOLIMIT_UNLIMITED); + tor->set_ratio_mode(TR_RATIOLIMIT_UNLIMITED); } - tor->isRunning = true; - tor->setDirty(); + tor->is_running_ = true; + tor->set_dirty(); tor->session->runInSessionThread(torrentStartImpl, tor); } @@ -860,8 +858,8 @@ void torrentStop(tr_torrent* const tor) TR_ASSERT(tor->session->amInSessionThread()); auto const lock = tor->unique_lock(); - tor->isRunning = false; - tor->isStopping = false; + tor->is_running_ = false; + tor->is_stopping_ = false; if (!tor->session->isClosing()) { @@ -875,7 +873,7 @@ void torrentStop(tr_torrent* const tor) tor->session->closeTorrentFiles(tor); - if (!tor->isDeleting) + if (!tor->is_deleting_) { tr_torrentSave(tor); } @@ -894,7 +892,7 @@ void tr_torrentStop(tr_torrent* tor) auto const lock = tor->unique_lock(); tor->start_when_stable = false; - tor->setDirty(); + tor->set_dirty(); tor->session->runInSessionThread(torrentStop, tor); } @@ -904,7 +902,7 @@ void tr_torrentRemove(tr_torrent* tor, bool delete_flag, tr_fileFunc delete_func TR_ASSERT(tr_isTorrent(tor)); - tor->isDeleting = true; + tor->is_deleting_ = true; tor->session->runInSessionThread(removeTorrentInSessionThread, tor, delete_flag, delete_func, user_data); } @@ -924,11 +922,11 @@ void tr_torrentFreeInSessionThread(tr_torrent* tor) torrentStop(tor); - if (tor->isDeleting) + if (tor->is_deleting_) { - tr_torrent_metainfo::removeFile(tor->session->torrentDir(), tor->name(), tor->infoHashString(), ".torrent"sv); - tr_torrent_metainfo::removeFile(tor->session->torrentDir(), tor->name(), tor->infoHashString(), ".magnet"sv); - tr_torrent_metainfo::removeFile(tor->session->resumeDir(), tor->name(), tor->infoHashString(), ".resume"sv); + tr_torrent_metainfo::remove_file(tor->session->torrentDir(), tor->name(), tor->info_hash_string(), ".torrent"sv); + tr_torrent_metainfo::remove_file(tor->session->torrentDir(), tor->name(), tor->info_hash_string(), ".magnet"sv); + tr_torrent_metainfo::remove_file(tor->session->resumeDir(), tor->name(), tor->info_hash_string(), ".resume"sv); } freeTorrent(tor); @@ -943,15 +941,15 @@ namespace torrent_init_helpers // Sniff out newly-added seeds so that they can skip the verify step bool isNewTorrentASeed(tr_torrent* tor) { - if (!tor->hasMetainfo()) + if (!tor->has_metainfo()) { return false; } - for (tr_file_index_t i = 0, n = tor->fileCount(); i < n; ++i) + for (tr_file_index_t i = 0, n = tor->file_count(); i < n; ++i) { // it's not a new seed if a file is missing - auto const found = tor->findFile(i); + auto const found = tor->find_file(i); if (!found) { return false; @@ -964,7 +962,7 @@ bool isNewTorrentASeed(tr_torrent* tor) } // it's not a new seed if a file size is wrong - if (found->size != tor->fileSize(i)) + if (found->size != tor->file_size(i)) { return false; } @@ -977,24 +975,24 @@ bool isNewTorrentASeed(tr_torrent* tor) } // check the first piece - return tor->ensurePieceIsChecked(0); + return tor->ensure_piece_is_checked(0); } void torrentInitFromInfoDict(tr_torrent* tor) { - tor->completion = tr_completion{ tor, &tor->blockInfo() }; - tor->obfuscated_hash = tr_sha1::digest("req2"sv, tor->infoHash()); + tor->completion = tr_completion{ tor, &tor->block_info() }; + tor->obfuscated_hash = tr_sha1::digest("req2"sv, tor->info_hash()); tor->fpm_.reset(tor->metainfo_); - tor->file_mtimes_.resize(tor->fileCount()); + tor->file_mtimes_.resize(tor->file_count()); tor->file_priorities_.reset(&tor->fpm_); tor->files_wanted_.reset(&tor->fpm_); - tor->checked_pieces_ = tr_bitfield{ size_t(tor->pieceCount()) }; + tor->checked_pieces_ = tr_bitfield{ size_t(tor->piece_count()) }; } void on_metainfo_completed(tr_torrent* tor) { // we can look for files now that we know what files are in the torrent - tor->refreshCurrentDir(); + tor->refresh_current_dir(); callScriptIfEnabled(tor, TR_SCRIPT_ON_TORRENT_ADDED); @@ -1004,15 +1002,15 @@ void on_metainfo_completed(tr_torrent* tor) } else { - tor->completion.setHasAll(); + tor->completion.set_has_all(); tor->doneDate = tor->addedDate; - tor->recheckCompleteness(); + tor->recheck_completeness(); if (tor->start_when_stable) { torrentStart(tor, {}); } - else if (tor->isRunning) + else if (tor->is_running()) { tr_torrentStop(tor); } @@ -1034,7 +1032,7 @@ void torrentInit(tr_torrent* tor, tr_ctor const* ctor) char const* dir = nullptr; if (tr_ctorGetDownloadDir(ctor, TR_FORCE, &dir) || tr_ctorGetDownloadDir(ctor, TR_FALLBACK, &dir)) { - tor->download_dir = dir; + tor->download_dir_ = dir; } if (!tr_ctorGetIncompleteDir(ctor, &dir)) @@ -1044,12 +1042,12 @@ void torrentInit(tr_torrent* tor, tr_ctor const* ctor) if (tr_sessionIsIncompleteDirEnabled(session)) { - tor->incomplete_dir = dir; + tor->incomplete_dir_ = dir; } - tor->bandwidth_.setParent(&session->top_bandwidth_); - tor->bandwidth_.setPriority(tr_ctorGetBandwidthPriority(ctor)); + tor->bandwidth_.set_parent(&session->top_bandwidth_); + tor->bandwidth_.set_priority(tr_ctorGetBandwidthPriority(ctor)); tor->error = TR_STAT_OK; - tor->finishedSeedingByIdle = false; + tor->finished_seeding_by_idle_ = false; auto const& labels = tr_ctorGetLabels(ctor); tor->setLabels(labels); @@ -1070,10 +1068,10 @@ void torrentInit(tr_torrent* tor, tr_ctor const* ctor) // that set things as dirty, but... these settings being loaded are // the same ones that would be saved back again, so don't let them // affect the 'is dirty' flag. - auto const was_dirty = tor->isDirty; + auto const was_dirty = tor->is_dirty_; loaded = tr_resume::load(tor, tr_resume::All, ctor); - tor->isDirty = was_dirty; - tr_torrent_metainfo::migrateFile(session->torrentDir(), tor->name(), tor->infoHashString(), ".torrent"sv); + tor->is_dirty_ = was_dirty; + tr_torrent_metainfo::migrate_file(session->torrentDir(), tor->name(), tor->info_hash_string(), ".torrent"sv); } tor->completeness = tor->completion.status(); @@ -1081,27 +1079,27 @@ void torrentInit(tr_torrent* tor, tr_ctor const* ctor) tr_ctorInitTorrentPriorities(ctor, tor); tr_ctorInitTorrentWanted(ctor, tor); - tor->refreshCurrentDir(); + tor->refresh_current_dir(); if ((loaded & tr_resume::Speedlimit) == 0) { - tor->useSpeedLimit(TR_UP, false); - tor->setSpeedLimitBps(TR_UP, tr_toSpeedBytes(tor->session->speedLimitKBps(TR_UP))); - tor->useSpeedLimit(TR_DOWN, false); - tor->setSpeedLimitBps(TR_DOWN, tr_toSpeedBytes(tor->session->speedLimitKBps(TR_DOWN))); + tor->use_speed_limit(TR_UP, false); + tor->set_speed_limit_bps(TR_UP, tr_toSpeedBytes(tor->session->speedLimitKBps(TR_UP))); + tor->use_speed_limit(TR_DOWN, false); + tor->set_speed_limit_bps(TR_DOWN, tr_toSpeedBytes(tor->session->speedLimitKBps(TR_DOWN))); tr_torrentUseSessionLimits(tor, true); } if ((loaded & tr_resume::Ratiolimit) == 0) { - tor->setRatioMode(TR_RATIOLIMIT_GLOBAL); + tor->set_ratio_mode(TR_RATIOLIMIT_GLOBAL); tr_torrentSetRatioLimit(tor, tor->session->desiredRatio()); } if ((loaded & tr_resume::Idlelimit) == 0) { tr_torrentSetIdleMode(tor, TR_IDLELIMIT_GLOBAL); - tor->setIdleLimit(tor->session->idleLimitMinutes()); + tor->set_idle_limit(tor->session->idleLimitMinutes()); } auto has_local_data = std::optional{}; @@ -1115,7 +1113,7 @@ void torrentInit(tr_torrent* tor, tr_ctor const* ctor) [](auto mtime) { return mtime > 0; }); } - auto const filename = tor->hasMetainfo() ? tor->torrentFile() : tor->magnetFile(); + auto const filename = tor->has_metainfo() ? tor->torrent_file() : tor->magnet_file(); // if we don't have a local .torrent or .magnet file already, // assume the torrent is new @@ -1125,7 +1123,7 @@ void torrentInit(tr_torrent* tor, tr_ctor const* ctor) { tr_error* error = nullptr; - if (tor->hasMetainfo()) // torrent file + if (tor->has_metainfo()) // torrent file { tr_ctorSaveContents(ctor, filename, &error); } @@ -1137,7 +1135,7 @@ void torrentInit(tr_torrent* tor, tr_ctor const* ctor) if (error != nullptr) { - tor->setLocalError(fmt::format( + tor->set_local_error(fmt::format( _("Couldn't save '{path}': {error} ({error_code})"), fmt::arg("path", filename), fmt::arg("error", error->message), @@ -1146,9 +1144,9 @@ void torrentInit(tr_torrent* tor, tr_ctor const* ctor) } } - tor->torrent_announcer = session->announcer_->addTorrent(tor, &tr_torrent::onTrackerResponse); + tor->torrent_announcer = session->announcer_->addTorrent(tor, &tr_torrent::on_tracker_response); - if (auto const has_metainfo = tor->hasMetainfo(); is_new_torrent && has_metainfo) + if (auto const has_metainfo = tor->has_metainfo(); is_new_torrent && has_metainfo) { on_metainfo_completed(tor); } @@ -1167,18 +1165,18 @@ void torrentInit(tr_torrent* tor, tr_ctor const* ctor) } // namespace torrent_init_helpers } // namespace -void tr_torrent::setMetainfo(tr_torrent_metainfo tm) +void tr_torrent::set_metainfo(tr_torrent_metainfo tm) { using namespace torrent_init_helpers; - TR_ASSERT(!hasMetainfo()); + TR_ASSERT(!has_metainfo()); metainfo_ = std::move(tm); torrentInitFromInfoDict(this); tr_peerMgrOnTorrentGotMetainfo(this); session->onMetadataCompleted(this); - this->setDirty(); - this->markEdited(); + this->set_dirty(); + this->mark_edited(); on_metainfo_completed(this); } @@ -1193,13 +1191,13 @@ tr_torrent* tr_torrentNew(tr_ctor* ctor, tr_torrent** setme_duplicate_of) // is the metainfo valid? auto metainfo = tr_ctorStealMetainfo(ctor); - if (std::empty(metainfo.infoHashString())) + if (std::empty(metainfo.info_hash_string())) { return nullptr; } // is it a duplicate? - if (auto* const duplicate_of = session->torrents().get(metainfo.infoHash()); duplicate_of != nullptr) + if (auto* const duplicate_of = session->torrents().get(metainfo.info_hash()); duplicate_of != nullptr) { if (setme_duplicate_of != nullptr) { @@ -1243,12 +1241,12 @@ void setLocationInSessionThread( tor->session->verifyRemove(tor); tr_error* error = nullptr; - ok = tor->metainfo_.files().move(tor->currentDir(), path, setme_progress, tor->name(), &error); + ok = tor->metainfo_.files().move(tor->current_dir(), path, setme_progress, tor->name(), &error); if (error != nullptr) { - tor->setLocalError(fmt::format( + tor->set_local_error(fmt::format( _("Couldn't move '{old_path}' to '{path}': {error} ({error_code})"), - fmt::arg("old_path", tor->currentDir()), + fmt::arg("old_path", tor->current_dir()), fmt::arg("path", path), fmt::arg("error", error->message), fmt::arg("error_code", error->code))); @@ -1260,12 +1258,12 @@ void setLocationInSessionThread( // tell the torrent where the files are if (ok) { - tor->setDownloadDir(path); + tor->set_download_dir(path); if (move_from_old_path) { - tor->incomplete_dir.clear(); - tor->current_dir = tor->downloadDir(); + tor->incomplete_dir_.clear(); + tor->current_dir_ = tor->download_dir(); } } @@ -1278,12 +1276,12 @@ size_t buildSearchPathArray(tr_torrent const* tor, std::string_view* paths) { auto* walk = paths; - if (auto const& path = tor->downloadDir(); !std::empty(path)) + if (auto const& path = tor->download_dir(); !std::empty(path)) { *walk++ = path.sv(); } - if (auto const& path = tor->incompleteDir(); !std::empty(path)) + if (auto const& path = tor->incomplete_dir(); !std::empty(path)) { *walk++ = path.sv(); } @@ -1293,7 +1291,7 @@ size_t buildSearchPathArray(tr_torrent const* tor, std::string_view* paths) } // namespace location_helpers } // namespace -void tr_torrent::setLocation( +void tr_torrent::set_location( std::string_view location, bool move_from_old_path, double volatile* setme_progress, @@ -1325,10 +1323,10 @@ void tr_torrentSetLocation( TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(!tr_str_is_empty(location)); - tor->setLocation(location, move_from_old_path, setme_progress, setme_state); + tor->set_location(location, move_from_old_path, setme_progress, setme_state); } -std::optional tr_torrent::findFile(tr_file_index_t file_index) const +std::optional tr_torrent::find_file(tr_file_index_t file_index) const { using namespace location_helpers; @@ -1337,7 +1335,7 @@ std::optional tr_torrent::findFile(tr_file_index_t return metainfo_.files().find(file_index, std::data(paths), n_paths); } -bool tr_torrent::hasAnyLocalData() const +bool tr_torrent::has_any_local_data() const { using namespace location_helpers; @@ -1350,9 +1348,9 @@ void tr_torrentSetDownloadDir(tr_torrent* tor, char const* path) { TR_ASSERT(tr_isTorrent(tor)); - if (tor->download_dir != path) + if (tor->download_dir_ != path) { - tor->setDownloadDir(path, true); + tor->set_download_dir(path, true); } } @@ -1360,21 +1358,21 @@ char const* tr_torrentGetDownloadDir(tr_torrent const* tor) { TR_ASSERT(tr_isTorrent(tor)); - return tor->downloadDir().c_str(); + return tor->download_dir().c_str(); } char const* tr_torrentGetCurrentDir(tr_torrent const* tor) { TR_ASSERT(tr_isTorrent(tor)); - return tor->currentDir().c_str(); + return tor->current_dir().c_str(); } void tr_torrentChangeMyPort(tr_torrent* tor) { TR_ASSERT(tr_isTorrent(tor)); - if (tor->isRunning) + if (tor->is_running()) { tr_announcerChangeMyPort(tor); } @@ -1390,7 +1388,7 @@ void torrentManualUpdateImpl(tr_torrent* const tor) { TR_ASSERT(tr_isTorrent(tor)); - if (tor->isRunning) + if (tor->is_running()) { tr_announcerManualAnnounce(tor); } @@ -1409,7 +1407,7 @@ void tr_torrentManualUpdate(tr_torrent* tor) bool tr_torrentCanManualUpdate(tr_torrent const* tor) { - return tr_isTorrent(tor) && tor->isRunning && tr_announcerCanManualAnnounce(tor); + return tr_isTorrent(tor) && tor->is_running() && tr_announcerCanManualAnnounce(tor); } // --- @@ -1469,36 +1467,36 @@ tr_stat const* tr_torrentStat(tr_torrent* tor) s->peersFrom[i] = swarm_stats.peer_from_count[i]; } - auto const piece_upload_speed_bytes_per_second = tor->bandwidth_.getPieceSpeedBytesPerSecond(now, TR_UP); + auto const piece_upload_speed_bytes_per_second = tor->bandwidth_.get_piece_speed_bytes_per_second(now, TR_UP); s->pieceUploadSpeed_KBps = tr_toSpeedKBps(piece_upload_speed_bytes_per_second); - auto const piece_download_speed_bytes_per_second = tor->bandwidth_.getPieceSpeedBytesPerSecond(now, TR_DOWN); + auto const piece_download_speed_bytes_per_second = tor->bandwidth_.get_piece_speed_bytes_per_second(now, TR_DOWN); s->pieceDownloadSpeed_KBps = tr_toSpeedKBps(piece_download_speed_bytes_per_second); - s->percentComplete = tor->completion.percentComplete(); + s->percentComplete = tor->completion.percent_complete(); s->metadataPercentComplete = tr_torrentGetMetadataPercent(tor); - s->percentDone = tor->completion.percentDone(); - s->leftUntilDone = tor->completion.leftUntilDone(); - s->sizeWhenDone = tor->completion.sizeWhenDone(); + s->percentDone = tor->completion.percent_done(); + s->leftUntilDone = tor->completion.left_until_done(); + s->sizeWhenDone = tor->completion.size_when_done(); - auto const verify_progress = tor->verifyProgress(); + auto const verify_progress = tor->verify_progress(); s->recheckProgress = verify_progress.value_or(0.0); s->activityDate = tor->activityDate; s->addedDate = tor->addedDate; s->doneDate = tor->doneDate; s->editDate = tor->editDate; s->startDate = tor->startDate; - s->secondsSeeding = tor->secondsSeeding(now_sec); - s->secondsDownloading = tor->secondsDownloading(now_sec); + s->secondsSeeding = tor->seconds_seeding(now_sec); + s->secondsDownloading = tor->seconds_downloading(now_sec); s->corruptEver = tor->corruptCur + tor->corruptPrev; s->downloadedEver = tor->downloadedCur + tor->downloadedPrev; s->uploadedEver = tor->uploadedCur + tor->uploadedPrev; - s->haveValid = tor->completion.hasValid(); - s->haveUnchecked = tor->hasTotal() - s->haveValid; + s->haveValid = tor->completion.has_valid(); + s->haveUnchecked = tor->has_total() - s->haveValid; s->desiredAvailable = tr_peerMgrGetDesiredAvailable(tor); - s->ratio = tr_getRatio(s->uploadedEver, tor->sizeWhenDone()); + s->ratio = tr_getRatio(s->uploadedEver, tor->size_when_done()); auto seed_ratio_bytes_left = uint64_t{}; auto seed_ratio_bytes_goal = uint64_t{}; @@ -1519,7 +1517,7 @@ tr_stat const* tr_torrentStat(tr_torrent* tor) tor->etaSpeedCalculatedAt = now; } - if (s->leftUntilDone > s->desiredAvailable && tor->webseedCount() < 1) + if (s->leftUntilDone > s->desiredAvailable && tor->webseed_count() < 1) { s->eta = TR_ETA_NOT_AVAIL; } @@ -1577,7 +1575,7 @@ tr_stat const* tr_torrentStat(tr_torrent* tor) /* s->haveValid is here to make sure a torrent isn't marked 'finished' * when the user hits "uncheck all" prior to starting the torrent... */ - s->finished = tor->finishedSeedingByIdle || (seed_ratio_applies && seed_ratio_bytes_left == 0 && s->haveValid != 0); + s->finished = tor->finished_seeding_by_idle_ || (seed_ratio_applies && seed_ratio_bytes_left == 0 && s->haveValid != 0); if (!seed_ratio_applies || s->finished) { @@ -1593,7 +1591,7 @@ tr_stat const* tr_torrentStat(tr_torrent* tor) } /* test some of the constraints */ - TR_ASSERT(s->sizeWhenDone <= tor->totalSize()); + TR_ASSERT(s->sizeWhenDone <= tor->total_size()); TR_ASSERT(s->leftUntilDone <= s->sizeWhenDone); TR_ASSERT(s->desiredAvailable <= s->leftUntilDone); @@ -1613,17 +1611,17 @@ tr_file_view tr_torrentFile(tr_torrent const* tor, tr_file_index_t file) { TR_ASSERT(tr_isTorrent(tor)); - auto const& subpath = tor->fileSubpath(file); - auto const priority = tor->file_priorities_.filePriority(file); - auto const wanted = tor->files_wanted_.fileWanted(file); - auto const length = tor->fileSize(file); + auto const& subpath = tor->file_subpath(file); + auto const priority = tor->file_priorities_.file_priority(file); + auto const wanted = tor->files_wanted_.file_wanted(file); + auto const length = tor->file_size(file); if (tor->completeness == TR_SEED || length == 0) { return { subpath.c_str(), length, length, 1.0, priority, wanted }; } - auto const have = tor->completion.countHasBytesInSpan(tor->fpm_.byteSpan(file)); + auto const have = tor->completion.count_has_bytes_in_span(tor->fpm_.byte_span(file)); return { subpath.c_str(), have, length, have >= length ? 1.0 : have / double(length), priority, wanted }; } @@ -1631,7 +1629,7 @@ size_t tr_torrentFileCount(tr_torrent const* torrent) { TR_ASSERT(tr_isTorrent(torrent)); - return torrent->fileCount(); + return torrent->file_count(); } tr_webseed_view tr_torrentWebseed(tr_torrent const* tor, size_t nth) @@ -1643,7 +1641,7 @@ size_t tr_torrentWebseedCount(tr_torrent const* tor) { TR_ASSERT(tr_isTorrent(tor)); - return tor->webseedCount(); + return tor->webseed_count(); } tr_tracker_view tr_torrentTracker(tr_torrent const* tor, size_t i) @@ -1662,23 +1660,23 @@ tr_torrent_view tr_torrentView(tr_torrent const* tor) auto ret = tr_torrent_view{}; ret.name = tr_torrentName(tor); - ret.hash_string = tor->infoHashString().c_str(); + ret.hash_string = tor->info_hash_string().c_str(); ret.comment = tor->comment().c_str(); ret.creator = tor->creator().c_str(); ret.source = tor->source().c_str(); - ret.total_size = tor->totalSize(); - ret.date_created = tor->dateCreated(); - ret.piece_size = tor->pieceSize(); - ret.n_pieces = tor->pieceCount(); - ret.is_private = tor->isPrivate(); - ret.is_folder = tor->fileCount() > 1 || (tor->fileCount() == 1 && tr_strvContains(tor->fileSubpath(0), '/')); + ret.total_size = tor->total_size(); + ret.date_created = tor->date_created(); + ret.piece_size = tor->piece_size(); + ret.n_pieces = tor->piece_count(); + ret.is_private = tor->is_private(); + ret.is_folder = tor->file_count() > 1 || (tor->file_count() == 1 && tr_strvContains(tor->file_subpath(0), '/')); return ret; } std::string tr_torrentFilename(tr_torrent const* tor) { - return std::string{ tor->torrentFile() }; + return std::string{ tor->torrent_file() }; } size_t tr_torrentFilenameToBuf(tr_torrent const* tor, char* buf, size_t buflen) @@ -1712,7 +1710,7 @@ void tr_torrentAvailability(tr_torrent const* tor, int8_t* tab, int size) void tr_torrentAmountFinished(tr_torrent const* tor, float* tabs, int n_tabs) { - return tor->amountDoneBins(tabs, n_tabs); + return tor->amount_done_bins(tabs, n_tabs); } // --- Start/Stop Callback @@ -1758,17 +1756,17 @@ void onVerifyDoneThreadFunc(tr_torrent* const tor) { TR_ASSERT(tor->session->amInSessionThread()); - if (tor->isDeleting) + if (tor->is_deleting_) { return; } - tor->recheckCompleteness(); + tor->recheck_completeness(); if (tor->start_when_stable) { auto opts = torrent_start_opts{}; - opts.has_local_data = !tor->checked_pieces_.hasNone(); + opts.has_local_data = !tor->checked_pieces_.has_none(); torrentStart(tor, opts); } } @@ -1778,7 +1776,7 @@ void verifyTorrent(tr_torrent* const tor) TR_ASSERT(tor->session->amInSessionThread()); auto const lock = tor->unique_lock(); - if (tor->isDeleting) + if (tor->is_deleting_) { return; } @@ -1786,12 +1784,12 @@ void verifyTorrent(tr_torrent* const tor) /* if the torrent's already being verified, stop it */ tor->session->verifyRemove(tor); - if (!tor->hasMetainfo()) + if (!tor->has_metainfo()) { return; } - if (tor->isRunning) + if (tor->is_running()) { torrentStop(tor); } @@ -1808,7 +1806,7 @@ void tr_torrentOnVerifyDone(tr_torrent* tor, bool aborted) { using namespace verify_helpers; - if (aborted || tor->isDeleting) + if (aborted || tor->is_deleting_) { return; } @@ -1823,13 +1821,13 @@ void tr_torrentVerify(tr_torrent* tor) tor->session->runInSessionThread(verifyTorrent, tor); } -void tr_torrent::setVerifyState(tr_verify_state state) +void tr_torrent::set_verify_state(tr_verify_state state) { TR_ASSERT(state == TR_VERIFY_NONE || state == TR_VERIFY_WAIT || state == TR_VERIFY_NOW); this->verify_state_ = state; this->verify_progress_ = {}; - this->markChanged(); + this->mark_changed(); } // --- @@ -1838,9 +1836,9 @@ void tr_torrentSave(tr_torrent* tor) { TR_ASSERT(tr_isTorrent(tor)); - if (tor->isDirty) + if (tor->is_dirty_) { - tor->isDirty = false; + tor->is_dirty_ = false; tr_resume::save(tor); } } @@ -1873,7 +1871,7 @@ namespace completeness_helpers } // namespace completeness_helpers } // namespace -void tr_torrent::recheckCompleteness() +void tr_torrent::recheck_completeness() { using namespace completeness_helpers; @@ -1886,8 +1884,8 @@ void tr_torrent::recheckCompleteness() if (new_completeness != completeness) { bool const recent_change = downloadedCur != 0; - bool const was_leeching = !this->isDone(); - bool const was_running = isRunning; + bool const was_leeching = !this->is_done(); + bool const was_running = is_running(); if (recent_change) { @@ -1902,12 +1900,12 @@ void tr_torrent::recheckCompleteness() this->completeness = new_completeness; this->session->closeTorrentFiles(this); - if (this->isDone()) + if (this->is_done()) { if (recent_change) { tr_announcerTorrentCompleted(this); - this->markChanged(); + this->mark_changed(); this->doneDate = tr_time(); } @@ -1917,24 +1915,24 @@ void tr_torrent::recheckCompleteness() tr_peerMgrClearInterest(this); } - if (this->currentDir() == this->incompleteDir()) + if (this->current_dir() == this->incomplete_dir()) { - this->setLocation(this->downloadDir(), true, nullptr, nullptr); + this->set_location(this->download_dir(), true, nullptr, nullptr); } } this->session->onTorrentCompletenessChanged(this, completeness, was_running); - if (this->isDone() && was_leeching && was_running) + if (this->is_done() && was_leeching && was_running) { /* if completeness was TR_LEECH, the seed limit check will have been skipped in bandwidthPulse */ tr_torrentCheckSeedLimit(this); } - this->setDirty(); + this->set_dirty(); - if (this->isDone()) + if (this->is_done()) { tr_torrentSave(this); callScriptIfEnabled(this, TR_SCRIPT_ON_TORRENT_DONE); @@ -1948,7 +1946,7 @@ void tr_torrentSetFileDLs(tr_torrent* tor, tr_file_index_t const* files, tr_file { TR_ASSERT(tr_isTorrent(tor)); - tor->setFilesWanted(files, n_files, wanted); + tor->set_files_wanted(files, n_files, wanted); } // --- @@ -1966,12 +1964,12 @@ void tr_torrent::setLabels(std::vector const& new_labels) } } this->labels.shrink_to_fit(); - this->setDirty(); + this->set_dirty(); } // --- -void tr_torrent::setBandwidthGroup(std::string_view group_name) noexcept +void tr_torrent::set_bandwidth_group(std::string_view group_name) noexcept { group_name = tr_strvStrip(group_name); @@ -1980,15 +1978,15 @@ void tr_torrent::setBandwidthGroup(std::string_view group_name) noexcept if (std::empty(group_name)) { this->bandwidth_group_ = tr_interned_string{}; - this->bandwidth_.setParent(&this->session->top_bandwidth_); + this->bandwidth_.set_parent(&this->session->top_bandwidth_); } else { this->bandwidth_group_ = group_name; - this->bandwidth_.setParent(&this->session->getBandwidthGroup(group_name)); + this->bandwidth_.set_parent(&this->session->getBandwidthGroup(group_name)); } - this->setDirty(); + this->set_dirty(); } // --- @@ -1997,7 +1995,7 @@ tr_priority_t tr_torrentGetPriority(tr_torrent const* tor) { TR_ASSERT(tr_isTorrent(tor)); - return tor->getPriority(); + return tor->get_priority(); } void tr_torrentSetPriority(tr_torrent* tor, tr_priority_t priority) @@ -2005,11 +2003,11 @@ void tr_torrentSetPriority(tr_torrent* tor, tr_priority_t priority) TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(tr_isPriority(priority)); - if (tor->bandwidth_.getPriority() != priority) + if (tor->bandwidth_.get_priority() != priority) { - tor->bandwidth_.setPriority(priority); + tor->bandwidth_.set_priority(priority); - tor->setDirty(); + tor->set_dirty(); } } @@ -2023,7 +2021,7 @@ void tr_torrentSetPeerLimit(tr_torrent* tor, uint16_t max_connected_peers) { tor->max_connected_peers_ = max_connected_peers; - tor->setDirty(); + tor->set_dirty(); } } @@ -2031,7 +2029,7 @@ uint16_t tr_torrentGetPeerLimit(tr_torrent const* tor) { TR_ASSERT(tr_isTorrent(tor)); - return tor->peerLimit(); + return tor->peer_limit(); } // --- @@ -2042,7 +2040,7 @@ bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_ int err = 0; - if (index >= tor->pieceCount()) + if (index >= tor->piece_count()) { err = 1; } @@ -2050,7 +2048,7 @@ bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_ { err = 2; } - else if (offset + length > tor->pieceSize(index)) + else if (offset + length > tor->piece_size(index)) { err = 3; } @@ -2058,7 +2056,7 @@ bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_ { err = 4; } - else if (tor->pieceLoc(index, offset, length).byte > tor->totalSize()) + else if (tor->piece_loc(index, offset, length).byte > tor->total_size()) { err = 5; } @@ -2074,15 +2072,15 @@ bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_ // TODO(ckerr) migrate to fpm? tr_block_span_t tr_torGetFileBlockSpan(tr_torrent const* tor, tr_file_index_t file) { - auto const [begin_byte, end_byte] = tor->fpm_.byteSpan(file); + auto const [begin_byte, end_byte] = tor->fpm_.byte_span(file); - auto const begin_block = tor->byteLoc(begin_byte).block; + auto const begin_block = tor->byte_loc(begin_byte).block; if (begin_byte >= end_byte) // 0-byte file { return { begin_block, begin_block + 1 }; } - auto const final_block = tor->byteLoc(end_byte - 1).block; + auto const final_block = tor->byte_loc(end_byte - 1).block; auto const end_block = final_block + 1; return { begin_block, end_block }; } @@ -2090,7 +2088,7 @@ tr_block_span_t tr_torGetFileBlockSpan(tr_torrent const* tor, tr_file_index_t fi // --- // TODO: should be const after tr_ioTestPiece() is const -bool tr_torrent::checkPiece(tr_piece_index_t piece) +bool tr_torrent::check_piece(tr_piece_index_t piece) { bool const pass = tr_ioTestPiece(this, piece); tr_logAddTraceTor(this, fmt::format("[LAZY] tr_torrent.checkPiece tested piece {}, pass=={}", piece, pass)); @@ -2099,7 +2097,7 @@ bool tr_torrent::checkPiece(tr_piece_index_t piece) // --- -bool tr_torrent::setTrackerList(std::string_view text) +bool tr_torrent::set_tracker_list(std::string_view text) { auto const lock = this->unique_lock(); @@ -2109,24 +2107,24 @@ bool tr_torrent::setTrackerList(std::string_view text) return false; } - auto const has_metadata = this->hasMetainfo(); - if (has_metadata && !announce_list.save(torrentFile())) + auto const has_metadata = this->has_metainfo(); + if (has_metadata && !announce_list.save(torrent_file())) { return false; } - this->metainfo_.announceList() = announce_list; - this->markEdited(); + this->metainfo_.announce_list() = announce_list; + this->mark_edited(); // magnet links if (!has_metadata) { - auto const magnet_file = magnetFile(); + auto const magnet_file = this->magnet_file(); auto const magnet_link = this->magnet(); tr_error* save_error = nullptr; if (!tr_saveFile(magnet_file, magnet_link, &save_error)) { - this->setLocalError(fmt::format( + this->set_local_error(fmt::format( _("Couldn't save '{path}': {error} ({error_code})"), fmt::arg("path", magnet_file), fmt::arg("error", save_error->message), @@ -2143,8 +2141,8 @@ bool tr_torrent::setTrackerList(std::string_view text) auto const error_url = this->error_announce_url; if (std::any_of( - std::begin(this->announceList()), - std::end(this->announceList()), + std::begin(this->announce_list()), + std::end(this->announce_list()), [error_url](auto const& tracker) { return tracker.announce == error_url; })) { tr_torrentClearError(this); @@ -2156,7 +2154,7 @@ bool tr_torrent::setTrackerList(std::string_view text) return true; } -void tr_torrent::onTrackerResponse(tr_tracker_event const* event) +void tr_torrent::on_tracker_response(tr_tracker_event const* event) { switch (event->type) { @@ -2166,7 +2164,7 @@ void tr_torrent::onTrackerResponse(tr_tracker_event const* event) break; case tr_tracker_event::Type::Counts: - if (isPrivate() && (event->leechers == 0)) + if (is_private() && (event->leechers == 0)) { tr_peerMgrSetSwarmIsAllSeeds(this); } @@ -2201,12 +2199,12 @@ void tr_torrent::onTrackerResponse(tr_tracker_event const* event) bool tr_torrentSetTrackerList(tr_torrent* tor, char const* text) { - return text != nullptr && tor->setTrackerList(text); + return text != nullptr && tor->set_tracker_list(text); } std::string tr_torrentGetTrackerList(tr_torrent const* tor) { - return tor->trackerList(); + return tor->tracker_list(); } size_t tr_torrentGetTrackerListToBuf(tr_torrent const* tor, char* buf, size_t buflen) @@ -2222,17 +2220,17 @@ uint64_t tr_torrentGetBytesLeftToAllocate(tr_torrent const* tor) uint64_t bytes_left = 0; - for (tr_file_index_t i = 0, n = tor->fileCount(); i < n; ++i) + for (tr_file_index_t i = 0, n = tor->file_count(); i < n; ++i) { - if (auto const wanted = tor->files_wanted_.fileWanted(i); !wanted) + if (auto const wanted = tor->files_wanted_.file_wanted(i); !wanted) { continue; } - auto const length = tor->fileSize(i); + auto const length = tor->file_size(i); bytes_left += length; - auto const found = tor->findFile(i); + auto const found = tor->find_file(i); if (found) { bytes_left -= found->size; @@ -2244,16 +2242,16 @@ uint64_t tr_torrentGetBytesLeftToAllocate(tr_torrent const* tor) // --- -std::string_view tr_torrent::primaryMimeType() const +std::string_view tr_torrent::primary_mime_type() const { // count up how many bytes there are for each mime-type in the torrent // NB: get_mime_type_for_filename() always returns the same ptr for a // mime_type, so its raw pointer can be used as a key. auto size_per_mime_type = std::unordered_map{}; - for (tr_file_index_t i = 0, n = this->fileCount(); i < n; ++i) + for (tr_file_index_t i = 0, n = this->file_count(); i < n; ++i) { - auto const mime_type = tr_get_mime_type_for_filename(this->fileSubpath(i)); - size_per_mime_type[mime_type] += this->fileSize(i); + auto const mime_type = tr_get_mime_type_for_filename(this->file_subpath(i)); + size_per_mime_type[mime_type] += this->file_size(i); } if (std::empty(size_per_mime_type)) @@ -2290,9 +2288,9 @@ void onFileCompleted(tr_torrent* tor, tr_file_index_t i) /* if the torrent's current filename isn't the same as the one in the * metadata -- for example, if it had the ".part" suffix appended to * it until now -- then rename it to match the one in the metadata */ - if (auto found = tor->findFile(i); found) + if (auto found = tor->find_file(i); found) { - if (auto const& file_subpath = tor->fileSubpath(i); file_subpath != found->subpath()) + if (auto const& file_subpath = tor->file_subpath(i); file_subpath != found->subpath()) { auto const& oldpath = found->filename(); auto const newpath = tr_pathbuf{ found->base(), '/', file_subpath }; @@ -2319,10 +2317,10 @@ void onPieceCompleted(tr_torrent* tor, tr_piece_index_t piece) tr_peerMgrPieceCompleted(tor, piece); // if this piece completes any file, invoke the fileCompleted func for it - auto const span = tor->fpm_.fileSpan(piece); + auto const span = tor->fpm_.file_span(piece); for (auto file = span.begin; file < span.end; ++file) { - if (tor->completion.hasBlocks(tr_torGetFileBlockSpan(tor, file))) + if (tor->completion.has_blocks(tr_torGetFileBlockSpan(tor, file))) { onFileCompleted(tor, file); } @@ -2333,11 +2331,11 @@ void onPieceFailed(tr_torrent* tor, tr_piece_index_t piece) { tr_logAddDebugTor(tor, fmt::format("Piece {}, which was just downloaded, failed its checksum test", piece)); - auto const n = tor->pieceSize(piece); + auto const n = tor->piece_size(piece); tor->corruptCur += n; tor->downloadedCur -= std::min(tor->downloadedCur, uint64_t{ n }); tr_peerMgrGotBadPiece(tor, piece); - tor->setHasPiece(piece, false); + tor->set_has_piece(piece, false); } } // namespace got_block_helpers } // namespace @@ -2349,29 +2347,29 @@ void tr_torrentGotBlock(tr_torrent* tor, tr_block_index_t block) TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(tor->session->amInSessionThread()); - if (tor->hasBlock(block)) + if (tor->has_block(block)) { tr_logAddDebugTor(tor, "we have this block already..."); - auto const n = tor->blockSize(block); + auto const n = tor->block_size(block); tor->downloadedCur -= std::min(tor->downloadedCur, uint64_t{ n }); return; } - tor->setDirty(); + tor->set_dirty(); - tor->completion.addBlock(block); + tor->completion.add_block(block); - auto const block_loc = tor->blockLoc(block); + auto const block_loc = tor->block_loc(block); auto const first_piece = block_loc.piece; - auto const last_piece = tor->byteLoc(block_loc.byte + tor->blockSize(block) - 1).piece; + auto const last_piece = tor->byte_loc(block_loc.byte + tor->block_size(block) - 1).piece; for (auto piece = first_piece; piece <= last_piece; ++piece) { - if (!tor->hasPiece(piece)) + if (!tor->has_piece(piece)) { continue; } - if (tor->checkPiece(piece)) + if (tor->check_piece(piece)) { onPieceCompleted(tor, piece); } @@ -2386,7 +2384,7 @@ void tr_torrentGotBlock(tr_torrent* tor, tr_block_index_t block) std::string tr_torrentFindFile(tr_torrent const* tor, tr_file_index_t file_num) { - auto const found = tor->findFile(file_num); + auto const found = tor->find_file(file_num); return std::string{ found ? found->filename().sv() : ""sv }; } @@ -2395,12 +2393,12 @@ size_t tr_torrentFindFileToBuf(tr_torrent const* tor, tr_file_index_t file_num, return tr_strvToBuf(tr_torrentFindFile(tor, file_num), buf, buflen); } -void tr_torrent::setDownloadDir(std::string_view path, bool is_new_torrent) +void tr_torrent::set_download_dir(std::string_view path, bool is_new_torrent) { - download_dir = path; - markEdited(); - setDirty(); - refreshCurrentDir(); + download_dir_ = path; + mark_edited(); + set_dirty(); + refresh_current_dir(); if (is_new_torrent) { @@ -2410,36 +2408,36 @@ void tr_torrent::setDownloadDir(std::string_view path, bool is_new_torrent) } else { - completion.setHasAll(); + completion.set_has_all(); doneDate = addedDate; - recheckCompleteness(); + recheck_completeness(); } } } // decide whether we should be looking for files in downloadDir or incompleteDir -void tr_torrent::refreshCurrentDir() +void tr_torrent::refresh_current_dir() { auto dir = tr_interned_string{}; - if (std::empty(incompleteDir())) + if (std::empty(incomplete_dir())) { - dir = downloadDir(); + dir = download_dir(); } - else if (!hasMetainfo()) // no files to find + else if (!has_metainfo()) // no files to find { - dir = incompleteDir(); + dir = incomplete_dir(); } else { - auto const found = findFile(0); - dir = found ? tr_interned_string{ found->base() } : incompleteDir(); + auto const found = find_file(0); + dir = found ? tr_interned_string{ found->base() } : incomplete_dir(); } TR_ASSERT(!std::empty(dir)); - TR_ASSERT(dir == downloadDir() || dir == incompleteDir()); + TR_ASSERT(dir == download_dir() || dir == incomplete_dir()); - current_dir = dir; + current_dir_ = dir; } // --- RENAME @@ -2458,11 +2456,11 @@ auto renameFindAffectedFiles(tr_torrent const* tor, std::string_view oldpath) { auto indices = std::vector{}; auto const oldpath_as_dir = tr_pathbuf{ oldpath, '/' }; - auto const n_files = tor->fileCount(); + auto const n_files = tor->file_count(); for (tr_file_index_t i = 0; i < n_files; ++i) { - auto const& name = tor->fileSubpath(i); + auto const& name = tor->file_subpath(i); if (name == oldpath || tr_strvStartsWith(name, oldpath_as_dir)) { indices.push_back(i); @@ -2476,7 +2474,7 @@ int renamePath(tr_torrent const* tor, std::string_view oldpath, std::string_view { int err = 0; - auto const base = tor->isDone() || std::empty(tor->incompleteDir()) ? tor->downloadDir() : tor->incompleteDir(); + auto const base = tor->is_done() || std::empty(tor->incomplete_dir()) ? tor->download_dir() : tor->incomplete_dir(); auto src = tr_pathbuf{ base, '/', oldpath }; @@ -2518,7 +2516,7 @@ int renamePath(tr_torrent const* tor, std::string_view oldpath, std::string_view void renameTorrentFileString(tr_torrent* tor, std::string_view oldpath, std::string_view newname, tr_file_index_t file_index) { auto name = std::string{}; - auto const subpath = std::string_view{ tor->fileSubpath(file_index) }; + auto const subpath = std::string_view{ tor->file_subpath(file_index) }; auto const oldpath_len = std::size(oldpath); if (!tr_strvContains(oldpath, TR_PATH_DELIMITER)) @@ -2553,7 +2551,7 @@ void renameTorrentFileString(tr_torrent* tor, std::string_view oldpath, std::str if (subpath != name) { - tor->setFileSubpath(file_index, name); + tor->set_file_subpath(file_index, name); } } @@ -2589,19 +2587,19 @@ void torrentRenamePath( } /* update tr_info.name if user changed the toplevel */ - if (std::size(file_indices) == tor->fileCount() && !tr_strvContains(oldpath, '/')) + if (std::size(file_indices) == tor->file_count() && !tr_strvContains(oldpath, '/')) { - tor->setName(newname); + tor->set_name(newname); } - tor->markEdited(); - tor->setDirty(); + tor->mark_edited(); + tor->set_dirty(); } } /// - tor->markChanged(); + tor->mark_changed(); /* callback */ if (callback != nullptr) @@ -2613,7 +2611,7 @@ void torrentRenamePath( } // namespace rename_helpers } // namespace -void tr_torrent::renamePath( +void tr_torrent::rename_path( std::string_view oldpath, std::string_view newname, tr_torrent_rename_done_func callback, @@ -2640,7 +2638,7 @@ void tr_torrentRenamePath( oldpath = oldpath != nullptr ? oldpath : ""; newname = newname != nullptr ? newname : ""; - tor->renamePath(oldpath, newname, callback, callback_user_data); + tor->rename_path(oldpath, newname, callback, callback_user_data); } // --- @@ -2651,57 +2649,57 @@ void tr_torrentSetFilePriorities( tr_file_index_t file_count, tr_priority_t priority) { - tor->setFilePriorities(files, file_count, priority); + tor->set_file_priorities(files, file_count, priority); } bool tr_torrentHasMetadata(tr_torrent const* tor) { - return tor->hasMetainfo(); + return tor->has_metainfo(); } -void tr_torrent::markEdited() +void tr_torrent::mark_edited() { this->editDate = tr_time(); } -void tr_torrent::markChanged() +void tr_torrent::mark_changed() { this->anyDate = tr_time(); } -void tr_torrent::setBlocks(tr_bitfield blocks) +void tr_torrent::set_blocks(tr_bitfield blocks) { - this->completion.setBlocks(std::move(blocks)); + this->completion.set_blocks(std::move(blocks)); } -[[nodiscard]] bool tr_torrent::ensurePieceIsChecked(tr_piece_index_t piece) +[[nodiscard]] bool tr_torrent::ensure_piece_is_checked(tr_piece_index_t piece) { - TR_ASSERT(piece < this->pieceCount()); + TR_ASSERT(piece < this->piece_count()); - if (isPieceChecked(piece)) + if (is_piece_checked(piece)) { return true; } - bool const checked = checkPiece(piece); - this->markChanged(); - this->setDirty(); + bool const checked = check_piece(piece); + this->mark_changed(); + this->set_dirty(); checked_pieces_.set(piece, checked); return checked; } -void tr_torrent::initCheckedPieces(tr_bitfield const& checked, time_t const* mtimes /*fileCount()*/) +void tr_torrent::init_checked_pieces(tr_bitfield const& checked, time_t const* mtimes /*fileCount()*/) { - TR_ASSERT(std::size(checked) == this->pieceCount()); + TR_ASSERT(std::size(checked) == this->piece_count()); checked_pieces_ = checked; - auto const n = this->fileCount(); + auto const n = this->file_count(); this->file_mtimes_.resize(n); for (size_t i = 0; i < n; ++i) { - auto const found = this->findFile(i); + auto const found = this->find_file(i); auto const mtime = found ? found->last_modified_at : 0; this->file_mtimes_[i] = mtime; @@ -2709,8 +2707,8 @@ void tr_torrent::initCheckedPieces(tr_bitfield const& checked, time_t const* mti // if a file has changed, mark its pieces as unchecked if (mtime == 0 || mtime != mtimes[i]) { - auto const [begin, end] = piecesInFile(i); - checked_pieces_.unsetSpan(begin, end); + auto const [begin, end] = pieces_in_file(i); + checked_pieces_.unset_span(begin, end); } } } diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index b4bf07d17..324bd522b 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -84,25 +84,25 @@ struct tr_torrent final : public tr_completion::torrent_view public: explicit tr_torrent(tr_torrent_metainfo&& tm) : metainfo_{ std::move(tm) } - , completion{ this, &this->metainfo_.blockInfo() } + , completion{ this, &this->metainfo_.block_info() } { } - void setLocation( + void set_location( std::string_view location, bool move_from_old_path, double volatile* setme_progress, int volatile* setme_state); - void renamePath( + void rename_path( std::string_view oldpath, std::string_view newname, tr_torrent_rename_done_func callback, void* callback_user_data); - tr_sha1_digest_t pieceHash(tr_piece_index_t i) const + tr_sha1_digest_t piece_hash(tr_piece_index_t i) const { - return metainfo_.pieceHash(i); + return metainfo_.piece_hash(i); } // these functions should become private when possible, @@ -110,7 +110,7 @@ public: // because much of tr_torrent's impl is in the non-member C bindings // Used to add metainfo to a magnet torrent. - void setMetainfo(tr_torrent_metainfo tm); + void set_metainfo(tr_torrent_metainfo tm); [[nodiscard]] auto unique_lock() const { @@ -129,153 +129,153 @@ public: return bandwidth_; } - constexpr void setSpeedLimitBps(tr_direction dir, tr_bytes_per_second_t bytes_per_second) + constexpr void set_speed_limit_bps(tr_direction dir, tr_bytes_per_second_t bytes_per_second) { - if (bandwidth().setDesiredSpeedBytesPerSecond(dir, bytes_per_second)) + if (bandwidth().set_desired_speed_bytes_per_second(dir, bytes_per_second)) { - setDirty(); + set_dirty(); } } - constexpr void useSpeedLimit(tr_direction dir, bool do_use) + constexpr void use_speed_limit(tr_direction dir, bool do_use) { - if (bandwidth().setLimited(dir, do_use)) + if (bandwidth().set_limited(dir, do_use)) { - setDirty(); + set_dirty(); } } - [[nodiscard]] constexpr auto speedLimitBps(tr_direction dir) const + [[nodiscard]] constexpr auto speed_limit_bps(tr_direction dir) const { - return bandwidth().getDesiredSpeedBytesPerSecond(dir); + return bandwidth().get_desired_speed_bytes_per_second(dir); } - [[nodiscard]] constexpr auto usesSessionLimits() const noexcept + [[nodiscard]] constexpr auto uses_session_limits() const noexcept { - return bandwidth().areParentLimitsHonored(TR_UP); + return bandwidth().are_parent_limits_honored(TR_UP); } - [[nodiscard]] constexpr auto usesSpeedLimit(tr_direction dir) const noexcept + [[nodiscard]] constexpr auto uses_speed_limit(tr_direction dir) const noexcept { - return bandwidth().isLimited(dir); + return bandwidth().is_limited(dir); } /// BLOCK INFO - [[nodiscard]] constexpr auto const& blockInfo() const noexcept + [[nodiscard]] constexpr auto const& block_info() const noexcept { - return metainfo_.blockInfo(); + return metainfo_.block_info(); } - [[nodiscard]] constexpr auto blockCount() const noexcept + [[nodiscard]] constexpr auto block_count() const noexcept { - return metainfo_.blockCount(); + return metainfo_.block_count(); } - [[nodiscard]] constexpr auto byteLoc(uint64_t byte) const noexcept + [[nodiscard]] constexpr auto byte_loc(uint64_t byte) const noexcept { - return metainfo_.byteLoc(byte); + return metainfo_.byte_loc(byte); } - [[nodiscard]] constexpr auto blockLoc(tr_block_index_t block) const noexcept + [[nodiscard]] constexpr auto block_loc(tr_block_index_t block) const noexcept { - return metainfo_.blockLoc(block); + return metainfo_.block_loc(block); } - [[nodiscard]] constexpr auto pieceLoc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const noexcept + [[nodiscard]] constexpr auto piece_loc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const noexcept { - return metainfo_.pieceLoc(piece, offset, length); + return metainfo_.piece_loc(piece, offset, length); } - [[nodiscard]] constexpr auto blockSize(tr_block_index_t block) const noexcept + [[nodiscard]] constexpr auto block_size(tr_block_index_t block) const noexcept { - return metainfo_.blockSize(block); + return metainfo_.block_size(block); } - [[nodiscard]] constexpr auto blockSpanForPiece(tr_piece_index_t piece) const noexcept + [[nodiscard]] constexpr auto block_span_for_piece(tr_piece_index_t piece) const noexcept { - return metainfo_.blockSpanForPiece(piece); + return metainfo_.block_span_for_piece(piece); } - [[nodiscard]] constexpr auto pieceCount() const noexcept + [[nodiscard]] constexpr auto piece_count() const noexcept { - return metainfo_.pieceCount(); + return metainfo_.piece_count(); } - [[nodiscard]] constexpr auto pieceSize() const noexcept + [[nodiscard]] constexpr auto piece_size() const noexcept { - return metainfo_.pieceSize(); + return metainfo_.piece_size(); } - [[nodiscard]] constexpr auto pieceSize(tr_piece_index_t piece) const noexcept + [[nodiscard]] constexpr auto piece_size(tr_piece_index_t piece) const noexcept { - return metainfo_.pieceSize(piece); + return metainfo_.piece_size(piece); } - [[nodiscard]] constexpr auto totalSize() const noexcept + [[nodiscard]] constexpr auto total_size() const noexcept { - return metainfo_.totalSize(); + return metainfo_.total_size(); } /// COMPLETION - [[nodiscard]] auto leftUntilDone() const + [[nodiscard]] auto left_until_done() const { - return completion.leftUntilDone(); + return completion.left_until_done(); } - [[nodiscard]] auto sizeWhenDone() const + [[nodiscard]] auto size_when_done() const { - return completion.sizeWhenDone(); + return completion.size_when_done(); } - [[nodiscard]] constexpr auto hasMetainfo() const noexcept + [[nodiscard]] constexpr auto has_metainfo() const noexcept { - return completion.hasMetainfo(); + return completion.has_metainfo(); } - [[nodiscard]] constexpr auto hasAll() const noexcept + [[nodiscard]] constexpr auto has_all() const noexcept { - return completion.hasAll(); + return completion.has_all(); } - [[nodiscard]] constexpr auto hasNone() const noexcept + [[nodiscard]] constexpr auto has_none() const noexcept { - return completion.hasNone(); + return completion.has_none(); } - [[nodiscard]] auto hasPiece(tr_piece_index_t piece) const + [[nodiscard]] auto has_piece(tr_piece_index_t piece) const { - return completion.hasPiece(piece); + return completion.has_piece(piece); } - [[nodiscard]] TR_CONSTEXPR20 auto hasBlock(tr_block_index_t block) const + [[nodiscard]] TR_CONSTEXPR20 auto has_block(tr_block_index_t block) const { - return completion.hasBlock(block); + return completion.has_block(block); } - [[nodiscard]] auto countMissingBlocksInPiece(tr_piece_index_t piece) const + [[nodiscard]] auto count_missing_blocks_in_piece(tr_piece_index_t piece) const { - return completion.countMissingBlocksInPiece(piece); + return completion.count_missing_blocks_in_piece(piece); } - [[nodiscard]] auto countMissingBytesInPiece(tr_piece_index_t piece) const + [[nodiscard]] auto count_missing_bytes_in_piece(tr_piece_index_t piece) const { - return completion.countMissingBytesInPiece(piece); + return completion.count_missing_bytes_in_piece(piece); } - [[nodiscard]] constexpr auto hasTotal() const + [[nodiscard]] constexpr auto has_total() const { - return completion.hasTotal(); + return completion.has_total(); } - [[nodiscard]] auto createPieceBitfield() const + [[nodiscard]] auto create_piece_bitfield() const { - return completion.createPieceBitfield(); + return completion.create_piece_bitfield(); } - [[nodiscard]] constexpr bool isDone() const noexcept + [[nodiscard]] constexpr bool is_done() const noexcept { return completeness != TR_LEECH; } - [[nodiscard]] constexpr bool isSeed() const noexcept + [[nodiscard]] constexpr bool is_seed() const noexcept { return completeness == TR_SEED; } - [[nodiscard]] constexpr bool isPartialSeed() const noexcept + [[nodiscard]] constexpr bool is_partial_seed() const noexcept { return completeness == TR_PARTIAL_SEED; } @@ -285,157 +285,157 @@ public: return completion.blocks(); } - void amountDoneBins(float* tab, int n_tabs) const + void amount_done_bins(float* tab, int n_tabs) const { - return completion.amountDone(tab, n_tabs); + return completion.amount_done(tab, n_tabs); } - void setBlocks(tr_bitfield blocks); + void set_blocks(tr_bitfield blocks); - void setHasPiece(tr_piece_index_t piece, bool has) + void set_has_piece(tr_piece_index_t piece, bool has) { - completion.setHasPiece(piece, has); + completion.set_has_piece(piece, has); } /// FILE <-> PIECE - [[nodiscard]] auto piecesInFile(tr_file_index_t file) const + [[nodiscard]] auto pieces_in_file(tr_file_index_t file) const { - return fpm_.pieceSpan(file); + return fpm_.piece_span(file); } - [[nodiscard]] auto fileOffset(tr_block_info::Location loc) const + [[nodiscard]] auto file_offset(tr_block_info::Location loc) const { - return fpm_.fileOffset(loc.byte); + return fpm_.file_offset(loc.byte); } - [[nodiscard]] auto byteSpan(tr_file_index_t file) const + [[nodiscard]] auto byte_span(tr_file_index_t file) const { - return fpm_.byteSpan(file); + return fpm_.byte_span(file); } /// WANTED - [[nodiscard]] bool pieceIsWanted(tr_piece_index_t piece) const final + [[nodiscard]] bool piece_is_wanted(tr_piece_index_t piece) const final { - return files_wanted_.pieceWanted(piece); + return files_wanted_.piece_wanted(piece); } - [[nodiscard]] TR_CONSTEXPR20 bool fileIsWanted(tr_file_index_t file) const + [[nodiscard]] TR_CONSTEXPR20 bool file_is_wanted(tr_file_index_t file) const { - return files_wanted_.fileWanted(file); + return files_wanted_.file_wanted(file); } - void initFilesWanted(tr_file_index_t const* files, size_t n_files, bool wanted) + void init_files_wanted(tr_file_index_t const* files, size_t n_files, bool wanted) { - setFilesWanted(files, n_files, wanted, /*is_bootstrapping*/ true); + set_files_wanted(files, n_files, wanted, /*is_bootstrapping*/ true); } - void setFilesWanted(tr_file_index_t const* files, size_t n_files, bool wanted) + void set_files_wanted(tr_file_index_t const* files, size_t n_files, bool wanted) { - setFilesWanted(files, n_files, wanted, /*is_bootstrapping*/ false); + set_files_wanted(files, n_files, wanted, /*is_bootstrapping*/ false); } - void recheckCompleteness(); // TODO(ckerr): should be private + void recheck_completeness(); // TODO(ckerr): should be private /// PRIORITIES - [[nodiscard]] tr_priority_t piecePriority(tr_piece_index_t piece) const + [[nodiscard]] tr_priority_t piece_priority(tr_piece_index_t piece) const { - return file_priorities_.piecePriority(piece); + return file_priorities_.piece_priority(piece); } - void setFilePriorities(tr_file_index_t const* files, tr_file_index_t file_count, tr_priority_t priority) + void set_file_priorities(tr_file_index_t const* files, tr_file_index_t file_count, tr_priority_t priority) { file_priorities_.set(files, file_count, priority); - setDirty(); + set_dirty(); } - void setFilePriority(tr_file_index_t file, tr_priority_t priority) + void set_file_priority(tr_file_index_t file, tr_priority_t priority) { file_priorities_.set(file, priority); - setDirty(); + set_dirty(); } /// LOCATION - [[nodiscard]] constexpr tr_interned_string currentDir() const noexcept + [[nodiscard]] constexpr tr_interned_string current_dir() const noexcept { - return this->current_dir; + return current_dir_; } - [[nodiscard]] constexpr tr_interned_string downloadDir() const noexcept + [[nodiscard]] constexpr tr_interned_string download_dir() const noexcept { - return this->download_dir; + return download_dir_; } - [[nodiscard]] constexpr tr_interned_string incompleteDir() const noexcept + [[nodiscard]] constexpr tr_interned_string incomplete_dir() const noexcept { - return this->incomplete_dir; + return incomplete_dir_; } /// METAINFO - FILES - [[nodiscard]] TR_CONSTEXPR20 auto fileCount() const noexcept + [[nodiscard]] TR_CONSTEXPR20 auto file_count() const noexcept { - return metainfo_.fileCount(); + return metainfo_.file_count(); } - [[nodiscard]] TR_CONSTEXPR20 auto const& fileSubpath(tr_file_index_t i) const + [[nodiscard]] TR_CONSTEXPR20 auto const& file_subpath(tr_file_index_t i) const { - return metainfo_.fileSubpath(i); + return metainfo_.file_subpath(i); } - [[nodiscard]] TR_CONSTEXPR20 auto fileSize(tr_file_index_t i) const + [[nodiscard]] TR_CONSTEXPR20 auto file_size(tr_file_index_t i) const { - return metainfo_.fileSize(i); + return metainfo_.file_size(i); } - void setFileSubpath(tr_file_index_t i, std::string_view subpath) + void set_file_subpath(tr_file_index_t i, std::string_view subpath) { - metainfo_.setFileSubpath(i, subpath); + metainfo_.set_file_subpath(i, subpath); } - [[nodiscard]] std::optional findFile(tr_file_index_t file_index) const; + [[nodiscard]] std::optional find_file(tr_file_index_t file_index) const; - [[nodiscard]] bool hasAnyLocalData() const; + [[nodiscard]] bool has_any_local_data() const; /// METAINFO - TRACKERS - [[nodiscard]] constexpr auto const& announceList() const noexcept + [[nodiscard]] constexpr auto const& announce_list() const noexcept { - return metainfo_.announceList(); + return metainfo_.announce_list(); } - [[nodiscard]] constexpr auto& announceList() noexcept + [[nodiscard]] constexpr auto& announce_list() noexcept { - return metainfo_.announceList(); + return metainfo_.announce_list(); } - [[nodiscard]] TR_CONSTEXPR20 auto trackerCount() const noexcept + [[nodiscard]] TR_CONSTEXPR20 auto tracker_count() const noexcept { - return std::size(this->announceList()); + return std::size(this->announce_list()); } [[nodiscard]] TR_CONSTEXPR20 auto const& tracker(size_t i) const { - return this->announceList().at(i); + return this->announce_list().at(i); } - [[nodiscard]] auto trackerList() const + [[nodiscard]] auto tracker_list() const { - return this->announceList().toString(); + return this->announce_list().toString(); } - bool setTrackerList(std::string_view text); + bool set_tracker_list(std::string_view text); - void onTrackerResponse(tr_tracker_event const* event); + void on_tracker_response(tr_tracker_event const* event); /// METAINFO - WEBSEEDS - [[nodiscard]] TR_CONSTEXPR20 auto webseedCount() const noexcept + [[nodiscard]] TR_CONSTEXPR20 auto webseed_count() const noexcept { - return metainfo_.webseedCount(); + return metainfo_.webseed_count(); } [[nodiscard]] TR_CONSTEXPR20 auto const& webseed(size_t i) const @@ -445,9 +445,9 @@ public: /// METAINFO - OTHER - void setName(std::string_view name) + void set_name(std::string_view name) { - metainfo_.setName(name); + metainfo_.set_name(name); } [[nodiscard]] constexpr auto const& name() const noexcept @@ -455,44 +455,44 @@ public: return metainfo_.name(); } - [[nodiscard]] constexpr auto const& infoHash() const noexcept + [[nodiscard]] constexpr auto const& info_hash() const noexcept { - return metainfo_.infoHash(); + return metainfo_.info_hash(); } - [[nodiscard]] constexpr auto isPrivate() const noexcept + [[nodiscard]] constexpr auto is_private() const noexcept { - return metainfo_.isPrivate(); + return metainfo_.is_private(); } - [[nodiscard]] constexpr auto isPublic() const noexcept + [[nodiscard]] constexpr auto is_public() const noexcept { - return !this->isPrivate(); + return !this->is_private(); } - [[nodiscard]] constexpr auto const& infoHashString() const noexcept + [[nodiscard]] constexpr auto const& info_hash_string() const noexcept { - return metainfo_.infoHashString(); + return metainfo_.info_hash_string(); } - [[nodiscard]] constexpr auto dateCreated() const noexcept + [[nodiscard]] constexpr auto date_created() const noexcept { - return metainfo_.dateCreated(); + return metainfo_.date_created(); } - [[nodiscard]] auto torrentFile() const + [[nodiscard]] auto torrent_file() const { - return metainfo_.torrentFile(session->torrentDir()); + return metainfo_.torrent_file(session->torrentDir()); } - [[nodiscard]] auto magnetFile() const + [[nodiscard]] auto magnet_file() const { - return metainfo_.magnetFile(session->torrentDir()); + return metainfo_.magnet_file(session->torrentDir()); } - [[nodiscard]] auto resumeFile() const + [[nodiscard]] auto resume_file() const { - return metainfo_.resumeFile(session->resumeDir()); + return metainfo_.resume_file(session->resumeDir()); } [[nodiscard]] auto magnet() const @@ -515,90 +515,90 @@ public: return metainfo_.source(); } - [[nodiscard]] constexpr auto infoDictSize() const noexcept + [[nodiscard]] constexpr auto info_dict_size() const noexcept { - return metainfo_.infoDictSize(); + return metainfo_.info_dict_size(); } - [[nodiscard]] constexpr auto infoDictOffset() const noexcept + [[nodiscard]] constexpr auto info_dict_offset() const noexcept { - return metainfo_.infoDictOffset(); + return metainfo_.info_dict_offset(); } /// METAINFO - PIECE CHECKSUMS - [[nodiscard]] TR_CONSTEXPR20 bool isPieceChecked(tr_piece_index_t piece) const + [[nodiscard]] TR_CONSTEXPR20 bool is_piece_checked(tr_piece_index_t piece) const { return checked_pieces_.test(piece); } - [[nodiscard]] bool checkPiece(tr_piece_index_t piece); + [[nodiscard]] bool check_piece(tr_piece_index_t piece); - [[nodiscard]] bool ensurePieceIsChecked(tr_piece_index_t piece); + [[nodiscard]] bool ensure_piece_is_checked(tr_piece_index_t piece); - void initCheckedPieces(tr_bitfield const& checked, time_t const* mtimes /*fileCount()*/); + void init_checked_pieces(tr_bitfield const& checked, time_t const* mtimes /*fileCount()*/); /// - [[nodiscard]] constexpr auto isQueued() const noexcept + [[nodiscard]] constexpr auto is_queued() const noexcept { - return this->is_queued; + return this->is_queued_; } - [[nodiscard]] constexpr auto queueDirection() const noexcept + [[nodiscard]] constexpr auto queue_direction() const noexcept { - return this->isDone() ? TR_UP : TR_DOWN; + return this->is_done() ? TR_UP : TR_DOWN; } - [[nodiscard]] constexpr auto allowsPex() const noexcept + [[nodiscard]] constexpr auto allows_pex() const noexcept { - return this->isPublic() && this->session->allowsPEX(); + return this->is_public() && this->session->allowsPEX(); } - [[nodiscard]] constexpr auto allowsDht() const noexcept + [[nodiscard]] constexpr auto allows_dht() const noexcept { - return this->isPublic() && this->session->allowsDHT(); + return this->is_public() && this->session->allowsDHT(); } - [[nodiscard]] constexpr auto allowsLpd() const noexcept // local peer discovery + [[nodiscard]] constexpr auto allows_lpd() const noexcept // local peer discovery { - return this->isPublic() && this->session->allowsLPD(); + return this->is_public() && this->session->allowsLPD(); } - [[nodiscard]] constexpr bool clientCanDownload() const + [[nodiscard]] constexpr bool client_can_download() const { - return this->isPieceTransferAllowed(TR_PEER_TO_CLIENT); + return this->is_piece_transfer_allowed(TR_PEER_TO_CLIENT); } - [[nodiscard]] constexpr bool clientCanUpload() const + [[nodiscard]] constexpr bool client_can_upload() const { - return this->isPieceTransferAllowed(TR_CLIENT_TO_PEER); + return this->is_piece_transfer_allowed(TR_CLIENT_TO_PEER); } - void setLocalError(std::string_view errmsg) + void set_local_error(std::string_view errmsg) { this->error = TR_STAT_LOCAL_ERROR; this->error_announce_url = TR_KEY_NONE; this->error_string = errmsg; } - void setDownloadDir(std::string_view path, bool is_new_torrent = false); + void set_download_dir(std::string_view path, bool is_new_torrent = false); - void refreshCurrentDir(); + void refresh_current_dir(); - void setVerifyState(tr_verify_state state); + void set_verify_state(tr_verify_state state); - [[nodiscard]] constexpr auto verifyState() const noexcept + [[nodiscard]] constexpr auto verify_state() const noexcept { return verify_state_; } - constexpr void setVerifyProgress(float f) noexcept + constexpr void set_verify_progress(float f) noexcept { verify_progress_ = f; } - [[nodiscard]] constexpr std::optional verifyProgress() const noexcept + [[nodiscard]] constexpr std::optional verify_progress() const noexcept { if (verify_state_ == TR_VERIFY_NOW) { @@ -613,7 +613,7 @@ public: return unique_id_; } - constexpr void setDateActive(time_t t) noexcept + constexpr void set_date_active(time_t t) noexcept { this->activityDate = t; @@ -625,24 +625,24 @@ public: [[nodiscard]] constexpr auto activity() const noexcept { - bool const is_seed = this->isDone(); + bool const is_seed = this->is_done(); - if (this->verifyState() == TR_VERIFY_NOW) + if (this->verify_state() == TR_VERIFY_NOW) { return TR_STATUS_CHECK; } - if (this->verifyState() == TR_VERIFY_WAIT) + if (this->verify_state() == TR_VERIFY_WAIT) { return TR_STATUS_CHECK_WAIT; } - if (this->isRunning) + if (this->is_running()) { return is_seed ? TR_STATUS_SEED : TR_STATUS_DOWNLOAD; } - if (this->isQueued()) + if (this->is_queued()) { if (is_seed && this->session->queueEnabled(TR_UP)) { @@ -662,76 +662,91 @@ public: /** Return the mime-type (e.g. "audio/x-flac") that matches more of the torrent's content than any other mime-type. */ - [[nodiscard]] std::string_view primaryMimeType() const; + [[nodiscard]] std::string_view primary_mime_type() const; - constexpr void setSequentialDownload(bool is_sequential) noexcept + constexpr void set_sequential_download(bool is_sequential) noexcept { - this->sequential_download_ = is_sequential; + sequential_download_ = is_sequential; } - [[nodiscard]] constexpr auto isSequentialDownload() const noexcept + [[nodiscard]] constexpr auto is_sequential_download() const noexcept { - return this->sequential_download_; + return sequential_download_; } - constexpr void setDirty() noexcept + [[nodiscard]] constexpr bool is_running() const noexcept { - this->isDirty = true; + return is_running_; } - void markEdited(); - void markChanged(); - - void setBandwidthGroup(std::string_view group_name) noexcept; - - [[nodiscard]] constexpr auto getPriority() const noexcept + [[nodiscard]] constexpr auto is_stopping() const noexcept { - return bandwidth().getPriority(); + return is_stopping_; } - [[nodiscard]] constexpr auto const& bandwidthGroup() const noexcept + [[nodiscard]] constexpr auto is_dirty() const noexcept + { + return is_dirty_; + } + + constexpr void set_dirty(bool dirty = true) noexcept + { + is_dirty_ = dirty; + } + + void mark_edited(); + void mark_changed(); + + void set_bandwidth_group(std::string_view group_name) noexcept; + + [[nodiscard]] constexpr auto get_priority() const noexcept + { + return bandwidth().get_priority(); + } + + [[nodiscard]] constexpr auto const& bandwidth_group() const noexcept { return bandwidth_group_; } - [[nodiscard]] constexpr auto idleLimitMode() const noexcept + [[nodiscard]] constexpr auto idle_limit_mode() const noexcept { return idle_limit_mode_; } - [[nodiscard]] constexpr auto idleLimitMinutes() const noexcept + [[nodiscard]] constexpr auto idle_limit_minutes() const noexcept { return idle_limit_minutes_; } - [[nodiscard]] constexpr auto peerLimit() const noexcept + [[nodiscard]] constexpr auto peer_limit() const noexcept { return max_connected_peers_; } - constexpr void setRatioMode(tr_ratiolimit mode) noexcept + constexpr void set_ratio_mode(tr_ratiolimit mode) noexcept { if (ratioLimitMode != mode) { ratioLimitMode = mode; - setDirty(); + set_dirty(); } } - constexpr void setIdleLimit(uint16_t idle_minutes) noexcept + constexpr void set_idle_limit(uint16_t idle_minutes) noexcept { if ((idle_limit_minutes_ != idle_minutes) && (idle_minutes > 0)) { idle_limit_minutes_ = idle_minutes; - setDirty(); + set_dirty(); } } - [[nodiscard]] constexpr auto secondsDownloading(time_t now) const noexcept + [[nodiscard]] constexpr auto seconds_downloading(time_t now) const noexcept { auto n_secs = seconds_downloading_before_current_start_; - if (isRunning) + if (is_running()) { if (doneDate > startDate) { @@ -746,11 +761,11 @@ public: return n_secs; } - [[nodiscard]] constexpr auto secondsSeeding(time_t now) const noexcept + [[nodiscard]] constexpr auto seconds_seeding(time_t now) const noexcept { auto n_secs = seconds_seeding_before_current_start_; - if (isRunning) + if (is_running()) { if (doneDate > startDate) { @@ -775,10 +790,10 @@ public: if (needs_completeness_check_) { needs_completeness_check_ = false; - recheckCompleteness(); + recheck_completeness(); } - if (isStopping) + if (is_stopping_) { tr_torrentStop(this); } @@ -797,7 +812,7 @@ public: // should be called when done modifying the torrent's announce list. void on_announce_list_changed() { - markEdited(); + mark_edited(); session->announcer_->resetTorrent(this); } @@ -866,15 +881,15 @@ public: tr_interned_string error_announce_url; // Where the files are when the torrent is complete. - tr_interned_string download_dir; + tr_interned_string download_dir_; // Where the files are when the torrent is incomplete. // a value of TR_KEY_NONE indicates the 'incomplete_dir' feature is unused - tr_interned_string incomplete_dir; + tr_interned_string incomplete_dir_; // Where the files are now. // Will equal either download_dir or incomplete_dir - tr_interned_string current_dir; + tr_interned_string current_dir_; tr_stat_errtype error = TR_STAT_OK; @@ -895,27 +910,27 @@ public: uint16_t idle_limit_minutes_ = 0; - bool finishedSeedingByIdle = false; + bool finished_seeding_by_idle_ = false; - bool isDeleting = false; - bool isDirty = false; - bool is_queued = false; - bool isRunning = false; - bool isStopping = false; + bool is_deleting_ = false; + bool is_dirty_ = false; + bool is_queued_ = false; + bool is_running_ = false; + bool is_stopping_ = false; // start the torrent after all the startup scaffolding is done, // e.g. fetching metadata from peers and/or verifying the torrent bool start_when_stable = false; private: - [[nodiscard]] constexpr bool isPieceTransferAllowed(tr_direction direction) const noexcept + [[nodiscard]] constexpr bool is_piece_transfer_allowed(tr_direction direction) const noexcept { - if (usesSpeedLimit(direction) && speedLimitBps(direction) <= 0) + if (uses_speed_limit(direction) && speed_limit_bps(direction) <= 0) { return false; } - if (usesSessionLimits()) + if (uses_session_limits()) { if (auto const limit = session->activeSpeedLimitBps(direction); limit && *limit == 0U) { @@ -926,17 +941,17 @@ private: return true; } - void setFilesWanted(tr_file_index_t const* files, size_t n_files, bool wanted, bool is_bootstrapping) + void set_files_wanted(tr_file_index_t const* files, size_t n_files, bool wanted, bool is_bootstrapping) { auto const lock = unique_lock(); files_wanted_.set(files, n_files, wanted); - completion.invalidateSizeWhenDone(); + completion.invalidate_size_when_done(); if (!is_bootstrapping) { - setDirty(); - recheckCompleteness(); + set_dirty(); + recheck_completeness(); } } diff --git a/libtransmission/torrents.cc b/libtransmission/torrents.cc index 3fa888e33..3d6f9fda2 100644 --- a/libtransmission/torrents.cc +++ b/libtransmission/torrents.cc @@ -26,17 +26,17 @@ struct CompareTorrentByHash bool operator()(tr_torrent const* a, tr_torrent const* b) const { - return (*this)(a->infoHash(), b->infoHash()); + return (*this)(a->info_hash(), b->info_hash()); } bool operator()(tr_torrent const* a, tr_sha1_digest_t const& b) const { - return (*this)(a->infoHash(), b); + return (*this)(a->info_hash(), b); } bool operator()(tr_sha1_digest_t const& a, tr_torrent const* b) const { - return (*this)(a, b->infoHash()); + return (*this)(a, b->info_hash()); } }; @@ -45,7 +45,7 @@ struct CompareTorrentByHash tr_torrent* tr_torrents::get(std::string_view magnet_link) { auto magnet = tr_magnet_metainfo{}; - return magnet.parseMagnet(magnet_link) ? get(magnet.infoHash()) : nullptr; + return magnet.parseMagnet(magnet_link) ? get(magnet.info_hash()) : nullptr; } tr_torrent* tr_torrents::get(tr_sha1_digest_t const& hash) diff --git a/libtransmission/torrents.h b/libtransmission/torrents.h index 336c6f2e2..efa31fde5 100644 --- a/libtransmission/torrents.h +++ b/libtransmission/torrents.h @@ -43,12 +43,12 @@ public: [[nodiscard]] tr_torrent const* get(tr_torrent_metainfo const& metainfo) const { - return get(metainfo.infoHash()); + return get(metainfo.info_hash()); } [[nodiscard]] tr_torrent* get(tr_torrent_metainfo const& metainfo) { - return get(metainfo.infoHash()); + return get(metainfo.info_hash()); } // These convenience functions use get(tr_sha1_digest_t const&) diff --git a/libtransmission/verify.cc b/libtransmission/verify.cc index 513978da3..d3291f0b1 100644 --- a/libtransmission/verify.cc +++ b/libtransmission/verify.cc @@ -76,26 +76,26 @@ bool tr_verify_worker::verifyTorrent(tr_torrent* tor, std::atomic const& s tr_logAddDebugTor(tor, "verifying torrent..."); - while (!stop_flag && piece < tor->pieceCount()) + while (!stop_flag && piece < tor->piece_count()) { - auto const file_length = tor->fileSize(file_index); + auto const file_length = tor->file_size(file_index); /* if we're starting a new piece... */ if (piece_pos == 0) { - had_piece = tor->hasPiece(piece); + had_piece = tor->has_piece(piece); } /* if we're starting a new file... */ if (file_pos == 0 && fd == TR_BAD_SYS_FILE && file_index != prev_file_index) { - auto const found = tor->findFile(file_index); + auto const found = tor->find_file(file_index); fd = !found ? TR_BAD_SYS_FILE : tr_sys_file_open(found->filename(), TR_SYS_FILE_READ | TR_SYS_FILE_SEQUENTIAL, 0); prev_file_index = file_index; } /* figure out how much we can read this pass */ - uint64_t left_in_piece = tor->pieceSize(piece) - piece_pos; + uint64_t left_in_piece = tor->piece_size(piece) - piece_pos; uint64_t left_in_file = file_length - file_pos; uint64_t bytes_this_pass = std::min(left_in_file, left_in_piece); bytes_this_pass = std::min(bytes_this_pass, uint64_t(std::size(buffer))); @@ -121,14 +121,14 @@ bool tr_verify_worker::verifyTorrent(tr_torrent* tor, std::atomic const& s /* if we're finishing a piece... */ if (left_in_piece == 0) { - if (auto const has_piece = sha->finish() == tor->pieceHash(piece); has_piece || had_piece) + if (auto const has_piece = sha->finish() == tor->piece_hash(piece); has_piece || had_piece) { - tor->setHasPiece(piece, has_piece); + tor->set_has_piece(piece, has_piece); changed |= has_piece != had_piece; } tor->checked_pieces_.set(piece, true); - tor->markChanged(); + tor->mark_changed(); /* sleeping even just a few msec per second goes a long * way towards reducing IO load... */ @@ -140,7 +140,7 @@ bool tr_verify_worker::verifyTorrent(tr_torrent* tor, std::atomic const& s sha->clear(); ++piece; - tor->setVerifyProgress(piece / float(tor->pieceCount())); + tor->set_verify_progress(piece / float(tor->piece_count())); piece_pos = 0; } @@ -171,8 +171,8 @@ bool tr_verify_worker::verifyTorrent(tr_torrent* tor, std::atomic const& s fmt::format( "Verification is done. It took {} seconds to verify {} bytes ({} bytes per second)", end - begin, - tor->totalSize(), - tor->totalSize() / (1 + (end - begin)))); + tor->total_size(), + tor->total_size() / (1 + (end - begin)))); return changed; } @@ -204,14 +204,14 @@ void tr_verify_worker::verifyThreadFunc() auto* const tor = current_node_->torrent; tr_logAddTraceTor(tor, "Verifying torrent"); - tor->setVerifyState(TR_VERIFY_NOW); + tor->set_verify_state(TR_VERIFY_NOW); auto const changed = verifyTorrent(tor, stop_current_); - tor->setVerifyState(TR_VERIFY_NONE); + tor->set_verify_state(TR_VERIFY_NONE); TR_ASSERT(tr_isTorrent(tor)); if (!stop_current_ && changed) { - tor->setDirty(); + tor->set_dirty(); } callCallback(tor, stop_current_); @@ -225,10 +225,10 @@ void tr_verify_worker::add(tr_torrent* tor) auto node = Node{}; node.torrent = tor; - node.current_size = tor->hasTotal(); + node.current_size = tor->has_total(); auto const lock = std::lock_guard(verify_mutex_); - tor->setVerifyState(TR_VERIFY_WAIT); + tor->set_verify_state(TR_VERIFY_WAIT); todo_.insert(node); if (!verify_thread_id_) @@ -257,7 +257,7 @@ void tr_verify_worker::remove(tr_torrent* tor) std::end(todo_), [tor](auto const& task) { return tor == task.torrent; }); - tor->setVerifyState(TR_VERIFY_NONE); + tor->set_verify_state(TR_VERIFY_NONE); if (iter != std::end(todo_)) { diff --git a/libtransmission/webseed.cc b/libtransmission/webseed.cc index b6a821620..7be7371d8 100644 --- a/libtransmission/webseed.cc +++ b/libtransmission/webseed.cc @@ -48,8 +48,8 @@ public: : webseed{ webseed_in } , session{ tor->session } , blocks{ blocks_in } - , end_byte{ tor->blockLoc(blocks.end - 1).byte + tor->blockSize(blocks.end - 1) } - , loc{ tor->blockLoc(blocks.begin) } + , end_byte{ tor->block_loc(blocks.end - 1).byte + tor->block_size(blocks.end - 1) } + , loc{ tor->block_loc(blocks.begin) } { } @@ -164,10 +164,10 @@ public: , callback{ callback_in } , callback_data{ callback_data_in } , idle_timer_{ session->timerMaker().create([this]() { on_idle(this); }) } - , have_{ tor->pieceCount() } + , have_{ tor->piece_count() } , bandwidth_{ &tor->bandwidth_ } { - have_.setHasAll(); + have_.set_has_all(); idle_timer_->startRepeating(IdleTimerInterval); } @@ -199,7 +199,7 @@ public: if (dir == TR_DOWN) { is_active = !std::empty(tasks); - bytes_per_second = bandwidth_.getPieceSpeedBytesPerSecond(now, dir); + bytes_per_second = bandwidth_.get_piece_speed_bytes_per_second(now, dir); } if (setme_bytes_per_second != nullptr) @@ -247,7 +247,7 @@ public: void gotPieceData(uint32_t n_bytes) { - bandwidth_.notifyBandwidthConsumed(TR_DOWN, n_bytes, true, tr_time_msec()); + bandwidth_.notify_bandwidth_consumed(TR_DOWN, n_bytes, true, tr_time_msec()); publish(tr_peer_event::GotPieceData(n_bytes)); connection_limiter.gotData(); } @@ -257,14 +257,14 @@ public: auto const* const tor = getTorrent(); for (auto block = block_span.begin; block < block_span.end; ++block) { - publish(tr_peer_event::GotRejected(tor->blockInfo(), block)); + publish(tr_peer_event::GotRejected(tor->block_info(), block)); } } void requestBlocks(tr_block_span_t const* block_spans, size_t n_spans) override { auto* const tor = getTorrent(); - if (tor == nullptr || !tor->isRunning || tor->isDone()) + if (tor == nullptr || !tor->is_running() || tor->is_done()) { return; } @@ -288,7 +288,7 @@ public: return {}; } - if (auto const* const tor = getTorrent(); tor == nullptr || !tor->isRunning || tor->isDone()) + if (auto const* const tor = getTorrent(); tor == nullptr || !tor->is_running() || tor->is_done()) { return {}; } @@ -353,7 +353,7 @@ public: if (auto const* const tor = tr_torrentFindFromId(session_, tor_id_); tor != nullptr) { session_->cache->writeBlock(tor_id_, block_, std::move(data_)); - webseed_->publish(tr_peer_event::GotBlock(tor->blockInfo(), block_)); + webseed_->publish(tr_peer_event::GotBlock(tor->block_info(), block_)); } delete this; @@ -382,13 +382,13 @@ void useFetchedBlocks(tr_webseed_task* task) auto* const buf = task->content(); for (;;) { - auto const block_size = tor->blockSize(task->loc.block); + auto const block_size = tor->block_size(task->loc.block); if (evbuffer_get_length(buf) < block_size) { break; } - if (tor->hasBlock(task->loc.block)) + if (tor->has_block(task->loc.block)) { evbuffer_drain(buf, block_size); } @@ -401,7 +401,7 @@ void useFetchedBlocks(tr_webseed_task* task) session->runInSessionThread(&write_block_data::write_block_func, data); } - task->loc = tor->byteLoc(task->loc.byte + block_size); + task->loc = tor->byte_loc(task->loc.byte + block_size); TR_ASSERT(task->loc.byte <= task->end_byte); TR_ASSERT(task->loc.byte == task->end_byte || task->loc.block_offset == 0); @@ -512,10 +512,10 @@ void task_request_next_chunk(tr_webseed_task* task) return; } - auto const loc = tor->byteLoc(task->loc.byte + evbuffer_get_length(task->content())); + auto const loc = tor->byte_loc(task->loc.byte + evbuffer_get_length(task->content())); - auto const [file_index, file_offset] = tor->fileOffset(loc); - auto const left_in_file = tor->fileSize(file_index) - file_offset; + auto const [file_index, file_offset] = tor->file_offset(loc); + auto const left_in_file = tor->file_size(file_index) - file_offset; auto const left_in_task = task->end_byte - loc.byte; auto const this_chunk = std::min(left_in_file, left_in_task); TR_ASSERT(this_chunk > 0U); @@ -523,7 +523,7 @@ void task_request_next_chunk(tr_webseed_task* task) webseed->connection_limiter.taskStarted(); auto url = tr_urlbuf{}; - makeUrl(webseed, tor->fileSubpath(file_index), std::back_inserter(url)); + makeUrl(webseed, tor->file_subpath(file_index), std::back_inserter(url)); auto options = tr_web::FetchOptions{ url.sv(), onPartialDataFetched, task }; options.range = fmt::format(FMT_STRING("{:d}-{:d}"), file_offset, file_offset + this_chunk - 1); options.speed_limit_tag = tor->id(); diff --git a/macosx/Controller.mm b/macosx/Controller.mm index 1791cedad..aa45efc62 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -1208,7 +1208,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool for (NSString* torrentPath in filenames) { auto metainfo = tr_torrent_metainfo{}; - if (!metainfo.parseTorrentFile(torrentPath.UTF8String)) // invalid torrent + if (!metainfo.parse_torrent_file(torrentPath.UTF8String)) // invalid torrent { if (type != AddTypeAuto) { @@ -1254,7 +1254,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool } //determine to show the options window - auto const is_multifile = metainfo.fileCount() > 1; + auto const is_multifile = metainfo.file_count() > 1; BOOL const showWindow = type == AddTypeShowOptions || ([self.fDefaults boolForKey:@"DownloadAsk"] && (is_multifile || ![self.fDefaults boolForKey:@"DownloadAskMulti"]) && (type != AddTypeAuto || ![self.fDefaults boolForKey:@"DownloadAskManual"])); @@ -3536,7 +3536,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool } auto metainfo = tr_torrent_metainfo{}; - if (!metainfo.parseTorrentFile(fullFile.UTF8String)) + if (!metainfo.parse_torrent_file(fullFile.UTF8String)) { continue; } @@ -3862,7 +3862,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool { torrent = YES; auto metainfo = tr_torrent_metainfo{}; - if (metainfo.parseTorrentFile(fileToParse.path.UTF8String)) + if (metainfo.parse_torrent_file(fileToParse.path.UTF8String)) { if (!self.fOverlayWindow) { @@ -3937,7 +3937,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool { torrent = YES; auto metainfo = tr_torrent_metainfo{}; - if (metainfo.parseTorrentFile(file.path.UTF8String)) + if (metainfo.parse_torrent_file(file.path.UTF8String)) { [filesToOpen addObject:file.path]; } diff --git a/macosx/DragOverlayWindow.mm b/macosx/DragOverlayWindow.mm index 22db8ce24..e2efdb503 100644 --- a/macosx/DragOverlayWindow.mm +++ b/macosx/DragOverlayWindow.mm @@ -69,20 +69,20 @@ [file.pathExtension caseInsensitiveCompare:@"torrent"] == NSOrderedSame) { auto metainfo = tr_torrent_metainfo{}; - if (metainfo.parseTorrentFile(file.UTF8String)) + if (metainfo.parse_torrent_file(file.UTF8String)) { ++count; - size += metainfo.totalSize(); + size += metainfo.total_size(); - auto const n_files = metainfo.fileCount(); + auto const n_files = metainfo.file_count(); fileCount += n_files; // only useful when one torrent if (count == 1) { if (n_files == 1) { - name = [NSString convertedStringFromCString:metainfo.fileSubpath(0).c_str()]; + name = [NSString convertedStringFromCString:metainfo.file_subpath(0).c_str()]; } else { diff --git a/macosx/QuickLookPlugin/GeneratePreviewForURL.mm b/macosx/QuickLookPlugin/GeneratePreviewForURL.mm index 7f98d37ef..7c3c8c868 100644 --- a/macosx/QuickLookPlugin/GeneratePreviewForURL.mm +++ b/macosx/QuickLookPlugin/GeneratePreviewForURL.mm @@ -41,7 +41,7 @@ NSString* generateIconData(NSString* fileExtension, NSUInteger width, NSMutableD return [@"cid:" stringByAppendingString:iconFileName]; } -OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) +OSStatus GeneratePreviewForURL(void* /*thisInterface*/, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) { // Before proceeding make sure the user didn't cancel the request if (QLPreviewRequestIsCancelled(preview)) @@ -54,7 +54,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview, //try to parse the torrent file auto metainfo = tr_torrent_metainfo{}; - if (!metainfo.parseTorrentFile(((__bridge NSURL*)url).path.UTF8String)) + if (!metainfo.parse_torrent_file(((__bridge NSURL*)url).path.UTF8String)) { return noErr; } @@ -71,7 +71,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview, NSString* name = @(metainfo.name().c_str()); - auto const n_files = metainfo.fileCount(); + auto const n_files = metainfo.file_count(); auto const is_multifile = n_files > 1; NSString* fileTypeString = is_multifile ? NSFileTypeForHFSTypeCode(kGenericFolderIcon) : name.pathExtension; @@ -82,7 +82,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview, width, name]; - NSString* fileSizeString = [NSString stringForFileSize:metainfo.totalSize()]; + NSString* fileSizeString = [NSString stringForFileSize:metainfo.total_size()]; if (is_multifile) { NSString* fileCountString = [NSString @@ -91,7 +91,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview, } [htmlString appendFormat:@"

%@

", fileSizeString]; - auto const date_created = metainfo.dateCreated(); + auto const date_created = metainfo.date_created(); NSString* dateCreatedString = date_created > 0 ? [NSDateFormatter localizedStringFromDate:[NSDate dateWithTimeIntervalSince1970:date_created] dateStyle:NSDateFormatterLongStyle timeStyle:NSDateFormatterShortStyle] : @@ -135,7 +135,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview, NSMutableArray* lists = [NSMutableArray array]; - auto const n_webseeds = metainfo.webseedCount(); + auto const n_webseeds = metainfo.webseed_count(); if (n_webseeds > 0) { NSMutableString* listSection = [NSMutableString string]; @@ -157,7 +157,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview, [lists addObject:listSection]; } - auto const& announce_list = metainfo.announceList(); + auto const& announce_list = metainfo.announce_list(); if (!std::empty(announce_list)) { NSMutableString* listSection = [NSMutableString string]; @@ -198,11 +198,11 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview, NSString* shortenedFilePath = [fullFilePath substringFromIndex:name.length + 1]; NSString* fileSize = [NSString stringForFileSize:size]; - NSUInteger const width = 16; + NSUInteger const icon_width = 16; [listSection appendFormat:@"%@%@", - generateIconData(shortenedFilePath.pathExtension, width, allImgProps), - width, - width, + generateIconData(shortenedFilePath.pathExtension, icon_width, allImgProps), + icon_width, + icon_width, shortenedFilePath, fileSize]; } @@ -234,7 +234,7 @@ OSStatus GeneratePreviewForURL(void* thisInterface, QLPreviewRequestRef preview, return noErr; } -void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview) +void CancelPreviewGeneration(void* /*thisInterface*/, QLPreviewRequestRef preview) { // Implement only if supported } diff --git a/qt/AddData.cc b/qt/AddData.cc index 5ab12d546..9de79ff74 100644 --- a/qt/AddData.cc +++ b/qt/AddData.cc @@ -21,13 +21,12 @@ namespace QString getNameFromMetainfo(QByteArray const& benc) { - auto metainfo = tr_torrent_metainfo{}; - if (!metainfo.parseBenc({ benc.constData(), static_cast(benc.size()) })) + if (auto metainfo = tr_torrent_metainfo{}; metainfo.parse_benc({ benc.constData(), static_cast(benc.size()) })) { - return {}; + return QString::fromStdString(metainfo.name()); } - return QString::fromStdString(metainfo.name()); + return {}; } QString getNameFromMagnet(QString const& magnet) @@ -44,7 +43,7 @@ QString getNameFromMagnet(QString const& magnet) return QString::fromStdString(tmp.name()); } - return QString::fromStdString(tmp.infoHashString()); + return QString::fromStdString(tmp.info_hash_string()); } } // namespace diff --git a/qt/OptionsDialog.cc b/qt/OptionsDialog.cc index 794215590..576e5919d 100644 --- a/qt/OptionsDialog.cc +++ b/qt/OptionsDialog.cc @@ -137,11 +137,11 @@ void OptionsDialog::reload() break; case AddData::FILENAME: - ok = metainfo.parseTorrentFile(add_.filename.toStdString()); + ok = metainfo.parse_torrent_file(add_.filename.toStdString()); break; case AddData::METAINFO: - ok = metainfo.parseBenc(add_.metainfo.toStdString()); + ok = metainfo.parse_benc(add_.metainfo.toStdString()); break; default: @@ -166,7 +166,7 @@ void OptionsDialog::reload() if (metainfo_) { - auto const n_files = metainfo_->fileCount(); + auto const n_files = metainfo_->file_count(); priorities_.assign(n_files, TR_PRI_NORMAL); wanted_.assign(n_files, true); @@ -176,9 +176,9 @@ void OptionsDialog::reload() f.index = i; f.priority = priorities_[i]; f.wanted = wanted_[i]; - f.size = metainfo_->fileSize(i); + f.size = metainfo_->file_size(i); f.have = 0; - f.filename = QString::fromStdString(metainfo_->fileSubpath(i)); + f.filename = QString::fromStdString(metainfo_->file_subpath(i)); files_.push_back(f); } } diff --git a/qt/WatchDir.cc b/qt/WatchDir.cc index aa831dd0f..193d872fa 100644 --- a/qt/WatchDir.cc +++ b/qt/WatchDir.cc @@ -33,12 +33,12 @@ WatchDir::WatchDir(TorrentModel const& model) WatchDir::AddResult WatchDir::metainfoTest(QString const& filename) const { auto metainfo = tr_torrent_metainfo(); - if (!metainfo.parseTorrentFile(filename.toUtf8().constData())) + if (!metainfo.parse_torrent_file(filename.toUtf8().constData())) { return AddResult::Error; } - if (model_.hasTorrent(TorrentHash{ metainfo.infoHash() })) + if (model_.hasTorrent(TorrentHash{ metainfo.info_hash() })) { return AddResult::Duplicate; } diff --git a/tests/libtransmission/announce-list-test.cc b/tests/libtransmission/announce-list-test.cc index db6b8cf8d..4ec6572a4 100644 --- a/tests/libtransmission/announce-list-test.cc +++ b/tests/libtransmission/announce-list-test.cc @@ -365,24 +365,24 @@ TEST_F(AnnounceListTest, save) // load the original auto original_tm = tr_torrent_metainfo{}; - EXPECT_TRUE(original_tm.parseBenc({ std::data(original_content), std::size(original_content) })); + EXPECT_TRUE(original_tm.parse_benc({ std::data(original_content), std::size(original_content) })); // load the scratch that we saved to auto modified_tm = tr_torrent_metainfo{}; - EXPECT_TRUE(modified_tm.parseTorrentFile(test_file.sv())); + EXPECT_TRUE(modified_tm.parse_torrent_file(test_file.sv())); // test that non-announce parts of the metainfo are the same EXPECT_EQ(original_tm.name(), modified_tm.name()); - EXPECT_EQ(original_tm.fileCount(), modified_tm.fileCount()); - EXPECT_EQ(original_tm.dateCreated(), modified_tm.dateCreated()); - EXPECT_EQ(original_tm.pieceCount(), modified_tm.pieceCount()); + EXPECT_EQ(original_tm.file_count(), modified_tm.file_count()); + EXPECT_EQ(original_tm.date_created(), modified_tm.date_created()); + EXPECT_EQ(original_tm.piece_count(), modified_tm.piece_count()); // test that the saved version has the updated announce list EXPECT_TRUE(std::equal( std::begin(announce_list), std::end(announce_list), - std::begin(modified_tm.announceList()), - std::end(modified_tm.announceList()))); + std::begin(modified_tm.announce_list()), + std::end(modified_tm.announce_list()))); // cleanup (void)std::remove(test_file.c_str()); diff --git a/tests/libtransmission/bitfield-test.cc b/tests/libtransmission/bitfield-test.cc index e8bdc702b..7d97c4a97 100644 --- a/tests/libtransmission/bitfield-test.cc +++ b/tests/libtransmission/bitfield-test.cc @@ -66,7 +66,7 @@ TEST(Bitfield, count) bf = tr_bitfield{ 100 }; EXPECT_EQ(0U, bf.count(0, 0)); EXPECT_EQ(0U, bf.count(0, 100)); - bf.setHasAll(); + bf.set_has_all(); EXPECT_EQ(0U, bf.count(0, 0)); EXPECT_EQ(1U, bf.count(0, 1)); EXPECT_EQ(100U, bf.count(0, 100)); @@ -88,11 +88,11 @@ TEST(Bitfield, ctorFromFlagArray) bool const have_none = true_count == 0; auto bf = tr_bitfield(n); - bf.setFromBools(std::data(flags), std::size(flags)); + bf.set_from_bools(std::data(flags), std::size(flags)); EXPECT_EQ(n, bf.size()); - EXPECT_EQ(have_all, bf.hasAll()); - EXPECT_EQ(have_none, bf.hasNone()); + EXPECT_EQ(have_all, bf.has_all()); + EXPECT_EQ(have_none, bf.has_none()); EXPECT_EQ(true_count, bf.count()); for (size_t i = 0; i < std::size(flags); ++i) @@ -110,7 +110,7 @@ TEST(Bitfield, setRaw) auto raw = std::vector(100, TestByte); auto bf = tr_bitfield(std::size(raw) * 8); - bf.setRaw(std::data(raw), std::size(raw)); + bf.set_raw(std::data(raw), std::size(raw)); EXPECT_EQ(TestByteTrueBits * std::size(raw), bf.count()); // The first byte of the bitfield corresponds to indices 0 - 7 @@ -129,7 +129,7 @@ TEST(Bitfield, setRaw) // check that has-all bitfield gets all-true bf = tr_bitfield(std::size(raw) * 8); - bf.setHasAll(); + bf.set_has_all(); raw = bf.raw(); EXPECT_EQ(std::size(bf) / 8, std::size(raw)); EXPECT_EQ(std::numeric_limits::max(), raw[0]); @@ -137,9 +137,9 @@ TEST(Bitfield, setRaw) // check that the spare bits t the end are zero bf = tr_bitfield{ 1 }; uint8_t const by = std::numeric_limits::max(); - bf.setRaw(&by, 1); - EXPECT_TRUE(bf.hasAll()); - EXPECT_FALSE(bf.hasNone()); + bf.set_raw(&by, 1); + EXPECT_TRUE(bf.has_all()); + EXPECT_FALSE(bf.has_none()); EXPECT_EQ(1U, bf.count()); raw = bf.raw(); EXPECT_EQ(1U, std::size(raw)); @@ -166,7 +166,7 @@ TEST(Bitfield, bitfields) } /* test tr_bitfield::setSpan */ - field.setSpan(0, bitcount); + field.set_span(0, bitcount); for (unsigned int i = 0; i < bitcount; i++) { @@ -188,8 +188,8 @@ TEST(Bitfield, bitfields) } /* test tr_bitfield::clearBitRange in the middle of a boundary */ - field.setSpan(0, 64); - field.unsetSpan(4, 21); + field.set_span(0, 64); + field.unset_span(4, 21); for (unsigned int i = 0; i < 64; i++) { @@ -197,8 +197,8 @@ TEST(Bitfield, bitfields) } /* test tr_bitfield::clearBitRange on the boundaries */ - field.setSpan(0, 64); - field.unsetSpan(8, 24); + field.set_span(0, 64); + field.unset_span(8, 24); for (unsigned int i = 0; i < 64; i++) { @@ -206,8 +206,8 @@ TEST(Bitfield, bitfields) } /* test tr_bitfield::clearBitRange when begin & end is on the same word */ - field.setSpan(0, 64); - field.unsetSpan(4, 5); + field.set_span(0, 64); + field.unset_span(4, 5); for (unsigned int i = 0; i < 64; i++) { @@ -215,8 +215,8 @@ TEST(Bitfield, bitfields) } /* test tr_bitfield::setSpan */ - field.unsetSpan(0, 64); - field.setSpan(4, 21); + field.unset_span(0, 64); + field.set_span(4, 21); for (unsigned int i = 0; i < 64; i++) { @@ -224,8 +224,8 @@ TEST(Bitfield, bitfields) } /* test tr_bitfield::setSpan on the boundaries */ - field.unsetSpan(0, 64); - field.setSpan(8, 24); + field.unset_span(0, 64); + field.set_span(8, 24); for (unsigned int i = 0; i < 64; i++) { @@ -233,8 +233,8 @@ TEST(Bitfield, bitfields) } /* test tr_bitfield::setSpan when begin & end is on the same word */ - field.unsetSpan(0, 64); - field.setSpan(4, 5); + field.unset_span(0, 64); + field.set_span(4, 5); for (unsigned int i = 0; i < 64; i++) { @@ -242,30 +242,30 @@ TEST(Bitfield, bitfields) } /* test tr_bitfield::setSpan when end runs beyond the end of the bitfield */ - field.setHasNone(); - field.setSpan(100, 1000); - EXPECT_FALSE(field.hasNone()); - EXPECT_FALSE(field.hasAll()); + field.set_has_none(); + field.set_span(100, 1000); + EXPECT_FALSE(field.has_none()); + EXPECT_FALSE(field.has_all()); EXPECT_EQ(std::size(field) - 100, field.count()); /* test tr_bitfield::unsetSpan when it changes nothing */ - field.setHasNone(); - field.unsetSpan(0, 100); - EXPECT_TRUE(field.hasNone()); - EXPECT_FALSE(field.hasAll()); + field.set_has_none(); + field.unset_span(0, 100); + EXPECT_TRUE(field.has_none()); + EXPECT_FALSE(field.has_all()); EXPECT_EQ(0U, field.count()); /* test tr_bitfield::setSpan when it changes nothing */ - field.setHasAll(); - field.setSpan(0, 100); - EXPECT_FALSE(field.hasNone()); - EXPECT_TRUE(field.hasAll()); + field.set_has_all(); + field.set_span(0, 100); + EXPECT_FALSE(field.has_none()); + EXPECT_TRUE(field.has_all()); EXPECT_EQ(std::size(field), field.count()); /* test tr_bitfield::setSpan with an invalid span doesn't crash */ - field.setHasAll(); - field.setSpan(0, 0); - EXPECT_TRUE(field.hasAll()); + field.set_has_all(); + field.set_span(0, 0); + EXPECT_TRUE(field.has_all()); } TEST(Bitfield, hasAllNone) @@ -273,67 +273,67 @@ TEST(Bitfield, hasAllNone) { tr_bitfield field(3); - EXPECT_TRUE(!field.hasAll()); - EXPECT_TRUE(field.hasNone()); + EXPECT_TRUE(!field.has_all()); + EXPECT_TRUE(field.has_none()); field.set(0); - EXPECT_TRUE(!field.hasAll()); - EXPECT_TRUE(!field.hasNone()); + EXPECT_TRUE(!field.has_all()); + EXPECT_TRUE(!field.has_none()); field.unset(0); field.set(1); - EXPECT_TRUE(!field.hasAll()); - EXPECT_TRUE(!field.hasNone()); + EXPECT_TRUE(!field.has_all()); + EXPECT_TRUE(!field.has_none()); field.unset(1); field.set(2); - EXPECT_TRUE(!field.hasAll()); - EXPECT_TRUE(!field.hasNone()); + EXPECT_TRUE(!field.has_all()); + EXPECT_TRUE(!field.has_none()); field.set(0); field.set(1); - EXPECT_TRUE(field.hasAll()); - EXPECT_TRUE(!field.hasNone()); + EXPECT_TRUE(field.has_all()); + EXPECT_TRUE(!field.has_none()); - field.setHasNone(); - EXPECT_TRUE(!field.hasAll()); - EXPECT_TRUE(field.hasNone()); + field.set_has_none(); + EXPECT_TRUE(!field.has_all()); + EXPECT_TRUE(field.has_none()); - field.setHasAll(); - EXPECT_TRUE(field.hasAll()); - EXPECT_TRUE(!field.hasNone()); + field.set_has_all(); + EXPECT_TRUE(field.has_all()); + EXPECT_TRUE(!field.has_none()); } { tr_bitfield field(0); - EXPECT_TRUE(!field.hasAll()); - EXPECT_TRUE(!field.hasNone()); + EXPECT_TRUE(!field.has_all()); + EXPECT_TRUE(!field.has_none()); - field.setHasNone(); - EXPECT_TRUE(!field.hasAll()); - EXPECT_TRUE(field.hasNone()); + field.set_has_none(); + EXPECT_TRUE(!field.has_all()); + EXPECT_TRUE(field.has_none()); - field.setHasAll(); - EXPECT_TRUE(field.hasAll()); - EXPECT_TRUE(!field.hasNone()); + field.set_has_all(); + EXPECT_TRUE(field.has_all()); + EXPECT_TRUE(!field.has_none()); } } TEST(Bitfield, percent) { auto field = tr_bitfield{ 100 }; - field.setHasAll(); + field.set_has_all(); EXPECT_NEAR(1.0F, field.percent(), 0.01); - field.setHasNone(); + field.set_has_none(); EXPECT_NEAR(0.0F, field.percent(), 0.01); - field.setSpan(0, std::size(field) / 2U); + field.set_span(0, std::size(field) / 2U); EXPECT_NEAR(0.5F, field.percent(), 0.01); - field.setHasNone(); - field.setSpan(0, std::size(field) / 4U); + field.set_has_none(); + field.set_span(0, std::size(field) / 4U); EXPECT_NEAR(0.25F, field.percent(), 0.01); } @@ -342,33 +342,33 @@ TEST(Bitfield, bitwiseOr) auto a = tr_bitfield{ 100 }; auto b = tr_bitfield{ 100 }; - a.setHasAll(); - b.setHasNone(); + a.set_has_all(); + b.set_has_none(); a |= b; - EXPECT_TRUE(a.hasAll()); + EXPECT_TRUE(a.has_all()); - a.setHasNone(); - b.setHasAll(); + a.set_has_none(); + b.set_has_all(); a |= b; - EXPECT_TRUE(a.hasAll()); + EXPECT_TRUE(a.has_all()); - a.setHasNone(); - b.setHasNone(); + a.set_has_none(); + b.set_has_none(); a |= b; - EXPECT_TRUE(a.hasNone()); + EXPECT_TRUE(a.has_none()); - a.setHasNone(); - b.setHasNone(); - a.setSpan(0, std::size(a) / 2U); - b.setSpan(std::size(a) / 2U, std::size(a)); + a.set_has_none(); + b.set_has_none(); + a.set_span(0, std::size(a) / 2U); + b.set_span(std::size(a) / 2U, std::size(a)); EXPECT_EQ(0.5, a.percent()); EXPECT_EQ(0.5, b.percent()); a |= b; EXPECT_EQ(1.0, a.percent()); - EXPECT_TRUE(a.hasAll()); + EXPECT_TRUE(a.has_all()); - a.setHasNone(); - b.setHasNone(); + a.set_has_none(); + b.set_has_none(); for (size_t i = 0; i < std::size(a); ++i) { if ((i % 2U) != 0U) @@ -383,7 +383,7 @@ TEST(Bitfield, bitwiseOr) EXPECT_NEAR(0.5F, a.percent(), 0.01); EXPECT_NEAR(0.5F, b.percent(), 0.01); a |= b; - EXPECT_TRUE(a.hasAll()); + EXPECT_TRUE(a.has_all()); } TEST(Bitfield, bitwiseAnd) @@ -391,32 +391,32 @@ TEST(Bitfield, bitwiseAnd) auto a = tr_bitfield{ 100 }; auto b = tr_bitfield{ 100 }; - a.setHasAll(); - b.setHasNone(); + a.set_has_all(); + b.set_has_none(); a &= b; - EXPECT_TRUE(a.hasNone()); + EXPECT_TRUE(a.has_none()); - a.setHasNone(); - b.setHasAll(); + a.set_has_none(); + b.set_has_all(); a &= b; - EXPECT_TRUE(a.hasNone()); + EXPECT_TRUE(a.has_none()); - a.setHasAll(); - b.setHasAll(); + a.set_has_all(); + b.set_has_all(); a &= b; - EXPECT_TRUE(a.hasAll()); + EXPECT_TRUE(a.has_all()); - a.setHasNone(); - b.setHasNone(); - a.setSpan(0, std::size(a) / 2U); - b.setSpan(std::size(a) / 2U, std::size(a)); + a.set_has_none(); + b.set_has_none(); + a.set_span(0, std::size(a) / 2U); + b.set_span(std::size(a) / 2U, std::size(a)); EXPECT_EQ(0.5, a.percent()); EXPECT_EQ(0.5, b.percent()); a &= b; - EXPECT_TRUE(a.hasNone()); + EXPECT_TRUE(a.has_none()); - a.setHasNone(); - b.setHasNone(); + a.set_has_none(); + b.set_has_none(); for (size_t i = 0; i < std::size(a); ++i) { if ((i % 2U) != 0U) @@ -429,19 +429,19 @@ TEST(Bitfield, bitwiseAnd) } } a &= b; - EXPECT_TRUE(a.hasNone()); + EXPECT_TRUE(a.has_none()); - a.setHasNone(); - a.setSpan(0U, std::size(a) / 10U); - b.setHasNone(); - b.setSpan(0U, std::size(a) / 20U); + a.set_has_none(); + a.set_span(0U, std::size(a) / 10U); + b.set_has_none(); + b.set_span(0U, std::size(a) / 20U); a &= b; EXPECT_NEAR(0.05F, a.percent(), 0.01); - a.setHasNone(); - a.setSpan(0U, std::size(a) / 10U); - b.setHasNone(); - b.setSpan(0U, std::size(a) / 20U); + a.set_has_none(); + a.set_span(0U, std::size(a) / 10U); + b.set_has_none(); + b.set_span(0U, std::size(a) / 20U); b &= a; EXPECT_NEAR(0.1F, a.percent(), 0.01); } @@ -451,32 +451,32 @@ TEST(Bitfield, intersects) auto a = tr_bitfield{ 100 }; auto b = tr_bitfield{ 100 }; - a.setHasAll(); - b.setHasNone(); + a.set_has_all(); + b.set_has_none(); EXPECT_FALSE(a.intersects(b)); EXPECT_FALSE(b.intersects(a)); - a.setHasAll(); - b.setHasAll(); + a.set_has_all(); + b.set_has_all(); EXPECT_TRUE(a.intersects(b)); EXPECT_TRUE(b.intersects(a)); - a.setHasNone(); - b.setHasNone(); + a.set_has_none(); + b.set_has_none(); EXPECT_FALSE(a.intersects(b)); EXPECT_FALSE(b.intersects(a)); - a.setHasNone(); - b.setHasNone(); - a.setSpan(0, std::size(a) / 2U); - b.setSpan(std::size(a) / 2U, std::size(a)); + a.set_has_none(); + b.set_has_none(); + a.set_span(0, std::size(a) / 2U); + b.set_span(std::size(a) / 2U, std::size(a)); EXPECT_EQ(0.5, a.percent()); EXPECT_EQ(0.5, b.percent()); EXPECT_FALSE(a.intersects(b)); EXPECT_FALSE(b.intersects(a)); - a.setHasNone(); - b.setHasNone(); + a.set_has_none(); + b.set_has_none(); for (size_t i = 0; i < std::size(a); ++i) { if ((i % 2U) != 0U) @@ -491,17 +491,17 @@ TEST(Bitfield, intersects) EXPECT_FALSE(a.intersects(b)); EXPECT_FALSE(b.intersects(a)); - a.setHasNone(); - a.setSpan(0U, std::size(a) / 10U); - b.setHasNone(); - b.setSpan(0U, std::size(a) / 20U); + a.set_has_none(); + a.set_span(0U, std::size(a) / 10U); + b.set_has_none(); + b.set_span(0U, std::size(a) / 20U); EXPECT_TRUE(a.intersects(b)); EXPECT_TRUE(b.intersects(a)); - a.setHasNone(); - a.setSpan(0U, std::size(a) / 10U); - b.setHasNone(); - b.setSpan(0U, std::size(a) / 20U); + a.set_has_none(); + a.set_span(0U, std::size(a) / 10U); + b.set_has_none(); + b.set_span(0U, std::size(a) / 20U); EXPECT_TRUE(a.intersects(b)); EXPECT_TRUE(b.intersects(a)); } diff --git a/tests/libtransmission/block-info-test.cc b/tests/libtransmission/block-info-test.cc index 384354b46..430a68a12 100644 --- a/tests/libtransmission/block-info-test.cc +++ b/tests/libtransmission/block-info-test.cc @@ -22,20 +22,20 @@ TEST_F(BlockInfoTest, fieldsAreSet) static auto constexpr TotalSize = PieceSize * PieceCount; auto info = tr_block_info{}; - info.initSizes(TotalSize, PieceSize); + info.init_sizes(TotalSize, PieceSize); - EXPECT_EQ(ExpectedBlockSize, info.blockSize(info.blockCount() - 1)); - EXPECT_EQ(PieceCount, info.pieceCount()); - EXPECT_EQ(PieceSize, info.pieceSize(info.pieceCount() - 1)); - EXPECT_EQ(PieceSize, info.pieceSize()); - EXPECT_EQ(TotalSize, info.totalSize()); + EXPECT_EQ(ExpectedBlockSize, info.block_size(info.block_count() - 1)); + EXPECT_EQ(PieceCount, info.piece_count()); + EXPECT_EQ(PieceSize, info.piece_size(info.piece_count() - 1)); + EXPECT_EQ(PieceSize, info.piece_size()); + EXPECT_EQ(TotalSize, info.total_size()); - info.initSizes(0, 0); - EXPECT_EQ(0U, info.blockSize(info.blockCount() - 1)); - EXPECT_EQ(0U, info.pieceCount()); - EXPECT_EQ(0U, info.pieceSize(info.pieceCount() - 1)); - EXPECT_EQ(0U, info.pieceSize()); - EXPECT_EQ(0U, info.totalSize()); + info.init_sizes(0, 0); + EXPECT_EQ(0U, info.block_size(info.block_count() - 1)); + EXPECT_EQ(0U, info.piece_count()); + EXPECT_EQ(0U, info.piece_size(info.piece_count() - 1)); + EXPECT_EQ(0U, info.piece_size()); + EXPECT_EQ(0U, info.total_size()); } TEST_F(BlockInfoTest, handlesOddSize) @@ -47,13 +47,13 @@ TEST_F(BlockInfoTest, handlesOddSize) static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U; auto info = tr_block_info{}; - info.initSizes(TotalSize, PieceSize); + info.init_sizes(TotalSize, PieceSize); - EXPECT_EQ(1U, info.blockSize(info.blockCount() - 1)); - EXPECT_EQ(1U, info.pieceSize(info.pieceCount() - 1)); - EXPECT_EQ(PieceCount, info.pieceCount()); - EXPECT_EQ(PieceSize, info.pieceSize()); - EXPECT_EQ(TotalSize, info.totalSize()); + EXPECT_EQ(1U, info.block_size(info.block_count() - 1)); + EXPECT_EQ(1U, info.piece_size(info.piece_count() - 1)); + EXPECT_EQ(PieceCount, info.piece_count()); + EXPECT_EQ(PieceSize, info.piece_size()); + EXPECT_EQ(TotalSize, info.total_size()); } TEST_F(BlockInfoTest, pieceSize) @@ -65,10 +65,10 @@ TEST_F(BlockInfoTest, pieceSize) static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U; auto info = tr_block_info{}; - info.initSizes(TotalSize, PieceSize); + info.init_sizes(TotalSize, PieceSize); - EXPECT_EQ(PieceSize, info.pieceSize(info.pieceCount() - 2)); - EXPECT_EQ(1U, info.pieceSize(info.pieceCount() - 1)); + EXPECT_EQ(PieceSize, info.piece_size(info.piece_count() - 2)); + EXPECT_EQ(1U, info.piece_size(info.piece_count() - 1)); } TEST_F(BlockInfoTest, blockSize) @@ -80,10 +80,10 @@ TEST_F(BlockInfoTest, blockSize) static auto constexpr TotalSize = PieceSize * (PieceCount - 1) + 1; auto info = tr_block_info{}; - info.initSizes(TotalSize, PieceSize); + info.init_sizes(TotalSize, PieceSize); - EXPECT_EQ(ExpectedBlockSize, info.blockSize(info.blockCount() - 2)); - EXPECT_EQ(1U, info.blockSize(info.blockCount() - 1)); + EXPECT_EQ(ExpectedBlockSize, info.block_size(info.block_count() - 2)); + EXPECT_EQ(1U, info.block_size(info.block_count() - 1)); } TEST_F(BlockInfoTest, blockSpanForPiece) @@ -95,19 +95,19 @@ TEST_F(BlockInfoTest, blockSpanForPiece) static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U; auto info = tr_block_info{}; - info.initSizes(TotalSize, PieceSize); + info.init_sizes(TotalSize, PieceSize); - EXPECT_EQ(0U, info.blockSpanForPiece(0).begin); - EXPECT_EQ(4U, info.blockSpanForPiece(0).end); - EXPECT_EQ(12U, info.blockSpanForPiece(3).begin); - EXPECT_EQ(16U, info.blockSpanForPiece(3).end); - EXPECT_EQ(16U, info.blockSpanForPiece(4).begin); - EXPECT_EQ(17U, info.blockSpanForPiece(4).end); + EXPECT_EQ(0U, info.block_span_for_piece(0).begin); + EXPECT_EQ(4U, info.block_span_for_piece(0).end); + EXPECT_EQ(12U, info.block_span_for_piece(3).begin); + EXPECT_EQ(16U, info.block_span_for_piece(3).end); + EXPECT_EQ(16U, info.block_span_for_piece(4).begin); + EXPECT_EQ(17U, info.block_span_for_piece(4).end); // test that uninitialized block_info returns an invalid span info = tr_block_info{}; - EXPECT_EQ(0U, info.blockSpanForPiece(0).begin); - EXPECT_EQ(0U, info.blockSpanForPiece(0).end); + EXPECT_EQ(0U, info.block_span_for_piece(0).begin); + EXPECT_EQ(0U, info.block_span_for_piece(0).end); } TEST_F(BlockInfoTest, blockLoc) @@ -119,14 +119,14 @@ TEST_F(BlockInfoTest, blockLoc) static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U; auto info = tr_block_info{}; - info.initSizes(TotalSize, PieceSize); + info.init_sizes(TotalSize, PieceSize); // begin - auto loc = info.blockLoc(0); + auto loc = info.block_loc(0); EXPECT_EQ(tr_block_info::Location{}, loc); // third block is halfway through the first piece - loc = info.blockLoc(2); + loc = info.block_loc(2); EXPECT_EQ(ExpectedBlockSize * 2U, loc.byte); EXPECT_EQ(2U, loc.block); EXPECT_EQ(0U, loc.block_offset); @@ -134,7 +134,7 @@ TEST_F(BlockInfoTest, blockLoc) EXPECT_EQ(ExpectedBlockSize * 2U, loc.piece_offset); // second piece aligns with fifth block - loc = info.blockLoc(4); + loc = info.block_loc(4); EXPECT_EQ(PieceSize, loc.byte); EXPECT_EQ(4U, loc.block); EXPECT_EQ(0U, loc.block_offset); @@ -151,16 +151,16 @@ TEST_F(BlockInfoTest, pieceLoc) static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U; auto info = tr_block_info{}; - info.initSizes(TotalSize, PieceSize); + info.init_sizes(TotalSize, PieceSize); // begin - auto loc = info.pieceLoc(0); + auto loc = info.piece_loc(0); EXPECT_EQ(tr_block_info::Location{}, loc); for (uint64_t i = 0; i < PieceCount; ++i) { - loc = info.pieceLoc(i); - EXPECT_EQ(info.blockLoc(i * ExpectedBlocksPerPiece), loc); + loc = info.piece_loc(i); + EXPECT_EQ(info.block_loc(i * ExpectedBlocksPerPiece), loc); EXPECT_EQ(PieceSize * i, loc.byte); EXPECT_EQ(ExpectedBlocksPerPiece * i, loc.block); EXPECT_EQ(0U, loc.block_offset); @@ -168,21 +168,21 @@ TEST_F(BlockInfoTest, pieceLoc) EXPECT_EQ(0U, loc.piece_offset); } - loc = info.pieceLoc(0, PieceSize - 1); + loc = info.piece_loc(0, PieceSize - 1); EXPECT_EQ(PieceSize - 1, loc.byte); EXPECT_EQ(ExpectedBlocksPerPiece - 1, loc.block); EXPECT_EQ(ExpectedBlockSize - 1, loc.block_offset); EXPECT_EQ(0U, loc.piece); EXPECT_EQ(PieceSize - 1, loc.piece_offset); - loc = info.pieceLoc(0, PieceSize); + loc = info.piece_loc(0, PieceSize); EXPECT_EQ(PieceSize, loc.byte); EXPECT_EQ(ExpectedBlocksPerPiece, loc.block); EXPECT_EQ(0U, loc.block_offset); EXPECT_EQ(1U, loc.piece); EXPECT_EQ(0U, loc.piece_offset); - loc = info.pieceLoc(0, PieceSize + 1); + loc = info.piece_loc(0, PieceSize + 1); EXPECT_EQ(PieceSize + 1, loc.byte); EXPECT_EQ(ExpectedBlocksPerPiece, loc.block); EXPECT_EQ(1U, loc.block_offset); @@ -199,12 +199,12 @@ TEST_F(BlockInfoTest, byteLoc) static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U; auto info = tr_block_info{}; - info.initSizes(TotalSize, PieceSize); + info.init_sizes(TotalSize, PieceSize); - auto loc = info.byteLoc(0); + auto loc = info.byte_loc(0); EXPECT_EQ(tr_block_info::Location{}, loc); - loc = info.byteLoc(1); + loc = info.byte_loc(1); EXPECT_EQ(1U, loc.byte); EXPECT_EQ(0U, loc.block); EXPECT_EQ(1U, loc.block_offset); @@ -212,7 +212,7 @@ TEST_F(BlockInfoTest, byteLoc) EXPECT_EQ(1U, loc.piece_offset); auto n = ExpectedBlockSize - 1; - loc = info.byteLoc(n); + loc = info.byte_loc(n); EXPECT_EQ(n, loc.byte); EXPECT_EQ(0U, loc.block); EXPECT_EQ(n, loc.block_offset); @@ -220,7 +220,7 @@ TEST_F(BlockInfoTest, byteLoc) EXPECT_EQ(n, loc.piece_offset); n = ExpectedBlockSize; - loc = info.byteLoc(n); + loc = info.byte_loc(n); EXPECT_EQ(n, loc.byte); EXPECT_EQ(1U, loc.block); EXPECT_EQ(0U, loc.block_offset); @@ -228,7 +228,7 @@ TEST_F(BlockInfoTest, byteLoc) EXPECT_EQ(n, loc.piece_offset); n = ExpectedBlockSize + 1; - loc = info.byteLoc(n); + loc = info.byte_loc(n); EXPECT_EQ(n, loc.byte); EXPECT_EQ(1U, loc.block); EXPECT_EQ(1U, loc.block_offset); @@ -236,7 +236,7 @@ TEST_F(BlockInfoTest, byteLoc) EXPECT_EQ(n, loc.piece_offset); n = PieceSize - 1; - loc = info.byteLoc(n); + loc = info.byte_loc(n); EXPECT_EQ(n, loc.byte); EXPECT_EQ(ExpectedBlocksPerPiece - 1, loc.block); EXPECT_EQ(ExpectedBlockSize - 1, loc.block_offset); @@ -244,7 +244,7 @@ TEST_F(BlockInfoTest, byteLoc) EXPECT_EQ(n, loc.piece_offset); n = PieceSize; - loc = info.byteLoc(n); + loc = info.byte_loc(n); EXPECT_EQ(n, loc.byte); EXPECT_EQ(ExpectedBlocksPerPiece, loc.block); EXPECT_EQ(0U, loc.block_offset); diff --git a/tests/libtransmission/completion-test.cc b/tests/libtransmission/completion-test.cc index 691c74880..3dd1e8c49 100644 --- a/tests/libtransmission/completion-test.cc +++ b/tests/libtransmission/completion-test.cc @@ -25,7 +25,7 @@ struct TestTorrent : public tr_completion::torrent_view { std::set dnd_pieces; - [[nodiscard]] bool pieceIsWanted(tr_piece_index_t piece) const final + [[nodiscard]] bool piece_is_wanted(tr_piece_index_t piece) const final { return dnd_pieces.count(piece) == 0; } @@ -41,18 +41,18 @@ TEST_F(CompletionTest, MagnetLink) auto block_info = tr_block_info{}; auto completion = tr_completion(&torrent, &block_info); - EXPECT_FALSE(completion.hasAll()); - EXPECT_TRUE(completion.hasNone()); - EXPECT_FALSE(completion.hasBlocks({ 0, 1 })); - EXPECT_FALSE(completion.hasBlocks({ 0, 1000 })); - EXPECT_FALSE(completion.hasPiece(0)); - EXPECT_DOUBLE_EQ(0.0, completion.percentDone()); - EXPECT_DOUBLE_EQ(0.0, completion.percentComplete()); + EXPECT_FALSE(completion.has_all()); + EXPECT_TRUE(completion.has_none()); + EXPECT_FALSE(completion.has_blocks({ 0, 1 })); + EXPECT_FALSE(completion.has_blocks({ 0, 1000 })); + EXPECT_FALSE(completion.has_piece(0)); + EXPECT_DOUBLE_EQ(0.0, completion.percent_done()); + EXPECT_DOUBLE_EQ(0.0, completion.percent_complete()); EXPECT_EQ(TR_LEECH, completion.status()); - EXPECT_EQ(0, completion.hasTotal()); - EXPECT_EQ(0, completion.hasValid()); - EXPECT_EQ(0, completion.leftUntilDone()); - EXPECT_EQ(0, completion.sizeWhenDone()); + EXPECT_EQ(0, completion.has_total()); + EXPECT_EQ(0, completion.has_valid()); + EXPECT_EQ(0, completion.left_until_done()); + EXPECT_EQ(0, completion.size_when_done()); } TEST_F(CompletionTest, setBlocks) @@ -63,18 +63,18 @@ TEST_F(CompletionTest, setBlocks) auto torrent = TestTorrent{}; auto const block_info = tr_block_info{ TotalSize, PieceSize }; auto completion = tr_completion(&torrent, &block_info); - EXPECT_FALSE(completion.blocks().hasAll()); - EXPECT_FALSE(completion.hasAll()); - EXPECT_EQ(0, completion.hasTotal()); + EXPECT_FALSE(completion.blocks().has_all()); + EXPECT_FALSE(completion.has_all()); + EXPECT_EQ(0, completion.has_total()); - auto bitfield = tr_bitfield{ block_info.blockCount() }; - bitfield.setHasAll(); + auto bitfield = tr_bitfield{ block_info.block_count() }; + bitfield.set_has_all(); // test that the bitfield did get replaced - completion.setBlocks(bitfield); - EXPECT_TRUE(completion.blocks().hasAll()); - EXPECT_TRUE(completion.hasAll()); - EXPECT_EQ(block_info.totalSize(), completion.hasTotal()); + completion.set_blocks(bitfield); + EXPECT_TRUE(completion.blocks().has_all()); + EXPECT_TRUE(completion.has_all()); + EXPECT_EQ(block_info.total_size(), completion.has_total()); } TEST_F(CompletionTest, hasBlock) @@ -85,16 +85,16 @@ TEST_F(CompletionTest, hasBlock) auto const block_info = tr_block_info{ TotalSize, PieceSize }; auto completion = tr_completion(&torrent, &block_info); - EXPECT_FALSE(completion.hasBlock(0)); - EXPECT_FALSE(completion.hasBlock(1)); + EXPECT_FALSE(completion.has_block(0)); + EXPECT_FALSE(completion.has_block(1)); - completion.addBlock(0); - EXPECT_TRUE(completion.hasBlock(0)); - EXPECT_FALSE(completion.hasBlock(1)); + completion.add_block(0); + EXPECT_TRUE(completion.has_block(0)); + EXPECT_FALSE(completion.has_block(1)); - completion.addPiece(0); - EXPECT_TRUE(completion.hasBlock(0)); - EXPECT_TRUE(completion.hasBlock(1)); + completion.add_piece(0); + EXPECT_TRUE(completion.has_block(0)); + EXPECT_TRUE(completion.has_block(1)); } TEST_F(CompletionTest, hasBlocks) @@ -105,12 +105,12 @@ TEST_F(CompletionTest, hasBlocks) auto const block_info = tr_block_info{ TotalSize, PieceSize }; auto completion = tr_completion(&torrent, &block_info); - EXPECT_FALSE(completion.hasBlocks({ 0, 1 })); - EXPECT_FALSE(completion.hasBlocks({ 0, 2 })); + EXPECT_FALSE(completion.has_blocks({ 0, 1 })); + EXPECT_FALSE(completion.has_blocks({ 0, 2 })); - completion.addBlock(0); - EXPECT_TRUE(completion.hasBlocks({ 0, 1 })); - EXPECT_FALSE(completion.hasBlocks({ 0, 2 })); + completion.add_block(0); + EXPECT_TRUE(completion.has_blocks({ 0, 1 })); + EXPECT_FALSE(completion.has_blocks({ 0, 2 })); } TEST_F(CompletionTest, hasNone) @@ -121,10 +121,10 @@ TEST_F(CompletionTest, hasNone) auto const block_info = tr_block_info{ TotalSize, PieceSize }; auto completion = tr_completion(&torrent, &block_info); - EXPECT_TRUE(completion.hasNone()); + EXPECT_TRUE(completion.has_none()); - completion.addBlock(0); - EXPECT_FALSE(completion.hasNone()); + completion.add_block(0); + EXPECT_FALSE(completion.has_none()); } TEST_F(CompletionTest, hasPiece) @@ -136,32 +136,32 @@ TEST_F(CompletionTest, hasPiece) // check that the initial state does not have it auto completion = tr_completion(&torrent, &block_info); - EXPECT_FALSE(completion.hasPiece(0)); - EXPECT_FALSE(completion.hasPiece(1)); - EXPECT_EQ(0, completion.hasValid()); + EXPECT_FALSE(completion.has_piece(0)); + EXPECT_FALSE(completion.has_piece(1)); + EXPECT_EQ(0, completion.has_valid()); // check that adding a piece means we have it - completion.addPiece(0); - EXPECT_TRUE(completion.hasPiece(0)); - EXPECT_FALSE(completion.hasPiece(1)); - EXPECT_EQ(PieceSize, completion.hasValid()); + completion.add_piece(0); + EXPECT_TRUE(completion.has_piece(0)); + EXPECT_FALSE(completion.has_piece(1)); + EXPECT_EQ(PieceSize, completion.has_valid()); // check that removing a piece means we don't have it - completion.removePiece(0); - EXPECT_FALSE(completion.hasPiece(0)); - EXPECT_FALSE(completion.hasPiece(1)); - EXPECT_EQ(0, completion.hasValid()); + completion.remove_piece(0); + EXPECT_FALSE(completion.has_piece(0)); + EXPECT_FALSE(completion.has_piece(1)); + EXPECT_EQ(0, completion.has_valid()); // check that adding all the blocks in a piece means we have it - for (tr_block_index_t i = 1, n = block_info.pieceLoc(1).block; i < n; ++i) + for (tr_block_index_t i = 1, n = block_info.piece_loc(1).block; i < n; ++i) { - completion.addBlock(i); + completion.add_block(i); } - EXPECT_FALSE(completion.hasPiece(0)); - EXPECT_EQ(0, completion.hasValid()); - completion.addBlock(0); - EXPECT_TRUE(completion.hasPiece(0)); - EXPECT_EQ(PieceSize, completion.hasValid()); + EXPECT_FALSE(completion.has_piece(0)); + EXPECT_EQ(0, completion.has_valid()); + completion.add_block(0); + EXPECT_TRUE(completion.has_piece(0)); + EXPECT_EQ(PieceSize, completion.has_valid()); } TEST_F(CompletionTest, percentCompleteAndDone) @@ -173,16 +173,16 @@ TEST_F(CompletionTest, percentCompleteAndDone) // check that in blank-slate initial state, isDone() is false auto completion = tr_completion(&torrent, &block_info); - EXPECT_DOUBLE_EQ(0.0, completion.percentComplete()); - EXPECT_DOUBLE_EQ(0.0, completion.percentDone()); + EXPECT_DOUBLE_EQ(0.0, completion.percent_complete()); + EXPECT_DOUBLE_EQ(0.0, completion.percent_done()); // add half the pieces for (size_t i = 0; i < 32; ++i) { - completion.addPiece(i); + completion.add_piece(i); } - EXPECT_DOUBLE_EQ(0.5, completion.percentComplete()); - EXPECT_DOUBLE_EQ(0.5, completion.percentDone()); + EXPECT_DOUBLE_EQ(0.5, completion.percent_complete()); + EXPECT_DOUBLE_EQ(0.5, completion.percent_done()); // but marking some of the pieces we have as unwanted // should not change percentDone @@ -190,9 +190,9 @@ TEST_F(CompletionTest, percentCompleteAndDone) { torrent.dnd_pieces.insert(i); } - completion.invalidateSizeWhenDone(); - EXPECT_DOUBLE_EQ(0.5, completion.percentComplete()); - EXPECT_DOUBLE_EQ(0.5, completion.percentDone()); + completion.invalidate_size_when_done(); + EXPECT_DOUBLE_EQ(0.5, completion.percent_complete()); + EXPECT_DOUBLE_EQ(0.5, completion.percent_done()); // but marking some of the pieces we DON'T have as unwanted // SHOULD change percentDone @@ -200,9 +200,9 @@ TEST_F(CompletionTest, percentCompleteAndDone) { torrent.dnd_pieces.insert(i); } - completion.invalidateSizeWhenDone(); - EXPECT_DOUBLE_EQ(0.5, completion.percentComplete()); - EXPECT_DOUBLE_EQ(2.0 / 3.0, completion.percentDone()); + completion.invalidate_size_when_done(); + EXPECT_DOUBLE_EQ(0.5, completion.percent_complete()); + EXPECT_DOUBLE_EQ(2.0 / 3.0, completion.percent_done()); } TEST_F(CompletionTest, hasTotalAndValid) @@ -214,33 +214,33 @@ TEST_F(CompletionTest, hasTotalAndValid) // check that the initial blank-slate state has nothing auto completion = tr_completion(&torrent, &block_info); - EXPECT_EQ(0, completion.hasTotal()); - EXPECT_EQ(completion.hasValid(), completion.hasTotal()); + EXPECT_EQ(0, completion.has_total()); + EXPECT_EQ(completion.has_valid(), completion.has_total()); // check that adding the final piece adjusts by block_info.final_piece_size - completion.setHasPiece(block_info.pieceCount() - 1, true); - EXPECT_EQ(block_info.pieceSize(block_info.pieceCount() - 1), completion.hasTotal()); - EXPECT_EQ(completion.hasValid(), completion.hasTotal()); + completion.set_has_piece(block_info.piece_count() - 1, true); + EXPECT_EQ(block_info.piece_size(block_info.piece_count() - 1), completion.has_total()); + EXPECT_EQ(completion.has_valid(), completion.has_total()); // check that adding a non-final piece adjusts by block_info.pieceSize() - completion.setHasPiece(0, true); - EXPECT_EQ(block_info.pieceSize(block_info.pieceCount() - 1) + block_info.pieceSize(), completion.hasTotal()); - EXPECT_EQ(completion.hasValid(), completion.hasTotal()); + completion.set_has_piece(0, true); + EXPECT_EQ(block_info.piece_size(block_info.piece_count() - 1) + block_info.piece_size(), completion.has_total()); + EXPECT_EQ(completion.has_valid(), completion.has_total()); // check that removing the final piece adjusts by block_info.final_piece_size - completion.setHasPiece(block_info.pieceCount() - 1, false); - EXPECT_EQ(block_info.pieceSize(), completion.hasValid()); - EXPECT_EQ(completion.hasValid(), completion.hasTotal()); + completion.set_has_piece(block_info.piece_count() - 1, false); + EXPECT_EQ(block_info.piece_size(), completion.has_valid()); + EXPECT_EQ(completion.has_valid(), completion.has_total()); // check that removing a non-final piece adjusts by block_info.pieceSize() - completion.setHasPiece(0, false); - EXPECT_EQ(0, completion.hasValid()); - EXPECT_EQ(completion.hasValid(), completion.hasTotal()); + completion.set_has_piece(0, false); + EXPECT_EQ(0, completion.has_valid()); + EXPECT_EQ(completion.has_valid(), completion.has_total()); // check that adding an incomplete piece adjusts hasTotal but not hasValid - completion.addBlock(0); - EXPECT_EQ(0, completion.hasValid()); - EXPECT_EQ(BlockSize, completion.hasTotal()); + completion.add_block(0); + EXPECT_EQ(0, completion.has_valid()); + EXPECT_EQ(BlockSize, completion.has_total()); } TEST_F(CompletionTest, leftUntilDone) @@ -252,43 +252,43 @@ TEST_F(CompletionTest, leftUntilDone) // check that the initial blank-slate state has nothing auto completion = tr_completion(&torrent, &block_info); - EXPECT_EQ(block_info.totalSize(), completion.leftUntilDone()); + EXPECT_EQ(block_info.total_size(), completion.left_until_done()); // check that adding the final piece adjusts by block_info.final_piece_size - completion.addPiece(block_info.pieceCount() - 1); - EXPECT_EQ(block_info.totalSize() - block_info.pieceSize(block_info.pieceCount() - 1), completion.leftUntilDone()); + completion.add_piece(block_info.piece_count() - 1); + EXPECT_EQ(block_info.total_size() - block_info.piece_size(block_info.piece_count() - 1), completion.left_until_done()); // check that adding a non-final piece adjusts by block_info.pieceSize() - completion.addPiece(0); + completion.add_piece(0); EXPECT_EQ( - block_info.totalSize() - block_info.pieceSize(block_info.pieceCount() - 1) - block_info.pieceSize(), - completion.leftUntilDone()); + block_info.total_size() - block_info.piece_size(block_info.piece_count() - 1) - block_info.piece_size(), + completion.left_until_done()); // check that removing the final piece adjusts by block_info.final_piece_size - completion.removePiece(block_info.pieceCount() - 1); - EXPECT_EQ(block_info.totalSize() - block_info.pieceSize(), completion.leftUntilDone()); + completion.remove_piece(block_info.piece_count() - 1); + EXPECT_EQ(block_info.total_size() - block_info.piece_size(), completion.left_until_done()); // check that dnd-flagging a piece we already have affects nothing torrent.dnd_pieces.insert(0); - completion.invalidateSizeWhenDone(); - EXPECT_EQ(block_info.totalSize() - block_info.pieceSize(), completion.leftUntilDone()); + completion.invalidate_size_when_done(); + EXPECT_EQ(block_info.total_size() - block_info.piece_size(), completion.left_until_done()); torrent.dnd_pieces.clear(); - completion.invalidateSizeWhenDone(); + completion.invalidate_size_when_done(); // check that dnd-flagging a piece we DON'T already have adjusts by block_info.pieceSize() torrent.dnd_pieces.insert(1); - completion.invalidateSizeWhenDone(); - EXPECT_EQ(block_info.totalSize() - block_info.pieceSize() * uint64_t{ 2U }, completion.leftUntilDone()); + completion.invalidate_size_when_done(); + EXPECT_EQ(block_info.total_size() - block_info.piece_size() * uint64_t{ 2U }, completion.left_until_done()); torrent.dnd_pieces.clear(); - completion.invalidateSizeWhenDone(); + completion.invalidate_size_when_done(); // check that removing a non-final piece adjusts by block_info.pieceSize() - completion.removePiece(0); - EXPECT_EQ(block_info.totalSize(), completion.leftUntilDone()); + completion.remove_piece(0); + EXPECT_EQ(block_info.total_size(), completion.left_until_done()); // check that adding a block adjusts by block_info.block_size - completion.addBlock(0); - EXPECT_EQ(block_info.totalSize() - tr_block_info::BlockSize, completion.leftUntilDone()); + completion.add_block(0); + EXPECT_EQ(block_info.total_size() - tr_block_info::BlockSize, completion.left_until_done()); } TEST_F(CompletionTest, sizeWhenDone) @@ -300,30 +300,30 @@ TEST_F(CompletionTest, sizeWhenDone) // check that adding or removing blocks or pieces does not affect sizeWhenDone auto completion = tr_completion(&torrent, &block_info); - EXPECT_EQ(block_info.totalSize(), completion.sizeWhenDone()); - completion.addBlock(0); - EXPECT_EQ(block_info.totalSize(), completion.sizeWhenDone()); - completion.addPiece(0); - EXPECT_EQ(block_info.totalSize(), completion.sizeWhenDone()); - completion.removePiece(0); - EXPECT_EQ(block_info.totalSize(), completion.sizeWhenDone()); + EXPECT_EQ(block_info.total_size(), completion.size_when_done()); + completion.add_block(0); + EXPECT_EQ(block_info.total_size(), completion.size_when_done()); + completion.add_piece(0); + EXPECT_EQ(block_info.total_size(), completion.size_when_done()); + completion.remove_piece(0); + EXPECT_EQ(block_info.total_size(), completion.size_when_done()); // check that flagging complete pieces as dnd does not affect sizeWhenDone for (size_t i = 0; i < 32; ++i) { - completion.addPiece(i); + completion.add_piece(i); torrent.dnd_pieces.insert(i); } - completion.invalidateSizeWhenDone(); - EXPECT_EQ(block_info.totalSize(), completion.sizeWhenDone()); + completion.invalidate_size_when_done(); + EXPECT_EQ(block_info.total_size(), completion.size_when_done()); // check that flagging missing pieces as dnd does not affect sizeWhenDone for (size_t i = 32; i < 48; ++i) { torrent.dnd_pieces.insert(i); } - completion.invalidateSizeWhenDone(); - EXPECT_EQ(block_info.totalSize() - uint64_t{ 16U } * block_info.pieceSize(), completion.sizeWhenDone()); + completion.invalidate_size_when_done(); + EXPECT_EQ(block_info.total_size() - uint64_t{ 16U } * block_info.piece_size(), completion.size_when_done()); } TEST_F(CompletionTest, createPieceBitfield) @@ -336,23 +336,23 @@ TEST_F(CompletionTest, createPieceBitfield) // make a completion object that has a random assortment of pieces auto completion = tr_completion(&torrent, &block_info); auto buf = tr_rand_obj>(); - ASSERT_EQ(std::size(buf), block_info.pieceCount()); - for (uint64_t i = 0; i < block_info.pieceCount(); ++i) + ASSERT_EQ(std::size(buf), block_info.piece_count()); + for (uint64_t i = 0; i < block_info.piece_count(); ++i) { if ((buf[i] % 2) != 0) { - completion.addPiece(i); + completion.add_piece(i); } } // serialize it to a raw bitfield, read it back into a bitfield, // and test that the new bitfield matches - auto const pieces_raw_bitfield = completion.createPieceBitfield(); - tr_bitfield pieces{ size_t{ block_info.pieceCount() } }; - pieces.setRaw(std::data(pieces_raw_bitfield), std::size(pieces_raw_bitfield)); - for (uint64_t i = 0; i < block_info.pieceCount(); ++i) + auto const pieces_raw_bitfield = completion.create_piece_bitfield(); + tr_bitfield pieces{ size_t{ block_info.piece_count() } }; + pieces.set_raw(std::data(pieces_raw_bitfield), std::size(pieces_raw_bitfield)); + for (uint64_t i = 0; i < block_info.piece_count(); ++i) { - EXPECT_EQ(completion.hasPiece(i), pieces.test(i)); + EXPECT_EQ(completion.has_piece(i), pieces.test(i)); } } @@ -368,19 +368,19 @@ TEST_F(CompletionTest, countMissingBytesInPiece) auto const block_info = tr_block_info{ TotalSize, PieceSize }; auto completion = tr_completion(&torrent, &block_info); - EXPECT_EQ(block_info.pieceSize(0), completion.countMissingBytesInPiece(0)); - completion.addBlock(0); - EXPECT_EQ(block_info.pieceSize(0) - tr_block_info::BlockSize, completion.countMissingBytesInPiece(0)); - completion.addPiece(0); - EXPECT_EQ(0U, completion.countMissingBytesInPiece(0)); + EXPECT_EQ(block_info.piece_size(0), completion.count_missing_bytes_in_piece(0)); + completion.add_block(0); + EXPECT_EQ(block_info.piece_size(0) - tr_block_info::BlockSize, completion.count_missing_bytes_in_piece(0)); + completion.add_piece(0); + EXPECT_EQ(0U, completion.count_missing_bytes_in_piece(0)); - auto const final_piece = block_info.pieceCount() - 1; - auto const final_block = block_info.blockCount() - 1; - EXPECT_EQ(block_info.pieceSize(final_piece), completion.countMissingBytesInPiece(final_piece)); - completion.addBlock(final_block); - EXPECT_EQ(1U, block_info.pieceSize(block_info.pieceCount() - 1)); - EXPECT_TRUE(completion.hasPiece(final_piece)); - EXPECT_EQ(0U, completion.countMissingBytesInPiece(final_piece)); + auto const final_piece = block_info.piece_count() - 1; + auto const final_block = block_info.block_count() - 1; + EXPECT_EQ(block_info.piece_size(final_piece), completion.count_missing_bytes_in_piece(final_piece)); + completion.add_block(final_block); + EXPECT_EQ(1U, block_info.piece_size(block_info.piece_count() - 1)); + EXPECT_TRUE(completion.has_piece(final_piece)); + EXPECT_EQ(0U, completion.count_missing_bytes_in_piece(final_piece)); } TEST_F(CompletionTest, amountDone) @@ -394,35 +394,35 @@ TEST_F(CompletionTest, amountDone) // make bins s.t. each bin is a single piece auto bins = std::array{}; - for (tr_piece_index_t piece = 0; piece < block_info.pieceCount(); ++piece) + for (tr_piece_index_t piece = 0; piece < block_info.piece_count(); ++piece) { - completion.removePiece(piece); + completion.remove_piece(piece); } - completion.amountDone(std::data(bins), std::size(bins)); + completion.amount_done(std::data(bins), std::size(bins)); std::for_each(std::begin(bins), std::end(bins), [](float bin) { EXPECT_DOUBLE_EQ(0.0, bin); }); // one block - completion.addBlock(0); - completion.amountDone(std::data(bins), std::size(bins)); + completion.add_block(0); + completion.amount_done(std::data(bins), std::size(bins)); EXPECT_DOUBLE_EQ(0.0, bins[1]); // one piece - completion.addPiece(0); - completion.amountDone(std::data(bins), std::size(bins)); + completion.add_piece(0); + completion.amount_done(std::data(bins), std::size(bins)); EXPECT_DOUBLE_EQ(1.0, bins[0]); EXPECT_DOUBLE_EQ(0.0, bins[1]); // all pieces - for (tr_piece_index_t piece = 0; piece < block_info.pieceCount(); ++piece) + for (tr_piece_index_t piece = 0; piece < block_info.piece_count(); ++piece) { - completion.addPiece(piece); + completion.add_piece(piece); } - completion.amountDone(std::data(bins), std::size(bins)); + completion.amount_done(std::data(bins), std::size(bins)); std::for_each(std::begin(bins), std::end(bins), [](float bin) { EXPECT_DOUBLE_EQ(1.0, bin); }); // don't do anything if fed bad input auto const backup = bins; - completion.amountDone(std::data(bins), 0); + completion.amount_done(std::data(bins), 0); EXPECT_EQ(backup, bins); } @@ -436,39 +436,39 @@ TEST_F(CompletionTest, countHasBytesInSpan) auto completion = tr_completion(&torrent, &block_info); // torrent is complete - auto blocks = tr_bitfield{ block_info.blockCount() }; - blocks.setHasAll(); - completion.setBlocks(blocks); + auto blocks = tr_bitfield{ block_info.block_count() }; + blocks.set_has_all(); + completion.set_blocks(blocks); - EXPECT_EQ(TotalSize, completion.countHasBytesInSpan({ 0, TotalSize })); - EXPECT_EQ(TotalSize, completion.countHasBytesInSpan({ 0, TotalSize + 1 })); + EXPECT_EQ(TotalSize, completion.count_has_bytes_in_span({ 0, TotalSize })); + EXPECT_EQ(TotalSize, completion.count_has_bytes_in_span({ 0, TotalSize + 1 })); // test span that's entirely in a single block - EXPECT_EQ(1, completion.countHasBytesInSpan({ 16, 17 })); - EXPECT_EQ(16, completion.countHasBytesInSpan({ 16, 32 })); + EXPECT_EQ(1, completion.count_has_bytes_in_span({ 16, 17 })); + EXPECT_EQ(16, completion.count_has_bytes_in_span({ 16, 32 })); // test edge cases on block boundary - EXPECT_EQ(1, completion.countHasBytesInSpan({ BlockSize - 1, BlockSize })); - EXPECT_EQ(1, completion.countHasBytesInSpan({ BlockSize, BlockSize + 1 })); - EXPECT_EQ(2, completion.countHasBytesInSpan({ BlockSize - 1, BlockSize + 1 })); + EXPECT_EQ(1, completion.count_has_bytes_in_span({ BlockSize - 1, BlockSize })); + EXPECT_EQ(1, completion.count_has_bytes_in_span({ BlockSize, BlockSize + 1 })); + EXPECT_EQ(2, completion.count_has_bytes_in_span({ BlockSize - 1, BlockSize + 1 })); // test edge cases on piece boundary - EXPECT_EQ(1, completion.countHasBytesInSpan({ PieceSize - 1, PieceSize })); - EXPECT_EQ(1, completion.countHasBytesInSpan({ PieceSize, PieceSize + 1 })); - EXPECT_EQ(2, completion.countHasBytesInSpan({ PieceSize - 1, PieceSize + 1 })); + EXPECT_EQ(1, completion.count_has_bytes_in_span({ PieceSize - 1, PieceSize })); + EXPECT_EQ(1, completion.count_has_bytes_in_span({ PieceSize, PieceSize + 1 })); + EXPECT_EQ(2, completion.count_has_bytes_in_span({ PieceSize - 1, PieceSize + 1 })); // test span that has a middle block - EXPECT_EQ(BlockSize * 3, completion.countHasBytesInSpan({ 0, BlockSize * 3 })); - EXPECT_EQ(BlockSize * 2, completion.countHasBytesInSpan({ BlockSize / 2, BlockSize * 2 + BlockSize / 2 })); + EXPECT_EQ(BlockSize * 3, completion.count_has_bytes_in_span({ 0, BlockSize * 3 })); + EXPECT_EQ(BlockSize * 2, completion.count_has_bytes_in_span({ BlockSize / 2, BlockSize * 2 + BlockSize / 2 })); // test span where first block is missing blocks.unset(0); - completion.setBlocks(blocks); - EXPECT_EQ(BlockSize * 2, completion.countHasBytesInSpan({ 0, BlockSize * 3 })); - EXPECT_EQ(BlockSize * 1.5, completion.countHasBytesInSpan({ BlockSize / 2, BlockSize * 2 + BlockSize / 2 })); + completion.set_blocks(blocks); + EXPECT_EQ(BlockSize * 2, completion.count_has_bytes_in_span({ 0, BlockSize * 3 })); + EXPECT_EQ(BlockSize * 1.5, completion.count_has_bytes_in_span({ BlockSize / 2, BlockSize * 2 + BlockSize / 2 })); // test span where final block is missing - blocks.setHasAll(); + blocks.set_has_all(); blocks.unset(2); - completion.setBlocks(blocks); - EXPECT_EQ(BlockSize * 2, completion.countHasBytesInSpan({ 0, BlockSize * 3 })); - EXPECT_EQ(BlockSize * 1.5, completion.countHasBytesInSpan({ BlockSize / 2, BlockSize * 2 + BlockSize / 2 })); + completion.set_blocks(blocks); + EXPECT_EQ(BlockSize * 2, completion.count_has_bytes_in_span({ 0, BlockSize * 3 })); + EXPECT_EQ(BlockSize * 1.5, completion.count_has_bytes_in_span({ BlockSize / 2, BlockSize * 2 + BlockSize / 2 })); } TEST_F(CompletionTest, wantNone) @@ -480,27 +480,27 @@ TEST_F(CompletionTest, wantNone) auto completion = tr_completion(&torrent, &block_info); // we have some data - completion.addBlock(0); + completion.add_block(0); // and want nothing - for (tr_piece_index_t i = 0, n = block_info.blockCount(); i < n; ++i) + for (tr_piece_index_t i = 0, n = block_info.block_count(); i < n; ++i) { torrent.dnd_pieces.insert(i); } - completion.invalidateSizeWhenDone(); + completion.invalidate_size_when_done(); - EXPECT_LE(completion.hasTotal(), completion.sizeWhenDone()); - EXPECT_EQ(completion.hasTotal(), block_info.BlockSize); - EXPECT_EQ(completion.sizeWhenDone(), block_info.BlockSize); - EXPECT_LE(completion.leftUntilDone(), completion.sizeWhenDone()); - EXPECT_EQ(completion.leftUntilDone(), 0); + EXPECT_LE(completion.has_total(), completion.size_when_done()); + EXPECT_EQ(completion.has_total(), block_info.BlockSize); + EXPECT_EQ(completion.size_when_done(), block_info.BlockSize); + EXPECT_LE(completion.left_until_done(), completion.size_when_done()); + EXPECT_EQ(completion.left_until_done(), 0); // but we magically get a block anyway - completion.addBlock(1); + completion.add_block(1); - EXPECT_LE(completion.hasTotal(), completion.sizeWhenDone()); - EXPECT_EQ(completion.hasTotal(), 2 * block_info.BlockSize); - EXPECT_EQ(completion.sizeWhenDone(), 2 * block_info.BlockSize); - EXPECT_LE(completion.leftUntilDone(), completion.sizeWhenDone()); - EXPECT_EQ(completion.leftUntilDone(), 0); + EXPECT_LE(completion.has_total(), completion.size_when_done()); + EXPECT_EQ(completion.has_total(), 2 * block_info.BlockSize); + EXPECT_EQ(completion.size_when_done(), 2 * block_info.BlockSize); + EXPECT_LE(completion.left_until_done(), completion.size_when_done()); + EXPECT_EQ(completion.left_until_done(), 0); } diff --git a/tests/libtransmission/file-piece-map-test.cc b/tests/libtransmission/file-piece-map-test.cc index bc90e0592..a42f1088b 100644 --- a/tests/libtransmission/file-piece-map-test.cc +++ b/tests/libtransmission/file-piece-map-test.cc @@ -50,9 +50,9 @@ protected: FileSizes[14] + FileSizes[15] + FileSizes[16] == TotalSize); - EXPECT_EQ(11U, block_info_.pieceCount()); - EXPECT_EQ(PieceSize, block_info_.pieceSize()); - EXPECT_EQ(TotalSize, block_info_.totalSize()); + EXPECT_EQ(11U, block_info_.piece_count()); + EXPECT_EQ(PieceSize, block_info_.piece_size()); + EXPECT_EQ(TotalSize, block_info_.total_size()); EXPECT_EQ(TotalSize, std::accumulate(std::begin(FileSizes), std::end(FileSizes), uint64_t{ 0 })); } }; @@ -62,26 +62,26 @@ TEST_F(FilePieceMapTest, fileOffset) auto const fpm = tr_file_piece_map{ block_info_, std::data(FileSizes), std::size(FileSizes) }; // first byte of the first file - auto file_offset = fpm.fileOffset(0); + auto file_offset = fpm.file_offset(0); EXPECT_EQ(0U, file_offset.index); EXPECT_EQ(0U, file_offset.offset); // final byte of the first file - file_offset = fpm.fileOffset(FileSizes[0] - 1); + file_offset = fpm.file_offset(FileSizes[0] - 1); EXPECT_EQ(0U, file_offset.index); EXPECT_EQ(FileSizes[0] - 1, file_offset.offset); // first byte of the second file // NB: this is an edge case, second file is 0 bytes. // The second nonzero file is file #5 - file_offset = fpm.fileOffset(FileSizes[0]); + file_offset = fpm.file_offset(FileSizes[0]); EXPECT_EQ(5U, file_offset.index); EXPECT_EQ(0U, file_offset.offset); // the last byte of in the torrent. // NB: reverse of previous edge case, since // the final 4 files in the torrent are all 0 bytes - file_offset = fpm.fileOffset(TotalSize - 1); + file_offset = fpm.file_offset(TotalSize - 1); EXPECT_EQ(12U, file_offset.index); EXPECT_EQ(FileSizes[12] - 1, file_offset.offset); } @@ -118,12 +118,12 @@ TEST_F(FilePieceMapTest, pieceSpan) uint64_t offset = 0; for (tr_file_index_t file = 0; file < n; ++file) { - EXPECT_EQ(ExpectedPieceSpans[file].begin, fpm.pieceSpan(file).begin); - EXPECT_EQ(ExpectedPieceSpans[file].end, fpm.pieceSpan(file).end); + EXPECT_EQ(ExpectedPieceSpans[file].begin, fpm.piece_span(file).begin); + EXPECT_EQ(ExpectedPieceSpans[file].end, fpm.piece_span(file).end); offset += FileSizes[file]; } EXPECT_EQ(TotalSize, offset); - EXPECT_EQ(block_info_.pieceCount(), fpm.pieceSpan(std::size(FileSizes) - 1).end); + EXPECT_EQ(block_info_.piece_count(), fpm.piece_span(std::size(FileSizes) - 1).end); } TEST_F(FilePieceMapTest, priorities) @@ -134,19 +134,19 @@ TEST_F(FilePieceMapTest, priorities) // make a helper to compare file & piece priorities auto expected_file_priorities = std::vector(n_files, TR_PRI_NORMAL); - auto expected_piece_priorities = std::vector(block_info_.pieceCount(), TR_PRI_NORMAL); + auto expected_piece_priorities = std::vector(block_info_.piece_count(), TR_PRI_NORMAL); auto const compare_to_expected = [&, this]() { for (tr_file_index_t i = 0; i < n_files; ++i) { auto const expected = int{ expected_file_priorities[i] }; - auto const actual = int{ file_priorities.filePriority(i) }; + auto const actual = int{ file_priorities.file_priority(i) }; EXPECT_EQ(expected, actual) << "idx[" << i << "] expected [" << expected << "] actual [" << actual << ']'; } - for (tr_piece_index_t i = 0; i < block_info_.pieceCount(); ++i) + for (tr_piece_index_t i = 0; i < block_info_.piece_count(); ++i) { auto const expected = int{ expected_piece_priorities[i] }; - auto const actual = int{ file_priorities.piecePriority(i) }; + auto const actual = int{ file_priorities.piece_priority(i) }; EXPECT_EQ(expected, actual) << "idx[" << i << "] expected [" << expected << "] actual [" << actual << ']'; } }; @@ -155,7 +155,7 @@ TEST_F(FilePieceMapTest, priorities) { for (tr_file_index_t i = 0; i < n_files; ++i) { - auto const [begin_piece, end_piece] = fpm.pieceSpan(i); + auto const [begin_piece, end_piece] = fpm.piece_span(i); expected_piece_priorities[begin_piece] = TR_PRI_HIGH; if (end_piece > begin_piece) { @@ -295,22 +295,22 @@ TEST_F(FilePieceMapTest, wanted) // make a helper to compare file & piece priorities auto expected_files_wanted = tr_bitfield(n_files); - auto expected_pieces_wanted = tr_bitfield(block_info_.pieceCount()); + auto expected_pieces_wanted = tr_bitfield(block_info_.piece_count()); auto const compare_to_expected = [&, this]() { for (tr_file_index_t i = 0; i < n_files; ++i) { - EXPECT_EQ(int(expected_files_wanted.test(i)), int(files_wanted.fileWanted(i))); + EXPECT_EQ(int(expected_files_wanted.test(i)), int(files_wanted.file_wanted(i))); } - for (tr_piece_index_t i = 0; i < block_info_.pieceCount(); ++i) + for (tr_piece_index_t i = 0; i < block_info_.piece_count(); ++i) { - EXPECT_EQ(int(expected_pieces_wanted.test(i)), int(files_wanted.pieceWanted(i))); + EXPECT_EQ(int(expected_pieces_wanted.test(i)), int(files_wanted.piece_wanted(i))); } }; // check everything is wanted by default - expected_files_wanted.setHasAll(); - expected_pieces_wanted.setHasAll(); + expected_files_wanted.set_has_all(); + expected_pieces_wanted.set_has_all(); compare_to_expected(); // set the first file as not wanted. @@ -319,7 +319,7 @@ TEST_F(FilePieceMapTest, wanted) bool const wanted = false; files_wanted.set(0, wanted); expected_files_wanted.set(0, wanted); - expected_pieces_wanted.setSpan(0, 5, wanted); + expected_pieces_wanted.set_span(0, 5, wanted); compare_to_expected(); // now test when a piece has >1 file. @@ -343,7 +343,7 @@ TEST_F(FilePieceMapTest, wanted) files_wanted.set(4, false); files_wanted.set(5, false); files_wanted.set(6, false); - expected_files_wanted.setSpan(1, 7, false); + expected_files_wanted.set_span(1, 7, false); expected_pieces_wanted.unset(5); compare_to_expected(); // but as soon as any of them is turned back to wanted, @@ -368,8 +368,8 @@ TEST_F(FilePieceMapTest, wanted) { files_wanted.set(i, false); } - expected_files_wanted.setHasNone(); - expected_pieces_wanted.setHasNone(); + expected_files_wanted.set_has_none(); + expected_pieces_wanted.set_has_none(); compare_to_expected(); // *Sigh* OK what happens to files_wanted if you say the only @@ -394,11 +394,11 @@ TEST_F(FilePieceMapTest, wanted) auto file_indices = std::vector(n_files); std::iota(std::begin(file_indices), std::end(file_indices), 0); files_wanted.set(std::data(file_indices), std::size(file_indices), true); - expected_files_wanted.setHasAll(); - expected_pieces_wanted.setHasAll(); + expected_files_wanted.set_has_all(); + expected_pieces_wanted.set_has_all(); compare_to_expected(); files_wanted.set(std::data(file_indices), std::size(file_indices), false); - expected_files_wanted.setHasNone(); - expected_pieces_wanted.setHasNone(); + expected_files_wanted.set_has_none(); + expected_pieces_wanted.set_has_none(); compare_to_expected(); } diff --git a/tests/libtransmission/magnet-metainfo-test.cc b/tests/libtransmission/magnet-metainfo-test.cc index ac8bec91c..9a98686c4 100644 --- a/tests/libtransmission/magnet-metainfo-test.cc +++ b/tests/libtransmission/magnet-metainfo-test.cc @@ -65,8 +65,8 @@ TEST(MagnetMetainfo, magnetParse) auto mm = tr_magnet_metainfo{}; EXPECT_TRUE(mm.parseMagnet(uri)); - EXPECT_EQ(2U, std::size(mm.announceList())); - auto it = std::begin(mm.announceList()); + EXPECT_EQ(2U, std::size(mm.announce_list())); + auto it = std::begin(mm.announce_list()); EXPECT_EQ(0U, it->tier); EXPECT_EQ("http://tracker.openbittorrent.com/announce"sv, it->announce.sv()); EXPECT_EQ("http://tracker.openbittorrent.com/scrape"sv, it->scrape.sv()); @@ -74,10 +74,10 @@ TEST(MagnetMetainfo, magnetParse) EXPECT_EQ(1U, it->tier); EXPECT_EQ("http://tracker.opentracker.org/announce", it->announce.sv()); EXPECT_EQ("http://tracker.opentracker.org/scrape", it->scrape.sv()); - EXPECT_EQ(1U, mm.webseedCount()); + EXPECT_EQ(1U, mm.webseed_count()); EXPECT_EQ("http://server.webseed.org/path/to/file"sv, mm.webseed(0)); EXPECT_EQ("Display Name"sv, mm.name()); - EXPECT_EQ(ExpectedHash, mm.infoHash()); + EXPECT_EQ(ExpectedHash, mm.info_hash()); } for (auto const& uri : { "2I2UAEFDZJFN4W3UE65QSOTCUOEZ744B"sv, "d2354010a3ca4ade5b7427bb093a62a3899ff381"sv }) @@ -85,9 +85,9 @@ TEST(MagnetMetainfo, magnetParse) auto mm = tr_magnet_metainfo{}; EXPECT_TRUE(mm.parseMagnet(uri)); - EXPECT_EQ(0U, std::size(mm.announceList())); - EXPECT_EQ(0U, mm.webseedCount()); - EXPECT_EQ(ExpectedHash, mm.infoHash()); + EXPECT_EQ(0U, std::size(mm.announce_list())); + EXPECT_EQ(0U, mm.webseed_count()); + EXPECT_EQ(ExpectedHash, mm.info_hash()); } } diff --git a/tests/libtransmission/makemeta-test.cc b/tests/libtransmission/makemeta-test.cc index 47710de54..38c5dcb6a 100644 --- a/tests/libtransmission/makemeta-test.cc +++ b/tests/libtransmission/makemeta-test.cc @@ -69,20 +69,20 @@ protected: EXPECT_EQ(error, nullptr) << *error; auto metainfo = tr_torrent_metainfo{}; - EXPECT_TRUE(metainfo.parseBenc(builder.benc())); - EXPECT_EQ(builder.fileCount(), metainfo.fileCount()); - EXPECT_EQ(builder.pieceSize(), metainfo.pieceSize()); - EXPECT_EQ(builder.totalSize(), metainfo.totalSize()); - EXPECT_EQ(builder.totalSize(), metainfo.totalSize()); - for (size_t i = 0, n = std::min(builder.fileCount(), metainfo.fileCount()); i < n; ++i) + EXPECT_TRUE(metainfo.parse_benc(builder.benc())); + EXPECT_EQ(builder.fileCount(), metainfo.file_count()); + EXPECT_EQ(builder.pieceSize(), metainfo.piece_size()); + EXPECT_EQ(builder.totalSize(), metainfo.total_size()); + EXPECT_EQ(builder.totalSize(), metainfo.total_size()); + for (size_t i = 0, n = std::min(builder.fileCount(), metainfo.file_count()); i < n; ++i) { EXPECT_EQ(builder.fileSize(i), metainfo.files().fileSize(i)); EXPECT_EQ(builder.path(i), metainfo.files().path(i)); } EXPECT_EQ(builder.name(), metainfo.name()); EXPECT_EQ(builder.comment(), metainfo.comment()); - EXPECT_EQ(builder.isPrivate(), metainfo.isPrivate()); - EXPECT_EQ(builder.announceList().toString(), metainfo.announceList().toString()); + EXPECT_EQ(builder.isPrivate(), metainfo.is_private()); + EXPECT_EQ(builder.announceList().toString(), metainfo.announce_list().toString()); return metainfo; } }; @@ -120,7 +120,7 @@ TEST_F(MakemetaTest, isPrivate) { auto builder = tr_metainfo_builder{ filename }; builder.setPrivate(is_private); - EXPECT_EQ(is_private, testBuilder(builder).isPrivate()); + EXPECT_EQ(is_private, testBuilder(builder).is_private()); } } @@ -133,7 +133,7 @@ TEST_F(MakemetaTest, pieceSize) { auto builder = tr_metainfo_builder{ filename }; builder.setPieceSize(piece_size); - EXPECT_EQ(piece_size, testBuilder(builder).pieceSize()); + EXPECT_EQ(piece_size, testBuilder(builder).piece_size()); } } @@ -147,7 +147,7 @@ TEST_F(MakemetaTest, webseeds) builder.setWebseeds(std::vector{ std::string{ Webseed } }); auto const metainfo = testBuilder(builder); - EXPECT_EQ(1U, metainfo.webseedCount()); + EXPECT_EQ(1U, metainfo.webseed_count()); EXPECT_EQ(Webseed, metainfo.webseed(0)); } @@ -168,7 +168,7 @@ TEST_F(MakemetaTest, anonymizeTrue) builder.setAnonymize(true); auto const metainfo = testBuilder(builder); EXPECT_EQ(""sv, metainfo.creator()); - EXPECT_EQ(time_t{}, metainfo.dateCreated()); + EXPECT_EQ(time_t{}, metainfo.date_created()); } TEST_F(MakemetaTest, anonymizeFalse) @@ -181,8 +181,8 @@ TEST_F(MakemetaTest, anonymizeFalse) auto const metainfo = testBuilder(builder); EXPECT_TRUE(tr_strvContains(metainfo.creator(), TR_NAME)) << metainfo.creator(); auto const now = time(nullptr); - EXPECT_LE(metainfo.dateCreated(), now); - EXPECT_LE(now - 60, metainfo.dateCreated()); + EXPECT_LE(metainfo.date_created(), now); + EXPECT_LE(now - 60, metainfo.date_created()); } TEST_F(MakemetaTest, nameIsRootMultifile) @@ -291,12 +291,12 @@ TEST_F(MakemetaTest, privateAndSourceHasDifferentInfoHash) builder.setPrivate(true); auto private_metainfo = testBuilder(builder); - EXPECT_NE(base_metainfo.infoHash(), private_metainfo.infoHash()); + EXPECT_NE(base_metainfo.info_hash(), private_metainfo.info_hash()); builder.setSource("FOO"); auto private_source_metainfo = testBuilder(builder); - EXPECT_NE(base_metainfo.infoHash(), private_source_metainfo.infoHash()); - EXPECT_NE(private_metainfo.infoHash(), private_source_metainfo.infoHash()); + EXPECT_NE(base_metainfo.info_hash(), private_source_metainfo.info_hash()); + EXPECT_NE(private_metainfo.info_hash(), private_source_metainfo.info_hash()); } } // namespace libtransmission::test diff --git a/tests/libtransmission/move-test.cc b/tests/libtransmission/move-test.cc index 89978c748..16fbc23af 100644 --- a/tests/libtransmission/move-test.cc +++ b/tests/libtransmission/move-test.cc @@ -58,7 +58,7 @@ TEST_P(IncompleteDirTest, incompleteDir) EXPECT_EQ(path, tr_torrentFindFile(tor, 0)); path.assign(incomplete_dir, '/', tr_torrentFile(tor, 1).name); EXPECT_EQ(path, tr_torrentFindFile(tor, 1)); - EXPECT_EQ(tor->pieceSize(), tr_torrentStat(tor)->leftUntilDone); + EXPECT_EQ(tor->piece_size(), tr_torrentStat(tor)->leftUntilDone); // auto constexpr completeness_unset = tr_completeness { -1 }; // auto completeness = completeness_unset; @@ -93,7 +93,7 @@ TEST_P(IncompleteDirTest, incompleteDir) data.session = session_; data.tor = tor; - auto const [begin, end] = tor->blockSpanForPiece(data.pieceIndex); + auto const [begin, end] = tor->block_span_for_piece(data.pieceIndex); for (tr_block_index_t block_index = begin; block_index < end; ++block_index) { diff --git a/tests/libtransmission/peer-mgr-wishlist-test.cc b/tests/libtransmission/peer-mgr-wishlist-test.cc index 51bc31a06..8dd201434 100644 --- a/tests/libtransmission/peer-mgr-wishlist-test.cc +++ b/tests/libtransmission/peer-mgr-wishlist-test.cc @@ -135,7 +135,7 @@ TEST_F(PeerMgrWishlistTest, doesNotRequestBlocksThatCannotBeRequested) auto requested = tr_bitfield(250); for (auto const& span : spans) { - requested.setSpan(span.begin, span.end); + requested.set_span(span.begin, span.end); } EXPECT_EQ(240U, requested.count()); EXPECT_EQ(0U, requested.count(0, 10)); @@ -262,7 +262,7 @@ TEST_F(PeerMgrWishlistTest, onlyRequestsDupesDuringEndgame) auto requested = tr_bitfield(300); for (auto const& span : spans) { - requested.setSpan(span.begin, span.end); + requested.set_span(span.begin, span.end); } EXPECT_EQ(150U, requested.count()); EXPECT_EQ(0U, requested.count(0, 150)); @@ -275,7 +275,7 @@ TEST_F(PeerMgrWishlistTest, onlyRequestsDupesDuringEndgame) requested = tr_bitfield(300); for (auto const& span : spans) { - requested.setSpan(span.begin, span.end); + requested.set_span(span.begin, span.end); } EXPECT_EQ(300U, requested.count()); EXPECT_EQ(150U, requested.count(0, 150)); @@ -325,7 +325,7 @@ TEST_F(PeerMgrWishlistTest, prefersNearlyCompletePieces) auto requested = tr_bitfield(300); for (auto const& range : ranges) { - requested.setSpan(range.begin, range.end); + requested.set_span(range.begin, range.end); } EXPECT_EQ(10U, requested.count()); EXPECT_EQ(10U, requested.count(0, 100)); @@ -341,7 +341,7 @@ TEST_F(PeerMgrWishlistTest, prefersNearlyCompletePieces) auto requested = tr_bitfield(300); for (auto const& range : ranges) { - requested.setSpan(range.begin, range.end); + requested.set_span(range.begin, range.end); } EXPECT_EQ(20U, requested.count()); EXPECT_EQ(10U, requested.count(0, 100)); diff --git a/tests/libtransmission/rename-test.cc b/tests/libtransmission/rename-test.cc index d038506e5..c0d7792fa 100644 --- a/tests/libtransmission/rename-test.cc +++ b/tests/libtransmission/rename-test.cc @@ -81,7 +81,7 @@ protected: static bool testFileExistsAndConsistsOfThisString(tr_torrent const* tor, tr_file_index_t file_index, std::string_view str) { - if (auto const found = tor->findFile(file_index); found) + if (auto const found = tor->find_file(file_index); found) { EXPECT_TRUE(tr_sys_path_exists(found->filename())); auto contents = std::vector{}; @@ -99,7 +99,7 @@ protected: EXPECT_EQ(TR_STAT_OK, tst->error); EXPECT_EQ(total_size, tst->sizeWhenDone); EXPECT_EQ(total_size, tst->leftUntilDone); - EXPECT_EQ(total_size, tor->totalSize()); + EXPECT_EQ(total_size, tor->total_size()); EXPECT_EQ(0, tst->haveValid); } @@ -137,14 +137,14 @@ TEST_F(RenameTest, singleFilenameTorrent) EXPECT_TRUE(tr_isTorrent(tor)); // sanity check the info - EXPECT_EQ(tr_file_index_t{ 1 }, tor->fileCount()); + EXPECT_EQ(tr_file_index_t{ 1 }, tor->file_count()); EXPECT_STREQ("hello-world.txt", tr_torrentFile(tor, 0).name); // sanity check the (empty) stats blockingTorrentVerify(tor); expectHaveNone(tor, TotalSize); - createSingleFileTorrentContents(tor->currentDir().sv()); + createSingleFileTorrentContents(tor->current_dir().sv()); // sanity check the stats again, now that we've added the file blockingTorrentVerify(tor); @@ -176,7 +176,7 @@ TEST_F(RenameTest, singleFilenameTorrent) **** Now try a rename that should succeed ***/ - auto tmpstr = tr_pathbuf{ tor->currentDir(), "/hello-world.txt" }; + auto tmpstr = tr_pathbuf{ tor->current_dir(), "/hello-world.txt" }; EXPECT_TRUE(tr_sys_path_exists(tmpstr)); EXPECT_STREQ("hello-world.txt", tr_torrentName(tor)); EXPECT_EQ(0, torrentRenameAndWait(tor, tr_torrentName(tor), "foobar")); @@ -185,7 +185,7 @@ TEST_F(RenameTest, singleFilenameTorrent) EXPECT_STREQ("foobar", tr_torrentFile(tor, 0).name); // confirm the file's name is now 'foobar' auto const torrent_filename = tr_torrentFilename(tor); EXPECT_EQ(std::string::npos, torrent_filename.find("foobar")); // confirm torrent file hasn't changed - tmpstr.assign(tor->currentDir(), "/foobar"); + tmpstr.assign(tor->current_dir(), "/foobar"); EXPECT_TRUE(tr_sys_path_exists(tmpstr)); // confirm the file's name is now 'foobar' on the disk EXPECT_TRUE(testFileExistsAndConsistsOfThisString(tor, 0, "hello, world!\n")); // confirm the contents are right @@ -200,7 +200,7 @@ TEST_F(RenameTest, singleFilenameTorrent) **** ...and rename it back again ***/ - tmpstr.assign(tor->currentDir(), "/foobar"); + tmpstr.assign(tor->current_dir(), "/foobar"); EXPECT_TRUE(tr_sys_path_exists(tmpstr)); EXPECT_EQ(0, torrentRenameAndWait(tor, "foobar", "hello-world.txt")); EXPECT_FALSE(tr_sys_path_exists(tmpstr)); @@ -250,8 +250,8 @@ TEST_F(RenameTest, multifileTorrent) // sanity check the info EXPECT_STREQ("Felidae", tr_torrentName(tor)); - EXPECT_EQ(TotalSize, tor->totalSize()); - EXPECT_EQ(tr_file_index_t{ 4 }, tor->fileCount()); + EXPECT_EQ(TotalSize, tor->total_size()); + EXPECT_EQ(tr_file_index_t{ 4 }, tor->file_count()); for (tr_file_index_t i = 0; i < 4; ++i) { @@ -263,7 +263,7 @@ TEST_F(RenameTest, multifileTorrent) expectHaveNone(tor, TotalSize); // build the local data - createMultifileTorrentContents(tor->currentDir().sv()); + createMultifileTorrentContents(tor->current_dir().sv()); // sanity check the (full) stats blockingTorrentVerify(tor); @@ -302,7 +302,7 @@ TEST_F(RenameTest, multifileTorrent) // (while the branch is renamed: confirm that the .resume file remembers the changes) tr_resume::save(tor); // this is a bit dodgy code-wise, but let's make sure the .resume file got the name - tor->setFileSubpath(1, "gabba gabba hey"sv); + tor->set_file_subpath(1, "gabba gabba hey"sv); auto const loaded = tr_resume::load(tor, tr_resume::All, ctor); EXPECT_NE(decltype(loaded){ 0 }, (loaded & tr_resume::Filenames)); EXPECT_EQ(ExpectedFiles[0], tr_torrentFile(tor, 0).name); @@ -439,12 +439,12 @@ TEST_F(RenameTest, partialFile) ***/ auto* tor = zeroTorrentInit(ZeroTorrentState::Partial); - EXPECT_EQ(TotalSize, tor->totalSize()); - EXPECT_EQ(PieceSize, tor->pieceSize()); - EXPECT_EQ(PieceCount, tor->pieceCount()); - EXPECT_EQ("files-filled-with-zeroes/1048576"sv, tor->fileSubpath(0)); - EXPECT_EQ("files-filled-with-zeroes/4096"sv, tor->fileSubpath(1)); - EXPECT_EQ("files-filled-with-zeroes/512"sv, tor->fileSubpath(2)); + EXPECT_EQ(TotalSize, tor->total_size()); + EXPECT_EQ(PieceSize, tor->piece_size()); + EXPECT_EQ(PieceCount, tor->piece_count()); + EXPECT_EQ("files-filled-with-zeroes/1048576"sv, tor->file_subpath(0)); + EXPECT_EQ("files-filled-with-zeroes/4096"sv, tor->file_subpath(1)); + EXPECT_EQ("files-filled-with-zeroes/512"sv, tor->file_subpath(2)); EXPECT_NE(0, tr_torrentFile(tor, 0).have); EXPECT_EQ(Length[0], tr_torrentFile(tor, 0).have + PieceSize); EXPECT_EQ(Length[1], tr_torrentFile(tor, 1).have); @@ -466,14 +466,14 @@ TEST_F(RenameTest, partialFile) for (tr_file_index_t i = 0; i < 3; ++i) { - EXPECT_EQ(strings[i], tor->fileSubpath(i)); + EXPECT_EQ(strings[i], tor->file_subpath(i)); } strings[0] = "foo/bar.part"; for (tr_file_index_t i = 0; i < 3; ++i) { - auto const expected = tr_pathbuf{ tor->currentDir(), '/', strings[i] }; + auto const expected = tr_pathbuf{ tor->current_dir(), '/', strings[i] }; auto const actual = tr_torrentFindFile(tor, i); EXPECT_EQ(expected, actual); } diff --git a/tests/libtransmission/test-fixtures.h b/tests/libtransmission/test-fixtures.h index 5636a5da4..512c144b0 100644 --- a/tests/libtransmission/test-fixtures.h +++ b/tests/libtransmission/test-fixtures.h @@ -459,12 +459,12 @@ protected: if (state != ZeroTorrentState::NoFiles) { auto const* const metainfo = tr_ctorGetMetainfo(ctor); - for (tr_file_index_t i = 0, n = metainfo->fileCount(); i < n; ++i) + for (tr_file_index_t i = 0, n = metainfo->file_count(); i < n; ++i) { auto const base = state == ZeroTorrentState::Partial && tr_sessionIsIncompleteDirEnabled(session_) ? tr_sessionGetIncompleteDir(session_) : tr_sessionGetDownloadDir(session_); - auto const& subpath = metainfo->fileSubpath(i); + auto const& subpath = metainfo->file_subpath(i); auto const partial = state == ZeroTorrentState::Partial && i == 0; auto const suffix = std::string_view{ partial ? ".part" : "" }; auto const filename = tr_pathbuf{ base, '/', subpath, suffix }; @@ -474,10 +474,10 @@ protected: tr_sys_dir_create(dirname, TR_SYS_DIR_CREATE_PARENTS, 0700); auto fd = tr_sys_file_open(filename, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_TRUNCATE, 0600); - auto const file_size = metainfo->fileSize(i); + auto const file_size = metainfo->file_size(i); for (uint64_t j = 0; j < file_size; ++j) { - auto const ch = partial && j < metainfo->pieceSize() ? '\1' : '\0'; + auto const ch = partial && j < metainfo->piece_size() ? '\1' : '\0'; tr_sys_file_write(fd, &ch, 1, nullptr); } diff --git a/tests/libtransmission/torrent-magnet-test.cc b/tests/libtransmission/torrent-magnet-test.cc index d812ad4f6..f38ed9bd6 100644 --- a/tests/libtransmission/torrent-magnet-test.cc +++ b/tests/libtransmission/torrent-magnet-test.cc @@ -42,15 +42,15 @@ TEST_F(TorrentMagnetTest, getMetadataPiece) info_dict_size += std::size(*info_dict_data); } benc.append("e"); - EXPECT_EQ(tor->infoDictSize(), info_dict_size); + EXPECT_EQ(tor->info_dict_size(), info_dict_size); auto torrent_metainfo = tr_torrent_metainfo{}; tr_error* error = nullptr; - EXPECT_TRUE(torrent_metainfo.parseBenc(benc, &error)); + EXPECT_TRUE(torrent_metainfo.parse_benc(benc, &error)); EXPECT_EQ(nullptr, error) << error->message; tr_error_clear(&error); - EXPECT_EQ(tor->pieceHash(0), torrent_metainfo.pieceHash(0)); + EXPECT_EQ(tor->piece_hash(0), torrent_metainfo.piece_hash(0)); } } // namespace libtransmission::test diff --git a/tests/libtransmission/torrent-metainfo-test.cc b/tests/libtransmission/torrent-metainfo-test.cc index 2f69cea21..707496877 100644 --- a/tests/libtransmission/torrent-metainfo-test.cc +++ b/tests/libtransmission/torrent-metainfo-test.cc @@ -37,8 +37,8 @@ TEST_F(TorrentMetainfoTest, magnetLink) auto metainfo = tr_torrent_metainfo{}; EXPECT_TRUE(metainfo.parseMagnet(MagnetLink)); - EXPECT_EQ(0U, metainfo.fileCount()); // because it's a magnet link - EXPECT_EQ(2U, std::size(metainfo.announceList())); + EXPECT_EQ(0U, metainfo.file_count()); // because it's a magnet link + EXPECT_EQ(2U, std::size(metainfo.announce_list())); EXPECT_EQ(MagnetLink, metainfo.magnet().sv()); } @@ -78,7 +78,7 @@ TEST_F(TorrentMetainfoTest, bucket) for (auto const& test : tests) { auto metainfo = tr_torrent_metainfo{}; - EXPECT_EQ(test.expected_parse_result, metainfo.parseBenc(test.benc)); + EXPECT_EQ(test.expected_parse_result, metainfo.parse_benc(test.benc)); } } @@ -91,7 +91,7 @@ TEST_F(TorrentMetainfoTest, parseBencFuzzRegressions) for (auto const& test : Tests) { auto tm = tr_torrent_metainfo{}; - tm.parseBenc(tr_base64_decode(test)); + tm.parse_benc(tr_base64_decode(test)); } } @@ -106,7 +106,7 @@ TEST_F(TorrentMetainfoTest, parseBencFuzz) // std::cerr << '[' << tr_base64_encode({ std::data(buf), std::size(buf) }) << ']' << std::endl; auto tm = tr_torrent_metainfo{}; - tm.parseBenc({ std::data(buf), std::size(buf) }); + tm.parse_benc({ std::data(buf), std::size(buf) }); } } @@ -177,9 +177,9 @@ TEST_F(TorrentMetainfoTest, AndroidTorrent) EXPECT_EQ(nullptr, error) << *error; auto const* const metainfo = tr_ctorGetMetainfo(ctor); EXPECT_NE(nullptr, metainfo); - EXPECT_EQ(336, metainfo->infoDictOffset()); - EXPECT_EQ(26583, metainfo->infoDictSize()); - EXPECT_EQ(592, metainfo->piecesOffset()); + EXPECT_EQ(336, metainfo->info_dict_offset()); + EXPECT_EQ(26583, metainfo->info_dict_size()); + EXPECT_EQ(592, metainfo->pieces_offset()); tr_ctorFree(ctor); } @@ -224,15 +224,15 @@ TEST_F(TorrentMetainfoTest, magnetInfoHash) // compatibility with magnet torrents created by Transmission <= 3.0 auto const src_filename = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, "/gimp-2.10.32-1-arm64.dmg.torrent"sv }; auto tm = tr_torrent_metainfo{}; - EXPECT_TRUE(tm.parseTorrentFile(src_filename)); + EXPECT_TRUE(tm.parse_torrent_file(src_filename)); } TEST_F(TorrentMetainfoTest, HoffmanStyleWebseeds) { auto const src_filename = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, "/debian-11.2.0-amd64-DVD-1.iso.torrent"sv }; auto tm = tr_torrent_metainfo{}; - EXPECT_TRUE(tm.parseTorrentFile(src_filename)); - EXPECT_EQ(size_t{ 2 }, tm.webseedCount()); + EXPECT_TRUE(tm.parse_torrent_file(src_filename)); + EXPECT_EQ(size_t{ 2 }, tm.webseed_count()); EXPECT_EQ( "https://cdimage.debian.org/cdimage/release/11.2.0//srv/cdbuilder.debian.org/dst/deb-cd/weekly-builds/amd64/iso-dvd/debian-11.2.0-amd64-DVD-1.iso"sv, tm.webseed(0)); @@ -245,8 +245,8 @@ TEST_F(TorrentMetainfoTest, GetRightStyleWebseedList) { auto const src_filename = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, "/webseed-getright-list.torrent"sv }; auto tm = tr_torrent_metainfo{}; - EXPECT_TRUE(tm.parseTorrentFile(src_filename)); - EXPECT_EQ(size_t{ 2 }, tm.webseedCount()); + EXPECT_TRUE(tm.parse_torrent_file(src_filename)); + EXPECT_EQ(size_t{ 2 }, tm.webseed_count()); EXPECT_EQ("http://www.webseed-one.com/"sv, tm.webseed(0)); EXPECT_EQ("http://webseed-two.com/"sv, tm.webseed(1)); } @@ -255,8 +255,8 @@ TEST_F(TorrentMetainfoTest, GetRightStyleWebseedString) { auto const src_filename = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, "/webseed-getright-string.torrent"sv }; auto tm = tr_torrent_metainfo{}; - EXPECT_TRUE(tm.parseTorrentFile(src_filename)); - EXPECT_EQ(size_t{ 1 }, tm.webseedCount()); + EXPECT_TRUE(tm.parse_torrent_file(src_filename)); + EXPECT_EQ(size_t{ 1 }, tm.webseed_count()); EXPECT_EQ("http://www.webseed-one.com/"sv, tm.webseed(0)); } @@ -264,7 +264,7 @@ TEST_F(TorrentMetainfoTest, GetRightStyleWebseedString) TEST_F(TorrentMetainfoTest, parseBencOOBWrite) { auto tm = tr_torrent_metainfo{}; - EXPECT_FALSE(tm.parseBenc(tr_base64_decode("ZGg0OmluZm9kNjpwaWVjZXMzOkFpzQ=="))); + EXPECT_FALSE(tm.parse_benc(tr_base64_decode("ZGg0OmluZm9kNjpwaWVjZXMzOkFpzQ=="))); } } // namespace libtransmission::test diff --git a/tests/libtransmission/torrents-test.cc b/tests/libtransmission/torrents-test.cc index 483157df2..07738cda7 100644 --- a/tests/libtransmission/torrents-test.cc +++ b/tests/libtransmission/torrents-test.cc @@ -25,7 +25,7 @@ TEST_F(TorrentsTest, simpleTests) auto owned = std::vector>{}; auto tm = tr_torrent_metainfo{}; - EXPECT_TRUE(tm.parseTorrentFile(TorrentFile)); + EXPECT_TRUE(tm.parse_torrent_file(TorrentFile)); owned.emplace_back(std::make_unique(std::move(tm))); auto* const tor = owned.back().get(); @@ -42,11 +42,11 @@ TEST_F(TorrentsTest, simpleTests) EXPECT_EQ(1U, std::size(torrents)); EXPECT_EQ(tor, torrents.get(id)); - EXPECT_EQ(tor, torrents.get(tor->infoHash())); + EXPECT_EQ(tor, torrents.get(tor->info_hash())); EXPECT_EQ(tor, torrents.get(tor->magnet())); tm = tr_torrent_metainfo{}; - EXPECT_TRUE(tm.parseTorrentFile(TorrentFile)); + EXPECT_TRUE(tm.parse_torrent_file(TorrentFile)); EXPECT_EQ(tor, torrents.get(tm)); // cleanup @@ -68,7 +68,7 @@ TEST_F(TorrentsTest, rangedLoop) { auto const path = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, '/', name }; auto tm = tr_torrent_metainfo{}; - EXPECT_TRUE(tm.parseTorrentFile(path)); + EXPECT_TRUE(tm.parse_torrent_file(path)); owned.emplace_back(std::make_unique(std::move(tm))); auto* const tor = owned.back().get(); @@ -101,7 +101,7 @@ TEST_F(TorrentsTest, removedSince) { auto const path = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, '/', name }; auto tm = tr_torrent_metainfo{}; - EXPECT_TRUE(tm.parseTorrentFile(path)); + EXPECT_TRUE(tm.parse_torrent_file(path)); owned.emplace_back(std::make_unique(std::move(tm))); auto* const tor = owned.back().get(); diff --git a/utils/show.cc b/utils/show.cc index 761ad71cd..3834bc0e5 100644 --- a/utils/show.cc +++ b/utils/show.cc @@ -188,16 +188,16 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo) { fmt::print("GENERAL\n\n"); fmt::print(" Name: {:s}\n", metainfo.name()); - if (metainfo.hasV1Metadata()) + if (metainfo.has_v1_metadata()) { - fmt::print(" Hash v1: {:s}\n", metainfo.infoHashString()); + fmt::print(" Hash v1: {:s}\n", metainfo.info_hash_string()); } - if (metainfo.hasV2Metadata()) + if (metainfo.has_v2_metadata()) { - fmt::print(" Hash v2: {:s}\n", metainfo.infoHash2String()); + fmt::print(" Hash v2: {:s}\n", metainfo.info_hash2_string()); } fmt::print(" Created by: {:s}\n", std::empty(metainfo.creator()) ? "Unknown" : metainfo.creator()); - fmt::print(" Created on: {:s}\n\n", toString(metainfo.dateCreated())); + fmt::print(" Created on: {:s}\n\n", toString(metainfo.date_created())); if (!std::empty(metainfo.comment())) { @@ -209,10 +209,10 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo) fmt::print(" Source: {:s}\n", metainfo.source()); } - fmt::print(" Piece Count: {:d}\n", metainfo.pieceCount()); - fmt::print(" Piece Size: {:s}\n", tr_formatter_mem_B(metainfo.pieceSize())); - fmt::print(" Total Size: {:s}\n", tr_formatter_size_B(metainfo.totalSize())); - fmt::print(" Privacy: {:s}\n", metainfo.isPrivate() ? "Private torrent" : "Public torrent"); + fmt::print(" Piece Count: {:d}\n", metainfo.piece_count()); + fmt::print(" Piece Size: {:s}\n", tr_formatter_mem_B(metainfo.piece_size())); + fmt::print(" Total Size: {:s}\n", tr_formatter_size_B(metainfo.total_size())); + fmt::print(" Privacy: {:s}\n", metainfo.is_private() ? "Private torrent" : "Public torrent"); } /** @@ -224,7 +224,7 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo) fmt::print("\nTRACKERS\n"); auto current_tier = std::optional{}; auto print_tier = size_t{ 1 }; - for (auto const& tracker : metainfo.announceList()) + for (auto const& tracker : metainfo.announce_list()) { if (!current_tier || current_tier != tracker.tier) { @@ -240,7 +240,7 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo) *** **/ - if (auto const n_webseeds = metainfo.webseedCount(); n_webseeds > 0) + if (auto const n_webseeds = metainfo.webseed_count(); n_webseeds > 0) { fmt::print("\nWEBSEEDS\n\n"); @@ -263,21 +263,21 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo) } auto filenames = std::vector{}; - for (tr_file_index_t i = 0, n = metainfo.fileCount(); i < n; ++i) + for (tr_file_index_t i = 0, n = metainfo.file_count(); i < n; ++i) { std::string filename; if (opts.show_bytesize) { - filename = std::to_string(metainfo.fileSize(i)); + filename = std::to_string(metainfo.file_size(i)); filename += " "; - filename += metainfo.fileSubpath(i); + filename += metainfo.file_subpath(i); } else { filename = " "; - filename += metainfo.fileSubpath(i); + filename += metainfo.file_subpath(i); filename += " ("; - filename += tr_formatter_size_B(metainfo.fileSize(i)); + filename += tr_formatter_size_B(metainfo.file_size(i)); filename += ')'; } filenames.emplace_back(filename); @@ -315,7 +315,7 @@ void doScrape(tr_torrent_metainfo const& metainfo) auto mediator = Mediator{}; auto web = tr_web::create(mediator); - for (auto const& tracker : metainfo.announceList()) + for (auto const& tracker : metainfo.announce_list()) { if (std::empty(tracker.scrape)) { @@ -326,7 +326,7 @@ void doScrape(tr_torrent_metainfo const& metainfo) auto scrape_url = tr_urlbuf{ tracker.scrape.sv() }; auto delimiter = tr_strvContains(scrape_url, '?') ? '&' : '?'; scrape_url.append(delimiter, "info_hash="); - tr_urlPercentEncode(std::back_inserter(scrape_url), metainfo.infoHash()); + tr_urlPercentEncode(std::back_inserter(scrape_url), metainfo.info_hash()); fmt::print("{:s} ... ", scrape_url); fflush(stdout); @@ -367,8 +367,8 @@ void doScrape(tr_torrent_metainfo const& metainfo) tr_quark key; tr_variant* val; - auto hashsv = std::string_view{ reinterpret_cast(std::data(metainfo.infoHash())), - std::size(metainfo.infoHash()) }; + auto hashsv = std::string_view{ reinterpret_cast(std::data(metainfo.info_hash())), + std::size(metainfo.info_hash()) }; while (tr_variantDictChild(files, child_pos, &key, &val)) { @@ -428,7 +428,7 @@ int tr_main(int argc, char* argv[]) /* try to parse the torrent file */ auto metainfo = tr_torrent_metainfo{}; tr_error* error = nullptr; - auto const parsed = metainfo.parseTorrentFile(opts.filename, nullptr, &error); + auto const parsed = metainfo.parse_torrent_file(opts.filename, nullptr, &error); if (error != nullptr) { fmt::print(stderr, "Error parsing torrent file '{:s}': {:s} ({:d})\n", opts.filename, error->message, error->code);