本文整理汇总了C++中code::message方法的典型用法代码示例。如果您正苦于以下问题:C++ code::message方法的具体用法?C++ code::message怎么用?C++ code::message使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code
的用法示例。
在下文中一共展示了code::message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start_connect
void session_batch::start_connect(const code& ec, const authority& host,
connector::ptr connect, channel_handler handler)
{
if (stopped() || ec == error::service_stopped)
{
LOG_DEBUG(LOG_NETWORK)
<< "Batch session stopped while starting.";
handler(error::service_stopped, nullptr);
return;
}
// This termination prevents a tight loop in the empty address pool case.
if (ec)
{
LOG_WARNING(LOG_NETWORK)
<< "Failure fetching new address: " << ec.message();
handler(ec, nullptr);
return;
}
// This creates a tight loop in the case of a small address pool.
if (blacklisted(host))
{
LOG_DEBUG(LOG_NETWORK)
<< "Fetched blacklisted address [" << host << "] ";
handler(error::address_blocked, nullptr);
return;
}
LOG_DEBUG(LOG_NETWORK)
<< "Connecting to [" << host << "]";
// CONNECT
connect->connect(host, handler);
}
示例2: handle_connect
void session_manual::handle_connect(const code& ec, channel::ptr channel,
const std::string& hostname, uint16_t port, uint32_t remaining,
connector::ptr connector, channel_handler handler)
{
unpend(connector);
if (ec)
{
LOG_WARNING(LOG_NETWORK)
<< "Failure connecting [" << config::endpoint(hostname, port)
<< "] manually: " << ec.message();
// Retry logic.
// The handler invoke is the failure end of the connect sequence.
if (settings_.manual_attempt_limit == 0)
start_connect(hostname, port, 0, handler);
else if (remaining > 0)
start_connect(hostname, port, remaining - 1, handler);
else
handler(ec, nullptr);
return;
}
LOG_INFO(LOG_NETWORK)
<< "Connected manual channel [" << config::endpoint(hostname, port)
<< "] as [" << channel->authority() << "]";
register_channel(channel,
BIND5(handle_channel_start, _1, hostname, port, channel, handler),
BIND3(handle_channel_stop, _1, hostname, port));
}
示例3: handle_event
// This is fired by the base timer and stop handler.
void protocol_header_sync::handle_event(const code& ec, event_handler complete)
{
if (ec == error::channel_stopped)
{
complete(ec);
return;
}
if (ec && ec != error::channel_timeout)
{
log::warning(LOG_PROTOCOL)
<< "Failure in header sync timer for [" << authority() << "] "
<< ec.message();
complete(ec);
return;
}
// It was a timeout, so ten more seconds have passed.
current_second_ += expiry_interval.total_seconds();
// Drop the channel if it falls below the min sync rate averaged over all.
if (sync_rate() < minimum_rate_)
{
log::debug(LOG_PROTOCOL)
<< "Header sync rate (" << sync_rate() << "/sec) from ["
<< authority() << "]";
complete(error::channel_timeout);
return;
}
}
示例4: start_connect
void session_batch::start_connect(const code& ec, const authority& host,
connector::ptr connect, atomic_counter_ptr counter, channel_handler handler)
{
if (counter->load() == batch_size_)
return;
// This termination prevents a tight loop in the empty address pool case.
if (ec)
{
log::error(LOG_NETWORK)
<< "Failure fetching new address: " << ec.message();
handler(ec, nullptr);
return;
}
// This creates a tight loop in the case of a small address pool.
if (blacklisted(host))
{
log::debug(LOG_NETWORK)
<< "Fetched blacklisted address [" << host << "] ";
handler(error::address_blocked, nullptr);
return;
}
log::debug(LOG_NETWORK)
<< "Connecting to [" << host << "]";
// CONNECT
connect->connect(host, BIND6(handle_connect, _1, _2, host, connect,
counter, handler));
}
示例5: handle_connect
void protocol::handle_connect(const code& ec, channel::ptr node,
const config::authority& peer)
{
if (ec)
{
log_debug(LOG_PROTOCOL)
<< "Failure connecting [" << peer << "] " << ec.message();
// Restart connection attempt.
new_connection();
return;
}
// Save the connection as we are now assured of getting stop event.
outbound_connections_.push_back(node);
// Connected!
log_info(LOG_PROTOCOL)
<< "Connected to peer [" << peer.to_string() << "] ("
<< outbound_connections_.size() << " total)";
const auto stop_handler =
dispatch_.ordered_delegate(&protocol::outbound_channel_stopped,
this, _1, node, peer.to_string());
start_talking(node, stop_handler, relay_);
}
示例6: handle_manual_connect
void protocol::handle_manual_connect(const code& ec,
channel::ptr node, const std::string& hostname, uint16_t port, bool relay,
size_t retries)
{
const config::endpoint peer(hostname, port);
if (ec)
{
// Warn because we are supposed to maintain this connection.
log_warning(LOG_PROTOCOL)
<< "Failure connecting [" << peer << "] manually: "
<< ec.message();
// Retry connection.
const config::endpoint address(hostname, port);
retry_manual_connection(address, relay, retries);
return;
}
// Save the connection as we are now assured of getting a stop event.
manual_connections_.push_back(node);
// Connected!
log_info(LOG_PROTOCOL)
<< "Connected to peer [" << peer << "] manually ("
<< manual_connections_.size() << " total)";
const auto stop_handler =
dispatch_.ordered_delegate(&protocol::manual_channel_stopped,
this, _1, node, peer.to_string(), relay, retries);
start_talking(node, stop_handler, relay);
}
示例7: handle_receive_headers
// This originates from send_header->annoucements and get_headers requests.
bool protocol_block_in::handle_receive_headers(const code& ec,
message::headers::ptr message)
{
if (stopped())
return false;
if (ec)
{
log::debug(LOG_NODE)
<< "Failure getting headers from [" << authority() << "] "
<< ec.message();
stop(ec);
return false;
}
///////////////////////////////////////////////////////////////////////////
// There is no benefit to this use of headers, in fact it is suboptimal.
// In v3 headers will be used to build block tree before getting blocks.
///////////////////////////////////////////////////////////////////////////
hash_list block_hashes;
message->to_hashes(block_hashes);
// TODO: implement orphan_pool_.fetch_missing_block_hashes(...)
handle_fetch_missing_orphans(error::success, block_hashes);
return true;
}
示例8: handle_receive_not_found
bool protocol_block_in::handle_receive_not_found(const code& ec,
message::not_found::ptr message)
{
if (stopped())
return false;
if (ec)
{
log::debug(LOG_NODE)
<< "Failure getting block not_found from [" << authority() << "] "
<< ec.message();
stop(ec);
return false;
}
hash_list hashes;
message->to_hashes(hashes, inventory_type_id::block);
// The peer cannot locate a block that it told us it had.
// This only results from reorganization assuming peer is proper.
for (const auto hash: hashes)
{
log::debug(LOG_NODE)
<< "Block not_found [" << encode_hash(hash) << "] from ["
<< authority() << "]";
}
return true;
}
示例9: handle_fetch_block_locator
void protocol_block_in::handle_fetch_block_locator(const code& ec,
const hash_list& locator)
{
if (stopped() || ec == error::service_stopped)
return;
if (ec)
{
log::error(LOG_NODE)
<< "Internal failure generating block locator for ["
<< authority() << "] " << ec.message();
stop(ec);
return;
}
///////////////////////////////////////////////////////////////////////////
// TODO: manage the stop_hash_ (see v2).
///////////////////////////////////////////////////////////////////////////
if (headers_from_peer_)
{
const get_headers request{ std::move(locator), stop_hash_ };
SEND2(request, handle_send, _1, request.command);
}
else
{
const get_blocks request{ std::move(locator), stop_hash_ };
SEND2(request, handle_send, _1, request.command);
}
}
示例10: handle_accept
void session_inbound::handle_accept(const code& ec, channel::ptr channel,
acceptor::ptr accept)
{
if (stopped())
return;
start_accept(error::success, accept);
if (ec)
{
log::debug(LOG_NETWORK)
<< "Failure accepting connection: " << ec.message();
return;
}
if (blacklisted(channel->authority()))
{
log::debug(LOG_NETWORK)
<< "Rejected inbound connection from ["
<< channel->authority() << "] due to blacklisted address.";
return;
}
connection_count(
dispatch_.ordered_delegate(&session_inbound::handle_connection_count,
shared_from_base<session_inbound>(), _1, channel));
}
示例11: handle_receive_get_address
void protocol_address::handle_receive_get_address(const code& ec,
const get_address& message)
{
if (stopped())
return;
if (ec)
{
log_debug(LOG_PROTOCOL)
<< "Failure receiving get_address message from ["
<< authority() << "] " << ec.message();
stop(ec);
return;
}
// TODO: allowing repeated queries can allow a peer to map our history.
// Resubscribe to get_address messages.
subscribe<get_address>(
&protocol_address::handle_receive_get_address, _1, _2);
// TODO: pull active hosts from host cache (currently just resending self).
// TODO: need to distort for privacy, don't send currently-connected peers.
address active({ { self_.to_network_address() } });
if (active.addresses.empty())
return;
log_debug(LOG_PROTOCOL)
<< "Sending addresses to [" << authority() << "] ("
<< active.addresses.size() << ")";
send(active, &protocol_address::handle_send_address, _1);
}
示例12: handle_receive_pong
bool protocol_ping::handle_receive_pong(const code& ec,
message::pong::ptr message, uint64_t nonce)
{
if (stopped())
return false;
if (ec)
{
log::debug(LOG_NETWORK)
<< "Failure getting pong from [" << authority() << "] "
<< ec.message();
stop(ec);
return false;
}
if (message->nonce != nonce)
{
log::warning(LOG_NETWORK)
<< "Invalid pong nonce from [" << authority() << "]";
// This could result from message overlap due to a short period,
// but we assume the response is not as expected and terminate.
stop(error::bad_stream);
}
return false;
}
示例13: handle_connect
void session_manual::handle_connect(const code& ec, channel::ptr channel,
const std::string& hostname, uint16_t port, channel_handler handler,
uint16_t retries)
{
if (ec)
{
log::warning(LOG_NETWORK)
<< "Failure connecting [" << config::endpoint(hostname, port)
<< "] manually: " << ec.message();
// Retry logic.
if (settings_.connect_attempts == 0)
start_connect(hostname, port, handler, 0);
else if (retries > 0)
start_connect(hostname, port, handler, retries - 1);
else
handler(ec, nullptr);
return;
}
log::info(LOG_NETWORK)
<< "Connected manual channel [" << config::endpoint(hostname, port)
<< "] as [" << channel->authority() << "]";
register_channel(channel,
std::bind(&session_manual::handle_channel_start,
shared_from_base<session_manual>(), _1, hostname, port, channel, handler),
std::bind(&session_manual::handle_channel_stop,
shared_from_base<session_manual>(), _1, hostname, port));
}
示例14: receive_get_data
// We don't seem to be getting getdata requests.
void responder::receive_get_data(const code& ec, const get_data& packet,
channel::ptr node)
{
if (ec == error::channel_stopped)
return;
const auto peer = node->authority();
if (ec)
{
log::debug(LOG_RESPONDER)
<< "Failure in receive get data [" << peer << "] " << ec.message();
node->stop(ec);
return;
}
// Resubscribe to serve tx and blocks.
node->subscribe<message::get_data>(
std::bind(&responder::receive_get_data,
this, _1, _2, node));
log::debug(LOG_RESPONDER)
<< "Getdata BEGIN [" << peer << "] "
<< "txs (" << packet.count(inventory_type_id::transaction) << ") "
<< "blocks (" << packet.count(inventory_type_id::block) << ") "
<< "bloom (" << packet.count(inventory_type_id::filtered_block) << ")";
for (const auto& inventory: packet.inventories)
{
switch (inventory.type)
{
case inventory_type_id::transaction:
log::debug(LOG_RESPONDER)
<< "Transaction getdata for [" << peer << "] "
<< encode_hash(inventory.hash);
tx_pool_.fetch(inventory.hash,
std::bind(&responder::send_pool_tx,
this, _1, _2, inventory.hash, node));
break;
case inventory_type_id::block:
log::debug(LOG_RESPONDER)
<< "Block getdata for [" << peer << "] "
<< encode_hash(inventory.hash);
block_fetcher::fetch(blockchain_, inventory.hash,
std::bind(&responder::send_block,
this, _1, _2, inventory.hash, node));
break;
case inventory_type_id::error:
case inventory_type_id::none:
default:
log::debug(LOG_RESPONDER)
<< "Ignoring invalid getdata type for [" << peer << "]";
}
}
log::debug(LOG_RESPONDER)
<< "Getdata END [" << peer << "]";
}
示例15: send_pool_tx
void responder::send_pool_tx(const code& ec, const transaction& tx,
const hash_digest& tx_hash, channel::ptr node)
{
if (ec == error::service_stopped)
return;
if (ec == error::not_found)
{
log::debug(LOG_RESPONDER)
<< "Transaction for [" << node->authority()
<< "] not in mempool [" << encode_hash(tx_hash) << "]";
// It wasn't in the mempool, so relay the request to the blockchain.
blockchain_.fetch_transaction(tx_hash,
std::bind(&responder::send_chain_tx,
this, _1, _2, tx_hash, node));
return;
}
if (ec)
{
log::error(LOG_RESPONDER)
<< "Failure fetching mempool tx data for ["
<< node->authority() << "] " << ec.message();
node->stop(ec);
return;
}
send_tx(tx, tx_hash, node);
}