diff options
author | TheCharlatan <seb.kung@gmail.com> | 2023-09-12 13:01:07 +0200 |
---|---|---|
committer | TheCharlatan <seb.kung@gmail.com> | 2023-09-12 22:49:49 +0200 |
commit | 9be330b654cfbd792620295f3867f592059d6a7a (patch) | |
tree | d1596eed457af928c181b2332c292d1c7a982b85 /src/net.cpp | |
parent | 37e2b011136ca1cf00dfb9e575d12f0d035a6a2c (diff) | |
download | bitcoin-9be330b654cfbd792620295f3867f592059d6a7a.tar.xz |
[refactor] Define MessageStartChars as std::array
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp index af2855932d..d091db74c4 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -730,7 +730,7 @@ V1Transport::V1Transport(const NodeId node_id, int nTypeIn, int nVersionIn) noex m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn) { assert(std::size(Params().MessageStart()) == std::size(m_magic_bytes)); - std::copy(std::begin(Params().MessageStart()), std::end(Params().MessageStart()), m_magic_bytes); + m_magic_bytes = Params().MessageStart(); LOCK(m_recv_mutex); Reset(); } @@ -759,7 +759,7 @@ int V1Transport::readHeader(Span<const uint8_t> msg_bytes) } // Check start string, network magic - if (memcmp(hdr.pchMessageStart, m_magic_bytes, CMessageHeader::MESSAGE_START_SIZE) != 0) { + if (hdr.pchMessageStart != m_magic_bytes) { LogPrint(BCLog::NET, "Header error: Wrong MessageStart %s received, peer=%d\n", HexStr(hdr.pchMessageStart), m_node_id); return -1; } @@ -1144,7 +1144,7 @@ bool V2Transport::ProcessReceivedKeyBytes() noexcept // they receive our uniformly random key and garbage, but detecting this case specially // means we can log it. static constexpr std::array<uint8_t, 12> MATCH = {'v', 'e', 'r', 's', 'i', 'o', 'n', 0, 0, 0, 0, 0}; - static constexpr size_t OFFSET = sizeof(CMessageHeader::MessageStartChars); + static constexpr size_t OFFSET = std::tuple_size_v<CMessageHeader::MessageStartChars>; if (!m_initiating && m_recv_buffer.size() >= OFFSET + MATCH.size()) { if (std::equal(MATCH.begin(), MATCH.end(), m_recv_buffer.begin() + OFFSET)) { LogPrint(BCLog::NET, "V2 transport error: V1 peer with wrong MessageStart %s\n", |