Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_fingerprint.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2017 The Bitcoin Core developers | # Copyright (c) 2017 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 various fingerprinting protections. | """Test various fingerprinting protections. | ||||
If a stale block more than a month old or its header are requested by a peer, | If a stale block more than a month old or its header are requested by a peer, | ||||
the node should pretend that it does not have it to avoid fingerprinting. | the node should pretend that it does not have it to avoid fingerprinting. | ||||
""" | """ | ||||
import time | import time | ||||
from test_framework.blocktools import (create_block, create_coinbase) | from test_framework.blocktools import (create_block, create_coinbase) | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
CInv, | CInv, | ||||
MSG_BLOCK, | |||||
msg_block, | msg_block, | ||||
msg_getdata, | msg_getdata, | ||||
msg_getheaders, | msg_getheaders, | ||||
msg_headers, | msg_headers, | ||||
) | ) | ||||
from test_framework.mininode import P2PInterface | from test_framework.mininode import P2PInterface | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal, wait_until | from test_framework.util import assert_equal, wait_until | ||||
Show All 17 Lines | def build_chain(self, nblocks, prev_hash, prev_height, prev_median_time): | ||||
prev_hash = block.hash | prev_hash = block.hash | ||||
prev_height += 1 | prev_height += 1 | ||||
prev_median_time = block_time | prev_median_time = block_time | ||||
return blocks | return blocks | ||||
# Send a getdata request for a given block hash | # Send a getdata request for a given block hash | ||||
def send_block_request(self, block_hash, node): | def send_block_request(self, block_hash, node): | ||||
msg = msg_getdata() | msg = msg_getdata() | ||||
# 2 == "Block" | msg.inv.append(CInv(MSG_BLOCK, block_hash)) | ||||
msg.inv.append(CInv(2, block_hash)) | |||||
node.send_message(msg) | node.send_message(msg) | ||||
# Send a getheaders request for a given single block hash | # Send a getheaders request for a given single block hash | ||||
def send_header_request(self, block_hash, node): | def send_header_request(self, block_hash, node): | ||||
msg = msg_getheaders() | msg = msg_getheaders() | ||||
msg.hashstop = block_hash | msg.hashstop = block_hash | ||||
node.send_message(msg) | node.send_message(msg) | ||||
▲ Show 20 Lines • Show All 96 Lines • Show Last 20 Lines |