refactor: even more torrent housekeeping (#2323)

This commit is contained in:
Charles Kerr 2021-12-16 22:51:53 -06:00 committed by GitHub
parent e4a172d39c
commit b9406dfebb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 107 additions and 95 deletions

View File

@ -447,8 +447,7 @@ static tr_tier* getTier(tr_announcer* announcer, tr_sha1_digest_t const& info_ha
if (announcer != nullptr)
{
tr_session* session = announcer->session;
tr_torrent* tor = tr_torrentFindFromHash(session, info_hash);
tr_torrent* const tor = announcer->session->getTorrent(info_hash);
if (tor != nullptr && tor->announcer_tiers != nullptr)
{
@ -818,7 +817,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 = tr_torrentHasMetadata(tor) ? tor->totalSize() - tor->hasTotal() : INT64_MAX;
req->leftUntilComplete = tor->hasMetadata() ? tor->totalSize() - tor->hasTotal() : INT64_MAX;
req->event = event;
req->numwant = event == TR_ANNOUNCE_EVENT_STOPPED ? 0 : Numwant;
req->key = announcer->key;
@ -1281,7 +1280,7 @@ static void on_scrape_done(tr_scrape_response const* response, void* vsession)
for (int i = 0; i < response->row_count; ++i)
{
struct tr_scrape_response_row const* row = &response->rows[i];
tr_torrent* tor = tr_torrentFindFromHash(session, row->info_hash);
tr_torrent* tor = session->getTorrent(row->info_hash);
if (tor != nullptr)
{

View File

@ -9,14 +9,13 @@
#ifndef TR_CRYPTO_UTILS_H
#define TR_CRYPTO_UTILS_H
#include <cinttypes>
#include <cstddef>
#include <cinttypes> // intX_t
#include <cstddef> // size_t
#include <optional>
#include <string>
#include <string_view>
#include "transmission.h" /* SHA_DIGEST_LENGTH */
#include "tr-macros.h"
/**
*** @addtogroup utils Utilities

View File

@ -175,7 +175,7 @@ static void setReadState(tr_handshake* handshake, handshake_state_t state)
static bool buildHandshakeMessage(tr_handshake* handshake, uint8_t* buf)
{
uint8_t const* const torrent_hash = tr_cryptoGetTorrentHash(handshake->crypto);
tr_torrent* const tor = torrent_hash == nullptr ? nullptr : tr_torrentFindFromHash(handshake->session, torrent_hash);
auto* const tor = torrent_hash == nullptr ? nullptr : handshake->session->getTorrent(torrent_hash);
bool const success = tor != nullptr;
if (success)
@ -245,8 +245,7 @@ static handshake_parse_err_t parseHandshake(tr_handshake* handshake, struct evbu
tr_peerIoReadBytes(handshake->io, inbuf, hash, sizeof(hash));
TR_ASSERT(tr_peerIoHasTorrentHash(handshake->io));
if (!tr_torrentExists(handshake->session, hash) ||
memcmp(hash, tr_peerIoGetTorrentHash(handshake->io), SHA_DIGEST_LENGTH) != 0)
if (!handshake->session->contains(hash) || memcmp(hash, tr_peerIoGetTorrentHash(handshake->io), SHA_DIGEST_LENGTH) != 0)
{
dbgmsg(handshake, "peer returned the wrong hash. wtf?");
return HANDSHAKE_BAD_TORRENT;
@ -260,7 +259,7 @@ static handshake_parse_err_t parseHandshake(tr_handshake* handshake, struct evbu
/* peer id */
dbgmsg(handshake, "peer-id is [%" TR_PRIsv "]", TR_PRIsv_ARG(peer_id));
auto* const tor = tr_torrentFindFromHash(handshake->session, hash);
auto* const tor = handshake->session->getTorrent(hash);
if (peer_id == tr_torrentGetPeerId(tor))
{
dbgmsg(handshake, "streuth! we've connected to ourselves.");
@ -645,7 +644,7 @@ static ReadState readHandshake(tr_handshake* handshake, struct evbuffer* inbuf)
if (tr_peerIoIsIncoming(handshake->io))
{
if (!tr_torrentExists(handshake->session, hash))
if (!handshake->session->contains(hash))
{
dbgmsg(handshake, "peer is trying to connect to us for a torrent we don't have.");
return tr_handshakeDone(handshake, false);
@ -702,7 +701,7 @@ static ReadState readPeerId(tr_handshake* handshake, struct evbuffer* inbuf)
dbgmsg(handshake, "peer-id is [%s] ... isIncoming is %d", client, tr_peerIoIsIncoming(handshake->io));
// if we've somehow connected to ourselves, don't keep the connection
auto* const tor = tr_torrentFindFromHash(handshake->session, tr_peerIoGetTorrentHash(handshake->io));
auto* const tor = handshake->session->getTorrent(tr_peerIoGetTorrentHash(handshake->io));
bool const connected_to_self = peer_id == tr_torrentGetPeerId(tor);
return tr_handshakeDone(handshake, !connected_to_self);
@ -1120,9 +1119,8 @@ static void gotError(tr_peerIo* io, short what, void* vhandshake)
{
/* This peer probably doesn't speak uTP. */
tr_torrent* const tor = tr_peerIoHasTorrentHash(io) ?
tr_torrentFindFromHash(handshake->session, tr_peerIoGetTorrentHash(io)) :
nullptr;
tr_torrent* const tor = tr_peerIoHasTorrentHash(io) ? handshake->session->getTorrent(tr_peerIoGetTorrentHash(io)) :
nullptr;
/* Don't mark a peer as non-uTP unless it's really a connect failure. */
if ((errcode == ETIMEDOUT || errcode == ECONNREFUSED) && tr_isTorrent(tor))

View File

@ -299,7 +299,7 @@ tr_address const* tr_peerAddress(tr_peer const* peer)
static tr_swarm* getExistingSwarm(tr_peerMgr* manager, uint8_t const* hash)
{
tr_torrent* tor = tr_torrentFindFromHash(manager->session, hash);
tr_torrent* tor = manager->session->getTorrent(hash);
return tor == nullptr ? nullptr : tor->swarm;
}
@ -1530,7 +1530,7 @@ void tr_peerUpdateProgress(tr_torrent* tor, tr_peer* peer)
{
float const true_count = have->count();
if (tr_torrentHasMetadata(tor))
if (tor->hasMetadata())
{
peer->progress = true_count / float(tor->pieceCount());
}
@ -1580,7 +1580,7 @@ void tr_peerMgrTorrentAvailability(tr_torrent const* tor, int8_t* tab, unsigned
memset(tab, 0, tabCount);
if (tr_torrentHasMetadata(tor))
if (tor->hasMetadata())
{
int const peerCount = tr_ptrArraySize(&tor->swarm->peers);
tr_peer const** peers = (tr_peer const**)tr_ptrArrayBase(&tor->swarm->peers);
@ -1648,7 +1648,7 @@ uint64_t tr_peerMgrGetDesiredAvailable(tr_torrent const* tor)
// common shortcuts...
if (!tor->isRunning || tor->isStopping || tor->isDone() || !tr_torrentHasMetadata(tor))
if (!tor->isRunning || tor->isStopping || tor->isDone() || !tor->hasMetadata())
{
return 0;
}
@ -1853,7 +1853,7 @@ static bool isPeerInteresting(tr_torrent* const tor, bool const* const piece_is_
{
/* these cases should have already been handled by the calling code... */
TR_ASSERT(!tor->isDone());
TR_ASSERT(tr_torrentIsPieceTransferAllowed(tor, TR_PEER_TO_CLIENT));
TR_ASSERT(tor->clientCanDownload());
if (tr_peerIsSeed(peer))
{
@ -1909,12 +1909,7 @@ static void rechokeDownloads(tr_swarm* s)
time_t const now = tr_time();
/* some cases where this function isn't necessary */
if (s->tor->isDone())
{
return;
}
if (!tr_torrentIsPieceTransferAllowed(s->tor, TR_PEER_TO_CLIENT))
if (s->tor->isDone() || !s->tor->clientCanDownload())
{
return;
}
@ -2161,7 +2156,7 @@ static void rechokeUploads(tr_swarm* s, uint64_t const now)
tr_peerMsgs** peers = (tr_peerMsgs**)tr_ptrArrayBase(&s->peers);
struct ChokeData* choke = tr_new0(struct ChokeData, peerCount);
tr_session const* session = s->manager->session;
bool const chokeAll = !tr_torrentIsPieceTransferAllowed(s->tor, TR_CLIENT_TO_PEER);
bool const chokeAll = !s->tor->clientCanUpload();
bool const isMaxedOut = isBandwidthMaxedOut(s->tor->bandwidth, now, TR_UP);
/* an optimistic unchoke peer's "optimistic"

View File

@ -536,7 +536,7 @@ private:
// TR_PEER_TO_CLIENT
if (!tr_torrentHasMetadata(torrent))
if (!torrent->hasMetadata())
{
return true;
}
@ -1059,7 +1059,7 @@ 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.
if (allow_metadata_xfer && tr_torrentHasMetadata(msgs->torrent) && msgs->torrent->infoDictLength > 0)
if (allow_metadata_xfer && msgs->torrent->hasMetadata() && msgs->torrent->infoDictLength > 0)
{
tr_variantDictAddInt(&val, TR_KEY_metadata_size, msgs->torrent->infoDictLength);
}
@ -1258,8 +1258,8 @@ static void parseUtMetadata(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuf
/* NOOP */
}
if (msg_type == METADATA_MSG_TYPE_DATA && !tr_torrentHasMetadata(msgs->torrent) &&
msg_end - benc_end <= METADATA_PIECE_SIZE && piece * METADATA_PIECE_SIZE + (msg_end - benc_end) <= total_size)
if (msg_type == METADATA_MSG_TYPE_DATA && !msgs->torrent->hasMetadata() && msg_end - benc_end <= METADATA_PIECE_SIZE &&
piece * METADATA_PIECE_SIZE + (msg_end - benc_end) <= total_size)
{
int const pieceLen = msg_end - benc_end;
tr_torrentSetMetadataPiece(msgs->torrent, piece, benc_end, pieceLen);
@ -1267,7 +1267,7 @@ static void parseUtMetadata(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuf
if (msg_type == METADATA_MSG_TYPE_REQUEST)
{
if (piece >= 0 && tr_torrentHasMetadata(msgs->torrent) && msgs->torrent->isPublic() &&
if (piece >= 0 && msgs->torrent->hasMetadata() && msgs->torrent->isPublic() &&
msgs->peerAskedForMetadataCount < MetadataReqQ)
{
msgs->peerAskedForMetadata[msgs->peerAskedForMetadataCount++] = piece;
@ -1533,7 +1533,7 @@ static bool messageLengthIsCorrect(tr_peerMsgsImpl const* msg, uint8_t id, uint3
return len == 5;
case BtBitfield:
if (tr_torrentHasMetadata(msg->torrent))
if (msg->torrent->hasMetadata())
{
return len == (msg->torrent->pieceCount() >> 3) + ((msg->torrent->pieceCount() & 7) != 0 ? 1 : 0) + 1U;
}
@ -1695,7 +1695,7 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si
tr_peerIoReadUint32(msgs->io, inbuf, &ui32);
dbgmsg(msgs, "got Have: %u", ui32);
if (tr_torrentHasMetadata(msgs->torrent) && ui32 >= msgs->torrent->pieceCount())
if (msgs->torrent->hasMetadata() && ui32 >= msgs->torrent->pieceCount())
{
msgs->publishError(ERANGE);
return READ_ERR;
@ -2005,7 +2005,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() || !tr_torrentHasMetadata(torrent) || msgs->client_is_choked_ || !msgs->client_is_interested_)
if (torrent->isDone() || !torrent->hasMetadata() || msgs->client_is_choked_ || !msgs->client_is_interested_)
{
msgs->desired_request_count = 0;
}
@ -2070,7 +2070,7 @@ static void updateMetadataRequests(tr_peerMsgsImpl* msgs, time_t now)
static void updateBlockRequests(tr_peerMsgsImpl* msgs)
{
if (!tr_torrentIsPieceTransferAllowed(msgs->torrent, TR_PEER_TO_CLIENT))
if (!msgs->torrent->clientCanDownload())
{
return;
}
@ -2329,7 +2329,7 @@ static void gotError(tr_peerIo* /*io*/, short what, void* vmsgs)
static void sendBitfield(tr_peerMsgsImpl* msgs)
{
TR_ASSERT(tr_torrentHasMetadata(msgs->torrent));
TR_ASSERT(msgs->torrent->hasMetadata());
struct evbuffer* out = msgs->outMessages;

View File

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

View File

@ -137,7 +137,7 @@ static auto getTorrents(tr_session* session, tr_variant* args)
}
else if (tr_variantGetStrView(node, &sv))
{
tor = tr_torrentFindFromHashString(session, sv);
tor = session->getTorrent(sv);
}
if (tor != nullptr)
@ -169,7 +169,7 @@ static auto getTorrents(tr_session* session, tr_variant* args)
}
else
{
tr_torrent* const tor = tr_torrentFindFromHashString(session, sv);
auto* const tor = session->getTorrent(sv);
if (tor != nullptr)
{
torrents.push_back(tor);
@ -680,7 +680,7 @@ static void initField(
break;
case TR_KEY_pieces:
if (tr_torrentHasMetadata(tor))
if (tor->hasMetadata())
{
auto const bytes = tor->createPieceBitfield();
auto* enc = static_cast<char*>(tr_base64_encode(bytes.data(), std::size(bytes), nullptr));
@ -2558,8 +2558,7 @@ void tr_rpc_request_exec_uri(
tr_variantInitDict(&top, 3);
tr_variant* const args = tr_variantDictAddDict(&top, TR_KEY_arguments, 0);
auto const parsed = tr_urlParse(request_uri);
if (parsed)
if (auto const parsed = tr_urlParse(request_uri); parsed)
{
for (auto const& [key, val] : tr_url_query_view(parsed->query))
{

View File

@ -30,6 +30,7 @@
#include "transmission.h"
#include "crypto-utils.h"
#include "net.h"
#include "tr-macros.h"
@ -119,6 +120,37 @@ public:
return is_closing_;
}
[[nodiscard]] auto const* getTorrent(uint8_t const* info_dict_hash) const
{
auto& src = this->torrentsByHash;
auto it = src.find(info_dict_hash);
return it == std::end(src) ? nullptr : it->second;
}
[[nodiscard]] auto* getTorrent(uint8_t const* info_dict_hash)
{
auto& src = this->torrentsByHash;
auto it = src.find(info_dict_hash);
return it == std::end(src) ? nullptr : it->second;
}
[[nodiscard]] auto getTorrent(tr_sha1_digest_t const& info_dict_hash)
{
return this->getTorrent(reinterpret_cast<uint8_t const*>(std::data(info_dict_hash)));
}
[[nodiscard]] auto getTorrent(std::string_view info_dict_hash_string)
{
auto info_dict_hash = std::array<uint8_t, TR_SHA1_DIGEST_LEN>{};
tr_hex_to_sha1(std::data(info_dict_hash), std::data(info_dict_hash_string));
return this->getTorrent(std::data(info_dict_hash));
}
[[nodiscard]] auto contains(uint8_t const* info_dict_hash) const
{
return getTorrent(info_dict_hash) != nullptr;
}
// download dir
std::string const& downloadDir() const

View File

@ -63,7 +63,7 @@ static void incompleteMetadataFree(struct tr_incomplete_metadata* m)
bool tr_torrentSetMetadataSizeHint(tr_torrent* tor, int64_t size)
{
if (tr_torrentHasMetadata(tor))
if (tor->hasMetadata())
{
return false;
}
@ -145,7 +145,7 @@ static size_t findInfoDictOffset(tr_torrent const* tor)
static void ensureInfoDictOffsetIsCached(tr_torrent* tor)
{
TR_ASSERT(tr_torrentHasMetadata(tor));
TR_ASSERT(tor->hasMetadata());
if (!tor->infoDictOffsetIsCached)
{
@ -162,7 +162,7 @@ void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len)
char* ret = nullptr;
if (tr_torrentHasMetadata(tor))
if (tor->hasMetadata())
{
ensureInfoDictOffsetIsCached(tor);
@ -377,7 +377,7 @@ bool tr_torrentGetNextMetadataRequest(tr_torrent* tor, time_t now, int* setme_pi
double tr_torrentGetMetadataPercent(tr_torrent const* tor)
{
if (tr_torrentHasMetadata(tor))
if (tor->hasMetadata())
{
return 1.0;
}

View File

@ -106,29 +106,15 @@ tr_torrent* tr_torrentFindFromId(tr_session* session, int id)
return it == std::end(src) ? nullptr : it->second;
}
tr_torrent* tr_torrentFindFromHashString(tr_session* session, std::string_view hash_string)
{
auto info_hash = std::array<uint8_t, TR_SHA1_DIGEST_LEN>{};
tr_hex_to_sha1(std::data(info_hash), std::data(hash_string));
return tr_torrentFindFromHash(session, std::data(info_hash));
}
tr_torrent* tr_torrentFindFromHash(tr_session* session, uint8_t const* hash)
{
auto& src = session->torrentsByHash;
auto it = src.find(hash);
return it == std::end(src) ? nullptr : it->second;
}
tr_torrent* tr_torrentFindFromHash(tr_session* session, tr_sha1_digest_t const& info_dict_hash)
{
return tr_torrentFindFromHash(session, reinterpret_cast<uint8_t const*>(std::data(info_dict_hash)));
return session->getTorrent(hash);
}
tr_torrent* tr_torrentFindFromMagnetLink(tr_session* session, char const* magnet_link)
{
auto mm = tr_magnet_metainfo{};
return mm.parseMagnet(magnet_link ? magnet_link : "") ? tr_torrentFindFromHash(session, mm.info_hash) : nullptr;
return mm.parseMagnet(magnet_link ? magnet_link : "") ? session->getTorrent(mm.info_hash) : nullptr;
}
tr_torrent* tr_torrentFindFromObfuscatedHash(tr_session* session, uint8_t const* obfuscatedTorrentHash)
@ -144,22 +130,21 @@ tr_torrent* tr_torrentFindFromObfuscatedHash(tr_session* session, uint8_t const*
return nullptr;
}
bool tr_torrentIsPieceTransferAllowed(tr_torrent const* tor, tr_direction direction)
bool tr_torrent::isPieceTransferAllowed(tr_direction direction) const
{
TR_ASSERT(tr_isTorrent(tor));
TR_ASSERT(tr_isDirection(direction));
bool allowed = true;
if (tr_torrentUsesSpeedLimit(tor, direction) && tor->speedLimitBps(direction) <= 0)
if (tr_torrentUsesSpeedLimit(this, direction) && this->speedLimitBps(direction) <= 0)
{
allowed = false;
}
if (tr_torrentUsesSessionLimits(tor))
if (tr_torrentUsesSessionLimits(this))
{
unsigned int limit = 0;
if (tr_sessionGetActiveSpeedLimit_Bps(tor->session, direction, &limit) && (limit <= 0))
if (tr_sessionGetActiveSpeedLimit_Bps(this->session, direction, &limit) && (limit <= 0))
{
allowed = false;
}
@ -778,12 +763,12 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
if (isNewTorrent)
{
if (tr_torrentHasMetadata(tor))
if (tor->hasMetadata())
{
callScriptIfEnabled(tor, TR_SCRIPT_ON_TORRENT_ADDED);
}
if (!tr_torrentHasMetadata(tor) && !doStart)
if (!tor->hasMetadata() && !doStart)
{
tor->prefetchMagnetMetadata = true;
tr_torrentStartNow(tor);
@ -842,7 +827,7 @@ tr_torrent* tr_torrentNew(tr_ctor const* ctor, int* setme_error, int* setme_dupl
return nullptr;
}
tr_torrent const* const dupe = tr_torrentFindFromHash(session, parsed->info.hash);
tr_torrent const* const dupe = session->getTorrent(parsed->info.hash);
if (dupe != nullptr)
{
if (setme_duplicate_id != nullptr)
@ -2298,7 +2283,7 @@ static void deleteLocalData(tr_torrent* tor, tr_fileFunc func)
}
/* if it's a magnet link, there's nothing to move... */
if (!tr_torrentHasMetadata(tor))
if (!tor->hasMetadata())
{
return;
}
@ -2807,7 +2792,7 @@ static void refreshCurrentDir(tr_torrent* tor)
{
dir = tor->downloadDir;
}
else if (!tr_torrentHasMetadata(tor)) /* no files to find */
else if (!tor->hasMetadata()) /* no files to find */
{
dir = tor->incompleteDir;
}
@ -3234,7 +3219,7 @@ void tr_torrentSetFilePriorities(
bool tr_torrentHasMetadata(tr_torrent const* tor)
{
return tor->info.fileCount > 0;
return tor->hasMetadata();
}
void tr_torrent::markEdited()

View File

@ -76,14 +76,8 @@ void tr_torrentChangeMyPort(tr_torrent* session);
tr_sha1_digest_t tr_torrentInfoHash(tr_torrent const* torrent);
tr_torrent* tr_torrentFindFromHash(tr_session* session, tr_sha1_digest_t const& info_dict_hah);
tr_torrent* tr_torrentFindFromHashString(tr_session* session, std::string_view hash_string);
tr_torrent* tr_torrentFindFromObfuscatedHash(tr_session* session, uint8_t const* hash);
bool tr_torrentIsPieceTransferAllowed(tr_torrent const* torrent, tr_direction direction);
bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_t offset, uint32_t length);
uint64_t tr_pieceOffset(tr_torrent const* tor, tr_piece_index_t index, uint32_t offset, uint32_t length);
@ -422,6 +416,11 @@ public:
return this->info.torrent;
}
[[nodiscard]] auto hasMetadata() const
{
return fileCount() > 0;
}
/// METAINFO - CHECKSUMS
[[nodiscard]] bool ensurePieceIsChecked(tr_piece_index_t piece)
@ -490,6 +489,18 @@ public:
return this->isPublic() && tr_sessionAllowsLPD(this->session);
}
[[nodiscard]] bool isPieceTransferAllowed(tr_direction direction) const;
[[nodiscard]] bool clientCanDownload() const
{
return this->isPieceTransferAllowed(TR_PEER_TO_CLIENT);
}
[[nodiscard]] bool clientCanUpload() const
{
return this->isPieceTransferAllowed(TR_CLIENT_TO_PEER);
}
void setVerifyState(tr_verify_state state);
void setDateActive(time_t t);
@ -674,11 +685,6 @@ private:
mutable std::vector<tr_sha1_digest_t> piece_checksums_;
};
static inline bool tr_torrentExists(tr_session const* session, uint8_t const* torrentHash)
{
return tr_torrentFindFromHash((tr_session*)session, torrentHash) != nullptr;
}
/***
****
***/

View File

@ -44,23 +44,22 @@
#include <netinet/in.h> /* sockaddr_in */
#endif
/* third party */
#include <event2/event.h>
#include <dht/dht.h>
/* libT */
#include "transmission.h"
#include "crypto-utils.h"
#include "file.h"
#include "log.h"
#include "net.h"
#include "peer-mgr.h" /* tr_peerMgrCompactToPex() */
#include "platform.h" /* tr_threadNew() */
#include "peer-mgr.h"
#include "platform.h"
#include "session.h"
#include "torrent.h" /* tr_torrentFindFromHash() */
#include "torrent.h"
#include "tr-assert.h"
#include "tr-dht.h"
#include "trevent.h" /* tr_runInEventThread() */
#include "trevent.h"
#include "utils.h"
#include "variant.h"
@ -625,7 +624,7 @@ static void callback(void* /*ignore*/, int event, unsigned char const* info_hash
{
auto const lock = session_->unique_lock();
tr_torrent* const tor = tr_torrentFindFromHash(session_, info_hash);
tr_torrent* const tor = session_->getTorrent(info_hash);
if (tor != nullptr && tor->allowsDht())
{
size_t n = 0;
@ -640,7 +639,7 @@ static void callback(void* /*ignore*/, int event, unsigned char const* info_hash
}
else if (event == DHT_EVENT_SEARCH_DONE || event == DHT_EVENT_SEARCH_DONE6)
{
tr_torrent* tor = tr_torrentFindFromHash(session_, info_hash);
tr_torrent* tor = session_->getTorrent(info_hash);
if (tor != nullptr)
{

View File

@ -557,7 +557,7 @@ static int tr_lpdConsiderAnnounce(tr_pex* peer, char const* const msg)
return res;
}
tor = tr_torrentFindFromHashString(session, hashString);
tor = session->getTorrent(hashString);
if (tr_isTorrent(tor) && tor->allowsLpd())
{