Skip to content

Commit

Permalink
Applies the silent check to incoming messages server-side only (#3623)
Browse files Browse the repository at this point in the history
  • Loading branch information
thsfs authored Dec 21, 2021
1 parent 7057482 commit 04e7c58
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 68 deletions.
48 changes: 24 additions & 24 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace std::chrono_literals;
TEST (bulk_pull, no_address)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = 1;
req->end = 2;
Expand All @@ -24,7 +24,7 @@ TEST (bulk_pull, no_address)
TEST (bulk_pull, genesis_to_end)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = nano::dev::genesis_key.pub;
req->end.clear ();
Expand All @@ -38,7 +38,7 @@ TEST (bulk_pull, genesis_to_end)
TEST (bulk_pull, no_end)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = nano::dev::genesis_key.pub;
req->end = 1;
Expand All @@ -63,7 +63,7 @@ TEST (bulk_pull, end_not_owned)
open.signature = nano::sign_message (key2.prv, key2.pub, open.hash ());
system.nodes[0]->work_generate_blocking (open);
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->process (open).code);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = key2.pub;
req->end = nano::dev::genesis->hash ();
Expand All @@ -75,7 +75,7 @@ TEST (bulk_pull, end_not_owned)
TEST (bulk_pull, none)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = nano::dev::genesis_key.pub;
req->end = nano::dev::genesis->hash ();
Expand All @@ -88,7 +88,7 @@ TEST (bulk_pull, none)
TEST (bulk_pull, get_next_on_open)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = nano::dev::genesis_key.pub;
req->end.clear ();
Expand All @@ -104,7 +104,7 @@ TEST (bulk_pull, get_next_on_open)
TEST (bulk_pull, by_block)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = nano::dev::genesis->hash ();
req->end.clear ();
Expand All @@ -121,7 +121,7 @@ TEST (bulk_pull, by_block)
TEST (bulk_pull, by_block_single)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = nano::dev::genesis->hash ();
req->end = nano::dev::genesis->hash ();
Expand All @@ -145,7 +145,7 @@ TEST (bulk_pull, count_limit)
auto receive1 (std::make_shared<nano::receive_block> (send1->hash (), send1->hash (), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (send1->hash ())));
ASSERT_EQ (nano::process_result::progress, node0->process (*receive1).code);

auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node0), node0));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node0, nano::socket::endpoint_type_t::server), node0));
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = receive1->hash ();
req->set_count_present (true);
Expand Down Expand Up @@ -1418,7 +1418,7 @@ TEST (frontier_req_response, DISABLED_destruction)
TEST (frontier_req, begin)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req->start.clear ();
req->age = std::numeric_limits<decltype (req->age)>::max ();
Expand All @@ -1432,7 +1432,7 @@ TEST (frontier_req, begin)
TEST (frontier_req, end)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req->start = nano::dev::genesis_key.pub.number () + 1;
req->age = std::numeric_limits<decltype (req->age)>::max ();
Expand Down Expand Up @@ -1474,7 +1474,7 @@ TEST (frontier_req, count)
node1->work_generate_blocking (*receive1);
ASSERT_EQ (nano::process_result::progress, node1->process (*receive1).code);

auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1), node1));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1, nano::socket::endpoint_type_t::server), node1));
auto req = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req->start.clear ();
req->age = std::numeric_limits<decltype (req->age)>::max ();
Expand All @@ -1488,7 +1488,7 @@ TEST (frontier_req, count)
TEST (frontier_req, time_bound)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req->start.clear ();
req->age = 1;
Expand All @@ -1502,7 +1502,7 @@ TEST (frontier_req, time_bound)
req2->start.clear ();
req2->age = 1;
req2->count = std::numeric_limits<decltype (req2->count)>::max ();
auto connection2 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection2 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
connection2->requests.push (std::unique_ptr<nano::message>{});
auto request2 (std::make_shared<nano::frontier_req_server> (connection, std::move (req2)));
ASSERT_TRUE (request2->current.is_zero ());
Expand All @@ -1511,7 +1511,7 @@ TEST (frontier_req, time_bound)
TEST (frontier_req, time_cutoff)
{
nano::system system (1);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
auto req = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req->start.clear ();
req->age = 3;
Expand All @@ -1526,7 +1526,7 @@ TEST (frontier_req, time_cutoff)
req2->start.clear ();
req2->age = 3;
req2->count = std::numeric_limits<decltype (req2->count)>::max ();
auto connection2 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection2 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));
connection2->requests.push (std::unique_ptr<nano::message>{});
auto request2 (std::make_shared<nano::frontier_req_server> (connection, std::move (req2)));
ASSERT_TRUE (request2->frontier.is_zero ());
Expand Down Expand Up @@ -1599,7 +1599,7 @@ TEST (frontier_req, confirmed_frontier)
ASSERT_EQ (nano::process_result::progress, node1->process (*receive2).code);

// Request for all accounts (confirmed only)
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1), node1));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1, nano::socket::endpoint_type_t::server), node1));
auto req = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req->start.clear ();
req->age = std::numeric_limits<decltype (req->age)>::max ();
Expand All @@ -1613,7 +1613,7 @@ TEST (frontier_req, confirmed_frontier)
ASSERT_EQ (nano::dev::genesis->hash (), request->frontier);

