mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-13 11:35:20 +01:00
This is intended to only be used for logging. This will allow log messages in the following commits to keep recording the peer's ID, even when logging is moved into V1TransportDeserializer.
48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
// Copyright (c) 2019 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <chainparams.h>
|
|
#include <net.h>
|
|
#include <protocol.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
|
|
#include <cassert>
|
|
#include <cstdint>
|
|
#include <limits>
|
|
#include <vector>
|
|
|
|
void initialize()
|
|
{
|
|
SelectParams(CBaseChainParams::REGTEST);
|
|
}
|
|
|
|
void test_one_input(const std::vector<uint8_t>& buffer)
|
|
{
|
|
// Construct deserializer, with a dummy NodeId
|
|
V1TransportDeserializer deserializer{Params().MessageStart(), (NodeId)0, SER_NETWORK, INIT_PROTO_VERSION};
|
|
const char* pch = (const char*)buffer.data();
|
|
size_t n_bytes = buffer.size();
|
|
while (n_bytes > 0) {
|
|
const int handled = deserializer.Read(pch, n_bytes);
|
|
if (handled < 0) {
|
|
break;
|
|
}
|
|
pch += handled;
|
|
n_bytes -= handled;
|
|
if (deserializer.Complete()) {
|
|
const std::chrono::microseconds m_time{std::numeric_limits<int64_t>::max()};
|
|
const CNetMessage msg = deserializer.GetMessage(Params().MessageStart(), m_time);
|
|
assert(msg.m_command.size() <= CMessageHeader::COMMAND_SIZE);
|
|
assert(msg.m_raw_message_size <= buffer.size());
|
|
assert(msg.m_raw_message_size == CMessageHeader::HEADER_SIZE + msg.m_message_size);
|
|
assert(msg.m_time == m_time);
|
|
if (msg.m_valid_header) {
|
|
assert(msg.m_valid_netmagic);
|
|
}
|
|
if (!msg.m_valid_netmagic) {
|
|
assert(!msg.m_valid_header);
|
|
}
|
|
}
|
|
}
|
|
}
|