refactor: stop tracking peerIo creation time (#4300)

This commit is contained in:
Charles Kerr 2022-12-02 10:39:46 -06:00 committed by GitHub
parent bf6c80ae35
commit 728e5b8350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 6 additions and 42 deletions

View File

@ -474,7 +474,6 @@ std::shared_ptr<tr_peerIo> tr_peerIo::create(
tr_bandwidth* parent,
tr_address const* addr,
tr_port port,
time_t current_time,
tr_sha1_digest_t const* torrent_hash,
bool is_incoming,
bool is_seed,
@ -492,9 +491,7 @@ std::shared_ptr<tr_peerIo> tr_peerIo::create(
maybeSetCongestionAlgorithm(socket.handle.tcp, session->peerCongestionAlgorithm());
}
auto io = std::shared_ptr<tr_peerIo>{
new tr_peerIo{ session, torrent_hash, is_incoming, *addr, port, is_seed, current_time, parent }
};
auto io = std::shared_ptr<tr_peerIo>{ new tr_peerIo{ session, torrent_hash, is_incoming, *addr, port, is_seed, parent } };
io->socket = socket;
io->bandwidth().setPeer(io);
tr_logAddTraceIo(io, fmt::format("bandwidth is {}; its parent is {}", fmt::ptr(&io->bandwidth()), fmt::ptr(parent)));
@ -543,13 +540,12 @@ std::shared_ptr<tr_peerIo> tr_peerIo::newIncoming(
tr_bandwidth* parent,
tr_address const* addr,
tr_port port,
time_t current_time,
struct tr_peer_socket const socket)
{
TR_ASSERT(session != nullptr);
TR_ASSERT(tr_address_is_valid(addr));
return tr_peerIo::create(session, parent, addr, port, current_time, nullptr, true, false, socket);
return tr_peerIo::create(session, parent, addr, port, nullptr, true, false, socket);
}
std::shared_ptr<tr_peerIo> tr_peerIo::newOutgoing(
@ -557,7 +553,6 @@ std::shared_ptr<tr_peerIo> tr_peerIo::newOutgoing(
tr_bandwidth* parent,
tr_address const* addr,
tr_port port,
time_t current_time,
tr_sha1_digest_t const& torrent_hash,
bool is_seed,
bool utp)
@ -586,7 +581,7 @@ std::shared_ptr<tr_peerIo> tr_peerIo::newOutgoing(
return nullptr;
}
return create(session, parent, addr, port, current_time, &torrent_hash, false, is_seed, socket);
return create(session, parent, addr, port, &torrent_hash, false, is_seed, socket);
}
/***

View File

@ -70,7 +70,6 @@ public:
tr_bandwidth* parent,
struct tr_address const* addr,
tr_port port,
time_t current_time,
tr_sha1_digest_t const& torrent_hash,
bool is_seed,
bool utp);
@ -80,7 +79,6 @@ public:
tr_bandwidth* parent,
struct tr_address const* addr,
tr_port port,
time_t current_time,
struct tr_peer_socket const socket);
void clear();
@ -231,8 +229,6 @@ public:
tr_session* const session;
time_t const time_created;
tr_can_read_cb canRead = nullptr;
tr_did_write_cb didWrite = nullptr;
tr_net_error_cb gotError = nullptr;
@ -297,7 +293,6 @@ private:
tr_bandwidth* parent,
tr_address const* addr,
tr_port port,
time_t current_time,
tr_sha1_digest_t const* torrent_hash,
bool is_incoming,
bool is_seed,
@ -310,10 +305,8 @@ private:
tr_address const& addr,
tr_port port,
bool is_seed,
time_t current_time,
tr_bandwidth* parent_bandwidth)
: session{ session_in }
, time_created{ current_time }
, bandwidth_{ parent_bandwidth }
, torrent_hash_{ torrent_hash != nullptr ? *torrent_hash : tr_sha1_digest_t{} }
, addr_{ addr }

View File

@ -1244,7 +1244,7 @@ void tr_peerMgrAddIncoming(tr_peerMgr* manager, tr_address const& addr, tr_port
{
auto* const handshake = tr_handshakeNew(
std::make_unique<tr_handshake_mediator_impl>(*session),
tr_peerIo::newIncoming(session, &session->top_bandwidth_, &addr, port, tr_time(), socket),
tr_peerIo::newIncoming(session, &session->top_bandwidth_, &addr, port, socket),
session->encryptionMode(),
on_handshake_done,
manager);
@ -2085,13 +2085,6 @@ struct ChokeData
}
};
/* is this a new connection? */
[[nodiscard]] bool isNew(tr_peerMsgs const* msgs)
{
auto constexpr CutoffSecs = time_t{ 45 };
return msgs != nullptr && !msgs->is_connection_older_than(tr_time() - CutoffSecs);
}
/* get a rate for deciding which peers to choke and unchoke. */
[[nodiscard]] auto getRateBps(tr_torrent const* tor, tr_peer const* peer, uint64_t now)
{
@ -2213,12 +2206,7 @@ void rechokeUploads(tr_swarm* s, uint64_t const now)
{
if (choked[i].is_interested)
{
int const x = isNew(choked[i].msgs) ? 3 : 1;
for (int y = 0; y < x; ++y)
{
rand_pool.push_back(&choked[i]);
}
rand_pool.push_back(&choked[i]);
}
}
@ -2807,7 +2795,6 @@ void initiateConnection(tr_peerMgr* mgr, tr_swarm* s, peer_atom& atom)
&mgr->session->top_bandwidth_,
&atom.addr,
atom.port,
tr_time(),
s->tor->infoHash(),
s->tor->completeness == TR_SEED,
utp);

View File

@ -407,11 +407,6 @@ public:
set_active(direction, calculate_active(direction));
}
[[nodiscard]] bool is_connection_older_than(time_t timestamp) const noexcept override
{
return io->time_created < timestamp;
}
[[nodiscard]] std::pair<tr_address, tr_port> socketAddress() const override
{
return io->socketAddress();

View File

@ -49,8 +49,6 @@ public:
[[nodiscard]] virtual bool is_active(tr_direction direction) const = 0;
virtual void update_active(tr_direction direction) = 0;
[[nodiscard]] virtual bool is_connection_older_than(time_t time) const noexcept = 0;
[[nodiscard]] virtual std::pair<tr_address, tr_port> socketAddress() const = 0;
virtual void cancel_block_request(tr_block_index_t block) = 0;

View File

@ -158,10 +158,8 @@ public:
{
auto sockpair = std::array<evutil_socket_t, 2>{ -1, -1 };
EXPECT_EQ(0, evutil_socketpair(LOCAL_SOCKETPAIR_AF, SOCK_STREAM, 0, std::data(sockpair))) << tr_strerror(errno);
auto const now = tr_time();
auto const peer_socket = tr_peer_socket_tcp_create(sockpair[0]);
auto
io = tr_peerIo::newIncoming(session, &session->top_bandwidth_, &DefaultPeerAddr, DefaultPeerPort, now, peer_socket);
auto io = tr_peerIo::newIncoming(session, &session->top_bandwidth_, &DefaultPeerAddr, DefaultPeerPort, peer_socket);
return std::make_pair(io, sockpair[1]);
}
@ -169,14 +167,12 @@ public:
{
auto sockpair = std::array<evutil_socket_t, 2>{ -1, -1 };
EXPECT_EQ(0, evutil_socketpair(LOCAL_SOCKETPAIR_AF, SOCK_STREAM, 0, std::data(sockpair))) << tr_strerror(errno);
auto const now = tr_time();
auto const peer_socket = tr_peer_socket_tcp_create(sockpair[0]);
auto io = tr_peerIo::create(
session,
&session->top_bandwidth_,
&DefaultPeerAddr,
DefaultPeerPort,
now,
&info_hash,
false /*is_incoming*/,
false /*is_seed*/,