| 721 | } |
| 722 | |
| 723 | int V1TransportDeserializer::readHeader(Span<const uint8_t> msg_bytes) |
| 724 | { |
| 725 | // copy data to temporary parsing buffer |
| 726 | unsigned int nRemaining = CMessageHeader::HEADER_SIZE - nHdrPos; |
| 727 | unsigned int nCopy = std::min<unsigned int>(nRemaining, msg_bytes.size()); |
| 728 | |
| 729 | memcpy(&hdrbuf[nHdrPos], msg_bytes.data(), nCopy); |
| 730 | nHdrPos += nCopy; |
| 731 | |
| 732 | // if header incomplete, exit |
| 733 | if (nHdrPos < CMessageHeader::HEADER_SIZE) |
| 734 | return nCopy; |
| 735 | |
| 736 | // deserialize to CMessageHeader |
| 737 | try { |
| 738 | hdrbuf >> hdr; |
| 739 | } |
| 740 | catch (const std::exception&) { |
| 741 | LogPrint(BCLog::NET, "Header error: Unable to deserialize, peer=%d\n", m_node_id); |
| 742 | return -1; |
| 743 | } |
| 744 | |
| 745 | // Check start string, network magic |
| 746 | if (memcmp(hdr.pchMessageStart, m_chain_params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) { |
| 747 | LogPrint(BCLog::NET, "Header error: Wrong MessageStart %s received, peer=%d\n", HexStr(hdr.pchMessageStart), m_node_id); |
| 748 | return -1; |
| 749 | } |
| 750 | |
| 751 | // reject messages larger than MAX_SIZE or MAX_PROTOCOL_MESSAGE_LENGTH |
| 752 | if (hdr.nMessageSize > MAX_SIZE || hdr.nMessageSize > MAX_PROTOCOL_MESSAGE_LENGTH) { |
| 753 | LogPrint(BCLog::NET, "Header error: Size too large (%s, %u bytes), peer=%d\n", SanitizeString(hdr.GetCommand()), hdr.nMessageSize, m_node_id); |
| 754 | return -1; |
| 755 | } |
| 756 | |
| 757 | // switch state to reading message data |
| 758 | in_data = true; |
| 759 | |
| 760 | return nCopy; |
| 761 | } |
| 762 | |
| 763 | int V1TransportDeserializer::readData(Span<const uint8_t> msg_bytes) |
| 764 | { |
nothing calls this directly
no test coverage detected