From 0c876aea2ad500b3b38bdf3fd4e90c7392b9e69a Mon Sep 17 00:00:00 2001 From: clemahieu Date: Mon, 27 Oct 2014 17:39:08 -0500 Subject: [PATCH] Cleaning some things up. --- rai/core/core.cpp | 8 ++++---- rai/test/client.cpp | 3 ++- rai/test/network.cpp | 25 ++++++++++++++++--------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/rai/core/core.cpp b/rai/core/core.cpp index a8f8d176..5c4afe3e 100644 --- a/rai/core/core.cpp +++ b/rai/core/core.cpp @@ -135,16 +135,16 @@ void rai::network::send_keepalive (boost::asio::ip::udp::endpoint const & endpoi } if (network_keepalive_logging ()) { - client.log.add (boost::str (boost::format ("Kepalive req sent to %1%") % endpoint_a)); + client.log.add (boost::str (boost::format ("Keepalive req sent from %1% to %2%") % endpoint ()% endpoint_a)); } - auto & client_l (client); - send_buffer (bytes->data (), bytes->size (), endpoint_a, [bytes, &client_l] (boost::system::error_code const & ec, size_t) + auto client_l (client.shared ()); + send_buffer (bytes->data (), bytes->size (), endpoint_a, [bytes, client_l, endpoint_a] (boost::system::error_code const & ec, size_t) { if (network_logging ()) { if (ec) { - client_l.log.add (boost::str (boost::format ("Error sending keepalive: %1%") % ec.message ())); + client_l->log.add (boost::str (boost::format ("Error sending keepalive from %1% to %2% %3%") % client_l->network.endpoint () % endpoint_a % ec.message ())); } } }); diff --git a/rai/test/client.cpp b/rai/test/client.cpp index 9863048c..facfb072 100644 --- a/rai/test/client.cpp +++ b/rai/test/client.cpp @@ -15,7 +15,8 @@ TEST (client, block_store_path_failure) rai::client_init init; rai::processor_service processor; auto service (boost::make_shared ()); - rai::client client (init, service, 0, boost::filesystem::path {}, processor, rai::address {}); + auto client (std::make_shared (init, service, 0, boost::filesystem::path {}, processor, rai::address {})); + client->stop (); } TEST (client, balance) diff --git a/rai/test/network.cpp b/rai/test/network.cpp index 93b34ae3..3fb27509 100644 --- a/rai/test/network.cpp +++ b/rai/test/network.cpp @@ -122,24 +122,26 @@ TEST (network, multi_keepalive) auto list1 (system.clients [0]->peers.list ()); ASSERT_EQ (0, list1.size ()); rai::client_init init1; - rai::client client1 (init1, system.service, 24001, system.processor, rai::test_genesis_key.pub); + auto client1 (std::make_shared (init1, system.service, 24001, system.processor, rai::test_genesis_key.pub)); ASSERT_FALSE (init1.error ()); - client1.start (); - client1.network.send_keepalive (system.clients [0]->network.endpoint ()); - ASSERT_EQ (0, client1.peers.size ()); - while (client1.peers.size () != 1 || system.clients [0]->peers.size () != 1) + client1->start (); + client1->network.send_keepalive (system.clients [0]->network.endpoint ()); + ASSERT_EQ (0, client1->peers.size ()); + while (client1->peers.size () != 1 || system.clients [0]->peers.size () != 1) { system.service->run_one (); } rai::client_init init2; - rai::client client2 (init2, system.service, 24002, system.processor, rai::test_genesis_key.pub); + auto client2 (std::make_shared (init2, system.service, 24002, system.processor, rai::test_genesis_key.pub)); ASSERT_FALSE (init2.error ()); - client2.start (); - client2.network.send_keepalive (system.clients [0]->network.endpoint ()); - while (client1.peers.size () != 2 || system.clients [0]->peers.size () != 2 || client2.peers.size () != 2) + client2->start (); + client2->network.send_keepalive (system.clients [0]->network.endpoint ()); + while (client1->peers.size () != 2 || system.clients [0]->peers.size () != 2 || client2->peers.size () != 2) { system.service->run_one (); } + client1->stop (); + client2->stop (); } TEST (network, publish_req) @@ -730,6 +732,7 @@ TEST (bootstrap_processor, process_none) { system.service->run_one (); } + client1->stop (); } TEST (bootstrap_processor, process_incomplete) @@ -768,6 +771,7 @@ TEST (bootstrap_processor, process_one) } auto hash3 (client1->ledger.latest (rai::test_genesis_key.pub)); ASSERT_EQ (hash1, hash3); + client1->stop (); } TEST (bootstrap_processor, process_two) @@ -796,6 +800,7 @@ TEST (bootstrap_processor, process_two) } auto hash4 (client1->ledger.latest (rai::test_genesis_key.pub)); ASSERT_EQ (hash3, hash4); + client1->stop (); } TEST (bootstrap_processor, process_new) @@ -828,6 +833,7 @@ TEST (bootstrap_processor, process_new) ASSERT_LT (iterations2, 200); } ASSERT_EQ (balance1, client1->ledger.account_balance (rai::test_genesis_key.pub)); + client1->stop (); } TEST (bulk_req, no_address) @@ -1030,6 +1036,7 @@ TEST (bulk, genesis) ASSERT_LT (iterations, 200); } while (!finished); ASSERT_EQ (system.clients [0]->ledger.latest (rai::test_genesis_key.pub), client1->ledger.latest (rai::test_genesis_key.pub)); + client1->stop (); } TEST (bulk, offline_send)