| 4147 | } |
| 4148 | |
| 4149 | bool PeerManagerImpl::MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer) |
| 4150 | { |
| 4151 | { |
| 4152 | LOCK(peer.m_misbehavior_mutex); |
| 4153 | |
| 4154 | // There's nothing to do if the m_should_discourage flag isn't set |
| 4155 | if (!peer.m_should_discourage) return false; |
| 4156 | |
| 4157 | peer.m_should_discourage = false; |
| 4158 | } // peer.m_misbehavior_mutex |
| 4159 | |
| 4160 | if (pnode.HasPermission(NetPermissionFlags::NoBan)) { |
| 4161 | // We never disconnect or discourage peers for bad behavior if they have NetPermissionFlags::NoBan permission |
| 4162 | LogPrintf("Warning: not punishing noban peer %d!\n", peer.m_id); |
| 4163 | return false; |
| 4164 | } |
| 4165 | |
| 4166 | if (pnode.IsManualConn()) { |
| 4167 | // We never disconnect or discourage manual peers for bad behavior |
| 4168 | LogPrintf("Warning: not punishing manually connected peer %d!\n", peer.m_id); |
| 4169 | return false; |
| 4170 | } |
| 4171 | |
| 4172 | if (pnode.addr.IsLocal()) { |
| 4173 | // We disconnect local peers for bad behavior but don't discourage (since that would discourage |
| 4174 | // all peers on the same local address) |
| 4175 | LogPrint(BCLog::NET, "Warning: disconnecting but not discouraging %s peer %d!\n", |
| 4176 | pnode.m_inbound_onion ? "inbound onion" : "local", peer.m_id); |
| 4177 | pnode.fDisconnect = true; |
| 4178 | return true; |
| 4179 | } |
| 4180 | |
| 4181 | // Normal case: Disconnect the peer and discourage all nodes sharing the address |
| 4182 | LogPrint(BCLog::NET, "Disconnecting and discouraging peer %d!\n", peer.m_id); |
| 4183 | if (m_banman) m_banman->Discourage(pnode.addr); |
| 4184 | m_connman.DisconnectNode(pnode.addr); |
| 4185 | return true; |
| 4186 | } |
| 4187 | |
| 4188 | bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgProc) |
| 4189 | { |
nothing calls this directly
no test coverage detected