refactor: Initialize magic bytes in constructor initializer

Also remove an assert that is already enforced by the compiler checking
that the length of the std::array matches.
This commit is contained in:
TheCharlatan 2023-11-11 13:04:18 +01:00
parent 8243762700
commit d49d198840
No known key found for this signature in database
GPG key ID: 9B79B45691DB4173
3 changed files with 3 additions and 6 deletions

View file

@ -684,10 +684,8 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
} }
V1Transport::V1Transport(const NodeId node_id, int nTypeIn, int nVersionIn) noexcept : V1Transport::V1Transport(const NodeId node_id, int nTypeIn, int nVersionIn) noexcept :
m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn) m_magic_bytes{Params().MessageStart()}, m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn)
{ {
assert(std::size(Params().MessageStart()) == std::size(m_magic_bytes));
m_magic_bytes = Params().MessageStart();
LOCK(m_recv_mutex); LOCK(m_recv_mutex);
Reset(); Reset();
} }

View file

@ -372,7 +372,7 @@ public:
class V1Transport final : public Transport class V1Transport final : public Transport
{ {
private: private:
MessageStartChars m_magic_bytes; const MessageStartChars m_magic_bytes;
const NodeId m_node_id; // Only for logging const NodeId m_node_id; // Only for logging
mutable Mutex m_recv_mutex; //!< Lock for receive state mutable Mutex m_recv_mutex; //!< Lock for receive state
mutable CHash256 hasher GUARDED_BY(m_recv_mutex); mutable CHash256 hasher GUARDED_BY(m_recv_mutex);

View file

@ -91,9 +91,8 @@ const static std::vector<std::string> g_all_net_message_types{
}; };
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn) CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
: pchMessageStart{pchMessageStartIn}
{ {
pchMessageStart = pchMessageStartIn;
// Copy the command name // Copy the command name
size_t i = 0; size_t i = 0;
for (; i < COMMAND_SIZE && pszCommand[i] != 0; ++i) pchCommand[i] = pszCommand[i]; for (; i < COMMAND_SIZE && pszCommand[i] != 0; ++i) pchCommand[i] = pszCommand[i];