// Request starting with account before genesis (confirmed only)
auto connection2 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1), node1));
auto connection2 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1, nano::socket::endpoint_type_t::server), node1));
auto req2 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req2->start = key_before_genesis.pub;
req2->age = std::numeric_limits<decltype (req2->age)>::max ();
Expand All @@ -1627,7 +1627,7 @@ TEST (frontier_req, confirmed_frontier)
ASSERT_EQ (nano::dev::genesis->hash (), request2->frontier);

// Request starting with account after genesis (confirmed only)
auto connection3 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1), node1));
auto connection3 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1, nano::socket::endpoint_type_t::server), node1));
auto req3 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req3->start = key_after_genesis.pub;
req3->age = std::numeric_limits<decltype (req3->age)>::max ();
Expand All @@ -1641,7 +1641,7 @@ TEST (frontier_req, confirmed_frontier)
ASSERT_TRUE (request3->frontier.is_zero ());

// Request for all accounts (unconfirmed blocks)
auto connection4 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1), node1));
auto connection4 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1, nano::socket::endpoint_type_t::server), node1));
auto req4 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req4->start.clear ();
req4->age = std::numeric_limits<decltype (req4->age)>::max ();
Expand All @@ -1653,7 +1653,7 @@ TEST (frontier_req, confirmed_frontier)
ASSERT_EQ (receive1->hash (), request4->frontier);

// Request starting with account after genesis (unconfirmed blocks)
auto connection5 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1), node1));
auto connection5 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1, nano::socket::endpoint_type_t::server), node1));
auto req5 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req5->start = key_after_genesis.pub;
req5->age = std::numeric_limits<decltype (req5->age)>::max ();
Expand All @@ -1667,7 +1667,7 @@ TEST (frontier_req, confirmed_frontier)
// Confirm account before genesis (confirmed only)
nano::blocks_confirm (*node1, { send1, receive1 }, true);
ASSERT_TIMELY (5s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (receive1->hash ()));
auto connection6 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1), node1));
auto connection6 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1, nano::socket::endpoint_type_t::server), node1));
auto req6 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req6->start = key_before_genesis.pub;
req6->age = std::numeric_limits<decltype (req6->age)>::max ();
Expand All @@ -1683,7 +1683,7 @@ TEST (frontier_req, confirmed_frontier)
// Confirm account after genesis (confirmed only)
nano::blocks_confirm (*node1, { send2, receive2 }, true);
ASSERT_TIMELY (5s, node1->block_confirmed (send2->hash ()) && node1->block_confirmed (receive2->hash ()));
auto connection7 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1), node1));
auto connection7 (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*node1, nano::socket::endpoint_type_t::server), node1));
auto req7 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
req7->start = key_after_genesis.pub;
req7->age = std::numeric_limits<decltype (req7->age)>::max ();
Expand Down Expand Up @@ -1858,7 +1858,7 @@ TEST (bulk_pull_account, basics)
auto send2 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 10));
auto send3 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 2));
ASSERT_TIMELY (5s, system.nodes[0]->balance (key1.pub) == 25);
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0]), system.nodes[0]));
auto connection (std::make_shared<nano::bootstrap_server> (std::make_shared<nano::socket> (*system.nodes[0], nano::socket::endpoint_type_t::server), system.nodes[0]));

{
auto req = std::make_unique<nano::bulk_pull_account> (nano::dev::network_params.network);
Expand Down
6 changes: 3 additions & 3 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ TEST (message_buffer_manager, stats)
TEST (tcp_listener, tcp_node_id_handshake)
{
nano::system system (1);
auto socket (std::make_shared<nano::socket> (*system.nodes[0]));
auto socket (std::make_shared<nano::client_socket> (*system.nodes[0]));
auto bootstrap_endpoint (system.nodes[0]->bootstrap.endpoint ());
auto cookie (system.nodes[0]->network.syn_cookies.assign (nano::transport::map_tcp_to_endpoint (bootstrap_endpoint)));
nano::node_id_handshake node_id_handshake{ nano::dev::network_params.network, cookie, boost::none };
Expand Down Expand Up @@ -814,7 +814,7 @@ TEST (tcp_listener, tcp_listener_timeout_empty)
{
nano::system system (1);
auto node0 (system.nodes[0]);
auto socket (std::make_shared<nano::socket> (*node0));
auto socket (std::make_shared<nano::client_socket> (*node0));
std::atomic<bool> connected (false);
socket->async_connect (node0->bootstrap.endpoint (), [&connected] (boost::system::error_code const & ec) {
ASSERT_FALSE (ec);
Expand All @@ -837,7 +837,7 @@ TEST (tcp_listener, tcp_listener_timeout_node_id_handshake)
{
nano::system system (1);
auto node0 (system.nodes[0]);
auto socket (std::make_shared<nano::socket> (*node0));
auto socket (std::make_shared<nano::client_socket> (*node0));
auto cookie (node0->network.syn_cookies.assign (nano::transport::map_tcp_to_endpoint (node0->bootstrap.endpoint ())));
nano::node_id_handshake node_id_handshake{ nano::dev::network_params.network, cookie, boost::none };
auto channel = std::make_shared<nano::transport::channel_tcp> (*node0, socket);
Expand Down
Loading

0 comments on commit 04e7c58

Please sign in to comment.