Skip to content

Commit

Permalink
Send live network messages over TCP (#1962)
Browse files Browse the repository at this point in the history
- merge_peer function modified to try TCP connection before UDP
- TCP channels ongoing_keepalive function used to wake up long not sending channels to prevent TCP disconnection from server
- Live TCP connection starts with node ID handshake
- After handshake node sends preferred peering ports for response channels (keepalive self)
- Received TCP live message is responded to sender with response channels
- Using #1938 multi-writer for TCP channel
- Multiple nodes system () tests using TCP connections by default
- Some tests modified to check 2 live network options: TCP connections & UDP connections
- tcp_incoming_connections_max added, max established incoming TCP connections
- bootstrap_server modified to accept live network messages
  • Loading branch information
SergiySW authored and Russel Waters committed May 22, 2019
1 parent f309379 commit 9ca0c64
Show file tree
Hide file tree
Showing 27 changed files with 1,602 additions and 395 deletions.
8 changes: 8 additions & 0 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ TEST (active_transactions, adjusted_difficulty_priority)
}
}

system.deadline_set (10s);
while (node1.active.confirmed.size () != 4)
{
ASSERT_NO_ERROR (system.poll ());
Expand All @@ -126,6 +127,7 @@ TEST (active_transactions, adjusted_difficulty_priority)
node1.process_active (send6); //key1
node1.process_active (send8); //key2

system.deadline_set (10s);
while (node1.active.size () != 6)
{
ASSERT_NO_ERROR (system.poll ());
Expand Down Expand Up @@ -183,12 +185,14 @@ TEST (active_transactions, keep_local)
auto open2 (std::make_shared<nano::state_block> (key4.pub, 0, key4.pub, nano::xrb_ratio, send4->hash (), key4.prv, key4.pub, system.work.generate (key4.pub)));
node1.process_active (open2);
//none are dropped since none are long_unconfirmed
system.deadline_set (10s);
while (node1.active.size () != 4)
{
ASSERT_NO_ERROR (system.poll ());
}
auto done (false);
//wait for all to be long_unconfirmed
system.deadline_set (10s);
while (!done)
{
ASSERT_FALSE (node1.active.empty ());
Expand All @@ -201,6 +205,7 @@ TEST (active_transactions, keep_local)
auto send5 (wallet.send_action (nano::test_genesis_key.pub, key1.pub, node1.config.receive_minimum.number ()));
node1.active.start (send5);
//drop two lowest non-wallet managed active_transactions before inserting a new into active as all are long_unconfirmed
system.deadline_set (10s);
while (node1.active.size () != 3)
{
ASSERT_NO_ERROR (system.poll ());
Expand Down Expand Up @@ -256,6 +261,7 @@ TEST (active_transactions, prioritize_chains)
node1.process_active (send4);
node1.process_active (send6);

system.deadline_set (10s);
while (node1.active.size () != 4)
{
ASSERT_NO_ERROR (system.poll ());
Expand All @@ -273,12 +279,14 @@ TEST (active_transactions, prioritize_chains)
}
std::this_thread::sleep_for (1s);
node1.process_active (open2);
system.deadline_set (10s);
while (node1.active.size () != 4)
{
ASSERT_NO_ERROR (system.poll ());
}
//wait for all to be long_unconfirmed
done = false;
system.deadline_set (10s);
while (!done)
{
{
Expand Down
236 changes: 156 additions & 80 deletions nano/core_test/network.cpp

Large diffs are not rendered by default.

297 changes: 159 additions & 138 deletions nano/core_test/node.cpp

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions nano/core_test/peer_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ TEST (peer_container, split)
system.nodes[0]->network.cleanup (now);
ASSERT_EQ (1, system.nodes[0]->network.size ());
ASSERT_EQ (1, system.nodes[0]->network.udp_channels.size ());
auto list (system.nodes[0]->network.udp_channels.list (1));
auto list (system.nodes[0]->network.list (1));
ASSERT_EQ (endpoint2, list[0]->get_endpoint ());
}

TEST (udp_channels, fill_random_clear)
TEST (channels, fill_random_clear)
{
nano::system system (24000, 1);
std::array<nano::endpoint, 8> target;
std::fill (target.begin (), target.end (), nano::endpoint (boost::asio::ip::address_v6::loopback (), 10000));
system.nodes[0]->network.udp_channels.random_fill (target);
system.nodes[0]->network.random_fill (target);
ASSERT_TRUE (std::all_of (target.begin (), target.end (), [](nano::endpoint const & endpoint_a) { return endpoint_a == nano::endpoint (boost::asio::ip::address_v6::any (), 0); }));
}

TEST (udp_channels, fill_random_full)
TEST (channels, fill_random_full)
{
nano::system system (24000, 1);
for (auto i (0); i < 100; ++i)
Expand All @@ -93,11 +93,11 @@ TEST (udp_channels, fill_random_full)
}
std::array<nano::endpoint, 8> target;
std::fill (target.begin (), target.end (), nano::endpoint (boost::asio::ip::address_v6::loopback (), 10000));
system.nodes[0]->network.udp_channels.random_fill (target);
system.nodes[0]->network.random_fill (target);
ASSERT_TRUE (std::none_of (target.begin (), target.end (), [](nano::endpoint const & endpoint_a) { return endpoint_a == nano::endpoint (boost::asio::ip::address_v6::loopback (), 10000); }));
}

TEST (udp_channels, fill_random_part)
TEST (channels, fill_random_part)
{
nano::system system (24000, 1);
std::array<nano::endpoint, 8> target;
Expand All @@ -107,7 +107,7 @@ TEST (udp_channels, fill_random_part)
system.nodes[0]->network.udp_channels.insert (nano::endpoint (boost::asio::ip::address_v6::loopback (), i + 1), 0);
}
std::fill (target.begin (), target.end (), nano::endpoint (boost::asio::ip::address_v6::loopback (), 10000));
system.nodes[0]->network.udp_channels.random_fill (target);
system.nodes[0]->network.random_fill (target);
ASSERT_TRUE (std::none_of (target.begin (), target.begin () + half, [](nano::endpoint const & endpoint_a) { return endpoint_a == nano::endpoint (boost::asio::ip::address_v6::loopback (), 10000); }));
ASSERT_TRUE (std::none_of (target.begin (), target.begin () + half, [](nano::endpoint const & endpoint_a) { return endpoint_a == nano::endpoint (boost::asio::ip::address_v6::loopback (), 0); }));
ASSERT_TRUE (std::all_of (target.begin () + half, target.end (), [](nano::endpoint const & endpoint_a) { return endpoint_a == nano::endpoint (boost::asio::ip::address_v6::any (), 0); }));
Expand All @@ -116,13 +116,13 @@ TEST (udp_channels, fill_random_part)
TEST (peer_container, list_fanout)
{
nano::system system (24000, 1);
auto list1 (system.nodes[0]->network.udp_channels.list_fanout ());
auto list1 (system.nodes[0]->network.list_fanout ());
ASSERT_TRUE (list1.empty ());
for (auto i (0); i < 1000; ++i)
{
ASSERT_NE (nullptr, system.nodes[0]->network.udp_channels.insert (nano::endpoint (boost::asio::ip::address_v6::loopback (), 10000 + i), nano::protocol_version));
}
auto list2 (system.nodes[0]->network.udp_channels.list_fanout ());
auto list2 (system.nodes[0]->network.list_fanout ());
ASSERT_EQ (32, list2.size ());
}

Expand Down
1 change: 1 addition & 0 deletions nano/core_test/wallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ TEST (wallets, reload)
ASSERT_FALSE (error);
ASSERT_EQ (1, system.nodes[0]->wallets.items.size ());
{
std::lock_guard<std::mutex> lock_wallet (system.nodes[0]->wallets.mutex);
nano::inactive_node node (system.nodes[0]->application_path, 24001);
auto wallet (node.node->wallets.create (one));
ASSERT_NE (wallet, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main (int argc, char * const * argv)
("disable_lazy_bootstrap", "Disables lazy bootstrap")
("disable_legacy_bootstrap", "Disables legacy bootstrap")
("disable_wallet_bootstrap", "Disables wallet lazy bootstrap")
("disable_bootstrap_listener", "Disables bootstrap listener (incoming connections)")
("disable_bootstrap_listener", "Disables bootstrap processing for TCP listener (not including realtime network TCP connections)")
("disable_unchecked_cleanup", "Disables periodic cleanup of old records from unchecked table")
("disable_unchecked_drop", "Disables drop of unchecked table at startup")
("fast_bootstrap", "Increase bootstrap speed for high end nodes with higher limits")
Expand Down
Loading

0 comments on commit 9ca0c64

Please sign in to comment.