mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-09 19:13:28 +02:00
Remove header checks out of net_processing
This moves header size and netmagic checking out of net_processing and into net. This check now runs in ReadHeader, so that net can exit early out of receiving bytes from the peer. IsValid is now slimmed down, so it no longer needs a MessageStartChars& parameter. Additionally this removes the rest of the m_valid_* members from CNetMessage.
This commit is contained in:
@@ -81,7 +81,7 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
||||
def test_magic_bytes(self):
|
||||
self.log.info("Test message with invalid magic bytes disconnects peer")
|
||||
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
|
||||
with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: INVALID MESSAGESTART badmsg']):
|
||||
with self.nodes[0].assert_debug_log(['HEADER ERROR - MESSAGESTART (badmsg, 2 bytes), received ffffffff']):
|
||||
msg = conn.build_message(msg_unrecognized(str_data="d"))
|
||||
# modify magic bytes
|
||||
msg = b'\xff' * 4 + msg[4:]
|
||||
@@ -105,7 +105,7 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
||||
def test_size(self):
|
||||
self.log.info("Test message with oversized payload disconnects peer")
|
||||
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
|
||||
with self.nodes[0].assert_debug_log(['']):
|
||||
with self.nodes[0].assert_debug_log(['HEADER ERROR - SIZE (badmsg, 4000001 bytes)']):
|
||||
msg = msg_unrecognized(str_data="d" * (VALID_DATA_LIMIT + 1))
|
||||
msg = conn.build_message(msg)
|
||||
conn.send_raw_message(msg)
|
||||
@@ -115,9 +115,8 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
||||
def test_msgtype(self):
|
||||
self.log.info("Test message with invalid message type logs an error")
|
||||
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
|
||||
with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: ERRORS IN HEADER']):
|
||||
with self.nodes[0].assert_debug_log(['HEADER ERROR - COMMAND']):
|
||||
msg = msg_unrecognized(str_data="d")
|
||||
msg.msgtype = b'\xff' * 12
|
||||
msg = conn.build_message(msg)
|
||||
# Modify msgtype
|
||||
msg = msg[:7] + b'\x00' + msg[7 + 1:]
|
||||
|
Reference in New Issue
Block a user