View in context in the libbitcoin Slack #general mirror.
headers_in protocol, less comments, log messages, and assertions:
void protocol_header_in::start() NOEXCEPT
{
if (started())
return;
SUBSCRIBE_CHANNEL2(headers, handle_receive_headers, _1, _2);
SEND1(create_get_headers(), handle_send, _1);
protocol::start();
}
bool protocol_header_in::handle_receive_headers(const code& ec, const headers::cptr& message) NOEXCEPT
{
if (stopped(ec))
return false;
for (const auto& header: message->header_ptrs)
{
if (!query().set(*header, database::context{}))
{
stop(network::error::protocol_violation);
return false;
}
};
if (message->header_ptrs.size() == max_get_headers)
{
SEND1(create_get_headers({ message->header_ptrs.back()->hash() }), handle_send, _1);
}
return true;
}
get_headers protocol_header_in::create_get_headers() NOEXCEPT
{
return create_get_headers(query().get_hashes(get_blocks::heights(query().get_top_candidate())));
}
get_headers protocol_header_in::create_get_headers(hashes&& hashes) NOEXCEPT
{
return { std::move(hashes), null_hash };
}