1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-30 19:03:04 +00:00

refactor: make tr_torrent::unique_id_ private (#6145)

This commit is contained in:
Charles Kerr 2023-10-20 21:23:14 -05:00 committed by GitHub
parent 9e5c528056
commit 8c1291ce8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 6 deletions

View file

@ -2149,7 +2149,7 @@ void tr_session::addIncoming(tr_peer_socket&& socket)
void tr_session::addTorrent(tr_torrent* tor)
{
tor->unique_id_ = torrents().add(tor);
tor->init_id(torrents().add(tor));
tr_peerMgrAddTorrent(peer_mgr_.get(), tor);
}

View file

@ -618,6 +618,13 @@ public:
return unique_id_;
}
void init_id(tr_torrent_id_t id)
{
TR_ASSERT(unique_id_ == tr_torrent_id_t{});
TR_ASSERT(id != tr_torrent_id_t{});
unique_id_ = id;
}
constexpr void set_date_active(time_t t) noexcept
{
this->activityDate = t;
@ -980,8 +987,6 @@ public:
size_t queuePosition = 0;
tr_torrent_id_t unique_id_ = 0;
tr_completeness completeness = TR_LEECH;
uint16_t max_connected_peers_ = TR_DEFAULT_PEER_LIMIT_TORRENT;
@ -1171,6 +1176,8 @@ private:
tr_announce_key_t announce_key_ = tr_rand_obj<tr_announce_key_t>();
tr_torrent_id_t unique_id_ = 0;
tr_ratiolimit seed_ratio_mode_ = TR_RATIOLIMIT_GLOBAL;
tr_idlelimit idle_limit_mode_ = TR_IDLELIMIT_GLOBAL;

View file

@ -42,7 +42,7 @@ TEST_F(TorrentsTest, simpleTests)
auto const id = torrents.add(tor);
EXPECT_GT(id, 0);
tor->unique_id_ = id;
tor->init_id(id);
EXPECT_TRUE(std::empty(torrents.removedSince(0)));
EXPECT_FALSE(std::empty(torrents));
@ -79,7 +79,7 @@ TEST_F(TorrentsTest, rangedLoop)
owned.emplace_back(std::make_unique<tr_torrent>(std::move(tm)));
auto* const tor = owned.back().get();
tor->unique_id_ = torrents.add(tor);
tor->init_id(torrents.add(tor));
EXPECT_EQ(tor, torrents.get(tor->id()));
torrents_set.insert(tor);
}
@ -112,7 +112,7 @@ TEST_F(TorrentsTest, removedSince)
owned.emplace_back(std::make_unique<tr_torrent>(std::move(tm)));
auto* const tor = owned.back().get();
tor->unique_id_ = torrents.add(tor);
tor->init_id(torrents.add(tor));
torrents_v.push_back(tor);
}