mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-19 12:10:19 +01:00
net: Clarify message header validation errors
Make the errors less shouty and more descriptive.
This commit is contained in:
10
src/net.cpp
10
src/net.cpp
@@ -681,19 +681,19 @@ int V1TransportDeserializer::readHeader(Span<const uint8_t> msg_bytes)
|
||||
hdrbuf >> hdr;
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
LogPrint(BCLog::NET, "HEADER ERROR - UNABLE TO DESERIALIZE, peer=%d\n", m_node_id);
|
||||
LogPrint(BCLog::NET, "Header error: Unable to deserialize, peer=%d\n", m_node_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check start string, network magic
|
||||
if (memcmp(hdr.pchMessageStart, m_chain_params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) {
|
||||
LogPrint(BCLog::NET, "HEADER ERROR - MESSAGESTART received %s, peer=%d\n", HexStr(hdr.pchMessageStart), m_node_id);
|
||||
LogPrint(BCLog::NET, "Header error: Wrong MessageStart %s received, peer=%d\n", HexStr(hdr.pchMessageStart), m_node_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// reject messages larger than MAX_SIZE or MAX_PROTOCOL_MESSAGE_LENGTH
|
||||
if (hdr.nMessageSize > MAX_SIZE || hdr.nMessageSize > MAX_PROTOCOL_MESSAGE_LENGTH) {
|
||||
LogPrint(BCLog::NET, "HEADER ERROR - SIZE (%s, %u bytes), peer=%d\n", SanitizeString(hdr.GetCommand()), hdr.nMessageSize, m_node_id);
|
||||
LogPrint(BCLog::NET, "Header error: Size too large (%s, %u bytes), peer=%d\n", SanitizeString(hdr.GetCommand()), hdr.nMessageSize, m_node_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -746,7 +746,7 @@ std::optional<CNetMessage> V1TransportDeserializer::GetMessage(const std::chrono
|
||||
|
||||
// Check checksum and header command string
|
||||
if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
|
||||
LogPrint(BCLog::NET, "CHECKSUM ERROR (%s, %u bytes), expected %s was %s, peer=%d\n",
|
||||
LogPrint(BCLog::NET, "Header error: Wrong checksum (%s, %u bytes), expected %s was %s, peer=%d\n",
|
||||
SanitizeString(msg->m_command), msg->m_message_size,
|
||||
HexStr(Span<uint8_t>(hash.begin(), hash.begin() + CMessageHeader::CHECKSUM_SIZE)),
|
||||
HexStr(hdr.pchChecksum),
|
||||
@@ -754,7 +754,7 @@ std::optional<CNetMessage> V1TransportDeserializer::GetMessage(const std::chrono
|
||||
out_err_raw_size = msg->m_raw_message_size;
|
||||
msg = std::nullopt;
|
||||
} else if (!hdr.IsCommandValid()) {
|
||||
LogPrint(BCLog::NET, "HEADER ERROR - COMMAND (%s, %u bytes), peer=%d\n",
|
||||
LogPrint(BCLog::NET, "Header error: Invalid message type (%s, %u bytes), peer=%d\n",
|
||||
SanitizeString(hdr.GetCommand()), msg->m_message_size, m_node_id);
|
||||
out_err_raw_size = msg->m_raw_message_size;
|
||||
msg.reset();
|
||||
|
||||
Reference in New Issue
Block a user