| 2960 | } |
| 2961 | |
| 2962 | static bool SendRejectsAndCheckIfBanned(CNode* pnode, CConnman* connman, bool enable_bip61) |
| 2963 | { |
| 2964 | AssertLockHeld(cs_main); |
| 2965 | CNodeState &state = *State(pnode->GetId()); |
| 2966 | |
| 2967 | if (enable_bip61) { |
| 2968 | for (const CBlockReject& reject : state.rejects) { |
| 2969 | connman->PushMessage(pnode, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, std::string(NetMsgType::BLOCK), reject.chRejectCode, reject.strRejectReason, reject.hashBlock)); |
| 2970 | } |
| 2971 | } |
| 2972 | state.rejects.clear(); |
| 2973 | |
| 2974 | if (state.fShouldBan) { |
| 2975 | state.fShouldBan = false; |
| 2976 | if (pnode->fWhitelisted) |
| 2977 | LogPrintf("Warning: not punishing whitelisted peer %s!\n", pnode->addr.ToString()); |
| 2978 | else if (pnode->m_manual_connection) |
| 2979 | LogPrintf("Warning: not punishing manually-connected peer %s!\n", pnode->addr.ToString()); |
| 2980 | else { |
| 2981 | pnode->fDisconnect = true; |
| 2982 | if (pnode->addr.IsLocal()) |
| 2983 | LogPrintf("Warning: not banning local peer %s!\n", pnode->addr.ToString()); |
| 2984 | else |
| 2985 | { |
| 2986 | connman->Ban(pnode->addr, BanReasonNodeMisbehaving); |
| 2987 | } |
| 2988 | } |
| 2989 | return true; |
| 2990 | } |
| 2991 | return false; |
| 2992 | } |
| 2993 | |
| 2994 | bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgProc) |
| 2995 | { |
no test coverage detected