| 666 | #undef X |
| 667 | |
| 668 | bool CNode::ReceiveMsgBytes(std::span<const uint8_t> msg_bytes, bool& complete) |
| 669 | { |
| 670 | complete = false; |
| 671 | const auto time{NodeClock::now()}; |
| 672 | LOCK(cs_vRecv); |
| 673 | m_last_recv = time; |
| 674 | nRecvBytes += msg_bytes.size(); |
| 675 | while (msg_bytes.size() > 0) { |
| 676 | // absorb network data |
| 677 | if (!m_transport->ReceivedBytes(msg_bytes)) { |
| 678 | // Serious transport problem, disconnect from the peer. |
| 679 | return false; |
| 680 | } |
| 681 | |
| 682 | if (m_transport->ReceivedMessageComplete()) { |
| 683 | // decompose a transport agnostic CNetMessage from the deserializer |
| 684 | bool reject_message{false}; |
| 685 | CNetMessage msg = m_transport->GetReceivedMessage(time, reject_message); |
| 686 | if (reject_message) { |
| 687 | // Message deserialization failed. Drop the message but don't disconnect the peer. |
| 688 | // store the size of the corrupt message |
| 689 | mapRecvBytesPerMsgType.at(NET_MESSAGE_TYPE_OTHER) += msg.m_raw_message_size; |
| 690 | continue; |
| 691 | } |
| 692 | |
| 693 | // Store received bytes per message type. |
| 694 | // To prevent a memory DOS, only allow known message types. |
| 695 | auto i = mapRecvBytesPerMsgType.find(msg.m_type); |
| 696 | if (i == mapRecvBytesPerMsgType.end()) { |
| 697 | i = mapRecvBytesPerMsgType.find(NET_MESSAGE_TYPE_OTHER); |
| 698 | } |
| 699 | assert(i != mapRecvBytesPerMsgType.end()); |
| 700 | i->second += msg.m_raw_message_size; |
| 701 | |
| 702 | // push the message to the process queue, |
| 703 | vRecvMsg.push_back(std::move(msg)); |
| 704 | |
| 705 | complete = true; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | return true; |
| 710 | } |
| 711 | |
| 712 | std::string CNode::LogPeer() const |
| 713 | { |