Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ class CNode
RecursiveMutex cs_sendProcessing;

uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};

std::atomic<int64_t> nLastSend{0};
std::atomic<int64_t> nLastRecv{0};
//! Unix epoch time at peer connection, in seconds.
Expand Down
34 changes: 34 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,40 @@ QString formatBytes(uint64_t bytes)
return QObject::tr("%1 GB").arg(bytes / 1'000'000'000);
}

QString formatBps(float bits)
{
if (bits < 10)
//: "Bits per second"
return QObject::tr("%1 bps").arg(0.01 * int(bits * 100));
if (bits < 100)
//: "Bits per second"
return QObject::tr("%1 bps").arg(0.1 * int(bits * 10));
if (bits < 1'000)
//: "Bits per second"
return QObject::tr("%1 bps").arg((int)bits);
if (bits < 10'000)
//: "Kilobits per second"
return QObject::tr("%1 kbps").arg(0.01 * ((int)bits / 10));
if (bits < 100'000)
//: "Kilobits per second"
return QObject::tr("%1 kbps").arg(0.1 * ((int)bits / 100));
if (bits < 1'000'000)
//: "Kilobits per second"
return QObject::tr("%1 kbps").arg((int)bits / 1'000);
if (bits < 10'000'000)
//: "Megabits per second"
return QObject::tr("%1 Mbps").arg(0.01 * ((int)bits / 10'000));
if (bits < 100'000'000)
//: "Megabits per second"
return QObject::tr("%1 Mbps").arg(0.1 * ((int)bits / 100'000));
if (bits < 10'000'000'000)
//: "Megabits per second"
return QObject::tr("%1 Mbps").arg((long)bits / 1'000'000);

//: "Gigabits per second"
return QObject::tr("%1 Gbps").arg((long)bits / 1'000'000'000);
}

qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize, qreal font_size) {
while(font_size >= minPointSize) {
font.setPointSizeF(font_size);
Expand Down
1 change: 1 addition & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ namespace GUIUtil
QString formatNiceTimeOffset(qint64 secs);

QString formatBytes(uint64_t bytes);
QString formatBps(float bits);

qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14);

Expand Down
20 changes: 15 additions & 5 deletions src/qt/peertablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,20 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
return GUIUtil::NetworkToQString(rec->nodeStats.m_network);
case Ping:
return GUIUtil::formatPingTime(rec->nodeStats.m_min_ping_time);
case Sent:
return GUIUtil::formatBytes(rec->nodeStats.nSendBytes);
case Received:
return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes);
case Sent: {
int64_t now = GetTimeSeconds();
if (now != rec->nodeStats.nTimeConnected) // Avoid division by zero
return GUIUtil::formatBps(rec->nodeStats.nSendBytes * 8.0 / (now - rec->nodeStats.nTimeConnected));
else
return QString::fromStdString("");
}
case Recv: {
int64_t now = GetTimeSeconds();
if (rec->nodeStats.nTimeConnected != now)
return GUIUtil::formatBps(rec->nodeStats.nRecvBytes * 8.0 / (now - rec->nodeStats.nTimeConnected));
else
return QString::fromStdString("");
}
case Subversion:
return QString::fromStdString(rec->nodeStats.cleanSubVer);
} // no default case, so the compiler can warn about missing cases
Expand All @@ -105,7 +115,7 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
return QVariant(Qt::AlignCenter);
case Ping:
case Sent:
case Received:
case Recv:
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
case Subversion:
return {};
Expand Down
8 changes: 4 additions & 4 deletions src/qt/peertablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PeerTableModel : public QAbstractTableModel
Network,
Ping,
Sent,
Received,
Recv,
Subversion
};

Expand Down Expand Up @@ -97,12 +97,12 @@ public Q_SLOTS:
/*: Title of Peers Table column which indicates the current latency
of the connection with the peer. */
tr("Ping"),
/*: Title of Peers Table column which indicates the total amount of
/*: Title of Peers Table column which indicates the speed of
network information we have sent to the peer. */
tr("Sent"),
/*: Title of Peers Table column which indicates the total amount of
/*: Title of Peers Table column which indicates the speed of
network information we have received from the peer. */
tr("Received"),
tr("Recv"),
/*: Title of Peers Table column which contains the peer's
User Agent string. */
tr("User Agent")};
Expand Down
17 changes: 13 additions & 4 deletions src/qt/peertablesortproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelInd
return left_stats.m_network < right_stats.m_network;
case PeerTableModel::Ping:
return left_stats.m_min_ping_time < right_stats.m_min_ping_time;
case PeerTableModel::Sent:
return left_stats.nSendBytes < right_stats.nSendBytes;
case PeerTableModel::Received:
return left_stats.nRecvBytes < right_stats.nRecvBytes;
case PeerTableModel::Sent: {
int64_t now = GetTimeSeconds();
int Right = right_stats.nSendBytes * 8 / (now + 1 - right_stats.nTimeConnected);
int Left = left_stats.nSendBytes * 8 / (now + 1 - left_stats.nTimeConnected);
return Left < Right;
}
case PeerTableModel::Recv: {
int64_t now = GetTimeSeconds();
int Right = right_stats.nRecvBytes * 8 / (now + 1 - right_stats.nTimeConnected);
int Left = left_stats.nRecvBytes * 8 / (now + 1 - left_stats.nTimeConnected);
return Left < Right;
}

case PeerTableModel::Subversion:
return left_stats.cleanSubVer.compare(right_stats.cleanSubVer) < 0;
} // no default case, so the compiler can warn about missing cases
Expand Down