mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
net: Break disconnecting out of Ban()
These are separate events which need to be carried out by separate subsystems. This also cleans up some whitespace and tabs in qt to avoid getting flagged by the linter. Current behavior is preserved.
This commit is contained in:
parent
f71c2ea662
commit
7cc2b9f678
7 changed files with 54 additions and 24 deletions
|
@ -144,6 +144,13 @@ public:
|
|||
}
|
||||
return false;
|
||||
}
|
||||
bool disconnect(const CNetAddr& net_addr) override
|
||||
{
|
||||
if (g_connman) {
|
||||
return g_connman->DisconnectNode(net_addr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool disconnect(NodeId id) override
|
||||
{
|
||||
if (g_connman) {
|
||||
|
|
|
@ -113,7 +113,10 @@ public:
|
|||
//! Unban node.
|
||||
virtual bool unban(const CSubNet& ip) = 0;
|
||||
|
||||
//! Disconnect node.
|
||||
//! Disconnect node by address.
|
||||
virtual bool disconnect(const CNetAddr& net_addr) = 0;
|
||||
|
||||
//! Disconnect node by id.
|
||||
virtual bool disconnect(NodeId id) = 0;
|
||||
|
||||
//! Get total bytes recv.
|
||||
|
|
26
src/net.cpp
26
src/net.cpp
|
@ -554,13 +554,6 @@ void CConnman::Ban(const CSubNet& subNet, const BanReason &banReason, int64_t ba
|
|||
}
|
||||
if(clientInterface)
|
||||
clientInterface->BannedListChanged();
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (CNode* pnode : vNodes) {
|
||||
if (subNet.Match(static_cast<CNetAddr>(pnode->addr)))
|
||||
pnode->fDisconnect = true;
|
||||
}
|
||||
}
|
||||
if(banReason == BanReasonManuallyAdded)
|
||||
DumpBanlist(); //store banlist to disk immediately if user requested ban
|
||||
}
|
||||
|
@ -2643,6 +2636,25 @@ bool CConnman::DisconnectNode(const std::string& strNode)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CConnman::DisconnectNode(const CSubNet& subnet)
|
||||
{
|
||||
bool disconnected = false;
|
||||
LOCK(cs_vNodes);
|
||||
for (CNode* pnode : vNodes) {
|
||||
if (subnet.Match(pnode->addr)) {
|
||||
pnode->fDisconnect = true;
|
||||
disconnected = true;
|
||||
}
|
||||
}
|
||||
return disconnected;
|
||||
}
|
||||
|
||||
bool CConnman::DisconnectNode(const CNetAddr& addr)
|
||||
{
|
||||
return DisconnectNode(CSubNet(addr));
|
||||
}
|
||||
|
||||
bool CConnman::DisconnectNode(NodeId id)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
|
|
|
@ -282,6 +282,8 @@ public:
|
|||
size_t GetNodeCount(NumConnections num);
|
||||
void GetNodeStats(std::vector<CNodeStats>& vstats);
|
||||
bool DisconnectNode(const std::string& node);
|
||||
bool DisconnectNode(const CSubNet& subnet);
|
||||
bool DisconnectNode(const CNetAddr& addr);
|
||||
bool DisconnectNode(NodeId id);
|
||||
|
||||
ServiceFlags GetLocalServices() const;
|
||||
|
|
|
@ -2961,14 +2961,14 @@ static bool SendRejectsAndCheckIfBanned(CNode* pnode, CConnman* connman, bool en
|
|||
LogPrintf("Warning: not punishing whitelisted peer %s!\n", pnode->addr.ToString());
|
||||
else if (pnode->m_manual_connection)
|
||||
LogPrintf("Warning: not punishing manually-connected peer %s!\n", pnode->addr.ToString());
|
||||
else {
|
||||
else if (pnode->addr.IsLocal()) {
|
||||
// Disconnect but don't ban _this_ local node
|
||||
LogPrintf("Warning: disconnecting but not banning local peer %s!\n", pnode->addr.ToString());
|
||||
pnode->fDisconnect = true;
|
||||
if (pnode->addr.IsLocal())
|
||||
LogPrintf("Warning: not banning local peer %s!\n", pnode->addr.ToString());
|
||||
else
|
||||
{
|
||||
connman->Ban(pnode->addr, BanReasonNodeMisbehaving);
|
||||
}
|
||||
} else {
|
||||
// Disconnect and ban all nodes sharing the address
|
||||
connman->Ban(pnode->addr, BanReasonNodeMisbehaving);
|
||||
connman->DisconnectNode(pnode->addr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1216,16 +1216,16 @@ void RPCConsole::banSelectedNode(int bantime)
|
|||
// 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;
|
||||
// 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
|
||||
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
|
||||
if(stats) {
|
||||
// Find possible nodes, ban it and clear the selected node
|
||||
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
|
||||
if (stats) {
|
||||
m_node.ban(stats->nodeStats.addr, BanReasonManuallyAdded, bantime);
|
||||
}
|
||||
m_node.disconnect(stats->nodeStats.addr);
|
||||
}
|
||||
}
|
||||
clearSelectedNode();
|
||||
clientModel->getBanTableModel()->refresh();
|
||||
|
|
|
@ -565,7 +565,13 @@ static UniValue setban(const JSONRPCRequest& request)
|
|||
if (request.params[3].isTrue())
|
||||
absolute = true;
|
||||
|
||||
isSubnet ? g_connman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute) : g_connman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
|
||||
if (isSubnet) {
|
||||
g_connman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute);
|
||||
g_connman->DisconnectNode(subNet);
|
||||
} else {
|
||||
g_connman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
|
||||
g_connman->DisconnectNode(netAddr);
|
||||
}
|
||||
}
|
||||
else if(strCommand == "remove")
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue