Skip to content

Commit

Permalink
Simplify system.add_node checks (#4614)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev authored May 14, 2024
1 parent 143c7b0 commit 47fe1e8
Showing 1 changed file with 6 additions and 39 deletions.
45 changes: 6 additions & 39 deletions nano/test_common/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,51 +134,18 @@ std::shared_ptr<nano::node> nano::test::system::add_node (nano::node_config cons
auto node1 (*i);
auto node2 (*j);

auto starting_size_1 = node1->network.size ();
auto starting_size_2 = node2->network.size ();

auto starting_realtime_1 = node1->tcp_listener.realtime_count ();
auto starting_realtime_2 = node2->tcp_listener.realtime_count ();

auto starting_keepalives_1 = node1->stats.count (stat::type::message, stat::detail::keepalive, stat::dir::in);
auto starting_keepalives_2 = node2->stats.count (stat::type::message, stat::detail::keepalive, stat::dir::in);

logger.debug (nano::log::type::system, "Connecting nodes: {} and {}", node1->identifier (), node2->identifier ());

// TCP is the only transport layer available.
debug_assert (type_a == nano::transport::transport_type::tcp);
node2->network.merge_peer (node1->network.endpoint ());

{
auto ec = poll_until_true (5s, [&node1, &node2, starting_size_1, starting_size_2] () {
auto size_1 = node1->network.size ();
auto size_2 = node2->network.size ();
return size_1 > starting_size_1 && size_2 > starting_size_2;
});
debug_assert (!ec);
}

if (type_a == nano::transport::transport_type::tcp && node_config_a.tcp_incoming_connections_max != 0 && !node_flags_a.disable_tcp_realtime)
{
{
// Wait for initial connection finish
auto ec = poll_until_true (5s, [&node1, &node2, starting_realtime_1, starting_realtime_2] () {
auto realtime_1 = node1->tcp_listener.realtime_count ();
auto realtime_2 = node2->tcp_listener.realtime_count ();
return realtime_1 > starting_realtime_1 && realtime_2 > starting_realtime_2;
});
debug_assert (!ec);
}
{
// Wait for keepalive message exchange
auto ec = poll_until_true (5s, [&node1, &node2, starting_keepalives_1, starting_keepalives_2] () {
auto keepalives_1 = node1->stats.count (stat::type::message, stat::detail::keepalive, stat::dir::in);
auto keepalives_2 = node2->stats.count (stat::type::message, stat::detail::keepalive, stat::dir::in);
return keepalives_1 > starting_keepalives_1 && keepalives_2 > starting_keepalives_2;
});
debug_assert (!ec);
}
}
auto ec = poll_until_true (5s, [&node1, &node2] () {
bool result_1 = node1->network.find_node_id (node2->node_id.pub) != nullptr;
bool result_2 = node2->network.find_node_id (node1->node_id.pub) != nullptr;
return result_1 && result_2;
});
debug_assert (!ec);
}

{
Expand Down

0 comments on commit 47fe1e8

Please sign in to comment.