From 8d64d38914d14240e2761760e4bbd63231b36c87 Mon Sep 17 00:00:00 2001 From: NotTsunami <4589807+NotTsunami@users.noreply.github.com> Date: Fri, 18 Sep 2020 15:33:17 -0400 Subject: [PATCH] Prevent peers from being lost when banning The selected rows aren't queried until after a user confirms they would like to ban the selected peers. If a peer disconnects before the confirmation is pressed, they will not be included in the selection. This commit makes sure the selected rows are stored before a selection is made to prevent the loss of any peers. Closes #13385. --- src/gui/properties/peerlistwidget.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index 1ec31bcd9..f1e40a9fc 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include "base/bittorrent/peeraddress.h" @@ -291,15 +292,24 @@ void PeerListWidget::showPeerListMenu(const QPoint &) void PeerListWidget::banSelectedPeers() { - // Confirm first - const QMessageBox::StandardButton btn = QMessageBox::question(this, tr("Ban peer permanently") - , tr("Are you sure you want to permanently ban the selected peers?")); - if (btn != QMessageBox::Yes) return; - + // Store selected rows first as selected peers may disconnect const QModelIndexList selectedIndexes = selectionModel()->selectedRows(); + + QVector selectedIPs; + selectedIPs.reserve(selectedIndexes.size()); + for (const QModelIndex &index : selectedIndexes) { const int row = m_proxyModel->mapToSource(index).row(); const QString ip = m_listModel->item(row, PeerListColumns::IP_HIDDEN)->text(); + selectedIPs += ip; + } + + // Confirm before banning peer + const QMessageBox::StandardButton btn = QMessageBox::question(this, tr("Ban peer permanently") + , tr("Are you sure you want to permanently ban the selected peers?")); + if (btn != QMessageBox::Yes) return; + + for (const QString &ip : selectedIPs) { BitTorrent::Session::instance()->banIP(ip); LogMsg(tr("Peer \"%1\" is manually banned").arg(ip)); }