heartbeat_socket::heartbeat_socket(zmq::context& context, server_node& node,
    bool secure)
  : http::socket(context, node.protocol_settings(), secure),
    settings_(node.server_settings()),
    protocol_settings_(node.protocol_settings())
{
}
// Heartbeat is capped at ~ 25 days by signed/millsecond conversions.
heartbeat_service::heartbeat_service(zmq::authenticator& authenticator,
    server_node& node, bool secure)
  : worker(node.thread_pool()),
    settings_(node.server_settings()),
    period_(to_milliseconds(settings_.heartbeat_interval_seconds)),
    authenticator_(authenticator),
    secure_(secure)
{
}
// TODO: use existing libbitcoin-node implementation.
void server_node::fullnode_fetch_history(server_node& node,
    const incoming_message& request, queue_send_callback queue_send)
{
    uint32_t from_height;
    payment_address payaddr;
    if (!unwrap_fetch_history_args(payaddr, from_height, request))
        return;

    fetch_history(node.blockchain(), node.transaction_indexer(), payaddr,
        std::bind(send_history_result, _1, _2, request, queue_send),
        from_height);
}
void server_node::fullnode_fetch_history(server_node& node,
        const incoming_message& request, queue_send_callback queue_send)
{
    uint32_t from_height;
    wallet::payment_address address;

    if (!unwrap_fetch_history_args(address, from_height, request))
        return;

    const auto handler =
        std::bind(send_history_result,
                  _1, _2, request, queue_send);

    fetch_history(node.blockchain(), node.transaction_indexer(), address,
                  handler, from_height);
}
void protocol_broadcast_transaction(server_node& node,
    const incoming_message& request, queue_send_callback queue_send)
{
    const data_chunk& raw_tx = request.data();
    chain::transaction tx;
    data_chunk result(4);
    auto serial = make_serializer(result.begin());

    if (!tx.from_data(raw_tx))
    {
        // error
        write_error_code(serial, error::bad_stream);
        outgoing_message response(request, result);
        queue_send(response);
        return;
    }

    auto ignore_send = [](const std::error_code&, size_t) {};

    // Send and hope for the best!
    node.protocol().broadcast(tx, ignore_send);

    // Response back to user saying everything is fine.
    write_error_code(serial, std::error_code());

    log_debug(LOG_SERVICE)
        << "protocol.broadcast_transaction() finished. Sending response.";

    outgoing_message response(request, result);
    queue_send(response);
}
Beispiel #6
0
 static void free_deep_notify(nova_server * server, server_node & node)
 {
     if (node.is_synth())
         server->notification_node_ended(&node);
     else {
         abstract_group * group = static_cast<abstract_group*>(&node);
         group->apply_on_children(std::bind(nova_server::free_deep_notify, server, std::placeholders::_1));
     }
 }
void protocol_total_connections(server_node& node,
    const incoming_message& request, queue_send_callback queue_send)
{
    BITCOIN_ASSERT(node.protocol().total_connections() <= max_uint32);
    const auto total_connections32 = static_cast<uint32_t>(
        node.protocol().total_connections());
    data_chunk result(8);
    auto serial = make_serializer(result.begin());
    write_error_code(serial, std::error_code());
    serial.write_4_bytes_little_endian(total_connections32);
    BITCOIN_ASSERT(serial.iterator() == result.end());

    log_debug(LOG_REQUEST)
        << "protocol.total_connections() finished. Sending response.";

    outgoing_message response(request, result);
    queue_send(response);
}
// NOTE: the format of this response changed in v3 (send only code on error).
void transaction_pool::validate(server_node& node, const message& request,
    send_handler handler)
{
    transaction tx;

    if (!tx.from_data(request.data()))
    {
        handler(message(request, error::bad_stream));
        return;
    }

    node.pool().validate(tx,
        std::bind(&transaction_pool::handle_validated,
            _1, _2, _3, _4, request, handler));
}
void transaction_pool::fetch_transaction(server_node& node,
    const message& request, send_handler handler)
{
    hash_digest hash;

    if (!unwrap_fetch_transaction_args(hash, request))
    {
        handler(message(request, error::bad_stream));
        return;
    }

    log::debug(LOG_SERVER)
        << "transaction_pool.fetch_transaction(" << encode_hash(hash) << ")";

    node.pool().fetch(hash,
        std::bind(transaction_fetched,
            _1, _2, request, handler));
}
Beispiel #10
0
 /** node_id mapping */
 friend std::size_t hash_value(server_node const & that)
 {
     return hash(that.id());
 }