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-2018 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 struct | import struct | ||||
from test_framework import messages | from test_framework import messages | ||||
from test_framework.mininode import P2PDataStore | from test_framework.mininode import P2PDataStore | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
node.add_p2p_connection(P2PDataStore()) | node.add_p2p_connection(P2PDataStore()) | ||||
# Node is still up. | # Node is still up. | ||||
conn = node.add_p2p_connection(P2PDataStore()) | conn = node.add_p2p_connection(P2PDataStore()) | ||||
conn.sync_with_ping() | conn.sync_with_ping() | ||||
def test_magic_bytes(self): | def test_magic_bytes(self): | ||||
conn = self.nodes[0].add_p2p_connection(P2PDataStore()) | conn = self.nodes[0].add_p2p_connection(P2PDataStore()) | ||||
# Need to ignore all incoming messages from now, since they come with | |||||
# "invalid" magic bytes | |||||
conn._on_data = lambda: None | |||||
conn.magic_bytes = b'\x00\x11\x22\x32' | conn.magic_bytes = b'\x00\x11\x22\x32' | ||||
with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: INVALID MESSAGESTART ping']): | with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: INVALID MESSAGESTART ping']): | ||||
conn.send_message(messages.msg_ping(nonce=0xff)) | conn.send_message(messages.msg_ping(nonce=0xff)) | ||||
conn.wait_for_disconnect(timeout=1) | conn.wait_for_disconnect(timeout=1) | ||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
def test_checksum(self): | def test_checksum(self): | ||||
conn = self.nodes[0].add_p2p_connection(P2PDataStore()) | conn = self.nodes[0].add_p2p_connection(P2PDataStore()) | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |