Skip to content

Commit

Permalink
Merging protocol_constants in to network_constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Aug 5, 2021
1 parent 20828e6 commit 7230b1f
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 107 deletions.
24 changes: 12 additions & 12 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ TEST (bootstrap_processor, lazy_hash)
node0->block_processor.flush ();
// Start lazy bootstrap with last block in chain known
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.logging, system.work));
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.protocol.protocol_version);
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.network.protocol_version);
node1->bootstrap_initiator.bootstrap_lazy (receive2->hash (), true);
{
auto lazy_attempt (node1->bootstrap_initiator.current_lazy_attempt ());
Expand Down Expand Up @@ -607,7 +607,7 @@ TEST (bootstrap_processor, lazy_hash_bootstrap_id)
node0->block_processor.flush ();
// Start lazy bootstrap with last block in chain known
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.logging, system.work));
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.protocol.protocol_version);
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.network.protocol_version);
node1->bootstrap_initiator.bootstrap_lazy (receive2->hash (), true, true, "123456");
{
auto lazy_attempt (node1->bootstrap_initiator.current_lazy_attempt ());
Expand Down Expand Up @@ -745,7 +745,7 @@ TEST (bootstrap_processor, lazy_hash_pruning)
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (3, node1->ledger.cache.pruned_count);
// Start lazy bootstrap with last block in chain known
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.protocol.protocol_version);
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.network.protocol_version);
node1->bootstrap_initiator.bootstrap_lazy (receive3->hash (), true);
// Check processed blocks
ASSERT_TIMELY (10s, node1->ledger.cache.block_count == 9);
Expand Down Expand Up @@ -848,7 +848,7 @@ TEST (bootstrap_processor, lazy_max_pull_count)
node0->block_processor.flush ();
// Start lazy bootstrap with last block in chain known
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.logging, system.work));
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.protocol.protocol_version);
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.network.protocol_version);
node1->bootstrap_initiator.bootstrap_lazy (change3->hash ());
// Check processed blocks
ASSERT_TIMELY (10s, node1->block (change3->hash ()));
Expand Down Expand Up @@ -906,7 +906,7 @@ TEST (bootstrap_processor, lazy_unclear_state_link)
ASSERT_EQ (nano::process_result::progress, node1->process (*receive).code);
// Start lazy bootstrap with last block in chain known
auto node2 = system.add_node (nano::node_config (nano::get_available_port (), system.logging), node_flags);
node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.protocol.protocol_version);
node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.network.protocol_version);
node2->bootstrap_initiator.bootstrap_lazy (receive->hash ());
// Check processed blocks
ASSERT_TIMELY (10s, !node2->bootstrap_initiator.in_progress ());
Expand Down Expand Up @@ -958,7 +958,7 @@ TEST (bootstrap_processor, lazy_unclear_state_link_not_existing)

// Start lazy bootstrap with last block in chain known
auto node2 = system.add_node (nano::node_config (nano::get_available_port (), system.logging), node_flags);
node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.protocol.protocol_version);
node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.network.protocol_version);
node2->bootstrap_initiator.bootstrap_lazy (send2->hash ());
// Check processed blocks
ASSERT_TIMELY (15s, !node2->bootstrap_initiator.in_progress ());
Expand Down Expand Up @@ -1020,7 +1020,7 @@ TEST (bootstrap_processor, DISABLED_lazy_destinations)

// Start lazy bootstrap with last block in sender chain
auto node2 = system.add_node (nano::node_config (nano::get_available_port (), system.logging), node_flags);
node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.protocol.protocol_version);
node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.network.protocol_version);
node2->bootstrap_initiator.bootstrap_lazy (send2->hash ());
// Check processed blocks
ASSERT_TIMELY (10s, !node2->bootstrap_initiator.in_progress ());
Expand Down Expand Up @@ -1098,7 +1098,7 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
// Start lazy bootstrap with last block in sender chain
config.peering_port = nano::get_available_port ();
auto node2 (std::make_shared<nano::node> (system.io_ctx, nano::unique_path (), config, system.work, node_flags, 1));
node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.protocol.protocol_version);
node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.network.protocol_version);
node2->bootstrap_initiator.bootstrap_lazy (send2->hash ());
// Check processed blocks
auto lazy_attempt (node2->bootstrap_initiator.current_lazy_attempt ());
Expand Down Expand Up @@ -1153,7 +1153,7 @@ TEST (bootstrap_processor, lazy_cancel)

// Start lazy bootstrap with last block in chain known
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.logging, system.work));
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.protocol.protocol_version);
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.network.protocol_version);
node1->bootstrap_initiator.bootstrap_lazy (send1->hash (), true); // Start "confirmed" block bootstrap
{
auto lazy_attempt (node1->bootstrap_initiator.current_lazy_attempt ());
Expand Down Expand Up @@ -1228,7 +1228,7 @@ TEST (bootstrap_processor, wallet_lazy_frontier)
node0->block_processor.flush ();
// Start wallet lazy bootstrap
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.logging, system.work));
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.protocol.protocol_version);
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.network.protocol_version);
auto wallet (node1->wallets.create (nano::random_wallet_id ()));
ASSERT_NE (nullptr, wallet);
wallet->insert_adhoc (key2.prv);
Expand Down Expand Up @@ -1295,7 +1295,7 @@ TEST (bootstrap_processor, wallet_lazy_pending)
node0->block_processor.flush ();
// Start wallet lazy bootstrap
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.logging, system.work));
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.protocol.protocol_version);
node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.network.protocol_version);
auto wallet (node1->wallets.create (nano::random_wallet_id ()));
ASSERT_NE (nullptr, wallet);
wallet->insert_adhoc (key2.prv);
Expand Down Expand Up @@ -1369,7 +1369,7 @@ TEST (bootstrap_processor, multiple_attempts)
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.bootstrap_initiator_threads = 3;
auto node2 (std::make_shared<nano::node> (system.io_ctx, nano::unique_path (), node_config, system.work));
node2->network.udp_channels.insert (node1->network.endpoint (), node2->network_params.protocol.protocol_version);
node2->network.udp_channels.insert (node1->network.endpoint (), node2->network_params.network.protocol_version);
node2->bootstrap_initiator.bootstrap_lazy (receive2->hash (), true);
node2->bootstrap_initiator.bootstrap ();
auto lazy_attempt (node2->bootstrap_initiator.current_lazy_attempt ());
Expand Down
20 changes: 10 additions & 10 deletions nano/core_test/message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ TEST (message_parser, exact_confirm_ack_size)
nano::network_filter filter (1);
nano::block_uniquer block_uniquer;
nano::vote_uniquer vote_uniquer (block_uniquer);
nano::protocol_constants protocol;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, protocol);
nano::network_constants network;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, network);
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, *system.work.generate (nano::root (1))));
auto vote (std::make_shared<nano::vote> (0, nano::keypair ().prv, 0, std::move (block)));
nano::confirm_ack message (vote);
Expand Down Expand Up @@ -102,8 +102,8 @@ TEST (message_parser, exact_confirm_req_size)
nano::network_filter filter (1);
nano::block_uniquer block_uniquer;
nano::vote_uniquer vote_uniquer (block_uniquer);
nano::protocol_constants protocol;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, protocol);
nano::network_constants network;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, network);
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, *system.work.generate (nano::root (1))));
nano::confirm_req message (std::move (block));
std::vector<uint8_t> bytes;
Expand Down Expand Up @@ -136,8 +136,8 @@ TEST (message_parser, exact_confirm_req_hash_size)
nano::network_filter filter (1);
nano::block_uniquer block_uniquer;
nano::vote_uniquer vote_uniquer (block_uniquer);
nano::protocol_constants protocol;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, protocol);
nano::network_constants network;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, network);
nano::send_block block (1, 1, 2, nano::keypair ().prv, 4, *system.work.generate (nano::root (1)));
nano::confirm_req message (block.hash (), block.root ());
std::vector<uint8_t> bytes;
Expand Down Expand Up @@ -170,8 +170,8 @@ TEST (message_parser, exact_publish_size)
nano::network_filter filter (1);
nano::block_uniquer block_uniquer;
nano::vote_uniquer vote_uniquer (block_uniquer);
nano::protocol_constants protocol;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, protocol);
nano::network_constants network;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, network);
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, *system.work.generate (nano::root (1))));
nano::publish message (std::move (block));
std::vector<uint8_t> bytes;
Expand Down Expand Up @@ -204,8 +204,8 @@ TEST (message_parser, exact_keepalive_size)
nano::network_filter filter (1);
nano::block_uniquer block_uniquer;
nano::vote_uniquer vote_uniquer (block_uniquer);
nano::protocol_constants protocol;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, protocol);
nano::network_constants network;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, network);
nano::keepalive message;
std::vector<uint8_t> bytes;
{
Expand Down
14 changes: 7 additions & 7 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ TEST (network, send_node_id_handshake)
system.nodes.push_back (node1);
auto initial (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in));
auto initial_node1 (node1->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in));
auto channel (std::make_shared<nano::transport::channel_udp> (node0->network.udp_channels, node1->network.endpoint (), node1->network_params.protocol.protocol_version));
auto channel (std::make_shared<nano::transport::channel_udp> (node0->network.udp_channels, node1->network.endpoint (), node1->network_params.network.protocol_version));
node0->network.send_keepalive (channel);
ASSERT_EQ (0, node0->network.size ());
ASSERT_EQ (0, node1->network.size ());
Expand Down Expand Up @@ -305,7 +305,7 @@ TEST (network, send_insufficient_work_udp)
auto & node2 = *system.add_node (node_flags);
auto block (std::make_shared<nano::send_block> (0, 1, 20, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, 0));
nano::publish publish (block);
nano::transport::channel_udp channel (node1.network.udp_channels, node2.network.endpoint (), node1.network_params.protocol.protocol_version);
nano::transport::channel_udp channel (node1.network.udp_channels, node2.network.endpoint (), node1.network_params.network.protocol_version);
channel.send (publish, [] (boost::system::error_code const & ec, size_t size) {});
ASSERT_EQ (0, node1.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work));
ASSERT_TIMELY (10s, node2.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work) != 0);
Expand Down Expand Up @@ -878,14 +878,14 @@ TEST (network, replace_port)
node1->start ();
system.nodes.push_back (node1);
auto wrong_endpoint = nano::endpoint (node1->network.endpoint ().address (), nano::get_available_port ());
auto channel0 (node0->network.udp_channels.insert (wrong_endpoint, node1->network_params.protocol.protocol_version));
auto channel0 (node0->network.udp_channels.insert (wrong_endpoint, node1->network_params.network.protocol_version));
ASSERT_NE (nullptr, channel0);
node0->network.udp_channels.modify (channel0, [&node1] (std::shared_ptr<nano::transport::channel> const & channel_a) {
channel_a->set_node_id (node1->node_id.pub);
});
auto peers_list (node0->network.list (std::numeric_limits<size_t>::max ()));
ASSERT_EQ (peers_list[0]->get_node_id (), node1->node_id.pub);
auto channel1 (std::make_shared<nano::transport::channel_udp> (node0->network.udp_channels, node1->network.endpoint (), node1->network_params.protocol.protocol_version));
auto channel1 (std::make_shared<nano::transport::channel_udp> (node0->network.udp_channels, node1->network.endpoint (), node1->network_params.network.protocol_version));
ASSERT_EQ (node0->network.udp_channels.size (), 1);
node0->network.send_keepalive (channel1);
// On handshake, the channel is replaced
Expand Down Expand Up @@ -941,7 +941,7 @@ TEST (network, duplicate_detection)
node_flags.disable_udp = false;
auto & node0 (*system.add_node (node_flags));
auto & node1 (*system.add_node (node_flags));
auto udp_channel (std::make_shared<nano::transport::channel_udp> (node0.network.udp_channels, node1.network.endpoint (), node1.network_params.protocol.protocol_version));
auto udp_channel (std::make_shared<nano::transport::channel_udp> (node0.network.udp_channels, node1.network.endpoint (), node1.network_params.network.protocol_version));
nano::publish publish (nano::dev::genesis);

