refactor: add tracer assertionf or bug #2727 (#2836)

This commit is contained in:
Charles Kerr 2022-03-28 23:29:35 -05:00 committed by GitHub
parent 2996e223dd
commit 2f677aebb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 33 deletions

View File

@ -881,7 +881,7 @@ static tr_announce_request* announce_request_new(
req->up = tier->byteCounts[TR_ANN_UP];
req->down = tier->byteCounts[TR_ANN_DOWN];
req->corrupt = tier->byteCounts[TR_ANN_CORRUPT];
req->leftUntilComplete = tor->hasMetadata() ? tor->totalSize() - tor->hasTotal() : INT64_MAX;
req->leftUntilComplete = tor->hasMetainfo() ? tor->totalSize() - tor->hasTotal() : INT64_MAX;
req->event = event;
req->numwant = event == TR_ANNOUNCE_EVENT_STOPPED ? 0 : Numwant;
req->key = announcer->key;

View File

@ -129,12 +129,12 @@ struct tr_completion
[[nodiscard]] uint64_t countHasBytesInSpan(tr_byte_span_t) const;
private:
[[nodiscard]] constexpr bool hasMetainfo() const
[[nodiscard]] constexpr bool hasMetainfo() const noexcept
{
return !std::empty(blocks_);
}
private:
[[nodiscard]] uint64_t computeHasValid() const;
[[nodiscard]] uint64_t computeSizeWhenDone() const;
[[nodiscard]] uint64_t countHasBytesInBlocks(tr_block_span_t) const;

View File

@ -1481,7 +1481,7 @@ void tr_peerUpdateProgress(tr_torrent* tor, tr_peer* peer)
{
float const true_count = have->count();
if (tor->hasMetadata())
if (tor->hasMetainfo())
{
peer->progress = true_count / float(tor->pieceCount());
}
@ -1531,7 +1531,7 @@ void tr_peerMgrTorrentAvailability(tr_torrent const* tor, int8_t* tab, unsigned
std::fill_n(tab, tabCount, int8_t{});
if (tor->hasMetadata())
if (tor->hasMetainfo())
{
int const peerCount = tr_ptrArraySize(&tor->swarm->peers);
auto const** peers = (tr_peer const**)tr_ptrArrayBase(&tor->swarm->peers);
@ -1599,7 +1599,7 @@ uint64_t tr_peerMgrGetDesiredAvailable(tr_torrent const* tor)
// common shortcuts...
if (!tor->isRunning || tor->isStopping || tor->isDone() || !tor->hasMetadata())
if (!tor->isRunning || tor->isStopping || tor->isDone() || !tor->hasMetainfo())
{
return 0;
}

View File

@ -536,7 +536,7 @@ private:
// TR_PEER_TO_CLIENT
if (!torrent->hasMetadata())
if (!torrent->hasMetainfo())
{
return true;
}
@ -1039,7 +1039,7 @@ static void sendLtepHandshake(tr_peerMsgsImpl* msgs)
// "m" dictionary) specifying an integer value of the number of
// bytes of the metadata.
auto const info_dict_size = msgs->torrent->infoDictSize();
if (allow_metadata_xfer && msgs->torrent->hasMetadata() && info_dict_size > 0)
if (allow_metadata_xfer && msgs->torrent->hasMetainfo() && info_dict_size > 0)
{
tr_variantDictAddInt(&val, TR_KEY_metadata_size, info_dict_size);
}
@ -1237,7 +1237,7 @@ static void parseUtMetadata(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuf
/* NOOP */
}
if (msg_type == MetadataMsgType::Data && !msgs->torrent->hasMetadata() && msg_end - benc_end <= METADATA_PIECE_SIZE &&
if (msg_type == MetadataMsgType::Data && !msgs->torrent->hasMetainfo() && msg_end - benc_end <= METADATA_PIECE_SIZE &&
piece * METADATA_PIECE_SIZE + (msg_end - benc_end) <= total_size)
{
int const pieceLen = msg_end - benc_end;
@ -1246,7 +1246,7 @@ static void parseUtMetadata(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuf
if (msg_type == MetadataMsgType::Request)
{
if (piece >= 0 && msgs->torrent->hasMetadata() && msgs->torrent->isPublic() &&
if (piece >= 0 && msgs->torrent->hasMetainfo() && msgs->torrent->isPublic() &&
msgs->peerAskedForMetadataCount < MetadataReqQ)
{
msgs->peerAskedForMetadata[msgs->peerAskedForMetadataCount++] = piece;
@ -1510,7 +1510,7 @@ static bool messageLengthIsCorrect(tr_peerMsgsImpl const* msg, uint8_t id, uint3
return len == 5;
case BtPeerMsgs::Bitfield:
if (msg->torrent->hasMetadata())
if (msg->torrent->hasMetainfo())
{
return len == (msg->torrent->pieceCount() >> 3) + ((msg->torrent->pieceCount() & 7) != 0 ? 1 : 0) + 1U;
}
@ -1672,7 +1672,7 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si
tr_peerIoReadUint32(msgs->io, inbuf, &ui32);
logtrace(msgs, "got Have: %u", ui32);
if (msgs->torrent->hasMetadata() && ui32 >= msgs->torrent->pieceCount())
if (msgs->torrent->hasMetainfo() && ui32 >= msgs->torrent->pieceCount())
{
msgs->publishError(ERANGE);
return READ_ERR;
@ -1690,6 +1690,13 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si
case BtPeerMsgs::Bitfield:
{
TR_ASSERT_MSG(
!msgs->torrent->hasMetainfo() || msglen == msgs->torrent->pieceCount() / 8,
"pieceCount:%zu msglen:%zu peer_id:%s",
size_t(msgs->torrent->pieceCount()),
size_t(msglen),
msgs->client.c_str());
auto* const tmp = tr_new(uint8_t, msglen);
logtrace(msgs, "got a bitfield");
tr_peerIoReadBytes(msgs->io, inbuf, tmp, msglen);
@ -1983,7 +1990,7 @@ static void updateDesiredRequestCount(tr_peerMsgsImpl* msgs)
tr_torrent const* const torrent = msgs->torrent;
/* there are lots of reasons we might not want to request any blocks... */
if (torrent->isDone() || !torrent->hasMetadata() || msgs->client_is_choked_ || !msgs->client_is_interested_)
if (torrent->isDone() || !torrent->hasMetainfo() || msgs->client_is_choked_ || !msgs->client_is_interested_)
{
msgs->desired_request_count = 0;
}
@ -2306,7 +2313,7 @@ static void gotError(tr_peerIo* /*io*/, short what, void* vmsgs)
static void sendBitfield(tr_peerMsgsImpl* msgs)
{
TR_ASSERT(msgs->torrent->hasMetadata());
TR_ASSERT(msgs->torrent->hasMetainfo());
struct evbuffer* out = msgs->outMessages;

View File

@ -943,7 +943,7 @@ void save(tr_torrent* tor)
tr_variantDictAddBool(&top, TR_KEY_paused, !tor->isRunning && !tor->isQueued());
savePeers(&top, tor);
if (tor->hasMetadata())
if (tor->hasMetainfo())
{
saveFilePriorities(&top, tor);
saveDND(&top, tor);

View File

@ -676,7 +676,7 @@ static void initField(tr_torrent const* const tor, tr_stat const* const st, tr_v
break;
case TR_KEY_pieces:
if (tor->hasMetadata())
if (tor->hasMetainfo())
{
auto const bytes = tor->createPieceBitfield();
auto const enc = tr_base64_encode({ reinterpret_cast<char const*>(std::data(bytes)), std::size(bytes) });

View File

@ -64,7 +64,7 @@ static void incompleteMetadataFree(struct tr_incomplete_metadata* m)
bool tr_torrentSetMetadataSizeHint(tr_torrent* tor, int64_t size)
{
if (tor->hasMetadata())
if (tor->hasMetainfo())
{
return false;
}
@ -118,7 +118,7 @@ void* tr_torrentGetMetadataPiece(tr_torrent const* tor, int piece, size_t* len)
TR_ASSERT(piece >= 0);
TR_ASSERT(len != nullptr);
if (!tor->hasMetadata())
if (!tor->hasMetainfo())
{
return nullptr;
}
@ -400,7 +400,7 @@ bool tr_torrentGetNextMetadataRequest(tr_torrent* tor, time_t now, int* setme_pi
double tr_torrentGetMetadataPercent(tr_torrent const* tor)
{
if (tor->hasMetadata())
if (tor->hasMetainfo())
{
return 1.0;
}

View File

@ -637,7 +637,7 @@ static bool setLocalErrorIfFilesDisappeared(tr_torrent* tor, std::optional<bool>
*/
static bool isNewTorrentASeed(tr_torrent* tor)
{
if (!tor->hasMetadata())
if (!tor->hasMetainfo())
{
return false;
}
@ -778,7 +778,7 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
[](auto mtime) { return mtime > 0; });
}
auto const filename = tor->hasMetadata() ? tor->torrentFile() : tor->magnetFile();
auto const filename = tor->hasMetainfo() ? tor->torrentFile() : tor->magnetFile();
// if we don't have a local .torrent or .magnet file already,
// assume the torrent is new
@ -788,7 +788,7 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
{
tr_error* error = nullptr;
if (tor->hasMetadata()) // torrent file
if (tor->hasMetainfo()) // torrent file
{
tr_ctorSaveContents(ctor, filename, &error);
}
@ -815,12 +815,12 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
if (is_new_torrent)
{
if (tor->hasMetadata())
if (tor->hasMetainfo())
{
callScriptIfEnabled(tor, TR_SCRIPT_ON_TORRENT_ADDED);
}
if (!tor->hasMetadata() && !doStart)
if (!tor->hasMetainfo() && !doStart)
{
tor->prefetchMagnetMetadata = true;
@ -2088,7 +2088,7 @@ bool tr_torrent::setTrackerList(std::string_view text)
return false;
}
auto const has_metadata = this->hasMetadata();
auto const has_metadata = this->hasMetainfo();
if (has_metadata && !announce_list.save(torrentFile()))
{
return false;
@ -2257,7 +2257,7 @@ static void deleteLocalData(tr_torrent const* tor, tr_fileFunc func)
}
/* if it's a magnet link, there's nothing to move... */
if (!tor->hasMetadata())
if (!tor->hasMetainfo())
{
return;
}
@ -2761,7 +2761,7 @@ static void refreshCurrentDir(tr_torrent* tor)
{
dir = tor->downloadDir();
}
else if (!tor->hasMetadata()) /* no files to find */
else if (!tor->hasMetainfo()) /* no files to find */
{
dir = tor->incompleteDir();
}
@ -3161,7 +3161,7 @@ void tr_torrentSetFilePriorities(
bool tr_torrentHasMetadata(tr_torrent const* tor)
{
return tor->hasMetadata();
return tor->hasMetainfo();
}
void tr_torrent::markEdited()

View File

@ -199,6 +199,11 @@ public:
return completion.sizeWhenDone();
}
[[nodiscard]] auto hasMetainfo() const noexcept
{
return completion.hasMetainfo() > 0;
}
[[nodiscard]] auto hasAll() const
{
return completion.hasAll();
@ -500,11 +505,6 @@ public:
return metainfo_.source();
}
[[nodiscard]] auto hasMetadata() const
{
return fileCount() > 0;
}
[[nodiscard]] auto infoDictSize() const
{
return metainfo_.infoDictSize();