Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rep crawler targets with ephemeral ports #2527

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3397,16 +3397,15 @@ TEST (node, dont_write_lock_node)
finished_promise.set_value ();
}

// Test is unstable on github actions for windows, disable if CI detected
#if (defined(_WIN32) && CI)
TEST (node, DISABLED_bidirectional_tcp)
#else
TEST (node, bidirectional_tcp)
#endif
{
nano::system system;
nano::node_flags node_flags;
node_flags.disable_udp = true; // Disable UDP connections
// Disable bootstrap to start elections for new blocks
node_flags.disable_legacy_bootstrap = true;
node_flags.disable_lazy_bootstrap = true;
node_flags.disable_wallet_bootstrap = true;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto node1 = system.add_node (node_config, node_flags);
Expand Down Expand Up @@ -3461,6 +3460,11 @@ TEST (node, bidirectional_tcp)
}
// Test block confirmation from node 2
system.wallet (1)->insert_adhoc (nano::test_genesis_key.prv);
system.deadline_set (10s);
while (node1->rep_crawler.representative_count () == 0)
{
ASSERT_NO_ERROR (system.poll ());
}
confirmed = false;
system.deadline_set (20s);
while (!confirmed)
Expand Down
6 changes: 3 additions & 3 deletions nano/node/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,9 @@ std::deque<std::shared_ptr<nano::transport::channel>> nano::network::list_fanout
return result;
}

std::unordered_set<std::shared_ptr<nano::transport::channel>> nano::network::random_set (size_t count_a, uint8_t min_version_a) const
std::unordered_set<std::shared_ptr<nano::transport::channel>> nano::network::random_set (size_t count_a, uint8_t min_version_a, bool include_temporary_channels_a) const
{
std::unordered_set<std::shared_ptr<nano::transport::channel>> result (tcp_channels.random_set (count_a, min_version_a));
std::unordered_set<std::shared_ptr<nano::transport::channel>> result (tcp_channels.random_set (count_a, min_version_a, include_temporary_channels_a));
std::unordered_set<std::shared_ptr<nano::transport::channel>> udp_random (udp_channels.random_set (count_a, min_version_a));
for (auto i (udp_random.begin ()), n (udp_random.end ()); i != n && result.size () < count_a * 1.5; ++i)
{
Expand All @@ -638,7 +638,7 @@ std::unordered_set<std::shared_ptr<nano::transport::channel>> nano::network::ran

void nano::network::random_fill (std::array<nano::endpoint, 8> & target_a) const
{
auto peers (random_set (target_a.size ()));
auto peers (random_set (target_a.size (), 0, false)); // Don't include channels with ephemeral remote ports
assert (peers.size () <= target_a.size ());
auto endpoint (nano::endpoint (boost::asio::ip::address_v6{}, 0));
assert (endpoint.address ().is_v6 ());
Expand Down
2 changes: 1 addition & 1 deletion nano/node/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class network final
// A list of random peers sized for the configured rebroadcast fanout
std::deque<std::shared_ptr<nano::transport::channel>> list_fanout ();
void random_fill (std::array<nano::endpoint, 8> &) const;
std::unordered_set<std::shared_ptr<nano::transport::channel>> random_set (size_t, uint8_t = 0) const;
std::unordered_set<std::shared_ptr<nano::transport::channel>> random_set (size_t, uint8_t = 0, bool = false) const;
// Get the next peer for attempting a tcp bootstrap connection
nano::tcp_endpoint bootstrap_peer (bool = false);
nano::endpoint endpoint ();
Expand Down
2 changes: 1 addition & 1 deletion nano/node/repcrawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ std::vector<std::shared_ptr<nano::transport::channel>> nano::rep_crawler::get_cr
required_peer_count += required_peer_count / 2;

// The rest of the endpoints are picked randomly
auto random_peers (node.network.random_set (required_peer_count));
auto random_peers (node.network.random_set (required_peer_count, 0, true)); // Include channels with ephemeral remote ports
std::vector<std::shared_ptr<nano::transport::channel>> result;
result.insert (result.end (), random_peers.begin (), random_peers.end ());
return result;
Expand Down
2 changes: 1 addition & 1 deletion nano/node/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void nano::telemetry::add (nano::telemetry_data const & telemetry_data_a, nano::
void nano::telemetry::get_metrics_random_peers_async (std::function<void(telemetry_data_responses const &)> const & callback_a)
{
// These peers will only be used if there isn't an already ongoing batch telemetry request round
auto random_peers = network.random_set (network.size_sqrt (), network_params.protocol.telemetry_protocol_version_min);
auto random_peers = network.random_set (network.size_sqrt (), network_params.protocol.telemetry_protocol_version_min, true);
nano::lock_guard<std::mutex> guard (mutex);
if (!stopped && !random_peers.empty ())
{
Expand Down
4 changes: 2 additions & 2 deletions nano/node/transport/tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ std::shared_ptr<nano::transport::channel_tcp> nano::transport::tcp_channels::fin
return result;
}

std::unordered_set<std::shared_ptr<nano::transport::channel>> nano::transport::tcp_channels::random_set (size_t count_a, uint8_t min_version) const
std::unordered_set<std::shared_ptr<nano::transport::channel>> nano::transport::tcp_channels::random_set (size_t count_a, uint8_t min_version, bool include_temporary_channels_a) const
{
std::unordered_set<std::shared_ptr<nano::transport::channel>> result;
result.reserve (count_a);
Expand All @@ -169,7 +169,7 @@ std::unordered_set<std::shared_ptr<nano::transport::channel>> nano::transport::t
auto index (nano::random_pool::generate_word32 (0, static_cast<CryptoPP::word32> (peers_size - 1)));

auto channel = channels.get<random_access_tag> ()[index].channel;
if (channel->get_network_version () >= min_version && !channel->server)
if (channel->get_network_version () >= min_version && (include_temporary_channels_a || !channel->server))
{
result.insert (channel);
}
Expand Down
2 changes: 1 addition & 1 deletion nano/node/transport/tcp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace transport
size_t size () const;
std::shared_ptr<nano::transport::channel_tcp> find_channel (nano::tcp_endpoint const &) const;
void random_fill (std::array<nano::endpoint, 8> &) const;
std::unordered_set<std::shared_ptr<nano::transport::channel>> random_set (size_t, uint8_t = 0) const;
std::unordered_set<std::shared_ptr<nano::transport::channel>> random_set (size_t, uint8_t = 0, bool = false) const;
bool store_all (bool = true);
std::shared_ptr<nano::transport::channel_tcp> find_node_id (nano::account const &);
// Get the next peer for attempting a tcp connection
Expand Down