Return if !node_l in channel_a->send()

This commit is contained in:
Thiago Silva 2022-09-20 13:35:57 -03:00
commit fdc8b3d121
No known key found for this signature in database
GPG key ID: 034303EB8F453169

View file

@ -677,7 +677,7 @@ void nano::transport::tcp_channels::start_tcp_receive_node_id (std::shared_ptr<n
return;
}
/* If node ID is known, don't establish new connection
Exception: temporary channels from bootstrap_server */
Exception: temporary channels from bootstrap_server */
auto existing_channel (node_l->network.tcp_channels.find_node_id (node_id));
if (existing_channel && !existing_channel->temporary)
{
@ -692,34 +692,36 @@ Exception: temporary channels from bootstrap_server */
node_l->logger.try_log (boost::str (boost::format ("Node ID handshake response sent with node ID %1% to %2%: query %3%") % node_l->node_id.pub.to_node_id () % endpoint_a % (*message.query).to_string ()));
}
channel_a->send (response_message, [node_w, channel_a, endpoint_a, cleanup_node_id_handshake_socket] (boost::system::error_code const & ec, std::size_t size_a) {
if (auto node_l = node_w.lock ())
auto node_l = node_w.lock ();
if (!node_l)
{
if (ec || !channel_a)
return;
}
if (ec || !channel_a)
{
if (node_l->config.logging.network_node_id_handshake_logging ())
{
if (node_l->config.logging.network_node_id_handshake_logging ())
{
node_l->logger.try_log (boost::str (boost::format ("Error sending node_id_handshake to %1%: %2%") % endpoint_a % ec.message ()));
}
cleanup_node_id_handshake_socket (endpoint_a);
return;
node_l->logger.try_log (boost::str (boost::format ("Error sending node_id_handshake to %1%: %2%") % endpoint_a % ec.message ()));
}
// Insert new node ID connection
if (auto socket_l = channel_a->socket.lock ())
{
channel_a->set_last_packet_sent (std::chrono::steady_clock::now ());
auto response_server = std::make_shared<nano::bootstrap_server> (socket_l, node_l);
node_l->network.tcp_channels.insert (channel_a, socket_l, response_server);
// Listen for possible responses
response_server->socket->type_set (nano::socket::type_t::realtime_response_server);
response_server->remote_node_id = channel_a->get_node_id ();
response_server->start ();
cleanup_node_id_handshake_socket (endpoint_a);
return;
}
// Insert new node ID connection
if (auto socket_l = channel_a->socket.lock ())
{
channel_a->set_last_packet_sent (std::chrono::steady_clock::now ());
auto response_server = std::make_shared<nano::bootstrap_server> (socket_l, node_l);
node_l->network.tcp_channels.insert (channel_a, socket_l, response_server);
// Listen for possible responses
response_server->socket->type_set (nano::socket::type_t::realtime_response_server);
response_server->remote_node_id = channel_a->get_node_id ();
response_server->start ();
if (!node_l->flags.disable_initial_telemetry_requests)
{
node_l->telemetry->get_metrics_single_peer_async (channel_a, [] (nano::telemetry_data_response const &) {
// Intentionally empty, starts the telemetry request cycle to more quickly disconnect from invalid peers
});
}
if (!node_l->flags.disable_initial_telemetry_requests)
{
node_l->telemetry->get_metrics_single_peer_async (channel_a, [] (nano::telemetry_data_response const &) {
// Intentionally empty, starts the telemetry request cycle to more quickly disconnect from invalid peers
});
}
}
});