diff options
author | Troy Giorshev <troygiorshev@gmail.com> | 2020-06-29 14:09:42 -0400 |
---|---|---|
committer | Troy Giorshev <troygiorshev@gmail.com> | 2020-09-22 22:01:14 -0400 |
commit | 2716647ebf60cea05fc9edce6a18dcce4e7727ad (patch) | |
tree | 95aeccb07b675773b935be187721b21d62219639 | |
parent | b1291b2e8fc39b366765d905200f022823e3d50b (diff) |
Give V1TransportDeserializer an m_node_id member
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.
-rw-r--r-- | src/net.cpp | 7 | ||||
-rw-r--r-- | src/net.h | 9 | ||||
-rw-r--r-- | src/test/fuzz/p2p_transport_deserializer.cpp | 3 |
3 files changed, 13 insertions, 6 deletions
diff --git a/src/net.cpp b/src/net.cpp index e7d3a146ff..73029655ce 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -699,10 +699,11 @@ CNetMessage V1TransportDeserializer::GetMessage(const CMessageHeader::MessageSta msg.m_valid_checksum = (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) == 0); if (!msg.m_valid_checksum) { - LogPrint(BCLog::NET, "CHECKSUM ERROR (%s, %u bytes), expected %s was %s\n", + LogPrint(BCLog::NET, "CHECKSUM ERROR (%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)); + HexStr(hdr.pchChecksum), + m_node_id); } // store receive time @@ -2828,7 +2829,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn LogPrint(BCLog::NET, "Added connection peer=%d\n", id); } - m_deserializer = MakeUnique<V1TransportDeserializer>(V1TransportDeserializer(Params().MessageStart(), SER_NETWORK, INIT_PROTO_VERSION)); + m_deserializer = MakeUnique<V1TransportDeserializer>(V1TransportDeserializer(Params().MessageStart(), GetId(), SER_NETWORK, INIT_PROTO_VERSION)); m_serializer = MakeUnique<V1TransportSerializer>(V1TransportSerializer()); } @@ -739,6 +739,7 @@ public: class V1TransportDeserializer final : public TransportDeserializer { private: + const NodeId m_node_id; // Only for logging mutable CHash256 hasher; mutable uint256 data_hash; bool in_data; // parsing header (false) or data (true) @@ -764,8 +765,12 @@ private: } public: - - V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) { + V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, const NodeId node_id, int nTypeIn, int nVersionIn) + : m_node_id(node_id), + hdrbuf(nTypeIn, nVersionIn), + hdr(pchMessageStartIn), + vRecv(nTypeIn, nVersionIn) + { Reset(); } diff --git a/src/test/fuzz/p2p_transport_deserializer.cpp b/src/test/fuzz/p2p_transport_deserializer.cpp index 6fba2bfaba..732136330b 100644 --- a/src/test/fuzz/p2p_transport_deserializer.cpp +++ b/src/test/fuzz/p2p_transport_deserializer.cpp @@ -19,7 +19,8 @@ void initialize() void test_one_input(const std::vector<uint8_t>& buffer) { - V1TransportDeserializer deserializer{Params().MessageStart(), SER_NETWORK, INIT_PROTO_VERSION}; + // 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) { |