Flag to disable TCP realtime network (#2103)

* Flag to disable TCP realtime network
* Fix errors
* Apply changes from review & add flags tests
This commit is contained in:
Sergey Kroshnin 2019-06-26 16:46:25 +03:00 committed by GitHub
commit 2c53ab098f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 3 deletions

View file

@ -988,6 +988,58 @@ TEST (json, backup)
ASSERT_EQ (get_file_count (), 2);
}
TEST (node_flags, disable_tcp_realtime)
{
nano::system system (24000, 1);
auto node1 = system.nodes[0];
nano::node_flags node_flags;
node_flags.disable_tcp_realtime = true;
auto node2 = system.add_node (nano::node_config (24001, system.logging), node_flags);
ASSERT_EQ (1, node1->network.size ());
auto list1 (node1->network.list (2));
ASSERT_EQ (node2->network.endpoint (), list1[0]->get_endpoint ());
ASSERT_EQ (nano::transport::transport_type::udp, list1[0]->get_type ());
ASSERT_EQ (1, node2->network.size ());
auto list2 (node2->network.list (2));
ASSERT_EQ (node1->network.endpoint (), list2[0]->get_endpoint ());
ASSERT_EQ (nano::transport::transport_type::udp, list2[0]->get_type ());
}
TEST (node_flags, disable_udp)
{
nano::system system (24000, 1);
auto node1 = system.nodes[0];
nano::node_flags node_flags;
node_flags.disable_udp = true;
nano::node_init init;
auto node2 (std::make_shared<nano::node> (init, system.io_ctx, nano::unique_path (), system.alarm, nano::node_config (24001, system.logging), system.work, node_flags));
system.nodes.push_back (node2);
node2->start ();
// Send UDP message
auto channel (std::make_shared<nano::transport::channel_udp> (node1->network.udp_channels, node2->network.endpoint ()));
node1->network.send_keepalive (channel);
std::this_thread::sleep_for (std::chrono::milliseconds (500));
// Check empty network
ASSERT_EQ (0, node1->network.size ());
ASSERT_EQ (0, node2->network.size ());
// Send TCP handshake
node1->network.merge_peer (node2->network.endpoint ());
system.deadline_set (5s);
while (node1->bootstrap.realtime_count != 1 || node2->bootstrap.realtime_count != 1)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (1, node1->network.size ());
auto list1 (node1->network.list (2));
ASSERT_EQ (node2->network.endpoint (), list1[0]->get_endpoint ());
ASSERT_EQ (nano::transport::transport_type::tcp, list1[0]->get_type ());
ASSERT_EQ (1, node2->network.size ());
auto list2 (node2->network.list (2));
ASSERT_EQ (node1->network.endpoint (), list2[0]->get_endpoint ());
ASSERT_EQ (nano::transport::transport_type::tcp, list2[0]->get_type ());
node2->stop ();
}
TEST (node, fork_publish)
{
std::weak_ptr<nano::node> node0;

View file

@ -45,7 +45,13 @@ void update_flags (nano::node_flags & flags_a, boost::program_options::variables
flags_a.disable_legacy_bootstrap = (vm.count ("disable_legacy_bootstrap") > 0);
flags_a.disable_wallet_bootstrap = (vm.count ("disable_wallet_bootstrap") > 0);
flags_a.disable_bootstrap_listener = (vm.count ("disable_bootstrap_listener") > 0);
flags_a.disable_tcp_realtime = (vm.count ("disable_tcp_realtime") > 0);
flags_a.disable_udp = (vm.count ("disable_udp") > 0);
if (flags_a.disable_tcp_realtime && flags_a.disable_udp)
{
std::cerr << "Flags --disable_tcp_realtime and --disable_udp cannot be used together" << std::endl;
std::exit (1);
}
flags_a.disable_unchecked_cleanup = (vm.count ("disable_unchecked_cleanup") > 0);
flags_a.disable_unchecked_drop = (vm.count ("disable_unchecked_drop") > 0);
flags_a.fast_bootstrap = (vm.count ("fast_bootstrap") > 0);
@ -90,6 +96,7 @@ int main (int argc, char * const * argv)
("disable_legacy_bootstrap", "Disables legacy bootstrap")
("disable_wallet_bootstrap", "Disables wallet lazy bootstrap")
("disable_bootstrap_listener", "Disables bootstrap processing for TCP listener (not including realtime network TCP connections)")
("disable_tcp_realtime", "Disables TCP realtime network")
("disable_udp", "Disables UDP realtime network")
("disable_unchecked_cleanup", "Disables periodic cleanup of old records from unchecked table")
("disable_unchecked_drop", "Disables drop of unchecked table at startup")

View file

@ -2248,7 +2248,7 @@ void nano::bootstrap_server::receive_node_id_handshake_action (boost::system::er
std::unique_ptr<nano::node_id_handshake> request (new nano::node_id_handshake (error, stream, header_a));
if (!error)
{
if (!node_id_handshake_finished)
if (!node_id_handshake_finished && !node->flags.disable_tcp_realtime)
{
add_request (std::unique_ptr<nano::message> (request.release ()));
}

View file

@ -66,7 +66,10 @@ void nano::network::start ()
{
udp_channels.start ();
}
tcp_channels.start ();
if (!node.flags.disable_tcp_realtime)
{
tcp_channels.start ();
}
ongoing_keepalive ();
}

View file

@ -89,6 +89,7 @@ public:
bool disable_legacy_bootstrap{ false };
bool disable_wallet_bootstrap{ false };
bool disable_bootstrap_listener{ false };
bool disable_tcp_realtime{ false };
bool disable_udp{ false };
bool disable_unchecked_cleanup{ false };
bool disable_unchecked_drop{ true };

View file

@ -63,7 +63,7 @@ std::shared_ptr<nano::node> nano::system::add_node (nano::node_config const & no
new1 = node1->network.size ();
new2 = node2->network.size ();
} while (new1 == starting1 || new2 == starting2);
if (type_a == nano::transport::transport_type::tcp)
if (type_a == nano::transport::transport_type::tcp && !node_flags_a.disable_tcp_realtime)
{
// Wait for initial connection finish
decltype (starting_listener1) new_listener1;

View file

@ -427,6 +427,11 @@ void nano::transport::tcp_channels::update (nano::tcp_endpoint const & endpoint_
void nano::transport::tcp_channels::start_tcp (nano::endpoint const & endpoint_a, std::function<void(std::shared_ptr<nano::transport::channel>)> const & callback_a)
{
if (node.flags.disable_tcp_realtime)
{
node.network.tcp_channels.udp_fallback (endpoint_a, callback_a);
return;
}
auto socket (std::make_shared<nano::socket> (node.shared_from_this (), boost::none, nano::socket::concurrency::multi_writer));
auto channel (std::make_shared<nano::transport::channel_tcp> (node, socket));
std::weak_ptr<nano::node> node_w (node.shared ());