示例#1
0
void poller::monitor(channel_ptr node)
{
    node->subscribe_inventory(
        strand_.wrap(std::bind(&poller::receive_inv,
                               this, _1, _2, node)));
    node->subscribe_block(
        std::bind(&poller::receive_block,
                  this, _1, _2, node));
}
示例#2
0
void ask_blocks(const std::error_code& ec, channel_ptr node,
    const message::block_locator& loc, blockchain_ptr chain,
    const hash_digest& hash_stop)
{
    if (ec)
        log_error() << ec.message();
    node->subscribe_inventory(std::bind(recv_inv, _1, _2, node));
    node->subscribe_block(std::bind(recv_blk, _1, _2, node, chain));

    message::get_blocks packet;
    packet.start_hashes = loc;
    packet.hash_stop = hash_stop;
    node->send(packet, std::bind(&handle_send_packet, _1));
}
示例#3
0
void handle_connect(const std::error_code& ec, channel_ptr node)
{
    recv_node = node;
    message::get_data getdat;
    getdat.inventories.push_back(
        {message::inventory_type::transaction,
            hash_from_pretty<hash_digest>("e72e4f025695446cfd5c5349d1720beb38801f329a00281f350cb7e847153397")});
    getdat.inventories.push_back(
        {message::inventory_type::block,
            hash_from_pretty<hash_digest>("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")});
    node->subscribe_block(handle_blk);
    sleep(1);
    node->send(getdat, handle_send);
}
示例#4
0
void poller::receive_block(const std::error_code& ec,
                           const block_type& blk, channel_ptr node)
{
    if (ec)
    {
        log_error(LOG_POLLER) << "Received bad block: " << ec.message();
        return;
    }
    chain_.store(blk,
                 std::bind(&poller::handle_store,
                           this, _1, _2, hash_block_header(blk.header), node));
    node->subscribe_block(
        std::bind(&poller::receive_block,
                  this, _1, _2, node));
}
示例#5
0
// Start monitoring this channel.
void poller::monitor(channel_ptr node)
{
    if (!node)
    {
        log_error(LOG_POLLER)
            << "The node is not initialized and cannot be monitored.";
        return;
    }

    //////node->subscribe_inventory(
    //////    std::bind(&poller::receive_inv,
    //////        this, _1, _2, node));

    node->subscribe_block(
        std::bind(&poller::receive_block,
            this, _1, _2, node));

    // Issue the initial ask for blocks.
    request_blocks(null_hash, node);
}
示例#6
0
void recv_blk(const std::error_code& ec, const message::block& packet,
    channel_ptr node, blockchain_ptr chain)
{
    static bool stop_inserts = false;
    if (ec)
        log_error() << ec.message();
    node->subscribe_block(std::bind(recv_blk, _1, _2, node, chain));
    // store block in bdb
    //if (hash_block_header(packet) ==
    //    hash_digest{0x00, 0x00, 0x00, 0x00, 0xd1, 0x14, 0x57, 0x90,
    //                0xa8, 0x69, 0x44, 0x03, 0xd4, 0x06, 0x3f, 0x32,
    //                0x3d, 0x49, 0x9e, 0x65, 0x5c, 0x83, 0x42, 0x68,
    //                0x34, 0xd4, 0xce, 0x2f, 0x8d, 0xd4, 0xa2, 0xee})
    //{
    //    test_mem_pool(packet);
    //    stop_inserts = true;
    //}
    //else if (!stop_inserts)
        chain->store(packet, std::bind(handle_store, _1, _2, node, chain, hash_block_header(packet)));
}
示例#7
0
void poller::receive_block(const std::error_code& ec,
    const block_type& block, channel_ptr node)
{
    if (!node)
        return;

    if (ec)
    {
        log_warning(LOG_POLLER) << "Received bad block: "
            << ec.message();
        node->stop(/* ec */);
        return;
    }

    blockchain_.store(block,
        strand_.wrap(&poller::handle_store_block,
            this, _1, _2, hash_block_header(block.header), node));

    // Resubscribe.
    node->subscribe_block(
        std::bind(&poller::receive_block,
            this, _1, _2, node));
}