mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-23 22:19:39 +01:00
Merge #16202: p2p: Refactor network message deserialization
ed2dc5e48aAdd override/final modifiers to V1TransportDeserializer (Pieter Wuille)f342a5e61aMake resetting implicit in TransportDeserializer::Read() (Pieter Wuille)6a91499496Remove oversized message detection from log and interface (Pieter Wuille)b0e10ff4dfForce CNetMessage::m_recv to use std::move (Jonas Schnelli)efecb74677Use adapter pattern for the network deserializer (Jonas Schnelli)1a5c656c31Remove transport protocol knowhow from CNetMessage / net processing (Jonas Schnelli)6294ecdb8bRefactor: split network transport deserializing from message container (Jonas Schnelli) Pull request description: **This refactors the network message deserialization.** * It transforms the `CNetMessage` into a transport protocol agnostic message container. * A new class `TransportDeserializer` (unique pointer of `CNode`) is introduced, handling the network buffer reading and the decomposing to a `CNetMessage` * **No behavioral changes** (in terms of disconnecting, punishing) * Moves the checksum finalizing into the `SocketHandler` thread (finalizing was in `ProcessMessages` before) The **optional last commit** makes the `TransportDeserializer` following an adapter pattern (polymorphic interface) to make it easier to later add a V2 transport protocol deserializer. Intentionally not touching the sending part. Pre-Requirement for BIP324 (v2 message transport protocol). Replacement for #14046 and inspired by a [comment](https://github.com/bitcoin/bitcoin/pull/14046#issuecomment-431528330) from sipa ACKs for top commit: promag: Code review ACKed2dc5e48a. marcinja: Code review ACKed2dc5e48aryanofsky: Code review ACKed2dc5e48a. 4 cleanup commits added since last review. Unaddressed comments: ariard: Code review and tested ACKed2dc5e. Tree-SHA512: bab8d87464e2e8742529e488ddcdc8650f0c2025c9130913df00a0b17ecdb9a525061cbbbd0de0251b76bf75a8edb72e3ad0dbf5b79e26f2ad05d61b4e4ded6d
This commit is contained in:
@@ -101,11 +101,10 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
||||
msg_over_size = msg_unrecognized(str_data="b" * (valid_data_limit + 1))
|
||||
assert len(msg_over_size.serialize()) == (msg_limit + 1)
|
||||
|
||||
with node.assert_debug_log(["Oversized message from peer=4, disconnecting"]):
|
||||
# An unknown message type (or *any* message type) over
|
||||
# MAX_PROTOCOL_MESSAGE_LENGTH should result in a disconnect.
|
||||
node.p2p.send_message(msg_over_size)
|
||||
node.p2p.wait_for_disconnect(timeout=4)
|
||||
# An unknown message type (or *any* message type) over
|
||||
# MAX_PROTOCOL_MESSAGE_LENGTH should result in a disconnect.
|
||||
node.p2p.send_message(msg_over_size)
|
||||
node.p2p.wait_for_disconnect(timeout=4)
|
||||
|
||||
node.disconnect_p2ps()
|
||||
conn = node.add_p2p_connection(P2PDataStore())
|
||||
@@ -168,7 +167,7 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
||||
|
||||
def test_checksum(self):
|
||||
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
|
||||
with self.nodes[0].assert_debug_log(['ProcessMessages(badmsg, 2 bytes): CHECKSUM ERROR expected 78df0a04 was ffffffff']):
|
||||
with self.nodes[0].assert_debug_log(['CHECKSUM ERROR (badmsg, 2 bytes), expected 78df0a04 was ffffffff']):
|
||||
msg = conn.build_message(msg_unrecognized(str_data="d"))
|
||||
cut_len = (
|
||||
4 + # magic
|
||||
|
||||
Reference in New Issue
Block a user