Preemptively return if existing_channel && !existing_channel->temporary
process may only be set to true iff existing_channel == true, so we can exit if (existing_channel && !existing_channel->temporary)
This commit is contained in:
parent
faa1066937
commit
21f8be2b0d
1 changed files with 34 additions and 37 deletions
|
@ -679,52 +679,49 @@ void nano::transport::tcp_channels::start_tcp_receive_node_id (std::shared_ptr<n
|
|||
/* If node ID is known, don't establish new connection
|
||||
Exception: temporary channels from bootstrap_server */
|
||||
auto existing_channel (node_l->network.tcp_channels.find_node_id (node_id));
|
||||
if (existing_channel)
|
||||
if (existing_channel && !existing_channel->temporary)
|
||||
{
|
||||
process = existing_channel->temporary;
|
||||
return;
|
||||
}
|
||||
if (process)
|
||||
channel_a->set_node_id (node_id);
|
||||
channel_a->set_last_packet_received (std::chrono::steady_clock::now ());
|
||||
boost::optional<std::pair<nano::account, nano::signature>> response (std::make_pair (node_l->node_id.pub, nano::sign_message (node_l->node_id.prv, node_l->node_id.pub, *message.query)));
|
||||
nano::node_id_handshake response_message (node_l->network_params.network, boost::none, response);
|
||||
if (node_l->config.logging.network_node_id_handshake_logging ())
|
||||
{
|
||||
channel_a->set_node_id (node_id);
|
||||
channel_a->set_last_packet_received (std::chrono::steady_clock::now ());
|
||||
boost::optional<std::pair<nano::account, nano::signature>> response (std::make_pair (node_l->node_id.pub, nano::sign_message (node_l->node_id.prv, node_l->node_id.pub, *message.query)));
|
||||
nano::node_id_handshake response_message (node_l->network_params.network, boost::none, response);
|
||||
if (node_l->config.logging.network_node_id_handshake_logging ())
|
||||
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 ())
|
||||
{
|
||||
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 ())
|
||||
if (ec || !channel_a)
|
||||
{
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue