mirror of
https://github.com/transmission/transmission
synced 2025-03-15 16:29:34 +00:00
refactor: rename tr_torrent.infoDictSize() (#2383)
This commit is contained in:
parent
8b65b660c8
commit
79d244db82
6 changed files with 29 additions and 25 deletions
|
@ -333,7 +333,7 @@ static char const* tr_metainfoParseImpl(
|
|||
tr_session const* session,
|
||||
tr_info* inf,
|
||||
std::vector<tr_sha1_digest_t>* pieces,
|
||||
uint64_t* infoDictLength,
|
||||
uint64_t* info_dict_size,
|
||||
tr_variant const* meta_in)
|
||||
{
|
||||
int64_t i = 0;
|
||||
|
@ -395,9 +395,9 @@ static char const* tr_metainfoParseImpl(
|
|||
inf->hash = *hash;
|
||||
tr_sha1_to_string(inf->hash, inf->hashString);
|
||||
|
||||
if (infoDictLength != nullptr)
|
||||
if (info_dict_size != nullptr)
|
||||
{
|
||||
*infoDictLength = std::size(benc);
|
||||
*info_dict_size = std::size(benc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -530,7 +530,7 @@ std::optional<tr_metainfo_parsed> tr_metainfoParse(tr_session const* session, tr
|
|||
{
|
||||
auto out = tr_metainfo_parsed{};
|
||||
|
||||
char const* bad_tag = tr_metainfoParseImpl(session, &out.info, &out.pieces, &out.info_dict_length, meta_in);
|
||||
char const* bad_tag = tr_metainfoParseImpl(session, &out.info, &out.pieces, &out.info_dict_size, meta_in);
|
||||
if (bad_tag != nullptr)
|
||||
{
|
||||
tr_error_set(error, TR_ERROR_EINVAL, tr_strvJoin("Error parsing metainfo: "sv, bad_tag));
|
||||
|
|
|
@ -37,7 +37,7 @@ enum tr_metainfo_basename_format
|
|||
struct tr_metainfo_parsed
|
||||
{
|
||||
tr_info info = {};
|
||||
uint64_t info_dict_length = 0;
|
||||
uint64_t info_dict_size = 0;
|
||||
std::vector<tr_sha1_digest_t> pieces;
|
||||
tr_bitfield files_renamed = tr_bitfield{ 0 };
|
||||
|
||||
|
@ -47,7 +47,7 @@ struct tr_metainfo_parsed
|
|||
{
|
||||
std::swap(this->info, that.info);
|
||||
std::swap(this->pieces, that.pieces);
|
||||
std::swap(this->info_dict_length, that.info_dict_length);
|
||||
std::swap(this->info_dict_size, that.info_dict_size);
|
||||
}
|
||||
|
||||
tr_metainfo_parsed(tr_metainfo_parsed const&) = delete;
|
||||
|
|
|
@ -1057,10 +1057,10 @@ static 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.
|
||||
auto const info_dict_length = msgs->torrent->infoDictLength();
|
||||
if (allow_metadata_xfer && msgs->torrent->hasMetadata() && info_dict_length > 0)
|
||||
auto const info_dict_size = msgs->torrent->infoDictSize();
|
||||
if (allow_metadata_xfer && msgs->torrent->hasMetadata() && info_dict_size > 0)
|
||||
{
|
||||
tr_variantDictAddInt(&val, TR_KEY_metadata_size, info_dict_length);
|
||||
tr_variantDictAddInt(&val, TR_KEY_metadata_size, info_dict_size);
|
||||
}
|
||||
|
||||
// http://bittorrent.org/beps/bep_0010.html
|
||||
|
@ -2149,7 +2149,7 @@ static size_t fillOutputBuffer(tr_peerMsgsImpl* msgs, time_t now)
|
|||
tr_variantInitDict(&tmp, 3);
|
||||
tr_variantDictAddInt(&tmp, TR_KEY_msg_type, METADATA_MSG_TYPE_DATA);
|
||||
tr_variantDictAddInt(&tmp, TR_KEY_piece, piece);
|
||||
tr_variantDictAddInt(&tmp, TR_KEY_total_size, msgs->torrent->infoDictLength());
|
||||
tr_variantDictAddInt(&tmp, TR_KEY_total_size, msgs->torrent->infoDictSize());
|
||||
evbuffer* const payload = tr_variantToBuf(&tmp, TR_VARIANT_FMT_BENC);
|
||||
|
||||
/* write it out as a LTEP message to our outMessages buffer */
|
||||
|
|
|
@ -150,10 +150,10 @@ static void ensureInfoDictOffsetIsCached(tr_torrent* tor)
|
|||
{
|
||||
TR_ASSERT(tor->hasMetadata());
|
||||
|
||||
if (!tor->infoDictOffsetIsCached)
|
||||
if (!tor->info_dict_offset_is_cached)
|
||||
{
|
||||
tor->infoDictOffset = findInfoDictOffset(tor);
|
||||
tor->infoDictOffsetIsCached = true;
|
||||
tor->info_dict_offset = findInfoDictOffset(tor);
|
||||
tor->info_dict_offset_is_cached = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,13 +176,13 @@ void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len)
|
|||
|
||||
ensureInfoDictOffsetIsCached(tor);
|
||||
|
||||
auto const info_dict_length = tor->infoDictLength();
|
||||
TR_ASSERT(info_dict_length > 0);
|
||||
auto const info_dict_size = tor->infoDictSize();
|
||||
TR_ASSERT(info_dict_size > 0);
|
||||
|
||||
char* ret = nullptr;
|
||||
if (size_t o = piece * METADATA_PIECE_SIZE; tr_sys_file_seek(fd, tor->infoDictOffset + o, TR_SEEK_SET, nullptr, nullptr))
|
||||
if (size_t o = piece * METADATA_PIECE_SIZE; tr_sys_file_seek(fd, tor->infoDictOffset() + o, TR_SEEK_SET, nullptr, nullptr))
|
||||
{
|
||||
size_t const l = o + METADATA_PIECE_SIZE <= info_dict_length ? METADATA_PIECE_SIZE : info_dict_length - o;
|
||||
size_t const l = o + METADATA_PIECE_SIZE <= info_dict_size ? METADATA_PIECE_SIZE : info_dict_size - o;
|
||||
|
||||
if (0 < l && l <= METADATA_PIECE_SIZE)
|
||||
{
|
||||
|
|
|
@ -3074,7 +3074,7 @@ void tr_torrent::swapMetainfo(tr_metainfo_parsed& parsed)
|
|||
{
|
||||
std::swap(this->info, parsed.info);
|
||||
std::swap(this->piece_checksums_, parsed.pieces);
|
||||
std::swap(this->info_dict_length, parsed.info_dict_length);
|
||||
std::swap(this->info_dict_size, parsed.info_dict_size);
|
||||
}
|
||||
|
||||
void tr_torrentSetFilePriorities(
|
||||
|
|
|
@ -479,9 +479,14 @@ public:
|
|||
return fileCount() > 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto infoDictLength() const
|
||||
[[nodiscard]] auto infoDictSize() const
|
||||
{
|
||||
return this->info_dict_length;
|
||||
return this->info_dict_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto infoDictOffset() const
|
||||
{
|
||||
return this->info_dict_offset;
|
||||
}
|
||||
|
||||
/// METAINFO - CHECKSUMS
|
||||
|
@ -642,13 +647,15 @@ public:
|
|||
tr_interned_string current_dir;
|
||||
|
||||
/* Length, in bytes, of the "info" dict in the .torrent file. */
|
||||
uint64_t info_dict_length = 0;
|
||||
uint64_t info_dict_size = 0;
|
||||
|
||||
/* Offset, in bytes, of the beginning of the "info" dict in the .torrent file.
|
||||
*
|
||||
* Used by the torrent-magnet code for serving metainfo to peers.
|
||||
* This field is lazy-generated and might not be initialized yet. */
|
||||
size_t infoDictOffset = 0;
|
||||
uint64_t info_dict_offset = 0;
|
||||
|
||||
bool info_dict_offset_is_cached = false;
|
||||
|
||||
tr_completeness completeness = TR_LEECH;
|
||||
|
||||
|
@ -708,9 +715,6 @@ public:
|
|||
bool prefetchMagnetMetadata = false;
|
||||
bool magnetVerify = false;
|
||||
|
||||
// TODO(ckerr) use std::optional
|
||||
bool infoDictOffsetIsCached = false;
|
||||
|
||||
void setDirty()
|
||||
{
|
||||
this->isDirty = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue