0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

qt: Use PeerTableModel::StatsRole

This change prevents direct calls to the PeerTableModel object that is a
layer violation.
This commit is contained in:
Hennadii Stepanov 2020-12-24 11:51:33 +02:00
parent 35007edf9c
commit 49c604077c
No known key found for this signature in database
GPG key ID: 410108112E7EA81F

View file

@ -1018,11 +1018,9 @@ void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
void RPCConsole::peerLayoutAboutToChange() void RPCConsole::peerLayoutAboutToChange()
{ {
QModelIndexList selected = ui->peerWidget->selectionModel()->selectedIndexes();
cachedNodeids.clear(); cachedNodeids.clear();
for(int i = 0; i < selected.size(); i++) for (const QModelIndex& peer : GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId)) {
{ const auto stats = peer.data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected.at(i).row());
cachedNodeids.append(stats->nodeStats.nodeid); cachedNodeids.append(stats->nodeStats.nodeid);
} }
} }
@ -1081,15 +1079,13 @@ void RPCConsole::peerLayoutChanged()
void RPCConsole::updateDetailWidget() void RPCConsole::updateDetailWidget()
{ {
QModelIndexList selected_rows; const QList<QModelIndex> selected_peers = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
auto selection_model = ui->peerWidget->selectionModel(); if (!clientModel || !clientModel->getPeerTableModel() || selected_peers.size() != 1) {
if (selection_model) selected_rows = selection_model->selectedRows();
if (!clientModel || !clientModel->getPeerTableModel() || selected_rows.size() != 1) {
ui->detailWidget->hide(); ui->detailWidget->hide();
ui->peerHeading->setText(tr("Select a peer to view detailed information.")); ui->peerHeading->setText(tr("Select a peer to view detailed information."));
return; return;
} }
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected_rows.first().row()); const auto stats = selected_peers.first().data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
// update the detail ui with latest node information // update the detail ui with latest node information
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) + " "); QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) + " ");
peerAddrDetails += tr("(peer id: %1)").arg(QString::number(stats->nodeStats.nodeid)); peerAddrDetails += tr("(peer id: %1)").arg(QString::number(stats->nodeStats.nodeid));
@ -1202,19 +1198,9 @@ void RPCConsole::banSelectedNode(int bantime)
if (!clientModel) if (!clientModel)
return; return;
// Get selected peer addresses for (const QModelIndex& peer : GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId)) {
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
for(int i = 0; i < nodes.count(); i++)
{
// Get currently selected peer address
NodeId id = nodes.at(i).data().toLongLong();
// Get currently selected peer address
int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(id);
if (detailNodeRow < 0) return;
// Find possible nodes, ban it and clear the selected node // Find possible nodes, ban it and clear the selected node
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow); const auto stats = peer.data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
if (stats) { if (stats) {
m_node.ban(stats->nodeStats.addr, bantime); m_node.ban(stats->nodeStats.addr, bantime);
m_node.disconnectByAddress(stats->nodeStats.addr); m_node.disconnectByAddress(stats->nodeStats.addr);