// Publish duplicate detection through UDP
Expand Down Expand Up @@ -1206,7 +1206,7 @@ TEST (network, cleanup_purge)
node1.network.cleanup (test_start);
ASSERT_EQ (0, node1.network.size ());

node1.network.udp_channels.insert (node2->network.endpoint (), node1.network_params.protocol.protocol_version);
node1.network.udp_channels.insert (node2->network.endpoint (), node1.network_params.network.protocol_version);
ASSERT_EQ (1, node1.network.size ());
node1.network.cleanup (test_start);
ASSERT_EQ (1, node1.network.size ());
Expand Down Expand Up @@ -1239,7 +1239,7 @@ TEST (network, loopback_channel)
ASSERT_EQ (channel1.get_type (), nano::transport::transport_type::loopback);
ASSERT_EQ (channel1.get_endpoint (), node1.network.endpoint ());
ASSERT_EQ (channel1.get_tcp_endpoint (), nano::transport::map_endpoint_to_tcp (node1.network.endpoint ()));
ASSERT_EQ (channel1.get_network_version (), node1.network_params.protocol.protocol_version);
ASSERT_EQ (channel1.get_network_version (), node1.network_params.network.protocol_version);
ASSERT_EQ (channel1.get_node_id (), node1.node_id.pub);
ASSERT_EQ (channel1.get_node_id_optional ().value_or (0), node1.node_id.pub);
nano::transport::channel_loopback channel2 (node2);
Expand Down
12 changes: 6 additions & 6 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,12 @@ TEST (node, connect_after_junk)
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.logging, system.work, node_flags));
std::vector<uint8_t> junk_buffer;
junk_buffer.push_back (0);
auto channel1 (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.protocol.protocol_version));
auto channel1 (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.network.protocol_version));
channel1->send_buffer (nano::shared_const_buffer (std::move (junk_buffer)), [] (boost::system::error_code const &, size_t) {});
ASSERT_TIMELY (10s, node0->stats.count (nano::stat::type::error) != 0);
node1->start ();
system.nodes.push_back (node1);
auto channel2 (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.protocol.protocol_version));
auto channel2 (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.network.protocol_version));
node1->network.send_keepalive (channel2);
ASSERT_TIMELY (10s, !node1->network.empty ());
node1->stop ();
Expand Down Expand Up @@ -1020,7 +1020,7 @@ TEST (node_flags, disable_udp)
ASSERT_EQ (nano::endpoint (boost::asio::ip::address_v6::loopback (), 0), node2->network.udp_channels.get_local_endpoint ());
ASSERT_NE (nano::endpoint (boost::asio::ip::address_v6::loopback (), 0), node2->network.endpoint ());
// Send UDP message
auto channel (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node2->network.endpoint (), node2->network_params.protocol.protocol_version));
auto channel (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node2->network.endpoint (), node2->network_params.network.protocol_version));
node1->network.send_keepalive (channel);
std::this_thread::sleep_for (std::chrono::milliseconds (500));
// Check empty network
Expand Down Expand Up @@ -1618,7 +1618,7 @@ TEST (node, DISABLED_fork_stale)
auto & node1 (*system1.nodes[0]);
auto & node2 (*system2.nodes[0]);
node2.bootstrap_initiator.bootstrap (node1.network.endpoint (), false);
std::shared_ptr<nano::transport::channel> channel (std::make_shared<nano::transport::channel_udp> (node2.network.udp_channels, node1.network.endpoint (), node2.network_params.protocol.protocol_version));
std::shared_ptr<nano::transport::channel> channel (std::make_shared<nano::transport::channel_udp> (node2.network.udp_channels, node1.network.endpoint (), node2.network_params.network.protocol_version));
auto vote = std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, std::vector<nano::block_hash> ());
node2.rep_crawler.response (channel, vote);
nano::keypair key1;
Expand Down Expand Up @@ -2252,8 +2252,8 @@ TEST (node, rep_remove)
}
// Add inactive UDP representative channel
nano::endpoint endpoint0 (boost::asio::ip::address_v6::loopback (), nano::get_available_port ());
std::shared_ptr<nano::transport::channel> channel0 (std::make_shared<nano::transport::channel_udp> (node.network.udp_channels, endpoint0, node.network_params.protocol.protocol_version));
auto channel_udp = node.network.udp_channels.insert (endpoint0, node.network_params.protocol.protocol_version);
std::shared_ptr<nano::transport::channel> channel0 (std::make_shared<nano::transport::channel_udp> (node.network.udp_channels, endpoint0, node.network_params.network.protocol_version));
auto channel_udp = node.network.udp_channels.insert (endpoint0, node.network_params.network.protocol_version);
auto vote1 = std::make_shared<nano::vote> (keypair1.pub, keypair1.prv, 0, nano::dev::genesis);
ASSERT_FALSE (node.rep_crawler.response (channel0, vote1));
ASSERT_TIMELY (5s, node.rep_crawler.representative_count () == 1);
Expand Down
Loading

0 comments on commit 7230b1f

Please sign in to comment.