|
| 1 | +// Copyright (c) 2024 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#ifndef BITCOIN_QML_MODELS_PEERDETAILSMODEL_H |
| 6 | +#define BITCOIN_QML_MODELS_PEERDETAILSMODEL_H |
| 7 | + |
| 8 | +#include <QObject> |
| 9 | + |
| 10 | +#include <qt/guiutil.h> |
| 11 | +#include <qt/peertablemodel.h> |
| 12 | +#include <qt/rpcconsole.h> |
| 13 | +#include <util/time.h> |
| 14 | + |
| 15 | +class PeerDetailsModel : public QObject |
| 16 | +{ |
| 17 | + Q_OBJECT |
| 18 | + Q_PROPERTY(int nodeId READ nodeId NOTIFY dataChanged) |
| 19 | + Q_PROPERTY(QString address READ address NOTIFY dataChanged) |
| 20 | + Q_PROPERTY(QString addressLocal READ addressLocal NOTIFY dataChanged) |
| 21 | + Q_PROPERTY(QString type READ type NOTIFY dataChanged) |
| 22 | + Q_PROPERTY(QString version READ version NOTIFY dataChanged) |
| 23 | + Q_PROPERTY(QString userAgent READ userAgent NOTIFY dataChanged) |
| 24 | + Q_PROPERTY(QString services READ services NOTIFY dataChanged) |
| 25 | + Q_PROPERTY(bool transactionRelay READ transactionRelay NOTIFY dataChanged) |
| 26 | + Q_PROPERTY(bool addressRelay READ addressRelay NOTIFY dataChanged) |
| 27 | + Q_PROPERTY(QString startingHeight READ startingHeight NOTIFY dataChanged) |
| 28 | + Q_PROPERTY(QString syncedHeaders READ syncedHeaders NOTIFY dataChanged) |
| 29 | + Q_PROPERTY(QString syncedBlocks READ syncedBlocks NOTIFY dataChanged) |
| 30 | + Q_PROPERTY(QString direction READ direction NOTIFY dataChanged) |
| 31 | + Q_PROPERTY(QString connectionDuration READ connectionDuration NOTIFY dataChanged) |
| 32 | + Q_PROPERTY(QString lastSend READ lastSend NOTIFY dataChanged) |
| 33 | + Q_PROPERTY(QString lastReceived READ lastReceived NOTIFY dataChanged) |
| 34 | + Q_PROPERTY(QString bytesSent READ bytesSent NOTIFY dataChanged) |
| 35 | + Q_PROPERTY(QString bytesReceived READ bytesReceived NOTIFY dataChanged) |
| 36 | + Q_PROPERTY(QString pingTime READ pingTime NOTIFY dataChanged) |
| 37 | + Q_PROPERTY(QString pingWait READ pingWait NOTIFY dataChanged) |
| 38 | + Q_PROPERTY(QString pingMin READ pingMin NOTIFY dataChanged) |
| 39 | + Q_PROPERTY(QString timeOffset READ timeOffset NOTIFY dataChanged) |
| 40 | + Q_PROPERTY(QString mappedAS READ mappedAS NOTIFY dataChanged) |
| 41 | + Q_PROPERTY(QString permission READ permission NOTIFY dataChanged) |
| 42 | + |
| 43 | +public: |
| 44 | + explicit PeerDetailsModel(CNodeCombinedStats* nodeStats, PeerTableModel* model); |
| 45 | + |
| 46 | + int nodeId() const { return m_combinedStats->nodeStats.nodeid; } |
| 47 | + QString address() const { return QString::fromStdString(m_combinedStats->nodeStats.m_addr_name); } |
| 48 | + QString addressLocal() const { return QString::fromStdString(m_combinedStats->nodeStats.addrLocal); } |
| 49 | + QString type() const { return GUIUtil::ConnectionTypeToQString(m_combinedStats->nodeStats.m_conn_type, /*prepend_direction=*/true); } |
| 50 | + QString version() const { return QString::number(m_combinedStats->nodeStats.nVersion); } |
| 51 | + QString userAgent() const { return QString::fromStdString(m_combinedStats->nodeStats.cleanSubVer); } |
| 52 | + QString services() const { return GUIUtil::formatServicesStr(m_combinedStats->nodeStateStats.their_services); } |
| 53 | + bool transactionRelay() const { return m_combinedStats->nodeStateStats.m_relay_txs; } |
| 54 | + bool addressRelay() const { return m_combinedStats->nodeStateStats.m_addr_relay_enabled; } |
| 55 | + QString startingHeight() const { return QString::number(m_combinedStats->nodeStateStats.m_starting_height); } |
| 56 | + QString syncedHeaders() const { return QString::number(m_combinedStats->nodeStateStats.nSyncHeight); } |
| 57 | + QString syncedBlocks() const { return QString::number(m_combinedStats->nodeStateStats.nCommonHeight); } |
| 58 | + QString direction() const { return QString::fromStdString(m_combinedStats->nodeStats.fInbound ? "Inbound" : "Outbound"); } |
| 59 | + QString connectionDuration() const { return GUIUtil::formatDurationStr(GetTime<std::chrono::seconds>() - m_combinedStats->nodeStats.m_connected); } |
| 60 | + QString lastSend() const { return GUIUtil::formatDurationStr(GetTime<std::chrono::seconds>() - m_combinedStats->nodeStats.m_last_send); } |
| 61 | + QString lastReceived() const { return GUIUtil::formatDurationStr(GetTime<std::chrono::seconds>() - m_combinedStats->nodeStats.m_last_recv); } |
| 62 | + QString bytesSent() const { return GUIUtil::formatBytes(m_combinedStats->nodeStats.nSendBytes); } |
| 63 | + QString bytesReceived() const { return GUIUtil::formatBytes(m_combinedStats->nodeStats.nRecvBytes); } |
| 64 | + QString pingTime() const { return GUIUtil::formatPingTime(m_combinedStats->nodeStats.m_last_ping_time); } |
| 65 | + QString pingMin() const { return GUIUtil::formatPingTime(m_combinedStats->nodeStats.m_min_ping_time); } |
| 66 | + QString pingWait() const { return GUIUtil::formatPingTime(m_combinedStats->nodeStateStats.m_ping_wait); } |
| 67 | + QString timeOffset() const { return GUIUtil::formatTimeOffset(m_combinedStats->nodeStats.nTimeOffset); } |
| 68 | + QString mappedAS() const { return m_combinedStats->nodeStats.m_mapped_as != 0 ? QString::number(m_combinedStats->nodeStats.m_mapped_as) : tr("N/A"); } |
| 69 | + QString permission() const { |
| 70 | + if (m_combinedStats->nodeStats.m_permission_flags == NetPermissionFlags::None) { |
| 71 | + return tr("N/A"); |
| 72 | + } |
| 73 | + QStringList permissions; |
| 74 | + for (const auto& permission : NetPermissions::ToStrings(m_combinedStats->nodeStats.m_permission_flags)) { |
| 75 | + permissions.append(QString::fromStdString(permission)); |
| 76 | + } |
| 77 | + return permissions.join(" & "); |
| 78 | + } |
| 79 | + |
| 80 | +Q_SIGNALS: |
| 81 | + void dataChanged(); |
| 82 | + void disconnected(); |
| 83 | + |
| 84 | +private Q_SLOTS: |
| 85 | + void onModelRowsRemoved(const QModelIndex& parent, int first, int last); |
| 86 | + void onModelDataChanged(const QModelIndex& top_left, const QModelIndex& bottom_right); |
| 87 | + |
| 88 | +private: |
| 89 | + int m_row; |
| 90 | + CNodeCombinedStats* m_combinedStats; |
| 91 | + PeerTableModel* m_model; |
| 92 | + bool m_disconnected; |
| 93 | +}; |
| 94 | + |
| 95 | +#endif // BITCOIN_QML_MODELS_PEERDETAILSMODEL_H |
0 commit comments