diff --git a/rai/core/core.cpp b/rai/core/core.cpp index 488842b0..367e132b 100644 --- a/rai/core/core.cpp +++ b/rai/core/core.cpp @@ -49,7 +49,7 @@ namespace } bool constexpr log_to_cerr () { - return true; + return false; } } @@ -354,9 +354,9 @@ void rai::network::receive_action (boost::system::error_code const & error, size } } -void rai::network::merge_peers (std::array const & peers_a) +void rai::network::merge_peers (std::array const & peers_a) { - for (auto i (peers_a.begin ()), j (peers_a.end ()); i != j; ++i) // Amplify attack, send to the same IP many times + for (auto i (peers_a.begin ()), j (peers_a.end ()); i != j; ++i) { if (*i != endpoint ()) { @@ -370,7 +370,7 @@ void rai::network::merge_peers (std::array const & peers_a) { if (i->address ().to_v4 ().to_ulong () != 0 || i->port () != 0) { - client.log.add (boost::str (boost::format ("Keepalive req contained reserved address"))); + client.log.add (boost::str (boost::format ("Keepalive contained reserved address"))); } } } @@ -2763,7 +2763,7 @@ rai::bootstrap_connection::~bootstrap_connection () } } -void rai::peer_container::random_fill (std::array & target_a) +void rai::peer_container::random_fill (std::array & target_a) { auto peers (list ()); while (peers.size () > target_a.size ()) diff --git a/rai/core/core.hpp b/rai/core/core.hpp index 584b1091..77ad1f2e 100644 --- a/rai/core/core.hpp +++ b/rai/core/core.hpp @@ -150,7 +150,7 @@ namespace rai { bool deserialize (rai::stream &); void serialize (rai::stream &) override; bool operator == (rai::keepalive const &) const; - std::array peers; + std::array peers; rai::uint256_union checksum; }; class publish : public message @@ -439,7 +439,7 @@ namespace rai { void rpc_action (boost::system::error_code const &, size_t); void publish_block (rai::endpoint const &, std::unique_ptr ); void confirm_block (std::unique_ptr , uint64_t); - void merge_peers (std::array const &); + void merge_peers (std::array const &); void maintain_keepalive (rai::endpoint const &); void send_confirm_req (rai::endpoint const &, rai::block const &); void send_buffer (uint8_t const *, size_t, rai::endpoint const &, std::function ); @@ -549,7 +549,7 @@ namespace rai { bool known_peer (rai::endpoint const &); void incoming_from_peer (rai::endpoint const &); bool contacting_peer (rai::endpoint const &); - void random_fill (std::array &); + void random_fill (std::array &); std::vector list (); void refresh_action (); void queue_next_refresh (); diff --git a/rai/test/peer_container.cpp b/rai/test/peer_container.cpp index f08c7aa2..46de7e8b 100644 --- a/rai/test/peer_container.cpp +++ b/rai/test/peer_container.cpp @@ -74,7 +74,7 @@ TEST (peer_container, split) TEST (peer_container, fill_random_clear) { rai::peer_container peers (rai::endpoint {}); - std::array target; + std::array target; std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000)); peers.random_fill (target); ASSERT_TRUE (std::all_of (target.begin (), target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); })); @@ -87,7 +87,7 @@ TEST (peer_container, fill_random_full) { peers.incoming_from_peer (rai::endpoint (boost::asio::ip::address_v6::loopback (), i)); } - std::array target; + std::array target; std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000)); peers.random_fill (target); ASSERT_TRUE (std::none_of (target.begin (), target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); })); @@ -96,14 +96,15 @@ TEST (peer_container, fill_random_full) TEST (peer_container, fill_random_part) { rai::peer_container peers (rai::endpoint {}); - for (auto i (0); i < 16; ++i) + std::array target; + auto half (target.size () / 2); + for (auto i (0); i < half; ++i) { peers.incoming_from_peer (rai::endpoint (boost::asio::ip::address_v6::loopback (), i + 1)); } - std::array target; std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000)); peers.random_fill (target); - ASSERT_TRUE (std::none_of (target.begin (), target.begin () + 16, [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); })); - ASSERT_TRUE (std::none_of (target.begin (), target.begin () + 16, [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 0); })); - ASSERT_TRUE (std::all_of (target.begin () + 16, target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); })); + ASSERT_TRUE (std::none_of (target.begin (), target.begin () + half, [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); })); + ASSERT_TRUE (std::none_of (target.begin (), target.begin () + half, [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 0); })); + ASSERT_TRUE (std::all_of (target.begin () + half, target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); })); } \ No newline at end of file