Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_messages.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2019 The Bitcoin Core developers | # Copyright (c) 2015-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test node responses to invalid network messages.""" | """Test node responses to invalid network messages.""" | ||||
import asyncio | import asyncio | ||||
import struct | import struct | ||||
import time | import time | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
CBlockHeader, | CBlockHeader, | ||||
CInv, | CInv, | ||||
msg_avahello, | msg_avahello, | ||||
msg_avapoll, | msg_avapoll, | ||||
msg_avaresponse, | msg_avaresponse, | ||||
msg_avaproof, | |||||
msg_getdata, | msg_getdata, | ||||
msg_headers, | msg_headers, | ||||
msg_inv, | msg_inv, | ||||
msg_ping, | msg_ping, | ||||
MSG_TX, | MSG_TX, | ||||
ser_string, | ser_string, | ||||
) | ) | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
▲ Show 20 Lines • Show All 343 Lines • ▼ Show 20 Lines | def test_unsolicited_ava_messages(self): | ||||
with self.nodes[0].assert_debug_log( | with self.nodes[0].assert_debug_log( | ||||
['Misbehaving', 'peer=9 (20 -> 40): unsolicited-avapoll']): | ['Misbehaving', 'peer=9 (20 -> 40): unsolicited-avapoll']): | ||||
msg = msg_avapoll() | msg = msg_avapoll() | ||||
conn.send_and_ping(msg) | conn.send_and_ping(msg) | ||||
with self.nodes[0].assert_debug_log( | with self.nodes[0].assert_debug_log( | ||||
['Misbehaving', 'peer=9 (40 -> 60): unsolicited-avaresponse']): | ['Misbehaving', 'peer=9 (40 -> 60): unsolicited-avaresponse']): | ||||
msg = msg_avaresponse() | msg = msg_avaresponse() | ||||
conn.send_and_ping(msg) | conn.send_and_ping(msg) | ||||
with self.nodes[0].assert_debug_log( | |||||
['Misbehaving', 'peer=9 (60 -> 80): unsolicited-avaproof']): | |||||
msg = msg_avaproof() | |||||
conn.send_and_ping(msg) | |||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
def _tweak_msg_data_size(self, message, wrong_size): | def _tweak_msg_data_size(self, message, wrong_size): | ||||
""" | """ | ||||
Return a raw message based on another message but with an incorrect data size in | Return a raw message based on another message but with an incorrect data size in | ||||
the message header. | the message header. | ||||
""" | """ | ||||
raw_msg = self.node.p2p.build_message(message) | raw_msg = self.node.p2p.build_message(message) | ||||
Show All 17 Lines |