-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PeerDetails page [Alternative] #388
Draft
jarolrod
wants to merge
3
commits into
bitcoin-core:main
Choose a base branch
from
jarolrod:peer-details-alternate
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <qml/models/peerdetailsmodel.h> | ||
|
||
PeerDetailsModel::PeerDetailsModel(CNodeCombinedStats* nodeStats, PeerTableModel* parent) | ||
: m_combinedStats{nodeStats} | ||
, m_model{parent} | ||
, m_disconnected{false} | ||
{ | ||
for (int row = 0; row < m_model->rowCount(); ++row) { | ||
QModelIndex index = m_model->index(row, 0); | ||
int nodeIdInRow = m_model->data(index, PeerTableModel::NetNodeId).toInt(); | ||
if (nodeIdInRow == m_combinedStats->nodeStats.nodeid) { | ||
m_row = row; | ||
break; | ||
} | ||
} | ||
connect(parent, &PeerTableModel::rowsRemoved, this, &PeerDetailsModel::onModelRowsRemoved); | ||
connect(parent, &PeerTableModel::dataChanged, this, &PeerDetailsModel::onModelDataChanged); | ||
} | ||
|
||
void PeerDetailsModel::onModelRowsRemoved(const QModelIndex& parent, int first, int last) | ||
{ | ||
for (int row = first; row <= last; ++row) { | ||
QModelIndex index = m_model->index(row, 0, parent); | ||
int nodeIdInRow = m_model->data(index, PeerTableModel::NetNodeId).toInt(); | ||
if (nodeIdInRow == this->nodeId()) { | ||
if (!m_disconnected) { | ||
m_disconnected = true; | ||
Q_EMIT disconnected(); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void PeerDetailsModel::onModelDataChanged(const QModelIndex& /* top_left */, const QModelIndex& /* bottom_right */) | ||
{ | ||
if (m_model->data(m_model->index(m_row, 0), PeerTableModel::NetNodeId).isNull() || | ||
m_model->data(m_model->index(m_row, 0), PeerTableModel::NetNodeId).toInt() != nodeId()) { | ||
if (!m_disconnected) { | ||
m_disconnected = true; | ||
Q_EMIT disconnected(); | ||
} | ||
return; | ||
} | ||
|
||
m_combinedStats = m_model->data(m_model->index(m_row, 0), PeerTableModel::StatsRole).value<CNodeCombinedStats*>(); | ||
|
||
// Only update when all information is available | ||
if (m_combinedStats && m_combinedStats->fNodeStateStatsAvailable) { | ||
Q_EMIT dataChanged(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_QML_MODELS_PEERDETAILSMODEL_H | ||
#define BITCOIN_QML_MODELS_PEERDETAILSMODEL_H | ||
|
||
#include <QObject> | ||
|
||
#include <qt/guiutil.h> | ||
#include <qt/peertablemodel.h> | ||
#include <qt/rpcconsole.h> | ||
#include <util/time.h> | ||
|
||
class PeerDetailsModel : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(int nodeId READ nodeId NOTIFY dataChanged) | ||
Q_PROPERTY(QString address READ address NOTIFY dataChanged) | ||
Q_PROPERTY(QString addressLocal READ addressLocal NOTIFY dataChanged) | ||
Q_PROPERTY(QString type READ type NOTIFY dataChanged) | ||
Q_PROPERTY(QString version READ version NOTIFY dataChanged) | ||
Q_PROPERTY(QString userAgent READ userAgent NOTIFY dataChanged) | ||
Q_PROPERTY(QString services READ services NOTIFY dataChanged) | ||
Q_PROPERTY(bool transactionRelay READ transactionRelay NOTIFY dataChanged) | ||
Q_PROPERTY(bool addressRelay READ addressRelay NOTIFY dataChanged) | ||
Q_PROPERTY(QString startingHeight READ startingHeight NOTIFY dataChanged) | ||
Q_PROPERTY(QString syncedHeaders READ syncedHeaders NOTIFY dataChanged) | ||
Q_PROPERTY(QString syncedBlocks READ syncedBlocks NOTIFY dataChanged) | ||
Q_PROPERTY(QString direction READ direction NOTIFY dataChanged) | ||
Q_PROPERTY(QString connectionDuration READ connectionDuration NOTIFY dataChanged) | ||
Q_PROPERTY(QString lastSend READ lastSend NOTIFY dataChanged) | ||
Q_PROPERTY(QString lastReceived READ lastReceived NOTIFY dataChanged) | ||
Q_PROPERTY(QString bytesSent READ bytesSent NOTIFY dataChanged) | ||
Q_PROPERTY(QString bytesReceived READ bytesReceived NOTIFY dataChanged) | ||
Q_PROPERTY(QString pingTime READ pingTime NOTIFY dataChanged) | ||
Q_PROPERTY(QString pingWait READ pingWait NOTIFY dataChanged) | ||
Q_PROPERTY(QString pingMin READ pingMin NOTIFY dataChanged) | ||
Q_PROPERTY(QString timeOffset READ timeOffset NOTIFY dataChanged) | ||
Q_PROPERTY(QString mappedAS READ mappedAS NOTIFY dataChanged) | ||
Q_PROPERTY(QString permission READ permission NOTIFY dataChanged) | ||
|
||
public: | ||
explicit PeerDetailsModel(CNodeCombinedStats* nodeStats, PeerTableModel* model); | ||
|
||
int nodeId() const { return m_combinedStats->nodeStats.nodeid; } | ||
QString address() const { return QString::fromStdString(m_combinedStats->nodeStats.m_addr_name); } | ||
QString addressLocal() const { return QString::fromStdString(m_combinedStats->nodeStats.addrLocal); } | ||
QString type() const { return GUIUtil::ConnectionTypeToQString(m_combinedStats->nodeStats.m_conn_type, /*prepend_direction=*/true); } | ||
QString version() const { return QString::number(m_combinedStats->nodeStats.nVersion); } | ||
QString userAgent() const { return QString::fromStdString(m_combinedStats->nodeStats.cleanSubVer); } | ||
QString services() const { return GUIUtil::formatServicesStr(m_combinedStats->nodeStateStats.their_services); } | ||
bool transactionRelay() const { return m_combinedStats->nodeStateStats.m_relay_txs; } | ||
bool addressRelay() const { return m_combinedStats->nodeStateStats.m_addr_relay_enabled; } | ||
QString startingHeight() const { return QString::number(m_combinedStats->nodeStateStats.m_starting_height); } | ||
QString syncedHeaders() const { return QString::number(m_combinedStats->nodeStateStats.nSyncHeight); } | ||
QString syncedBlocks() const { return QString::number(m_combinedStats->nodeStateStats.nCommonHeight); } | ||
QString direction() const { return QString::fromStdString(m_combinedStats->nodeStats.fInbound ? "Inbound" : "Outbound"); } | ||
QString connectionDuration() const { return GUIUtil::formatDurationStr(GetTime<std::chrono::seconds>() - m_combinedStats->nodeStats.m_connected); } | ||
QString lastSend() const { return GUIUtil::formatDurationStr(GetTime<std::chrono::seconds>() - m_combinedStats->nodeStats.m_last_send); } | ||
QString lastReceived() const { return GUIUtil::formatDurationStr(GetTime<std::chrono::seconds>() - m_combinedStats->nodeStats.m_last_recv); } | ||
QString bytesSent() const { return GUIUtil::formatBytes(m_combinedStats->nodeStats.nSendBytes); } | ||
QString bytesReceived() const { return GUIUtil::formatBytes(m_combinedStats->nodeStats.nRecvBytes); } | ||
QString pingTime() const { return GUIUtil::formatPingTime(m_combinedStats->nodeStats.m_last_ping_time); } | ||
QString pingMin() const { return GUIUtil::formatPingTime(m_combinedStats->nodeStats.m_min_ping_time); } | ||
QString pingWait() const { return GUIUtil::formatPingTime(m_combinedStats->nodeStateStats.m_ping_wait); } | ||
QString timeOffset() const { return GUIUtil::formatTimeOffset(m_combinedStats->nodeStats.nTimeOffset); } | ||
QString mappedAS() const { return m_combinedStats->nodeStats.m_mapped_as != 0 ? QString::number(m_combinedStats->nodeStats.m_mapped_as) : tr("N/A"); } | ||
QString permission() const { | ||
if (m_combinedStats->nodeStats.m_permission_flags == NetPermissionFlags::None) { | ||
return tr("N/A"); | ||
} | ||
QStringList permissions; | ||
for (const auto& permission : NetPermissions::ToStrings(m_combinedStats->nodeStats.m_permission_flags)) { | ||
permissions.append(QString::fromStdString(permission)); | ||
} | ||
return permissions.join(" & "); | ||
} | ||
|
||
Q_SIGNALS: | ||
void dataChanged(); | ||
void disconnected(); | ||
|
||
private Q_SLOTS: | ||
void onModelRowsRemoved(const QModelIndex& parent, int first, int last); | ||
void onModelDataChanged(const QModelIndex& top_left, const QModelIndex& bottom_right); | ||
|
||
private: | ||
int m_row; | ||
CNodeCombinedStats* m_combinedStats; | ||
PeerTableModel* m_model; | ||
bool m_disconnected; | ||
}; | ||
|
||
#endif // BITCOIN_QML_MODELS_PEERDETAILSMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QML is camelCase