Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_sendheaders.py
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | d. Announce 49 headers that don't connect. | ||||
Expect: getheaders message each time. | Expect: getheaders message each time. | ||||
e. Announce one more that doesn't connect. | e. Announce one more that doesn't connect. | ||||
Expect: disconnect. | Expect: disconnect. | ||||
""" | """ | ||||
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 ( | ||||
CBlockHeader, | CBlockHeader, | ||||
CInv, | CInv, | ||||
MSG_BLOCK, | |||||
msg_block, | msg_block, | ||||
msg_getblocks, | msg_getblocks, | ||||
msg_getdata, | msg_getdata, | ||||
msg_getheaders, | msg_getheaders, | ||||
msg_headers, | msg_headers, | ||||
msg_inv, | msg_inv, | ||||
msg_sendheaders, | msg_sendheaders, | ||||
) | ) | ||||
Show All 17 Lines | def __init__(self): | ||||
self.block_announced = False | self.block_announced = False | ||||
self.last_blockhash_announced = None | self.last_blockhash_announced = None | ||||
self.recent_headers_announced = [] | self.recent_headers_announced = [] | ||||
def send_get_data(self, block_hashes): | def send_get_data(self, block_hashes): | ||||
"""Request data for a list of block hashes.""" | """Request data for a list of block hashes.""" | ||||
msg = msg_getdata() | msg = msg_getdata() | ||||
for x in block_hashes: | for x in block_hashes: | ||||
msg.inv.append(CInv(2, x)) | msg.inv.append(CInv(MSG_BLOCK, x)) | ||||
self.send_message(msg) | self.send_message(msg) | ||||
def send_get_headers(self, locator, hashstop): | def send_get_headers(self, locator, hashstop): | ||||
msg = msg_getheaders() | msg = msg_getheaders() | ||||
msg.locator.vHave = locator | msg.locator.vHave = locator | ||||
msg.hashstop = hashstop | msg.hashstop = hashstop | ||||
self.send_message(msg) | self.send_message(msg) | ||||
def send_block_inv(self, blockhash): | def send_block_inv(self, blockhash): | ||||
msg = msg_inv() | msg = msg_inv() | ||||
msg.inv = [CInv(2, blockhash)] | msg.inv = [CInv(MSG_BLOCK, blockhash)] | ||||
self.send_message(msg) | self.send_message(msg) | ||||
def send_header_for_blocks(self, new_blocks): | def send_header_for_blocks(self, new_blocks): | ||||
headers_message = msg_headers() | headers_message = msg_headers() | ||||
headers_message.headers = [CBlockHeader(b) for b in new_blocks] | headers_message.headers = [CBlockHeader(b) for b in new_blocks] | ||||
self.send_message(headers_message) | self.send_message(headers_message) | ||||
def send_getblocks(self, locator): | def send_getblocks(self, locator): | ||||
▲ Show 20 Lines • Show All 493 Lines • Show Last 20 Lines |