Skip to content

Commit

Permalink
gui: fix ban from qt console
Browse files Browse the repository at this point in the history
Rather than doing a circle and re-resolving the node's IP, just use the one
from nodestats directly.

This requires syncing the addr field from CNode.
  • Loading branch information
theuni committed Oct 4, 2016
1 parent d7615af commit cb78c60
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/net.cpp
Expand Up @@ -629,6 +629,7 @@ void CNode::copyStats(CNodeStats &stats)
{
stats.nodeid = this->GetId();
X(nServices);
X(addr);
X(fRelayTxes);
X(nLastSend);
X(nLastRecv);
Expand Down
1 change: 1 addition & 0 deletions src/net.h
Expand Up @@ -505,6 +505,7 @@ class CNodeStats
double dPingWait;
double dPingMin;
std::string addrLocal;
CAddress addr;
};


Expand Down
25 changes: 13 additions & 12 deletions src/qt/rpcconsole.cpp
Expand Up @@ -981,20 +981,21 @@ void RPCConsole::banSelectedNode(int bantime)
if (!clientModel || !g_connman)
return;

// Get currently selected peer address
QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address).toString();
// Find possible nodes, ban it and clear the selected node
std::string nStr = strNode.toStdString();
std::string addr;
int port = 0;
SplitHostPort(nStr, port, addr);
if(cachedNodeid == -1)
return;

CNetAddr resolved;
if(!LookupHost(addr.c_str(), resolved, false))
// Get currently selected peer address
int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(cachedNodeid);
if(detailNodeRow < 0)
return;
g_connman->Ban(resolved, BanReasonManuallyAdded, bantime);
clearSelectedNode();
clientModel->getBanTableModel()->refresh();

// Find possible nodes, ban it and clear the selected node
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
if(stats) {
g_connman->Ban(stats->nodeStats.addr, BanReasonManuallyAdded, bantime);
clearSelectedNode();
clientModel->getBanTableModel()->refresh();
}
}

void RPCConsole::unbanSelectedNode()
Expand Down

0 comments on commit cb78c60

Please sign in to comment.