mirror of
https://github.com/transmission/transmission
synced 2025-03-10 06:02:57 +00:00
refactor: add tr_peer.activeReqCount() (#3373)
rename peer_stats.pendingReqs to .activeReqs for consistency
This commit is contained in:
parent
7e278c453a
commit
88a3149ce4
8 changed files with 66 additions and 21 deletions
|
@ -1327,14 +1327,14 @@ void refreshPeerRow(Gtk::TreeIter const& iter, tr_peer_stat const* peer)
|
|||
down_speed = tr_formatter_speed_KBps(peer->rateToClient_KBps);
|
||||
}
|
||||
|
||||
if (peer->pendingReqsToPeer > 0)
|
||||
if (peer->activeReqsToPeer > 0)
|
||||
{
|
||||
down_count = std::to_string(peer->pendingReqsToPeer);
|
||||
down_count = std::to_string(peer->activeReqsToPeer);
|
||||
}
|
||||
|
||||
if (peer->pendingReqsToClient > 0)
|
||||
if (peer->activeReqsToClient > 0)
|
||||
{
|
||||
up_count = std::to_string(peer->pendingReqsToClient);
|
||||
up_count = std::to_string(peer->activeReqsToClient);
|
||||
}
|
||||
|
||||
if (peer->blocksToPeer > 0)
|
||||
|
@ -1358,9 +1358,9 @@ void refreshPeerRow(Gtk::TreeIter const& iter, tr_peer_stat const* peer)
|
|||
}
|
||||
|
||||
(*iter)[peer_cols.progress] = (int)(100.0 * peer->progress);
|
||||
(*iter)[peer_cols.upload_request_count_int] = peer->pendingReqsToClient;
|
||||
(*iter)[peer_cols.upload_request_count_int] = peer->activeReqsToClient;
|
||||
(*iter)[peer_cols.upload_request_count_string] = up_count;
|
||||
(*iter)[peer_cols.download_request_count_int] = peer->pendingReqsToPeer;
|
||||
(*iter)[peer_cols.download_request_count_int] = peer->activeReqsToPeer;
|
||||
(*iter)[peer_cols.download_request_count_string] = down_count;
|
||||
(*iter)[peer_cols.download_rate_double] = peer->rateToClient_KBps;
|
||||
(*iter)[peer_cols.download_rate_string] = down_speed;
|
||||
|
|
|
@ -236,6 +236,11 @@ public:
|
|||
tr_bandwidth_limits getLimits() const;
|
||||
void setLimits(tr_bandwidth_limits const* limits);
|
||||
|
||||
[[nodiscard]] constexpr auto* parent() noexcept
|
||||
{
|
||||
return parent_;
|
||||
}
|
||||
|
||||
private:
|
||||
static unsigned int getSpeedBytesPerSecond(RateControl& r, unsigned int interval_msec, uint64_t now);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
class tr_peer;
|
||||
class tr_swarm;
|
||||
struct Bandwidth;
|
||||
struct peer_atom;
|
||||
|
||||
/**
|
||||
|
@ -81,6 +82,11 @@ public:
|
|||
|
||||
[[nodiscard]] virtual bool hasPiece(tr_piece_index_t piece) const noexcept = 0;
|
||||
|
||||
[[nodiscard]] virtual Bandwidth* bandwidth() noexcept = 0;
|
||||
|
||||
// requests that have been made but haven't been fulfilled yet
|
||||
[[nodiscard]] virtual size_t activeReqCount(tr_direction) const noexcept = 0;
|
||||
|
||||
tr_session* const session;
|
||||
|
||||
tr_swarm* const swarm;
|
||||
|
|
|
@ -1654,8 +1654,8 @@ namespace peer_stat_helpers
|
|||
stats.cancelsToPeer = peer->cancels_sent_to_peer.count(now, CancelHistorySec);
|
||||
stats.cancelsToClient = peer->cancels_sent_to_client.count(now, CancelHistorySec);
|
||||
|
||||
stats.pendingReqsToPeer = peer->swarm->active_requests.count(peer);
|
||||
stats.pendingReqsToClient = peer->pendingReqsToClient();
|
||||
stats.activeReqsToPeer = peer->activeReqCount(TR_CLIENT_TO_PEER);
|
||||
stats.activeReqsToClient = peer->activeReqCount(TR_PEER_TO_CLIENT);
|
||||
|
||||
char* pch = stats.flagStr;
|
||||
|
||||
|
|
|
@ -308,9 +308,20 @@ public:
|
|||
return Bps > 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t pendingReqsToClient() const noexcept override
|
||||
[[nodiscard]] size_t activeReqCount(tr_direction dir) const noexcept override
|
||||
{
|
||||
return std::size(peer_requested_);
|
||||
switch (dir)
|
||||
{
|
||||
case TR_CLIENT_TO_PEER: // requests we sent
|
||||
return tr_peerMgrCountActiveRequestsToPeer(torrent, this);
|
||||
|
||||
case TR_PEER_TO_CLIENT: // requests they sent
|
||||
return std::size(peer_requested_);
|
||||
|
||||
default:
|
||||
TR_ASSERT(0);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] bool is_peer_choked() const noexcept override
|
||||
|
@ -348,6 +359,11 @@ public:
|
|||
return io->isIncoming();
|
||||
}
|
||||
|
||||
[[nodiscard]] Bandwidth* bandwidth() noexcept override
|
||||
{
|
||||
return io->bandwidth;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool is_active(tr_direction direction) const override
|
||||
{
|
||||
TR_ASSERT(tr_isDirection(direction));
|
||||
|
@ -683,6 +699,8 @@ public:
|
|||
|
||||
evbuffer* const outMessages; /* all the non-piece messages */
|
||||
|
||||
tr_peerIo* const io;
|
||||
|
||||
struct QueuedPeerRequest : public peer_request
|
||||
{
|
||||
explicit QueuedPeerRequest(peer_request in) noexcept
|
||||
|
@ -716,8 +734,6 @@ public:
|
|||
|
||||
UniqueTimer pex_timer;
|
||||
|
||||
tr_peerIo* io = nullptr;
|
||||
|
||||
tr_bitfield have_;
|
||||
|
||||
private:
|
||||
|
|
|
@ -37,9 +37,6 @@ public:
|
|||
|
||||
virtual ~tr_peerMsgs() override = default;
|
||||
|
||||
/* how many requests the peer has made that we haven't responded to yet */
|
||||
[[nodiscard]] virtual size_t pendingReqsToClient() const noexcept = 0;
|
||||
|
||||
[[nodiscard]] virtual bool is_peer_choked() const noexcept = 0;
|
||||
[[nodiscard]] virtual bool is_peer_interested() const noexcept = 0;
|
||||
[[nodiscard]] virtual bool is_client_choked() const noexcept = 0;
|
||||
|
|
|
@ -1291,10 +1291,10 @@ struct tr_peer_stat
|
|||
uint32_t cancelsToClient;
|
||||
|
||||
/* how many requests the peer has made that we haven't responded to yet */
|
||||
int pendingReqsToClient;
|
||||
int activeReqsToClient;
|
||||
|
||||
/* how many requests we've made and are currently awaiting a response for */
|
||||
int pendingReqsToPeer;
|
||||
int activeReqsToPeer;
|
||||
};
|
||||
|
||||
tr_peer_stat* tr_torrentPeers(tr_torrent const* torrent, int* peerCount);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <numeric> // std::accumulate()
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
@ -158,7 +159,7 @@ public:
|
|||
, base_url{ url }
|
||||
, callback{ callback_in }
|
||||
, callback_data{ callback_data_in }
|
||||
, bandwidth(&tor->bandwidth_)
|
||||
, bandwidth_(&tor->bandwidth_)
|
||||
, pulse_timer(evtimer_new(session->event_base, &tr_webseed::onTimer, this), event_free)
|
||||
{
|
||||
startTimer();
|
||||
|
@ -184,7 +185,7 @@ public:
|
|||
if (direction == TR_DOWN)
|
||||
{
|
||||
is_active = !std::empty(tasks);
|
||||
Bps = bandwidth.getPieceSpeedBytesPerSecond(now, direction);
|
||||
Bps = bandwidth_.getPieceSpeedBytesPerSecond(now, direction);
|
||||
}
|
||||
|
||||
if (setme_Bps != nullptr)
|
||||
|
@ -195,6 +196,26 @@ public:
|
|||
return is_active;
|
||||
}
|
||||
|
||||
[[nodiscard]] Bandwidth* bandwidth() noexcept override
|
||||
{
|
||||
return &bandwidth_;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t activeReqCount(tr_direction dir) const noexcept override
|
||||
{
|
||||
if (dir == TR_CLIENT_TO_PEER) // blocks we've requested
|
||||
{
|
||||
return std::accumulate(
|
||||
std::begin(tasks),
|
||||
std::end(tasks),
|
||||
size_t{},
|
||||
[](size_t sum, auto const* task) { return sum + (task->blocks.end - task->blocks.begin); });
|
||||
}
|
||||
|
||||
// webseed will never request blocks from us
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string readable() const override
|
||||
{
|
||||
if (auto const parsed = tr_urlParse(base_url); parsed)
|
||||
|
@ -212,7 +233,7 @@ public:
|
|||
|
||||
void gotPieceData(uint32_t n_bytes)
|
||||
{
|
||||
bandwidth.notifyBandwidthConsumed(TR_DOWN, n_bytes, true, tr_time_msec());
|
||||
bandwidth_.notifyBandwidthConsumed(TR_DOWN, n_bytes, true, tr_time_msec());
|
||||
publishClientGotPieceData(n_bytes);
|
||||
connection_limiter.gotData();
|
||||
}
|
||||
|
@ -249,7 +270,6 @@ public:
|
|||
tr_peer_callback const callback;
|
||||
void* const callback_data;
|
||||
|
||||
Bandwidth bandwidth;
|
||||
ConnectionLimiter connection_limiter;
|
||||
std::set<tr_webseed_task*> tasks;
|
||||
|
||||
|
@ -282,6 +302,7 @@ private:
|
|||
webseed->startTimer();
|
||||
}
|
||||
|
||||
Bandwidth bandwidth_;
|
||||
std::shared_ptr<event> const pulse_timer;
|
||||
static int constexpr IdleTimerMsec = 2000;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue