def on_getheaders(self, message):
    'Search back through our block store for the locator, and reply with a headers message if found.'
    (locator, hash_stop) = (message.locator, message.hashstop)
    if (not self.block_store):
        return
    headers_list = [self.block_store[self.last_block_hash]]
    maxheaders = 2000
    while (headers_list[(- 1)].sha256 not in locator.vHave):
        prev_block_hash = headers_list[(- 1)].hashPrevBlock
        if (prev_block_hash in self.block_store):
            prev_block_header = CBlockHeader(self.block_store[prev_block_hash])
            headers_list.append(prev_block_header)
            if (prev_block_header.sha256 == hash_stop):
                break
        else:
            logger.debug('block hash {} not found in block store'.format(hex(prev_block_hash)))
            break
    headers_list = headers_list[:((- maxheaders) - 1):(- 1)]
    response = msg_headers(headers_list)
    if (response is not None):
        self.send_message(response)
Search back through our block store for the locator, and reply with a headers message if found.
def on_getheaders(self, message):
    
    (locator, hash_stop) = (message.locator, message.hashstop)
    if (not self.block_store):
        return
    headers_list = [self.block_store[self.last_block_hash]]
    maxheaders = 2000
    while (headers_list[(- 1)].sha256 not in locator.vHave):
        prev_block_hash = headers_list[(- 1)].hashPrevBlock
        if (prev_block_hash in self.block_store):
            prev_block_header = CBlockHeader(self.block_store[prev_block_hash])
            headers_list.append(prev_block_header)
            if (prev_block_header.sha256 == hash_stop):
                break
        else:
            logger.debug('block hash {} not found in block store'.format(hex(prev_block_hash)))
            break
    headers_list = headers_list[:((- maxheaders) - 1):(- 1)]
    response = msg_headers(headers_list)
    if (response is not None):
        self.send_message(response)