mirror of
https://github.com/transmission/transmission
synced 2025-02-21 21:57:01 +00:00
perf: avoid atom lookup in tr_peerMgrSetUtpSupported() (#5766)
This commit is contained in:
parent
0350b62248
commit
bc562eb9a5
3 changed files with 26 additions and 38 deletions
|
@ -104,13 +104,7 @@ public:
|
|||
return session_.allowsTCP();
|
||||
}
|
||||
|
||||
void set_utp_failed(tr_sha1_digest_t const& info_hash, tr_socket_address const& socket_address) override
|
||||
{
|
||||
if (auto* const tor = session_.torrents().get(info_hash); tor != nullptr)
|
||||
{
|
||||
tr_peerMgrSetUtpFailed(tor, socket_address, true);
|
||||
}
|
||||
}
|
||||
void set_utp_failed(tr_sha1_digest_t const& info_hash, tr_socket_address const& socket_address) override;
|
||||
|
||||
[[nodiscard]] libtransmission::TimerMaker& timer_maker() override
|
||||
{
|
||||
|
@ -508,18 +502,6 @@ public:
|
|||
return it != pool.end() ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] peer_atom const* get_existing_atom(tr_socket_address const& socket_address) const noexcept
|
||||
{
|
||||
auto const& it = pool.find(socket_address);
|
||||
return it != pool.cend() ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool peer_is_a_seed(tr_socket_address const& socket_address) const noexcept
|
||||
{
|
||||
auto const* const atom = get_existing_atom(socket_address);
|
||||
return atom != nullptr && atom->isSeed();
|
||||
}
|
||||
|
||||
peer_atom* ensure_atom_exists(tr_socket_address const& socket_address, uint8_t const flags, uint8_t const from)
|
||||
{
|
||||
TR_ASSERT(socket_address.first.is_valid());
|
||||
|
@ -940,20 +922,18 @@ void tr_peerMgrFree(tr_peerMgr* manager)
|
|||
|
||||
// ---
|
||||
|
||||
void tr_peerMgrSetUtpSupported(tr_torrent* tor, tr_socket_address const& socket_address)
|
||||
void tr_peerMgrSetUtpSupported(peer_atom* atom)
|
||||
{
|
||||
if (auto* const atom = tor->swarm->get_existing_atom(socket_address); atom != nullptr)
|
||||
{
|
||||
atom->flags |= ADDED_F_UTP_FLAGS;
|
||||
}
|
||||
TR_ASSERT(atom != nullptr);
|
||||
|
||||
atom->flags |= ADDED_F_UTP_FLAGS;
|
||||
}
|
||||
|
||||
void tr_peerMgrSetUtpFailed(tr_torrent* tor, tr_socket_address const& socket_address, bool failed)
|
||||
void tr_peerMgrSetUtpFailed(peer_atom* atom, bool failed)
|
||||
{
|
||||
if (auto* const atom = tor->swarm->get_existing_atom(socket_address); atom != nullptr)
|
||||
{
|
||||
atom->utp_failed = failed;
|
||||
}
|
||||
TR_ASSERT(atom != nullptr);
|
||||
|
||||
atom->utp_failed = failed;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1132,9 +1112,7 @@ void create_bit_torrent_peer(tr_torrent* tor, std::shared_ptr<tr_peerIo> io, str
|
|||
{
|
||||
if (s != nullptr)
|
||||
{
|
||||
struct peer_atom* atom = s->get_existing_atom(socket_address);
|
||||
|
||||
if (atom != nullptr)
|
||||
if (peer_atom* const atom = s->get_existing_atom(socket_address); atom != nullptr)
|
||||
{
|
||||
++atom->num_fails;
|
||||
|
||||
|
@ -2546,3 +2524,14 @@ void tr_peerMgr::make_new_peer_connections()
|
|||
// remove the N candidates that we just consumed
|
||||
candidates.resize(std::size(candidates) - n_this_pass);
|
||||
}
|
||||
|
||||
void HandshakeMediator::set_utp_failed(tr_sha1_digest_t const& info_hash, tr_socket_address const& socket_address)
|
||||
{
|
||||
if (auto* const tor = session_.torrents().get(info_hash); tor != nullptr)
|
||||
{
|
||||
if (auto* const atom = tor->swarm->get_existing_atom(socket_address); atom != nullptr)
|
||||
{
|
||||
tr_peerMgrSetUtpFailed(atom, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,9 +156,9 @@ constexpr bool tr_isPex(tr_pex const* pex)
|
|||
|
||||
void tr_peerMgrFree(tr_peerMgr* manager);
|
||||
|
||||
void tr_peerMgrSetUtpSupported(tr_torrent* tor, tr_socket_address const& socket_address);
|
||||
void tr_peerMgrSetUtpSupported(struct peer_atom* atom);
|
||||
|
||||
void tr_peerMgrSetUtpFailed(tr_torrent* tor, tr_socket_address const& socket_address, bool failed);
|
||||
void tr_peerMgrSetUtpFailed(struct peer_atom*, bool failed);
|
||||
|
||||
[[nodiscard]] std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_peer const* peer, size_t numwant);
|
||||
|
||||
|
|
|
@ -345,9 +345,8 @@ public:
|
|||
|
||||
if (io->supports_utp())
|
||||
{
|
||||
auto const& socket_address = socketAddress();
|
||||
tr_peerMgrSetUtpSupported(torrent, socket_address);
|
||||
tr_peerMgrSetUtpFailed(torrent, socket_address, false);
|
||||
tr_peerMgrSetUtpSupported(atom);
|
||||
tr_peerMgrSetUtpFailed(atom, false);
|
||||
}
|
||||
|
||||
if (io->supports_ltep())
|
||||
|
@ -1102,7 +1101,7 @@ void parseLtepHandshake(tr_peerMsgsImpl* msgs, MessageReader& payload)
|
|||
{
|
||||
/* Mysterious µTorrent extension that we don't grok. However,
|
||||
it implies support for µTP, so use it to indicate that. */
|
||||
tr_peerMgrSetUtpFailed(msgs->torrent, msgs->socketAddress(), false);
|
||||
tr_peerMgrSetUtpFailed(msgs->atom, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue